Skip to content

Commit

Permalink
Merge branch 'wip-mdl-30421' of git://github.com/rajeshtaneja/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hemelryk committed Dec 1, 2011
2 parents bba1338 + 35b81f2 commit 7bebeb2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 35 deletions.
1 change: 1 addition & 0 deletions mod/forum/lang/en/forum.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@
$string['viewalldiscussions'] = 'View all discussions'; $string['viewalldiscussions'] = 'View all discussions';
$string['warnafter'] = 'Post threshold for warning'; $string['warnafter'] = 'Post threshold for warning';
$string['warnafter_help'] = 'Students can be warned as they approach the maximum number of posts allowed in a given period. This setting specifies after how many posts they are warned. Users with the capability mod/forum:postwithoutthrottling are exempt from post limits.'; $string['warnafter_help'] = 'Students can be warned as they approach the maximum number of posts allowed in a given period. This setting specifies after how many posts they are warned. Users with the capability mod/forum:postwithoutthrottling are exempt from post limits.';
$string['warnformorepost'] = 'Warning! There is more than one discussion in this forum - using the most recent';
$string['yournewquestion'] = 'Your new question'; $string['yournewquestion'] = 'Your new question';
$string['yournewtopic'] = 'Your new discussion topic'; $string['yournewtopic'] = 'Your new discussion topic';
$string['yourreply'] = 'Your reply'; $string['yourreply'] = 'Your reply';
49 changes: 25 additions & 24 deletions mod/forum/lib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -153,30 +153,31 @@ function forum_update_instance($forum, $mform) {
} }


if ($forum->type == 'single') { // Update related discussion and post. if ($forum->type == 'single') { // Update related discussion and post.
if (! $discussion = $DB->get_record('forum_discussions', array('forum'=>$forum->id))) { $discussions = $DB->get_records('forum_discussions', array('forum'=>$forum->id), 'timemodified ASC');
if ($discussions = $DB->get_records('forum_discussions', array('forum'=>$forum->id), 'timemodified ASC')) { if (!empty($discussions)) {
echo $OUTPUT->notification('Warning! There is more than one discussion in this forum - using the most recent'); if (count($discussions) > 1) {
$discussion = array_pop($discussions); echo $OUTPUT->notification(get_string('warnformorepost', 'forum'));
} else { }
// try to recover by creating initial discussion - MDL-16262 $discussion = array_pop($discussions);
$discussion = new stdClass(); } else {
$discussion->course = $forum->course; // try to recover by creating initial discussion - MDL-16262
$discussion->forum = $forum->id; $discussion = new stdClass();
$discussion->name = $forum->name; $discussion->course = $forum->course;
$discussion->assessed = $forum->assessed; $discussion->forum = $forum->id;
$discussion->message = $forum->intro; $discussion->name = $forum->name;
$discussion->messageformat = $forum->introformat; $discussion->assessed = $forum->assessed;
$discussion->messagetrust = true; $discussion->message = $forum->intro;
$discussion->mailnow = false; $discussion->messageformat = $forum->introformat;
$discussion->groupid = -1; $discussion->messagetrust = true;

$discussion->mailnow = false;
$message = ''; $discussion->groupid = -1;


forum_add_discussion($discussion, null, $message); $message = '';


if (! $discussion = $DB->get_record('forum_discussions', array('forum'=>$forum->id))) { forum_add_discussion($discussion, null, $message);
print_error('cannotadd', 'forum');
} if (! $discussion = $DB->get_record('forum_discussions', array('forum'=>$forum->id))) {
print_error('cannotadd', 'forum');
} }
} }
if (! $post = $DB->get_record('forum_posts', array('id'=>$discussion->firstpost))) { if (! $post = $DB->get_record('forum_posts', array('id'=>$discussion->firstpost))) {
Expand Down
17 changes: 6 additions & 11 deletions mod/forum/view.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@
// If it's a simple single discussion forum, we need to print the display // If it's a simple single discussion forum, we need to print the display
// mode control. // mode control.
if ($forum->type == 'single') { if ($forum->type == 'single') {
if (! $discussion = $DB->get_record("forum_discussions", array("forum" => $forum->id))) { $discussion = NULL;
if ($discussions = $DB->get_records("forum_discussions", array("forum", $forum->id), "timemodified ASC")) { $discussions = $DB->get_records('forum_discussions', array('forum'=>$forum->id), 'timemodified ASC');
$discussion = array_pop($discussions); if (!empty($discussions)) {
} $discussion = array_pop($discussions);
} }
if ($discussion) { if ($discussion) {
if ($mode) { if ($mode) {
Expand All @@ -167,13 +167,8 @@


switch ($forum->type) { switch ($forum->type) {
case 'single': case 'single':
if (! $discussion = $DB->get_record("forum_discussions", array("forum" => $forum->id))) { if (!empty($discussions) && count($discussions) > 1) {
if ($discussions = $DB->get_records("forum_discussions", array("forum" => $forum->id), "timemodified ASC")) { echo $OUTPUT->notification(get_string('warnformorepost', 'forum'));
echo $OUTPUT->notification("Warning! There is more than one discussion in this forum - using the most recent");
$discussion = array_pop($discussions);
} else {
print_error('nodiscussions', 'forum');
}
} }
if (! $post = forum_get_post_full($discussion->firstpost)) { if (! $post = forum_get_post_full($discussion->firstpost)) {
print_error('cannotfindfirstpost', 'forum'); print_error('cannotfindfirstpost', 'forum');
Expand Down

0 comments on commit 7bebeb2

Please sign in to comment.