diff options
author | marcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-06-24 17:14:59 +0000 |
---|---|---|
committer | marcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-06-24 17:14:59 +0000 |
commit | ee18a9dc58e75113b3377d08f460788dde419869 (patch) | |
tree | 166497cedeae1f0a355241c4c28054e4e1e29b0f | |
parent | 3e5f7cf353e44de8d4d22c19f3c904b0a16401a8 (diff) | |
download | elgg-ee18a9dc58e75113b3377d08f460788dde419869.tar.gz elgg-ee18a9dc58e75113b3377d08f460788dde419869.tar.bz2 |
Closes #83 - API & Interface for selecting notification methods
git-svn-id: https://code.elgg.org/elgg/trunk@1110 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r-- | actions/notifications/settings/usersettings/save.php | 37 | ||||
-rw-r--r-- | engine/lib/notification.php | 70 | ||||
-rw-r--r-- | languages/en.php | 15 | ||||
-rw-r--r-- | views/default/notifications/settings/usersettings.php | 46 |
4 files changed, 166 insertions, 2 deletions
diff --git a/actions/notifications/settings/usersettings/save.php b/actions/notifications/settings/usersettings/save.php new file mode 100644 index 000000000..79970421a --- /dev/null +++ b/actions/notifications/settings/usersettings/save.php @@ -0,0 +1,37 @@ +<?php + /** + * Elgg notifications user preference save acion. + * + * @package Elgg + * @subpackage Core + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Marcus Povey + * @copyright Curverider Ltd 2008 + * @link http://elgg.org/ + */ + + // Method + $method = get_input('method'); + gatekeeper(); + + $result = false; + foreach ($method as $k => $v) + { + $result = set_user_notification_setting($_SESSION['user']->guid, $k, ($v == 'yes') ? true : false); + + if (!$result) + { + system_message(elgg_echo('notifications:usersettings:save:fail')); + forward($_SERVER['HTTP_REFERER']); + + exit; + } + } + + if ($result) + system_message(elgg_echo('notifications:usersettings:save:ok')); + else + system_message(elgg_echo('notifications:usersettings:save:fail')); + + forward($_SERVER['HTTP_REFERER']); +?>
\ No newline at end of file diff --git a/engine/lib/notification.php b/engine/lib/notification.php index 8df897394..30dd8da99 100644 --- a/engine/lib/notification.php +++ b/engine/lib/notification.php @@ -85,6 +85,70 @@ } /** + * Get the notification settings for a given user. + * + * @param int $user_guid The user id + * @return stdClass + */ + function get_user_notification_settings($user_guid = 0) + { + $user_guid = (int)$user_guid; + + if ($user_guid == 0) + $user_guid = $_SESSION['user']->guid; + + $all_metadata = get_metadata_for_entity($user_guid); + if ($all_metadata) + { + $prefix = "notification:method:"; + $return = new stdClass; + + foreach ($all_metadata as $meta) + { + $name = substr($meta->name, strlen($prefix)); + $value = $meta->value; + + if (strpos($meta->name, $prefix) === 0) + $return->$name = $value; + } + + return $return; + } + + return false; + } + + /** + * Set a user notification pref. + * + * @param int $user_guid The user id. + * @param string $method The delivery method (eg. email) + * @param bool $value On(true) or off(false). + * @return bool + */ + function set_user_notification_setting($user_guid, $method, $value) + { + $user_guid = (int)$user_guid; + $method = sanitise_string($method); + + if ($user_guid == 0) + $user_guid = $_SESSION['user']->guid; + + $user = get_entity($user_guid); + + if (($user) && ($user instanceof ElggUser)) + { + $prefix = "notification:method:$method"; + $user->$prefix = $value; + $user->save(); + + return true; + } + + return false; + } + + /** * Notification exception. * @author Marcus Povey */ @@ -121,7 +185,13 @@ */ function notification_init() { + // Register a notification handler for the default email method register_notification_handler("email", "email_notify_handler"); + + // Add settings view to user settings & register action + extend_elgg_settings_page('notifications/settings/usersettings', 'usersettings/user'); + register_action("notifications/settings/usersettings/save"); + } // Register a startup event diff --git a/languages/en.php b/languages/en.php index dd4679893..29aaa00bb 100644 --- a/languages/en.php +++ b/languages/en.php @@ -208,7 +208,15 @@ 'plugins:settings:save:fail' => "There was a problem saving settings for the %s plugin.", 'plugins:usersettings:save:ok' => "User settings for the %s plugin were saved successfully.", 'plugins:usersettings:save:fail' => "There was a problem saving user settings for the %s plugin.",
-
+ + /** + * Notifications + */ + 'notifications:usersettings' => "Notification settings", + 'notifications:methods' => "Please specify which methods you want to permit.", + + 'notifications:usersettings:save:ok' => "Your notification settings were successfully saved.", + 'notifications:usersettings:save:fail' => "There was a problem saving your notification settings.",
/**
* Search
*/
@@ -326,7 +334,10 @@ 'upload' => "Upload", 'ban' => "Ban", 'enable' => "Enable", - 'disable' => "Disable",
+ 'disable' => "Disable", + + 'yes' => "Yes", + 'no' => "No",
/**
* Generic data words
diff --git a/views/default/notifications/settings/usersettings.php b/views/default/notifications/settings/usersettings.php new file mode 100644 index 000000000..71c12fdc5 --- /dev/null +++ b/views/default/notifications/settings/usersettings.php @@ -0,0 +1,46 @@ +<?php + /** + * User settings for notifications. + * + * @package Elgg + * @subpackage Core + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Marcus Povey + * @copyright Curverider Ltd 2008 + * @link http://elgg.org/ + */ + + global $NOTIFICATION_HANDLERS; + $notification_settings = get_user_notification_settings(); +?> +<form action="<?php echo $vars['url']; ?>action/notifications/settings/usersettings/save" method="post"> + <h2><?php echo elgg_echo('notifications:usersettings'); ?></h2> + + <p><?php echo elgg_echo('notifications:methods'); ?> + + <table> +<?php + // Loop through options + foreach ($NOTIFICATION_HANDLERS as $k => $v) + { +?> + <tr> + <td><?php echo $k; ?>: </td> + + <td> + <input type="radio" name="method[<?php echo $k; ?>]" value="yes" <?php if ($notification_settings->$k) echo "checked=\"yes\" "; ?>/><?php echo elgg_echo("yes"); ?><br /> + <input type="radio" name="method[<?php echo $k; ?>]" value="no" <?php if (!$notification_settings->$k) echo "checked=\"yes\" "; ?>/><?php echo elgg_echo("no"); ?> + </td> + </tr> +<?php + } +?> + </table> + <p> + <input type="submit" value="<?php + + echo elgg_echo('save'); + + ?>" /> + </p> +</form>
\ No newline at end of file |