예제 #1
0
/**
 * Gets the current group - either from the session variable or from the database.
 *
 * @global object
 * @param int $courseid The course being examined - relates to id field in
 * 'course' table.
 * @param bool $full If true, the return value is a full record object.
 * If false, just the id of the record.
 * @return int|bool
 */
function get_current_group($courseid, $full = false) {
    global $SESSION;

    if (isset($SESSION->currentgroup[$courseid])) {
        if ($full) {
            return groups_get_group($SESSION->currentgroup[$courseid]);
        } else {
            return $SESSION->currentgroup[$courseid];
        }
    }

    $mygroupid = mygroupid($courseid);
    if (is_array($mygroupid)) {
        $mygroupid = array_shift($mygroupid);
        set_current_group($courseid, $mygroupid);
        if ($full) {
            return groups_get_group($mygroupid);
        } else {
            return $mygroupid;
        }
    }

    if ($full) {
        return false;
    } else {
        return 0;
    }
}
예제 #2
0
 course_setup($course->id);
 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
 $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
 if (!forum_user_can_post($forum)) {
     if (has_capability('moodle/legacy:guest', $coursecontext, NULL, false)) {
         // User is a guest here!
         $SESSION->wantsurl = $FULLME;
         $SESSION->enrolcancel = $_SERVER['HTTP_REFERER'];
         redirect($CFG->wwwroot . '/course/enrol.php?id=' . $course->id, get_string('youneedtoenrol'));
     } else {
         print_error('nopostforum', 'forum');
     }
 }
 if (groupmode($course, $cm)) {
     // Make sure user can post here
     $mygroupid = mygroupid($course->id);
     if (!((empty($mygroupid) and $discussion->groupid == -1) || ismember($discussion->groupid) || has_capability('moodle/site:accessallgroups', $modcontext, NULL, false))) {
         print_error('nopostdiscussion', 'forum');
     }
 }
 if (!$cm->visible and !has_capability('moodle/course:manageactivities', $coursecontext)) {
     error(get_string("activityiscurrentlyhidden"));
 }
 // Load up the $post variable.
 $post = new object();
 $post->course = $course->id;
 $post->forum = $forum->id;
 $post->discussion = $parent->discussion;
 $post->parent = $parent->id;
 $post->subject = $parent->subject;
 $post->userid = $USER->id;
예제 #3
0
 } else {
     array_unshift($learningtable->head, $strsection);
 }
 array_unshift($learningtable->align, "center");
 if ($learningforums) {
     $currentsection = "";
     foreach ($learningforums as $key => $forum) {
         $forum->visible = instance_is_visible("forum", $forum) || has_capability('moodle/course:view', $coursecontext);
         $cm = get_coursemodule_from_instance("forum", $forum->id, $course->id);
         $context = get_context_instance(CONTEXT_MODULE, $cm->id);
         if (!groups_course_module_visible($cm)) {
             continue;
         }
         $currentgroup = groups_get_activity_group($cm);
         $groupmode = groups_get_activity_groupmode($cm);
         $cantaccessagroup = $groupmode and !has_capability('moodle/site:accessallgroups', $context) and !mygroupid($course->id);
         if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
             $count = count_records("forum_discussions", "forum", "{$forum->id}", "groupid", $currentgroup);
         } else {
             $count = count_records("forum_discussions", "forum", "{$forum->id}");
         }
         if ($usetracking) {
             if ($forum->trackingtype == FORUM_TRACKING_ON || !isset($untracked[$forum->id])) {
                 $groupid = $groupmode == SEPARATEGROUPS && !has_capability('moodle/site:accessallgroups', $context) ? $currentgroup : false;
                 $unread = forum_tp_count_forum_unread_posts($USER->id, $forum->id, $groupid);
                 if ($unread > 0) {
                     $unreadlink = '<span class="unread"><a href="view.php?f=' . $forum->id . '">' . $unread . '</a>';
                     $unreadlink .= '<a title="' . $strmarkallread . '" href="markposts.php?f=' . $forum->id . '&amp;mark=read"><img src="' . $CFG->pixpath . '/t/clear.gif" alt="' . $strmarkallread . '" /></a></span>';
                 } else {
                     $unreadlink = '<span class="read"><a href="view.php?f=' . $forum->id . '">' . $unread . '</a></span>';
                 }
예제 #4
0
/**
 * Gets the current group - either from the session variable or from the database.
 *
 * @deprecated Since year 2006 - please do not use this function any more.
 * @todo MDL-50273 This will be deleted in Moodle 3.2.
 *
 * @global object
 * @param int $courseid The course being examined - relates to id field in
 * 'course' table.
 * @param bool $full If true, the return value is a full record object.
 * If false, just the id of the record.
 * @return int|bool
 */
function get_current_group($courseid, $full = false)
{
    global $SESSION;
    debugging('get_current_group() is deprecated, please use groups_get_* instead', DEBUG_DEVELOPER);
    if (isset($SESSION->currentgroup[$courseid])) {
        if ($full) {
            return groups_get_group($SESSION->currentgroup[$courseid]);
        } else {
            return $SESSION->currentgroup[$courseid];
        }
    }
    $mygroupid = mygroupid($courseid);
    if (is_array($mygroupid)) {
        $mygroupid = array_shift($mygroupid);
        set_current_group($courseid, $mygroupid);
        if ($full) {
            return groups_get_group($mygroupid);
        } else {
            return $mygroupid;
        }
    }
    if ($full) {
        return false;
    } else {
        return 0;
    }
}
예제 #5
0
파일: lib.php 프로젝트: kai707/ITSA-backup
function get_feedback_groupid($course, $cm)
{
    $groupmode = groupmode($course, $cm);
    //get groupid
    if ($groupmode > 0 && !isadmin()) {
        return mygroupid($course->id);
    } else {
        return false;
    }
}
예제 #6
0
파일: lib.php 프로젝트: nadavkav/MoodleTAO
function wiki_user_can_access_teacher_wiki(&$wiki, $groupid, &$course)
{
    global $USER;
    /// Get the groupmode. It's been added to the wiki object.
    $groupmode = groups_get_activity_groupmode($wiki);
    /// A user can access a teacher wiki, if:
    ///     - group mode is NOGROUPS,
    ///     - group mode is VISIBLEGROUPS,
    ///     - group mode is SEPARATEGROUPS, and they are a member of the requested group,
    ///     - they are a teacher or administrator,
    if ($groupmode == NOGROUPS or $groupmode == VISIBLEGROUPS or $groupmode == SEPARATEGROUPS and @in_array($groupid, mygroupid($course->id)) or wiki_is_teacher($wiki, $USER->id)) {
        $can_access = true;
    } else {
        $can_access = false;
    }
    return $can_access;
}
예제 #7
0
/**
 * Given a course and a date, prints a summary of all the new
 * messages posted in the course since that date
 */
function forum_print_recent_activity($course, $isteacher, $timestart)
{
    global $CFG;
    $LIKE = sql_ilike();
    $heading = false;
    $content = false;
    if (!($logs = get_records_select('log', 'time > \'' . $timestart . '\' AND ' . 'course = \'' . $course->id . '\' AND ' . 'module = \'forum\' AND ' . 'action ' . $LIKE . ' \'add %\' ', 'time ASC'))) {
        return false;
    }
    $strftimerecent = get_string('strftimerecent');
    $mygroupid = mygroupid($course->id);
    $groupmode = array();
    // To cache group modes
    $count = 0;
    foreach ($logs as $log) {
        //Get post info, I'll need it later
        if ($post = forum_get_post_from_log($log)) {
            //Create a temp valid module structure (course,id)
            $tempmod = new object();
            $tempmod->course = $log->course;
            $tempmod->id = $post->forum;
            //Obtain the visible property from the instance
            $coursecontext = get_context_instance(CONTEXT_COURSE, $tempmod->course);
            $modvisible = instance_is_visible('forum', $tempmod) || has_capability('moodle/course:viewhiddenactivities', $coursecontext);
        }
        //Only if the post exists and mod is visible
        if ($post && $modvisible) {
            if (!isset($cm[$post->forum])) {
                $cm[$post->forum] = get_coursemodule_from_instance('forum', $post->forum, $course->id);
            }
            $modcontext = get_context_instance(CONTEXT_MODULE, $cm[$post->forum]->id);
            // Check whether this is belongs to a discussion in a group that
            // should NOT be accessible to the current user
            if (!has_capability('moodle/site:accessallgroups', $modcontext) && $post->groupid != -1) {
                // Open discussions have groupid -1
                $groupmode[$post->forum] = groups_get_activity_groupmode($cm[$post->forum]);
                if ($groupmode[$post->forum]) {
                    //hope i didn't break anything
                    if (!@in_array($mygroupid, $post->groupid)) {
                        continue;
                    }
                }
            }
            if (!$heading) {
                print_headline(get_string('newforumposts', 'forum') . ':', 3);
                $heading = true;
                $content = true;
            }
            $date = userdate($post->modified, $strftimerecent);
            $subjectclass = $log->action == 'add discussion' ? ' bold' : '';
            //Accessibility: markup as a list.
            if ($count < 1) {
                echo "\n<ul class='unlist'>\n";
            }
            $count++;
            echo '<li><div class="head">' . '<div class="date">' . $date . '</div>' . '<div class="name">' . fullname($post, has_capability('moodle/site:viewfullnames', $coursecontext)) . '</div>' . '</div>';
            echo '<div class="info' . $subjectclass . '">';
            echo '"<a href="' . $CFG->wwwroot . '/mod/forum/' . str_replace('&', '&amp;', $log->url) . '">';
            $post->subject = break_up_long_words(format_string($post->subject, true));
            echo $post->subject;
            echo "</a>\"</div></li>\n";
        }
    }
    echo "</ul>\n";
    return $content;
}
예제 #8
0
} else {
    $cm->id = 0;
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
}
if ($user) {
    if (!has_capability('mod/forum:managesubscriptions', $context)) {
        error('You do not have the permission to subscribe/unsubscribe other people!');
    }
    if (!($user = get_record("user", "id", $user))) {
        error("User ID was incorrect");
    }
} else {
    $user = $USER;
}
if (groupmode($course, $cm) and !forum_is_subscribed($user->id, $forum->id) and !has_capability('moodle/site:accessallgroups', $context)) {
    if (!mygroupid($course->id)) {
        error('Sorry, but you must be a group member to subscribe.');
    }
}
require_login($course->id, false, $cm);
if (isguest()) {
    // Guests can't subscribe
    $wwwroot = $CFG->wwwroot . '/login/index.php';
    if (!empty($CFG->loginhttps)) {
        $wwwroot = str_replace('http:', 'https:', $wwwroot);
    }
    $navigation = build_navigation('', $cm);
    print_header($course->shortname, $course->fullname, $navigation, '', '', true, "", user_login_string($course) . '<hr style="width:95%">' . navmenu($course, $cm));
    notice_yesno(get_string('noguestsubscribe', 'forum') . '<br /><br />' . get_string('liketologin'), $wwwroot, $_SERVER['HTTP_REFERER']);
    print_footer($course);
    exit;