Commit 64de8055 authored by Penny Leach's avatar Penny Leach
Browse files

activity/notification/account prefs stuff

parent 30623242
......@@ -29,9 +29,72 @@ define('MENUITEM', 'account');
define('SUBMENUITEM', 'activityprefs');
require(dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php');
require_once('form.php');
$smarty = smarty();
$activitytypes = get_records('activity_type', 'admin', 0);
$notifications = plugins_installed('notification');
$elements = array();
foreach ($activitytypes as $type) {
$elements[$type->name] = array(
'value' => $type->name,
'type' => 'select',
'title' => get_string('type' . $type->name, 'activity'),
'options' => array(),
'rules' => array(
'required' => true
)
);
foreach ($notifications as $n) {
$elements[$type->name]['options'][$n->name] = get_string('name', 'notification.' . $n->name);
}
}
$elements['submit'] = array(
'type' => 'submit',
'value' => get_string('save'),
);
$prefsform = array(
'name' => 'activityprefs',
'method' => 'post',
'ajaxpost' => true,
'plugintype ' => 'core',
'pluginname' => 'account',
'elements' => $elements,
);
$smarty = smarty();
$smarty->assign('prefsdescr', get_string('prefsdescr', 'activity'));
$smarty->assign('form', form($prefsform));
$smarty->display('account/activity/preferences/index.tpl');
function activityprefs_submit($values) {
global $activitytypes, $SESSION;
$userid = $SESSION->get('id');
db_begin();
delete_records('usr_activity_preference', 'usr', $userid);
try {
foreach ($activitytypes as $type) {
$t = new StdClass;
$t->usr = $userid;
$t->type = $type->name;
$t->method = $values[$type->name];
insert_record('usr_activity_preference', $t);
}
}
catch (Exception $e) {
db_rollback();
throw $e;
// @todo actually return a json failure
}
db_commit();
}
?>
......@@ -29,7 +29,7 @@ define('MENUITEM', 'account');
define('SUBMENUITEM', 'accountprefs');
require(dirname(dirname(__FILE__)) . '/init.php');
require('form.php');
require_once('form.php');
// load up user preferences
$prefs = (object)($SESSION->get('accountprefs'));
......@@ -71,6 +71,7 @@ $prefsform = array(
'type' => 'radio',
'value' => $prefs->messages,
'title' => get_string('messagesdescr', 'account'),
'separator' => HTML_BR,
'options' => array(
'nobody' => get_string('messagesnobody', 'account'),
'friends' => get_string('messagesfriends', 'account'),
......@@ -93,8 +94,16 @@ $smarty->assign('form', form($prefsform));
$smarty->display('account/index.tpl');
function accountprefs_submit($values) {
// use this as looping through values is not safe.
$expectedprefs = expected_account_preferences();
try {
foreach (array_keys($expectedprefs) as $pref) {
set_account_preference($SESSION->get('id'), $pref, $expectedprefs[$pref]);
}
}
catch (Exception $e) {
}
}
......
......@@ -38,4 +38,5 @@ $string['typevirusrelease'] = 'Virus flag release';
$string['type'] = 'Activity type: ';
$string['attime'] = 'at';
$string['prefsdescr'] = 'For options other than Activity log, notifications will still go into the Activity log, but will be automatically marked as read';
?>
......@@ -603,6 +603,16 @@ function plugin_types() {
return $pluginstocheck;
}
/**
* This return returns the names of plugins installed
* for the given plugin type.
*
* @param string $plugintype type of plugin
*/
function plugins_installed($plugintype) {
return get_records($plugintype . '_installed');
}
/**
* Helper to call a static method when you do not know the name of the class
* you want to call the method on. PHP5 does not support $class::method().
......
......@@ -30,4 +30,6 @@ $string['emailsubject'] = 'Message from Mahara: %s';
$string['emailbodynoreply'] = "This is an auto generated notification from Mahara. Please do not reply to this message. Following is the content of your notification\n\n--------------------------------------------------\n\n";
$string['emailbody'] = "This is an auto generated notification from Mahara. Following is the content of your notification\n\n--------------------------------------------------\n\n";
$string['emailbodyending'] = 'To update your notification preferences, visit %s';
$string['name'] = 'Email';
?>
......@@ -30,4 +30,6 @@ $string['emailsubject'] = 'Message from Mahara: Daily digest';
$string['emailbodynoreply'] = "This is an auto generated notification from Mahara. Following is the daily digest of all your notifications\n\n--------------------------------------------------\n\n";
$string['emailbodyending'] = 'To update your notification preferences, visit %s';
$string['name'] = 'Email digest';
?>
......@@ -31,5 +31,4 @@ abstract class PluginNotification extends Plugin {
public abstract static function notify_user($user, $data);
}
?>
......@@ -5,7 +5,8 @@
<h2>{str tag="account"}</h2>
<div class="content">
Content from database here
{$prefsdescr}
{$form}
</div>
{include file="footer.tpl"}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment