From 1e90e40d3a9fe2cb826b56686f23a33879418048 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 28 Jul 2009 13:47:22 -0700 Subject: Use events to generate menus, instead of having xxx_menu helpers. This is the first step towards having a simple, lightweight and unified API for module interaction. --- modules/comment/helpers/comment_event.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'modules/comment/helpers/comment_event.php') diff --git a/modules/comment/helpers/comment_event.php b/modules/comment/helpers/comment_event.php index 3850a001..614c7c65 100644 --- a/modules/comment/helpers/comment_event.php +++ b/modules/comment/helpers/comment_event.php @@ -21,4 +21,21 @@ class comment_event_Core { static function item_deleted($item) { Database::instance()->delete("comments", array("item_id" => $item->id)); } + + static function admin_menu($menu, $theme) { + $menu->get("content_menu") + ->append(Menu::factory("link") + ->id("comments") + ->label(t("Comments")) + ->url(url::site("admin/comments"))); + } + + static function photo_menu($menu, $theme) { + $menu + ->append(Menu::factory("link") + ->id("comments") + ->label(t("View comments on this item")) + ->url("#comments") + ->css_id("gCommentsLink")); + } } -- cgit v1.2.3 From 44bc74edb9ae77bfaeb70f708411026131ec12bb Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 28 Jul 2009 20:30:34 -0700 Subject: Change search callbacks to use the event system, so move them out of xxx_search helpers and into xxx_event helpers. --- modules/comment/helpers/comment_event.php | 11 ++++++++++ modules/comment/helpers/comment_search.php | 34 ------------------------------ modules/gallery/helpers/gallery_event.php | 6 ++++++ modules/gallery/helpers/gallery_search.php | 24 --------------------- modules/search/helpers/search.php | 12 ++++------- modules/tag/helpers/tag_event.php | 4 ++++ modules/tag/helpers/tag_search.php | 24 --------------------- 7 files changed, 25 insertions(+), 90 deletions(-) delete mode 100644 modules/comment/helpers/comment_search.php delete mode 100644 modules/gallery/helpers/gallery_search.php delete mode 100644 modules/tag/helpers/tag_search.php (limited to 'modules/comment/helpers/comment_event.php') diff --git a/modules/comment/helpers/comment_event.php b/modules/comment/helpers/comment_event.php index 614c7c65..0234aea9 100644 --- a/modules/comment/helpers/comment_event.php +++ b/modules/comment/helpers/comment_event.php @@ -38,4 +38,15 @@ class comment_event_Core { ->url("#comments") ->css_id("gCommentsLink")); } + + static function item_index_data($item, $data) { + foreach (Database::instance() + ->select("text") + ->from("comments") + ->where("item_id", $item->id) + ->get() + ->as_array() as $row) { + $data[] = $row->text; + } + } } diff --git a/modules/comment/helpers/comment_search.php b/modules/comment/helpers/comment_search.php deleted file mode 100644 index 29762eae..00000000 --- a/modules/comment/helpers/comment_search.php +++ /dev/null @@ -1,34 +0,0 @@ -select("text") - ->from("comments") - ->where("item_id", $item->id) - ->get() - ->as_array() as $row) { - $data[] = $row->text; - } - return join(" ", $data); - } -} diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 1cd96372..64f2a9ff 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -47,4 +47,10 @@ class gallery_event_Core { module::clear_var("gallery", "choose_default_tookit"); } } + + static function item_index_data($item, $data) { + $data[] = $item->description; + $data[] = $item->name; + $data[] = $item->title; + } } diff --git a/modules/gallery/helpers/gallery_search.php b/modules/gallery/helpers/gallery_search.php deleted file mode 100644 index 2a4029d3..00000000 --- a/modules/gallery/helpers/gallery_search.php +++ /dev/null @@ -1,24 +0,0 @@ -description, $item->name, $item->title)); - } -} diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php index b08cf89d..c03de983 100644 --- a/modules/search/helpers/search.php +++ b/modules/search/helpers/search.php @@ -64,19 +64,15 @@ class search_Core { } static function update($item) { - $data = array(); + $data = new ArrayObject(); $record = ORM::factory("search_record")->where("item_id", $item->id)->find(); if (!$record->loaded) { $record->item_id = $item->id; } - foreach (module::active() as $module) { - $class_name = "{$module->name}_search"; - if (method_exists($class_name, "item_index_data")) { - $data[] = call_user_func(array($class_name, "item_index_data"), $record->item()); - } - } - $record->data = join(" ", $data); + module::event("item_index_data", $record->item(), $data); + Kohana::log("alert",print_r($data,1)); + $record->data = join(" ", (array)$data); $record->dirty = 0; $record->save(); } diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php index f5fa6d4c..57986e40 100644 --- a/modules/tag/helpers/tag_event.php +++ b/modules/tag/helpers/tag_event.php @@ -93,4 +93,8 @@ class tag_event_Core { ->label(t("Tags")) ->url(url::site("admin/tags"))); } + + static function item_index_data($item, $data) { + $data[] = join(" ", tag::item_tags($item)); + } } diff --git a/modules/tag/helpers/tag_search.php b/modules/tag/helpers/tag_search.php deleted file mode 100644 index 034b7af5..00000000 --- a/modules/tag/helpers/tag_search.php +++ /dev/null @@ -1,24 +0,0 @@ -