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


PHP Album::exists方法代码示例

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


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

示例1: testCreateAlbum

	/** 
	 * TC12: Create operation on Albums
	*	Test to verify that the database can save new albums
	*	The test is performed by creating an album object with the required input fields
	*	Once the test is complete no errors will appear and the album will be in the database
	*/
	public function testCreateAlbum() {
		//Create the album
		$album = new Album();

		$album['artist_id'] = $this->artist['artist_id'];
		$album['name'] = 'testalbum2';
		$album['added_by_user_id'] = 1; //SYSTEM user

		$album->save();
		
		//Verify it exist now
		$this->assertTrue($album->exists());
	}
开发者ID:prismhdd,项目名称:victorioussecret,代码行数:19,代码来源:AlbumTest.php

示例2: 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']);
//.........这里部分代码省略.........
开发者ID:Caldis,项目名称:htdocs,代码行数:101,代码来源:sites.php

示例3: 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}");
 }
开发者ID:Caldis,项目名称:htdocs,代码行数:94,代码来源:albums.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: context

 function context($params, $auth)
 {
     if (!$params['neighbors']) {
         $single_neighbors = true;
         $n = 1;
     } else {
         $single_neighbors = false;
         $n = $params['neighbors'] / 2;
     }
     $to_arr_options = array('auth' => $auth);
     if (!isset($params['context_order'])) {
         $params['context_order'] = 'left_id';
         $params['context_order_direction'] = 'ASC';
     }
     if ($params['context_order'] === 'manual') {
         $params['context_order'] = 'left_id';
     }
     $next_operator = strtolower($params['context_order_direction']) === 'asc' ? '>' : '<';
     $prev_operator = $next_operator === '>' ? '<' : '>';
     $arr = array();
     $next = new Album();
     $prev = new Album();
     if (isset($params['context']) && strpos($params['context'], 'tag-') === 0) {
         $tag = str_replace('tag-', '', urldecode($params['context']));
         $t = new Tag();
         $t->where('name', $tag)->get();
         if ($t->exists()) {
             $prev->where('deleted', 0)->where('id !=', $this->id)->where('title <', $this->title)->where_related_tag('id', $t->id)->order_by('title DESC, id DESC');
             $next->where('deleted', 0)->where('id !=', $this->id)->where('title >', $this->title)->where_related_tag('id', $t->id)->order_by('title ASC, id ASC');
             $arr['type'] = 'tag';
             $arr['title'] = $tag;
             $arr['slug'] = $tag;
             $to_arr_options['context'] = "tag-{$tag}";
             $t->model = 'tag_albums';
             $t->slug = $t->name;
             $url = $t->url();
             if ($url) {
                 list($arr['__koken_url'], $arr['url']) = $url;
             }
         }
     } else {
         if (isset($params['context']) && strpos($params['context'], 'category-') === 0) {
             $category = str_replace('category-', '', $params['context']);
             $cat = new Category();
             $cat->where('slug', $category)->get();
             if ($cat->exists()) {
                 $prev->where('deleted', 0)->where('id !=', $this->id)->where('title <', $this->title)->where_related_category('id', $cat->id)->order_by('title DESC, id DESC');
                 $next->where('deleted', 0)->where('id !=', $this->id)->where('title >', $this->title)->where_related_category('id', $cat->id)->order_by('title ASC, id ASC');
                 $arr['type'] = 'category';
                 $arr['title'] = $cat->title;
                 $arr['slug'] = $cat->slug;
                 $to_arr_options['context'] = "category-{$cat->id}";
                 $cat->model = 'category_albums';
                 $url = $cat->url();
                 if ($url) {
                     list($arr['__koken_url'], $arr['url']) = $url;
                 }
             }
         } else {
             $prev->where('deleted', 0)->where("{$params['context_order']} {$prev_operator}", $this->{$params['context_order']})->where('level', $this->level)->order_by("{$params['context_order']} " . ($prev_operator === '<' ? 'DESC' : 'ASC'));
             $next->where('deleted', 0)->where("{$params['context_order']} {$next_operator}", $this->{$params['context_order']})->where('level', $this->level)->order_by("{$params['context_order']} {$params['context_order_direction']}");
             if ($this->level > 1) {
                 $parent = new Album();
                 $parent->select('left_id,right_id')->where('left_id <', $this->left_id)->where('level <', $this->level)->where('visibility', $this->visibility)->where('deleted', 0)->order_by('left_id DESC')->limit(1)->get();
                 if ($parent->exists()) {
                     $next->where('left_id >', $parent->left_id);
                     $next->where('right_id <', $parent->right_id);
                     $prev->where('left_id >', $parent->left_id);
                     $prev->where('right_id <', $parent->right_id);
                 }
             }
         }
     }
     if (!$auth) {
         $next->where('visibility', 0);
         $prev->where('visibility', 0);
     }
     if (!$params['include_empty_neighbors']) {
         $next->where('total_count >', 0);
         $prev->where('total_count >', 0);
     }
     $max = $next->get_clone()->count();
     $min = $prev->get_clone()->count();
     $arr['total'] = $max + $min + 1;
     $arr['position'] = $min + 1;
     $pre_limit = $next_limit = $n;
     if ($min < $pre_limit) {
         $next_limit += $pre_limit - $min;
         $pre_limit = $min;
     }
     if ($max < $next_limit) {
         $pre_limit = min($min, $pre_limit + ($next_limit - $max));
         $next_limit = $max;
     }
     $arr['previous'] = array();
     $arr['next'] = array();
     if ($next_limit > 0) {
         $next->limit($next_limit)->get_iterated();
         foreach ($next as $a) {
             $arr['next'][] = $a->to_array($to_arr_options);
//.........这里部分代码省略.........
开发者ID:Atomox,项目名称:benhelmerphotography,代码行数:101,代码来源:album.php


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