lib.php
来自「很棒的在线教学系统」· PHP 代码 · 共 396 行 · 第 1/2 页
PHP
396 行
<?php // $Id: lib.php,v 1.18.2.17 2008/12/29 20:19:59 skodak Exp $///////////////////////////////////////////////////////////////////////////// //// NOTICE OF COPYRIGHT //// //// Moodle - Modular Object-Oriented Dynamic Learning Environment //// http://moodle.com //// //// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //// //// This program is free software; you can redistribute it and/or modify //// it under the terms of the GNU General Public License as published by //// the Free Software Foundation; either version 2 of the License, or //// (at your option) any later version. //// //// This program is distributed in the hope that it will be useful, //// but WITHOUT ANY WARRANTY; without even the implied warranty of //// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //// GNU General Public License for more details: //// //// http://www.gnu.org/copyleft/gpl.html //// //////////////////////////////////////////////////////////////////////////////** * File in which the user_report class is defined. * @package gradebook */require_once($CFG->dirroot . '/grade/report/lib.php');require_once($CFG->libdir.'/tablelib.php');/** * Class providing an API for the user report building and displaying. * @uses grade_report * @package gradebook */class grade_report_user extends grade_report { /** * The user. * @var object $user */ var $user; /** * A flexitable to hold the data. * @var object $table */ var $table; /** * Flat structure similar to grade tree */ var $gseq; /** * show student ranks */ var $showrank; /** * show grade percentages */ var $showpercentage; /** * Show hidden items even when user does not have required cap */ var $showhiddenitems; /** * Constructor. Sets local copies of user preferences and initialises grade_tree. * @param int $courseid * @param object $gpr grade plugin return tracking object * @param string $context * @param int $userid The id of the user */ function grade_report_user($courseid, $gpr, $context, $userid) { global $CFG; parent::grade_report($courseid, $gpr, $context); $this->showrank = grade_get_setting($this->courseid, 'report_user_showrank', $CFG->grade_report_user_showrank); $this->showpercentage = grade_get_setting($this->courseid, 'report_user_showpercentage', $CFG->grade_report_user_showpercentage); $this->showhiddenitems = grade_get_setting($this->courseid, 'report_user_showhiddenitems', $CFG->grade_report_user_showhiddenitems); $switch = grade_get_setting($this->courseid, 'aggregationposition', $CFG->grade_aggregationposition); // Grab the grade_seq for this course $this->gseq = new grade_seq($this->courseid, $switch); // get the user (for full name) $this->user = get_record('user', 'id', $userid); // base url for sorting by first/last name $this->baseurl = $CFG->wwwroot.'/grade/report?id='.$courseid.'&userid='.$userid; $this->pbarurl = $this->baseurl; // no groups on this report - rank is from all course users $this->setup_table(); } /** * Prepares the headers and attributes of the flexitable. */ function setup_table() { global $CFG; /* * Table has 5-6 columns *| itemname/description | final grade | percentage final grade | rank (optional) | feedback | */ // setting up table headers $tablecolumns = array('itemname', 'category', 'grade'); $tableheaders = array($this->get_lang_string('gradeitem', 'grades'), $this->get_lang_string('category'), $this->get_lang_string('grade')); if ($this->showpercentage) { $tablecolumns[] = 'percentage'; $tableheaders[] = $this->get_lang_string('percentage', 'grades'); } if ($this->showrank) { // TODO: this is broken if hidden grades present!! $tablecolumns[] = 'rank'; $tableheaders[] = $this->get_lang_string('rank', 'grades'); } $tablecolumns[] = 'feedback'; $tableheaders[] = $this->get_lang_string('feedback', 'grades'); $this->table = new flexible_table('grade-report-user-'.$this->courseid); $this->table->define_columns($tablecolumns); $this->table->define_headers($tableheaders); $this->table->define_baseurl($this->baseurl); $this->table->set_attribute('cellspacing', '0'); $this->table->set_attribute('id', 'user-grade'); $this->table->set_attribute('class', 'boxaligncenter generaltable'); // not sure tables should be sortable or not, because if we allow it then sorted results distort grade category structure and sortorder $this->table->set_control_variables(array( TABLE_VAR_SORT => 'ssort', TABLE_VAR_HIDE => 'shide', TABLE_VAR_SHOW => 'sshow', TABLE_VAR_IFIRST => 'sifirst', TABLE_VAR_ILAST => 'silast', TABLE_VAR_PAGE => 'spage' )); $this->table->setup(); } function fill_table() { global $CFG; $numusers = $this->get_numusers(false); // total course users $items =& $this->gseq->items; $grades = array(); $canviewhidden = has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $this->courseid)); // fetch or create all grades foreach ($items as $key=>$unused) { if (!$grade_grade = grade_grade::fetch(array('itemid'=>$items[$key]->id, 'userid'=>$this->user->id))) { $grade_grade = new grade_grade(); $grade_grade->userid = $this->user->id; $grade_grade->itemid = $items[$key]->id; } $grades[$key] = $grade_grade; $grades[$key]->grade_item =& $items[$key]; } if ($canviewhidden) { $altered = array(); $unknown = array(); } else { $hiding_affected = grade_grade::get_hiding_affected($grades, $items); $altered = $hiding_affected['altered']; $unknown = $hiding_affected['unknown']; unset($hiding_affected); } foreach ($items as $itemid=>$unused) { $grade_item =& $items[$itemid]; $grade_grade =& $grades[$itemid]; if (!$canviewhidden and $grade_item->is_hidden()) { if ($this->showhiddenitems == 0) { // no hidden items at all continue; } else if ($this->showhiddenitems == 1 and !$grade_item->is_hiddenuntil()) { // hidden until that are still hidden are visible continue; } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?