diff options
| author | Tim Almdal <tnalmdal@shaw.ca> | 2009-01-30 20:52:25 +0000 | 
|---|---|---|
| committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-01-30 20:52:25 +0000 | 
| commit | 38cf6ca403b485644405b8ec39af334a877e58b2 (patch) | |
| tree | d8da46a1a2e5e834ac9f98d5e716f7da2010d764 /modules/notification | |
| parent | b925d9da5320790d7a1e6aaa7d6d80b1eea1a67d (diff) | |
The start of the notification module.  At this point, the icon has been added to the item menu in the sidebar (both photo and album).  There is a corresponding icon in themes/default/images that needs to be spruced up. You can add and remove notifications to albums and photos, but nothing happens under the covers for event handling.
Diffstat (limited to 'modules/notification')
| -rw-r--r-- | modules/notification/controllers/notification.php | 68 | ||||
| -rw-r--r-- | modules/notification/helpers/notification.php | 119 | ||||
| -rw-r--r-- | modules/notification/helpers/notification_event.php | 26 | ||||
| -rw-r--r-- | modules/notification/helpers/notification_installer.php | 46 | ||||
| -rw-r--r-- | modules/notification/helpers/notification_menu.php | 50 | ||||
| -rw-r--r-- | modules/notification/models/notification.php | 22 | ||||
| -rw-r--r-- | modules/notification/models/subscription.php | 23 | ||||
| -rw-r--r-- | modules/notification/module.info | 3 | 
8 files changed, 357 insertions, 0 deletions
| diff --git a/modules/notification/controllers/notification.php b/modules/notification/controllers/notification.php new file mode 100644 index 00000000..804a908e --- /dev/null +++ b/modules/notification/controllers/notification.php @@ -0,0 +1,68 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA. + */ +class Notification_Controller extends Controller { +  function watch($id) { +    $item = ORM::factory("item", $id); +    access::required("view", $item); + +    $watching = notification::is_watching($item->id); +    $form = $this->_get_form($item, $watching); +    if (request::method() == "post") { +      if ($form->validate()) { +        $watch_children = $form->watch->inputs["apply_to_children"]->value; +        if (!$watching) { +          notification::add_watch($item, $watch_children); +          message::success(sprintf(t("Watch Enabled on %s!"), $item->title)); +          $response = json_encode(array("result" => "success")); +        } else { +          notification::remove_watch($item, $watch_children); +          $response = json_encode(array("result" => "success")); +          message::success(sprintf(t("Watch Removed on %s!"), $item->title)); +        } +      } else { +        $response = json_encode(array("result" => "error", "form" => $form->__toString())); +      } +    } else { +      $response = $form; +    } + +    print $response; +  } + +  function _get_form($item, $watching) { +    $button_text = $watching ? t("Remove Watch") : t("Add Watch"); +    if ($item->is_album()) { +      $label = $watching ? t("Remove Watch from Album") : t("Add Watch to Album"); +    } else { +      $label = $watching ? t("Remove Watch from Photo") : t("Add Watch to Photo"); +    } +    $form = new Forge("notification/watch/$item->id", "", "post", array("id" => "gAddWatchForm")); +    $group = $form->group("watch")->label($label); +    $checkbox = $group->checkbox("apply_to_children") +      ->label(t("Apply to Children")) +      ->checked($item->is_album()); +    if (!$item->is_album()) { +      $checkbox->disabled("disabled"); +    } +    $group->submit("")->value($button_text); + +    return $form; +  } +} diff --git a/modules/notification/helpers/notification.php b/modules/notification/helpers/notification.php new file mode 100644 index 00000000..79f7288e --- /dev/null +++ b/modules/notification/helpers/notification.php @@ -0,0 +1,119 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA. + */ +class notification { +  static function get_subscriptions($item_id, $user=null) { +    if (empty($user)) { +      $user = user::active(); +    } + +    return ORM::factory("subscription") +      ->where("item_id", $item_id) +      ->where("user_id", $user->id) +      ->find_all(); +  } + +  static function is_watching($item_id, $user=null) { +    if (empty($user)) { +      $user = user::active(); +    } + +    $count = ORM::factory("subscription") +      ->where("item_id", $item_id) +      ->where("user_id", $user->id) +      ->count_all(); + +    return $count > 0; +  } + +  static function add_watch($item, $watch_children=false, $user=null) { +    if (empty($user)) { +      $user = user::active(); +    } +    $subscription = ORM::factory("subscription"); +    $subscription->item_id = $item->id; +    $subscription->apply_to_children = $watch_children; +    $subscription->user_id = $user->id; +    $subscription->save(); + +    if ($watch_children && $item->is_album()) { +      $children = ORM::factory("item") +      ->viewable() +      ->where("parent_id", $item->id) +      ->find_all(); +      foreach ($children as $child) { +        self::add_watch($child, $watch_children, $user); +      } +    } +  } + +  static function remove_watch($item, $watch_children=false, $user=null) { +    if (empty($user)) { +      $user = user::active(); +    } + +    $subscription = ORM::factory("subscription") +      ->where("item_id", $item->id) +      ->where("user_id", $user->id) +      ->find(); +    $subscription->delete(); + +    if ($watch_children && $item->is_album()) { +      $children = ORM::factory("item") +      ->viewable() +      ->where("parent_id", $item->id) +      ->find_all(); +      foreach ($children as $child) { +        self::remove_watch($child, $watch_children, $user); +      } +    } +  } + +  static function get_subscribers($item_id) { +    return ORM::factory("subscription") +      ->where("item_id", $item_id) +      ->find_all(); +  } +     +  static function count_subscribers($item_id) { +    return ORM::factory("subscription") +      ->where("item_id", $item_id) +      ->count_all(); +  } +     +  static function get_watched_items($user=null) { +    if (empty($user)) { +      $user = user::active(); +    } + +    return ORM::factory("subscription") +      ->where("user_id", $item_id) +      ->find_all(); +  } + +  static function count_watched_items($user=null) { +    if (empty($user)) { +      $user = user::active(); +    } + +    return ORM::factory("subscription") +      ->where("user_id", $item_id) +      ->count_all(); +  } +} diff --git a/modules/notification/helpers/notification_event.php b/modules/notification/helpers/notification_event.php new file mode 100644 index 00000000..06b5b1f6 --- /dev/null +++ b/modules/notification/helpers/notification_event.php @@ -0,0 +1,26 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA. + */ +class notification_event_Core { +  static function comment_created($comment) { +  } + +  static function comment_updated($old, $new) { +  } +} diff --git a/modules/notification/helpers/notification_installer.php b/modules/notification/helpers/notification_installer.php new file mode 100644 index 00000000..c2a9828f --- /dev/null +++ b/modules/notification/helpers/notification_installer.php @@ -0,0 +1,46 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA. + */ +class notification_installer { +  static function install() { +    $db = Database::instance(); +    $version = module::get_version("notification"); + +    if ($version == 0) { +      $db->query("CREATE TABLE IF NOT EXISTS `subscriptions` ( +                 `id` int(9) NOT NULL auto_increment, +                 `item_id` int(9) NOT NULL, +                 `apply_to_children` tinyint(1) NOT NULL, +                 `user_id` int(9) NOT NULL, +                 PRIMARY KEY (`id`), +                 UNIQUE KEY (`item_id`, `user_id`), +                 UNIQUE KEY (`user_id`, `item_id`)) +                 ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + +      module::set_version("notification", 1); +    } +  } + +  static function uninstall() { +    $db = Database::instance(); +    $db->query("DROP TABLE IF EXISTS `subscriptions`;"); +     +    module::delete("notification"); +  } +} diff --git a/modules/notification/helpers/notification_menu.php b/modules/notification/helpers/notification_menu.php new file mode 100644 index 00000000..8c2e84d8 --- /dev/null +++ b/modules/notification/helpers/notification_menu.php @@ -0,0 +1,50 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA. + */ +class notification_menu_Core { +  static function album($menu, $theme) { +    if (!user::active()->guest) { +      $item = $theme->item(); + +      if ($item) { +        $menu +          ->append(Menu::factory("dialog") +               ->id("watch") +               ->label(t("Enable notifications for this album")) +               ->url(url::site("notification/watch/$item->id")) +               ->css_id("gWatchLink")); +      } +    } +  } + +  static function photo($menu, $theme) { +    if (!user::active()->guest) { +      $item = $theme->item(); + +      if ($item) { +        $menu +          ->append(Menu::factory("dialog") +               ->id("watch") +               ->label(t("Enable notifications for this photo")) +               ->url(url::site("notification/watch/$item->id")) +               ->css_id("gWatchLink")); +      } +    } +  } +} diff --git a/modules/notification/models/notification.php b/modules/notification/models/notification.php new file mode 100644 index 00000000..0ba183eb --- /dev/null +++ b/modules/notification/models/notification.php @@ -0,0 +1,22 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA. + */ +class Notification_Model extends ORM { +  protected $belongs_to = array("subscription"); +}
\ No newline at end of file diff --git a/modules/notification/models/subscription.php b/modules/notification/models/subscription.php new file mode 100644 index 00000000..aa90a58c --- /dev/null +++ b/modules/notification/models/subscription.php @@ -0,0 +1,23 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA. + */ +class Subscription_Model extends ORM { +  protected $has_one = array("item"); +  protected $has_many = array("user"); +}
\ No newline at end of file diff --git a/modules/notification/module.info b/modules/notification/module.info new file mode 100644 index 00000000..d4dc34e0 --- /dev/null +++ b/modules/notification/module.info @@ -0,0 +1,3 @@ +name = Notification +description = "Send notifications to users when changes are made to watched albums." +version = 1 | 
