本文整理汇总了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']);
}
示例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;
}
示例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']);
}
}
示例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']);
}
}
示例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;
}
示例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;
}
示例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;
}
}
}
示例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;
}
示例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;
}
示例10: findPopular
public function findPopular(Query $query, array $options)
{
$query->limit(isset($options['limit']) ? $options['limit'] : 10);
$query->order(['Hashtags.counter' => 'DESC']);
return $query;
}
示例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;
}
示例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);
}
示例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())]);
}
}
示例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);
}
示例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']);
}