diff --git a/grade/report/user/lib.php b/grade/report/user/lib.php index 65f66a6ebca..a6f15d1c643 100644 --- a/grade/report/user/lib.php +++ b/grade/report/user/lib.php @@ -67,6 +67,12 @@ class grade_report_user extends grade_report { */ public $tabledata = array(); + /** + * An array containing the grade items data for external usage (web services, ajax, etc...) + * @var array + */ + public $gradeitemsdata = array(); + /** * The grade tree structure * @var grade_tree @@ -387,6 +393,7 @@ class grade_report_user extends grade_report { $element['userid'] = $this->user->id; $fullname = $this->gtree->get_element_header($element, true, true, true, true, true); $data = array(); + $gradeitemdata = array(); $hidden = ''; $excluded = ''; $itemlevel = ($type == 'categoryitem' || $type == 'category' || $type == 'courseitem') ? $depth : ($depth + 1); @@ -436,6 +443,7 @@ class grade_report_user extends grade_report { $instances = $this->modinfo->get_instances_of($grade_object->itemmodule); if (!empty($instances[$grade_object->iteminstance])) { $cm = $instances[$grade_object->iteminstance]; + $gradeitemdata['cmid'] = $cm->id; if (!$cm->uservisible) { // If there is 'availableinfo' text then it is only greyed // out and not entirely hidden. @@ -499,6 +507,16 @@ class grade_report_user extends grade_report { $data['itemname']['celltype'] = 'th'; $data['itemname']['id'] = $header_row; + // Basic grade item information. + $gradeitemdata['id'] = $grade_object->id; + $gradeitemdata['itemtype'] = $grade_object->itemtype; + $gradeitemdata['itemmodule'] = $grade_object->itemmodule; + $gradeitemdata['iteminstance'] = $grade_object->iteminstance; + $gradeitemdata['itemnumber'] = $grade_object->itemnumber; + $gradeitemdata['categoryid'] = $grade_object->categoryid; + $gradeitemdata['outcomeid'] = $grade_object->outcomeid; + $gradeitemdata['scaleid'] = $grade_object->outcomeid; + if ($this->showfeedback) { // Copy $class before appending itemcenter as feedback should not be centered $classfeedback = $class; @@ -513,13 +531,23 @@ class grade_report_user extends grade_report { // This obliterates the weight because it provides a more informative description. if (is_numeric($hint['weight'])) { $data['weight']['content'] = format_float($hint['weight'] * 100.0, 2) . ' %'; + $gradeitemdata['weightraw'] = $hint['weight']; + $gradeitemdata['weightformatted'] = $data['weight']['content']; } if ($hint['status'] != 'used' && $hint['status'] != 'unknown') { $data['weight']['content'] .= '
' . get_string('aggregationhint' . $hint['status'], 'grades'); + $gradeitemdata['status'] = $hint['status']; } } if ($this->showgrade) { + $gradeitemdata['graderaw'] = ''; + $gradeitemdata['gradehiddenbydate'] = false; + $gradeitemdata['gradeneedsupdate'] = $grade_grade->grade_item->needsupdate; + $gradeitemdata['gradeishidden'] = $grade_grade->is_hidden(); + $gradeitemdata['gradedatesubmitted'] = $grade_grade->get_datesubmitted(); + $gradeitemdata['gradedategraded'] = $grade_grade->get_dategraded(); + if ($grade_grade->grade_item->needsupdate) { $data['grade']['class'] = $class.' gradingerror'; $data['grade']['content'] = get_string('error'); @@ -529,11 +557,13 @@ class grade_report_user extends grade_report { $class .= ' datesubmitted'; $data['grade']['class'] = $class; $data['grade']['content'] = get_string('submittedon', 'grades', userdate($grade_grade->get_datesubmitted(), get_string('strftimedatetimeshort'))); - + $gradeitemdata['gradehiddenbydate'] = true; } else if ($grade_grade->is_hidden()) { $data['grade']['class'] = $class.' dimmed_text'; $data['grade']['content'] = '-'; + if ($this->canviewhidden) { + $gradeitemdata['graderaw'] = $gradeval; $data['grade']['content'] = grade_format_gradevalue($gradeval, $grade_grade->grade_item, true); @@ -543,8 +573,10 @@ class grade_report_user extends grade_report { $data['grade']['content'] = grade_format_gradevalue($gradeval, $grade_grade->grade_item, true); + $gradeitemdata['graderaw'] = $gradeval; } $data['grade']['headers'] = "$header_cat $header_row grade"; + $gradeitemdata['gradeformatted'] = $data['grade']['content']; } // Range @@ -552,6 +584,10 @@ class grade_report_user extends grade_report { $data['range']['class'] = $class; $data['range']['content'] = $grade_grade->grade_item->get_formatted_range(GRADE_DISPLAY_TYPE_REAL, $this->rangedecimals); $data['range']['headers'] = "$header_cat $header_row range"; + + $gradeitemdata['rangeformatted'] = $data['range']['content']; + $gradeitemdata['grademin'] = $grade_grade->grade_item->grademin; + $gradeitemdata['grademax'] = $grade_grade->grade_item->grademax; } // Percentage @@ -570,6 +606,7 @@ class grade_report_user extends grade_report { $data['percentage']['content'] = grade_format_gradevalue($gradeval, $grade_grade->grade_item, true, GRADE_DISPLAY_TYPE_PERCENTAGE); } $data['percentage']['headers'] = "$header_cat $header_row percentage"; + $gradeitemdata['percentageformatted'] = $data['percentage']['content']; } // Lettergrade @@ -589,10 +626,12 @@ class grade_report_user extends grade_report { $data['lettergrade']['content'] = grade_format_gradevalue($gradeval, $grade_grade->grade_item, true, GRADE_DISPLAY_TYPE_LETTER); } $data['lettergrade']['headers'] = "$header_cat $header_row lettergrade"; + $gradeitemdata['lettergradeformatted'] = $data['lettergrade']['content']; } // Rank if ($this->showrank) { + $gradeitemdata['rank'] = 0; if ($grade_grade->grade_item->needsupdate) { $data['rank']['class'] = $class.' gradingerror'; $data['rank']['content'] = get_string('error'); @@ -614,16 +653,23 @@ class grade_report_user extends grade_report { $rank = $DB->count_records_sql($sql, array($grade_grade->finalgrade, $grade_grade->grade_item->id)) + 1; $data['rank']['class'] = $class; - $data['rank']['content'] = "$rank/".$this->get_numusers(false); // total course users + $numusers = $this->get_numusers(false); + $data['rank']['content'] = "$rank/$numusers"; // Total course users. + + $gradeitemdata['rank'] = $rank; + $gradeitemdata['numusers'] = $numusers; } $data['rank']['headers'] = "$header_cat $header_row rank"; } // Average if ($this->showaverage) { + $gradeitemdata['averageformatted'] = ''; + $data['average']['class'] = $class; if (!empty($this->gtree->items[$eid]->avg)) { $data['average']['content'] = $this->gtree->items[$eid]->avg; + $gradeitemdata['averageformatted'] = $this->gtree->items[$eid]->avg; } else { $data['average']['content'] = '-'; } @@ -632,15 +678,20 @@ class grade_report_user extends grade_report { // Feedback if ($this->showfeedback) { + $gradeitemdata['feedback'] = ''; + $gradeitemdata['feedbackformat'] = $grade_grade->feedbackformat; + if ($grade_grade->overridden > 0 AND ($type == 'categoryitem' OR $type == 'courseitem')) { $data['feedback']['class'] = $classfeedback.' feedbacktext'; $data['feedback']['content'] = get_string('overridden', 'grades').': ' . format_text($grade_grade->feedback, $grade_grade->feedbackformat); + $gradeitemdata['feedback'] = $grade_grade->feedback; } else if (empty($grade_grade->feedback) or (!$this->canviewhidden and $grade_grade->is_hidden())) { $data['feedback']['class'] = $classfeedback.' feedbacktext'; $data['feedback']['content'] = ' '; } else { $data['feedback']['class'] = $classfeedback.' feedbacktext'; $data['feedback']['content'] = format_text($grade_grade->feedback, $grade_grade->feedbackformat); + $gradeitemdata['feedback'] = $grade_grade->feedback; } $data['feedback']['headers'] = "$header_cat $header_row feedback"; } @@ -651,6 +702,7 @@ class grade_report_user extends grade_report { $data['contributiontocoursetotal']['headers'] = "$header_cat $header_row contributiontocoursetotal"; } + $this->gradeitemsdata[] = $gradeitemdata; } // We collect the aggregation hints whether they are hidden or not. if ($this->showcontributiontocoursetotal) {