Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-18128 - forum - Addition of group editing for forums.

  • Loading branch information...
commit 72682b886895e963a7602deaff9df83e989da711 1 parent acb3bf8
Adrian Greeve abgreeve authored

Showing 2 changed files with 28 additions and 6 deletions. Show diff stats Hide diff stats

  1. +11 0 mod/forum/post.php
  2. +17 6 mod/forum/post_form.php
11 mod/forum/post.php
@@ -599,6 +599,8 @@
599 599 // WARNING: the $fromform->message array has been overwritten, do not use it anymore!
600 600 $fromform->messagetrust = trusttext_trusted($modcontext);
601 601
  602 + $contextcheck = isset($fromform->groupinfo) && has_capability('mod/forum:movediscussions', $modcontext);
  603 +
602 604 if ($fromform->edit) { // Updating a post
603 605 unset($fromform->groupid);
604 606 $fromform->id = $fromform->edit;
@@ -621,6 +623,11 @@
621 623 print_error('cannotupdatepost', 'forum');
622 624 }
623 625
  626 + // If the user has access to all groups and they are changing the group, then update the post.
  627 + if ($contextcheck) {
  628 + $DB->set_field('forum_discussions' ,'groupid' , $fromform->groupinfo, array('firstpost' => $fromform->id));
  629 + }
  630 +
624 631 $updatepost = $fromform; //realpost
625 632 $updatepost->forum = $forum->id;
626 633 if (!forum_update_post($updatepost, $mform_post, $message)) {
@@ -712,6 +719,10 @@
712 719 if (!forum_user_can_post_discussion($forum, $fromform->groupid, -1, $cm, $modcontext)) {
713 720 print_error('cannotcreatediscussion', 'forum');
714 721 }
  722 + // If the user has access all groups capability let them choose the group.
  723 + if ($contextcheck) {
  724 + $fromform->groupid = $fromform->groupinfo;
  725 + }
715 726 if (empty($fromform->groupid)) {
716 727 $fromform->groupid = -1;
717 728 }
23 mod/forum/post_form.php
@@ -112,15 +112,26 @@ function definition() {
112 112 }
113 113
114 114 if (groups_get_activity_groupmode($cm, $course)) { // hack alert
115   - if (empty($post->groupid)) {
116   - $groupname = get_string('allparticipants');
  115 + $groupdata = groups_get_activity_allowed_groups($cm);
  116 + $groupcount = count($groupdata);
  117 + $modulecontext = get_context_instance(CONTEXT_MODULE, $cm->id);
  118 + $contextcheck = has_capability('mod/forum:movediscussions', $modulecontext) && empty($post->parent) && $groupcount > 1;
  119 + if ($contextcheck) {
  120 + $groupinfo = array('0' => get_string('allparticipants'));
  121 + foreach ($groupdata as $grouptemp) {
  122 + $groupinfo[$grouptemp->id] = $grouptemp->name;
  123 + }
  124 + $mform->addElement('select','groupinfo', get_string('group'), $groupinfo);
  125 + $mform->setDefault('groupinfo', $post->groupid);
117 126 } else {
118   - $group = groups_get_group($post->groupid);
119   - $groupname = format_string($group->name);
  127 + if (empty($post->groupid)) {
  128 + $groupname = get_string('allparticipants');
  129 + } else {
  130 + $groupname = format_string($groupdata[$post->groupid]->name);
  131 + }
  132 + $mform->addElement('static', 'groupinfo', get_string('group'), $groupname);
120 133 }
121   - $mform->addElement('static', 'groupinfo', get_string('group'), $groupname);
122 134 }
123   -
124 135 //-------------------------------------------------------------------------------
125 136 // buttons
126 137 if (isset($post->edit)) { // hack alert

0 comments on commit 72682b8

Please sign in to comment.
Something went wrong with that request. Please try again.