diff --git a/3.0/modules/tag_albums/controllers/tag_albums.php b/3.0/modules/tag_albums/controllers/tag_albums.php index 49e2017b..a36f0555 100644 --- a/3.0/modules/tag_albums/controllers/tag_albums.php +++ b/3.0/modules/tag_albums/controllers/tag_albums.php @@ -18,6 +18,48 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class tag_albums_Controller extends Controller { + public function make_tag_album_cover($id, $tag_id, $album_id) { + if (!identity::active_user()->admin) { + message::error(t("You do not have sufficient privileges to do this")); + url::redirect("tag_albums/show/" . $id . "/" . $tag_id . "/" . $album_id . "/" . urlencode($item->name)); + } + + $item = ORM::factory("item", $id); + + if (($album_id > 0) && ($tag_id == 0)) { + // If we are dealing with a dynamic album, set it's thumbnail to this pics. + // Based on modules/gallery/helpers/item.php + $album_tags = ORM::factory("tags_album_id") + ->where("id", "=", $album_id) + ->find_all(); + if (count($album_tags) > 0) { + $parent = ORM::factory("item", $album_tags[0]->album_id); + $parent->album_cover_item_id = $item->id; + $parent->thumb_dirty = 1; + graphics::generate($parent); + $parent->save(); + + $grand_parent = $parent->parent(); + if ($grand_parent && access::can("edit", $grand_parent) && + $grand_parent->album_cover_item_id == null) { + item::make_album_cover($parent); + } + } + message::success(t("Made " . $item->title . " this album's cover")); + url::redirect("tag_albums/show/" . $id . "/" . $tag_id . "/" . $album_id . "/" . urlencode($item->name)); + } else { + // If setting a thumbnail for an auto-generated all tags->tag album. + $record = ORM::factory("tags_album_tag_cover")->where("tag_id", "=", $tag_id)->find(); + if (!$record->loaded()) { + $record->tag_id = $tag_id; + } + $record->photo_id = $id; + $record->save(); + message::success(t("Made " . $item->title . " this album's cover")); + url::redirect("tag_albums/show/" . $id . "/" . $tag_id . "/" . $album_id . "/" . urlencode($item->name)); + } + } + public function album($id) { // Displays a dynamic page containing items that have been // tagged with one or more tags. @@ -318,21 +360,48 @@ class tag_albums_Controller extends Controller { } // Generate an arry of "fake" items, one for each tag on the page. - // Grab thumbnails from the most recently uploaded item for each tag, if available. + // Grab thumbnails from a admin-specified photo, or the most recently + // uploaded item for each tag, if available. $children_array = Array(); foreach ($display_tags as $one_tag) { - $tag_item = ORM::factory("item") - ->viewable() - ->join("items_tags", "items.id", "items_tags.item_id") - ->where("items_tags.tag_id", "=", $one_tag->id) - ->order_by("items.id", "DESC") - ->find_all(1, 0); - $child_tag = new Tag_Albums_Item($one_tag->name, url::site("tag_albums/tag/" . $one_tag->id . "/" . $id . "/" . urlencode($one_tag->name)), "album", 0); - if (count($tag_item) > 0) { - if ($tag_item[0]->has_thumb()) { - $child_tag->set_thumb($tag_item[0]->thumb_url(), $tag_item[0]->thumb_width, $tag_item[0]->thumb_height); + $tag_thumb_url = ""; + $tag_thumb_width = ""; + $tag_thumb_height = ""; + + // Check and see if the admin specified a photo to use for this tags thumbnail. + $record = ORM::factory("tags_album_tag_cover")->where("tag_id", "=", $one_tag->id)->find(); + if ($record->loaded()) { + $tag_thumb_item = ORM::factory("item", $record->photo_id); + if ($tag_thumb_item->loaded()) { + $tag_thumb_url = $tag_thumb_item->thumb_url(); + $tag_thumb_width = $tag_thumb_item->thumb_width; + $tag_thumb_height = $tag_thumb_item->thumb_height; } } + + // If no pre-specified thumbnail was found, use the most recently uploaded photo (if available). + if ($tag_thumb_url == "") { + $tag_item = ORM::factory("item") + ->viewable() + ->join("items_tags", "items.id", "items_tags.item_id") + ->where("items_tags.tag_id", "=", $one_tag->id) + ->order_by("items.id", "DESC") + ->find_all(1, 0); + if (count($tag_item) > 0) { + if ($tag_item[0]->has_thumb()) { + $tag_thumb_url = $tag_item[0]->thumb_url(); + $tag_thumb_width = $tag_item[0]->thumb_width; + $tag_thumb_height = $tag_item[0]->thumb_height; + } + } + } + + // Create a new object to represent this virtual album, and add it to the array of objects for + // this page. + $child_tag = new Tag_Albums_Item($one_tag->name, url::site("tag_albums/tag/" . $one_tag->id . "/" . $id . "/" . urlencode($one_tag->name)), "album", 0); + if ($tag_thumb_url != "") { + $child_tag->set_thumb($tag_thumb_url, $tag_thumb_width, $tag_thumb_height); + } $children_array[] = $child_tag; } $children = new Tag_Albums_Children($children_array); diff --git a/3.0/modules/tag_albums/helpers/tag_albums_event.php b/3.0/modules/tag_albums/helpers/tag_albums_event.php index ae2d566c..73cac565 100644 --- a/3.0/modules/tag_albums/helpers/tag_albums_event.php +++ b/3.0/modules/tag_albums/helpers/tag_albums_event.php @@ -106,4 +106,19 @@ class tag_albums_event_Core { db::build()->delete("tags_album_ids")->where("album_id", "=", $item->id)->execute(); } } + + static function site_menu($menu, $theme) { + if ($item = $theme->item()) { + if ($item->is_photo()) { + if ((identity::active_user()->admin) && (isset($theme->is_tagalbum_page))) { + $menu->get("options_menu") + ->append(Menu::factory("link") + ->id("g-tag-albums-set-cover") + ->label(t("Choose as the tag album cover")) + ->css_id("g-tag-albums-set-cover") + ->url(url::site("tag_albums/make_tag_album_cover/" . $item->id . "/" . $theme->tag_id . "/" . $theme->album_id))); + } + } + } + } } diff --git a/3.0/modules/tag_albums/helpers/tag_albums_installer.php b/3.0/modules/tag_albums/helpers/tag_albums_installer.php index 43431d26..834ca1f3 100644 --- a/3.0/modules/tag_albums/helpers/tag_albums_installer.php +++ b/3.0/modules/tag_albums/helpers/tag_albums_installer.php @@ -29,6 +29,14 @@ class tag_albums_installer { KEY(`album_id`, `id`)) DEFAULT CHARSET=utf8;"); + $db->query("CREATE TABLE IF NOT EXISTS {tags_album_tag_covers} ( + `id` int(9) NOT NULL auto_increment, + `tag_id` int(9) NOT NULL, + `photo_id` int(9) NOT NULL, + PRIMARY KEY (`id`), + KEY(`tag_id`, `id`)) + DEFAULT CHARSET=utf8;"); + // Set up some default values. module::set_var("tag_albums", "tag_sort_by", "name"); module::set_var("tag_albums", "tag_sort_direction", "ASC"); @@ -43,12 +51,24 @@ class tag_albums_installer { } static function upgrade($version) { + $db = Database::instance(); if ($version == 1) { module::set_var("tag_albums", "tag_index", "default"); module::set_var("tag_albums", "tag_index_scope", "0"); module::set_var("tag_albums", "tag_index_filter", "0"); module::set_version("tag_albums", 2); } + + if ($version == 2) { + $db->query("CREATE TABLE IF NOT EXISTS {tags_album_tag_covers} ( + `id` int(9) NOT NULL auto_increment, + `tag_id` int(9) NOT NULL, + `photo_id` int(9) NOT NULL, + PRIMARY KEY (`id`), + KEY(`tag_id`, `id`)) + DEFAULT CHARSET=utf8;"); + module::set_version("tag_albums", 3); + } } static function deactivate() { diff --git a/3.0/modules/tag_albums/models/tags_album_tag_cover.php b/3.0/modules/tag_albums/models/tags_album_tag_cover.php new file mode 100644 index 00000000..ef694f2a --- /dev/null +++ b/3.0/modules/tag_albums/models/tags_album_tag_cover.php @@ -0,0 +1,21 @@ +