本文整理汇总了PHP中Album::select方法的典型用法代码示例。如果您正苦于以下问题:PHP Album::select方法的具体用法?PHP Album::select怎么用?PHP Album::select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Album
的用法示例。
在下文中一共展示了Album::select方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
//
$sortby = Input::get('sortby');
$order = Input::get('order');
$keyword = Input::get('keyword');
$option = Input::get('search_opt');
if ($sortby && $option && $keyword && $option == "fullname") {
$users = User::where('fullname', 'LIKE', "%{$keyword}%")->get();
$users_id = array();
foreach ($users as $key => $user) {
$users_id[] = $user->id;
}
$albums = Album::whereIn('user_id', $users_id)->orderBy($sortby, $order)->paginate(8);
} elseif ($sortby && $option && $keyword && $option == "title") {
$albums = Album::select('*')->where('title', 'LIKE', '%' . $keyword . '%')->orderBy($sortby, $order)->paginate(5);
} elseif ($keyword && $option == "fullname") {
$users = User::where('fullname', 'LIKE', "%{$keyword}%")->get();
$users_id = array();
foreach ($users as $key => $user) {
$users_id[] = $user->id;
}
$albums = Album::whereIn('user_id', $users_id)->paginate(8);
} elseif ($keyword && $option == "title") {
$albums = Album::select('*')->where($option, 'LIKE', '%' . $keyword . '%')->paginate(5);
} elseif ($sortby && $order) {
$albums = Album::select('*')->orderBy($sortby, $order)->paginate(8);
} else {
$albums = Album::select('*')->paginate(5);
}
return View::make('backend.album.index', compact('albums', 'sortby', 'order', 'keyword', 'option'));
}
示例2: getSearch
public function getSearch()
{
$key = Input::get('title');
$data['albums'] = Album::select('*')->where('title', 'like', '%' . $key . '%')->get();
return View::make('frontend/index')->with('data', $data);
// SELECT * FROM `images` where images.`title` LIKE '%t%' OR images.album_id IN
// (SELECT id FROM albums WHERE `title` LIKE '%t%')
}
示例3: foreach
function build_autos($items, $data, $user)
{
foreach ($items as $index => &$item) {
if (isset($item['auto'])) {
if (isset($data['urls'][$item['auto']])) {
$item['path'] = $data['urls'][$item['auto']];
} else {
if ($item['auto'] === 'set') {
$item['path'] = '';
}
}
if ($item['auto'] === 'profile') {
switch ($item['id']) {
case 'twitter':
$item['path'] = 'https://twitter.com/' . $user->twitter;
break;
default:
$item['path'] = $user->{$item['id']};
if (empty($item['path'])) {
unset($items[$index]);
continue;
}
break;
}
if (!isset($item['label']) || empty($item['label'])) {
$item['label'] = ucwords($item['id']) . ($item['id'] === 'google' ? '+' : '');
}
} else {
if ($item['auto'] === 'rss') {
$item['path'] = '/feed/' . $item['id'] . ($item['id'] === 'essay' ? 's' : '') . '/recent.rss';
if (!isset($item['label'])) {
$item['label'] = $data['url_data'][$item['id']]['plural'] . ' RSS';
}
} else {
if (preg_match('/s$/', $item['auto']) || $item['auto'] === 'timeline') {
if ($item['auto'] === 'timeline' && isset($item['year'])) {
$item['path'] .= $item['year'] . '/';
if (isset($item['month']) && $item['month'] !== false && $item['month'] !== 'any') {
$m = str_pad($item['month'], 2, '0', STR_PAD_LEFT);
$item['path'] .= $m . '/';
}
}
if (strpos($item['auto'], '_') !== false) {
foreach (array('id', 'slug', 'month', 'year', 'day') as $id) {
if ($id === 'month') {
if (!isset($item['month']) || $item['month'] === 'any' || $item['month'] === false) {
$item['month'] = '';
} else {
$item['month'] = str_pad($item['month'], 2, '0', STR_PAD_LEFT);
}
}
if ($id === 'day' && !isset($item['day'])) {
$item['day'] = '';
}
if ($id === 'slug' && !isset($item['slug']) && isset($item['id'])) {
if (strpos($item['auto'], 'tag_') === 0) {
$item['slug'] = $item['id'];
} else {
$c = new Category();
if (is_numeric($item['id'])) {
$c->select('slug')->get_by_id($item['id']);
$item['slug'] = $c->slug;
} else {
$item['slug'] = $item['id'];
}
}
}
if (isset($item[$id])) {
$item['path'] = str_replace(":{$id}", $item[$id], $item['path']);
}
}
} else {
if (!isset($item['label'])) {
$item['label'] = $data['url_data'][$item['auto'] === 'categories' ? 'category' : rtrim($item['auto'], 's')]['plural'];
}
}
} else {
if ($item['auto'] === 'home') {
if (!isset($item['label'])) {
$item['label'] = $data['url_data']['home'];
}
$item['path'] = '/home/';
} else {
if ($item['auto'] === 'album' || $item['auto'] === 'set') {
$a = new Album();
$a->select('id,slug,created_on,title');
if (is_numeric($item['id'])) {
$a->where('id', $item['id']);
} else {
$a->where('slug', $item['id'])->or_where('internal_id', $item['id']);
}
$a->get();
if (!$a->exists()) {
unset($items[$index]);
continue;
}
$item['path'] = str_replace(':id', $a->id, $item['path']);
$item['path'] = str_replace(':slug', $a->slug, $item['path']);
$item['path'] = str_replace(':year', date('Y', $a->created_on), $item['path']);
$item['path'] = str_replace(':month', date('m', $a->created_on), $item['path']);
//.........这里部分代码省略.........
示例4: covers
function covers()
{
list($params, $id) = $this->parse_params(func_get_args());
$params['auth'] = $this->auth;
// Standard add/delete cover
list($id, $content_id) = $id;
if ($this->method === 'get') {
$this->redirect("/albums/{$id}");
}
$a = new Album($id);
$c = new Content();
if (!$a->exists()) {
$this->error('404', 'Album not found.');
return;
}
$cover_count = $a->covers->count();
if ($cover_count > 50) {
$this->error('403', 'Only 50 covers can be added to any one album.');
return;
}
if ($a->album_type == 2 && $cover_count == 0) {
$subs = new Album();
$subs->select('id')->where('right_id <', $a->right_id)->where('left_id >', $a->left_id)->where('visibility', $a->visibility)->get_iterated();
$id_arr = array();
foreach ($subs as $sub) {
$id_arr[] = $sub->id;
}
if (!empty($id_arr)) {
$subc = new Content();
$covers = $subc->query("SELECT DISTINCT cover_id FROM {$a->db_join_prefix}albums_covers WHERE album_id IN (" . join(',', $id_arr) . ") GROUP BY album_id LIMIT " . (3 - $cover_count));
$f_ids = array();
foreach ($covers as $f) {
$f_ids[] = $f->cover_id;
}
if (!empty($f_ids)) {
$subc->query("SELECT id FROM {$subc->table} WHERE id IN(" . join(',', $f_ids) . ") ORDER BY FIELD(id, " . join(',', array_reverse($f_ids)) . ")");
foreach ($subc as $content) {
$a->save_cover($content);
}
}
}
}
if (is_numeric($content_id)) {
if ($this->method == 'delete') {
$c->where_related('covers', 'id', $id)->get_by_id($content_id);
} else {
if ($a->album_type == 2) {
$c->get_by_id($content_id);
} else {
$c->where_related('album', 'id', $id)->get_by_id($content_id);
}
}
if (!$c->exists()) {
$this->error('404', 'Content not found.');
return;
}
if ($this->method == 'delete') {
$a->delete_cover($c);
$a->reset_covers();
} else {
$a->delete_cover($c);
$a->save_cover($c);
}
} else {
$content_id = explode(',', $content_id);
if ($this->method == 'delete') {
$c->where_related('covers', 'id', $id)->where_in('id', $content_id)->get_iterated();
} else {
if ($a->album_type == 2) {
$c->where_in('id', $content_id)->get_iterated();
} else {
$c->where_related('album', 'id', $id)->where_in('id', $content_id)->get_iterated();
}
}
if (!$c->result_count()) {
$this->error('404', 'Content not found.');
return;
}
if ($this->method == 'delete') {
foreach ($c as $cover) {
$a->delete_cover($cover);
}
$a->reset_covers();
} else {
foreach ($c as $cover) {
$a->delete_cover($cover);
}
foreach ($content_id as $cid) {
$a->save_cover($c->get_by_id($cid));
}
}
}
$this->redirect("/albums/{$id}");
}
示例5: 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') {
//.........这里部分代码省略.........
示例6: listing
//.........这里部分代码省略.........
}
} else {
$this->group_start();
$this->like($options['search_filter'], $term, 'both');
$this->group_end();
}
} else {
$this->group_start();
$this->like('title', $term, 'both');
$this->or_like('caption', $term, 'both');
$t = new Tag();
$t->where('name', $term)->get();
if ($t->exists()) {
$this->or_where_related('tag', 'id', $t->id);
}
$this->group_end();
}
} else {
if ($options['tags'] || $options['tags_not']) {
$this->_do_tag_filtering($options);
}
}
if (!is_null($options['featured'])) {
$this->where('featured', $options['featured']);
}
if (!is_null($options['favorites'])) {
$this->where('favorite', $options['favorites']);
}
if ($options['category']) {
$this->where_related('category', 'id', $options['category']);
} else {
if ($options['category_not']) {
$cat = new Content();
$cat->select('id')->where_related('category', 'id', $options['category_not'])->get_iterated();
$cids = array();
foreach ($cat as $c) {
$cids[] = $c->id;
}
$this->where_not_in('id', $cids);
}
}
if ($options['after']) {
$this->where($options['after_column'] . ' >=', $options['after']);
}
if ($options['before']) {
$this->where($options['before_column'] . ' <=', $options['before']);
}
if ($options['visibility'] === 'album') {
$this->where('visibility <', $options['in_album']->visibility + 1);
} else {
if ($options['visibility'] !== false) {
$this->where('visibility', $options['visibility']);
}
}
if ($id) {
$sql_order = "ORDER BY FIELD(id,{$id})";
$id = explode(',', $id);
$this->where_in('id', $id);
}
if ($options['order_by'] === 'captured_on' || $options['order_by'] === 'uploaded_on' || $options['order_by'] === 'modified_on' || $options['order_by'] === 'published_on') {
$bounds_order = $options['order_by'];
} else {
$bounds_order = 'published_on';
}
$s = new Setting();
$s->where('name', 'site_timezone')->get();
示例7: 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 {
//.........这里部分代码省略.........
示例8: Slug
<?php
$s = new Slug();
$slug_count = $s->like('id', 'album.', 'after')->count();
$c = new Album();
$content_count = $c->count();
if ($slug_count < $content_count) {
$slugs = array();
$c = new Album();
foreach ($c->select('slug')->get_iterated() as $content) {
$slugs[] = "('album." . $content->slug . "')";
}
$slugs = join(', ', $slugs);
$this->db->query("INSERT INTO {$s->table}(id) VALUES {$slugs} ON DUPLICATE KEY UPDATE id=id;");
}
$done = true;
示例9: Setting
function _all($params)
{
$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);
}
$content_col = $params['content_column'];
$select = "COUNT(*) as count, YEAR(FROM_UNIXTIME({$content_col}{$shift})) as event_year";
$group = 'event_year';
$order = 'event_year DESC';
if (!$params['scope'] || $params['scope'] !== 'year') {
$select .= ", MONTH(FROM_UNIXTIME({$content_col}{$shift})) as event_month";
$group .= ',event_month';
$order .= ',event_month DESC';
}
if (!$params['limit_to'] && !$params['scope']) {
$select .= ", DAY(FROM_UNIXTIME({$content_col}{$shift})) as event_day";
$group .= ',event_day';
$order .= ',event_day DESC';
}
$a = new Album();
$c = new Content();
$t = new Text();
$c->select(str_replace($content_col, $c->table . '.' . $content_col, $select))->include_related('album', 'id')->where('visibility', 0)->where('deleted', 0);
if (!$params['limit_to']) {
$c->group_start()->where('album_id', null)->or_where($c->table . '.published_on > `' . $a->table . '`.`published_on`')->group_end();
}
$a->select(str_replace($content_col, 'published_on', $select))->where('visibility', 0)->where('deleted', 0)->where('total_count >', 0);
$t->select(str_replace($content_col, 'published_on', $select))->where('page_type', 0)->where('published', 1);
if ($params['featured']) {
$c->where('featured', 1);
$a->where('featured', 1);
$t->where('featured', 1);
}
$c->group_by($group)->order_by($order);
$t->group_by($group)->order_by($order);
$a->group_by($group)->order_by($order);
$dates = array();
if (!$params['limit_to'] || $params['limit_to'] === 'content') {
foreach ($c->get_iterated() as $content) {
if ($params['scope'] === 'year') {
$key = "{$content->event_year}";
} else {
if ($params['limit_to'] || $params['scope']) {
$key = "{$content->event_year}-{$content->event_month}";
} else {
$key = "{$content->event_year}-{$content->event_month}-{$content->event_day}";
}
}
$key = strtotime($key);
if (is_numeric($content->event_year)) {
$dates[$key] = array('year' => (int) $content->event_year, 'month' => (int) $content->event_month, 'day' => (int) $content->event_day, 'counts' => array('content' => (int) $content->count, 'albums' => 0, 'essays' => 0));
}
}
}
if (!$params['limit_to'] || $params['limit_to'] === 'albums') {
foreach ($a->get_iterated() as $album) {
if ($params['scope'] === 'year') {
$key = "{$album->event_year}";
} else {
if ($params['limit_to'] || $params['scope']) {
$key = "{$album->event_year}-{$album->event_month}";
} else {
$key = "{$album->event_year}-{$album->event_month}-{$album->event_day}";
}
}
$key = strtotime($key);
if (is_numeric($album->event_year)) {
if (!isset($dates[$key])) {
$dates[$key] = array('year' => (int) $album->event_year, 'month' => (int) $album->event_month, 'day' => (int) $album->event_day, 'counts' => array('content' => 0, 'albums' => (int) $album->count, 'essays' => 0));
} else {
$dates[$key]['counts']['albums'] = (int) $album->count;
}
}
}
}
if (!$params['limit_to'] || $params['limit_to'] === 'essays') {
foreach ($t->get_iterated() as $essay) {
if ($params['scope'] === 'year') {
$key = "{$essay->event_year}";
} else {
if ($params['limit_to'] || $params['scope']) {
$key = "{$essay->event_year}-{$essay->event_month}";
} else {
$key = "{$essay->event_year}-{$essay->event_month}-{$essay->event_day}";
}
}
$key = strtotime($key);
if (is_numeric($essay->event_year)) {
if (!isset($dates[$key])) {
$dates[$key] = array('year' => (int) $essay->event_year, 'month' => (int) $essay->event_month, 'day' => (int) $essay->event_day, 'counts' => array('content' => 0, 'albums' => 0, 'essays' => (int) $essay->count));
} else {
$dates[$key]['counts']['essays'] = (int) $essay->count;
}
}
//.........这里部分代码省略.........