message MDL-25297 refactored quiz to make message notifications work

This commit is contained in:
Andrew Davis 2010-11-19 05:18:34 +00:00
parent 060cd0c887
commit bc68fc9a9b
7 changed files with 65 additions and 9 deletions

View File

@ -41,7 +41,7 @@ $string['cannotsavemessageprefs'] = 'Could not save user messaging preferences';
$string['contactlistempty'] = 'Your contact list is empty';
$string['contacts'] = 'Contacts';
$string['context'] = 'context';
$string['couldnotfindpreference'] = 'Could not load preference {$a}. Does the component and name you supplied to message_send() match a row in message_provider? Message providers must appear in the database so users can configure how they will be notified when they receive messages.';
$string['couldnotfindpreference'] = 'Could not load preference {$a}. Does the component and name you supplied to message_send() match a row in message_providers? Message providers must appear in the database so users can configure how they will be notified when they receive messages.';
$string['deletemessagesdays'] = 'Number of days before old messages are automatically deleted';
$string['disabled'] = 'Messaging is disabled on this site';
$string['discussion'] = 'Discussion';
@ -113,6 +113,8 @@ $string['unblockcontact'] = 'Unblock contact';
$string['unreadmessages'] = 'Unread messages ({$a})';
$string['unreadnewmessages'] = 'New messages ({$a})';
$string['unreadnewmessage'] = 'New message from {$a}';
$string['unreadnewnotification'] = 'New notification';
$string['unreadnewnotifications'] = 'New notifications ({$a})';
$string['userisblockingyou'] = 'This user has blocked you from sending messages to them';
$string['userisblockingyounoncontact'] = 'This user is only accepting messages from people listed as contacts, and you are not currently on the list.';
$string['userssearchresults'] = 'Users found: {$a}';

View File

@ -73,7 +73,7 @@ function message_send($eventdata) {
}
// Work out if the user is logged in or not
if ((time() - $timetoshowusers) < $eventdata->userto->lastaccess) {
if (!empty($eventdata->userto->lastaccess) && (time()-$timetoshowusers) < $eventdata->userto->lastaccess) {
$userstate = 'loggedin';
} else {
$userstate = 'loggedoff';

View File

@ -9107,7 +9107,7 @@ function message_popup_window() {
$USER->message_lastpopup = 0;
} else if ($USER->message_lastpopup > (time()-120)) {
//dont run the query to check whether to display a popup if its been run in the last 2 minutes
//return;
return;
}
//a quick query to check whether the user has new messages
@ -9140,10 +9140,14 @@ WHERE m.useridto = :userid AND p.name='popup'";
$strmessages = get_string('unreadnewmessages', 'message', count($message_users));
} else {
$message_users = reset($message_users);
//show who the message is from if its not a notification
if (!$message_users->notification) {
$strmessages = get_string('unreadnewmessage', 'message', fullname($message_users) );
$strmessages = get_string('unreadnewmessage', 'message', fullname($message_users) );
}
//try to display the small version of the message
$smallmessage = null;
if (!empty($message_users->smallmessage)) {
//display the first 200 chars of the message in the popup
$smallmessage = null;
@ -9152,6 +9156,11 @@ WHERE m.useridto = :userid AND p.name='popup'";
} else {
$smallmessage = $message_users->smallmessage;
}
} else if ($message_users->notification) {
//its a notification with no smallmessage so just say they have a notification
$smallmessage = get_string('unreadnewnotification', 'message');
}
if (!empty($smallmessage)) {
$strmessages .= '<div id="usermessage">'.$smallmessage.'</div>';
}
}

36
mod/quiz/db/messages.php Normal file
View File

@ -0,0 +1,36 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Defines message providers (types of messages being sent)
*
* @package mod-forum
* @copyright 1999 onwards Martin Dougiamas http://moodle.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$messageproviders = array (
/// Ordinary single forum posts
'submission' => array (
'capability' => 'mod/quiz:emailnotifysubmission'
)
);

View File

@ -302,6 +302,7 @@ $string['emailnotifybody'] = 'Dear {$a->username},
in course \'{$a->coursename}\'
You can review this attempt at {$a->quizreviewurl}.';
$string['emailnotifysmall'] = '{$a->studentname} has completed {$a->quizname}';
$string['emailnotifysubject'] = '{$a->studentname} has completed quiz {$a->quizname}';
$string['empty'] = 'Empty';
$string['enabled'] = 'Enabled';
@ -475,6 +476,7 @@ $string['matcherror'] = 'Grades do not match grade options - question skipped';
$string['matchgrades'] = 'Match grades';
$string['matchgradeserror'] = 'Error if grade not listed';
$string['matchgradesnearest'] = 'Nearest grade if not listed';
$string['messageprovider:submission'] = 'Quiz submission notifications';
$string['max'] = 'Max';
$string['min'] = 'Min';
$string['minutes'] = 'Minutes';

View File

@ -1029,7 +1029,7 @@ function quiz_send_confirmation($a) {
}
/**
* Sends notification email to the interested parties that assign the role capability
* Sends notification messages to the interested parties that assign the role capability
*
* @param object $recipient user object of the intended recipient
* @param stdClass $a associative array of replaceable fields for the templates
@ -1043,7 +1043,7 @@ function quiz_send_notification($recipient, $a) {
// recipient info for template
$a->username = fullname($recipient);
$a->userusername = $recipient->username;
$a->userusername = $recipient->username;
//$a->userusername = $recipient->username;
// fetch the subject and body from strings
$subject = get_string('emailnotifysubject', 'quiz', $a);
@ -1051,14 +1051,21 @@ function quiz_send_notification($recipient, $a) {
// send email and analyse result
$eventdata = new stdClass();
$eventdata->modulename = 'quiz';
$eventdata->component = 'mod_quiz';
$eventdata->name = 'submission';
$eventdata->notification = 1;
$eventdata->userfrom = $USER;
$eventdata->userto = $recipient;
$eventdata->subject = $subject;
$eventdata->fullmessage = $body;
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
$eventdata->smallmessage = '';
$eventdata->smallmessage = get_string('emailnotifysmall', 'quiz', $a);
$eventdata->contexturl = $a->quizreviewurl;
$eventdata->contexturlname = $a->quizname;
return message_send($eventdata);
}

View File

@ -5,7 +5,7 @@
// This fragment is called by moodle_needs_upgrading() and /admin/index.php
////////////////////////////////////////////////////////////////////////////////
$module->version = 2010102000; // The (date) version of this module
$module->version = 2010111900; // The (date) version of this module
$module->requires = 2010080300; // Requires this Moodle version
$module->cron = 0; // How often should cron check this module (seconds)?