📄 lib.php
字号:
switch($this->sortitemid) { case 'lastname': $sort = "u.lastname $this->sortorder, u.firstname $this->sortorder"; break; case 'firstname': $sort = "u.firstname $this->sortorder, u.lastname $this->sortorder"; break; case 'idnumber': default: $sort = "u.idnumber $this->sortorder"; break; } $sql = "SELECT DISTINCT u.id, u.firstname, u.lastname, u.imagealt, u.picture, u.idnumber FROM {$CFG->prefix}user u JOIN {$CFG->prefix}role_assignments ra ON u.id = ra.userid $this->groupsql WHERE ra.roleid in ($this->gradebookroles) $this->groupwheresql AND ra.contextid ".get_related_contexts_string($this->context)." ORDER BY $sort"; } $this->users = get_records_sql($sql, $this->get_pref('studentsperpage') * $this->page, $this->get_pref('studentsperpage')); if (empty($this->users)) { $this->userselect = ''; $this->users = array(); } else { $this->userselect = 'AND g.userid in ('.implode(',', array_keys($this->users)).')'; } return $this->users; } /** * we supply the userids in this query, and get all the grades * pulls out all the grades, this does not need to worry about paging */ function load_final_grades() { global $CFG; // please note that we must fetch all grade_grades fields if we want to contruct grade_grade object from it! $sql = "SELECT g.* FROM {$CFG->prefix}grade_items gi, {$CFG->prefix}grade_grades g WHERE g.itemid = gi.id AND gi.courseid = {$this->courseid} {$this->userselect}"; $userids = array_keys($this->users); if ($grades = get_records_sql($sql)) { foreach ($grades as $graderec) { if (in_array($graderec->userid, $userids) and array_key_exists($graderec->itemid, $this->gtree->items)) { // some items may not be present!! $this->grades[$graderec->userid][$graderec->itemid] = new grade_grade($graderec, false); $this->grades[$graderec->userid][$graderec->itemid]->grade_item =& $this->gtree->items[$graderec->itemid]; // db caching } } } // prefil grades that do not exist yet foreach ($userids as $userid) { foreach ($this->gtree->items as $itemid=>$unused) { if (!isset($this->grades[$userid][$itemid])) { $this->grades[$userid][$itemid] = new grade_grade(); $this->grades[$userid][$itemid]->itemid = $itemid; $this->grades[$userid][$itemid]->userid = $userid; $this->grades[$userid][$itemid]->grade_item =& $this->gtree->items[$itemid]; // db caching } } } } /** * Builds and returns a div with on/off toggles. * @return string HTML code */ function get_toggles_html() { global $CFG, $USER, $COURSE; $html = '<div id="grade-report-toggles">'; if ($USER->gradeediting[$this->courseid]) { if (has_capability('moodle/grade:manage', $this->context) or has_capability('moodle/grade:hide', $this->context)) { $html .= $this->print_toggle('eyecons', true); } if (has_capability('moodle/grade:manage', $this->context) or has_capability('moodle/grade:lock', $this->context) or has_capability('moodle/grade:unlock', $this->context)) { $html .= $this->print_toggle('locks', true); } if (has_capability('moodle/grade:manage', $this->context)) { $html .= $this->print_toggle('quickfeedback', true); } if (has_capability('moodle/grade:manage', $this->context)) { $html .= $this->print_toggle('calculations', true); } } if ($this->canviewhidden) { $html .= $this->print_toggle('averages', true); } if (has_capability('moodle/grade:viewall', $this->context) and has_capability('moodle/site:accessallgroups', $this->context) and ($course_has_groups = true)) { // TODO replace that last condition with proper check $html .= $this->print_toggle('groups', true); } $html .= $this->print_toggle('ranges', true); if (!empty($CFG->enableoutcomes)) { $html .= $this->print_toggle('nooutcomes', true); } $html .= '</div>'; return $html; } /** * Shortcut function for printing the grader report toggles. * @param string $type The type of toggle * @param bool $return Whether to return the HTML string rather than printing it * @return void */ function print_toggle($type, $return=false) { global $CFG; $icons = array('eyecons' => 't/hide.gif', 'calculations' => 't/calc.gif', 'locks' => 't/lock.gif', 'averages' => 't/mean.gif', 'quickfeedback' => 't/feedback.gif', 'nooutcomes' => 't/outcomes.gif'); $pref_name = 'grade_report_show' . $type; if (array_key_exists($pref_name, $CFG)) { $show_pref = get_user_preferences($pref_name, $CFG->$pref_name); } else { $show_pref = get_user_preferences($pref_name); } $strshow = $this->get_lang_string('show' . $type, 'grades'); $strhide = $this->get_lang_string('hide' . $type, 'grades'); $show_hide = 'show'; $toggle_action = 1; if ($show_pref) { $show_hide = 'hide'; $toggle_action = 0; } if (array_key_exists($type, $icons)) { $image_name = $icons[$type]; } else { $image_name = "t/$type.gif"; } $string = ${'str' . $show_hide}; $img = '<img src="'.$CFG->pixpath.'/'.$image_name.'" class="iconsmall" alt="' .$string.'" title="'.$string.'" />'. "\n"; $retval = '<div class="gradertoggle">' . $img . '<a href="' . $this->baseurl . "&toggle=$toggle_action&toggle_type=$type\">" . $string . '</a></div>'; if ($return) { return $retval; } else { echo $retval; } } /** * Builds and returns the HTML code for the headers. * @return string $headerhtml */ function get_headerhtml() { global $CFG, $USER; $strsortasc = $this->get_lang_string('sortasc', 'grades'); $strsortdesc = $this->get_lang_string('sortdesc', 'grades'); $strfirstname = $this->get_lang_string('firstname'); $strlastname = $this->get_lang_string('lastname'); $showuseridnumber = $this->get_pref('showuseridnumber'); if ($this->sortitemid === 'lastname') { if ($this->sortorder == 'ASC') { $lastarrow = print_arrow('up', $strsortasc, true); } else { $lastarrow = print_arrow('down', $strsortdesc, true); } } else { $lastarrow = ''; } if ($this->sortitemid === 'firstname') { if ($this->sortorder == 'ASC') { $firstarrow = print_arrow('up', $strsortasc, true); } else { $firstarrow = print_arrow('down', $strsortdesc, true); } } else { $firstarrow = ''; } // Prepare Table Headers $headerhtml = ''; $numrows = count($this->gtree->levels); $columns_to_unset = array(); foreach ($this->gtree->levels as $key=>$row) { $columncount = 0; if ($key == 0) { // do not display course grade category // continue; } $headerhtml .= '<tr class="heading r'.$this->rowcount++.'">'; if ($key == $numrows - 1) { $headerhtml .= '<th class="header c'.$columncount++.'" scope="col"><a href="'.$this->baseurl.'&sortitemid=firstname">' . $strfirstname . '</a> ' . $firstarrow. '/ <a href="'.$this->baseurl.'&sortitemid=lastname">' . $strlastname . '</a>'. $lastarrow .'</th>'; if ($showuseridnumber) { if ('idnumber' == $this->sortitemid) { if ($this->sortorder == 'ASC') { $idnumberarrow = print_arrow('up', $strsortasc, true); } else { $idnumberarrow = print_arrow('down', $strsortdesc, true); } } else { $idnumberarrow = ''; } $headerhtml .= '<th class="header c'.$columncount++.' useridnumber" scope="col"><a href="'.$this->baseurl.'&sortitemid=idnumber">' . get_string('idnumber') . '</a> ' . $idnumberarrow . '</th>'; } } else { $colspan=''; if ($showuseridnumber) { $colspan = 'colspan="2" '; } $headerhtml .= '<td '.$colspan.'class="cell c'.$columncount++.' topleft"> </td>'; if ($showuseridnumber) { $columncount++; } } foreach ($row as $columnkey => $element) { $sort_link = ''; if (isset($element['object']->id)) { $sort_link = $this->baseurl.'&sortitemid=' . $element['object']->id; } $eid = $element['eid']; $object = $element['object']; $type = $element['type']; $categorystate = @$element['categorystate']; $itemmodule = null; $iteminstance = null; $columnclass = 'c' . $columncount++; if (!empty($element['colspan'])) { $colspan = 'colspan="'.$element['colspan'].'"'; $columnclass = ''; } else { $colspan = ''; } if (!empty($element['depth'])) { $catlevel = ' catlevel'.$element['depth']; } else { $catlevel = ''; }// Element is a filler if ($type == 'filler' or $type == 'fillerfirst' or $type == 'fillerlast') { $headerhtml .= '<th class="'.$columnclass.' '.$type.$catlevel.'" '.$colspan.' scope="col"> </th>'; }// Element is a category else if ($type == 'category') { $headerhtml .= '<th class="header '. $columnclass.' category'.$catlevel.'" '.$colspan.' scope="col">' . shorten_text($element['object']->get_name()); $headerhtml .= $this->get_collapsing_icon($element); // Print icons if ($USER->gradeediting[$this->courseid]) { $headerhtml .= $this->get_icons($element); } $headerhtml .= '</th>'; }// Element is a grade_item else { $itemmodule = $element['object']->itemmodule; $iteminstance = $element['object']->iteminstance; if ($element['object']->id == $this->sortitemid) { if ($this->sortorder == 'ASC') { $arrow = $this->get_sort_arrow('up', $sort_link); } else { $arrow = $this->get_sort_arrow('down', $sort_link); } } else { $arrow = $this->get_sort_arrow('move', $sort_link); } $hidden = ''; if ($element['object']->is_hidden()) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -