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


PHP Query::clause方法代码示例

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


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

示例1: beforeFind

 public function beforeFind(Event $event, Query $query, $options, $primary)
 {
     if ($query->clause('limit') == 1) {
         return $query;
     }
     foreach ($this->orderBy() as $field => $ord) {
         $f = $this->aliasField($field);
         $query->order([$this->aliasField($field) => $ord]);
     }
     if (!is_array($this->primaryKey())) {
         return $query;
     }
     $query->sql();
     // force evaluation of internal state/objects
     foreach ($query->clause('join') as $join) {
         if (!$this->association($join['table'])) {
             continue;
         }
         $table = TableRegistry::get($join['table']);
         $table->alias($join['alias']);
         foreach ($table->orderBy() as $field => $ord) {
             $query->order([$table->aliasField($field) => $ord]);
         }
     }
     return $query;
 }
开发者ID:pwerken,项目名称:va-void,代码行数:26,代码来源:AppTable.php

示例2: beforeFind

 public function beforeFind(Event $event, Query $query, \ArrayObject $options, $primary)
 {
     $order = $query->clause('order');
     if ($order === null || !count($order)) {
         $query->order(['Viewers.name']);
     }
 }
开发者ID:array-pop-tarts,项目名称:flimsy,代码行数:7,代码来源:ViewersTable.php

示例3: beforeFind

 public function beforeFind(Event $event, Query $query, \ArrayObject $options, $primary)
 {
     $order = $query->clause('order');
     if ($order === null || !count($order)) {
         $query->order(['Films.released DESC', 'Films.title']);
     }
 }
开发者ID:array-pop-tarts,项目名称:flimsy,代码行数:7,代码来源:FilmsTable.php

示例4: findRandom

 /**
  * "Random" find method
  * @param Query $query Query object
  * @param array $options Options
  * @return Query Query object
  */
 public function findRandom(Query $query, array $options)
 {
     $query->order('rand()');
     if (!$query->clause('limit')) {
         $query->limit(1);
     }
     return $query;
 }
开发者ID:mirko-pagliai,项目名称:me-cms,代码行数:14,代码来源:AppTable.php

示例5: findCached

 public function findCached(Query $query, array $options)
 {
     if ($conditions = $query->clause('where')) {
         $query->cache(function ($q) use($conditions) {
             return $this->table() . '-' . md5(serialize($conditions));
         });
     }
     return $query;
 }
开发者ID:gourmet,项目名称:kitchen-sink,代码行数:9,代码来源:CachedFinderTrait.php

示例6: beforeFind

 /**
  * Add default order clause to query as necessary.
  *
  * @param \Cake\Event\Event $event Event
  * @param \Cake\ORM\Query $query Query
  * @param \ArrayObject $options Options
  * @param bool $primary Boolean indicating whether it's primary query.
  * @return void
  */
 public function beforeFind(Event $event, Query $query, ArrayObject $options, $primary)
 {
     $orders = $this->_config['orders'];
     $args = [$query, $options, $primary];
     foreach ($orders as $config) {
         if (!empty($config['callback']) && call_user_func_array($config['callback'], $args) || !$query->clause('order')) {
             $query->order($config['order']);
             break;
         }
     }
 }
开发者ID:UseMuffin,项目名称:Orderly,代码行数:20,代码来源:OrderlyBehavior.php

示例7: scope

 /**
  * {@inheritDoc}
  *
  * Look for virtual columns in query's WHERE clause.
  *
  * @param \Cake\ORM\Query $query The query to scope
  * @param string|null $bundle Consider attributes only for a specific bundle
  * @return \Cake\ORM\Query The modified query object
  */
 public function scope(Query $query, $bundle = null)
 {
     $whereClause = $query->clause('where');
     if (!$whereClause) {
         return $query;
     }
     $whereClause->traverse(function (&$expression) use($bundle, $query) {
         if ($expression instanceof ExpressionInterface) {
             $expression = $this->_inspectExpression($expression, $bundle, $query);
         }
     });
     return $query;
 }
开发者ID:quickapps-plugins,项目名称:eav,代码行数:22,代码来源:WhereScope.php

示例8: beforeFind

 public function beforeFind(Event $event, Query $query, $options, $primary)
 {
     $config = $this->config();
     $tableAlias = $query->repository()->alias();
     $founded = false;
     if ($where = $query->clause('where')) {
         $where->iterateParts(function ($w) use($config, $tableAlias, &$founded) {
             $field = is_object($w) ? $w->getField() : $w;
             if ($field == $tableAlias . '.' . $config['field'] || $field == $config['field']) {
                 $founded = true;
             }
             return $w;
         });
     }
     if (!$founded) {
         $query->where(['deleted' => 0]);
     }
 }
开发者ID:st3ph,项目名称:cakephp-softdeletable,代码行数:18,代码来源:SoftDeletableBehavior.php

示例9: scope

 /**
  * {@inheritDoc}
  *
  * Look for virtual columns in query's WHERE clause.
  *
  * @param \Cake\ORM\Query $query The query to scope
  * @param string|null $bundle Consider attributes only for a specific bundle
  * @return \Cake\ORM\Query The modified query object
  */
 public function scope(Query $query, $bundle = null)
 {
     $orderClause = $query->clause('order');
     if (!$orderClause) {
         return $query;
     }
     $class = new \ReflectionClass($orderClause);
     $property = $class->getProperty('_conditions');
     $property->setAccessible(true);
     $conditions = $property->getValue($orderClause);
     foreach ($conditions as $column => $direction) {
         if (empty($column) || in_array($column, (array) $this->_table->schema()->columns()) || !in_array($column, $this->_toolbox->getAttributeNames())) {
             continue;
         }
         $conditions['(' . $this->_subQuery($column, $bundle) . ')'] = $direction;
         unset($conditions[$column]);
     }
     $property->setValue($orderClause, $conditions);
     return $query;
 }
开发者ID:quickapps-plugins,项目名称:eav,代码行数:29,代码来源:OrderScope.php

示例10: _calculateColumnMap

 /**
  * Creates a map of row keys out of the query select clause that can be
  * used to hydrate nested result sets more quickly.
  *
  * @return void
  */
 protected function _calculateColumnMap()
 {
     $map = [];
     foreach ($this->_query->clause('select') as $key => $field) {
         $key = trim($key, '"`[]');
         if (strpos($key, '__') > 0) {
             $parts = explode('__', $key, 2);
             $map[$parts[0]][$key] = $parts[1];
         } else {
             $map[$this->_defaultAlias][$key] = $key;
         }
     }
     foreach ($this->_matchingMap as $alias => $assoc) {
         if (!isset($map[$alias])) {
             continue;
         }
         $this->_matchingMapColumns[$alias] = $map[$alias];
         unset($map[$alias]);
     }
     $this->_map = $map;
 }
开发者ID:QueenCityCodeFactory,项目名称:cakephp,代码行数:27,代码来源:ResultSet.php

示例11: _traverseClause

 /**
  * Traverse over a clause to alias fields
  *
  * The objective here is to transparently prevent ambiguous field errors by
  * prefixing fields with the appropriate table alias. This method currently
  * expects to receive a where clause only.
  *
  * @param \Cake\ORM\Query $query the query to check
  * @param string $name The clause name
  * @param array $config the config to use for adding fields
  * @return bool Whether a join to the translation table is required
  */
 protected function _traverseClause(Query $query, $name = '', $config = [])
 {
     $clause = $query->clause($name);
     if (!$clause || !$clause->count()) {
         return false;
     }
     $alias = $config['hasOneAlias'];
     $fields = $this->_translationFields();
     $mainTableAlias = $config['mainTableAlias'];
     $mainTableFields = $this->_mainFields();
     $alias = $config['referenceName'];
     $joinRequired = false;
     $clause->traverse(function ($expression) use($fields, $alias, $mainTableAlias, $mainTableFields, &$joinRequired) {
         if (!$expression instanceof FieldInterface) {
             return;
         }
         $field = $expression->getField();
         if (!$field || strpos($field, '.')) {
             return;
         }
         if (in_array($field, $fields)) {
             $joinRequired = true;
             $expression->setField("{$alias}.{$field}");
             return;
         }
         if (in_array($field, $mainTableFields)) {
             $expression->setField("{$mainTableAlias}.{$field}");
         }
     });
     return $joinRequired;
 }
开发者ID:adayth,项目名称:cakephp-shadow-translate,代码行数:43,代码来源:ShadowTranslateBehavior.php

示例12: beforeFind

 /**
  * Adds order value if not already set in query.
  *
  * @param \Cake\Event\Event $event The beforeFind event that was fired.
  * @param \Cake\ORM\Query $query The query object.
  * @param \ArrayObject $options The options passed to the find method.
  *
  * @return void
  */
 public function beforeFind(Event $event, Query $query, ArrayObject $options)
 {
     if (!$query->clause('order')) {
         $query->order([$this->_table->alias() . '.' . $this->_config['order'] => 'ASC']);
     }
 }
开发者ID:lorenzo,项目名称:cakephp-sequence,代码行数:15,代码来源:SequenceBehavior.php

示例13: testContainToFieldsDefault

 /**
  * Tests that default fields for associations are added to the select clause when
  * none is specified
  *
  * @return void
  */
 public function testContainToFieldsDefault()
 {
     $contains = ['clients' => ['orders']];
     $query = new Query($this->connection, $this->table);
     $query->select()->contain($contains)->sql();
     $select = $query->clause('select');
     $expected = ['foo__id' => 'foo.id', 'clients__name' => 'clients.name', 'clients__id' => 'clients.id', 'clients__phone' => 'clients.phone', 'orders__id' => 'orders.id', 'orders__total' => 'orders.total', 'orders__placed' => 'orders.placed'];
     $expected = $this->_quoteArray($expected);
     $this->assertEquals($expected, $select);
     $contains['clients']['fields'] = ['name'];
     $query = new Query($this->connection, $this->table);
     $query->select('foo.id')->contain($contains)->sql();
     $select = $query->clause('select');
     $expected = ['foo__id' => 'foo.id', 'clients__name' => 'clients.name'];
     $expected = $this->_quoteArray($expected);
     $this->assertEquals($expected, $select);
     $contains['clients']['fields'] = [];
     $contains['clients']['orders']['fields'] = false;
     $query = new Query($this->connection, $this->table);
     $query->select()->contain($contains)->sql();
     $select = $query->clause('select');
     $expected = ['foo__id' => 'foo.id', 'clients__id' => 'clients.id', 'clients__name' => 'clients.name', 'clients__phone' => 'clients.phone'];
     $expected = $this->_quoteArray($expected);
     $this->assertEquals($expected, $select);
 }
开发者ID:alexunique0519,项目名称:Blog_Cakephp_association,代码行数:31,代码来源:EagerLoaderTest.php

示例14: getVirtualColumns

 /**
  * Gets a list of all virtual columns present in given $query's SELECT clause.
  *
  * This method will alter the given Query object removing any virtual column
  * present in its SELECT clause in order to avoid incorrect SQL statements.
  * Selected virtual columns should be fetched after query is executed using
  * mapReduce or similar.
  *
  * @param \Cake\ORM\Query $query The query object to be scoped
  * @param string|null $bundle Consider attributes only for a specific bundle
  * @return array List of virtual columns names
  */
 public function getVirtualColumns(Query $query, $bundle = null)
 {
     static $selectedVirtual = [];
     $cacheKey = md5($query->sql()) . '_' . $bundle;
     if (isset($selectedVirtual[$cacheKey])) {
         return $selectedVirtual[$cacheKey];
     }
     $selectClause = (array) $query->clause('select');
     if (empty($selectClause)) {
         $selectedVirtual[$cacheKey] = array_keys($this->_toolbox->attributes($bundle));
         return $selectedVirtual[$cacheKey];
     }
     $selectedVirtual[$cacheKey] = [];
     $virtualColumns = array_keys($this->_toolbox->attributes($bundle));
     foreach ($selectClause as $index => $column) {
         list($table, $column) = pluginSplit($column);
         if ((empty($table) || $table == $this->_table->alias()) && in_array($column, $virtualColumns)) {
             $selectedVirtual[$cacheKey][$index] = $column;
             unset($selectClause[$index]);
         }
     }
     if (empty($selectClause) && !empty($selectedVirtual[$cacheKey])) {
         $selectClause[] = $this->_table->primaryKey();
     }
     $query->select($selectClause, true);
     return $selectedVirtual[$cacheKey];
 }
开发者ID:quickapps-plugins,项目名称:eav,代码行数:39,代码来源:SelectScope.php

示例15: _appendFields

 /**
  * Helper function used to conditionally append fields to the select clause of
  * a query from the fields found in another query object.
  *
  * @param \Cake\ORM\Query $query the query that will get the fields appended to
  * @param \Cake\ORM\Query $surrogate the query having the fields to be copied from
  * @param array $options options passed to the method `attachTo`
  * @return void
  */
 protected function _appendFields($query, $surrogate, $options)
 {
     $fields = $surrogate->clause('select') ?: $options['fields'];
     $target = $this->_targetTable;
     $autoFields = $surrogate->autoFields();
     if ($query->eagerLoader()->autoFields() === false) {
         return;
     }
     if (empty($fields) && !$autoFields) {
         if ($options['includeFields'] && ($fields === null || $fields !== false)) {
             $fields = $target->schema()->columns();
         }
     }
     if ($autoFields === true) {
         $fields = array_merge((array) $fields, $target->schema()->columns());
     }
     if (!empty($fields)) {
         $query->select($query->aliasFields($fields, $target->alias()));
     }
 }
开发者ID:m1nd53t,项目名称:cakephp,代码行数:29,代码来源:Association.php


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