本文整理汇总了PHP中get_current_group函数的典型用法代码示例。如果您正苦于以下问题:PHP get_current_group函数的具体用法?PHP get_current_group怎么用?PHP get_current_group使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_current_group函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: webquestscorm
/**
* Constructor for the webquestscorm class
*
* Constructor for the base assignment class.
* If cmid is set create the cm, course, assignment objects.
* If the assignment is hidden and the user is not a teacher then
* this prints a page header and notice.
*
* @param cmid integer, the current course module id - not set for new assignments
* @param assignment object, usually null, but if we have it we pass it to save db access
* @param cm object, usually null, but if we have it we pass it to save db access
* @param course object, usually null, but if we have it we pass it to save db access
*/
function webquestscorm($cmid = 0, $webquestscorm = NULL, $cm = NULL, $course = NULL)
{
global $CFG;
if ($cmid) {
if ($cm) {
$this->cm = $cm;
} else {
if (!($this->cm = get_coursemodule_from_id('webquestscorm', $cmid))) {
error('Course Module ID was incorrect');
}
}
$this->context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
if ($course) {
$this->course = $course;
} else {
if (!($this->course = get_record('course', 'id', $this->cm->course))) {
error('Course is misconfigured');
}
}
if ($webquestscorm) {
$this->webquestscorm = $webquestscorm;
} else {
if (!($this->webquestscorm = get_record('webquestscorm', 'id', $this->cm->instance))) {
error('webquestscorm ID was incorrect');
}
}
$this->strwebquestscorm = get_string('modulename', 'webquestscorm');
$this->strwebquestscorms = get_string('modulenameplural', 'webquestscorm');
$this->strsubmissions = get_string('submissions', 'webquestscorm');
$this->strlastmodified = get_string('lastmodified');
if ($this->course->category) {
$this->navigation = "<a target=\"{$CFG->framename}\" href=\"{$CFG->wwwroot}/course/view.php?id={$this->course->id}\">{$this->course->shortname}</a> -> " . "<a target=\"{$CFG->framename}\" href=\"index.php?id={$this->course->id}\">{$this->strwebquestscorms}</a> ->";
} else {
$this->navigation = "<a target=\"{$CFG->framename}\" href=\"index.php?id={$this->course->id}\">{$this->strwebquestscorms}</a> ->";
}
$this->pagetitle = strip_tags($this->course->shortname . ': ' . $this->strwebquestscorm . ': ' . format_string($this->webquestscorm->name, true));
// visibility
$this->context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
if (!$this->cm->visible and !has_capability('moodle/course:viewhiddenactivities', $this->context)) {
$this->pagetitle = strip_tags($this->course->shortname . ': ' . $this->strwebquestscorm);
print_header($this->pagetitle, $this->course->fullname, "{$this->navigation} {$this->strwebquestscorm}", "", "", true, '', navmenu($this->course, $this->cm));
notice(get_string("activityiscurrentlyhidden"), "{$CFG->wwwroot}/course/view.php?id={$this->course->id}");
}
$this->currentgroup = get_current_group($this->course->id);
$this->path = $CFG->dataroot . '/' . $this->cm->course . '/moddata/webquestscorm' . '/' . $this->cm->id;
}
if ($this->usehtmleditor = can_use_html_editor()) {
$this->defaultformat = FORMAT_HTML;
} else {
$this->defaultformat = FORMAT_MOODLE;
}
}
示例2: journal_user_complete_index
function journal_user_complete_index($course, $user, $journal, $journalopen, $heading)
{
/// Prints a journal, entry and feedback ... used on the journal index page.
if (isteacher($course->id)) {
$entrycount = journal_count_entries($journal, get_current_group($course->id));
$entryinfo = " (<a href=\"report.php?id={$journal->coursemodule}\">" . get_string("viewallentries", "journal", $entrycount) . "</a>)";
} else {
$entryinfo = "";
}
$journal->name = "<a href=\"view.php?id={$journal->coursemodule}\">" . format_string($journal->name, true) . "</a>";
if ($heading) {
echo "<h3>{$heading} - {$journal->name}{$entryinfo}</h3>";
} else {
echo "<h3>{$journal->name}{$entryinfo}</h3>";
}
print_simple_box_start("left", "90%");
echo format_text($journal->intro, $journal->introformat);
print_simple_box_end();
echo "<br clear=\"all\" />";
echo "<br />";
if (isstudent($course->id) or isteacher($course->id)) {
print_simple_box_start("right", "90%");
if ($journalopen) {
echo "<p align=\"right\"><a href=\"edit.php?id={$journal->coursemodule}\">";
echo get_string("edit") . "</a></p>";
} else {
echo "<p align=\"right\"><a href=\"view.php?id={$journal->coursemodule}\">";
echo get_string("view") . "</a></p>";
}
if ($entry = get_record("journal_entries", "userid", $user->id, "journal", $journal->id)) {
if ($entry->modified) {
echo "<p align=\"center\"><font size=\"1\">" . get_string("lastedited") . ": " . userdate($entry->modified) . "</font></p>";
}
if ($entry->text) {
echo format_text($entry->text, $entry->format);
}
if ($entry->teacher) {
$grades = make_grades_menu($journal->assessed);
journal_print_feedback($course, $entry, $grades);
}
} else {
print_string("noentry", "journal");
}
print_simple_box_end();
echo "<br clear=\"all\" />";
echo "<br />";
}
}
示例3: choice_show_results
function choice_show_results($choice, $course, $cm, $forcepublish = '')
{
global $CFG, $COLUMN_HEIGHT, $USER;
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
print_heading(get_string("responses", "choice"));
if (empty($forcepublish)) {
//alow the publish setting to be overridden
$forcepublish = $choice->publish;
}
$groupmode = groupmode($course, $cm);
if ($groupmode > 0) {
$currentgroup = get_current_group($course->id);
} else {
$currentgroup = 0;
}
$users = get_users_by_capability($context, 'mod/choice:choose', 'u.id, u.picture, u.firstname, u.lastname, u.idnumber', 'u.firstname ASC', '', '', $currentgroup, '', false, true);
if (!$users) {
print_heading(get_string("nousersyet"));
}
$answers = array();
if ($allresponses = get_records("choice_answers", "choiceid", $choice->id)) {
foreach ($allresponses as $aa) {
//TODO: rewrite with SQL
if ($groupmode and $currentgroup) {
if (ismember($currentgroup, $aa->userid)) {
$answers[$aa->userid] = $aa;
}
} else {
$answers[$aa->userid] = $aa;
}
}
}
$timenow = time();
foreach ($choice->option as $optionid => $text) {
$useranswer[$optionid] = array();
}
if (!empty($users)) {
foreach ($users as $user) {
if (!empty($user->id) and !empty($answers[$user->id])) {
$answer = $answers[$user->id];
$useranswer[(int) $answer->optionid][] = $user;
} else {
$useranswer[0][] = $user;
}
}
}
foreach ($choice->option as $optionid => $text) {
if (!$choice->option[$optionid]) {
unset($useranswer[$optionid]);
// Throw away any data that doesn't apply
}
}
ksort($useranswer);
switch ($forcepublish) {
case CHOICE_PUBLISH_NAMES:
$tablewidth = (int) (100.0 / count($useranswer));
if (has_capability('mod/choice:readresponses', $context)) {
echo '<div id="tablecontainer">';
echo '<form id="attemptsform" method="post" action="' . $_SERVER['PHP_SELF'] . '" onsubmit="var menu = document.getElementById(\'menuaction\'); return (menu.options[menu.selectedIndex].value == \'delete\' ? \'' . addslashes(get_string('deleteattemptcheck', 'quiz')) . '\' : true);">';
echo '<div>';
echo '<input type="hidden" name="id" value="' . $cm->id . '" />';
echo '<input type="hidden" name="mode" value="overview" />';
}
echo "<table cellpadding=\"5\" cellspacing=\"10\" class=\"results names\">";
echo "<tr>";
$count = 0;
$columncount = array();
// number of votes in each column
foreach ($useranswer as $optionid => $userlist) {
$columncount[$optionid] = 0;
// init counters
if ($optionid) {
echo "<th class=\"col{$count} header\" style=\"width:{$tablewidth}%\" scope=\"col\">";
} else {
if ($choice->showunanswered) {
echo "<th class=\"col{$count} header\" style=\"width:{$tablewidth}%\" scope=\"col\">";
} else {
continue;
}
}
echo format_string(choice_get_option_text($choice, $optionid));
echo "</th>";
$count++;
}
echo "</tr><tr>";
$count = 0;
foreach ($useranswer as $optionid => $userlist) {
if ($optionid) {
echo "<td class=\"col{$count} data\" style=\"width:{$tablewidth}%;\">";
} else {
if ($choice->showunanswered) {
echo "<td class=\"col{$count} data\" style=\"width:{$tablewidth}%;\">";
} else {
continue;
}
}
// added empty row so that when the next iteration is empty,
// we do not get <table></table> erro from w3c validator
// MDL-7861
echo "<table class=\"choiceresponse\"><tr><td></td></tr>";
//.........这里部分代码省略.........
示例4: 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;
}
示例5: build_logs_array
function build_logs_array($course, $user = 0, $date = 0, $order = "l.time ASC", $limitfrom = '', $limitnum = '', $modname = "", $modid = 0, $modaction = "", $groupid = 0)
{
// It is assumed that $date is the GMT time of midnight for that day,
// and so the next 86400 seconds worth of logs are printed.
/// Setup for group handling.
/// If the group mode is separate, and this user does not have editing privileges,
/// then only the user's group can be viewed.
if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
$groupid = get_current_group($course->id);
} else {
if (!$course->groupmode) {
$groupid = 0;
}
}
$joins = array();
if ($course->id != SITEID || $modid != 0) {
$joins[] = "l.course='{$course->id}'";
}
if ($modname) {
$joins[] = "l.module = '{$modname}'";
}
if ('site_errors' === $modid) {
$joins[] = "( l.action='error' OR l.action='infected' )";
} else {
if ($modid) {
$joins[] = "l.cmid = '{$modid}'";
}
}
if ($modaction) {
$firstletter = substr($modaction, 0, 1);
if (preg_match('/[[:alpha:]]/', $firstletter)) {
$joins[] = "lower(l.action) LIKE '%" . strtolower($modaction) . "%'";
} else {
if ($firstletter == '-') {
$joins[] = "lower(l.action) NOT LIKE '%" . strtolower(substr($modaction, 1)) . "%'";
}
}
}
/// Getting all members of a group.
if ($groupid and !$user) {
if ($gusers = groups_get_members($groupid)) {
$gusers = array_keys($gusers);
$joins[] = 'l.userid IN (' . implode(',', $gusers) . ')';
} else {
$joins[] = 'l.userid = 0';
// No users in groups, so we want something that will always be false.
}
} else {
if ($user) {
$joins[] = "l.userid = '{$user}'";
}
}
if ($date) {
$enddate = $date + 86400;
$joins[] = "l.time > '{$date}' AND l.time < '{$enddate}'";
}
$selector = implode(' AND ', $joins);
$totalcount = 0;
// Initialise
$result = array();
$result['logs'] = get_logs($selector, $order, $limitfrom, $limitnum, $totalcount);
$result['totalcount'] = $totalcount;
return $result;
}
示例6: get_string
$strweek = get_string('week');
$strtopic = get_string('topic');
$strissued = get_string('issued', 'certificate');
if ($course->format == 'weeks') {
$table->head = array($strweek, $strname, $strissued);
$table->align = array('CENTER', 'LEFT');
} else {
if ($course->format == 'topics') {
$table->head = array($strtopic, $strname, $strissued);
$table->align = array('CENTER', 'LEFT', 'LEFT', 'LEFT');
} else {
$table->head = array($strname, $strissued);
$table->align = array('LEFT', 'LEFT', 'LEFT');
}
}
$currentgroup = get_current_group($course->id);
if ($currentgroup and has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_COURSE, $id))) {
$group = get_record('groups', 'id', $currentgroup);
$groupname = " ({$group->name})";
} else {
$groupname = "";
}
$currentsection = "";
foreach ($certificates as $certificate) {
if (!$certificate->visible) {
//Show dimmed if the mod is hidden
$link = "<a class=\"dimmed\" href=\"view.php?id={$certificate->coursemodule}\">{$certificate->name}</a>";
} else {
//Show normal if the mod is visible
$link = "<a href=\"view.php?id={$certificate->coursemodule}\">{$certificate->name}</a>";
}
示例7: 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;
}
示例8: print_mnet_log_selector_form
function print_mnet_log_selector_form($hostid, $course, $selecteduser = 0, $selecteddate = 'today', $modname = "", $modid = 0, $modaction = '', $selectedgroup = -1, $showcourses = 0, $showusers = 0)
{
global $USER, $CFG, $SITE;
require_once $CFG->dirroot . '/mnet/peer.php';
$mnet_peer = new mnet_peer();
$mnet_peer->set_id($hostid);
$sql = "select distinct course, hostid, coursename from {$CFG->prefix}mnet_log";
$courses = get_records_sql($sql);
$remotecoursecount = count($courses);
// first check to see if we can override showcourses and showusers
$numcourses = $remotecoursecount + count_records_select("course", "", "COUNT(id)");
if ($numcourses < COURSE_MAX_COURSES_PER_DROPDOWN && !$showcourses) {
$showcourses = 1;
}
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
// Context for remote data is always SITE
// Groups for remote data are always OFF
if ($hostid == $CFG->mnet_localhost_id) {
$context = get_context_instance(CONTEXT_COURSE, $course->id);
/// Setup for group handling.
if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
$selectedgroup = get_current_group($course->id);
$showgroups = false;
} else {
if ($course->groupmode) {
$selectedgroup = $selectedgroup == -1 ? get_current_group($course->id) : $selectedgroup;
$showgroups = true;
} else {
$selectedgroup = 0;
$showgroups = false;
}
}
} else {
$context = $sitecontext;
}
// Get all the possible users
$users = array();
// If looking at a different host, we're interested in all our site users
if ($hostid == $CFG->mnet_localhost_id && $course->id != SITEID) {
if ($selectedgroup) {
// If using a group, only get users in that group.
$courseusers = get_group_users($selectedgroup, 'u.lastname ASC', '', 'u.id, u.firstname, u.lastname, u.idnumber');
} else {
$courseusers = get_course_users($course->id, '', '', 'u.id, u.firstname, u.lastname, u.idnumber');
}
} else {
$courseusers = get_site_users("u.lastaccess DESC", "u.id, u.firstname, u.lastname, u.idnumber");
}
if (count($courseusers) < COURSE_MAX_USERS_PER_DROPDOWN && !$showusers) {
$showusers = 1;
}
if ($showusers) {
if ($courseusers) {
foreach ($courseusers as $courseuser) {
$users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', $context));
}
}
if ($guest = get_guest()) {
$users[$guest->id] = fullname($guest);
}
}
// Get all the hosts that have log records
$sql = "select distinct\n h.id,\n h.name\n from\n {$CFG->prefix}mnet_host h,\n {$CFG->prefix}mnet_log l\n where\n h.id = l.hostid\n order by\n h.name";
$hostarray = array();
$dropdown = array();
if ($hosts = get_records_sql($sql)) {
foreach ($hosts as $host) {
$hostarray[$host->id] = $host->name;
}
}
$hostarray[$CFG->mnet_localhost_id] = $SITE->fullname;
asort($hostarray);
// $hostid already exists
foreach ($hostarray as $hostid_ => $name) {
$courses = array();
$sites = array();
if (has_capability('moodle/site:viewreports', $context) && $showcourses) {
if ($CFG->mnet_localhost_id == $hostid_) {
if ($ccc = get_records("course", "", "", "fullname", "id,fullname,category")) {
foreach ($ccc as $cc) {
if ($cc->id == SITEID) {
$sites["{$hostid_}/{$cc->id}"] = format_string($cc->fullname) . ' (' . get_string('site') . ')';
} else {
$courses["{$hostid_}/{$cc->id}"] = format_string($cc->fullname);
}
}
}
} else {
$sql = "select distinct course, coursename from mdl_mnet_log where hostid = '{$hostid_}'";
if ($ccc = get_records_sql($sql)) {
foreach ($ccc as $cc) {
if (1 == $cc->course) {
// TODO: MDL-8187 : this might be wrong - site course may have another id
$sites["{$hostid_}/{$cc->course}"] = $cc->coursename . ' (' . get_string('site') . ')';
} else {
$courses["{$hostid_}/{$cc->course}"] = $cc->coursename;
}
}
}
}
//.........这里部分代码省略.........
示例9: exercise_print_league_table
function exercise_print_league_table($exercise)
{
// print an order table of (student) submissions in grade order, only print the student's best submission when
// there are multiple submissions
if (!($course = get_record("course", "id", $exercise->course))) {
error("Print league table: Course is misconfigured");
}
$groupid = get_current_group($course->id);
$nentries = $exercise->showleaguetable;
if ($nentries == 99) {
$nentries = 999999;
// a large number
}
if ($exercise->anonymous and isstudent($course->id)) {
$table->head = array(get_string("title", "exercise"), get_string("grade"));
$table->align = array("left", "center");
$table->size = array("*", "*");
} else {
// show names
$table->head = array(get_string("title", "exercise"), get_string("name"), get_string("grade"));
$table->align = array("left", "left", "center");
$table->size = array("*", "*", "*");
}
$table->cellpadding = 2;
$table->cellspacing = 0;
if ($submissions = exercise_get_student_submissions($exercise, "grade", $groupid)) {
$n = 1;
foreach ($submissions as $submission) {
if (empty($done[$submission->userid])) {
if ($submission->late) {
continue;
}
if (!($user = get_record("user", "id", $submission->userid))) {
error("Print league table: user not found");
}
if ($exercise->anonymous and isstudent($course->id)) {
$table->data[] = array(exercise_print_submission_title($exercise, $submission), number_format($submission->grade * $exercise->grade / 100.0, 1));
} else {
$table->data[] = array(exercise_print_submission_title($exercise, $submission), fullname($user), number_format($submission->grade * $exercise->grade / 100.0, 1));
}
$n++;
if ($n > $nentries) {
break;
}
$done[$submission->userid] = 'ok';
}
}
print_heading(get_string("leaguetable", "exercise"));
print_table($table);
}
}
示例10: grade_download
function grade_download($download, $id)
{
global $CFG;
require_login();
if (!($course = get_record("course", "id", $id))) {
error("Course ID was incorrect");
}
require_capability('moodle/course:viewcoursegrades', get_context_instance(CONTEXT_COURSE, $id));
$strgrades = get_string("grades");
$strgrade = get_string("grade");
$strmax = get_string("maximumshort");
$stractivityreport = get_string("activityreport");
/// Check to see if groups are being used in this course
$currentgroup = get_current_group($course->id);
if (($currentgroup = get_current_group($course->id)) && groupmode($course) != 0) {
$students = get_group_students($currentgroup, "u.lastname ASC");
} else {
$students = grade_get_course_students($course->id);
}
if (!empty($students)) {
foreach ($students as $student) {
$grades[$student->id] = array();
// Collect all grades in this array
$gradeshtml[$student->id] = array();
// Collect all grades html formatted in this array
$totals[$student->id] = array();
// Collect all totals in this array
}
}
$columns = array();
// Accumulate column names in this array.
$columnhtml = array();
// Accumulate column html in this array.
/// Collect modules data
get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
/// Search through all the modules, pulling out grade data
$sections = get_all_sections($course->id);
// Sort everything the same as the course
for ($i = 0; $i <= $course->numsections; $i++) {
if (isset($sections[$i])) {
// should always be true
$section = $sections[$i];
if ($section->sequence) {
$sectionmods = explode(",", $section->sequence);
foreach ($sectionmods as $sectionmod) {
$mod = $mods[$sectionmod];
$instance = get_record("{$mod->modname}", "id", "{$mod->instance}");
$libfile = "{$CFG->dirroot}/mod/{$mod->modname}/lib.php";
if (file_exists($libfile)) {
require_once $libfile;
$gradefunction = $mod->modname . "_grades";
if (function_exists($gradefunction)) {
// Skip modules without grade function
if ($modgrades = $gradefunction($mod->instance)) {
if (!empty($modgrades->maxgrade)) {
if ($mod->visible) {
$maxgrade = "{$strmax}: {$modgrades->maxgrade}";
} else {
$maxgrade = "{$strmax}: {$modgrades->maxgrade}";
}
} else {
$maxgrade = "";
}
$columns[] = "{$mod->modfullname}: " . format_string($instance->name, true) . " - {$maxgrade}";
if (!empty($students)) {
foreach ($students as $student) {
if (!empty($modgrades->grades[$student->id])) {
$grades[$student->id][] = $currentstudentgrade = $modgrades->grades[$student->id];
} else {
$grades[$student->id][] = $currentstudentgrade = "";
$gradeshtml[$student->id][] = "";
}
if (!empty($modgrades->maxgrade)) {
$totals[$student->id] = (double) $totals[$student->id] + (double) $currentstudentgrade;
} else {
$totals[$student->id] = (double) $totals[$student->id] + 0;
}
}
}
}
}
}
}
}
}
}
// a new Moodle nesting record? ;-)
/// OK, we have all the data, now present it to the user
/// OK, we have all the data, now present it to the user
if ($download == "ods" and confirm_sesskey()) {
require_once "../lib/odslib.class.php";
/// Calculate file name
$downloadfilename = clean_filename("{$course->shortname} {$strgrades}.ods");
/// Creating a workbook
$workbook = new MoodleODSWorkbook("-");
/// Sending HTTP headers
$workbook->send($downloadfilename);
/// Adding the worksheet
$myxls =& $workbook->add_worksheet($strgrades);
/// Print names of all the fields
//.........这里部分代码省略.........
示例11: data_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 databases, this id
* points out an indexed data record page.
* @param user the user record denoting the user who searches
* @param group_id the current group used by the user when searching
* @return true if access is allowed, false elsewhere
*/
function data_check_text_access($path, $itemtype, $this_id, $user, $group_id, $context_id)
{
global $CFG;
// get the database object and all related stuff
if ($itemtype == 'record') {
$record = get_record('data_records', 'id', $this_id);
} elseif ($itemtype == 'comment') {
$comment = get_record('data_comments', 'id', $this_id);
$record = get_record('data_records', 'id', $comment->recordid);
} else {
// we do not know what type of information is required
return false;
}
$data = get_record('data', 'id', $record->dataid);
$course = get_record('course', 'id', $data->course);
$module_context = get_record('context', 'id', $context_id);
$cm = get_record('course_modules', 'id', $module_context->instanceid);
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $module_context)) {
return false;
}
//group consistency check : checks the following situations about groups
// trap if user is not same group and groups are separated
$current_group = get_current_group($course->id);
if (groupmode($course) == SEPARATEGROUPS && !groups_is_member($group_id) && !has_capability('moodle/site:accessallgroups', $module_context)) {
return false;
}
//ownership check : checks the following situations about user
// trap if user is not owner and has cannot see other's entries
if ($itemtype == 'record') {
if ($user->id != $record->userid && !has_capability('mod/data:viewentry', $module_context) && !has_capability('mod/data:manageentries', $module_context)) {
return false;
}
}
//approval check
// trap if unapproved and has not approval capabilities
// TODO : report a potential capability lack of : mod/data:approve
$approval = get_field('data_records', 'approved', 'id', $record->id);
if (!$approval && !isteacher($data->course) && !has_capability('mod/data:manageentries', $module_context)) {
return false;
}
//minimum records to view check
// trap if too few records
// TODO : report a potential capability lack of : mod/data:viewhiddenentries
$recordsAmount = count_records('data_records', 'dataid', $data->id);
if ($data->requiredentriestoview > $recordsAmount && !isteacher($data->course) && !has_capability('mod/data:manageentries', $module_context)) {
return false;
}
//opening periods check
// trap if user has not capability to see hidden records and date is out of opening range
// TODO : report a potential capability lack of : mod/data:viewhiddenentries
$now = usertime(time());
if ($data->timeviewfrom > 0) {
if ($now < $data->timeviewfrom && !isteacher($data->course) && !has_capability('mod/data:manageentries', $module_context)) {
return false;
}
}
if ($data->timeviewto > 0) {
if ($now > $data->timeviewto && !isteacher($data->course) && !has_capability('mod/data:manageentries', $module_context)) {
return false;
}
}
return true;
}
示例12: get_questions
function get_questions()
{
global $conn;
$sql = 'select * from vcn_data' . (get_current_group() ? ' where group_id="' . get_current_group()->id . '"' : '');
$rs = mysql_query($sql);
return $rs;
}
示例13: print_section
//.........这里部分代码省略.........
if ($ismoving) {
if ($mod->id == $USER->activitycopy) {
echo "</li>\n";
continue;
}
echo '<a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&sesskey=' . $USER->sesskey . '">' . '<img class="movetarget" src="' . $CFG->pixpath . '/movehere.gif" ' . ' alt="' . $strmovehere . '" /></a><br />
';
}
$instancename = urldecode($modinfo[$modnumber]->name);
$instancename = format_string($instancename, true, $course->id);
if (!empty($modinfo[$modnumber]->extra)) {
$extra = urldecode($modinfo[$modnumber]->extra);
} else {
$extra = "";
}
if (!empty($modinfo[$modnumber]->icon)) {
$icon = "{$CFG->pixpath}/" . urldecode($modinfo[$modnumber]->icon);
} else {
$icon = "{$CFG->modpixpath}/{$mod->modname}/icon.gif";
}
if ($mod->indent) {
print_spacer(12, 20 * $mod->indent, false);
}
if ($mod->modname == "label") {
if (!$mod->visible) {
echo "<span class=\"dimmed_text\">";
}
echo format_text($extra, FORMAT_HTML, $labelformatoptions);
if (!$mod->visible) {
echo "</span>";
}
} else {
// Normal activity
//Accessibility: for files get description via icon.
$altname = '';
if ('resource' == $mod->modname) {
if (!empty($modinfo[$modnumber]->icon)) {
$possaltname = $modinfo[$modnumber]->icon;
$mimetype = mimeinfo_from_icon('type', $possaltname);
$altname = get_mimetype_description($mimetype);
//get_string($mimetype, 'mimetypes');
} else {
$altname = $mod->modfullname;
}
} else {
$altname = $mod->modfullname;
}
// Avoid unnecessary duplication.
if (false !== stripos($instancename, $altname)) {
$altname = '';
}
// File type after name, for alphabetic lists.
if ($altname) {
$altname = get_accesshide(' ' . $altname);
}
$linkcss = $mod->visible ? "" : " class=\"dimmed\" ";
echo '<a ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . '<img src="' . $icon . '" class="activityicon" alt="" /> <span>' . $instancename . $altname . '</span></a>';
}
if ($usetracking && $mod->modname == 'forum') {
$groupmode = groupmode($course, $mod);
$groupid = $groupmode == SEPARATEGROUPS && !has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id)) ? get_current_group($course->id) : false;
if (forum_tp_can_track_forums() && !isset($untracked[$mod->instance])) {
$unread = forum_tp_count_forum_unread_posts($USER->id, $mod->instance, $groupid);
if ($unread) {
echo '<span class="unread"> <a href="' . $CFG->wwwroot . '/mod/forum/view.php?id=' . $mod->id . '">';
if ($unread == 1) {
echo $strunreadpostsone;
} else {
print_string('unreadpostsnumber', 'forum', $unread);
}
echo '</a> </span>';
}
}
}
if ($isediting) {
// TODO: we must define this as mod property!
if ($groupbuttons and $mod->modname != 'label' and $mod->modname != 'resource' and $mod->modname != 'glossary') {
if (!($mod->groupmodelink = $groupbuttonslink)) {
$mod->groupmode = $course->groupmode;
}
} else {
$mod->groupmode = false;
}
echo ' ';
echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section);
}
echo "</li>\n";
}
}
} elseif ($ismoving) {
echo "<ul class=\"section\">\n";
}
if ($ismoving) {
echo '<li><a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&sesskey=' . $USER->sesskey . '">' . '<img class="movetarget" src="' . $CFG->pixpath . '/movehere.gif" ' . ' alt="' . $strmovehere . '" /></a></li>
';
}
if (!empty($section->sequence) || $ismoving) {
echo "</ul><!--class='section'-->\n\n";
}
}
示例14: display_submission
/**
* Display a single submission, ready for grading on a popup window
*
* This default method prints the teacher info and submissioncomment box at the top and
* the student info and submission at the bottom.
* This method also fetches the necessary data in order to be able to
* provide a "Next submission" button.
* Calls preprocess_submission() to give assignment type plug-ins a chance
* to process submissions before they are graded
* This method gets its arguments from the page parameters userid and offset
*/
function display_submission($extra_javascript = '')
{
global $CFG;
$userid = optional_param('userid', PARAM_INT);
$offset = required_param('offset', PARAM_INT);
//offset for where to start looking for student.
//echo '<p>userid: '.$userid;
if (!($user = get_record('user', 'id', $userid))) {
error('No such user!');
}
if (!($submission = $this->get_submission($user->id))) {
$submission = $this->prepare_new_submission($userid);
}
if ($submission->timemodified > $submission->timemarked) {
$subtype = 'webquestscormnew';
} else {
$subtype = 'webquestscormold';
}
/// Get all teachers and students
$currentgroup = get_current_group($this->course->id);
if ($currentgroup) {
$users = get_group_users($currentgroup);
} else {
$users = get_users_by_capability($this->context, 'mod/webquestscorm:submit');
//$users = get_course_users($this->course->id);
}
$select = 'SELECT u.id, u.firstname, u.lastname, u.picture,
s.id AS submissionid, s.grade, s.submissioncomment,
s.timemodified, s.timemarked ';
$sql = 'FROM ' . $CFG->prefix . 'user u ' . 'LEFT JOIN ' . $CFG->prefix . 'webquestscorm_submissions s ON u.id = s.userid
AND s.webquestscorm = ' . $this->wqid . ' ' . 'WHERE u.id IN (' . implode(',', array_keys($users)) . ') ';
require_once $CFG->libdir . '/tablelib.php';
if ($sort = flexible_table::get_sql_sort('mod-webquestscorm-submissions')) {
$sort = 'ORDER BY ' . $sort . ' ';
}
$nextid = 0;
if (($auser = get_records_sql($select . $sql . $sort, $offset + 1, 1)) !== false) {
$nextuser = array_shift($auser);
/// Calculate user status
$nextuser->status = $nextuser->timemarked > 0 && $nextuser->timemarked >= $nextuser->timemodified;
$nextid = $nextuser->id;
}
print_header(get_string('feedback', 'webquestscorm') . ':' . fullname($user, true) . ':' . format_string($this->wqname));
/// Print any extra javascript needed for saveandnext
echo $extra_javascript;
///SOme javascript to help with setting up >.>
echo '<script type="text/javascript">' . "\n";
echo 'function setNext(){' . "\n";
echo 'document.submitform.mode.value=\'next\';' . "\n";
echo 'document.submitform.userid.value="' . $nextid . '";' . "\n";
echo '}' . "\n";
echo 'function saveNext(){' . "\n";
echo 'document.submitform.mode.value=\'saveandnext\';' . "\n";
echo 'document.submitform.userid.value="' . $nextid . '";' . "\n";
echo 'document.submitform.saveuserid.value="' . $userid . '";' . "\n";
echo 'document.submitform.menuindex.value = document.submitform.grade.selectedIndex;' . "\n";
echo '}' . "\n";
echo '</script>' . "\n";
echo '<table cellspacing="0" class="feedback ' . $subtype . '" >';
///Start of teacher info row
echo '<tr>';
echo '<td width="35" valign="top" class="picture teacher">';
if ($submission->teacher) {
$teacher = get_record('user', 'id', $submission->teacher);
} else {
global $USER;
$teacher = $USER;
}
print_user_picture($teacher->id, $this->course->id, $teacher->picture);
echo '</td>';
echo '<td class="content">';
echo '<form name="submitform" action="submissions.php?cmid=' . $this->cm->id . '" method="post">';
echo '<input type="hidden" name="offset" value="' . ++$offset . '">';
echo '<input type="hidden" name="userid" value="' . $userid . '" />';
echo '<input type="hidden" name="id" value="' . $this->cm->id . '" />';
echo '<input type="hidden" name="mode" value="grade" />';
//echo '<input type="hidden" name="tabs" value="required" />';
echo '<input type="hidden" name="menuindex" value="0" />';
//selected menu index
//new hidden field, initialized to -1.
echo '<input type="hidden" name="saveuserid" value="-1" />';
if ($submission->timemarked) {
echo '<div class="from">';
echo '<div class="fullname">' . fullname($teacher, true) . '</div>';
echo '<div class="time">' . userdate($submission->timemarked) . '</div>';
echo '</div>';
}
echo '<div class="grade">' . get_string('grade') . ':';
choose_from_menu(make_grades_menu($this->wqgrade), 'grade', $submission->grade, get_string('nograde'), '', -1);
//.........这里部分代码省略.........
示例15: training_reports_print_header_xls
/**
* a raster for xls printing of a report structure header
* with all the relevant data about a user.
*
*/
function training_reports_print_header_xls(&$worksheet, $userid, $courseid, $data, $xls_formats)
{
global $CFG;
$user = get_record('user', 'id', $userid);
$course = get_record('course', 'id', $courseid);
$row = 0;
$worksheet->set_row(0, 40, $xls_formats['t']);
$worksheet->write_string($row, 0, get_string('sessionreports', 'report_trainingsessions'), $xls_formats['t']);
$worksheet->merge_cells($row, 0, 0, 12);
$row++;
$worksheet->write_string($row, 0, get_string('user') . ' :', $xls_formats['p']);
$worksheet->write_string($row, 1, fullname($user));
$row++;
$worksheet->write_string($row, 0, get_string('email') . ' :', $xls_formats['p']);
$worksheet->write_string($row, 1, $user->email);
$row++;
$worksheet->write_string($row, 0, get_string('city') . ' :', $xls_formats['p']);
$worksheet->write_string($row, 1, $user->city);
$row++;
$worksheet->write_string($row, 0, get_string('institution') . ' :', $xls_formats['p']);
$worksheet->write_string($row, 1, $user->institution);
$row++;
$worksheet->write_string($row, 0, get_string('course', 'report_trainingsessions') . ' :', $xls_formats['p']);
$worksheet->write_string($row, 1, $course->fullname);
$row++;
$worksheet->write_string($row, 0, get_string('from') . ' :', $xls_formats['p']);
$worksheet->write_string($row, 1, userdate($data->from));
$row++;
$worksheet->write_string($row, 0, get_string('to') . ' :', $xls_formats['p']);
$worksheet->write_string($row, 1, userdate(time()));
$row++;
$usergroups = groups_get_all_groups($courseid, $userid, 0, 'g.id, g.name');
// print group status
$worksheet->write_string($row, 0, get_string('groups') . ' :', $xls_formats['p']);
$str = '';
if (!empty($usergroups)) {
foreach ($usergroups as $group) {
$str = $group->name;
if ($group->id == get_current_group($courseid)) {
$str = "[{$str}]";
}
$groupnames[] = $str;
}
$str = implode(', ', $groupnames);
}
$worksheet->write_string($row, 1, $str);
$row++;
$context = get_context_instance(CONTEXT_COURSE, $courseid);
$worksheet->write_string($row, 0, get_string('roles') . ' :', $xls_formats['p']);
$worksheet->write_string($row, 1, strip_tags(get_user_roles_in_context($userid, $context)));
$row++;
// print completion bar
$completed = $data->done / $data->items;
$remaining = 1 - $completed;
$completedpc = ceil($completed * 100);
$remainingpc = 100 - $completedpc;
$worksheet->write_string($row, 0, get_string('done', 'report_trainingsessions'), $xls_formats['p']);
$worksheet->write_string($row, 1, $data->done . ' ' . get_string('over', 'report_trainingsessions') . ' ' . $data->items . ' (' . $completedpc . ' %)');
$row++;
$worksheet->write_string($row, 0, get_string('elapsed', 'report_trainingsessions') . ' :', $xls_formats['p']);
$worksheet->write_number($row, 1, training_reports_format_time($data->elapsed, 'xls'), $xls_formats['zt']);
$row++;
$worksheet->write_string($row, 0, get_string('hits', 'report_trainingsessions') . ' :', $xls_formats['p']);
$worksheet->write_number($row, 1, $data->events);
return $row;
}