当前位置: 首页>>代码示例>>PHP>>正文


PHP QueryBuilder::expr方法代码示例

本文整理汇总了PHP中Doctrine\ORM\QueryBuilder::expr方法的典型用法代码示例。如果您正苦于以下问题:PHP QueryBuilder::expr方法的具体用法?PHP QueryBuilder::expr怎么用?PHP QueryBuilder::expr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\ORM\QueryBuilder的用法示例。


在下文中一共展示了QueryBuilder::expr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: buildIdsCondition

 /**
  * @param array        $ids
  * @param QueryBuilder $qbr
  * @return Query\Expr\Comparison|Query\Expr\Orx
  */
 private function buildIdsCondition(array $ids, QueryBuilder $qbr)
 {
     $cond = $qbr->expr()->eq(1, 0);
     foreach ($ids as $row) {
         $cond = $qbr->expr()->orX($cond, sprintf('%s.id=\'%s\'', static::TABLE_ALIAS, (string) $row));
     }
     return $cond;
 }
开发者ID:Werkint,项目名称:QueryBundle,代码行数:13,代码来源:AbstractDoctrineHandler.php

示例2: expr

 /**
  * {@inheritdoc}
  */
 public function expr()
 {
     if ($this->expressionBuilder === null) {
         $this->expressionBuilder = new OrmExpressionBuilder($this->qb->expr());
     }
     return $this->expressionBuilder;
 }
开发者ID:xamin123,项目名称:platform,代码行数:10,代码来源:OrmFilterDatasourceAdapter.php

示例3: matchOperator

 /**
  * @param QueryBuilder $qb
  * @param string $field
  * @param string $operator
  * @param string $value
  * @param int $i
  *
  * @throws WebServerLogException
  *
  * @return \Doctrine\ORM\Query\Expr\Andx|\Doctrine\ORM\Query\Expr\Comparison|\Doctrine\ORM\Query\Expr\Func
  */
 private function matchOperator(QueryBuilder $qb, $field, $operator, $value, $i = 0)
 {
     // TODO expose operators logic into methods, or use appropriate design pattern
     switch ($operator) {
         case 'eq':
         case 'gt':
         case 'lt':
             $placeholder = ':' . $this->fieldName . '_' . $i;
             $qb->setParameter($placeholder, $value);
             return $qb->expr()->{$operator}($field, $placeholder);
         case 'regex':
             $placeholder = ':regexp_' . $this->fieldName . '_' . $i;
             $qb->setParameter($placeholder, $value);
             return $qb->expr()->andX("REGEXP({$field}, {$placeholder}) = true");
         case 'like':
             $placeholder = ':like_' . $this->fieldName . '_' . $i;
             $qb->setParameter($placeholder, '%' . $value . '%');
             return $qb->expr()->like($field, $placeholder);
         case 'between':
             list($from, $to) = explode(',', $value);
             $qb->setParameter('from_' . $i, $from);
             $qb->setParameter('to_' . $i, $to);
             return $qb->expr()->between($field, ':from_' . $i, ':to_' . $i);
         default:
             throw WebServerLogException::unknownFilterOperator($operator);
     }
 }
开发者ID:warlock39,项目名称:webserverlog,代码行数:38,代码来源:Filter.php

示例4: filters

 public function filters(QueryBuilder $qb, $key, $val)
 {
     switch ($key) {
         case 'history':
             if ($val) {
                 $orx = $qb->expr()->orX();
                 $orx->add('s.fk = :fk');
                 $orx->add('t.fk = :fk');
                 $qb->andWhere($orx);
                 $qb->setParameter('fk', intval($val));
             }
             break;
         case 'class':
             $orx = $qb->expr()->orX();
             $orx->add('s.class = :class');
             $orx->add('t.class = :class');
             $qb->andWhere($orx);
             $qb->setParameter('class', $val);
             break;
         case 'blamed':
             if ($val === 'null') {
                 $qb->andWhere($qb->expr()->isNull('a.blame'));
             } else {
                 // this allows us to safely ignore empty values
                 // otherwise if $qb is not changed, it would add where the string is empty statement.
                 $qb->andWhere($qb->expr()->eq('b.fk', ':blame'));
                 $qb->setParameter('blame', $val);
             }
             break;
         default:
             // if user attemps to filter by other fields, we restrict it
             throw new \Exception("filter not allowed");
     }
 }
开发者ID:vaidasif,项目名称:symfony-force,代码行数:34,代码来源:AuditController.php

示例5: buildCount

 public function buildCount(QueryBuilder $queryBuilder) : Query
 {
     if (!empty($this->name)) {
         $queryBuilder->where($queryBuilder->expr()->like('o.name.name', ':name'))->setParameter('name', '%' . $this->name . '%');
     }
     return $queryBuilder->select($queryBuilder->expr()->count('o.id'))->from(Organization::class, 'o')->leftJoin('o.organizationMembers', 'om')->leftJoin('o.owners', 'ow')->andWhere($queryBuilder->expr()->orX($queryBuilder->expr()->eq('om.userId', ':userId'), $queryBuilder->expr()->eq('ow.userId', ':userId')))->setParameter('userId', $this->userId->id())->getQuery();
 }
开发者ID:kreta,项目名称:kreta,代码行数:7,代码来源:DoctrineORMNameFilterableSpecification.php

示例6: attachCriteriaToQueryBuilder

 /**
  * @param QueryBuilder $qb
  * @param array $criteria
  * @param array $orderBy
  * @param int $limit
  * @param int $offset
  *
  * @return QueryBuilder
  */
 protected function attachCriteriaToQueryBuilder(QueryBuilder $qb, $criteria, $orderBy, $limit, $offset)
 {
     if (array_key_exists('alerts', $criteria)) {
         $ids = is_array($criteria['alerts']) ? $criteria['alerts'] : [$criteria['alerts']];
         $qb->join('x.alerts', 'al');
         $qb->andWhere($qb->expr()->in('al.id', ':alerts'));
         $qb->setParameter(':alerts', $ids);
     }
     //cleanup all the possible relationship filters
     unset($criteria['alerts']);
     if (count($criteria)) {
         foreach ($criteria as $key => $value) {
             $values = is_array($value) ? $value : [$value];
             $qb->andWhere($qb->expr()->in("x.{$key}", ":{$key}"));
             $qb->setParameter(":{$key}", $values);
         }
     }
     if (empty($orderBy)) {
         $orderBy = ['id' => 'ASC'];
     }
     if (is_array($orderBy)) {
         foreach ($orderBy as $sort => $order) {
             $qb->addOrderBy('x.' . $sort, $order);
         }
     }
     if ($offset) {
         $qb->setFirstResult($offset);
     }
     if ($limit) {
         $qb->setMaxResults($limit);
     }
     return $qb;
 }
开发者ID:stopfstedt,项目名称:ilios,代码行数:42,代码来源:AlertChangeTypeRepository.php

示例7: extendQueryWhereId

 /**
  * Extend a query with a where constraint on the id of an entity.
  *
  * @param QueryBuilder     $queryBuilder
  * @param mixed            $id
  * @param EntityInterface  $entity
  * @param bool             $standalone
  * @param \ReflectionClass $entityClass
  *
  * @throws \RuntimeException
  */
 public static function extendQueryWhereId(QueryBuilder $queryBuilder, EntityInterface $entity, $standalone = false, \ReflectionClass $entityClass = null)
 {
     /** @var EntityAccessor $entityAccessor */
     $entityAccessor = $GLOBALS['container']['doctrine.orm.entityAccessor'];
     if (!$entityClass) {
         $entityClass = new \ReflectionClass($entity);
     }
     if ($entityClass->isSubclassOf('Contao\\Doctrine\\ORM\\EntityInterface')) {
         $keys = $entityClass->getMethod('entityPrimaryKeyNames')->invoke(null);
     } else {
         $keys = array('id');
     }
     foreach ($keys as $index => $key) {
         $value = $entityAccessor->getProperty($entity, $key);
         if ($value !== null) {
             $where = $queryBuilder->expr()->neq('e.' . $key, ':key' . $index);
             $queryBuilder->setParameter(':key' . $index, $value);
         } else {
             $where = $queryBuilder->expr()->isNotNull('e.' . $key);
         }
         if ($index > 0 || !$standalone) {
             $queryBuilder->andWhere($where);
         } else {
             $queryBuilder->where($where);
         }
     }
 }
开发者ID:bit3,项目名称:contao-doctrine-orm,代码行数:38,代码来源:Helper.php

示例8: whereRootFieldEq

 /**
  * @param string $column
  * @param mixed  $value
  * @return void
  */
 public function whereRootFieldEq($column, $value)
 {
     $qualified = $this->aliases->get($this->getRootId()) . '.' . $column;
     $param = ':' . $this->aliases->get($this->getRootId()) . $column;
     $this->builder->andWhere($this->builder->expr()->eq($qualified, $param));
     $this->builder->setParameter($param, $value);
 }
开发者ID:vend,项目名称:doxport,代码行数:12,代码来源:JoinWalk.php

示例9: attachCriteriaToQueryBuilder

 /**
  * @param QueryBuilder $qb
  * @param array $criteria
  * @param array $orderBy
  * @param int $limit
  * @param int $offset
  *
  * @return QueryBuilder
  */
 protected function attachCriteriaToQueryBuilder(QueryBuilder $qb, $criteria, $orderBy, $limit, $offset)
 {
     if (array_key_exists('courses', $criteria)) {
         $ids = is_array($criteria['courses']) ? $criteria['courses'] : [$criteria['courses']];
         $qb->join('p.programYears', 'c_programYear');
         $qb->join('c_programYear.cohort', 'c_cohort');
         $qb->join('c_cohort.courses', 'c_course');
         $qb->andWhere($qb->expr()->in('c_course.id', ':courses'));
         $qb->setParameter(':courses', $ids);
     }
     if (array_key_exists('sessions', $criteria)) {
         $ids = is_array($criteria['sessions']) ? $criteria['sessions'] : [$criteria['sessions']];
         $qb->join('p.programYears', 'se_programYear');
         $qb->join('se_programYear.cohort', 'se_cohort');
         $qb->join('se_cohort.courses', 'se_course');
         $qb->join('se_course.sessions', 'se_session');
         $qb->andWhere($qb->expr()->in('se_session.id', ':sessions'));
         $qb->setParameter(':sessions', $ids);
     }
     if (array_key_exists('terms', $criteria)) {
         $ids = is_array($criteria['terms']) ? $criteria['terms'] : [$criteria['terms']];
         $qb->join('p.programYears', 't_programYear');
         $qb->join('t_programYear.terms', 't_term');
         $qb->andWhere($qb->expr()->in('t_term.id', ':terms'));
         $qb->setParameter(':terms', $ids);
     }
     if (array_key_exists('schools', $criteria)) {
         $ids = is_array($criteria['schools']) ? $criteria['schools'] : [$criteria['schools']];
         $qb->join('p.school', 'sc_school');
         $qb->andWhere($qb->expr()->in('sc_school.id', ':schools'));
         $qb->setParameter(':schools', $ids);
     }
     unset($criteria['schools']);
     unset($criteria['courses']);
     unset($criteria['sessions']);
     unset($criteria['terms']);
     if (count($criteria)) {
         foreach ($criteria as $key => $value) {
             $values = is_array($value) ? $value : [$value];
             $qb->andWhere($qb->expr()->in("p.{$key}", ":{$key}"));
             $qb->setParameter(":{$key}", $values);
         }
     }
     if (empty($orderBy)) {
         $orderBy = ['id' => 'ASC'];
     }
     if (is_array($orderBy)) {
         foreach ($orderBy as $sort => $order) {
             $qb->addOrderBy('p.' . $sort, $order);
         }
     }
     if ($offset) {
         $qb->setFirstResult($offset);
     }
     if ($limit) {
         $qb->setMaxResults($limit);
     }
     return $qb;
 }
开发者ID:stopfstedt,项目名称:ilios,代码行数:68,代码来源:ProgramRepository.php

示例10: convert

 /**
  * Convert an array of ID's to Doctrine entities / arrays
  *
  * @param  array $data
  * @return array
  */
 public function convert($data)
 {
     if (empty($data)) {
         return array();
     }
     $this->qb->andWhere($this->qb->expr()->in($this->searchfield, $data));
     return $this->qb->getQuery()->getResult();
 }
开发者ID:outeredge,项目名称:edge-zf2,代码行数:14,代码来源:IdToResultConverter.php

示例11: applyCriteria

 protected function applyCriteria(QueryBuilder $queryBuilder, array $criteria = null)
 {
     if (isset($criteria['groups'])) {
         $queryBuilder->innerJoin($this->getAlias() . '.machine', 'm', 'WITH', $this->getAlias() . '.machine = m.id')->innerJoin('m.groups', 'g', 'WITH', $queryBuilder->expr()->andX($queryBuilder->expr()->in('g.id', $criteria['groups'])));
         unset($criteria['groups']);
     }
     parent::applyCriteria($queryBuilder, $criteria);
 }
开发者ID:Onneil,项目名称:dedipanel,代码行数:8,代码来源:MachineRelatedRepository.php

示例12: addQueryTranslationSupport

 /**
  * @param QueryBuilder $query
  * @param $source
  * @param $locale
  * @param bool $resetJoin
  */
 public function addQueryTranslationSupport(QueryBuilder $query, $source, $locale, $resetJoin = true)
 {
     if ($resetJoin) {
         $query->resetDQLPart('join');
     }
     $query->leftJoin($source->getTableAlias() . '.translations', '_translations', 'WITH', $query->expr()->orX($query->expr()->eq('_translations.locale', ':locale'), $query->expr()->isNull('_translations.id')));
     $query->setParameter('locale', $locale);
 }
开发者ID:pmdc,项目名称:UnifikSystemBundle,代码行数:14,代码来源:DatagridBridge.php

示例13: addQueryFilter

 private function addQueryFilter(QueryBuilder $query, $filter)
 {
     $expr = $query->expr();
     /*$query->orWhere($expr->eq('entity.id', ':filter_int'));*/
     $query->andWhere($query->expr()->orX($expr->like('entity.code', ':filter_str'), $expr->like('entity.manufacturer', ':filter_str'), $expr->like('entity.model', ':filter_str')));
     /*$query->setParameter('filter_int', $filter);*/
     $query->setParameter('filter_str', '%' . $filter . '%');
     return $query;
 }
开发者ID:EPICUB,项目名称:R2RioBundle,代码行数:9,代码来源:R2SearchAircraftRepository.php

示例14: setUp

 public function setUp()
 {
     $entityManager = $this->getMockForAbstractClass(EntityManagerInterface::class);
     $expressionBuilder = new Expr();
     $entityManager->expects($this->any())->method('getExpressionBuilder')->willReturn($expressionBuilder);
     $this->queryBuilder = new QueryBuilder($entityManager);
     /** \Doctrine\ORM\Query\Expr */
     $expression = $this->queryBuilder->expr();
     $this->userSpecificationFactory = new UserSpecificationFactory($expression);
 }
开发者ID:gidman,项目名称:nexode-specification,代码行数:10,代码来源:SimpleSpecTest.php

示例15: prepareEmailCondition

 protected function prepareEmailCondition(QueryBuilder $qb, PropertyEmailInterface $condition, $alias)
 {
     if ($condition->getEmail()) {
         $qb->andWhere($qb->expr()->eq($alias . '.email', ':email'))->setParameter('email', $condition->getEmail());
     } else {
         if ($condition->getEmailNotSpecified()) {
             $qb->andWhere($qb->expr()->isNull($alias . '.email'));
         }
     }
 }
开发者ID:Exanrus,项目名称:crm-bundle,代码行数:10,代码来源:PrepareEmailTrait.php


注:本文中的Doctrine\ORM\QueryBuilder::expr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。