當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Criteria::getWhereExpression方法代碼示例

本文整理匯總了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());
 }
開發者ID:Dren-x,項目名稱:mobit,代碼行數:12,代碼來源:CriteriaTest.php

示例2: testWhere

 public function testWhere()
 {
     $expr = new Comparison("field", "=", "value");
     $criteria = new Criteria();
     $criteria->where($expr);
     $this->assertSame($expr, $criteria->getWhereExpression());
 }
開發者ID:richardjh,項目名稱:zf2-addressbook,代碼行數:7,代碼來源:CriteriaTest.php

示例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));
 }
開發者ID:dominium,項目名稱:mongodb-odm,代碼行數:7,代碼來源:DocumentRepositoryTest.php

示例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;
 }
開發者ID:VadymKalin,項目名稱:crm,代碼行數:26,代碼來源:CustomerSearchApiEntityManager.php

示例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);
     }
 }
開發者ID:nmallare,項目名稱:platform,代碼行數:27,代碼來源:QueryBuilderHelper.php

示例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;
 }
開發者ID:relo-san,項目名稱:doctrine2,代碼行數:32,代碼來源:QueryBuilder.php

示例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'));
 }
開發者ID:eoko,項目名稱:odm-driver-dynamodb,代碼行數:25,代碼來源:DynamoDBDriver.php

示例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);
 }
開發者ID:eltondias,項目名稱:Relogio,代碼行數:25,代碼來源:ArrayCollection.php

示例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);
    }
開發者ID:nattaphat,項目名稱:hgis,代碼行數:19,代碼來源:BasicEntityPersister.php

示例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');
 }
開發者ID:shitikovkirill,項目名稱:zend-shop.com,代碼行數:16,代碼來源:SelectableAdapterTest.php

示例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);
 }
開發者ID:ezprit,項目名稱:JMSJobQueueBundle,代碼行數:31,代碼來源:PersistentRelatedEntitiesCollection.php

示例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());
 }
開發者ID:2ndkauboy,項目名稱:platform,代碼行數:11,代碼來源:AssociationManager.php

示例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);
 }
開發者ID:liyunfan,項目名稱:doctrine2,代碼行數:23,代碼來源:BasicEntityPersister.php

示例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);
 }
開發者ID:BozzaCoon,項目名稱:SPHERE-Framework,代碼行數:23,代碼來源:BasicEntityPersister.php

示例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);
 }
開發者ID:waltertamboer,項目名稱:doctrine-criteria-serializer,代碼行數:11,代碼來源:CriteriaSerializer.php


注:本文中的Doctrine\Common\Collections\Criteria::getWhereExpression方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。