本文整理汇总了PHP中grade_grade::get_hiding_affected方法的典型用法代码示例。如果您正苦于以下问题:PHP grade_grade::get_hiding_affected方法的具体用法?PHP grade_grade::get_hiding_affected怎么用?PHP grade_grade::get_hiding_affected使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类grade_grade
的用法示例。
在下文中一共展示了grade_grade::get_hiding_affected方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: grade_report_grader
//$users = $report_evalcomix->load_users();
//$finalgrades = $report_evalcomix->get_grades();
$numpages = (int) ($numusers / $studentsperpage);
if ($numusers % $studentsperpage > 0) {
$numpages += 1;
}
for ($ipage = 0; $ipage < $numpages; ++$ipage) {
$report_grader = new grade_report_grader($courseid, null, $context, $ipage, $sortitemid);
$report_grader->load_users();
$report_grader->load_final_grades();
foreach ($report_grader->users as $userid => $user) {
if ($report_grader->canviewhidden) {
$altered = array();
$unknown = array();
} else {
$hidingaffected = grade_grade::get_hiding_affected($report_grader->grades[$userid], $report_grader->gtree->get_items());
$altered = $hidingaffected['altered'];
$unknown = $hidingaffected['unknown'];
unset($hidingaffected);
}
foreach ($report_grader->gtree->items as $itemid => $unused) {
$item =& $report_grader->gtree->items[$itemid];
$grade = $report_grader->grades[$userid][$item->id];
// Get the decimal points preference for this item
$decimalpoints = $item->get_decimals();
if (in_array($itemid, $unknown)) {
$gradeval = null;
} else {
if (array_key_exists($itemid, $altered)) {
$gradeval = $altered[$itemid];
} else {
示例2: fill_table
public function fill_table()
{
global $CFG, $DB;
// MDL-11679, only show 'mycourses' instead of all courses
if ($courses = get_my_courses($this->user->id, 'c.sortorder ASC', 'id, shortname, showgrades')) {
$numusers = $this->get_numusers(false);
foreach ($courses as $course) {
if (!$course->showgrades) {
continue;
}
$courselink = '<a href="' . $CFG->wwwroot . '/grade/report/user/index.php?id=' . $course->id . '">' . $course->shortname . '</a>';
$canviewhidden = has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $course->id));
// Get course grade_item
$course_item = grade_item::fetch_course_item($course->id);
// Get the stored grade
$course_grade = new grade_grade(array('itemid' => $course_item->id, 'userid' => $this->user->id));
$course_grade->grade_item =& $course_item;
$finalgrade = $course_grade->finalgrade;
if (!$canviewhidden and !is_null($finalgrade)) {
if ($course_grade->is_hidden()) {
$finalgrade = null;
} else {
// This is a really ugly hack, it will be fixed in 2.0
$items = grade_item::fetch_all(array('courseid' => $course->id));
$grades = array();
$sql = "SELECT g.*\n FROM {grade_grades} g\n JOIN {grade_items} gi ON gi.id = g.itemid\n WHERE g.userid = ? AND gi.courseid = ?";
if ($gradesrecords = $DB->get_records_sql($sql, array($this->user->id, $course->id))) {
foreach ($gradesrecords as $grade) {
$grades[$grade->itemid] = new grade_grade($grade, false);
}
unset($gradesrecords);
}
foreach ($items as $itemid => $unused) {
if (!isset($grades[$itemid])) {
$grade_grade = new grade_grade();
$grade_grade->userid = $this->user->id;
$grade_grade->itemid = $items[$itemid]->id;
$grades[$itemid] = $grade_grade;
}
$grades[$itemid]->grade_item =& $items[$itemid];
}
$hiding_affected = grade_grade::get_hiding_affected($grades, $items);
if (array_key_exists($course_item->id, $hiding_affected['altered'])) {
$finalgrade = $hiding_affected['altered'][$course_item->id];
} else {
if (!empty($hiding_affected['unknown'][$course_item->id])) {
$finalgrade = null;
}
}
unset($hiding_affected);
unset($grades);
unset($items);
}
}
$data = array($courselink, grade_format_gradevalue($finalgrade, $course_item, true));
if (!$this->showrank) {
//nothing to do
} else {
if (!is_null($finalgrade)) {
/// find the number of users with a higher grade
/// please note this can not work if hidden grades involved :-( to be fixed in 2.0
$params = array($finalgrade, $course_item->id);
$sql = "SELECT COUNT(DISTINCT(userid))\n FROM {grade_grades}\n WHERE finalgrade IS NOT NULL AND finalgrade > ?\n AND itemid = ?";
$rank = $DB->count_records_sql($sql, $params) + 1;
$data[] = "{$rank}/{$numusers}";
} else {
// no grade, no rank
$data[] = '-';
}
}
$this->table->add_data($data);
}
return true;
} else {
notify(get_string('nocourses', 'grades'));
return false;
}
}
示例3: get_studentshtml
/**
* Builds and return the HTML rows of the table (grades headed by student).
* @return string HTML
*/
function get_studentshtml()
{
global $CFG, $USER;
$studentshtml = '';
$strfeedback = $this->get_lang_string("feedback");
$strgrade = $this->get_lang_string('grade');
$gradetabindex = 1;
$numusers = count($this->users);
$showuserimage = $this->get_pref('showuserimage');
$showuseridnumber = $this->get_pref('showuseridnumber');
$fixedstudents = $this->is_fixed_students();
// Preload scale objects for items with a scaleid
$scales_list = '';
$tabindices = array();
foreach ($this->gtree->items as $item) {
if (!empty($item->scaleid)) {
$scales_list .= "{$item->scaleid},";
}
$tabindices[$item->id]['grade'] = $gradetabindex;
$tabindices[$item->id]['feedback'] = $gradetabindex + $numusers;
$gradetabindex += $numusers * 2;
}
$scales_array = array();
if (!empty($scales_list)) {
$scales_list = substr($scales_list, 0, -1);
$scales_array = get_records_list('scale', 'id', $scales_list);
}
$row_classes = array(' even ', ' odd ');
$row_classes = array(' even ', ' odd ');
foreach ($this->users as $userid => $user) {
if ($this->canviewhidden) {
$altered = array();
$unknown = array();
} else {
$hiding_affected = grade_grade::get_hiding_affected($this->grades[$userid], $this->gtree->items);
$altered = $hiding_affected['altered'];
$unknown = $hiding_affected['unknown'];
unset($hiding_affected);
}
$columncount = 0;
if ($fixedstudents) {
$studentshtml .= '<tr class="r' . $this->rowcount++ . $row_classes[$this->rowcount % 2] . '">';
} else {
// Student name and link
$user_pic = null;
if ($showuserimage) {
$user_pic = '<div class="userpic">' . print_user_picture($user, $this->courseid, null, 0, true) . '</div>';
}
$studentshtml .= '<tr class="r' . $this->rowcount++ . $row_classes[$this->rowcount % 2] . '">' . '<th class="c' . $columncount++ . ' user" scope="row" onclick="set_row(this.parentNode.rowIndex);">' . $user_pic . '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '&course=' . $this->course->id . '">' . fullname($user) . '</a></th>';
if ($showuseridnumber) {
$studentshtml .= '<th class="c' . $columncount++ . ' useridnumber" onclick="set_row(this.parentNode.rowIndex);">' . $user->idnumber . '</th>';
}
}
foreach ($this->gtree->items as $itemid => $unused) {
$item =& $this->gtree->items[$itemid];
$grade = $this->grades[$userid][$item->id];
// Get the decimal points preference for this item
$decimalpoints = $item->get_decimals();
if (in_array($itemid, $unknown)) {
$gradeval = null;
} else {
if (array_key_exists($itemid, $altered)) {
$gradeval = $altered[$itemid];
} else {
$gradeval = $grade->finalgrade;
}
}
// MDL-11274
// Hide grades in the grader report if the current grader doesn't have 'moodle/grade:viewhidden'
if (!$this->canviewhidden and $grade->is_hidden()) {
if (!empty($CFG->grade_hiddenasdate) and $grade->get_datesubmitted() and !$item->is_category_item() and !$item->is_course_item()) {
// the problem here is that we do not have the time when grade value was modified, 'timemodified' is general modification date for grade_grades records
$studentshtml .= '<td class="cell c' . $columncount++ . '"><span class="datesubmitted">' . userdate($grade->get_datesubmitted(), get_string('strftimedatetimeshort')) . '</span></td>';
} else {
$studentshtml .= '<td class="cell c' . $columncount++ . '">-</td>';
}
continue;
}
// emulate grade element
$eid = $this->gtree->get_grade_eid($grade);
$element = array('eid' => $eid, 'object' => $grade, 'type' => 'grade');
$cellclasses = 'grade cell c' . $columncount++;
if ($item->is_category_item()) {
$cellclasses .= ' cat';
}
if ($item->is_course_item()) {
$cellclasses .= ' course';
}
if ($grade->is_overridden()) {
$cellclasses .= ' overridden';
}
if ($grade->is_excluded()) {
// $cellclasses .= ' excluded';
}
$grade_title = '<div class="fullname">' . fullname($user) . '</div>';
$grade_title .= '<div class="itemname">' . $item->get_name(true) . '</div>';
//.........这里部分代码省略.........
示例4: blank_hidden_total
/**
* Optionally blank out course/category totals if they contain any hidden items
* @param string $courseid the course id
* @param string $course_item an instance of grade_item
* @param string $finalgrade the grade for the course_item
* @return string The new final grade
*/
protected function blank_hidden_total($courseid, $course_item, $finalgrade)
{
global $CFG, $DB;
static $hiding_affected = null;
//array of items in this course affected by hiding
// If we're dealing with multiple users we need to know when we've moved on to a new user.
static $previous_userid = null;
// If we're dealing with multiple courses we need to know when we've moved on to a new course.
static $previous_courseid = null;
if (!is_array($this->showtotalsifcontainhidden)) {
debugging('showtotalsifcontainhidden should be an array', DEBUG_DEVELOPER);
$this->showtotalsifcontainhidden = array($courseid => $this->showtotalsifcontainhidden);
}
if ($this->showtotalsifcontainhidden[$courseid] == GRADE_REPORT_SHOW_REAL_TOTAL_IF_CONTAINS_HIDDEN) {
return $finalgrade;
}
// If we've moved on to another course or user, reload the grades.
if ($previous_userid != $this->user->id || $previous_courseid != $courseid) {
$hiding_affected = null;
$previous_userid = $this->user->id;
$previous_courseid = $courseid;
}
if (!$hiding_affected) {
$items = grade_item::fetch_all(array('courseid' => $courseid));
$grades = array();
$sql = "SELECT g.*\n FROM {grade_grades} g\n JOIN {grade_items} gi ON gi.id = g.itemid\n WHERE g.userid = {$this->user->id} AND gi.courseid = {$courseid}";
if ($gradesrecords = $DB->get_records_sql($sql)) {
foreach ($gradesrecords as $grade) {
$grades[$grade->itemid] = new grade_grade($grade, false);
}
unset($gradesrecords);
}
foreach ($items as $itemid => $unused) {
if (!isset($grades[$itemid])) {
$grade_grade = new grade_grade();
$grade_grade->userid = $this->user->id;
$grade_grade->itemid = $items[$itemid]->id;
$grades[$itemid] = $grade_grade;
}
$grades[$itemid]->grade_item =& $items[$itemid];
}
$hiding_affected = grade_grade::get_hiding_affected($grades, $items);
}
//if the item definitely depends on a hidden item
if (array_key_exists($course_item->id, $hiding_affected['altered'])) {
if (!$this->showtotalsifcontainhidden[$courseid]) {
//hide the grade
$finalgrade = null;
} else {
//use reprocessed marks that exclude hidden items
$finalgrade = $hiding_affected['altered'][$course_item->id];
}
} else {
if (!empty($hiding_affected['unknown'][$course_item->id])) {
//not sure whether or not this item depends on a hidden item
if (!$this->showtotalsifcontainhidden[$courseid]) {
//hide the grade
$finalgrade = null;
} else {
//use reprocessed marks that exclude hidden items
$finalgrade = $hiding_affected['unknown'][$course_item->id];
}
}
}
return $finalgrade;
}
示例5: get_right_rows
//.........这里部分代码省略.........
$rows = $this->get_right_icons_row($rows);
// Preload scale objects for items with a scaleid
$scaleslist = array();
$tabindices = array();
foreach ($this->gtree->get_items() as $itemid=>$item) {
$scale = null;
if (!empty($item->scaleid)) {
$scaleslist[] = $item->scaleid;
$jsarguments['items'][$itemid] = array('id'=>$itemid, 'name'=>$item->get_name(true), 'type'=>'scale', 'scale'=>$item->scaleid, 'decimals'=>$item->get_decimals());
} else {
$jsarguments['items'][$itemid] = array('id'=>$itemid, 'name'=>$item->get_name(true), 'type'=>'value', 'scale'=>false, 'decimals'=>$item->get_decimals());
}
$tabindices[$item->id]['grade'] = $gradetabindex;
$tabindices[$item->id]['feedback'] = $gradetabindex + $numusers;
$gradetabindex += $numusers * 2;
}
$scalesarray = array();
if (!empty($scaleslist)) {
$scalesarray = $DB->get_records_list('scale', 'id', $scaleslist);
}
$jsscales = $scalesarray;
$rowclasses = array('even', 'odd');
foreach ($this->users as $userid => $user) {
if ($this->canviewhidden) {
$altered = array();
$unknown = array();
} else {
$hidingaffected = grade_grade::get_hiding_affected($this->grades[$userid], $this->gtree->get_items());
$altered = $hidingaffected['altered'];
$unknown = $hidingaffected['unknown'];
unset($hidingaffected);
}
$itemrow = new html_table_row();
$itemrow->id = 'user_'.$userid;
$itemrow->attributes['class'] = $rowclasses[$this->rowcount % 2];
$jsarguments['users'][$userid] = fullname($user);
foreach ($this->gtree->items as $itemid=>$unused) {
$item =& $this->gtree->items[$itemid];
$grade = $this->grades[$userid][$item->id];
$itemcell = new html_table_cell();
$itemcell->id = 'u'.$userid.'i'.$itemid;
// Get the decimal points preference for this item
$decimalpoints = $item->get_decimals();
if (in_array($itemid, $unknown)) {
$gradeval = null;
} else if (array_key_exists($itemid, $altered)) {
$gradeval = $altered[$itemid];
} else {
$gradeval = $grade->finalgrade;
}
// MDL-11274
示例6: get_right_rows
//.........这里部分代码省略.........
$itemcell->scope = 'col';
$headingrow->cells[] = $itemcell;
}
}
}
$rows[] = $headingrow;
}
$rows = $this->get_right_icons_row($rows);
// Preload scale objects for items with a scaleid and initialize tab indices
$scaleslist = array();
$tabindices = array();
foreach ($this->gtree->get_items() as $itemid => $item) {
$scale = null;
if (!empty($item->scaleid)) {
$scaleslist[] = $item->scaleid;
$jsarguments['items'][$itemid] = array('id' => $itemid, 'name' => $item->get_name(true), 'type' => 'scale', 'scale' => $item->scaleid, 'decimals' => $item->get_decimals());
} else {
$jsarguments['items'][$itemid] = array('id' => $itemid, 'name' => $item->get_name(true), 'type' => 'value', 'scale' => false, 'decimals' => $item->get_decimals());
}
$tabindices[$item->id]['grade'] = $gradetabindex;
$tabindices[$item->id]['feedback'] = $gradetabindex + $numusers;
$gradetabindex += $numusers * 2;
}
$scalesarray = array();
if (!empty($scaleslist)) {
$scalesarray = $DB->get_records_list('scale', 'id', $scaleslist);
}
$jsscales = $scalesarray;
foreach ($this->users as $userid => $user) {
if ($this->canviewhidden) {
$altered = array();
$unknown = array();
} else {
$hidingaffected = grade_grade::get_hiding_affected($this->grades[$userid], $this->gtree->get_items());
$altered = $hidingaffected['altered'];
$unknown = $hidingaffected['unknown'];
unset($hidingaffected);
}
$itemrow = new html_table_row();
$itemrow->id = 'user_' . $userid;
$fullname = fullname($user);
$jsarguments['users'][$userid] = $fullname;
foreach ($this->gtree->items as $itemid => $unused) {
$item =& $this->gtree->items[$itemid];
$grade = $this->grades[$userid][$item->id];
$itemcell = new html_table_cell();
$itemcell->id = 'u' . $userid . 'i' . $itemid;
$itemcell->attributes['data-itemid'] = $itemid;
// Get the decimal points preference for this item
$decimalpoints = $item->get_decimals();
if (in_array($itemid, $unknown)) {
$gradeval = null;
} else {
if (array_key_exists($itemid, $altered)) {
$gradeval = $altered[$itemid];
} else {
$gradeval = $grade->finalgrade;
}
}
if (!empty($grade->finalgrade)) {
$gradevalforjs = null;
if ($item->scaleid && !empty($scalesarray[$item->scaleid])) {
$gradevalforjs = (int) $gradeval;
} else {
$gradevalforjs = format_float($gradeval, $decimalpoints);
}
示例7: get_studentrowhtml
/**
* Given a userid, and provided the gtree is correctly loaded, returns a complete HTML row for this user.
*
* @param object $user
* @return string
*/
function get_studentrowhtml($user)
{
global $CFG, $USER;
$showuserimage = $this->get_pref('showuserimage');
$showuseridnumber = $this->get_pref('showuseridnumber');
$fixedstudents = empty($USER->screenreader) && $this->get_pref('fixedstudents');
$studentrowhtml = '';
$row_classes = array(' even ', ' odd ');
if ($this->canviewhidden) {
$altered = array();
$unknown = array();
} else {
$hiding_affected = grade_grade::get_hiding_affected($this->grades[$userid], $this->gtree->items);
$altered = $hiding_affected['altered'];
$unknown = $hiding_affected['unknown'];
unset($hiding_affected);
}
$columncount = 0;
if ($fixedstudents) {
$studentrowhtml .= '<tr class="r' . $this->rowcount++ . $row_classes[$this->rowcount % 2] . '">';
} else {
// Student name and link
$user_pic = null;
if ($showuserimage) {
$user_pic = '<div class="userpic">' . print_user_picture($user, $this->courseid, true, 0, true) . '</div>';
}
$studentrowhtml .= '<tr class="r' . $this->rowcount++ . $row_classes[$this->rowcount % 2] . '">' . '<th class="header c' . $columncount++ . ' user" scope="row" onclick="set_row(this.parentNode.rowIndex);">' . $user_pic . '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '&course=' . $this->course->id . '">' . fullname($user) . '</a></th>';
if ($showuseridnumber) {
$studentrowhtml .= '<th class="header c' . $columncount++ . ' useridnumber" onclick="set_row(this.parentNode.rowIndex);">' . $user->idnumber . '</th>';
}
}
$columntabcount = 0;
$feedback_tabindex_modifier = 1;
// Used to offset the grade value at the beginning of each new column
if ($this->get_pref('showquickfeedback')) {
$feedback_tabindex_modifier = 2;
}
foreach ($this->gtree->items as $itemid => $unused) {
$nexttabindex = $this->tabindex + $columntabcount * $feedback_tabindex_modifier * $this->numusers;
$studentrowhtml .= $this->get_gradecellhtml($user, $itemid, $columncount, $nexttabindex, $altered, $unknown);
$columntabcount++;
}
$studentrowhtml .= '</tr>';
return $studentrowhtml;
}
示例8: get_studentshtml
/**
* Builds and return the HTML rows of the table (grades headed by student).
* @return string HTML
*/
function get_studentshtml()
{
global $CFG, $USER;
$studentshtml = '';
$strfeedback = $this->get_lang_string("feedback");
$strgrade = $this->get_lang_string('grade');
/*
if ($showquickfeedback ) {
$gradetabindex += $numusers * 4;
} else {
$gradetabindex += $numusers * 2;
}
*
*/
$gradetabindex = 1;
$numusers = count($this->users);
$showuserimage = $this->get_pref('showuserimage');
$showuseridnumber = $this->get_pref('showuseridnumber');
$showquickfeedback = $this->get_pref('showquickfeedback');
$accuratetotals = get_user_preferences('grade_report_accuratepointtotals') == null ? 1 : 0;
// turn off fixed students column no matter what for this report
$fixedstudents = 0;
//$this->is_fixed_students();
$quickgrading = $this->get_pref('quickgrading');
// Preload scale objects for items with a scaleid
$scales_list = '';
$tabindices = array();
foreach ($this->gtree->items as $item) {
if (!empty($item->scaleid)) {
$scales_list .= "{$item->scaleid},";
}
if ($item->type == 'item') {
$tabindices[$item->id]['grade'] = $gradetabindex;
if ($showquickfeedback) {
$tabindices[$item->id]['feedback'] = $gradetabindex + $numusers;
$gradetabindex += $numusers * 2;
} else {
$gradetabindex += $numusers;
}
}
}
$scales_array = array();
if (!empty($scales_list)) {
$scales_list = substr($scales_list, 0, -1);
$scales_array = get_records_list('scale', 'id', $scales_list);
}
$row_classes = array(' even ', ' odd ');
foreach ($this->users as $userid => $user) {
if ($this->canviewhidden) {
$altered = array();
$unknown = array();
} else {
$hiding_affected = grade_grade::get_hiding_affected($this->grades[$userid], $this->gtree->items);
$altered = $hiding_affected['altered'];
$unknown = $hiding_affected['unknown'];
unset($hiding_affected);
}
$columncount = 0;
if ($fixedstudents) {
$studentshtml .= '<tr class="r' . $this->rowcount++ . $row_classes[$this->rowcount % 2] . '">';
} else {
// Student name and link
$user_pic = null;
if ($showuserimage) {
$user_pic = '<div class="userpic">' . print_user_picture($user, $this->courseid, null, 0, true) . '</div>';
}
//we're either going to add a th or a colspan to keep things aligned
// REMOVING $colspan AS ANYTHING
$userreportcell = '';
$userreportcellcolspan = '';
if (has_capability('gradereport/' . $CFG->grade_profilereport . ':view', $this->context)) {
$a->user = fullname($user);
$strgradesforuser = get_string('gradesforuser', 'grades', $a);
$userreportcell = '<td class="tduser"><a href="' . $CFG->wwwroot . '/grade/report/' . $CFG->grade_profilereport . '/index.php?id=' . $this->courseid . '&userid=' . $user->id . '" target="_blank">' . '<img class="userreport" src="' . $CFG->pixpath . '/t/grades.gif" alt="' . $strgradesforuser . '" style="align:center" title="' . $strgradesforuser . '" /></a></td>';
// $userreportcell = '<a href="'.$CFG->wwwroot.'/grade/report/'.$CFG->grade_profilereport.'/index.php?id='.$this->courseid.'&userid='.$user->id.'" target="_blank">'
// .'<img class="userreport" src="'.$CFG->pixpath.'/t/grades.gif" alt="'.$strgradesforuser.'" style="align:center" title="'.$strgradesforuser.'" /></a>';
} else {
$userreportcell = '<td class="userreport"></td>';
}
$studentshtml .= '<tr class="r' . $this->rowcount++ . $row_classes[$this->rowcount % 2] . '">' . '<th class="c' . $columncount++ . ' user">' . $user_pic . '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '&course=' . $this->course->id . '">' . $user->firstname . '<br /><span class="lastname">' . $user->lastname . "</a></span></th>{$userreportcell}";
// .fullname($user)."</a></th>$userreportcell";
if ($showuseridnumber) {
$studentshtml .= '<th class="c' . $columncount++ . ' useridnumber" onclick="set_row(this.parentNode.rowIndex);">' . $user->idnumber . '</th>';
}
}
// each loop does an item, entire cycle does a user's row
foreach ($this->gtree->items as $itemid => $unused) {
$item =& $this->gtree->items[$itemid];
$grade = $this->grades[$userid][$item->id];
// Get the decimal points preference for this item
$decimalpoints = $item->get_decimals();
if (in_array($itemid, $unknown)) {
$gradeval = null;
} else {
if (array_key_exists($itemid, $altered)) {
$gradeval = $altered[$itemid];
//.........这里部分代码省略.........
示例9: blank_hidden_total_and_adjust_bounds
/**
* Optionally blank out course/category totals if they contain any hidden items
* @param string $courseid the course id
* @param string $course_item an instance of grade_item
* @param string $finalgrade the grade for the course_item
* @return array[] containing values for 'grade', 'grademax', 'grademin', 'aggregationstatus' and 'aggregationweight'
*/
protected function blank_hidden_total_and_adjust_bounds($courseid, $course_item, $finalgrade)
{
global $CFG, $DB;
static $hiding_affected = null;
//array of items in this course affected by hiding
// If we're dealing with multiple users we need to know when we've moved on to a new user.
static $previous_userid = null;
// If we're dealing with multiple courses we need to know when we've moved on to a new course.
static $previous_courseid = null;
$coursegradegrade = grade_grade::fetch(array('userid' => $this->user->id, 'itemid' => $course_item->id));
$grademin = $course_item->grademin;
$grademax = $course_item->grademax;
if ($coursegradegrade) {
$grademin = $coursegradegrade->get_grade_min();
$grademax = $coursegradegrade->get_grade_max();
} else {
$coursegradegrade = new grade_grade(array('userid' => $this->user->id, 'itemid' => $course_item->id), false);
}
$hint = $coursegradegrade->get_aggregation_hint();
$aggregationstatus = $hint['status'];
$aggregationweight = $hint['weight'];
if (!is_array($this->showtotalsifcontainhidden)) {
debugging('showtotalsifcontainhidden should be an array', DEBUG_DEVELOPER);
$this->showtotalsifcontainhidden = array($courseid => $this->showtotalsifcontainhidden);
}
if ($this->showtotalsifcontainhidden[$courseid] == GRADE_REPORT_SHOW_REAL_TOTAL_IF_CONTAINS_HIDDEN) {
return array('grade' => $finalgrade, 'grademin' => $grademin, 'grademax' => $grademax, 'aggregationstatus' => $aggregationstatus, 'aggregationweight' => $aggregationweight);
}
// If we've moved on to another course or user, reload the grades.
if ($previous_userid != $this->user->id || $previous_courseid != $courseid) {
$hiding_affected = null;
$previous_userid = $this->user->id;
$previous_courseid = $courseid;
}
if (!$hiding_affected) {
$items = grade_item::fetch_all(array('courseid' => $courseid));
$grades = array();
$sql = "SELECT g.*\n FROM {grade_grades} g\n JOIN {grade_items} gi ON gi.id = g.itemid\n WHERE g.userid = {$this->user->id} AND gi.courseid = {$courseid}";
if ($gradesrecords = $DB->get_records_sql($sql)) {
foreach ($gradesrecords as $grade) {
$grades[$grade->itemid] = new grade_grade($grade, false);
}
unset($gradesrecords);
}
foreach ($items as $itemid => $unused) {
if (!isset($grades[$itemid])) {
$grade_grade = new grade_grade();
$grade_grade->userid = $this->user->id;
$grade_grade->itemid = $items[$itemid]->id;
$grades[$itemid] = $grade_grade;
}
$grades[$itemid]->grade_item =& $items[$itemid];
}
$hiding_affected = grade_grade::get_hiding_affected($grades, $items);
}
//if the item definitely depends on a hidden item
if (array_key_exists($course_item->id, $hiding_affected['altered']) || array_key_exists($course_item->id, $hiding_affected['alteredgrademin']) || array_key_exists($course_item->id, $hiding_affected['alteredgrademax']) || array_key_exists($course_item->id, $hiding_affected['alteredaggregationstatus']) || array_key_exists($course_item->id, $hiding_affected['alteredaggregationweight'])) {
if (!$this->showtotalsifcontainhidden[$courseid] && array_key_exists($course_item->id, $hiding_affected['altered'])) {
// Hide the grade, but only when it has changed.
$finalgrade = null;
} else {
//use reprocessed marks that exclude hidden items
if (array_key_exists($course_item->id, $hiding_affected['altered'])) {
$finalgrade = $hiding_affected['altered'][$course_item->id];
}
if (array_key_exists($course_item->id, $hiding_affected['alteredgrademin'])) {
$grademin = $hiding_affected['alteredgrademin'][$course_item->id];
}
if (array_key_exists($course_item->id, $hiding_affected['alteredgrademax'])) {
$grademax = $hiding_affected['alteredgrademax'][$course_item->id];
}
if (array_key_exists($course_item->id, $hiding_affected['alteredaggregationstatus'])) {
$aggregationstatus = $hiding_affected['alteredaggregationstatus'][$course_item->id];
}
if (array_key_exists($course_item->id, $hiding_affected['alteredaggregationweight'])) {
$aggregationweight = $hiding_affected['alteredaggregationweight'][$course_item->id];
}
if (!$this->showtotalsifcontainhidden[$courseid]) {
// If the course total is hidden we must hide the weight otherwise
// it can be used to compute the course total.
$aggregationstatus = 'unknown';
$aggregationweight = null;
}
}
} else {
if (!empty($hiding_affected['unknown'][$course_item->id])) {
//not sure whether or not this item depends on a hidden item
if (!$this->showtotalsifcontainhidden[$courseid]) {
//hide the grade
$finalgrade = null;
} else {
//use reprocessed marks that exclude hidden items
$finalgrade = $hiding_affected['unknown'][$course_item->id];
//.........这里部分代码省略.........
示例10: fill_table
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;
}
}
}
$class = 'gradeitem';
if ($grade_item->is_course_item()) {
$class = 'courseitem';
} else {
if ($grade_item->is_category_item()) {
$class = 'categoryitem';
}
}
if (in_array($itemid, $unknown)) {
$gradeval = null;
} else {
if (array_key_exists($itemid, $altered)) {
$gradeval = $altered[$itemid];
} else {
$gradeval = $grade_grade->finalgrade;
}
}
$data = array();
// all users should know which items are still hidden
$hidden = '';
if ($grade_item->is_hidden()) {
$hidden = ' hidden ';
}
$element = $this->gseq->locate_element($this->gseq->get_item_eid($grade_item));
$header = $this->gseq->get_element_header($element, true, true, true);
/// prints grade item name
$data[] = '<span class="' . $hidden . $class . '">' . $header . '</span>';
/// prints category
$cat = $grade_item->get_parent_category();
$data[] = '<span class="' . $hidden . $class . '">' . $cat->get_name() . '</span>';
$hidden = '';
if ($grade_item->is_hidden()) {
// can not see grades in hidden items
$hidden = ' hidden ';
} else {
if ($canviewhidden and $grade_grade->is_hidden()) {
// if user can see hidden grades, indicate which ones are hidden
$hidden = ' hidden ';
}
}
/// prints the grade
if ($grade_grade->is_excluded()) {
$excluded = get_string('excluded', 'grades') . ' ';
} else {
$excluded = '';
}
if ($grade_item->needsupdate) {
$data[] = '<span class="' . $hidden . $class . ' gradingerror">' . get_string('error') . '</span>';
} else {
if (!empty($CFG->grade_hiddenasdate) and $grade_grade->get_datesubmitted() and !$canviewhidden and $grade_grade->is_hidden() and !$grade_item->is_category_item() and !$grade_item->is_course_item()) {
// the problem here is that we do not have the time when grade value was modified, 'timemodified' is general modification date for grade_grades records
$data[] = '<span class="' . $hidden . $class . ' datesubmitted">' . $excluded . get_string('submittedon', 'grades', userdate($grade_grade->get_datesubmitted(), get_string('strftimedatetimeshort'))) . '</span>';
} else {
$data[] = '<span class="' . $hidden . $class . '">' . $excluded . grade_format_gradevalue($gradeval, $grade_item, true) . '</span>';
}
}
/// prints percentage
if ($grade_item->needsupdate) {
$data[] = '<span class="' . $hidden . $class . 'gradingerror">' . get_string('error') . '</span>';
//.........这里部分代码省略.........
示例11: blank_hidden_total
/**
* Optionally blank out course/category totals if they contain any hidden items
* @param string $courseid the course id
* @param string $course_item an instance of grade_item
* @param string $finalgrade the grade for the course_item
* @return string The new final grade
*/
function blank_hidden_total($courseid, $course_item, $finalgrade)
{
global $CFG;
static $hiding_affected = null;
//array of items in this course affected by hiding
if ($this->showtotalsifcontainhidden == GRADE_REPORT_SHOW_REAL_TOTAL_IF_CONTAINS_HIDDEN) {
return $finalgrade;
}
if (!$hiding_affected) {
$items = grade_item::fetch_all(array('courseid' => $courseid));
$grades = array();
$sql = "SELECT g.*\n FROM {$CFG->prefix}grade_grades g\n JOIN {$CFG->prefix}grade_items gi ON gi.id = g.itemid\n WHERE g.userid = {$this->user->id} AND gi.courseid = {$courseid}";
if ($gradesrecords = get_records_sql($sql)) {
foreach ($gradesrecords as $grade) {
$grades[$grade->itemid] = new grade_grade($grade, false);
}
unset($gradesrecords);
}
foreach ($items as $itemid => $unused) {
if (!isset($grades[$itemid])) {
$grade_grade = new grade_grade();
$grade_grade->userid = $this->user->id;
$grade_grade->itemid = $items[$itemid]->id;
$grades[$itemid] = $grade_grade;
}
$grades[$itemid]->grade_item =& $items[$itemid];
}
$hiding_affected = grade_grade::get_hiding_affected($grades, $items);
}
//if the item definitely depends on a hidden item
if (array_key_exists($course_item->id, $hiding_affected['altered'])) {
if (!$this->showtotalsifcontainhidden) {
//hide the grade
$finalgrade = null;
} else {
//use reprocessed marks that exclude hidden items
$finalgrade = $hiding_affected['altered'][$course_item->id];
}
} else {
if (!empty($hiding_affected['unknown'][$course_item->id])) {
//not sure whether or not this item depends on a hidden item
if (!$this->showtotalsifcontainhidden) {
//hide the grade
$finalgrade = null;
} else {
//use reprocessed marks that exclude hidden items
$finalgrade = $hiding_affected['unknown'][$course_item->id];
}
}
}
//unset($hiding_affected);
//unset($grades);
//unset($items);
return $finalgrade;
}