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.
This commit is contained in:
+21
-15
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -193,21 +193,19 @@ function forum_update_instance($forum, $mform) {
|
||||
$cm = get_coursemodule_from_instance('forum', $forum->id);
|
||||
$modcontext = get_context_instance(CONTEXT_MODULE, $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;
|
||||
@@ -3331,7 +3329,13 @@ 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);
|
||||
}
|
||||
|
||||
@@ -3339,7 +3343,9 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa
|
||||
$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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user