/** * @param Request $request * @param FilterInterface $filter * @param Criteria $criteria * @param ClassMetadata $embedClassMeta * * @return null */ protected function applyFilter(Request $request, FilterInterface $filter, Criteria $criteria, ClassMetadata $embedClassMeta) { $properties = $filter->getRequestProperties($request); if ($filter instanceof OrderFilter && !empty($properties)) { $criteria->orderBy($properties); return null; } if ($filter instanceof SearchFilter) { foreach ($properties as $name => $propertie) { if (in_array($name, $embedClassMeta->getIdentifier())) { continue; } $expCriterial = Criteria::expr(); if ($embedClassMeta->hasAssociation($name)) { $associationTargetClass = $embedClassMeta->getAssociationTargetClass($name); $propertyResource = $this->resourceResolver->getResourceForEntity($associationTargetClass); $propertyObj = $this->dataProviderChain->getItem($propertyResource, (int) $propertie['value'], true); if ($propertyObj && $propertyResource instanceof ResourceInterface) { $whereCriteria = $expCriterial->in($name, [$propertyObj]); $criteria->where($whereCriteria); } } else { if ($embedClassMeta->hasField($name)) { $fieldMapping = $embedClassMeta->getFieldMapping($name); $type = isset($fieldMapping['type']) ? $fieldMapping['type'] : null; $value = isset($this->mappingFilterVar[$type]) ? filter_var($propertie['value'], $this->mappingFilterVar[$type]) : $propertie['value']; $whereCriteria = isset($propertie['precision']) && $propertie['precision'] === 'exact' ? $expCriterial->eq($name, $value) : $expCriterial->contains($name, $propertie['value']); $criteria->where($whereCriteria); } } } } }
/** * Gets emails by ids * * @param int[] $ids * * @return Email[] */ public function findEmailsByIds($ids) { $queryBuilder = $this->createQueryBuilder('e'); $criteria = new Criteria(); $criteria->where(Criteria::expr()->in('id', $ids)); $criteria->orderBy(['sentAt' => Criteria::DESC]); $queryBuilder->addCriteria($criteria); $result = $queryBuilder->getQuery()->getResult(); return $result; }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { $criteria = new Criteria(); $criteria->where($criteria->expr()->neq('xThreadId', null)); /** @var QueryBuilder $threadQueryBuilder */ $threadQueryBuilder = $manager->getRepository('OroEmailBundle:Email')->createQueryBuilder('entity'); $threadQueryBuilder->distinct()->select('entity.xThreadId'); $threadQueryBuilder->addCriteria($criteria); $iterator = new BufferedQueryResultIterator($threadQueryBuilder); $iterator->setBufferSize(self::BATCH_SIZE); $itemsCount = 0; $entities = []; foreach ($iterator as $threadResult) { $threadId = $threadResult['xThreadId']; /** @var QueryBuilder $queryBuilder */ $queryBuilder = $manager->getRepository('OroEmailBundle:Email')->createQueryBuilder('entity'); $criteria = new Criteria(); $criteria->where($criteria->expr()->eq('xThreadId', $threadId)); $criteria->orderBy(['created' => 'ASC']); $queryBuilder->addCriteria($criteria); $queryBuilder->setFirstResult(0); $emails = $queryBuilder->getQuery()->execute(); if (count($emails) > 1) { $itemsCount++; $newThread = new EmailThread(); $manager->persist($newThread); foreach ($emails as $key => $email) { /** @var Email $email */ if ($key == 0) { $email->setHead(true); } else { $email->setHead(false); } $email->setThread($newThread); $entities[] = $email; } } elseif (count($emails) == 1) { $email = $emails[0]; $email->setHead(true); $itemsCount++; $entities[] = $email; } if (0 == $itemsCount % self::BATCH_SIZE) { $this->saveEntities($manager, $entities); $entities = []; } } if ($itemsCount % self::BATCH_SIZE > 0) { $this->saveEntities($manager, $entities); } }
/** * Returns the collection of producers for given identifiers * * @param array $identifiers * * @return \Doctrine\Common\Collections\Collection */ protected function getProducerCollection(array $identifiers = []) { $criteria = new Criteria(); $criteria->orderBy(['id' => 'asc']); $criteria->where($criteria->expr()->in('id', $identifiers)); return $this->producerRepository->matching($criteria); }
/** * {@inheritdoc} */ public function getShippingMethods() : Collection { $criteria = new Criteria(); $criteria->where($criteria->expr()->eq('enabled', true)); $criteria->orderBy(['hierarchy' => 'asc']); $methods = $this->matching($criteria)->filter(function (ShippingMethodInterface $shippingMethod) { $paymentMethodsCount = $shippingMethod->getPaymentMethods()->count(); $shippingMethodCostCount = $shippingMethod->getCosts()->count(); return $paymentMethodsCount > 0 && $shippingMethodCostCount > 0; }); return $methods; }
/** * Get emails in thread of current one * * @param EntityManager $entityManager * @param Email $entity * * @return Email[] */ public function getThreadEmails(EntityManager $entityManager, Email $entity) { $thread = $entity->getThread(); if ($thread) { /** @var QueryBuilder $queryBuilder */ $queryBuilder = $entityManager->getRepository('OroEmailBundle:Email')->createQueryBuilder('e'); $criteria = new Criteria(); $criteria->where($criteria->expr()->eq('thread', $thread)); $criteria->orderBy(['sentAt' => Criteria::DESC]); $queryBuilder->addCriteria($criteria); $result = $queryBuilder->getQuery()->getResult(); } else { $result = [$entity]; } return $result; }
/** * @Template("Event/sidebarEvents.html.twig") * @return type */ public function sidebarEventsAction() { $em = $this->getDoctrine()->getManager(); $eventRepository = $em->getRepository("TruckeeMatchBundle:Event"); // $user = $this->getUser(); $criteria = new Criteria(); $criteria->where($criteria->expr()->gte('eventdate', new \DateTime())); $criteria->orderBy(['eventdate' => 'ASC']); $criteria->setMaxResults(5); $templates[] = 'Event/hr.html.twig'; if (!empty($eventRepository)) { return array('templates' => $templates, 'events' => $eventRepository->matching($criteria)); } else { return array('templates' => $templates); } }
public function createService(ServiceLocatorInterface $serviceLocator) { $entityManager = $serviceLocator->get('entity-manager'); $languageEntity = $serviceLocator->get('lang-entity'); $criteria = new Criteria(); $criteria->where($criteria->expr()->gt('status', 0))->orderBy(['status' => Criteria::DESC]); $language = new \Application\Service\Invokable\Language(); $languageClassName = get_class($languageEntity); $activeLanguages = $entityManager->getRepository($languageClassName)->matching($criteria); $language->setActiveLanguages($activeLanguages); $defaultLanguage = $entityManager->getRepository($languageClassName)->findOneByStatus(Lang::STATUS_DEFAULT); $defaultLanguage = $defaultLanguage ?: new Lang(); $language->setDefaultLanguage($defaultLanguage); $request = $serviceLocator->get('Request'); $router = $serviceLocator->get('Router'); $match = $router->match($request); if ($match) { $matchedLangIso = $match->getParam('lang', $defaultLanguage->getIsoCode()); if ($matchedLangIso) { $currentLanguage = $entityManager->getRepository($languageClassName)->findOneByIsoCode($matchedLangIso); } } $currentLanguage = isset($currentLanguage) ? $currentLanguage : new Lang(); $language->setCurrentLanguage($currentLanguage); return $language; }
public function testWhere() { $expr = new Comparison("field", "=", "value"); $criteria = new Criteria(); $criteria->where($expr); $this->assertSame($expr, $criteria->getWhereExpression()); }
public function testUsersWithFacebookLogin() { $criteria = new Criteria(); $criteria->where($criteria->expr()->neq('facebook_id', null)); $users = $this->getUserRepository()->matching($criteria); $this->assertCount(8, $users); }
/** * Returns the report's criteria * * @param ReportConfiguration $configuration * * @return Criteria */ protected function getCriteria(ReportConfiguration $configuration) { $criteria = new Criteria(); $criteria->where($criteria->expr()->gte('createdAt', $configuration->getStartDate())); $criteria->andWhere($criteria->expr()->lte('createdAt', $configuration->getEndDate())); return $criteria; }
/** * @param User $user * @param int $limit * @return Collection|Game[] */ public function findAvailableForUser(User $user, $limit) { $criteria = new Criteria(); $expr = Criteria::expr(); $criteria->where($expr->neq('user1', $user))->andWhere($expr->isNull('user2'))->setMaxResults($limit)->orderBy(['id' => 'DESC']); return $this->matching($criteria); }
/** * view the property selected, if tenant ask for more informations, as him to register * @return ViewModel */ public function visualizaAction() { //save new tenant or get the tenant prior registered if ($this->getRequest()->isPost()) { //getting posible tenant prior registered $criterio = new Criteria(); $criterio->where($criterio->expr()->eq('nome', $this->getRequest()->getPost('nome')))->andWhere($criterio->expr()->eq('email', $this->getRequest()->getPost('email')))->andWhere($criterio->expr()->eq('foneCelular', $this->getRequest()->getPost('telefone'))); $locatario = $this->getEm()->getRepository('MyClasses\\Entities\\Locatario')->matching($criterio); //if quantity of tenants by criteria above is zero... if (!$locatario->count()) { //...register new tenant... $locatario = new Locatario(); $locatario->setNome($this->getRequest()->getPost('nome')); $locatario->setEmail($this->getRequest()->getPost('email')); $locatario->setFoneCelular($this->getRequest()->getPost('telefone')); $this->getEm()->persist($locatario); $this->getEm()->flush(); //...else, get the tenant prior registered } else { $locatario = $locatario->first(); } $this->sessao->locatario = $locatario; } //get the property and send to view if ($this->Params('id')) { $imovel = $this->getEm()->getRepository("MyClasses\\Entities\\Imovel")->find($this->Params('id')); return new ViewModel(array('imovel' => $imovel, 'mais' => $this->Params('mais'), 'locatario' => $this->sessao->locatario)); } }
public function getProductReviews(ProductInterface $product) : Collection { $criteria = new Criteria(); $criteria->where($criteria->expr()->eq('product', $product)); $criteria->andWhere($criteria->expr()->eq('enabled', true)); return $this->matching($criteria); }
public function resolve(int $currentShopId, string $url) : ShopInterface { $criteria = new Criteria(); $criteria->where($criteria->expr()->eq('id', $currentShopId)); $criteria->orWhere($criteria->expr()->eq('url', $url)); $criteria->orWhere($criteria->expr()->gte('id', 1)); return $this->matching($criteria)->first(); }
/** * Finds operations * * @param Status $status status to filter upon * @param DateTime $date optional date to filter upon * * @return OperationInterface[] */ public function findByStatusAndBeforeUpdatedAt(Status $status, DateTime $date) { $criteria = new Criteria(); $exprBuilder = new ExpressionBuilder(); $criteria->where($exprBuilder->eq('status', $status->getValue())); $criteria->andWhere($exprBuilder->lte('updatedAt', $date)); return $this->matching($criteria)->toArray(); }
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(); }
private function findPreviousOrdersToday() : Collection { $today = Carbon::now()->startOfDay(); $criteria = new Criteria(); $criteria->where($criteria->expr()->gte('updatedAt', $today)); $criteria->andWhere($criteria->expr()->eq('confirmed', true)); return $this->orderRepository->matching($criteria); }
/** * @depends testUpdate */ public function testFind() { $criteria = new Criteria(); $expression = new ExpressionBuilder(); $exp = $expression->eq('username', 'john'); $criteria->where($exp); $this->assertEquals(1, count($this->getRepository(UserExtraEntity::class)->findBy($criteria))); $this->assertEquals(2, count($this->getRepository(UserExtraEntity::class)->findAll())); }
public function copyLocaleData(LocaleInterface $sourceLocale, LocaleInterface $targetLocale) { $criteria = new Criteria(); $criteria->where($criteria->expr()->eq('locale', $sourceLocale->getCode())); foreach ($this->entityClasses as $className => $options) { $repository = $this->doctrineHelper->getRepositoryForClass($className); $entities = $repository->matching($criteria); $this->duplicateTranslatableEntities($entities, $options['properties'], $targetLocale); } $this->doctrineHelper->getEntityManager()->flush(); }
public function testOrWhere() { $expr = new Comparison("field", "=", "value"); $criteria = new Criteria(); $criteria->where($expr); $expr = $criteria->getWhereExpression(); $criteria->orWhere($expr); $where = $criteria->getWhereExpression(); $this->assertInstanceOf('Doctrine\\Common\\Collections\\Expr\\CompositeExpression', $where); $this->assertEquals(CompositeExpression::TYPE_OR, $where->getType()); $this->assertSame(array($expr, $expr), $where->getExpressionList()); }
/** * list the projects * @return \Zend\View\Model\ViewModel */ public function indexAction() { $usuario = $this->getEm()->getRepository('MyClasses\\Entities\\AclUsuario')->findOneBy(array("id" => $this->identity()[0]->getId())); if ($this->identity()[1] == "adm") { $criterio = new Criteria(); $criterio->where($criterio->expr()->eq('usuario', $usuario))->orWhere($criterio->expr()->isNull('usuario')); $projetos = $this->getEm()->getRepository('MyClasses\\Entities\\Projeto')->matching($criterio); } else { $projetos = $usuario->getProjetos(); } return new ViewModel(array('projetos' => $projetos)); }
public function loadUserByUsername($username) { $criteria = new Criteria(); $criteria->where(new Comparison("username", Comparison::EQ, $username)); $criteria->orWhere(new Comparison("email", Comparison::EQ, $username)); $criteria->setMaxResults(1); $user = $this->em->getRepository("CoreUserBundle:User")->matching($criteria)->first(); if ($user) { return $user; } //throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username)); throw new BadCredentialsException("Bad credentials."); }
/** * @param Game $game * @param string $eventType * @param int $player 1|2 * @return Criteria */ private function createFindForGameByTypeAndPlayerCriteria(Game $game, $eventType = null, $player = null) { $criteria = new Criteria(); $expr = Criteria::expr(); $criteria->where($expr->eq('game', $game)); if ($eventType !== null) { $criteria->andWhere($expr->eq('type', $eventType)); } if ($player !== null) { $criteria->andWhere($expr->eq('player', $player)); } return $criteria; }
/** * @depends testSearchEntity */ public function testDeleteWithGlobalIndexEntity() { $criteria = new Criteria(); $exp = new ExpressionBuilder(); $criteria->where($exp->eq('is_default', 'true')); $result = $this->getDriver()->findBy($criteria, $this->getClassMetadata()); $this->assertEquals(2, count($result)); foreach ($result as $item) { $result = $this->getDriver()->deleteItem(['scope_name' => $item['scope_name']], $this->getClassMetadata()); $this->assertTrue($result); } $result = $this->getDriver()->findBy($criteria, $this->getClassMetadata()); $this->assertEquals(0, count($result)); }
/** * list tasks * @return \Zend\View\Model\ViewModel */ public function indexAction() { $tarefasPessoais = null; $usuario = $this->getEm()->getRepository('MyClasses\\Entities\\AclUsuario')->findOneBy(array("id" => $this->identity()[0]->getId())); if ($this->identity()[1] == "adm") { $criterio = new Criteria(); $criterio->where($criterio->expr()->eq('usuario', $usuario))->orWhere($criterio->expr()->isNull('usuario')); $projetos = $this->getEm()->getRepository('MyClasses\\Entities\\Projeto')->matching($criterio); } else { $projetos = $usuario->getProjetos(); $idsProjetos[] = 0; foreach ($projetos as $projeto) { $idsProjetos[] = $projeto->getId(); } $tarefasPessoais = $usuario->getTarefasCorrelatas($idsProjetos); //echo $tarefasPessoais->count(); //$tarefasEquipe = $usuario;//TODO get the user's team tasks } return new ViewModel(array('projetos' => $projetos, 'tarefasPessoais' => $tarefasPessoais)); }
public function hasErrors() { $criteria = new Criteria(); $criteria->where($criteria->expr()->eq('error', TRUE)); return count($this->outputs->matching($criteria)) !== 0; }
public function testAddCriteriaWhere() { $qb = $this->_em->createQueryBuilder(); $criteria = new Criteria(); $criteria->where($criteria->expr()->eq('field', 'value')); $qb->addCriteria($criteria); $this->assertEquals('field = :field', (string) $qb->getDQLPart('where')); $this->assertNotNull($qb->getParameter('field')); }
/** * {@inheritdoc} */ public function getCollectionByAttribute(AttributeInterface $attribute) { $criteria = new Criteria(); $criteria->where($criteria->expr()->eq('attribute', $attribute)); return $this->matching($criteria); }
public function findAllPublicWithQuery($query, $page, $itemPerPage) { $publicCriteria = new Criteria(); $publicCriteria->where($publicCriteria->expr()->eq('r.published', true)); $queryCriteria = new Criteria(); $queryCriteria->where($queryCriteria->expr()->contains('r.title', $query)); $queryCriteria->orWhere($queryCriteria->expr()->contains('r.content', $query)); $orderCriteria = new Criteria(); $orderCriteria->orderBy(['r.dateUpdated' => 'DESC']); /** @var QueryBuilder $queryBuilder */ $queryBuilder = $this->objectRepository->createQueryBuilder('r'); $queryBuilder->addCriteria($publicCriteria); $queryBuilder->addCriteria($queryCriteria); $queryBuilder->addCriteria($orderCriteria); $queryBuilder->setFirstResult(($page - 1) * $itemPerPage); $queryBuilder->setMaxResults($itemPerPage); return new Paginator($queryBuilder); }