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


PHP ProxyQueryInterface::addMust方法代码示例

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


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

示例1: filter

 /**
  * {@inheritdoc}
  */
 public function filter(ProxyQueryInterface $query, $alias, $field, $data)
 {
     if (!$data || !is_array($data) || !array_key_exists('type', $data) || !array_key_exists('value', $data)) {
         return;
     }
     if (is_array($data['value'])) {
         $values = array();
         foreach ($data['value'] as $v) {
             if (!in_array($v, array(BooleanType::TYPE_NO, BooleanType::TYPE_YES))) {
                 continue;
             }
             $values[] = $v == BooleanType::TYPE_YES;
         }
         if (count($values) == 0) {
             return;
         }
         $queryBuilder = new \Elastica\Query\Builder();
         $queryBuilder->fieldOpen('terms')->field($field, $values)->fieldClose();
         $query->addMust($queryBuilder);
     } else {
         if (!in_array($data['value'], array(BooleanType::TYPE_NO, BooleanType::TYPE_YES))) {
             return;
         }
         $queryBuilder = new \Elastica\Query\Builder();
         $queryBuilder->fieldOpen('term')->field($field, $data['value'] == BooleanType::TYPE_YES)->fieldClose();
         $query->addMust($queryBuilder);
     }
 }
开发者ID:Kertudex,项目名称:SonataAdminSearchBundle,代码行数:31,代码来源:BooleanFilter.php

示例2: filter

 /**
  * {@inheritdoc}
  */
 public function filter(ProxyQueryInterface $query, $alias, $field, $data)
 {
     if (!$data || !is_array($data) || !array_key_exists('type', $data) || !array_key_exists('value', $data)) {
         return;
     }
     $data['type'] = !isset($data['type']) ? ChoiceType::TYPE_CONTAINS : $data['type'];
     list($firstOperator, $secondOperator) = $this->getOperators((int) $data['type']);
     if (is_array($data['value'])) {
         if (count($data['value']) == 0) {
             return;
         }
         if (in_array('all', $data['value'], true)) {
             return;
         }
         $queryBuilder = new \Elastica\Query\Builder();
         $queryBuilder->fieldOpen($secondOperator)->field($field, Util::escapeTerm($data['value']))->fieldClose();
         if ($firstOperator == 'must') {
             $query->addMust($queryBuilder);
         } else {
             $query->addMustNot($queryBuilder);
         }
     } else {
         if ($data['value'] === '' || $data['value'] === null || $data['value'] === false || $data['value'] === 'all') {
             return;
         }
         $queryBuilder = new \Elastica\Query\Builder();
         $queryBuilder->fieldOpen($secondOperator)->field($field, Util::escapeTerm(array($data['value'])))->fieldClose();
         if ($firstOperator == 'must') {
             $query->addMust($queryBuilder);
         } else {
             $query->addMustNot($queryBuilder);
         }
     }
 }
开发者ID:Kertudex,项目名称:SonataAdminSearchBundle,代码行数:37,代码来源:ChoiceFilter.php

示例3: filter

 /**
  * {@inheritdoc}
  */
 public function filter(ProxyQueryInterface $query, $alias, $field, $data)
 {
     // check data sanity
     if (!$data || !is_array($data) || !array_key_exists('value', $data)) {
         return;
     }
     $format = array_key_exists('format', $this->getFieldOptions()) ? $this->getFieldOptions()['format'] : 'c';
     $queryBuilder = new \Elastica\Query\Builder();
     if ($this->range) {
         // additional data check for ranged items
         if (!array_key_exists('start', $data['value']) || !array_key_exists('end', $data['value'])) {
             return;
         }
         if (!$data['value']['start'] || !$data['value']['end']) {
             return;
         }
         // transform types
         if ($this->getOption('input_type') == 'timestamp') {
             $data['value']['start'] = $data['value']['start'] instanceof \DateTime ? $data['value']['start']->getTimestamp() : 0;
             $data['value']['end'] = $data['value']['end'] instanceof \DateTime ? $data['value']['end']->getTimestamp() : 0;
         }
         // default type for range filter
         $data['type'] = !isset($data['type']) || !is_numeric($data['type']) ? DateRangeType::TYPE_BETWEEN : $data['type'];
         $queryBuilder->fieldOpen('range')->fieldOpen($field)->field('gte', $data['value']['start']->format($format))->field('lte', $data['value']['end']->format($format))->fieldClose()->fieldClose();
         if ($data['type'] == DateRangeType::TYPE_NOT_BETWEEN) {
             $query->addMustNot($queryBuilder);
         } else {
             $query->addMust($queryBuilder);
         }
     } else {
         if (!$data['value']) {
             return;
         }
         // default type for simple filter
         $data['type'] = !isset($data['type']) || !is_numeric($data['type']) ? DateType::TYPE_GREATER_EQUAL : $data['type'];
         // just find an operator and apply query
         $operator = $this->getOperator($data['type']);
         // transform types
         if ($this->getOption('input_type') == 'timestamp') {
             $data['value'] = $data['value'] instanceof \DateTime ? $data['value']->getTimestamp() : 0;
         }
         // null / not null only check for col
         if (in_array($operator, array('missing', 'exists'))) {
             $queryBuilder->fieldOpen($operator)->field('field', $field)->fieldClose();
         } elseif ($operator == '=') {
             $queryBuilder->fieldOpen('range')->fieldOpen($field)->field('gte', $data['value']->format($format))->field('lte', $data['value']->format($format))->fieldClose()->fieldClose();
         } else {
             $queryBuilder->fieldOpen('range')->fieldOpen($field)->field($operator, $data['value']->format($format))->fieldClose()->fieldClose();
         }
         $query->addMust($queryBuilder);
     }
 }
开发者ID:Kertudex,项目名称:SonataAdminSearchBundle,代码行数:55,代码来源:AbstractDateFilter.php

示例4: filter

 /**
  * {@inheritdoc}
  */
 public function filter(ProxyQueryInterface $query, $alias, $field, $data)
 {
     if (!$data || !is_array($data) || !array_key_exists('value', $data) || !is_numeric($data['value'])) {
         return;
     }
     $type = isset($data['type']) ? $data['type'] : false;
     $operator = $this->getOperator($type);
     $queryBuilder = new \Elastica\Query\Builder();
     if ($operator === false) {
         // Match query to get equality
         $queryBuilder->fieldOpen('match')->field($field, $data['value'])->fieldClose();
     } else {
         // Range query
         $queryBuilder->range()->fieldOpen($field)->field($operator, $data['value'])->fieldClose()->rangeClose();
     }
     $query->addMust($queryBuilder);
 }
开发者ID:Kertudex,项目名称:SonataAdminSearchBundle,代码行数:20,代码来源:NumberFilter.php

示例5: filter

 /**
  * {@inheritdoc}
  */
 public function filter(ProxyQueryInterface $query, $alias, $field, $data)
 {
     if (!$data || !is_array($data) || !array_key_exists('value', $data)) {
         return;
     }
     $data['value'] = trim($data['value']);
     if (strlen($data['value']) == 0) {
         return;
     }
     $data['type'] = !isset($data['type']) ? ChoiceType::TYPE_CONTAINS : $data['type'];
     list($firstOperator, $secondOperator) = $this->getOperators((int) $data['type']);
     // Create a query that match terms (indepedent of terms order) or a phrase
     $queryBuilder = new \Elastica\Query\Builder();
     $queryBuilder->fieldOpen($secondOperator)->fieldOpen($field)->field('query', str_replace(array('\\', '"'), array('\\\\', '\\"'), $data['value']))->field('operator', 'and')->fieldClose()->fieldClose();
     if ($firstOperator == 'must') {
         $query->addMust($queryBuilder);
     } else {
         $query->addMustNot($queryBuilder);
     }
 }
开发者ID:Kertudex,项目名称:SonataAdminSearchBundle,代码行数:23,代码来源:StringFilter.php


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