Skip to content

Commit

Permalink
Merge branch 'MDL-4908-m' of git://github.com/andrewnicols/moodle
Browse files Browse the repository at this point in the history
Conflicts:
	version.php
  • Loading branch information
Sam Hemelryk committed Aug 13, 2013
2 parents aae18d2 + 2eb67df commit 0b7e4a1
Show file tree
Hide file tree
Showing 12 changed files with 375 additions and 17 deletions.
7 changes: 7 additions & 0 deletions lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,13 @@
<p>It contains easy instructions to complete your registration.</p>
<p>If you continue to have difficulty, contact the site administrator.</p>';
$string['emaildigest'] = 'Email digest type';
$string['emaildigest_help'] = 'This is the daily digest setting that forums will use by default.
* No digest - you will receive one e-mail per forum post;
* Digest - complete posts - you will receive one digest e-mail per day containing the complete contents of each forum post;
* Digest - subjects only - you will receive one digest e-mail per day containing just the subject of each forum post.
You can also choose a different setting for each forum if you wish.';
$string['emaildigestcomplete'] = 'Complete (daily email with full posts)';
$string['emaildigestoff'] = 'No digest (single email per forum post)';
$string['emaildigestsubjects'] = 'Subjects (daily email with subjects only)';
Expand Down
12 changes: 12 additions & 0 deletions mod/forum/backup/moodle2/backup_forum_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ protected function define_structure() {
$subscription = new backup_nested_element('subscription', array('id'), array(
'userid'));

$digests = new backup_nested_element('digests');

$digest = new backup_nested_element('digest', array('id'), array(
'userid', 'maildigest'));

$readposts = new backup_nested_element('readposts');

$read = new backup_nested_element('read', array('id'), array(
Expand All @@ -89,6 +94,9 @@ protected function define_structure() {
$forum->add_child($subscriptions);
$subscriptions->add_child($subscription);

$forum->add_child($digests);
$digests->add_child($digest);

$forum->add_child($readposts);
$readposts->add_child($read);

Expand Down Expand Up @@ -118,6 +126,8 @@ protected function define_structure() {

$subscription->set_source_table('forum_subscriptions', array('forum' => backup::VAR_PARENTID));

$digest->set_source_table('forum_digests', array('forum' => backup::VAR_PARENTID));

$read->set_source_table('forum_read', array('forumid' => backup::VAR_PARENTID));

$track->set_source_table('forum_track_prefs', array('forumid' => backup::VAR_PARENTID));
Expand All @@ -143,6 +153,8 @@ protected function define_structure() {

$subscription->annotate_ids('user', 'userid');

$digest->annotate_ids('user', 'userid');

$read->annotate_ids('user', 'userid');

$track->annotate_ids('user', 'userid');
Expand Down
13 changes: 13 additions & 0 deletions mod/forum/backup/moodle2/restore_forum_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected function define_structure() {
$paths[] = new restore_path_element('forum_post', '/activity/forum/discussions/discussion/posts/post');
$paths[] = new restore_path_element('forum_rating', '/activity/forum/discussions/discussion/posts/post/ratings/rating');
$paths[] = new restore_path_element('forum_subscription', '/activity/forum/subscriptions/subscription');
$paths[] = new restore_path_element('forum_digest', '/activity/forum/digests/digest');
$paths[] = new restore_path_element('forum_read', '/activity/forum/readposts/read');
$paths[] = new restore_path_element('forum_track', '/activity/forum/trackedprefs/track');
}
Expand Down Expand Up @@ -149,6 +150,18 @@ protected function process_forum_subscription($data) {
$newitemid = $DB->insert_record('forum_subscriptions', $data);
}

protected function process_forum_digest($data) {
global $DB;

$data = (object)$data;
$oldid = $data->id;

$data->forum = $this->get_new_parentid('forum');
$data->userid = $this->get_mappingid('user', $data->userid);

$newitemid = $DB->insert_record('forum_digests', $data);
}

protected function process_forum_read($data) {
global $DB;

Expand Down
18 changes: 16 additions & 2 deletions mod/forum/db/install.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/forum/db" VERSION="20130205" COMMENT="XMLDB file for Moodle mod/forum"
<XMLDB PATH="mod/forum/db" VERSION="20130710" COMMENT="XMLDB file for Moodle mod/forum"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
Expand Down Expand Up @@ -120,6 +120,20 @@
<INDEX NAME="userid" UNIQUE="false" FIELDS="userid"/>
</INDEXES>
</TABLE>
<TABLE NAME="forum_digests" COMMENT="Keeps track of user mail delivery preferences for each forum">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="forum" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="maildigest" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="-1" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id"/>
<KEY NAME="forum" TYPE="foreign" FIELDS="forum" REFTABLE="forum" REFFIELDS="id"/>
<KEY NAME="forumdigest" TYPE="unique" FIELDS="forum, userid, maildigest"/>
</KEYS>
</TABLE>
<TABLE NAME="forum_read" COMMENT="Tracks each users read posts">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
Expand Down Expand Up @@ -153,4 +167,4 @@
</INDEXES>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>
25 changes: 23 additions & 2 deletions mod/forum/db/upgrade.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,30 @@ function xmldb_forum_upgrade($oldversion) {

// Moodle v2.5.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2013071000) {
// Define table forum_digests to be created.
$table = new xmldb_table('forum_digests');

// Adding fields to table forum_digests.
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('forum', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('maildigest', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '-1');

// Adding keys to table forum_digests.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
$table->add_key('forum', XMLDB_KEY_FOREIGN, array('forum'), 'forum', array('id'));
$table->add_key('forumdigest', XMLDB_KEY_UNIQUE, array('forum', 'userid', 'maildigest'));

// Conditionally launch create table for forum_digests.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}

// Forum savepoint reached.
upgrade_mod_savepoint(true, 2013071000, 'forum');
}

return true;
}


42 changes: 41 additions & 1 deletion mod/forum/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,21 @@
$stryes = get_string('yes');
$strno = get_string('no');
$strrss = get_string('rss');
$stremaildigest = get_string('emaildigest');

$searchform = forum_search_form($course);

// Retrieve the list of forum digest options for later.
$digestoptions = forum_get_user_digest_options();
$digestoptions_selector = new single_select(new moodle_url('/mod/forum/maildigest.php',
array(
'backtoindex' => 1,
)),
'maildigest',
$digestoptions,
null,
'');
$digestoptions_selector->method = 'post';

// Start of the table for General Forums

Expand All @@ -94,6 +106,9 @@
if ($can_subscribe) {
$generaltable->head[] = $strsubscribed;
$generaltable->align[] = 'center';

$generaltable->head[] = $stremaildigest . ' ' . $OUTPUT->help_icon('emaildigesttype', 'mod_forum');
$generaltable->align[] = 'center';
}

if ($show_rss = (($can_subscribe || $course->id == SITEID) &&
Expand All @@ -111,7 +126,13 @@
// some special ones are not. These get placed in the general forums
// category with the forums in section 0.

$forums = $DB->get_records('forum', array('course' => $course->id));
$forums = $DB->get_records_sql("
SELECT f.*,
d.maildigest
FROM {forum} f
LEFT JOIN {forum_digests} d ON d.forum = f.id AND d.userid = ?
WHERE f.course = ?
", array($USER->id, $course->id));

$generalforums = array();
$learningforums = array();
Expand Down Expand Up @@ -252,6 +273,14 @@
} else {
$row[] = '-';
}

$digestoptions_selector->url->param('id', $forum->id);
if ($forum->maildigest === null) {
$digestoptions_selector->selected = -1;
} else {
$digestoptions_selector->selected = $forum->maildigest;
}
$row[] = $OUTPUT->render($digestoptions_selector);
}

//If this forum has RSS activated, calculate it
Expand Down Expand Up @@ -297,6 +326,9 @@
if ($can_subscribe) {
$learningtable->head[] = $strsubscribed;
$learningtable->align[] = 'center';

$learningtable->head[] = $stremaildigest . ' ' . $OUTPUT->help_icon('emaildigesttype', 'mod_forum');
$learningtable->align[] = 'center';
}

if ($show_rss = (($can_subscribe || $course->id == SITEID) &&
Expand Down Expand Up @@ -390,6 +422,14 @@
} else {
$row[] = '-';
}

$digestoptions_selector->url->param('id', $forum->id);
if ($forum->maildigest === null) {
$digestoptions_selector->selected = -1;
} else {
$digestoptions_selector->selected = $forum->maildigest;
}
$row[] = $OUTPUT->render($digestoptions_selector);
}

//If this forum has RSS activated, calculate it
Expand Down
22 changes: 21 additions & 1 deletion mod/forum/lang/en/forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@
$string['deletedposts'] = 'Those posts have been deleted';
$string['deletesure'] = 'Are you sure you want to delete this post?';
$string['deletesureplural'] = 'Are you sure you want to delete this post and all replies? ({$a} posts)';
$string['digestmailheader'] = 'This is your daily digest of new posts from the {$a->sitename} forums. To change your forum email preferences, go to {$a->userprefs}.';
$string['digestmailheader'] = 'This is your daily digest of new posts from the {$a->sitename} forums. To change your default forum email preferences, go to {$a->userprefs}.';
$string['digestmailpost'] = 'Change your forum digest preferences';
$string['digestmailprefs'] = 'your user profile';
$string['digestmailsubject'] = '{$a}: forum digest';
$string['digestmailtime'] = 'Hour to send digest emails';
Expand Down Expand Up @@ -142,6 +143,23 @@
$string['editedby'] = 'Edited by {$a->name} - original submission {$a->date}';
$string['editedpostupdated'] = '{$a}\'s post was updated';
$string['editing'] = 'Editing';
$string['emaildigestcompleteshort'] = 'Complete posts';
$string['emaildigestdefault'] = 'Default ({$a})';
$string['emaildigestoffshort'] = 'No digest';
$string['emaildigestsubjectsshort'] = 'Subjects only';
$string['emaildigesttype'] = 'Email digest options';
$string['emaildigesttype_help'] = 'The type of notification that you will receive for each forum.
* Default - follow the digest setting found in your user profile. If you update your profile, then that change will be reflected here too;
* No digest - you will receive one e-mail per forum post;
* Digest - complete posts - you will receive one digest e-mail per day containing the complete contents of each forum post;
* Digest - subjects only - you will receive one digest e-mail per day containing just the subject of each forum post.
';
$string['emaildigestupdated'] = 'The e-mail digest option was changed to \'{$a->maildigesttitle}\' for the forum \'{$a->forum}\'. {$a->maildigestdescription}';
$string['emaildigestupdated_default'] = 'Your default profile setting of \'{$a->maildigesttitle}\' was used for the forum \'{$a->forum}\'. {$a->maildigestdescription}.';
$string['emaildigest_0'] = 'You will receive one e-mail per forum post.';
$string['emaildigest_1'] = 'You will receive one digest e-mail per day containing the complete contents of each forum post.';
$string['emaildigest_2'] = 'You will receive one digest e-mail per day containing the subject of each forum post.';
$string['emptymessage'] = 'Something was wrong with your post. Perhaps you left it blank, or the attachment was too big. Your changes have NOT been saved.';
$string['erroremptymessage'] = 'Post message cannot be empty';
$string['erroremptysubject'] = 'Post subject cannot be empty.';
Expand Down Expand Up @@ -209,6 +227,7 @@
$string['introteacher'] = 'A forum for teacher-only notes and discussion';
$string['invalidaccess'] = 'This page was not accessed correctly';
$string['invaliddiscussionid'] = 'Discussion ID was incorrect or no longer exists';
$string['invaliddigestsetting'] = 'An invalid mail digest setting was provided';
$string['invalidforcesubscribe'] = 'Invalid force subscription mode';
$string['invalidforumid'] = 'Forum ID was incorrect';
$string['invalidparentpostid'] = 'Parent post ID was incorrect';
Expand Down Expand Up @@ -347,6 +366,7 @@
$string['replytouser'] = 'Use email address in reply';
$string['resetforums'] = 'Delete posts from';
$string['resetforumsall'] = 'Delete all posts';
$string['resetdigests'] = 'Delete all per-user forum digest preferences';
$string['resetsubscriptions'] = 'Delete all forum subscriptions';
$string['resettrackprefs'] = 'Delete all forum tracking preferences';
$string['rsssubscriberssdiscussions'] = 'RSS feed of discussions';
Expand Down
Loading

0 comments on commit 0b7e4a1

Please sign in to comment.