summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-02-02 03:09:17 +0000
committerTim Almdal <tnalmdal@shaw.ca>2009-02-02 03:09:17 +0000
commit69a7e238a4da3ac92f0b62aa2aba6ce3b530a943 (patch)
tree8e64d2da818f1b0f37ce7e5ebbbf07b80edf8a64
parent41dbe5cf6cbd9939da1423a5000808814bb5979e (diff)
As we stagger towards completing the notification module.
Item changes and Item additions email notifications with this change. Still to come is item deleted, comment added and comment updated.
-rw-r--r--modules/notification/helpers/notification.php68
-rw-r--r--modules/notification/helpers/notification_event.php2
-rw-r--r--modules/notification/views/comment_added.html.php0
-rw-r--r--modules/notification/views/comment_changed.html.php0
-rw-r--r--modules/notification/views/item_added.html.php25
-rw-r--r--modules/notification/views/item_deleted.html.php0
-rw-r--r--modules/notification/views/item_updated.html.php36
7 files changed, 102 insertions, 29 deletions
diff --git a/modules/notification/helpers/notification.php b/modules/notification/helpers/notification.php
index 00ea994d..9a942728 100644
--- a/modules/notification/helpers/notification.php
+++ b/modules/notification/helpers/notification.php
@@ -82,48 +82,60 @@ class notification {
return $subscribers;
}
- static function send_item_changed($old, $new=null) {
- $users = self::get_subscribers($item);
+ static function send_item_updated($old, $new) {
+ $body = new View("item_updated.html");
+ $body->subject = sprintf(t("Item %s updated"), $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);
}
static function send_item_add($item) {
- $users = self::get_subscribers($item);
- Sendmail::factory()
- ->to($users)
- ->from("from@gallery3.com")
- ->subject(t("Item added to Gallery3"))
- ->message($item->title)
- ->send();
+ $body = new View("item_added.html");
+ $body->subject = sprintf(t("Item added to %s"), $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);
}
static function send_item_delete($item) {
- $users = self::get_subscribers($item);
- Sendmail::factory()
- ->to($users)
- ->from("from@gallery3.com")
- ->subject("Item deleted: $item->title")
- ->message("It was deleted")
- ->send();
+ $body = new View("item_deleted.html");
+ $body->subject = sprintf(t("Item deleted from %s"), $item->parent()->title);
+
+ self::_send_message($item, $body);
}
static function send_comment_added($comment) {
- $users = self::get_subscribers($comment->item());
- Sendmail::factory()
- ->to($users)
- ->from("from@gallery3.com")
- ->subject("Comment added to $comment->$item->title")
- ->message($comment->text)
- ->send();
+ $body = new View("comment_added.html");
+ $body->subject = sprintf(t("Comment added to %s"), $comment->item()->title);
+
+ self::_send_message($comment->item(), $body);
}
static function send_comment_changed($old, $new) {
- $users = self::get_subscribers($comment->item());
+ $body = new View("comment_changed.html");
+ $body->subject = sprintf(t("Comment changed on %s"), $old->item()->title);
+
+ self::_send_message($old->item(), $body);
+ }
+
+ private function _send_message($item, $body) {
+ $users = self::get_subscribers($item);
Sendmail::factory()
->to($users)
- ->from("from@gallery3.com")
- ->subject("Comment updated on item: $comment->$item-title")
- ->message($new->text)
+ ->subject($body->subject)
+ ->header("Mime-Version", "1.0")
+ ->header("Content-type", "text/html; charset=iso-8859-1")
+ ->message($body->render())
->send();
}
-
}
diff --git a/modules/notification/helpers/notification_event.php b/modules/notification/helpers/notification_event.php
index 415093a5..e7c7aac1 100644
--- a/modules/notification/helpers/notification_event.php
+++ b/modules/notification/helpers/notification_event.php
@@ -19,7 +19,7 @@
*/
class notification_event_Core {
static function item_updated($old, $new) {
- notification::send_item_changed($old, $new);
+ notification::send_item_updated($old, $new);
}
static function item_created($item) {
diff --git a/modules/notification/views/comment_added.html.php b/modules/notification/views/comment_added.html.php
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/modules/notification/views/comment_added.html.php
diff --git a/modules/notification/views/comment_changed.html.php b/modules/notification/views/comment_changed.html.php
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/modules/notification/views/comment_changed.html.php
diff --git a/modules/notification/views/item_added.html.php b/modules/notification/views/item_added.html.php
new file mode 100644
index 00000000..1832fb39
--- /dev/null
+++ b/modules/notification/views/item_added.html.php
@@ -0,0 +1,25 @@
+<?php defined("SYSPATH") or die("No direct script access.") ?>
+<html>
+<head>
+ <title><?= $subject ?> </title>
+</head>
+<body>
+ <h2><?= sprintf(t("A new %s was added to %s"), $type, $parent_title); ?></h2>
+ <table>
+ <tr>
+ <td><?= t("Title:") ?></td>
+ <td><?= $item_title ?></td>
+ </tr>
+ <tr>
+ <td><?= t("Url:") ?></td>
+ <td><a href="<?= $url ?>"><?= $url ?></a></td>
+ </tr>
+ <? if (!empty($description)): ?>
+ <tr>
+ <td><?= t("Description:") ?></td>
+ <td><?= $description ?></td>
+ </tr>
+ <? endif ?>
+ </table>
+</body>
+</html>
diff --git a/modules/notification/views/item_deleted.html.php b/modules/notification/views/item_deleted.html.php
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/modules/notification/views/item_deleted.html.php
diff --git a/modules/notification/views/item_updated.html.php b/modules/notification/views/item_updated.html.php
new file mode 100644
index 00000000..126bd5cc
--- /dev/null
+++ b/modules/notification/views/item_updated.html.php
@@ -0,0 +1,36 @@
+<?php defined("SYSPATH") or die("No direct script access.") ?>
+<html>
+<head>
+ <title><?= $subject ?> </title>
+</head>
+<body>
+ <h2><?= sprintf(t("%s %s was updated"), ucfirst($type), $item_title); ?></h2>
+ <table>
+ <tr>
+ <? if (!empty($new_title)): ?>
+ <td><?= t("New Title:") ?></td>
+ <td><?= $new_title ?></td>
+ <? else: ?>
+ <td><?= t("Title:") ?></td>
+ <td><?= $item_title ?></td>
+ <? endif ?>
+ </tr>
+ <tr>
+ <td><?= t("Url:") ?></td>
+ <td><a href="<?= $url ?>"><?= $url ?></a></td>
+ </tr>
+ <? if (!empty($new_description)): ?>
+ <tr>
+ <td><?= t("New Description:") ?></td>
+ <td><?= $new_description ?></td>
+ </tr>
+ <? else: if (!empty($description)): ?>
+ <tr>
+ <td><?= t("Description:") ?></td>
+ <td><?= $description ?></td>
+ </tr>
+ <? endif ?>
+ <? endif ?>
+ </table>
+</body>
+</html>