Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'w50_MDL-37111_m23_forumsinglefirst' of git://github.com…

…/skodak/moodle into MOODLE_23_STABLE
  • Loading branch information...
commit 59fc0958d6f0069518d135d4ddf99037e32c70c7 2 parents b3f4616 + 372bfa2
@samhemelryk samhemelryk authored
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));
}
}
@@ -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);
}
Please sign in to comment.
Something went wrong with that request. Please try again.