本文整理汇总了PHP中Doctrine\Common\Collections\Criteria::where方法的典型用法代码示例。如果您正苦于以下问题:PHP Criteria::where方法的具体用法?PHP Criteria::where怎么用?PHP Criteria::where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Collections\Criteria
的用法示例。
在下文中一共展示了Criteria::where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: applyFilter
/**
* @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);
}
}
}
}
}
示例2: findEmailsByIds
/**
* 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;
}
示例3: load
/**
* {@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);
}
}
示例4: getProducerCollection
/**
* 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);
}
示例5: getShippingMethods
/**
* {@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;
}
示例6: getThreadEmails
/**
* 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;
}
示例7: sidebarEventsAction
/**
* @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);
}
}
示例8: createService
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;
}
示例9: testWhere
public function testWhere()
{
$expr = new Comparison("field", "=", "value");
$criteria = new Criteria();
$criteria->where($expr);
$this->assertSame($expr, $criteria->getWhereExpression());
}
示例10: testUsersWithFacebookLogin
public function testUsersWithFacebookLogin()
{
$criteria = new Criteria();
$criteria->where($criteria->expr()->neq('facebook_id', null));
$users = $this->getUserRepository()->matching($criteria);
$this->assertCount(8, $users);
}
示例11: getCriteria
/**
* 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;
}
示例12: findAvailableForUser
/**
* @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);
}
示例13: visualizaAction
/**
* 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));
}
}
示例14: getProductReviews
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);
}
示例15: resolve
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();
}