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


PHP Query::order方法代码示例

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


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

示例1: findDistance

 /**
  * Custom finder for distance.
  *
  * Options:
  * - lat (required)
  * - lng (required)
  * - tableName
  * - distance
  *
  * @param \Cake\ORM\Query $query Query.
  * @param array $options Array of options as described above
  * @return \Cake\ORM\Query
  */
 public function findDistance(Query $query, array $options)
 {
     $options += ['tableName' => null];
     $sql = $this->distance($options['lat'], $options['lng'], null, null, $options['tableName']);
     $query->select(['distance' => $query->newExpr($sql)]);
     if (isset($options['distance'])) {
         // Some SQL versions cannot reuse the select() distance field, so we better reuse the $sql snippet
         $query->where(['(' . $sql . ') <' => $options['distance']]);
     }
     return $query->order(['distance' => 'ASC']);
 }
开发者ID:edukondaluetg,项目名称:cakephp-geo,代码行数:24,代码来源:GeocoderBehavior.php

示例2: 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

示例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: 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

示例5: 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

示例6: findTagged

 public function findTagged(Query $query, array $options)
 {
     $query->contain(['Users', 'Users.AccountParameters', 'Hashtags']);
     $query->matching('Hashtags', function ($q) use($options) {
         return $q->where(['Hashtags.name' => $options['tag_name']]);
     });
     $query->order(['Tweets.created' => 'DESC']);
     return $query;
 }
开发者ID:TituxMetal,项目名称:Twitthome-CakePHP3,代码行数:9,代码来源:TweetsTable.php

示例7: 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

示例8: findUserActivities

 /**
  * Retrieve activity records based upon user and timeframe
  * 
  * Requires the pass of the request as the options element
  * pass_params[0] is the number of days to return
  * pass_params[1] is the user, or ALL for all users
  * 
  * If there is an Auth user, and no user param is passed, 
  * the Auth user is used
  * 
  * @param Query $query
  * @param array $options
  * @return Query
  */
 public function findUserActivities(Query $query, array $options)
 {
     $session_user = $options['request']->session()->read('Auth.User.id');
     $default = [0 => 15, 1 => is_null($session_user) ? 'ALL' : $session_user];
     list($days, $user) = $options['request']->params['pass'] + $default;
     $query->order(['Activities.time_in' => 'DESC']);
     $query->contain(['Users', 'Projects', 'Tasks']);
     $query->where(['Activities.time_in >=' => new DateTime("-{$days} days")]);
     if ($user != 'ALL') {
         $query->where(['Activities.user_id' => $user]);
     }
     return $query;
 }
开发者ID:OrigamiStructures,项目名称:foldingTime,代码行数:27,代码来源:ActivitiesTable.php

示例9: scope

 /**
  * {@inheritDoc}
  */
 public function scope(Query $query, TokenInterface $token)
 {
     $fields = $this->config('fields');
     if ($token->negated() || empty($fields)) {
         return $query;
     }
     $tableAlias = $this->_table->alias();
     $fields = $this->config('fields');
     $value = strtolower($token->value());
     if (is_string($fields)) {
         $fields = [$fields];
     }
     foreach (explode(';', $value) as $segment) {
         $parts = explode(',', $segment);
         if (in_array($parts[0], $fields)) {
             $dir = empty($parts[1]) || !in_array($parts[1], ['asc', 'desc']) ? 'asc' : $parts[1];
             $query->order(["{$tableAlias}.{$parts[0]}" => $dir]);
         }
     }
     return $query;
 }
开发者ID:quickapps-plugins,项目名称:search,代码行数:24,代码来源:OrderOperator.php

示例10: findPopular

 public function findPopular(Query $query, array $options)
 {
     $query->limit(isset($options['limit']) ? $options['limit'] : 10);
     $query->order(['Hashtags.counter' => 'DESC']);
     return $query;
 }
开发者ID:TituxMetal,项目名称:Twitthome-CakePHP3,代码行数:6,代码来源:HashtagsTable.php

示例11: findDistance

 /**
  * Custom finder for distance.
  *
  * Options:
  * - lat (required)
  * - lng (required)
  * - tableName
  * - distance
  * - sort
  *
  * @param \Cake\ORM\Query $query Query.
  * @param array $options Array of options as described above
  * @return \Cake\ORM\Query
  */
 public function findDistance(Query $query, array $options)
 {
     $options += ['tableName' => null, 'sort' => true];
     $sql = $this->distanceExpr($options['lat'], $options['lng'], null, null, $options['tableName']);
     if ($query->autoFields() === null) {
         $query->autoFields(true);
     }
     $query->select(['distance' => $query->newExpr($sql)]);
     if (isset($options['distance'])) {
         // Some SQL versions cannot reuse the select() distance field, so we better reuse the $sql snippet
         $query->where(function ($exp) use($sql, $options) {
             return $exp->lt($sql, $options['distance']);
         });
     }
     if ($options['sort']) {
         $sort = $options['sort'] === true ? 'ASC' : $options['sort'];
         $query->order(['distance' => $sort]);
     }
     return $query;
 }
开发者ID:dereuromark,项目名称:cakephp-geo,代码行数:34,代码来源:GeocoderBehavior.php

示例12: findRecent

 /**
  * Finder method to get recent requests as a simple array
  *
  * @param Cake\ORM\Query $query The query
  * @param array $options The options
  * @return Query The query.
  */
 public function findRecent(Query $query, array $options)
 {
     return $query->order(['Requests.requested_at' => 'DESC'])->limit(10);
 }
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:11,代码来源:RequestsTable.php

示例13: prepareOrder

 /**
  * Prepare CakePHP order
  *
  * @param Request $request DataTable request
  */
 protected function prepareOrder(Request $request)
 {
     foreach ($request->getOrder() as $order) {
         $this->query->order([$this->table->getColumns()[$order->getColumn()]->getData() => strtoupper($order->getDir())]);
     }
 }
开发者ID:atkrad,项目名称:data-tables,代码行数:11,代码来源:CakePHP.php

示例14: findLatest

 /**
  * Find latest logs
  * @param Query $query
  * @param array $options limit default 100 record
  */
 public function findLatest(Query $query, array $options)
 {
     return $query->order(['created' => 'DESC'])->limit(isset($options['limit']) ?: 100);
 }
开发者ID:simaostephanie,项目名称:UserActivity,代码行数:9,代码来源:LogsTable.php

示例15: findDistance

 /**
  * Custom finder for distance.
  *
  * Used to be a virtual field in 2.x via setDistanceAsVirtualField()
  *
  * Options:
  * - lat (required)
  * - lng (required)
  * - tableName
  * - distance
  *
  * @param \Cake\ORM\Query $query Query.
  * @param array $options Array of options as described above
  * @return \Cake\ORM\Query
  */
 public function findDistance(Query $query, array $options)
 {
     $options += array('tableName' => null);
     $sql = $this->distance($options['lat'], $options['lng'], null, null, $options['tableName']);
     $query->select(['distance' => $query->newExpr($sql)]);
     if (isset($options['distance'])) {
         $query->where(['distance <' => $options['distance']]);
     }
     return $query->order(['distance' => 'ASC']);
 }
开发者ID:surjit,项目名称:cakephp-geo,代码行数:25,代码来源:GeocoderBehavior.php


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