Permalink
Browse files

MDL-37111 copy first post files in single type forum using intro options

This patch also removed the delete button from the first post in single
discussion type forum.

Edit button in the first post leads to the forum edit page now, this should
prevent other problems throwing first post and intro out of sync.
  • Loading branch information...
1 parent 4c7e6ea commit 599e7fe00675ab5576daa313adedfd2013733cfa @skodak skodak committed Dec 13, 2012
Showing with 21 additions and 15 deletions.
  1. +21 −15 mod/forum/lib.php
View
36 mod/forum/lib.php
@@ -96,12 +96,12 @@ function forum_add_instance($forum, $mform = null) {
$discussion->id = forum_add_discussion($discussion, null, $message);
if ($mform and $draftid = file_get_submitted_draft_itemid('introeditor')) {
- // ugly hack - we need to copy the files somehow
+ // Ugly hack - we need to copy the files somehow.
$discussion = $DB->get_record('forum_discussions', array('id'=>$discussion->id), '*', MUST_EXIST);
$post = $DB->get_record('forum_posts', array('id'=>$discussion->firstpost), '*', MUST_EXIST);
- $post->message = file_save_draft_area_files($draftid, $modcontext->id, 'mod_forum', 'post', $post->id,
- mod_forum_post_form::attachment_options($forum), $post->message);
+ $options = array('subdirs'=>true); // Use the same options as intro field!
+ $post->message = file_save_draft_area_files($draftid, $modcontext->id, 'mod_forum', 'post', $post->id, $options, $post->message);
$DB->set_field('forum_posts', 'message', $post->message, array('id'=>$post->id));
}
}
@@ -187,21 +187,19 @@ function forum_update_instance($forum, $mform) {
$cm = get_coursemodule_from_instance('forum', $forum->id);
$modcontext = context_module::instance($cm->id, MUST_EXIST);
- if ($mform and $draftid = file_get_submitted_draft_itemid('introeditor')) {
- // ugly hack - we need to copy the files somehow
- $discussion = $DB->get_record('forum_discussions', array('id'=>$discussion->id), '*', MUST_EXIST);
- $post = $DB->get_record('forum_posts', array('id'=>$discussion->firstpost), '*', MUST_EXIST);
-
- $post->message = file_save_draft_area_files($draftid, $modcontext->id, 'mod_forum', 'post', $post->id,
- mod_forum_post_form::editor_options(), $post->message);
- }
-
+ $post = $DB->get_record('forum_posts', array('id'=>$discussion->firstpost), '*', MUST_EXIST);
$post->subject = $forum->name;
$post->message = $forum->intro;
$post->messageformat = $forum->introformat;
$post->messagetrust = trusttext_trusted($modcontext);
$post->modified = $forum->timemodified;
- $post->userid = $USER->id; // MDL-18599, so that current teacher can take ownership of activities
+ $post->userid = $USER->id; // MDL-18599, so that current teacher can take ownership of activities.
+
+ if ($mform and $draftid = file_get_submitted_draft_itemid('introeditor')) {
+ // Ugly hack - we need to copy the files somehow.
+ $options = array('subdirs'=>true); // Use the same options as intro field!
+ $post->message = file_save_draft_area_files($draftid, $modcontext->id, 'mod_forum', 'post', $post->id, $options, $post->message);
+ }
$DB->update_record('forum_posts', $post);
$discussion->name = $forum->name;
@@ -3327,15 +3325,23 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa
if (!$post->parent && $forum->type == 'news' && $discussion->timestart > time()) {
$age = 0;
}
- if (($ownpost && $age < $CFG->maxeditingtime) || $cm->cache->caps['mod/forum:editanypost']) {
+
+ if ($forum->type == 'single' and $discussion->firstpost == $post->id) {
+ if (has_capability('moodle/course:manageactivities', $modcontext)) {
+ // The first post in single simple is the forum description.
+ $commands[] = array('url'=>new moodle_url('/course/modedit.php', array('update'=>$cm->id, 'sesskey'=>sesskey(), 'return'=>1)), 'text'=>$str->edit);
+ }
+ } else if (($ownpost && $age < $CFG->maxeditingtime) || $cm->cache->caps['mod/forum:editanypost']) {
$commands[] = array('url'=>new moodle_url('/mod/forum/post.php', array('edit'=>$post->id)), 'text'=>$str->edit);
}
if ($cm->cache->caps['mod/forum:splitdiscussions'] && $post->parent && $forum->type != 'single') {
$commands[] = array('url'=>new moodle_url('/mod/forum/post.php', array('prune'=>$post->id)), 'text'=>$str->prune, 'title'=>$str->pruneheading);
}
- if (($ownpost && $age < $CFG->maxeditingtime && $cm->cache->caps['mod/forum:deleteownpost']) || $cm->cache->caps['mod/forum:deleteanypost']) {
+ if ($forum->type == 'single' and $discussion->firstpost == $post->id) {
+ // Do not allow deleting of first post in single simple type.
+ } else if (($ownpost && $age < $CFG->maxeditingtime && $cm->cache->caps['mod/forum:deleteownpost']) || $cm->cache->caps['mod/forum:deleteanypost']) {
$commands[] = array('url'=>new moodle_url('/mod/forum/post.php', array('delete'=>$post->id)), 'text'=>$str->delete);
}

0 comments on commit 599e7fe

Please sign in to comment.