From 29001ad1866cb38231f21f24d3155d90aa54cacf Mon Sep 17 00:00:00 2001 From: rWatcher Date: Sun, 16 Aug 2009 00:18:49 -0400 Subject: [PATCH] TagFaces bugfix. --- modules/tagfaces/controllers/tagfaces.php | 15 ++++++++++++++- modules/tagfaces/helpers/tagfaces_event.php | 8 ++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/modules/tagfaces/controllers/tagfaces.php b/modules/tagfaces/controllers/tagfaces.php index 6df1ee76..0a4fc4df 100644 --- a/modules/tagfaces/controllers/tagfaces.php +++ b/modules/tagfaces/controllers/tagfaces.php @@ -20,12 +20,25 @@ class tagfaces_Controller extends Controller { public function drawfaces($id) { // Generate the page that allows the user to draw boxes over a photo. - + // Make sure user has access to view and edit the photo. $item = ORM::factory("item", $id); access::required("view", $item); access::required("edit", $item); + // Make sure the item actually has tags on it. + $all_tags = ORM::factory("tag") + ->join("items_tags", "tags.id", "items_tags.tag_id") + ->where("items_tags.item_id", $id) + ->find_all(); + + // If it doesn't, display an error and direct back to the photo. + if (count($all_tags) == 0) { + message::error(t("Please add some tags first.")); + url::redirect(url::abs_site("{$item->type}s/{$item->id}")); + + } + // Create the page. $template = new Theme_View("page.html", "drawfaces"); $template->set_global("item_id", $id); diff --git a/modules/tagfaces/helpers/tagfaces_event.php b/modules/tagfaces/helpers/tagfaces_event.php index af5a6c82..1e876b8b 100644 --- a/modules/tagfaces/helpers/tagfaces_event.php +++ b/modules/tagfaces/helpers/tagfaces_event.php @@ -34,10 +34,14 @@ class tagfaces_event_Core { static function site_menu($menu, $theme) { // Create a menu option for adding face data. + if (!$theme->item()) { + return; + } + $item = $theme->item(); - if ((access::can("view", $item)) && (access::can("edit", $item))) { - if ($item->is_photo()) { + if ($item->is_photo()) { + if ((access::can("view", $item)) && (access::can("edit", $item))) { $menu->get("options_menu") ->append(Menu::factory("link") ->id("tagfaces")