return record_exists('forum_posts','discussion',$did,'userid',$userid);
}
-function forum_user_can_post_discussion($forum, $currentgroup=false, $groupmode='') {
+function forum_user_can_post_discussion($forum, $currentgroup=false, $groupmode=false) {
// $forum is an object
global $USER, $SESSION;
return false;
}
- if ($forum->type == "eachuser") {
+ if ($forum->type == 'eachuser') {
return (!forum_user_has_posted_discussion($forum->id, $USER->id));
} else if ($currentgroup) {
return (has_capability('moodle/site:accessallgroups', $context)
/// If it's a grouped discussion, make sure the user is a member
if ($discussion->groupid > 0) {
- if ($cm->groupmode == SEPARATEGROUPS) {
- return ismember($discussion->groupid) ||
- has_capability('moodle/site:accessallgroups', $modcontext);
+ $groupmode = groupmode($course, $cm);
+ if ($groupmode == SEPARATEGROUPS) {
+ return ismember($discussion->groupid) || has_capability('moodle/site:accessallgroups', $modcontext);
}
}
return true;
/// First check the group stuff
if ($groupmode == -1) { /// We need to reconstruct groupmode because none was given
- if ($cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) {
- $groupmode = groupmode($course, $cm);
- } else {
- $groupmode = SEPARATEGROUPS;
- }
+ $cm = get_coursemodule_from_instance('forum', $forum->id, $course->id);
+ $groupmode = groupmode($course, $cm); // Works even if $cm is not valid
}
if ($currentgroup == -1) { /// We need to reconstruct currentgroup because none was given
$currentgroup = get_current_group($course->id);
}
- if (!$currentgroup and ($groupmode != SEPARATEGROUPS or
- has_capability('moodle/site:accessallgroups', $context)) ) {
+ if (!$currentgroup and
+ ($groupmode != SEPARATEGROUPS or has_capability('moodle/site:accessallgroups', $context)) ) {
$visiblegroups = -1;
} else {
$visiblegroups = $currentgroup;
/// button for it. We do not show the button if we are showing site news
/// and the current user is a guest.
- // TODO: Add group mode in there, to test for visible group.
if (forum_user_can_post_discussion($forum, $currentgroup, $groupmode)) {
echo '<div class="singlebutton forumaddnew">';
-?>
\ No newline at end of file
+?>