/**
* 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;
}
}
/**
* 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;
}
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;
}
/**
* 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;
}
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);
}
}
开发者ID:r007,项目名称:PMoodle,代码行数:51,代码来源:locallib.php
示例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
//.........这里部分代码省略.........
/**
* 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;
}
请发表评论