本文整理匯總了PHP中Doctrine\Common\Collections\Criteria::orWhere方法的典型用法代碼示例。如果您正苦於以下問題:PHP Criteria::orWhere方法的具體用法?PHP Criteria::orWhere怎麽用?PHP Criteria::orWhere使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\Common\Collections\Criteria
的用法示例。
在下文中一共展示了Criteria::orWhere方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: searchByContains
public function searchByContains(array $criteria, array $orderBy = null, $page = 0, $pageSize = PHP_INT_MAX)
{
if ($page < 0 || $pageSize < 1) {
throw new \Exception("Invalid page or pageSize: page must be >= 0 and pageSize must be > 0");
} else {
$criteriaObj = new Criteria();
$i = 0;
foreach ($criteria as $field => $value) {
if ($value == null) {
continue;
} else {
if ($i++ == 0) {
$criteriaObj->where($criteriaObj->expr()->contains($field, $value));
} else {
$criteriaObj->orWhere($criteriaObj->expr()->contains($field, $value));
}
}
}
if ($orderBy != null) {
$criteriaObj->orderBy($orderBy);
}
$total = $this->repository->matching($criteriaObj)->count();
$query = $this->repository->createQueryBuilder("q")->addCriteria($criteriaObj);
$items = $query->setFirstResult($page * $pageSize)->setMaxResults($pageSize)->getQuery()->getResult();
return ResponseUtils::createSearchResponse($total, $items, $page, $pageSize);
}
}
示例2: 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();
}
示例3: testOrWhere
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());
}
示例4: loadUserByUsername
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.");
}
示例5: addDefaultCriteria
/**
* @param Criteria $criteria
*/
protected function addDefaultCriteria(Criteria $criteria)
{
$defaultCriteria = $this->getCriteriaWithOutOrganizationAndUser();
$criteria->orWhere(Criteria::expr()->orX($defaultCriteria->getWhereExpression()));
}
示例6: findAllPublicWithQuery
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);
}