Skip to content

Commit

Permalink
MDL-18128 - forum - Addition of group editing for forums.
Browse files Browse the repository at this point in the history
  • Loading branch information
abgreeve committed Dec 21, 2011
1 parent acb3bf8 commit 72682b8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
11 changes: 11 additions & 0 deletions mod/forum/post.php
Expand Up @@ -599,6 +599,8 @@
// WARNING: the $fromform->message array has been overwritten, do not use it anymore! // WARNING: the $fromform->message array has been overwritten, do not use it anymore!
$fromform->messagetrust = trusttext_trusted($modcontext); $fromform->messagetrust = trusttext_trusted($modcontext);


$contextcheck = isset($fromform->groupinfo) && has_capability('mod/forum:movediscussions', $modcontext);

if ($fromform->edit) { // Updating a post if ($fromform->edit) { // Updating a post
unset($fromform->groupid); unset($fromform->groupid);
$fromform->id = $fromform->edit; $fromform->id = $fromform->edit;
Expand All @@ -621,6 +623,11 @@
print_error('cannotupdatepost', 'forum'); 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 = $fromform; //realpost
$updatepost->forum = $forum->id; $updatepost->forum = $forum->id;
if (!forum_update_post($updatepost, $mform_post, $message)) { if (!forum_update_post($updatepost, $mform_post, $message)) {
Expand Down Expand Up @@ -712,6 +719,10 @@
if (!forum_user_can_post_discussion($forum, $fromform->groupid, -1, $cm, $modcontext)) { if (!forum_user_can_post_discussion($forum, $fromform->groupid, -1, $cm, $modcontext)) {
print_error('cannotcreatediscussion', 'forum'); 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)) { if (empty($fromform->groupid)) {
$fromform->groupid = -1; $fromform->groupid = -1;
} }
Expand Down
23 changes: 17 additions & 6 deletions mod/forum/post_form.php
Expand Up @@ -112,15 +112,26 @@ function definition() {
} }


if (groups_get_activity_groupmode($cm, $course)) { // hack alert if (groups_get_activity_groupmode($cm, $course)) { // hack alert
if (empty($post->groupid)) { $groupdata = groups_get_activity_allowed_groups($cm);
$groupname = get_string('allparticipants'); $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 { } else {
$group = groups_get_group($post->groupid); if (empty($post->groupid)) {
$groupname = format_string($group->name); $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 // buttons
if (isset($post->edit)) { // hack alert if (isset($post->edit)) { // hack alert
Expand Down

0 comments on commit 72682b8

Please sign in to comment.