Пример #1
0
 public function count(array $criteria)
 {
     $criteriaObj = new Criteria();
     foreach ($criteria as $field => $value) {
         $criteriaObj->where($criteriaObj->expr()->eq($field, $value));
     }
     return $this->repository->matching($criteriaObj)->count();
 }
Пример #2
0
 /**
  * Select all elements from a selectable that match the expression and
  * return a new collection containing these elements.
  *
  * @param Criteria $criteria
  * @return \Doctrine\Common\Collections\Collection
  * @throws \LogicException
  */
 public function matching(Criteria $criteria)
 {
     if (!$this->baseRepository instanceof Selectable) {
         throw new \LogicException('The base repository does not implement Selectable.');
     }
     return $this->baseRepository->matching($criteria);
 }
 /**
  *
  * @return array
  */
 public function getAllAsArray(Organisation $organisation = null)
 {
     $list = array();
     if ($organisation) {
         $criteria = Criteria::create()->where(Criteria::expr()->eq('organisation', $organisation));
         $list = parent::matching($criteria);
     } else {
         $list = parent::findAll();
     }
     $res = array();
     foreach ($list as $element) {
         $res[$element->getId()] = $element->getName();
     }
     return $res;
 }
Пример #4
0
 /**
  *
  * @return array
  */
 public function getAllAsArray($criteria = null)
 {
     $list = array();
     if ($criteria === null) {
         $list = parent::findAll();
     } else {
         if ($criteria instanceof Criteria) {
             $list = parent::matching($criteria);
         } else {
             $list = parent::findBy($criteria);
         }
     }
     $res = array();
     foreach ($list as $element) {
         $res[$element->getId()] = $element->getName();
     }
     return $res;
 }
Пример #5
0
 protected function findTranslatableEntities(EntityRepository $repository, LocaleInterface $locale) : Collection
 {
     $criteria = new Criteria();
     $criteria->where($criteria->expr()->eq('locale', $locale->getCode()));
     $collection = $repository->matching($criteria);
     return $collection;
 }
 /**
  * @param Criteria $criteria
  * @return int
  */
 public function totalNumberOfFilteredRecords(Criteria $criteria)
 {
     return parent::matching($criteria)->count();
 }
Пример #7
0
 /** {@inheritdoc} @override */
 public function matching(Criteria $criteria)
 {
     if (null !== ($config = $this->getConfig()) && $config->get('multitenant.enabled')) {
         $criteria->andWhere($criteria->expr()->eq($config->get('multitenant.keymap'), $config->get('app.key')));
     }
     return parent::matching($criteria);
 }
 /**
  * Deletes the translatable entities for locale
  *
  * @param EntityRepository $repository
  * @param LocaleInterface  $locale
  * @param OutputInterface  $output
  */
 protected function deleteTranslatableEntities(EntityRepository $repository, LocaleInterface $locale, OutputInterface $output)
 {
     $entityManager = $this->getDoctrineHelper()->getEntityManager();
     $criteria = new Criteria();
     $criteria->where($criteria->expr()->eq('locale', $locale->getCode()));
     $collection = $repository->matching($criteria);
     $collection->map(function (LocaleAwareInterface $entity) use($entityManager) {
         $entityManager->remove($entity);
     });
     $output->write(sprintf('Deleted <info>%s</info> entities <info>%s</info>', $collection->count(), $repository->getClassName()), true);
 }