diff --git a/lib/db/install.xml b/lib/db/install.xml index d573bdabddd..c6fe7214354 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -579,9 +579,11 @@ - - - + + + + + @@ -600,10 +602,12 @@ - - - - + + + + + + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 17d7be4995c..dd4436c272d 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -5318,20 +5318,24 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); } //MDL-24771 - if ($oldversion < 2010102500) { - $field = new xmldb_field('notification', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0); + if ($oldversion < 2010102600) { - $table = new xmldb_table('message'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); + $fieldnotification = new xmldb_field('notification', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'smallmessage'); + $fieldcontexturl = new xmldb_field('contexturl', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'notification'); + $fieldcontexturlname = new xmldb_field('contexturlname', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'contexturl'); + $fieldstoadd = array($fieldnotification, $fieldcontexturl, $fieldcontexturlname); + + $tablestomodify = array(new xmldb_table('message'), new xmldb_table('message_read')); + + foreach($tablestomodify as $table) { + foreach($fieldstoadd as $field) { + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + } } - $table = new xmldb_table('message_read'); - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - upgrade_main_savepoint(true, 2010102500); + upgrade_main_savepoint(true, 2010102600); } // MDL-24694 needs increasing size of user_preferences.name(varchar[50]) field due to diff --git a/lib/messagelib.php b/lib/messagelib.php index 6fdcc625610..cfa830efb6e 100644 --- a/lib/messagelib.php +++ b/lib/messagelib.php @@ -40,6 +40,8 @@ defined('MOODLE_INTERNAL') || die(); * fullmessageformat - the format if the full message (FORMAT_MOODLE, FORMAT_HTML, ..) * fullmessagehtml - the full version (the message processor will choose with one to use) * smallmessage - the small version of the message + * contexturl - if this is a notification then you can specify a url to view the event. For example the forum post the user is being notified of. + * contexturlname - the display text for contexturl * * @param object $eventdata information about the message (modulename, userfrom, userto, ...) * @return boolean success @@ -83,6 +85,18 @@ function message_send($eventdata) { $savemessage->notification = 0; } + if (!empty($eventdata->contexturl)) { + $savemessage->contexturl = $eventdata->contexturl; + } else { + $savemessage->contexturl = null; + } + + if (!empty($eventdata->contexturlname)) { + $savemessage->contexturlname = $eventdata->contexturlname; + } else { + $savemessage->contexturlname = null; + } + $savemessage->timecreated = time(); // Find out what processors are defined currently diff --git a/message/lib.php b/message/lib.php index d21531cddec..d2b64b3827f 100644 --- a/message/lib.php +++ b/message/lib.php @@ -1521,10 +1521,22 @@ function message_format_message(&$message, &$user, $format='', $keywords='', $cl $messagetext = format_text($message->fullmessage, $message->fullmessageformat, $options); } + if (!empty($message->contexturl)) { + $displaytext = null; + if (!empty($message->contexturlname)) { + $displaytext= $message->contexturlname; + } else { + $displaytext= $message->contexturl; + } + $messagetext .= html_writer::start_tag('div',array('class'=>'messagecontext')); + $messagetext .= get_string('view').': '.html_writer::tag('a', $displaytext, array('href' => $message->contexturl)); + $messagetext .= html_writer::end_tag('div'); + } + if ($keywords) { $messagetext = highlight($keywords, $messagetext); } - //return '
'.s(fullname($user)).' ['.$time.']: '.$messagetext.'
'; + return '
'.$time.': '.$messagetext.'
'; } diff --git a/mod/forum/lang/en/forum.php b/mod/forum/lang/en/forum.php index a836f231865..2e544c3ced6 100644 --- a/mod/forum/lang/en/forum.php +++ b/mod/forum/lang/en/forum.php @@ -336,7 +336,7 @@ $string['seeallposts'] = 'See all posts made by this user'; $string['shortpost'] = 'Short post'; $string['showsubscribers'] = 'Show/edit current subscribers'; $string['singleforum'] = 'A single simple discussion'; -$string['smallmessage'] = '{$a->user} posted in {$a->forumname}
View discussion: {$a->replylink}'; +$string['smallmessage'] = '{$a->user} posted in {$a->forumname}'; $string['startedby'] = 'Started by'; $string['subject'] = 'Subject'; $string['subscribe'] = 'Subscribe to this forum'; diff --git a/mod/forum/lib.php b/mod/forum/lib.php index ae9a578b283..cc8b210af14 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -635,14 +635,16 @@ function forum_cron() { $eventdata->fullmessage = $posttext; $eventdata->fullmessageformat = FORMAT_PLAIN; $eventdata->fullmessagehtml = $posthtml; + $eventdata->notification = 1; $smallmessagestrings = new stdClass(); $smallmessagestrings->user = fullname($userfrom); - $smallmessagestrings->forumname = "{$course->shortname}->".format_string($forum->name,true); - $smallmessagestrings->replylink = "{$discussion->name}"; + $smallmessagestrings->forumname = "{$course->shortname}: ".format_string($forum->name,true).": ".$discussion->name; $smallmessagestrings->message = $post->message; $eventdata->smallmessage = get_string('smallmessage', 'forum', $smallmessagestrings); - $eventdata->notification = 1; + + $eventdata->contexturl = "{$CFG->wwwroot}/mod/forum/discuss.php?d={$discussion->id}#p{$post->id}"; + $eventdata->contexturlname = $discussion->name; $mailresult = message_send($eventdata); if (!$mailresult){