Skip to content

Commit

Permalink
MDL-13936 fixed group handling when adding new discussions; merged fr…
Browse files Browse the repository at this point in the history
…om MOODLE_19_STABLE
  • Loading branch information
skodak committed Apr 14, 2008
1 parent 4136c23 commit 89d35c4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 27 deletions.
5 changes: 3 additions & 2 deletions mod/forum/lib.php
Expand Up @@ -63,6 +63,7 @@ function forum_add_instance($forum) {
$discussion->assessed = $forum->assessed;
$discussion->format = $forum->type;
$discussion->mailnow = false;
$discussion->groupid = -1;

if (! forum_add_discussion($discussion, $discussion->intro)) {
error('Could not add the discussion for this forum');
Expand Down Expand Up @@ -4194,7 +4195,7 @@ function forum_user_has_posted($forumid, $did, $userid) {
/**
*
*/
function forum_user_can_post_discussion($forum, $currentgroup=-1, $unused=-1, $cm=NULL, $context=NULL) {
function forum_user_can_post_discussion($forum, $currentgroup=null, $unused=-1, $cm=NULL, $context=NULL) {
// $forum is an object
global $USER;

Expand All @@ -4219,7 +4220,7 @@ function forum_user_can_post_discussion($forum, $currentgroup=-1, $unused=-1, $c
return false;
}

if ($currentgroup == -1) {
if ($currentgroup === null) {
$currentgroup = groups_get_activity_group($cm);
}

Expand Down
40 changes: 18 additions & 22 deletions mod/forum/post.php
Expand Up @@ -13,6 +13,7 @@
$prune = optional_param('prune', 0, PARAM_INT);
$name = optional_param('name', '', PARAM_CLEAN);
$confirm = optional_param('confirm', 0, PARAM_INT);
$groupid = optional_param('groupid', null, PARAM_INT);


//these page_params will be passed as hidden variables later in the form.
Expand Down Expand Up @@ -80,7 +81,7 @@

$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);

if (! forum_user_can_post_discussion($forum, -1, -1, $cm)) {
if (! forum_user_can_post_discussion($forum, $groupid, -1, $cm)) {
if (has_capability('moodle/legacy:guest', $coursecontext, NULL, false)) { // User is a guest here!
$SESSION->wantsurl = $FULLME;
$SESSION->enrolcancel = $_SERVER['HTTP_REFERER'];
Expand Down Expand Up @@ -112,14 +113,12 @@
$post->userid = $USER->id;
$post->message = '';

if ($groupmode = groups_get_activity_groupmode($cm)) {
$post->groupid = groups_get_activity_group($cm);
if (empty($post->groupid)) {
$post->groupid = -1;
}
if (isset($groupid)) {
$post->groupid = $groupid;
} else {
$post->groupid = null;
$post->groupid = groups_get_activity_group($cm);
}

forum_set_return();

} else if (!empty($reply)) { // User is writing a new reply
Expand Down Expand Up @@ -153,11 +152,10 @@
}
}

if (groupmode($course, $cm) == SEPARATEGROUPS) { // Make sure user can post here
// Make sure user can post here
if (groupmode($course, $cm) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $modcontext)) {
if ($discussion->groupid == -1) {
if (!has_capability('moodle/site:accessallgroups', $modcontext)) {
print_error('nopostforum', 'forum');
}
print_error('nopostforum', 'forum');
} else {
if (!groups_is_member($discussion->groupid)) {
print_error('nopostforum', 'forum');
Expand All @@ -180,11 +178,7 @@
$post->userid = $USER->id;
$post->message = '';

if ($groupmode = groups_get_activity_groupmode($cm)) {
$post->groupid = $discussion->groupid;
} else {
$post->groupid = null;
}
$post->groupid = ($discussion->groupid == -1) ? 0 : $discussion->groupid;

$strre = get_string('re', 'forum');
if (!(substr($post->subject, 0, strlen($strre)) == $strre)) {
Expand Down Expand Up @@ -234,11 +228,7 @@
$post->edit = $edit;
$post->course = $course->id;
$post->forum = $forum->id;
if ($groupmode = groups_get_activity_groupmode($cm)) {
$post->groupid = $discussion->groupid;
} else {
$post->groupid = null;
}
$post->groupid = ($discussion->groupid == -1) ? 0 : $discussion->groupid;

trusttext_prepare_edit($post->message, $post->format, can_use_html_editor(), $modcontext);

Expand Down Expand Up @@ -469,6 +459,7 @@
trusttext_after_edit($fromform->message, $modcontext);

if ($fromform->edit) { // Updating a post
unset($fromform->groupid);
$fromform->id = $fromform->edit;
$message = '';

Expand Down Expand Up @@ -530,6 +521,7 @@


} else if ($fromform->discussion) { // Adding a new post to an existing discussion
unset($fromform->groupid);
$message = '';
$addpost=$fromform;
$addpost->forum=$forum->id;
Expand Down Expand Up @@ -574,6 +566,10 @@
if (!forum_user_can_post_discussion($forum, $fromform->groupid, -1, $cm, $modcontext)) {
error('Can not add discussion, sorry.');
}
if (empty($fromform->groupid)) {
$fromform->groupid = -1;
}

$fromform->mailnow = empty($fromform->mailnow) ? 0 : 1;
$discussion = $fromform;
$discussion->name = $fromform->subject;
Expand Down Expand Up @@ -681,7 +677,7 @@
if (!empty($parent) && !forum_user_can_see_post($forum, $discussion, $post, null, $cm)) {
error("You cannot reply to this post");
}
if (empty($parent) && empty($edit) && !forum_user_can_post_discussion($forum, -1, -1, $cm, $modcontext)) {
if (empty($parent) && empty($edit) && !forum_user_can_post_discussion($forum, $groupid, -1, $cm, $modcontext)) {
error("You cannot start a new discussion in this forum");
}

Expand Down
4 changes: 2 additions & 2 deletions mod/forum/post_form.php
Expand Up @@ -82,8 +82,8 @@ function definition() {
$mform->setConstants(array('timestart'=> 0, 'timeend'=>0));
}

if (groups_get_activity_groupmode($cm, $course) and !empty($post->groupid)) { // hack alert
if ($post->groupid == -1) {
if (groups_get_activity_groupmode($cm, $course)) { // hack alert
if (empty($post->groupid)) {
$groupname = get_string('allparticipants');
} else {
$group = groups_get_group($post->groupid);
Expand Down
2 changes: 1 addition & 1 deletion mod/forum/view.php
Expand Up @@ -239,7 +239,7 @@
print_box(format_text($forum->intro), 'generalbox', 'intro');
}
echo '<p align="center">';
if (forum_user_can_post_discussion($forum, -1, -1, $cm)) {
if (forum_user_can_post_discussion($forum, null, -1, $cm)) {
print_string("allowsdiscussions", "forum");
} else {
echo '&nbsp;';
Expand Down

0 comments on commit 89d35c4

Please sign in to comment.