本文整理汇总了PHP中groupmode函数的典型用法代码示例。如果您正苦于以下问题:PHP groupmode函数的具体用法?PHP groupmode怎么用?PHP groupmode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了groupmode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: jclic_get_students
function jclic_get_students($cm, $course, $jclicid)
{
global $CFG;
$version_moodle = (double) substr($CFG->release, 0, 3);
if ($version_moodle >= 1.7) {
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$currentgroup = get_and_set_current_group($course, groupmode($course, $cm));
$users = get_users_by_capability($context, 'mod/jclic:submit', 'u.id, u.id', '', '', '', $currentgroup, '', false);
$dbstudents = array();
if (!empty($users)) {
$select = 'SELECT u.id AS userid, u.firstname, u.lastname, u.picture ';
$sql = 'FROM ' . $CFG->prefix . 'user u ' . 'LEFT JOIN ' . $CFG->prefix . 'jclic_sessions a ON u.id = a.user_id AND a.jclicid = ' . $jclicid . ' ' . 'WHERE u.id IN (' . implode(',', array_keys($users)) . ') ';
$dbstudents = get_records_sql($select . $sql);
}
} else {
$dbstudents = get_records_sql("SELECT DISTINCT us.userid, u.firstname, u.lastname\n \t\t\t\t FROM {$CFG->prefix}user u,{$CFG->prefix}user_students us, {$CFG->prefix}jclic j\n \t\t\t\t WHERE us.course=j.course AND j.id={$jclicid} AND u.id=us.userid");
}
return $dbstudents;
}
示例2: course_setup
}
// call course_setup to use forced language, MDL-6926
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;
示例3: dialogue_get_available_teachers
/**
* Return a list of teachers that the current user is able to open a dialogue with
*
* Called by dialogue_get_available_users(). The list is used to populate a drop-down
* list in the UI. The returned array of usernames is filtered to hide teacher names
* if those teachers have a hidden role assignment, unless the list is being returned
* for a teacher in which case those hidden teachers are listed
* @param object $dialogue
* @param object $context for a user in this activity
* @param int $editconversationid
* @return array usernames and ids
*/
function dialogue_get_available_teachers($dialogue, $context, $editconversationid = 0)
{
global $USER, $CFG;
$canseehidden = has_capability('moodle/role:viewhiddenassigns', $context);
if (!($course = get_record('course', 'id', $dialogue->course))) {
error('Course is misconfigured');
}
if (!($cm = get_coursemodule_from_instance('dialogue', $dialogue->id, $course->id))) {
error('Course Module ID was incorrect');
}
// get the list of teachers (actually, those who have dialogue:manage capability)
$hiddenTeachers = array();
if ($users = get_users_by_capability($context, 'mod/dialogue:manage', '', null, null, null, null, null, null, true, null)) {
foreach ($users as $user) {
$userRoles = get_user_roles($context, $user->id, true);
foreach ($userRoles as $role) {
if ($role->hidden == 1) {
$hiddenTeachers[$user->id] = 1;
break;
}
}
}
$canSeeHidden = false;
if (has_capability('moodle/role:viewhiddenassigns', $context)) {
$canSeeHidden = true;
}
$groupid = get_current_group($course->id);
foreach ($users as $otheruser) {
// ...exclude self and ...
if ($USER->id != $otheruser->id) {
// ...if groupmode is SEPARATEGROUPS then exclude teachers not in student's group
if ($groupid and groupmode($course, $cm) == SEPARATEGROUPS) {
if (!ismember($groupid, $otheruser->id)) {
continue;
}
}
if (!$canSeeHidden && array_key_exists($otheruser->id, $hiddenTeachers) && $hiddenTeachers[$otheruser->id] == 1) {
continue;
}
// ...any already in open conversations unless multiple conversations allowed
if ($dialogue->multipleconversations or count_records_select('dialogue_conversations', "dialogueid = {$dialogue->id} AND id != {$editconversationid} AND ((userid = {$USER->id} AND \n recipientid = {$otheruser->id}) OR (userid = {$otheruser->id} AND \n recipientid = {$USER->id})) AND closed = 0") == 0) {
$names[$otheruser->id] = fullname($otheruser);
}
}
}
}
if (isset($names)) {
natcasesort($names);
return $names;
}
return;
}
示例4: feedback_email_teachers
function feedback_email_teachers($cm, $feedback, $course, $userid)
{
global $CFG;
if ($feedback->email_notification == 0) {
// No need to do anything
return;
}
$user = get_record('user', 'id', $userid);
if (groupmode($course, $cm) == SEPARATEGROUPS) {
// Separate groups are being used
if (!($group = user_group($course->id, $user->id))) {
// Try to find a group
$group->id = 0;
// Not in a group, never mind
}
$teachers = get_group_teachers($course->id, $group->id);
// Works even if not in group
} else {
$teachers = get_course_teachers($course->id);
}
if ($teachers) {
$strfeedbacks = get_string('modulenameplural', 'feedback');
$strfeedback = get_string('modulename', 'feedback');
$strcompleted = get_string('completed', 'feedback');
foreach ($teachers as $teacher) {
unset($info);
$info->username = fullname($user);
$info->feedback = format_string($feedback->name, true);
$info->url = $CFG->wwwroot . '/mod/feedback/show_entries.php?id=' . $cm->id . '&userid=' . $userid;
$postsubject = $strcompleted . ': ' . $info->username . ' -> ' . $feedback->name;
$posttext = feedback_email_teachers_text($info, $course);
$posthtml = $teacher->mailformat == 1 ? feedback_email_teachers_html($info, $course, $cm) : '';
@email_to_user($teacher, $user, $postsubject, $posttext, $posthtml);
}
}
}
示例5: display
/**
* Display the report.
*/
public function display($game, $cm, $course)
{
global $CFG, $SESSION, $DB;
// Define some strings.
$strreallydel = addslashes(get_string('deleteattemptcheck', 'game'));
$strtimeformat = get_string('strftimedatetime');
$strreviewquestion = get_string('reviewresponse', 'quiz');
// Only print headers if not asked to download data.
if (!($download = optional_param('download', null))) {
$this->print_header_and_tabs($cm, $course, $game, $reportmode = "overview");
}
// Deal with actions.
$action = optional_param('action', '', PARAM_ACTION);
switch ($action) {
case 'delete':
// Some attempts need to be deleted.
$attemptids = optional_param('attemptid', array(), PARAM_INT);
foreach ($attemptids as $attemptid) {
if ($attemptid && ($todelete = get_record('game_attempts', 'id', $attemptid))) {
delete_records('game_attempts', 'id', $attemptid);
delete_records('game_queries', 'attemptid', $attemptid);
// Search game_attempts for other instances by this user.
// If none, then delete record for this game, this user from game_grades.
// else recalculate best grade.
$userid = $todelete->userid;
if (!record_exists('game_attempts', 'userid', $userid, 'gameid', $game->id)) {
delete_records('game_grades', 'userid', $userid, 'gameid', $game->id);
} else {
game_save_best_score($game, $userid);
}
}
}
break;
}
// Print information on the number of existing attempts.
if (!$download) {
// Do not print notices when downloading.
if ($attemptnum = count_records('game_attempts', 'gameid', $game->id)) {
$a = new stdClass();
$a->attemptnum = $attemptnum;
$a->studentnum = count_records_select('game_attempts', "gameid = '{$game->id}' AND preview = '0'", 'COUNT(DISTINCT userid)');
$a->studentstring = $course->students;
notify(get_string('numattempts', 'game', $a));
}
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
// Find out current groups mode.
if ($groupmode = groupmode($course, $cm)) {
// Groups are being used.
if (!$download) {
$currentgroup = setup_and_print_groups($course, $groupmode, "report.php?id={$cm->id}&mode=overview");
} else {
$currentgroup = get_and_set_current_group($course, $groupmode);
}
} else {
$currentgroup = get_and_set_current_group($course, $groupmode);
}
// Set table options.
$noattempts = optional_param('noattempts', 0, PARAM_INT);
$detailedmarks = optional_param('detailedmarks', 0, PARAM_INT);
$pagesize = optional_param('pagesize', 10, PARAM_INT);
$hasfeedback = game_has_feedback($game->id) && $game->grade > 1.0E-7;
if ($pagesize < 1) {
$pagesize = 10;
}
// Now check if asked download of data.
if ($download) {
$filename = clean_filename("{$course->shortname} " . format_string($game->name, true));
$sort = '';
}
// Define table columns.
$tablecolumns = array('checkbox', 'picture', 'fullname', 'timestart', 'timefinish', 'duration');
$tableheaders = array(null, '', get_string('fullname'), get_string('startedon', 'game'), get_string('timecompleted', 'game'), get_string('attemptduration', 'game'));
if ($game->grade) {
$tablecolumns[] = 'grade';
$tableheaders[] = get_string('grade', 'game') . '/' . $game->grade;
}
if ($detailedmarks) {
// We want to display marks for all questions.
// Start by getting all questions.
$questionlist = game_questions_in_game($game->questions);
$questionids = explode(',', $questionlist);
$sql = "SELECT q.*, i.score AS maxgrade, i.id AS instance" . " FROM {question} q," . " {game_queries} i" . " WHERE i.gameid = '{$game->id}' AND q.id = i.questionid" . " AND q.id IN ({$questionlist})";
if (!($questions = get_records_sql($sql))) {
print_error('No questions found');
}
$number = 1;
foreach ($questionids as $key => $id) {
if ($questions[$id]->length) {
// Only print questions of non-zero length.
$tablecolumns[] = '$' . $id;
$tableheaders[] = '#' . $number;
$questions[$id]->number = $number;
$number += $questions[$id]->length;
} else {
// Get rid of zero length questions.
unset($questions[$id]);
//.........这里部分代码省略.........
示例6: hotpot_get_report_users
function hotpot_get_report_users($course, $formdata)
{
$users = array();
/// Check to see if groups are being used in this module
$groupmode = groupmode($course, $cm);
//TODO: there is no $cm defined!
$currentgroup = setup_and_print_groups($course, $groupmode, "report.php?id={$cm->id}&mode=simple");
$sort = "u.lastname ASC";
switch ($formdata['reportusers']) {
case 'students':
if ($currentgroup) {
$users = get_group_students($currentgroup, $sort);
} else {
$users = get_course_students($course->id, $sort);
}
break;
case 'all':
if ($currentgroup) {
$users = get_group_users($currentgroup, $sort);
} else {
$users = get_course_users($course->id, $sort);
}
break;
}
return $users;
}
示例7: modgroupmode_settings
/**
* This is called from modedit.php to load the default for the groupmode element.
*
* @param object $course
* @param object $cm
*/
function modgroupmode_settings()
{
global $COURSE;
return array('groupmode' => groupmode($COURSE, $this->_cm));
}
示例8: feedback_send_email
/**
* sends an email to the teachers of the course where the given feedback is placed.
*
* @global object
* @global object
* @uses FEEDBACK_ANONYMOUS_NO
* @uses FORMAT_PLAIN
* @param object $cm the coursemodule-record
* @param object $feedback
* @param object $course
* @param int $userid
* @return void
*/
function feedback_send_email($cm, $feedback, $course, $userid)
{
global $CFG, $DB;
if ($feedback->email_notification == 0) {
// No need to do anything
return;
}
$user = $DB->get_record('user', array('id' => $userid));
if (groupmode($course, $cm) == SEPARATEGROUPS) {
// Separate groups are being used
$groups = $DB->get_records_sql_menu("SELECT g.name, g.id\n FROM {groups} g, {groups_members} m\n WHERE g.courseid = ?\n AND g.id = m.groupid\n AND m.userid = ?\n ORDER BY name ASC", array($course->id, $userid));
$groups = array_values($groups);
$teachers = feedback_get_receivemail_users($cm->id, $groups);
} else {
$teachers = feedback_get_receivemail_users($cm->id);
}
if ($teachers) {
$strfeedbacks = get_string('modulenameplural', 'feedback');
$strfeedback = get_string('modulename', 'feedback');
$strcompleted = get_string('completed', 'feedback');
$printusername = $feedback->anonymous == FEEDBACK_ANONYMOUS_NO ? fullname($user) : get_string('anonymous_user', 'feedback');
foreach ($teachers as $teacher) {
$info = new object();
$info->username = $printusername;
$info->feedback = format_string($feedback->name, true);
$info->url = $CFG->wwwroot . '/mod/feedback/show_entries.php?id=' . $cm->id . '&userid=' . $userid . '&do_show=showentries';
$postsubject = $strcompleted . ': ' . $info->username . ' -> ' . $feedback->name;
$posttext = feedback_send_email_text($info, $course);
$posthtml = $teacher->mailformat == 1 ? feedback_send_email_html($info, $course, $cm) : '';
if ($feedback->anonymous == FEEDBACK_ANONYMOUS_NO) {
$eventdata = new object();
$eventdata->modulename = 'feedback';
$eventdata->userfrom = $user;
$eventdata->userto = $teacher;
$eventdata->subject = $postsubject;
$eventdata->fullmessage = $posttext;
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = $posthtml;
$eventdata->smallmessage = '';
if (events_trigger('message_send', $eventdata) > 0) {
}
} else {
$eventdata = new object();
$eventdata->modulename = 'feedback';
$eventdata->userfrom = $teacher;
$eventdata->userto = $teacher;
$eventdata->subject = $postsubject;
$eventdata->fullmessage = $posttext;
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = $posthtml;
$eventdata->smallmessage = '';
if (events_trigger('message_send', $eventdata) > 0) {
}
}
}
}
}
示例9: get_string
$strgradeitemadd = get_string('gradeitemadd', 'grades');
$strgradeitemremove = get_string('gradeitemremove', 'grades');
$strgradeiteminfo = get_string('gradeiteminfo', 'grades');
$strgradeiteminfopeople = get_string('gradeiteminfopeople', 'grades');
$strgradeitemrandomassign = get_string('gradeitemrandomassign', 'grades');
$strgradeitemaddusers = get_string('gradeitemaddusers', 'grades');
$strgradeitems = get_string('gradeitems', 'grades');
$courseid = $course->id;
$listgrade_items = array();
$listmembers = array();
$nonmembers = array();
$grade_items = array();
$grade_items = get_records('grade_item', 'courseid', $course->id);
$grade_itemcount = count($grade_items);
// get current group of students and assign that to be the working list of students
if (groupmode($course) != 0) {
if ($currentgroup = get_current_group($course->id)) {
//groupmode is either separate or visible and there is a group
$students = get_group_users($group);
} else {
//groupmode is either separate or visible and the current group is all participants
$students = grade_get_course_students($course->id);
}
} else {
$students = grade_get_course_students($course->id);
//groupmode is not set (all participants)
}
// we need to create a multidimensional array keyed by grade_itemid with all_students at each level
if (isset($grade_items)) {
foreach ($grade_items as $grade_item) {
$nonmembers[$grade_item->id] = array();
示例10: workshop_print_league_table
function workshop_print_league_table($workshop)
{
// print an order table of (student) submissions showing teacher's and student's assessments
if (!($course = get_record("course", "id", $workshop->course))) {
error("Print league table: Course is misconfigured");
}
if (!($cm = get_coursemodule_from_instance("workshop", $workshop->id, $workshop->course))) {
error("Course Module ID was incorrect");
}
// set $groupid if workshop is in SEPARATEGROUPS mode
if (groupmode($course, $cm) == SEPARATEGROUPS) {
$groupid = get_current_group($course->id);
} else {
$groupid = 0;
}
$nentries = $workshop->showleaguetable;
if ($workshop->anonymous and workshop_is_student($workshop)) {
$table->head = array(get_string("title", "workshop"), get_string("teacherassessments", "workshop", $course->teacher), get_string("studentassessments", "workshop", $course->student), get_string("overallgrade", "workshop"));
$table->align = array("left", "center", "center", "center");
$table->size = array("*", "*", "*", "*");
} else {
// show names
$table->head = array(get_string("title", "workshop"), get_string("name"), get_string("teacherassessments", "workshop", $course->teacher), get_string("studentassessments", "workshop", $course->student), get_string("overallgrade", "workshop"));
$table->align = array("left", "left", "center", "center", "center");
$table->size = array("*", "*", "*", "*", "*");
}
$table->cellpadding = 2;
$table->cellspacing = 0;
if ($submissions = workshop_get_student_submissions($workshop)) {
foreach ($submissions as $submission) {
if ($groupid) {
// check submission's group
if (!groups_is_member($groupid, $submission->userid)) {
continue;
// skip this submission
}
}
$grades[$submission->id] = workshop_submission_grade($workshop, $submission);
}
arsort($grades);
// largest grade first
reset($grades);
$n = 1;
while (list($submissionid, $grade) = each($grades)) {
if (!($submission = get_record("workshop_submissions", "id", $submissionid))) {
error("Print league table: submission not found");
}
if (!($user = get_record("user", "id", $submission->userid))) {
error("Print league table: user not found");
}
if ($workshop->anonymous and workshop_is_student($workshop)) {
$table->data[] = array(workshop_print_submission_title($workshop, $submission), workshop_print_submission_assessments($workshop, $submission, "teacher"), workshop_print_submission_assessments($workshop, $submission, "student"), $grade);
} else {
$table->data[] = array(workshop_print_submission_title($workshop, $submission), fullname($user), workshop_print_submission_assessments($workshop, $submission, "teacher"), workshop_print_submission_assessments($workshop, $submission, "student"), $grade);
}
$n++;
if ($n > $nentries) {
break;
}
}
print_heading(get_string("leaguetable", "workshop"));
print_table($table);
workshop_print_key($workshop);
}
}
示例11: certificate_email_teachers
function certificate_email_teachers($certificate)
{
global $course, $USER, $CFG;
if ($certificate->emailteachers == 0) {
// No need to do anything
return;
}
$certrecord = certificate_get_issue($course, $USER, $certificate->id);
$student = $certrecord->studentname;
$cm = get_coursemodule_from_instance("certificate", $certificate->id, $course->id);
if (groupmode($course, $cm) == SEPARATEGROUPS) {
// Separate groups are being used
if (!($group = user_group($course->id, $user->id))) {
// Try to find a group
$group->id = 0;
// Not in a group, never mind
}
$teachers = get_group_teachers($course->id, $group->id);
// Works even if not in group
} else {
$teachers = get_course_teachers($course->id);
}
if ($teachers) {
$strcertificates = get_string('modulenameplural', 'certificate');
$strcertificate = get_string('modulename', 'certificate');
$strawarded = get_string('awarded', 'certificate');
foreach ($teachers as $teacher) {
unset($info);
$info->student = $student;
$info->course = format_string($course->fullname, true);
$info->certificate = format_string($certificate->name, true);
$info->url = $CFG->wwwroot . '/mod/certificate/report.php?id=' . $cm->id;
$from = $student;
$postsubject = $strawarded . ': ' . $info->student . ' -> ' . $certificate->name;
$posttext = certificate_email_teachers_text($info);
$posthtml = certificate_email_teachers_html($info);
$posthtml = $teacher->mailformat == 1 ? certificate_email_teachers_html($info) : '';
@email_to_user($teacher, $from, $postsubject, $posttext, $posthtml);
// If it fails, oh well, too bad.
set_field("certificate_issues", "mailed", "1", "certificateid", $certificate->id, "userid", $USER->id);
}
}
}
示例12: forum_get_recent_mod_activity
/**
* Prepares array of recent activity in course forums
*
* Returns all forum posts since a given time. If forum and/or user is specified then
* this restricts the results.
*
* @param array &$activities An array of objects representing recent activites
* @param int &$index ???
* @param int $sincetime Searches only for a activitity since this timestamp
* @param int $courseid Searches only for a activitity in a given course module (default 0 means all)
* @param string $user Searches only for a user's activity (given by username)
* @param array $groupid Searches only for an activity in particular groups
* @return No return value but modifies &$activities and &$index
*/
function forum_get_recent_mod_activity(&$activities, &$index, $sincetime, $courseid, $cmid = "0", $user = "", $groupid = "")
{
global $CFG, $USER, $COURSE;
if ($cmid) {
$forumselect = " AND cm.id = '{$cmid}'";
} else {
$forumselect = "";
}
if ($user) {
$userselect = " AND u.id = '{$user}'";
} else {
$userselect = "";
}
if (is_numeric($groupid)) {
// the behaviour of mygroupid() has been changed so we are getting array now
$groupid = array($groupid);
}
$posts = get_records_sql("SELECT p.*, d.name, u.firstname, u.lastname, u.username,\n u.picture, d.groupid, cm.instance, f.name,\n cm.section, cm.id AS cmid\n FROM {$CFG->prefix}forum_posts p,\n {$CFG->prefix}forum_discussions d,\n {$CFG->prefix}user u,\n {$CFG->prefix}course_modules cm,\n {$CFG->prefix}forum f\n WHERE p.modified > '{$sincetime}' {$forumselect}\n AND p.userid = u.id {$userselect}\n AND d.course = '{$courseid}'\n AND p.discussion = d.id\n AND cm.instance = f.id\n AND cm.course = d.course\n AND cm.course = f.course\n AND f.id = d.forum\n ORDER BY p.discussion ASC,p.created ASC");
if (empty($posts)) {
return;
}
$groupmode = array();
// To cache group modes of particular forums
$cm = array();
// To cache course modules
$mygroupids = groups_get_groups_for_user($USER->id, $COURSE->id) or $mygroupids = array();
foreach ($posts as $post) {
$modcontext = get_context_instance(CONTEXT_MODULE, $post->cmid);
// Check whether this post belongs to a discussion in a group that
// should NOT be accessible to the current user
// Open discussions have groupid -1
if (!has_capability('moodle/site:accessallgroups', $modcontext) && $post->groupid != -1) {
if (!isset($cm[$post->cmid])) {
$cm[$post->cmid] = get_coursemodule_from_instance('forum', $post->cmid, $courseid);
}
if (!isset($groupmode[$post->cmid])) {
$groupmode[$post->cmid] = groupmode($COURSE, $cm[$post->cmid]);
}
if ($groupmode[$post->cmid] == SEPARATEGROUPS) {
if (!in_array($post->groupid, $mygroupids)) {
continue;
}
}
}
// the user wants to restrict results on selected group only
if (is_array($groupid) && !in_array($post->groupid, $groupid)) {
continue;
}
$tmpactivity = new Object();
$tmpactivity->type = "forum";
$tmpactivity->defaultindex = $index;
$tmpactivity->instance = $post->instance;
$tmpactivity->name = $post->name;
$tmpactivity->section = $post->section;
$tmpactivity->content->id = $post->id;
$tmpactivity->content->discussion = $post->discussion;
$tmpactivity->content->subject = $post->subject;
$tmpactivity->content->parent = $post->parent;
$tmpactivity->user->userid = $post->userid;
$tmpactivity->user->fullname = fullname($post);
$tmpactivity->user->picture = $post->picture;
$tmpactivity->timestamp = $post->modified;
$activities[] = $tmpactivity;
$index++;
}
return;
}
示例13: forum_menu_list
/**
* @todo Document this function
*/
function forum_menu_list($course)
{
$menu = array();
$currentgroup = get_and_set_current_group($course, groupmode($course));
if ($forums = get_all_instances_in_course("forum", $course)) {
if ($course->format == 'weeks') {
$strsection = get_string('week');
} else {
$strsection = get_string('topic');
}
foreach ($forums as $forum) {
if ($cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) {
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!isset($forum->visible)) {
if (!instance_is_visible("forum", $forum) && !has_capability('moodle/course:viewhiddenactivities', $context)) {
continue;
}
}
$groupmode = groupmode($course, $cm);
// Groups are being used
if ($groupmode == SEPARATEGROUPS && $currentgroup === false && !has_capability('moodle/site:accessallgroups', $context)) {
continue;
}
}
$menu[$forum->id] = format_string($forum->name, true);
}
}
return $menu;
}
示例14: array_unshift
$learningtable->align[] = 'center';
}
/// Now let's process the learning forums
if ($course->id != SITEID) {
// Only real courses have learning forums
// Add extra field for section number, at the front
if ($course->format == 'weeks' or $course->format == 'weekscss') {
array_unshift($learningtable->head, $strweek);
} else {
array_unshift($learningtable->head, $strsection);
}
array_unshift($learningtable->align, "center");
if ($learningforums) {
$currentsection = "";
foreach ($learningforums as $key => $forum) {
$groupmode = groupmode($course, $forum);
/// Can do this because forum->groupmode is defined
$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 ($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_OFF) {
$unreadlink = '-';
$trackedlink = '-';
} else {
if ($forum->trackingtype == FORUM_TRACKING_ON || !isset($untracked[$forum->id])) {
示例15: forum_check_text_access
/**
* this function handles the access policy to contents indexed as searchable documents. If this
* function does not exist, the search engine assumes access is allowed.
* When this point is reached, we already know that :
* - user is legitimate in the surrounding context
* - user may be guest and guest access is allowed to the module
* - the function may perform local checks within the module information logic
* @param path the access path to the module script code
* @param itemtype the information subclassing (usefull for complex modules, defaults to 'standard')
* @param this_id the item id within the information class denoted by itemtype. In forums, this id
* points out the individual post.
* @param user the user record denoting the user who searches
* @param group_id the current group used by the user when searching
* @uses CFG, USER
* @return true if access is allowed, false elsewhere
*/
function forum_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id)
{
global $CFG, $USER;
include_once "{$CFG->dirroot}/{$path}/lib.php";
// get the forum post and all related stuff
$post = get_record('forum_posts', 'id', $this_id);
$discussion = get_record('forum_discussions', 'id', $post->discussion);
$context = get_record('context', 'id', $context_id);
$cm = get_record('course_modules', 'id', $context->instanceid);
if (empty($cm)) {
return false;
}
// Shirai 20093005 - MDL19342 - course module might have been delete
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)) {
if (!empty($CFG->search_access_debug)) {
echo "search reject : hidden forum resource ";
}
return false;
}
// approval check : entries should be approved for being viewed, or belongs to the user
if ($post->userid != $USER->id && !$post->mailed && !has_capability('mod/forum:viewhiddentimeposts', $context)) {
if (!empty($CFG->search_access_debug)) {
echo "search reject : time hidden forum item";
}
return false;
}
// group check : entries should be in accessible groups
$current_group = get_current_group($discussion->course);
$course = get_record('course', 'id', $discussion->course);
if ($group_id >= 0 && groupmode($course, $cm) == SEPARATEGROUPS && $group_id != $current_group && !has_capability('mod/forum:viewdiscussionsfromallgroups', $context)) {
if (!empty($CFG->search_access_debug)) {
echo "search reject : separated grouped forum item";
}
return false;
}
return true;
}