本文整理汇总了PHP中Content::order_by方法的典型用法代码示例。如果您正苦于以下问题:PHP Content::order_by方法的具体用法?PHP Content::order_by怎么用?PHP Content::order_by使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Content
的用法示例。
在下文中一共展示了Content::order_by方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
//.........这里部分代码省略.........
// Make sure $neighbors is at least 2
$options['neighbors'] = max($options['neighbors'], 2);
// Make sure neighbors is even
if ($options['neighbors'] & 1 != 0) {
$options['neighbors']++;
}
$options['neighbors'] = $options['neighbors'] / 2;
$single_neighbors = false;
} else {
$options['neighbors'] = 1;
$single_neighbors = true;
}
if ($options['context'] && !in_array($original_context, array('stream', 'favorites', 'features')) && strpos($original_context, 'tag-') !== 0 && strpos($original_context, 'category-') !== 0) {
$options['in_album'] = $a;
}
$final = $content->to_array($options);
if ($options['context']) {
// TODO: Performance check
$next = new Content();
$prev = new Content();
$in_a = new Album();
$next->where('deleted', 0);
$prev->where('deleted', 0);
$options['context'] = urldecode($options['context']);
if (!in_array($original_context, array('stream', 'favorites', 'features')) && strpos($original_context, 'tag-') !== 0 && strpos($original_context, 'category-') !== 0) {
if (!isset($options['context_order'])) {
list($options['context_order'], $options['context_order_direction']) = explode(' ', $a->sort);
}
$final['context']['album'] = $a->to_array(array('auth' => $this->auth || $options['context'] === $a->internal_id));
$in_a->where("{$context_field} !=", $options['context']);
$next->where_related_album('id', $a->id);
$prev->where_related_album('id', $a->id);
if ($options['context_order'] === 'manual') {
$next->order_by_join_field('album', 'order', 'ASC')->group_start()->where_join_field('album', 'order >', $content->join_order)->or_group_start()->where_join_field('album', 'order', $content->join_order)->where_join_field('album', 'id >', $content->join_id)->group_end()->group_end();
$prev->order_by_join_field('album', 'order', 'DESC')->group_start()->where_join_field('album', 'order <', $content->join_order)->or_group_start()->where_join_field('album', 'order', $content->join_order)->where_join_field('album', 'id <', $content->join_id)->group_end()->group_end();
} else {
$next_operator = strtolower($options['context_order_direction']) === 'desc' ? '<' : '>';
$prev_operator = $next_operator === '<' ? '>' : '<';
$next->group_start()->where($options['context_order'] . " {$next_operator}", $content->{$options['context_order']})->or_group_start()->where($options['context_order'], $content->{$options['context_order']})->where("id {$next_operator}", $content->id)->group_end()->group_end();
$prev->group_start()->where($options['context_order'] . " {$prev_operator}", $content->{$options['context_order']})->or_group_start()->where($options['context_order'], $content->{$options['context_order']})->where("id {$prev_operator}", $content->id)->group_end()->group_end();
}
if (!$this->auth) {
$next->where('visibility <', $final['context']['album']['visibility'] < 1 ? 1 : 2);
$prev->where('visibility <', $final['context']['album']['visibility'] < 1 ? 1 : 2);
}
$in_album = $a;
$final['context']['type'] = 'album';
$final['context']['title'] = $a->title;
$final['context']['__koken_url'] = $final['context']['album']['__koken_url'];
$final['context']['url'] = $final['context']['album']['url'];
} else {
if (!isset($options['context_order'])) {
$options['context_order'] = 'captured_on';
$options['context_order_direction'] = 'DESC';
} else {
if ($options['context_order'] === 'manual' && $original_context === 'favorites') {
$options['context_order'] = 'favorite_order';
$options['context_order_direction'] = 'ASC';
} else {
if ($options['context_order'] === 'manual' && $original_context === 'features') {
$options['context_order'] = 'featured_order';
$options['context_order_direction'] = 'ASC';
}
}
}
$next_operator = strtolower($options['context_order_direction']) === 'desc' ? '<' : '>';
示例2: array
function apply_smart_conditions($smart_rules, $options = array(), $limit_for_preview = false)
{
$content = new Content();
$array = unserialize($smart_rules);
$conditions = $array['conditions'];
if (!empty($conditions)) {
if ($array['any_all']) {
$content->group_start();
} else {
$content->or_group_start();
}
foreach ($conditions as $c) {
if (isset($c['bool']) && !$c['bool']) {
$bool = ' NOT ';
} else {
$c['bool'] = true;
$bool = '';
}
switch ($c['type']) {
case 'album':
if (!empty($c['filter']) && is_numeric($c['filter'])) {
$content->where_related_album('id' . ($c['bool'] ? '' : '!='), $c['filter']);
}
break;
case 'tag':
if (!empty($c['input'])) {
$content->group_start();
if ($c['bool']) {
$method = 'like';
} else {
$method = 'not_like';
$content->or_group_start();
}
$content->{$method}('tags', "{$c['input']},");
if (!$c['bool']) {
$content->where('tags IS NULL');
$content->group_end();
}
if (is_numeric($c['filter'])) {
$content->where_related_album('id', $c['filter']);
}
$content->group_end();
}
break;
case 'date':
switch ($c['modifier']) {
// TODO: Time zone offsets
case 'on':
$start = strtotime($c['start'] . ' 00:00:00');
$end = strtotime($c['start'] . ' 23:59:59');
$content->where($c['column'] . "{$bool}BETWEEN {$start} AND {$end}");
break;
case 'before':
$start = strtotime($c['start'] . ' 00:00:00');
$content->group_start();
$content->where($c['column'] . ' ' . ($c['bool'] ? '<' : '>'), $start)->where($c['column'] . ' IS NOT NULL')->where($c['column'] . ' <> 0');
$content->group_end();
break;
case 'after':
$start = strtotime($c['start'] . ' 23:59:59');
$content->where($c['column'] . ' ' . ($c['bool'] ? '>' : '<'), $start);
break;
case 'between':
$start = strtotime($c['start'] . ' 00:00:00');
$end = strtotime($c['end'] . ' 23:59:59');
$content->where($c['column'] . "{$bool}BETWEEN {$start} AND {$end}");
break;
case 'within':
$end_str = date('Y-m-d') . ' 23:59:59';
$end = strtotime($end_str);
$start = strtotime($end_str . ' -' . $c['within'] . ' ' . $c['within_modifier'] . 's');
$content->where($c['column'] . ' ' . ($c['bool'] ? '>' : '<'), $start);
break;
}
break;
}
}
$content->group_end();
if (isset($array['limit_to']) && is_numeric($array['limit_to'])) {
$content->where('file_type', $array['limit_to']);
}
switch ($array['order']) {
case 'file':
// TODO: Is this enough, or do we need to use natcasesort?
$column = 'filename';
break;
default:
if ($array['order'] == 'date') {
$column = 'created_on';
} else {
$column = 'captured_on';
}
break;
}
$content->order_by($column . ' ' . $array['order_direction']);
if (isset($options['limit']) && is_numeric($array['limit'])) {
if (!$options['limit'] || $array['limit'] < $options['limit']) {
$options['limit'] = $array['limit'];
}
$options['cap'] = $array['limit'];
//.........这里部分代码省略.........
示例3: aggregate
function aggregate($type, $options = array())
{
$options = array_merge(array('featured' => false), $options);
$shared_params = array();
if ($type === 'tag') {
$shared_params['tags'] = $options['tag_slug'];
} else {
if ($type === 'category') {
$shared_params['category'] = $options['category'];
}
}
$album_params = $shared_params;
$date_marker = false;
if ($type === 'date') {
$s = new Setting();
$s->where('name', 'site_timezone')->get();
$tz = new DateTimeZone($s->value);
$offset = $tz->getOffset(new DateTime('now', new DateTimeZone('UTC')));
if ($offset === 0) {
$shift = '';
} else {
$shift = ($offset < 0 ? '-' : '+') . abs($offset);
}
// Need to - the offset here, as we need to shift this timestamp by the inverse of the offset to match DB UTC time.
// For example. Midnight in user's time (say, CT -5) is UTC+5.
$album_params['before'] = $date_marker = strtotime("{$options['year']}-{$options['month']}-{$options['day']} 23:59:59") - $offset;
}
$aggregate = $essay_ids = $album_ids = $content_ids = $updated_album_ids = $exclude_albums = $exclude_content = $sets = $range = array();
$t = new Text();
$t->select('id, featured, featured_image_id, published_on')->where('page_type', 0)->where('published', 1);
if ($type === 'date') {
$t->where("YEAR(FROM_UNIXTIME({$t->table}.published_on{$shift}))", $options['year'])->where("MONTH(FROM_UNIXTIME({$t->table}.published_on{$shift}))", $options['month'])->where("DAY(FROM_UNIXTIME({$t->table}.published_on{$shift}))", $options['day']);
} else {
if ($type === 'tag') {
$t->where_related('tag', 'id', $options['tag']);
} else {
$t->where_related('category', 'id', $options['category']);
}
}
if ($options['featured']) {
$t->where('featured', 1);
}
$t->include_related('album', 'id')->order_by($t->table . '.published_on DESC')->get_iterated();
foreach ($t as $essay) {
$essay_ids[$essay->id] = $essay->published_on;
$aggregate[] = array('type' => 'essay', 'id' => $essay->id, 'date' => $essay->published_on, 'featured' => $essay->featured);
if ($essay->album_id) {
$exclude_albums[] = $essay->album_id;
}
if (is_numeric($essay->featured_image_id)) {
$exclude_content[] = $essay->featured_image_id;
}
}
$a = new Album();
$a->select('id, featured, published_on, left_id, right_id, level')->where('visibility', 0)->where('deleted', 0)->where('total_count >', 0);
if ($type === 'date') {
$a->where("YEAR(FROM_UNIXTIME({$a->table}.published_on{$shift}))", $options['year'])->where("MONTH(FROM_UNIXTIME({$a->table}.published_on{$shift}))", $options['month'])->where("DAY(FROM_UNIXTIME({$a->table}.published_on{$shift}))", $options['day']);
} else {
if ($type === 'tag') {
$a->where_related('tag', 'id', $options['tag']);
} else {
$a->where_related('category', 'id', $options['category']);
}
}
if ($options['featured']) {
$a->where('featured', 1);
}
$a->include_related('content', 'id')->order_by($a->table . '.published_on DESC')->get_iterated();
foreach ($a as $album) {
if (is_numeric($album->content_id)) {
$exclude_content[] = $album->content_id;
}
if (!array_key_exists($album->id, $album_ids) && !in_array($album->id, $exclude_albums)) {
$album_ids[$album->id] = $album->published_on;
$aggregate[] = array('type' => 'album', 'id' => $album->id, 'date' => $album->published_on, 'featured' => $album->featured);
}
if ($album->level < 2) {
$range = array_merge($range, range($album->left_id, $album->right_id));
}
if ($album->level > 1) {
$sets[$album->id] = $album->left_id;
}
}
foreach ($sets as $id => $left) {
if (in_array($left, $range)) {
unset($album_ids[$id]);
foreach ($aggregate as $i => $info) {
if ($info['type'] === 'album' && $info['id'] == $id) {
unset($aggregate[$i]);
}
}
}
}
$c = new Content();
$c->select('id, published_on, featured');
if (!empty($exclude_content)) {
$c->where_not_in('id', $exclude_content);
}
$c->where('visibility', 0)->where('deleted', 0);
if ($type === 'date') {
//.........这里部分代码省略.........
示例4: content
function content()
{
list($params, $id) = $this->parse_params(func_get_args());
$c = new Content();
if (is_null($id)) {
$this->error('403', 'Required parameter "id" not present.');
return;
}
$options = array('order_by' => 'created_on', 'order_direction' => 'DESC', 'images_only' => false, 'videos_only' => false, 'audio_only' => false, 'page' => 1, 'limit' => false);
$options = array_merge($options, $params);
if (!is_numeric($options['limit'])) {
$options['limit'] = false;
}
if ($options['images_only']) {
$c->where('file_type', 0);
} else {
if ($options['videos_only']) {
$c->where('file_type', 1);
} else {
if ($options['audio_only']) {
$c->where('file_type', 2);
}
}
}
$c->where('created_by', $id);
$final = $c->paginate($options);
$c->order_by($options['order_by'] . ' ' . $options['order_direction']);
$data = $c->get_iterated();
if (!isset($final['per_page'])) {
$final['per_page'] = $data->result_count();
$final['total'] = $data->result_count();
}
$final['content'] = array();
foreach ($data as $content) {
$final['content'][] = $content->to_array($params);
}
$this->set_response_data($final);
}