Skip to content

Commit

Permalink
message MDL-24771 another big commit of messaging fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Davis committed Oct 26, 2010
1 parent 7955689 commit 14a0e7d
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 23 deletions.
20 changes: 12 additions & 8 deletions lib/db/install.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20101020" COMMENT="XMLDB file for core Moodle tables"
<XMLDB PATH="lib/db" VERSION="20101026" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
Expand Down Expand Up @@ -579,9 +579,11 @@
<FIELD NAME="fullmessage" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="subject" NEXT="fullmessageformat"/>
<FIELD NAME="fullmessageformat" TYPE="int" LENGTH="4" NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="The format of the full message" PREVIOUS="fullmessage" NEXT="fullmessagehtml"/>
<FIELD NAME="fullmessagehtml" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" COMMENT="html format of message" PREVIOUS="fullmessageformat" NEXT="smallmessage"/>
<FIELD NAME="smallmessage" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" COMMENT="Smal version of message (eg sms)" PREVIOUS="fullmessagehtml" NEXT="timecreated"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="smallmessage" NEXT="notification"/>
<FIELD NAME="notification" TYPE="int" LENGTH="1" NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timecreated"/>
<FIELD NAME="smallmessage" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" COMMENT="Smal version of message (eg sms)" PREVIOUS="fullmessagehtml" NEXT="notification"/>
<FIELD NAME="notification" TYPE="int" LENGTH="1" NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="smallmessage" NEXT="contexturl"/>
<FIELD NAME="contexturl" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" COMMENT="If this message is a notification of an event contexturl should contain a link to view this event. For example if its a notification of a forum post contexturl should contain a link to the forum post." PREVIOUS="notification" NEXT="contexturlname"/>
<FIELD NAME="contexturlname" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" COMMENT="Display text for the contexturl" PREVIOUS="contexturl" NEXT="timecreated"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="contexturlname"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand All @@ -600,10 +602,12 @@
<FIELD NAME="fullmessage" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="subject" NEXT="fullmessageformat"/>
<FIELD NAME="fullmessageformat" TYPE="int" LENGTH="4" NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="The format of the full message" PREVIOUS="fullmessage" NEXT="fullmessagehtml"/>
<FIELD NAME="fullmessagehtml" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" COMMENT="html format of message" PREVIOUS="fullmessageformat" NEXT="smallmessage"/>
<FIELD NAME="smallmessage" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" COMMENT="Smal version of message (eg sms)" PREVIOUS="fullmessagehtml" NEXT="timecreated"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="smallmessage" NEXT="timeread"/>
<FIELD NAME="timeread" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="timecreated" NEXT="notification"/>
<FIELD NAME="notification" TYPE="int" LENGTH="1" NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timeread"/>
<FIELD NAME="smallmessage" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" COMMENT="Smal version of message (eg sms)" PREVIOUS="fullmessagehtml" NEXT="notification"/>
<FIELD NAME="notification" TYPE="int" LENGTH="1" NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="smallmessage" NEXT="contexturl"/>
<FIELD NAME="contexturl" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" COMMENT="If this message is a notification of an event contexturl should contain a link to view this event. For example if its a notification of a forum post contexturl should contain a link to the forum post." PREVIOUS="notification" NEXT="contexturlname"/>
<FIELD NAME="contexturlname" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" COMMENT="Display text for the contexturl" PREVIOUS="contexturl" NEXT="timecreated"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="contexturlname" NEXT="timeread"/>
<FIELD NAME="timeread" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="timecreated"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand Down
24 changes: 14 additions & 10 deletions lib/db/upgrade.php
Expand Up @@ -5318,20 +5318,24 @@ function xmldb_main_upgrade($oldversion) {
}

//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);

$table = new xmldb_table('message_read');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
$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);
}
}
}

upgrade_main_savepoint(true, 2010102500);
upgrade_main_savepoint(true, 2010102600);
}

// MDL-24694 needs increasing size of user_preferences.name(varchar[50]) field due to
Expand Down
14 changes: 14 additions & 0 deletions lib/messagelib.php
Expand Up @@ -40,6 +40,8 @@
* 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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion message/lib.php
Expand Up @@ -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 '<div class="message '.$class.'"><a name="m'.$message->id.'"></a><span class="author">'.s(fullname($user)).'</span> <span class="time">['.$time.']</span>: <span class="content">'.$messagetext.'</span></div>';

return '<div class="message '.$class.'"><a name="m'.$message->id.'"></a> <span class="time">'.$time.'</span>: <span class="content">'.$messagetext.'</span></div>';
}

Expand Down
2 changes: 1 addition & 1 deletion mod/forum/lang/en/forum.php
Expand Up @@ -336,7 +336,7 @@
$string['shortpost'] = 'Short post';
$string['showsubscribers'] = 'Show/edit current subscribers';
$string['singleforum'] = 'A single simple discussion';
$string['smallmessage'] = '{$a->user} posted in {$a->forumname}<br />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';
Expand Down
8 changes: 5 additions & 3 deletions mod/forum/lib.php
Expand Up @@ -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 = "<a href='{$CFG->wwwroot}/mod/forum/discuss.php?d={$discussion->id}#p{$post->id}'>{$discussion->name}</a>";
$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){
Expand Down

0 comments on commit 14a0e7d

Please sign in to comment.