public static function clean_annotationfeedback_notifications() { safe_require('notification', 'internal'); PluginNotificationInternal::clean_notifications(array('annotationfeedback')); }
public function notify_user($user) { $changes = new stdClass(); $userdata = $this->to_stdclass(); // some stuff gets overridden by user specific stuff if (!empty($user->url)) { $userdata->url = $user->url; } if (empty($user->lang) || $user->lang == 'default') { $user->lang = get_config('lang'); } if (empty($user->method)) { // If method is not set then either the user has selected 'none' or their setting has not been set (so use default). if ($record = get_record('usr_activity_preference', 'usr', $user->id, 'activity', $this->get_id())) { $user->method = $record->method; if (empty($user->method)) { // The user specified 'none' as their notification type. return; } } else { $user->method = $this->get_default_method(); if (empty($user->method)) { // The default notification type is 'none' for this activity type. return; } } } // always do internal foreach (PluginNotificationInternal::$userdata as &$p) { $function = 'get_' . $p; $userdata->{$p} = $this->{$function}($user); } $userdata->internalid = PluginNotificationInternal::notify_user($user, $userdata); if ($this->update_url($userdata->internalid)) { $changes->url = $userdata->url = $this->url; } if ($user->method != 'internal' || isset($changes->url)) { // OVERWRITE 1: replacement, changed from: //$changes->read = (int) ($user->method != 'internal'); $changes->read = 0; // END OVERWRITE 1 $changes->id = $userdata->internalid; update_record('notification_internal_activity', $changes); } if ($user->method != 'internal') { $method = $user->method; safe_require('notification', $method); $notificationclass = generate_class_name('notification', $method); $classvars = get_class_vars($notificationclass); if (!empty($classvars['userdata'])) { foreach ($classvars['userdata'] as &$p) { $function = 'get_' . $p; if (!isset($userdata->{$p}) && method_exists($this, $function)) { $userdata->{$p} = $this->{$function}($user); } } } try { call_static_method($notificationclass, 'notify_user', $user, $userdata); } catch (MaharaException $e) { static $badnotification = false; static $adminnotified = array(); // We don't mind other notification methods failing, as it'll // go into the activity log as 'unread' $changes->read = 0; update_record('notification_internal_activity', $changes); if (!$badnotification && !($e instanceof EmailDisabledException || $e instanceof InvalidEmailException)) { // Admins should probably know about the error, but to avoid sending too many similar notifications, // save an initial prefix of the message being sent and throw away subsequent exceptions with the // same prefix. To cut down on spam, it's worth missing out on a few similar messages. $k = substr($e, 0, 60); if (!isset($adminnotified[$k])) { $message = (object) array('users' => get_column('usr', 'id', 'admin', 1), 'subject' => get_string('adminnotificationerror', 'activity'), 'message' => $e); $adminnotified[$k] = 1; $badnotification = true; activity_occurred('maharamessage', $message); $badnotification = false; } } } } // The user's unread message count does not need to be updated from $changes->read // because of the db trigger on notification_internal_activity. }
public static function clean_forum_notifications() { safe_require('notification', 'internal'); PluginNotificationInternal::clean_notifications(array('newpost')); }
/** * A cronjob to clean general internal activity notifications */ function cron_clean_internal_activity_notifications() { safe_require('notification', 'internal'); PluginNotificationInternal::clean_notifications(array('viewaccess', 'watchlist', 'institutionmessage')); }
function questionnaire_submit(Pieform $form, $values) { safe_require('notification', 'internal'); global $SESSION, $USER, $survey; $id = $values['id']; $show_results = $values['show_results']; // Keep user responses only! // Strip out: section_type, show_results, sesskey, submit and fs (if exists) $responses = array(); foreach ($values as $key => $value) { if (!in_array($key, array('section_type', 'show_results', 'fs', 'sesskey', 'submit'))) { $responses = array_merge($responses, array($key => $value)); } } try { $survey->set('description', serialize($responses)); $survey->set('mtime', time()); $survey->commit(); $ownername = $USER->get('firstname') . ' ' . $USER->get('lastname') . ' (' . $USER->get('username') . ')'; // Get users who are recipients - can get the results of user's survey $recipients = get_column('artefact_access_usr', 'usr', 'artefact', $id); // Get correct activity type $type = get_field('activity_type', 'id', 'name', 'feedback', 'plugintype', 'artefact', 'pluginname', 'survey'); if (!empty($recipients)) { foreach ($recipients as $recipient) { $user = new StdClass(); $user->id = $recipient; $data = new StdClass(); $data->type = $type; $data->parent = null; $data->message = get_string('surveyaccessmessage', 'artefact.survey', $ownername); $data->subject = get_string('surveyaccesssubject', 'artefact.survey', $ownername); $data->url = get_config('wwwroot') . 'artefact/survey/results.php?id=' . $id; $data->urltext = get_string('surveyaccessurltext', 'artefact.survey'); $data->fromuser = $USER->get('id'); PluginNotificationInternal::notify_user($user, $data); } } } catch (Exception $e) { $SESSION->add_error_msg(get_string('surveysavefailed', 'artefact.survey'), false); } $SESSION->add_ok_msg(get_string('surveysaved', 'artefact.survey')); if ($show_results) { redirect('/artefact/survey/results.php?id=' . $survey->get('id')); } else { redirect('/artefact/survey/'); } }