本文整理汇总了PHP中Doctrine\Common\Collections\Criteria::andWhere方法的典型用法代码示例。如果您正苦于以下问题:PHP Criteria::andWhere方法的具体用法?PHP Criteria::andWhere怎么用?PHP Criteria::andWhere使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Collections\Criteria
的用法示例。
在下文中一共展示了Criteria::andWhere方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMenu
public function getMenu()
{
$criteria = new Criteria();
$criteria->orderBy(['hierarchy' => 'asc']);
$criteria->andWhere($criteria->expr()->eq('parent', null));
return $this->adminMenuRepository->matching($criteria);
}
示例2: addFilters
/**
* Adds filters to a query builder
*
* @param QueryBuilder $qb
* @param array|Criteria $filters Additional filtering criteria, e.g. ['allDay' => true, ...]
* or \Doctrine\Common\Collections\Criteria
*/
protected function addFilters(QueryBuilder $qb, $filters)
{
if ($filters) {
if (is_array($filters)) {
$newCriteria = new Criteria();
foreach ($filters as $fieldName => $value) {
$newCriteria->andWhere(Criteria::expr()->eq($fieldName, $value));
}
$filters = $newCriteria;
}
if ($filters instanceof Criteria) {
$qb->addCriteria($filters);
}
}
}
示例3: searchClients
public function searchClients(array $criteria, array $orderBy = null, $page = 0, $pageSize = 10)
{
$params = new ClientSearch($criteria);
$criteriaObj = new Criteria();
if ($params->getApprovedforbusiness()) {
$criteriaObj->andWhere($criteriaObj->expr()->eq('approvedforbusiness', 1));
}
if ($params->getClientcode() != null) {
$criteriaObj->andWhere($criteriaObj->expr()->contains('clientcode', $params->getClientcode()));
}
if ($params->getSearchtext() != null) {
$criteriaObj->andWhere($criteriaObj->expr()->orX($criteriaObj->expr()->contains('name', $params->getSearchtext()), $criteriaObj->expr()->contains('address', $params->getSearchtext()), $criteriaObj->expr()->contains('postcode', $params->getSearchtext())));
}
if ($orderBy != null) {
$criteriaObj->orderBy($orderBy);
}
return $this->clientsRepo->searchByCriteria($criteriaObj, $page, $pageSize);
}
示例4: initDatabaseMock
/**
* Initialize mocks for Doctrine
*
* @param array $managersToMock List of managers to be mocked
*
* @return void
*/
protected function initDatabaseMock($managersToMock)
{
if (is_null($this->mockedManager)) {
$test = $this;
foreach ($managersToMock as $manager) {
$entityName = $manager['entityName'];
// EntityManager mock
$entityManagerMock = new \mock\Doctrine\ORM\EntityManager();
// ClassMetadata mock
$classMetadata = new \mock\Doctrine\ORM\Mapping\ClassMetadata($entityName);
$entityClassName = $manager['entityClassName'];
$this->calling($classMetadata)->getName = function () use($entityClassName) {
return $entityClassName;
};
// EntityRepository mock
$entityRepositoryMock = new \mock\Doctrine\ORM\EntityRepository($entityManagerMock, $classMetadata);
$this->calling($entityRepositoryMock)->find = function ($id) use($test, $entityName) {
if (!empty($test->database[$entityName]) && array_key_exists($id, $test->database[$entityName])) {
return clone $test->database[$entityName][$id];
}
return null;
};
$this->calling($entityRepositoryMock)->findBy = function ($criteria = [], $sort = null, $limit = null, $start = 0) use($test, $entityName) {
$entities = new ArrayCollection($test->database[$entityName]);
$crit = new Criteria();
foreach ($criteria as $field => $value) {
$crit->andWhere($crit->expr()->eq($field, $value));
}
if (!is_null($sort)) {
$crit->orderBy($sort);
}
$crit->setFirstResult($start);
$crit->setMaxResults($limit);
return $entities->matching($crit)->map(function ($item) {
return clone $item;
});
};
// Overload main EntityManager functions
$this->calling($entityManagerMock)->getRepository = function () use($entityRepositoryMock) {
return $entityRepositoryMock;
};
$this->calling($entityManagerMock)->getClassMetadata = function ($entity) use($classMetadata) {
return $classMetadata;
};
$this->calling($entityManagerMock)->persist = function ($entity) use($test, $entityName) {
if (!$entity->getId()) {
if (!empty($test->database[$entityName])) {
$entity->setId(count($test->database[$entityName]) + 1);
} else {
$entity->setId(1);
}
}
$test->database[$entityName][$entity->getId()] = $entity;
return true;
};
$this->calling($entityManagerMock)->remove = function ($entity) use($test, $entityName) {
if (!$entity->getId() || empty($test->database[$entityName][$entity->getId()])) {
return false;
}
unset($test->database[$entityName][$entity->getId()]);
return true;
};
$mockClass = '\\mock' . $manager['className'];
$managerMock = new $mockClass($entityManagerMock, $entityName);
$this->mockedManager[$manager['serviceName']] = $managerMock;
}
}
}
示例5: getList
/**
* @param int $limit
* @param int $lastId
*
* @return Collection|Car[]
*/
public function getList($limit, $lastId)
{
$criteria = new Criteria();
$criteria->andWhere($criteria->expr()->gt('id', $lastId));
return $this->repository->matching($criteria)->slice(0, $limit);
}
示例6: createFindForGameByTypeAndPlayerCriteria
/**
* @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;
}
示例7: apply
/**
* {@inheritdoc}
*/
public function apply(Criteria $criteria, FilterValue $value = null)
{
$expr = $this->createExpression($value);
if (null !== $expr) {
$criteria->andWhere($expr);
}
}
示例8: applyFilterSelect
/**
* Filter by select value
* @param Filter\FilterSelect $filter
* @return void
*/
public function applyFilterSelect(Filter\FilterSelect $filter)
{
foreach ($filter->getCondition() as $column => $value) {
$expr = Criteria::expr()->eq($column, $value);
$this->criteria->andWhere($expr);
}
}
示例9: 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);
}
示例10: 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;
}
示例11: findByTag
public function findByTag($tagstring)
{
$criteria = new Criteria();
$criteria->andWhere(Criteria::expr()->contains('t.name', "%" . $tagstring . "%"));
$queryBuilder = $this->_em->createQueryBuilder()->select('p')->distinct(true)->from($this->getEntityName(), "p")->leftJoin('Product\\Entity\\ProductTags', 'pt', \Doctrine\ORM\Query\Expr\Join::WITH, 'p.id = pt.idProduct')->leftJoin('Product\\Entity\\Tags', 't', \Doctrine\ORM\Query\Expr\Join::WITH, 't.id = pt.idTag')->addCriteria($criteria)->orderBy("p.creationdate", "ASC")->getQuery();
return $queryBuilder->getArrayResult();
}
示例12: findPreviousOrdersToday
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);
}
示例13: findByStatusAndBeforeUpdatedAt
/**
* 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();
}
示例14: applyAclToCriteria
/**
* Add ACL checks to Criteria
*
* @param string $className
* @param Criteria $criteria
* @param string $permission
*
* @return Criteria
*/
public function applyAclToCriteria($className, Criteria $criteria, $permission)
{
$conditionData = $this->builder->getAclConditionData($className, $permission);
if (!empty($conditionData)) {
$entityField = $value = $pathExpressionType = $organizationField = $organizationValue = $ignoreOwner = null;
list($entityField, $value, $pathExpressionType, $organizationField, $organizationValue, $ignoreOwner) = $conditionData;
if (!is_null($organizationField) && !is_null($organizationValue)) {
$criteria->andWhere(Criteria::expr()->in($organizationField, [$organizationValue]));
}
if (!$ignoreOwner && !empty($value)) {
if (!is_array($value)) {
$value = [$value];
}
$criteria->andWhere(Criteria::expr()->in($entityField, $value));
}
}
return $criteria;
}
示例15: testAndWhere
public function testAndWhere()
{
$expr = new Comparison("field", "=", "value");
$criteria = new Criteria();
$criteria->where($expr);
$expr = $criteria->getWhereExpression();
$criteria->andWhere($expr);
$where = $criteria->getWhereExpression();
$this->assertInstanceOf('Doctrine\\Common\\Collections\\Expr\\CompositeExpression', $where);
$this->assertEquals(CompositeExpression::TYPE_AND, $where->getType());
$this->assertSame(array($expr, $expr), $where->getExpressionList());
}