diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-03-04 06:25:55 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-03-04 06:25:55 +0000 |
commit | b493a534f2966e23eb0244654e8929320721da8e (patch) | |
tree | 93f239b73a197d94300620bbf821599fceda96e3 /modules/notification/helpers | |
parent | 83e12961b13d1ab1e11a60e30b335d26b1875a25 (diff) |
A variety of cleanups:
* Allow for the "movie" type in all of our text
* Try to follow the pattern of mainly only passing ORM objects
to the view and let it generate its own text (this becomes
even more important when 3rd parties want to customize notification
messages)
* Rename _send_message to be _notify_subscribers to be more acccurate
and have it explicitly take a subject in the API
* Use Item_Model::url() in the views instead of hand crafting URLs
* Reformat HTML in views
* Use $comment->author_xxx() functions instead of replicating that code
* Fix several places where we were encoding data by doing ucfirst($item->type)
with conditionals where we form the text properly. We should *never*
be showing data types to the end user! This is not localizable!
Note that this probably breaks the existing batch processing code. I
am going to redo that in a subsequent pass.
Diffstat (limited to 'modules/notification/helpers')
-rw-r--r-- | modules/notification/helpers/notification.php | 96 | ||||
-rw-r--r-- | modules/notification/helpers/notification_event.php | 4 |
2 files changed, 45 insertions, 55 deletions
diff --git a/modules/notification/helpers/notification.php b/modules/notification/helpers/notification.php index 4a644812..4d095888 100644 --- a/modules/notification/helpers/notification.php +++ b/modules/notification/helpers/notification.php @@ -84,93 +84,85 @@ class notification { static function send_item_updated($old, $new) { $body = new View("item_updated.html"); + $body->old = $old; + $body->new = $new; $body->subject = $old->is_album() ? t("Album %title updated", array("title" => $old->title)) : - t("Photo %title updated", array("title" => $old->title)); - $body->type = ucfirst($old->type); - $body->item_title = $old->title; - $body->description = $item->description; - $body->new_title = $old->title != $new->title ? $new->title : null; - $body->new_description = $old->title != $new->description ? $new->description : null; - $body->url = url::site("{$old->type}s/$old->id", "http"); - - self::_send_message($old, $body); + ($old->is_photo() ? + t("Photo %title updated", array("title" => $old->title)) + : t("Movie %title updated", array("title" => $old->title))); + + self::_notify_subscribers($old, $body, $body->subject); } static function send_item_add($item) { $body = new View("item_added.html"); - $body->subject = $item->is_album() ? + $body->item = $item; + + $parent = $item->parent(); + $subject = $item->is_album() ? t("Album %title added to %parent_title", - array("title" => $item->title, "parent_title" => $item->parent()->title)) : - t("Photo %title added to %parent_title", - array("title" => $item->title, "parent_title" => $item->parent()->title)); - $body->parent_title = $item->parent()->title; - $body->type = $item->type; - $body->item_title = $item->title; - $body->description = $item->description; - $body->url = url::site("{$item->type}s/$item->id", "http"); - - self::_send_message($item, $body); + array("title" => $item->title, "parent_title" => $parent->title)) : + ($item->is_photo() ? + t("Photo %title added to %parent_title", + array("title" => $item->title, "parent_title" => $parent->title)) + : t("Movie %title added to %parent_title", + array("title" => $item->title, "parent_title" => $parent->title))); + + self::_notify_subscribers($item, $body, $subject); } static function send_batch_add($parent_id) { $parent = ORM::factory("item", $parent_id); if ($parent->loaded) { $body = new View("batch_add.html"); - $body->subject = t("%parent_title Updated", - array("parent_title" => $parent->title)); - $body->parent_title = $parent->title; - $body->url = url::site("{$parent->type}s/$parent->id", "http"); + $body->item = $parent; - self::_send_message($parent, $body); + $subject = t("Album %title updated", array("title" => $parent->title)); + self::_notify_subscribers($parent, $body, $subject); } } static function send_item_deleted($item) { - $parent = $item->parent(); $body = new View("item_deleted.html"); - $body->subject = - $item->is_album() ? + $body->item = $item; + $parent = $item->parent(); + $subject = $item->is_album() ? t("Album %title removed from %parent_title", - array("title" => $item->title, "parent_title" => $item->parent()->title)) : - t("Photo %title removed from %parent_title", - array("title" => $item->title, "parent_title" => $item->parent()->title)); - $body->parent_title = $parent->title; - $body->type = $item->type; - $body->item_title = $item->title; - $body->url = url::site("albums/$parent->id", "http"); - - self::_send_message($item, $body); + array("title" => $item->title, "parent_title" => $parent->title)) : + ($item->is_photo() ? + t("Photo %title removed from %parent_title", + array("title" => $item->title, "parent_title" => $parent->title)) + : t("Movie %title removed from %parent_title", + array("title" => $item->title, "parent_title" => $parent->title))); + + self::_notify_subscribers($item, $body, $subject); } static function send_comment_published($comment) { - $item = $comment->item(); $body = new View("comment_published.html"); - $body->subject = $item->is_album() ? + $body->comment = $comment; + + $item = $comment->item(); + $subject = $item->is_album() ? t("A new comment was published for album %title", array("title" => $item->title)) : - t("A new comment was published for photo %title", array("title" => $item->title)); - $body->text = $comment->text; - if (!empty($comment->author_id)) { - $author = ORM::factory("user", $comment->author_id); - $body->author = empty($author->full_name) ? $author->name : $author->full_name; - } else { - $body->author = $comment->guest_name; - } - $body->url = url::site("albums/$item->id#comments", "http"); + ($item->is_photo() ? + t("A new comment was published for photo %title", array("title" => $item->title)) + : t("A new comment was published for movie %title", array("title" => $item->title))); - self::_send_message($item, $body); + self::_notify_subscribers($item, $body, $subject); } static function process_notifications() { Kohana::log("error", "processing notifications in shutdown"); } - - private static function _send_message($item, $body) { + + private static function _notify_subscribers($item, $body, $subject) { $users = self::get_subscribers($item); if (!empty($users)) { Sendmail::factory() ->to($users) - ->subject($body->subject) + ->subject($subject) ->header("Mime-Version", "1.0") ->header("Content-type", "text/html; charset=utf-8") ->message($body->render()) diff --git a/modules/notification/helpers/notification_event.php b/modules/notification/helpers/notification_event.php index df06a2f1..dde328d8 100644 --- a/modules/notification/helpers/notification_event.php +++ b/modules/notification/helpers/notification_event.php @@ -23,9 +23,7 @@ class notification_event_Core { } static function item_created($item) { - if (!batch::in_progress("add")) { - notification::send_item_add($item); - } + notification::send_item_add($item); } static function item_before_delete($item) { |