Your IP : 216.73.217.79


Current Path : /var/www/v3.cesa.co.za/src/MemberBundle/Repository/
Upload File :
Current File : /var/www/v3.cesa.co.za/src/MemberBundle/Repository/ADecTransformationRepository.php

<?php

namespace App\MemberBundle\Repository;

use App\MemberBundle\Entity\ADecTransformation;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
 * @extends ServiceEntityRepository<ADecTransformation>
 *
 * @method ADecTransformation|null find($id, $lockMode = null, $lockVersion = null)
 * @method ADecTransformation|null findOneBy(array $criteria, array $orderBy = null)
 * @method ADecTransformation[]    findAll()
 * @method ADecTransformation[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 */
class ADecTransformationRepository extends ServiceEntityRepository {

    public function __construct(ManagerRegistry $registry) {
        parent::__construct($registry, ADecTransformation::class);
    }

    public function findOneByLiveFirmAndDeclarationYear(int $liveFirmId, int $year): ?ADecTransformation
    {
        return $this->findOneBy([
            'prev_firm_id' => $liveFirmId,
            'declaration_year' => $year,
        ]);
    }

    /**
     * Get the list of IDs
     * @return array
     */
    public function findOneByArray($params) {

        if (isset($params['year']) && !is_null($params['year']) && $params['year'] != 'members') {

            $conn = $this->getEntityManager()->getConnection();

            $tableName = 'ADec_Transformation_' . $params['year'];
            $whereClause = '';

            if ($params['year'] > 2023) {
                $tableName = 'ADec_Transformation';
                $whereClause = ' AND mf.DeclarationYear = ' . $params['year'] . ' ';
            }

            $sql = "SELECT mf.* 
                FROM " . $tableName . " mf 
                    WHERE mf.Prev_FirmID = " . $params['member_firm']->getId() . " "
                . $whereClause;
//            echo $sql . '<br />';

            $resultSet = $conn->executeQuery($sql);

            return $resultSet->fetchAllAssociative();
        } else {
            return $this->createQueryBuilder('mf')
                ->where('mf.prev_firm_id = :prevFirmId')->setParameter('prevFirmId', $params['member_firm']->getId())
                ->andWhere('mf.declaration_year = :declarationYear')->setParameter('declarationYear', date('Y'))
                ->getQuery()->getArrayResult();
        }
        
        $qb = $this->createQueryBuilder('mft')
                ->where('1 = 1');

        foreach ($params as $col => $param) {
//            echo $param->getId() . '<br />';
            $qb->andWhere('mft.' . $col . ' = :' . $col)->setParameter($col, $param);
        }

//        echo $qb->getQuery()->getSQL();
//        exit;

        return $qb->getQuery()->getArrayResult();
    }

//    /**
//     * @return ADecTransformation[] Returns an array of ADecTransformation objects
//     */
//    public function findByExampleField($value): array
//    {
//        return $this->createQueryBuilder('a')
//            ->andWhere('a.exampleField = :val')
//            ->setParameter('val', $value)
//            ->orderBy('a.id', 'ASC')
//            ->setMaxResults(10)
//            ->getQuery()
//            ->getResult()
//        ;
//    }
//    public function findOneBySomeField($value): ?ADecTransformation
//    {
//        return $this->createQueryBuilder('a')
//            ->andWhere('a.exampleField = :val')
//            ->setParameter('val', $value)
//            ->getQuery()
//            ->getOneOrNullResult()
//        ;
//    }
}