Skip to content

Commit

Permalink
Change search callbacks to use the event system, so move them out of
Browse files Browse the repository at this point in the history
xxx_search helpers and into xxx_event helpers.
  • Loading branch information
bharat committed Jul 29, 2009
1 parent 1e90e40 commit 44bc74e
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 90 deletions.
11 changes: 11 additions & 0 deletions modules/comment/helpers/comment_event.php
Expand Up @@ -38,4 +38,15 @@ static function photo_menu($menu, $theme) {
->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;
}
}
}
34 changes: 0 additions & 34 deletions modules/comment/helpers/comment_search.php

This file was deleted.

6 changes: 6 additions & 0 deletions modules/gallery/helpers/gallery_event.php
Expand Up @@ -47,4 +47,10 @@ static function user_login($user) {
module::clear_var("gallery", "choose_default_tookit");
}
}

static function item_index_data($item, $data) {
$data[] = $item->description;
$data[] = $item->name;
$data[] = $item->title;
}
}
24 changes: 0 additions & 24 deletions modules/gallery/helpers/gallery_search.php

This file was deleted.

12 changes: 4 additions & 8 deletions modules/search/helpers/search.php
Expand Up @@ -64,19 +64,15 @@ static function check_index() {
}

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();
}
Expand Down
4 changes: 4 additions & 0 deletions modules/tag/helpers/tag_event.php
Expand Up @@ -93,4 +93,8 @@ static function admin_menu($menu, $theme) {
->label(t("Tags"))
->url(url::site("admin/tags")));
}

static function item_index_data($item, $data) {
$data[] = join(" ", tag::item_tags($item));
}
}
24 changes: 0 additions & 24 deletions modules/tag/helpers/tag_search.php

This file was deleted.

0 comments on commit 44bc74e

Please sign in to comment.