Commit 7bc5b382 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Institution activity type added; send email notification on membership request

parent 115763e5
......@@ -37,6 +37,7 @@ $string['typeobjectionable'] = 'Objectionable content';
$string['typevirusrepeat'] = 'Repeat virus upload';
$string['typevirusrelease'] = 'Virus flag release';
$string['typeadminmessages'] = 'Administration messages';
$string['typeinstitutionmessage'] = 'Institution message';
$string['type'] = 'Activity type';
$string['attime'] = 'at';
......@@ -93,4 +94,7 @@ $string['removedgroupmembersubj'] = '%s is no longer a group member';
$string['addtowatchlist'] = 'Add to watchlist';
$string['removefromwatchlist'] = 'Remove from watchlist';
$string['institutionrequestsubject'] = '%s has asked to be added as a member of %s.';
$string['institutionrequestmessage'] = 'You can add users to institutions by visiting the Institution Members page:';
?>
......@@ -156,6 +156,23 @@ function handle_activity($activitytype, $data, $cron=false) {
}
$users = activity_get_users($activitytype->name, $data->users);
break;
case 'institutionmessage':
if ($data->messagetype == 'request') {
$userstring = $data->username . ' (' . $data->fullname . ')';
$data->subject = get_string('institutionrequestsubject', 'activity', $userstring,
$data->institution->displayname);
$data->message = get_string('institutionrequestmessage', 'activity');
$data->url = get_config('wwwroot') . 'admin/users/institutionusers.php';
$admins = get_column_sql('
SELECT u.id
FROM {usr} u
LEFT OUTER JOIN {usr_institution} i ON (u.id = i.usr AND i.institution = ?)
WHERE u.admin = 1 OR i.admin = 1',
array($data->institution->name));
$users = activity_get_users($activitytype->name, $admins);
} else if ($data->messagetype == 'invite') {
}
break;
case 'usermessage':
if (!is_numeric($data->userto) || !is_numeric($data->userfrom)) {
throw new InvalidArgumentException("User message requires userto and userfrom to be set");
......@@ -394,11 +411,18 @@ function activity_get_users($activitytype, $userids=null, $userobjs=null, $admin
*/
function activity_set_defaults($user_id) {
$activitytypes = get_records_array('activity_type', 'admin', 0);
$haveemail = in_array('email', array_map(create_function('$a', 'return $a->name;'),
plugins_installed('notification')));
foreach ($activitytypes as $type) {
if ($type->name == 'institutionmessage' && $haveemail) {
$method = 'email';
} else {
$method = 'internal';
}
insert_record('usr_activity_preference', (object)array(
'usr' => $user_id,
'activity' => $type->name,
'method' => 'internal',
'method' => $method,
));
}
......
......@@ -514,6 +514,27 @@ function xmldb_core_upgrade($oldversion=0) {
execute_sql('ALTER TABLE {institution} ADD COLUMN defaultmembershipperiod bigint');
}
if ($oldversion < 2007120500) {
insert_record('activity_type', (object) array(
'name' => 'institutionmessage',
'admin' => 0,
'delay' => 0
));
if (in_array('email', array_map(create_function('$a', 'return $a->name;'),
plugins_installed('notification')))) {
$method = 'email';
} else {
$method = 'internal';
}
foreach (get_column('usr', 'id') as $userid) {
insert_record('usr_activity_preference', (object) array(
'usr' => $userid,
'activity' => 'institutionmessage',
'method' => $method
));
}
}
return $status;
}
......
......@@ -248,6 +248,13 @@ class Institution {
);
insert_record('usr_institution_request', $request);
// Send request notification
$data = new StdClass;
$data->messagetype = 'request';
$data->username = $user->username;
$data->fullname = $user->firstname . ' ' . $user->lastname;
$data->institution = (object)array('name' => $this->name, 'displayname' => $this->displayname);
$data->url = get_config('wwwroot') . 'foo';
activity_occurred('institutionmessage', $data);
} else if ($request->confirmedinstitution) {
$this->addUserAsMember($user);
}
......
......@@ -639,6 +639,7 @@ function core_install_firstcoredata_defaults() {
array('objectionable', 1, 1),
array('virusrepeat', 1, 1),
array('virusrelease', 1, 1),
array('institutionmessage', 0, 0),
);
foreach ($activitytypes as $at) {
......
......@@ -27,7 +27,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2007112600;
$config->version = 2007120500;
$config->release = '0.9.0alpha3dev';
$config->minupgradefrom = 2007080700;
$config->minupgraderelease = '0.8.0 (release tag 0.8.0_RELEASE)';
......
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