本文整理匯總了PHP中Doctrine\Common\Collections\Criteria::getWhereExpression方法的典型用法代碼示例。如果您正苦於以下問題:PHP Criteria::getWhereExpression方法的具體用法?PHP Criteria::getWhereExpression怎麽用?PHP Criteria::getWhereExpression使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\Common\Collections\Criteria
的用法示例。
在下文中一共展示了Criteria::getWhereExpression方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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());
}
示例2: testWhere
public function testWhere()
{
$expr = new Comparison("field", "=", "value");
$criteria = new Criteria();
$criteria->where($expr);
$this->assertSame($expr, $criteria->getWhereExpression());
}
示例3: testMatchingAcceptsCriteriaWithNullWhereExpression
public function testMatchingAcceptsCriteriaWithNullWhereExpression()
{
$repository = $this->dm->getRepository('Documents\\User');
$criteria = new Criteria();
$this->assertNull($criteria->getWhereExpression());
$this->assertInstanceOf('Doctrine\\Common\\Collections\\Collection', $repository->matching($criteria));
}
示例4: getSearchResult
/**
* Gets search result
*
* @param int $page Page number
* @param int $limit Number of items per page
* @param string $search The search string.
* @param Criteria|null $criteria
*
* @return array
*/
public function getSearchResult($page = 1, $limit = 10, $search = '', $criteria = null)
{
$searchQuery = $this->searchIndexer->getSimpleSearchQuery($search, $this->getOffset($page, $limit), $limit, $this->getCustomerSearchAliases());
if ($criteria && ($expression = $criteria->getWhereExpression())) {
$searchQuery->getCriteria()->andWhere($expression);
}
$searchResult = $this->searchIndexer->query($searchQuery);
$result = ['result' => [], 'totalCount' => function () use($searchResult) {
return $searchResult->getRecordsCount();
}];
if ($searchResult->count() > 0) {
$customers = $this->getCustomerListQueryBuilder($searchResult)->getQuery()->getResult();
$result['result'] = $this->mergeResults($searchResult, $customers);
}
return $result;
}
示例5: addCriteria
/**
* @param QueryBuilder $qb
* @param Criteria $criteria
*/
public static function addCriteria(QueryBuilder $qb, Criteria $criteria)
{
$rootAlias = $qb->getRootAlias();
$visitor = new QueryExpressionVisitor($rootAlias);
if ($whereExpression = $criteria->getWhereExpression()) {
$qb->andWhere($visitor->dispatch($whereExpression));
foreach ($visitor->getParameters() as $parameter) {
$qb->getParameters()->add($parameter);
}
}
if ($criteria->getOrderings()) {
foreach ($criteria->getOrderings() as $sort => $order) {
$qb->addOrderBy($rootAlias . '.' . $sort, $order);
}
}
// Overwrite limits only if they was set in criteria
if (($firstResult = $criteria->getFirstResult()) !== null) {
$qb->setFirstResult($firstResult);
}
if (($maxResults = $criteria->getMaxResults()) !== null) {
$qb->setMaxResults($maxResults);
}
}
示例6: addCriteria
/**
* Add criteria to query.
* Add where expressions with AND operator.
* Add orderings.
* Override firstResult and maxResults if they set.
*
* @param Criteria $criteria
* @return QueryBuilder
*/
public function addCriteria(Criteria $criteria)
{
$visitor = new QueryExpressionVisitor();
if ($whereExpression = $criteria->getWhereExpression()) {
$this->andWhere($visitor->dispatch($whereExpression));
foreach ($visitor->getParameters() as $parameter) {
$this->parameters->add($parameter);
}
}
if ($criteria->getOrderings()) {
foreach ($criteria->getOrderings() as $sort => $order) {
$this->addOrderBy($sort, $order);
}
}
// Overwrite limits only if they was set in criteria
if (($firstResult = $criteria->getFirstResult()) !== null) {
$this->setFirstResult($firstResult);
}
if (($maxResults = $criteria->getMaxResults()) !== null) {
$this->setMaxResults($maxResults);
}
return $this;
}
示例7: findBy
/**
* @todo handle more criteria, only where can be used
* @param Criteria $criteria
* @param ClassMetadata $classMetadata
* @return array
* @internal param int $limit
*/
public function findBy(Criteria $criteria, ClassMetadata $classMetadata)
{
$expression = $criteria->getWhereExpression()->visit(new QueryBuilder(), $classMetadata);
$tokens = isset($expression['tokens']) ? $expression['tokens'] : [];
$tokens = array_map(function ($item) use($classMetadata) {
$type = $this->mapTypeField($classMetadata->getTypeOfField($item['field']));
$value = $item['value'];
if ($type === 'N') {
$value = (string) $value;
}
return [$type => $value];
}, $tokens);
$request = ['TableName' => $this->getTableName($classMetadata), 'FilterExpression' => $expression['expression'], 'ExpressionAttributeValues' => $tokens];
$result = $this->commit('scan', $request);
return array_map(function ($item) {
return $this->strategy->extract($item);
}, $result->get('Items'));
}
示例8: matching
/**
* {@inheritDoc}
*/
public function matching(Criteria $criteria)
{
$expr = $criteria->getWhereExpression();
$filtered = $this->elements;
if ($expr) {
$visitor = new ClosureExpressionVisitor();
$filter = $visitor->dispatch($expr);
$filtered = array_filter($filtered, $filter);
}
if ($orderings = $criteria->getOrderings()) {
foreach (array_reverse($orderings) as $field => $ordering) {
$next = ClosureExpressionVisitor::sortByField($field, $ordering == Criteria::DESC ? -1 : 1);
}
usort($filtered, $next);
}
$offset = $criteria->getFirstResult();
$length = $criteria->getMaxResults();
if ($offset || $length) {
$filtered = array_slice($filtered, (int) $offset, $length);
}
return new static($filtered);
}
示例9: getSelectConditionCriteriaSQL
/**
* Gets the Select Where Condition from a Criteria object.
*
* @param \Doctrine\Common\Collections\Criteria $criteria
*
* @return string
*/
protected function getSelectConditionCriteriaSQL(Criteria $criteria)
{
$expression = $criteria->getWhereExpression();
if ($expression === null) {
return '';
}
$visitor = new SqlExpressionVisitor($this, $this->class);
return $visitor->dispatch($expression);
}
示例10: testReturnsCorrectCount
/**
* @covers \DoctrineModule\Paginator\Adapter\Selectable::count
*/
public function testReturnsCorrectCount()
{
$selectable = $this->getMock('Doctrine\\Common\\Collections\\Selectable');
$expression = Criteria::expr()->eq('foo', 'bar');
$criteria = new Criteria($expression, array('baz' => Criteria::DESC), 10, 20);
$adapter = new SelectableAdapter($selectable, $criteria);
$selectable->expects($this->once())->method('matching')->with($this->callback(function (Criteria $criteria) use($expression) {
return $criteria->getWhereExpression() == $expression && array('baz' => Criteria::DESC) === $criteria->getOrderings() && null === $criteria->getFirstResult() && null === $criteria->getMaxResults();
}))->will($this->returnValue(new ArrayCollection(range(1, 101))));
$this->assertEquals(101, $adapter->count());
$this->assertSame(10, $criteria->getFirstResult(), 'Original criteria was not modified');
$this->assertSame(20, $criteria->getMaxResults(), 'Original criteria was not modified');
}
示例11: matching
/**
* Select all elements from a selectable that match the criteria and
* return a new collection containing these elements.
*
* @param Criteria $criteria
* @return Collection2
*/
public function matching(Criteria $criteria)
{
$this->initialize();
$expr = $criteria->getWhereExpression();
$filtered = $this->entities;
if ($expr) {
$visitor = new ClosureExpressionVisitor();
$filter = $visitor->dispatch($expr);
$filtered = array_filter($filtered, $filter);
}
if (null !== ($orderings = $criteria->getOrderings())) {
$next = null;
foreach (array_reverse($orderings) as $field => $ordering) {
$next = ClosureExpressionVisitor::sortByField($field, $ordering == 'DESC' ? -1 : 1, $next);
}
usort($filtered, $next);
}
$offset = $criteria->getFirstResult();
$length = $criteria->getMaxResults();
if ($offset || $length) {
$filtered = array_slice($filtered, (int) $offset, $length);
}
return new ArrayCollection($filtered);
}
示例12: cloneCriteria
/**
* Makes a clone of the given Criteria
*
* @param Criteria $criteria
*
* @return Criteria
*/
protected function cloneCriteria(Criteria $criteria)
{
return new Criteria($criteria->getWhereExpression(), $criteria->getOrderings(), $criteria->getFirstResult(), $criteria->getMaxResults());
}
示例13: exists
/**
* {@inheritdoc}
*/
public function exists($entity, Criteria $extraConditions = null)
{
$criteria = $this->class->getIdentifierValues($entity);
if (!$criteria) {
return false;
}
$alias = $this->getSQLTableAlias($this->class->name);
$sql = 'SELECT 1 ' . $this->getLockTablesSql(null) . ' WHERE ' . $this->getSelectConditionSQL($criteria);
list($params, $types) = $this->expandParameters($criteria);
if (null !== $extraConditions && null !== $extraConditions->getWhereExpression()) {
$sql .= ' AND ' . $this->getSelectConditionCriteriaSQL($extraConditions);
list($criteriaParams, $criteriaTypes) = $this->expandCriteriaParameters($extraConditions);
$params = array_merge($params, $criteriaParams);
$types = array_merge($types, $criteriaTypes);
}
if ($filterSql = $this->generateFilterConditionSQL($this->class, $alias)) {
$sql .= ' AND ' . $filterSql;
}
return (bool) $this->conn->fetchColumn($sql, $params, 0, $types);
}
示例14: expandCriteriaParameters
/**
* {@inheritdoc}
*/
public function expandCriteriaParameters(Criteria $criteria)
{
$expression = $criteria->getWhereExpression();
$sqlParams = array();
$sqlTypes = array();
if ($expression === null) {
return array($sqlParams, $sqlTypes);
}
$valueVisitor = new SqlValueVisitor();
$valueVisitor->dispatch($expression);
list($params, $types) = $valueVisitor->getParamsAndTypes();
foreach ($params as $param) {
$sqlParams = array_merge($sqlParams, $this->getValues($param));
}
foreach ($types as $type) {
list($field, $value) = $type;
$sqlTypes = array_merge($sqlTypes, $this->getTypes($field, $value, $this->class));
}
return array($sqlParams, $sqlTypes);
}
示例15: serialize
/**
* Serializes a the given criteria to a PHP serialized format.
*
* @param Criteria $criteria The criteria to serialize.
* @return string
*/
public function serialize(Criteria $criteria)
{
$structure = array('whereExpression' => $this->dispatch($criteria->getWhereExpression()), 'firstResult' => $criteria->getFirstResult(), 'maxResults' => $criteria->getMaxResults(), 'orderings' => $criteria->getOrderings());
return serialize($structure);
}