/** * Get Query for All Entities * * @param User $user * * @param \DateTime $minDtCrea * * @return \Doctrine\ORM\Query */ public function getAllByAdminQuery(User $user, \DateTime $minDtCrea = null) { $companies = $user->getAdmCompanies(); if (null == $companies || \count($companies) == 0) { if (null == $minDtCrea) { return $this->createQueryBuilder('t')->where('t.companyId IN (:companyIds)')->andWhere('t.actionEntity NOT IN (:entities)')->orderBy('t.dtCrea', 'ASC')->addOrderBy('t.actionType', 'ASC')->addOrderBy('t.actionEntity', 'ASC')->setParameter('companyIds', null)->setParameter('entities', array(Trace::AE_DOCGROUPSYST, Trace::AE_DOCGROUPAUDIT, Trace::AE_SHAREHOLDER, Trace::AE_PILOT, Trace::AE_CUSER, Trace::AE_CADMIN))->getQuery(); } else { return $this->createQueryBuilder('t')->where('t.companyId IN (:companyIds)')->andWhere('t.actionEntity NOT IN (:entities)')->andWhere('t.dtCrea >= :minDate')->orderBy('t.dtCrea', 'ASC')->addOrderBy('t.actionType', 'ASC')->addOrderBy('t.actionEntity', 'ASC')->setParameter('companyIds', null)->setParameter('entities', array(Trace::AE_DOCGROUPSYST, Trace::AE_DOCGROUPAUDIT, Trace::AE_SHAREHOLDER, Trace::AE_PILOT, Trace::AE_CUSER, Trace::AE_CADMIN))->setParameter('minDate', $minDtCrea)->getQuery(); } } else { $cIds = array(); foreach ($companies as $company) { $cIds[] = $company->getId(); } if (null == $minDtCrea) { return $this->createQueryBuilder('t')->where('t.companyId IN (:companyIds)')->andWhere('t.actionEntity NOT IN (:entities)')->orderBy('t.dtCrea', 'ASC')->addOrderBy('t.actionType', 'ASC')->addOrderBy('t.actionEntity', 'ASC')->setParameter('companyIds', $cIds)->setParameter('entities', array(Trace::AE_DOCGROUPSYST, Trace::AE_DOCGROUPAUDIT, Trace::AE_SHAREHOLDER, Trace::AE_PILOT, Trace::AE_CUSER, Trace::AE_CADMIN))->getQuery(); } else { return $this->createQueryBuilder('t')->where('t.companyId IN (:companyIds)')->andWhere('t.actionEntity NOT IN (:entities)')->andWhere('t.dtCrea >= :minDate')->orderBy('t.dtCrea', 'ASC')->addOrderBy('t.actionType', 'ASC')->addOrderBy('t.actionEntity', 'ASC')->setParameter('companyIds', $cIds)->setParameter('entities', array(Trace::AE_DOCGROUPSYST, Trace::AE_DOCGROUPAUDIT, Trace::AE_SHAREHOLDER, Trace::AE_PILOT, Trace::AE_CUSER, Trace::AE_CADMIN))->setParameter('minDate', $minDtCrea)->getQuery(); } } }