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


PHP Content::where_in方法代码示例

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


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

示例1: index


//.........这里部分代码省略.........
                 if (is_null($id)) {
                     $this->error('403', 'Required parameter "id" not present.');
                     return;
                 } else {
                     $t = new Tag();
                     if (is_numeric($id)) {
                         $content = $c->get_by_id($id);
                         if ($c->exists()) {
                             $trash = new Trash();
                             $this->db->query("DELETE from {$trash->table} WHERE id = 'content-{$c->id}'");
                             $c->do_delete();
                         } else {
                             $this->error('404', "Content with ID: {$id} not found.");
                             return;
                         }
                     } else {
                         $is_trash = $id === 'trash';
                         if ($id === 'trash') {
                             $id = array();
                             $trash = new Trash();
                             $trash->like('id', 'content-')->select_func('REPLACE', '@id', 'content-', '', 'actual_id')->get_iterated();
                             foreach ($trash as $item) {
                                 $id[] = (int) $item->actual_id;
                             }
                         } else {
                             $id = explode(',', $id);
                         }
                         /*
                         	Multiple delete
                          	/content/n1/n2/n3
                         */
                         // Keep track of tags to --
                         $tags = array();
                         $c->where_in('id', $id);
                         $contents = $c->get_iterated();
                         $trash = new Trash();
                         foreach ($contents as $c) {
                             if ($c->exists()) {
                                 $tags = array_merge($tags, $c->tags);
                                 $this->db->query("DELETE from {$trash->table} WHERE id = 'content-{$c->id}'");
                                 $c->do_delete();
                             }
                         }
                     }
                 }
                 exit;
                 break;
         }
     }
     $c = new Content();
     if ($slug || isset($id) && strpos($id, ',') === false) {
         $options = array('context' => false, 'neighbors' => false);
         $options = array_merge($options, $params);
         $original_context = $options['context'];
         if ($options['context'] && !in_array($options['context'], array('stream', 'favorites', 'features')) && strpos($options['context'], 'tag-') !== 0 && strpos($options['context'], 'category-') !== 0) {
             if (is_numeric($options['context'])) {
                 $context_field = 'id';
             } else {
                 $context_field = 'slug';
                 $options['context'] = str_replace('slug-', '', $options['context']);
             }
             $a = new Album();
             $a->group_start()->where($context_field, $options['context'])->or_where('internal_id', $options['context'])->group_end()->get();
             $c->include_join_fields()->where_related_album('id', $a->id);
         }
         $with_token = false;
开发者ID:Caldis,项目名称:htdocs,代码行数:67,代码来源:contents.php

示例2: aggregate


//.........这里部分代码省略.........
         $c->include_related('album')->where("YEAR(FROM_UNIXTIME({$c->table}.published_on{$shift}))", $options['year'])->where("MONTH(FROM_UNIXTIME({$c->table}.published_on{$shift}))", $options['month'])->where("DAY(FROM_UNIXTIME({$c->table}.published_on{$shift}))", $options['day'])->group_start()->where($a->table . '.id', null)->or_where($a->table . '.deleted', 0)->group_end();
     } else {
         if ($type === 'tag') {
             $c->where_related('tag', 'id', $options['tag']);
         } else {
             $c->where_related('category', 'id', $options['category']);
         }
     }
     if ($options['featured']) {
         $c->where('featured', 1);
     }
     $c->order_by($c->table . '.published_on DESC')->get_iterated();
     foreach ($c as $content) {
         if ($content->album_id && $content->album_visibility < 1 && $content->album_published_on <= $date_marker) {
             if (!isset($updated_album_ids[$content->album_id])) {
                 $updated_album_ids[$content->album_id] = array('items' => array($content->id), 'date' => $content->published_on, 'featured' => $content->album_featured);
             } else {
                 $updated_album_ids[$content->album_id]['items'][] = $content->id;
                 $updated_album_ids[$content->album_id]['date'] = max($content->published_on, $updated_album_ids[$content->album_id]['date']);
             }
         } else {
             if (!$content->album_id) {
                 $content_ids[$content->id] = $content->published_on;
                 $aggregate[] = array('type' => 'content', 'id' => $content->id, 'date' => $content->published_on, 'featured' => $content->featured);
             }
         }
     }
     foreach ($updated_album_ids as $id => $a) {
         $aggregate[] = array('type' => 'updated_album', 'id' => $id, 'date' => $a['date'], 'featured' => $a['featured']);
     }
     $total = count($aggregate);
     if (!function_exists('_sort')) {
         function _sort($one, $two)
         {
             if ($one['featured'] && !$two['featured']) {
                 return -1;
             } else {
                 if ($one['featured'] && $two['featured']) {
                     return $one['date'] < $two['date'] ? 1 : -1;
                 }
             }
             return $two['featured'] || $one['date'] < $two['date'] || $one['date'] === $two['date'] && $two['id'] > $one['id'] ? 1 : -1;
         }
     }
     usort($aggregate, '_sort');
     $stream = array('page' => (int) isset($options['page']) ? (int) $options['page'] : 1, 'pages' => (int) ceil($total / $options['limit']), 'per_page' => (int) min($options['limit'], $total), 'total' => (int) $total);
     $load = array_slice($aggregate, ($stream['page'] - 1) * $options['limit'], $options['limit']);
     $counts = array('essays' => count($essay_ids), 'albums' => count($album_ids), 'content' => count($content_ids));
     $counts['total'] = $counts['essays'] + $counts['albums'] + $counts['content'];
     $updated_album_ids_arr = $updated_album_ids;
     $essay_ids = $album_ids = $content_ids = $updated_album_ids = $final = $index = array();
     foreach ($load as $i => $item) {
         $index[$item['type'] . '-' . $item['id']] = $i;
         ${$item['type'] . '_ids'}[] = $item['id'];
     }
     if (!empty($essay_ids)) {
         $e = new Text();
         $e->where_in('id', $essay_ids)->get_iterated();
         foreach ($e as $essay) {
             $final[$index['essay-' . $essay->id]] = $essay->to_array($shared_params);
         }
     }
     if (!empty($album_ids)) {
         $a = new Album();
         $a->where_in('id', $album_ids)->get_iterated();
         foreach ($a as $album) {
             $final[$index['album-' . $album->id]] = $album->to_array($album_params);
         }
     }
     if (!empty($content_ids)) {
         $c = new Content();
         $c->where_in('id', $content_ids)->get_iterated();
         foreach ($c as $content) {
             $final[$index['content-' . $content->id]] = $content->to_array(array_merge($shared_params, array('order_by' => 'published_on')));
         }
     }
     if (!empty($updated_album_ids)) {
         $a = new Album();
         $a->where_in('id', $updated_album_ids)->get_iterated();
         foreach ($a as $album) {
             $arr = $album->to_array();
             $arr['event_type'] = 'album_update';
             $arr['content'] = array();
             $info = $updated_album_ids_arr[$album->id];
             $c = new Content();
             $c->where_in('id', $info['items'])->order_by('published_on DESC')->get_iterated();
             foreach ($c as $i => $content) {
                 $carr = $content->to_array(array('order_by' => 'published_on', 'in_album' => $album));
                 if ($i === 0) {
                     $arr['date'] = $carr['date'];
                 }
                 $arr['content'][] = $carr;
             }
             $final[$index['updated_album-' . $album->id]] = $arr;
         }
     }
     ksort($final);
     $stream['items'] = array_values($final);
     return array($stream, $counts);
 }
开发者ID:Caldis,项目名称:htdocs,代码行数:101,代码来源:Koken_Controller.php

示例3: array

 function to_array($options = array())
 {
     $options = array_merge(array('with_covers' => true, 'auth' => false), $options);
     $koken_url_info = $this->config->item('koken_url_info');
     $exclude = array('deleted', 'total_count', 'video_count', 'featured_order', 'tags_old', 'old_slug');
     $dates = array('created_on', 'modified_on', 'featured_on', 'published_on');
     $strings = array('title', 'summary', 'description');
     $bools = array('featured');
     list($data, $public_fields) = $this->prepare_for_output($options, $exclude, $bools, $dates, $strings);
     if (!$options['auth'] && $data['visibility'] < 1) {
         unset($data['internal_id']);
     }
     if (!$data['featured']) {
         unset($data['featured_on']);
     }
     $sort = array();
     list($sort['by'], $sort['direction']) = explode(' ', $data['sort']);
     $data['sort'] = $sort;
     $data['__koken__'] = 'album';
     if (array_key_exists('album_type', $data)) {
         switch ($data['album_type']) {
             case 2:
                 $data['album_type'] = 'set';
                 break;
             case 1:
                 $data['album_type'] = 'smart';
                 break;
             default:
                 $data['album_type'] = 'standard';
         }
     }
     if ($this->album_type == 2) {
         $sum = new Album();
         $sum->select_sum('total_count')->select_sum('video_count')->where('right_id <', $this->right_id)->where('left_id >', $this->left_id)->where('album_type', 0)->where('visibility', 0)->get();
         $data['counts'] = array('total' => (int) $this->total_count, 'videos' => (int) $sum->video_count, 'images' => $sum->total_count - $sum->video_count);
     } else {
         $data['counts'] = array('total' => (int) $this->total_count, 'videos' => (int) $this->video_count, 'images' => $this->total_count - $this->video_count);
     }
     $data['tags'] = $this->_get_tags_for_output($options);
     $data['categories'] = array('count' => is_null($this->category_count) ? $this->categories->count() : (int) $this->category_count, 'url' => $koken_url_info->base . 'api.php?/albums/' . $data['id'] . '/categories');
     $data['topics'] = array('count' => is_null($this->text_count) ? $this->text->count() : (int) $this->text_count, 'url' => $koken_url_info->base . 'api.php?/albums/' . $data['id'] . '/topics');
     if ($options['with_covers']) {
         $data['covers'] = $existing = array();
         $covers = $this->covers;
         if (isset($options['before'])) {
             $covers->where('published_on <=', $options['before']);
             $data['__cover_hint_before'] = $options['before'];
         }
         $covers->include_related_count('albums', NULL, array('visibility' => 0));
         $covers->include_related_count('categories');
         foreach ($covers->order_by("covers_{$this->db_join_prefix}albums_covers.id ASC")->get_iterated() as $f) {
             if ($f->exists()) {
                 $data['covers'][] = $f->to_array(array('in_album' => $this));
                 $existing[] = $f->id;
             }
         }
         $covers_count_set = false;
         if ($this->album_type == 2) {
             $covers_count_set = $this->covers->count();
         }
         if ($covers_count_set !== false && $covers_count_set < 3) {
             $a = new Album();
             $ids = $a->select('id')->where('right_id <', $this->right_id)->where('left_id >', $this->left_id)->where('visibility', $this->visibility)->get_iterated();
             $id_arr = array();
             foreach ($ids as $id) {
                 $id_arr[] = $id->id;
             }
             if (!empty($id_arr)) {
                 $c = new Content();
                 $q = "SELECT DISTINCT cover_id FROM {$this->db_join_prefix}albums_covers WHERE album_id IN (" . join(',', $id_arr) . ")";
                 if (!empty($existing)) {
                     $q .= ' AND cover_id NOT IN(' . join(',', $existing) . ')';
                 }
                 $covers = $c->query($q . "GROUP BY album_id LIMIT " . (3 - $covers_count_set));
                 $f_ids = array();
                 foreach ($covers as $f) {
                     $f_ids[] = $f->cover_id;
                 }
                 if (!empty($f_ids)) {
                     $c->where_in('id', $f_ids)->get_iterated();
                     foreach ($c as $content) {
                         // TODO: auth needs to be passed in here
                         array_unshift($data['covers'], $content->to_array(array('in_album' => $this)));
                     }
                 }
             }
         }
         // Latest covers first
         $data['covers'] = array_reverse($data['covers']);
     }
     if (isset($options['order_by']) && in_array($options['order_by'], array('created_on', 'modified_on'))) {
         $data['date'] =& $data[$options['order_by']];
     } else {
         $data['date'] =& $data['published_on'];
     }
     if ($data['level'] > 1 && (!array_key_exists('include_parent', $options) || $options['include_parent'])) {
         $parent = new Album();
         $parent->where('left_id <', $data['left_id'])->where('level <', $data['level'])->where('visibility', $this->visibility)->where('deleted', 0)->order_by('left_id DESC')->limit(1)->get();
         $data['parent'] = $parent->to_array();
     } else {
//.........这里部分代码省略.........
开发者ID:Atomox,项目名称:benhelmerphotography,代码行数:101,代码来源:album.php

示例4: index

 function index()
 {
     // TODO: Make sure user is admin over content they trash
     list($params, $id) = $this->parse_params(func_get_args());
     if ($this->method != 'get') {
         $c = new Content();
         $a = new Album();
         $t = new Trash();
         $tag = new Tag();
         $options = array('content' => array(), 'albums' => array());
         $params = array_merge($options, $params);
         if (!empty($params['content'])) {
             $params['content'] = explode(',', $params['content']);
         }
         if (!empty($params['albums'])) {
             $params['albums'] = explode(',', $params['albums']);
         }
         switch ($this->method) {
             case 'post':
                 $q = array();
                 $content_ids = array();
                 $album_ids = array();
                 $now = time();
                 if (!empty($params['content'])) {
                     $content = $c->where_in('id', $params['content'])->get_iterated();
                     foreach ($content as $c) {
                         $q[] = "('content-{$c->id}', '" . $this->db->escape_str(utf8_encode(serialize($c->to_array(array('auth' => $this->auth))))) . "', {$now})";
                     }
                 }
                 if (!empty($params['albums'])) {
                     foreach ($params['albums'] as $album_id) {
                         $al = new Album();
                         $al->get_by_id($album_id);
                         if ($al->exists()) {
                             $q[] = "('album-{$al->id}', '" . $this->db->escape_str(utf8_encode(serialize($al->to_array()))) . "', {$now})";
                             $al->tree_trash();
                             foreach ($al->categories->get_iterated() as $category) {
                                 $category->update_counts('album');
                             }
                             foreach ($al->tags->get_iterated() as $tag) {
                                 $tag->update_counts('album');
                             }
                         }
                     }
                     $a->update_set_counts();
                 }
                 if (!empty($q)) {
                     $q = join(',', $q);
                     $this->db->query("INSERT INTO {$t->table} VALUES {$q} ON DUPLICATE KEY UPDATE data = VALUES(data)");
                 }
                 if (!empty($params['content'])) {
                     $c->where_in('id', $params['content'])->update('deleted', 1);
                     $albums = $a->where_in_related('content', 'id', $params['content'])->get_iterated();
                     foreach ($albums as $a) {
                         $a->update_counts();
                     }
                     $previews = $a->where_in_related('cover', 'id', $params['content'])->distinct()->get_iterated();
                     $prefix = preg_replace('/trash$/', '', $t->table);
                     $this->db->query("DELETE FROM {$prefix}join_albums_covers WHERE cover_id IN(" . join(',', $params['content']) . ")");
                     foreach ($previews as $a) {
                         $a->reset_covers();
                     }
                     foreach ($c->where_in('id', $params['content'])->get_iterated() as $content) {
                         foreach ($content->categories->get_iterated() as $category) {
                             $category->update_counts('content');
                         }
                         foreach ($content->tags->get_iterated() as $tag) {
                             $tag->update_counts('content');
                         }
                     }
                 }
                 $this->redirect('/trash');
                 break;
             case 'delete':
                 $ids = array();
                 foreach ($params['content'] as $id) {
                     $ids[] = "'content-{$id}'";
                 }
                 foreach ($params['albums'] as $id) {
                     $ids[] = "'album-{$id}'";
                 }
                 if (!empty($ids)) {
                     $ids = join(',', $ids);
                     $this->db->query("DELETE FROM {$t->table} WHERE id IN ({$ids})");
                 }
                 if (!empty($params['albums'])) {
                     foreach ($params['albums'] as $album_id) {
                         $al = new Album();
                         $al->get_by_id($album_id);
                         if ($al->exists()) {
                             $al->tree_trash_restore();
                             foreach ($al->categories->get_iterated() as $category) {
                                 $category->update_counts('album');
                             }
                             foreach ($al->tags->get_iterated() as $tag) {
                                 $tag->update_counts('album');
                             }
                         }
                     }
                     $a->update_set_counts();
//.........这里部分代码省略.........
开发者ID:Atomox,项目名称:benhelmerphotography,代码行数:101,代码来源:trashes.php

示例5: index

 function index()
 {
     // TODO: Make sure user is admin over content they fave
     list($params, $id) = $this->parse_params(func_get_args());
     if ($this->method != 'get') {
         $c = new Content();
         if ($this->method != 'put' && is_null($id)) {
             $this->error('403', 'Required parameter "id" not present.');
             return;
         }
         $tail = '';
         switch ($this->method) {
             case 'put':
                 if (isset($params['order'])) {
                     $ids = explode(',', $params['order']);
                     $new_order_map = array();
                     foreach ($ids as $key => $val) {
                         $pos = $key + 1;
                         $new_order_map[$val] = $pos;
                     }
                     $favs = $c->where('favorite', 1)->order_by('favorite_order ASC')->get_iterated();
                     foreach ($favs as $f) {
                         if (isset($new_order_map[$f->id]) && $new_order_map[$f->id] != $f->favorite_order) {
                             echo $new_order_map[$f->id];
                             $f->where('id', $f->id)->update('favorite_order', $new_order_map[$f->id]);
                         }
                     }
                 }
                 break;
             case 'post':
             case 'delete':
                 if (is_numeric($id)) {
                     $id = array($id);
                 } else {
                     $id = explode(',', $id);
                 }
                 if ($this->method == 'delete') {
                     $c->where_in('id', $id)->update(array('favorite' => 0, 'favorite_order' => null, 'favorited_on' => null));
                 } else {
                     $max = $c->select_func('max', '@favorite_order', 'max_favorite')->where('favorite', 1)->get();
                     if (!is_numeric($max->max_favorite)) {
                         $max_order = 1;
                     } else {
                         $max_order = $max->max_favorite;
                     }
                     foreach ($id as $id) {
                         $c->where('id', $id)->update(array('favorite' => 1, 'favorite_order' => $max_order++, 'favorited_on' => strtotime(gmdate('Y-m-d H:i:s'))));
                     }
                 }
                 break;
         }
         if ($this->method == 'delete') {
             exit;
         } else {
             $this->redirect('/favorites');
         }
     }
     $c2 = new Content();
     $c2->where('favorite', 1)->where('deleted', 0);
     $sort = $c2->_get_site_order('favorite');
     $options = array('order_by' => $sort['by'], 'order_direction' => $sort['direction'], 'favorite' => true);
     $params = array_merge($options, $params);
     if ($params['order_by'] === 'manual') {
         $params['order_by'] = 'favorite_order, favorited_on';
         $params['order_direction'] = 'asc';
     }
     $params['auth'] = $this->auth;
     $final = $c2->listing($params);
     $final['sort'] = $sort;
     $this->set_response_data($final);
 }
开发者ID:Atomox,项目名称:benhelmerphotography,代码行数:71,代码来源:favorites.php


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