MDL-18128 - forum - Addition of group editing for forums.
authoradrian@moodle.com <abgreeve@gmail.com>
Mon, 12 Dec 2011 06:21:59 +0000 (14:21 +0800)
committeradrian@moodle.com <abgreeve@gmail.com>
Wed, 21 Dec 2011 07:25:44 +0000 (15:25 +0800)
mod/forum/post.php
mod/forum/post_form.php

index 197d3c2..f3f2f82 100644 (file)
@@ -599,6 +599,8 @@ if ($fromform = $mform_post->get_data()) {
     // WARNING: the $fromform->message array has been overwritten, do not use it anymore!
     $fromform->messagetrust  = trusttext_trusted($modcontext);
 
+    $contextcheck = isset($fromform->groupinfo) && has_capability('mod/forum:movediscussions', $modcontext);
+
     if ($fromform->edit) {           // Updating a post
         unset($fromform->groupid);
         $fromform->id = $fromform->edit;
@@ -621,6 +623,11 @@ if ($fromform = $mform_post->get_data()) {
             print_error('cannotupdatepost', 'forum');
         }
 
+        // If the user has access to all groups and they are changing the group, then update the post.
+        if ($contextcheck) {
+            $DB->set_field('forum_discussions' ,'groupid' , $fromform->groupinfo, array('firstpost' => $fromform->id));
+        }
+
         $updatepost = $fromform; //realpost
         $updatepost->forum = $forum->id;
         if (!forum_update_post($updatepost, $mform_post, $message)) {
@@ -712,6 +719,10 @@ if ($fromform = $mform_post->get_data()) {
         if (!forum_user_can_post_discussion($forum, $fromform->groupid, -1, $cm, $modcontext)) {
             print_error('cannotcreatediscussion', 'forum');
         }
+        // If the user has access all groups capability let them choose the group.
+        if ($contextcheck) {
+            $fromform->groupid = $fromform->groupinfo;
+        }
         if (empty($fromform->groupid)) {
             $fromform->groupid = -1;
         }
index b26deaf..e3caa53 100644 (file)
@@ -112,15 +112,26 @@ class mod_forum_post_form extends moodleform {
         }
 
         if (groups_get_activity_groupmode($cm, $course)) { // hack alert
-            if (empty($post->groupid)) {
-                $groupname = get_string('allparticipants');
+            $groupdata = groups_get_activity_allowed_groups($cm);
+            $groupcount = count($groupdata);
+            $modulecontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+            $contextcheck = has_capability('mod/forum:movediscussions', $modulecontext) && empty($post->parent) && $groupcount > 1;
+            if ($contextcheck) {
+                $groupinfo = array('0' => get_string('allparticipants'));
+                foreach ($groupdata as $grouptemp) {
+                    $groupinfo[$grouptemp->id] = $grouptemp->name;
+                }
+                $mform->addElement('select','groupinfo', get_string('group'), $groupinfo);
+                $mform->setDefault('groupinfo', $post->groupid);
             } else {
-                $group = groups_get_group($post->groupid);
-                $groupname = format_string($group->name);
+                if (empty($post->groupid)) {
+                    $groupname = get_string('allparticipants');
+                } else {
+                    $groupname = format_string($groupdata[$post->groupid]->name);
+                }
+                $mform->addElement('static', 'groupinfo', get_string('group'), $groupname);
             }
-            $mform->addElement('static', 'groupinfo', get_string('group'), $groupname);
         }
-
         //-------------------------------------------------------------------------------
         // buttons
         if (isset($post->edit)) { // hack alert