本文整理汇总了PHP中Album::update_counts方法的典型用法代码示例。如果您正苦于以下问题:PHP Album::update_counts方法的具体用法?PHP Album::update_counts怎么用?PHP Album::update_counts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Album
的用法示例。
在下文中一共展示了Album::update_counts方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
//.........这里部分代码省略.........
示例2: Album
function do_delete()
{
$a = new Album();
$previews = $a->where_related('cover', 'id', $this->id)->get_iterated();
foreach ($previews as $a) {
$a->reset_covers();
}
$albums = $a->where_related('content', 'id', $this->id)->get_iterated();
foreach ($albums as $a) {
$a->update_counts();
}
$this->clear_cache();
if (empty($this->storage_url)) {
$original = $this->path_to_original();
$info = pathinfo($original);
$mid = preg_replace('/\\.' . $info['extension'] . '$/', '.1600.' . $info['extension'], $original);
unlink($original);
if (file_exists($mid)) {
unlink($mid);
}
if ($this->file_type > 0 && is_dir($original . '_previews')) {
delete_files($original . '_previews', true, 1);
}
if (@rmdir(dirname($original))) {
@rmdir(dirname(dirname($original)));
}
} else {
Shutter::delete_original($this->storage_url);
if (!empty($this->storage_url_midsize)) {
Shutter::delete_original($this->storage_url_midsize);
}
}
Shutter::hook('content.delete', $this->to_array(array('auth' => true)));
$s = new Slug();
$this->db->query("DELETE FROM {$s->table} WHERE id = 'content.{$this->slug}'");
$this->delete();
}