Commit 98529d2d authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Send notifications to tutors/admins when views are submitted (bug 3406)


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent a094fa36
......@@ -38,6 +38,7 @@ $string['typevirusrepeat'] = 'Repeat virus upload';
$string['typevirusrelease'] = 'Virus flag release';
$string['typeadminmessages'] = 'Administration messages';
$string['typeinstitutionmessage'] = 'Institution message';
$string['typegroupmessage'] = 'Group message';
$string['type'] = 'Activity type';
$string['attime'] = 'at';
......@@ -107,4 +108,8 @@ $string['institutioninvitemessage'] = 'You can confirm your membership of this i
$string['deleteallnotifications'] = 'Delete all notifications';
$string['reallydeleteallnotifications'] = 'Are you sure you want to delete all your notifications?';
$string['viewsubmittedsubject'] = 'View submitted to %s';
$string['viewsubmittedmessage'] = '%s has submitted their view "%s" to %s';
?>
......@@ -830,6 +830,57 @@ class ActivityTypeViewaccess extends ActivityType {
}
}
class ActivityTypeGroupMessage extends ActivityType {
protected $group;
protected $roles;
protected $submittedview;
private $viewinfo;
private $groupinfo;
/**
* @param array $data Parameters:
* - subject (string)
* - message (string)
* - group (integer)
* - roles (list of roles)
*/
public function __construct($data, $cron=false) {
require_once('group.php');
parent::__construct($data, $cron);
$this->groupinfo = get_record('group', 'id', $this->group);
$members = group_get_member_ids($this->group, isset($this->roles) ? $this->roles : null);
$this->users = activity_get_users($this->get_id(), $members);
if ($this->submittedview) {
$this->viewinfo = get_record('view', 'id', $this->submittedview);
$this->viewinfo->ownername = display_name($this->viewinfo->owner);
$this->url = get_config('wwwroot') . 'view/view.php?id=' . $this->submittedview;
}
}
public function get_subject($user) {
if ($this->submittedview) {
return get_string_from_language($user->lang, 'viewsubmittedsubject', 'activity', $this->groupinfo->name);
}
return $this->subject;
}
public function get_message($user) {
if ($this->submittedview) {
return get_string_from_language($user->lang, 'viewsubmittedmessage', 'activity', $this->viewinfo->ownername, $this->viewinfo->title, $this->groupinfo->name);
}
return $this->subject;
}
public function get_required_parameters() {
return array('message', 'subject', 'group');
}
}
abstract class ActivityTypePlugin extends ActivityType {
abstract public function get_plugintype();
......
......@@ -1246,6 +1246,10 @@ function xmldb_core_upgrade($oldversion=0) {
insert_record('view_layout', $record);
}
if ($oldversion < 2009102200) {
insert_record('activity_type', (object) array('name' => 'groupmessage', 'admin' => 0, 'delay' => 0));
}
return $status;
}
......
......@@ -1131,4 +1131,14 @@ function group_get_user_groups($userid=null, $roles=null) {
return array();
}
function group_get_member_ids($group, $roles=null) {
$rolesql = is_null($roles) ? '' : (' AND gm.role IN (' . join(',', array_map('db_quote', $roles)) . ')');
return get_column_sql('
SELECT gm.member
FROM {group_member} gm INNER JOIN {group} g ON gm.group = g.id
WHERE g.deleted = 0 AND g.id = ?' . $rolesql,
array($group)
);
}
?>
......@@ -744,6 +744,7 @@ function core_install_firstcoredata_defaults() {
array('virusrepeat', 1, 1),
array('virusrelease', 1, 1),
array('institutionmessage', 0, 0),
array('groupmessage', 0, 0),
);
foreach ($activitytypes as $at) {
......
......@@ -28,7 +28,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2009102100;
$config->version = 2009102200;
$config->release = '1.2.0beta5dev';
$config->minupgradefrom = 2008040200;
$config->minupgraderelease = '1.0.0 (release tag 1.0.0_RELEASE)';
......
......@@ -30,6 +30,7 @@ define('MENUITEM', 'myportfolio/views');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
require_once('view.php');
require_once('activity.php');
$viewid = param_integer('id');
$groupid = param_integer('group');
......@@ -72,8 +73,18 @@ $smarty->assign('form', $form);
$smarty->display('view/submit.tpl');
function submitview_submit(Pieform $form, $values) {
global $SESSION, $viewid, $groupid;
global $SESSION, $USER, $viewid, $groupid;
db_begin();
update_record('view', array('submittedgroup' => $groupid), array('id' => $viewid));
activity_occurred('groupmessage', array(
'subject' => get_string('viewsubmitted', 'view'), // will be overwritten
'message' => get_string('viewsubmitted', 'view'), // will be overwritten
'submittedview' => $viewid,
'viewowner' => $USER->get('id'),
'group' => $groupid,
'roles' => array('admin', 'tutor'),
));
db_commit();
$SESSION->add_ok_msg(get_string('viewsubmitted', 'view'));
redirect('/view/');
}
......
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