MDL-55928 gradereport_user: Return grade items data among the table data

This commit is contained in:
Juan Leyva 2016-09-12 14:00:17 +01:00
parent 0344082208
commit 345330d172

View File

@ -67,6 +67,12 @@ class grade_report_user extends grade_report {
*/ */
public $tabledata = array(); 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 * The grade tree structure
* @var grade_tree * @var grade_tree
@ -387,6 +393,7 @@ class grade_report_user extends grade_report {
$element['userid'] = $this->user->id; $element['userid'] = $this->user->id;
$fullname = $this->gtree->get_element_header($element, true, true, true, true, true); $fullname = $this->gtree->get_element_header($element, true, true, true, true, true);
$data = array(); $data = array();
$gradeitemdata = array();
$hidden = ''; $hidden = '';
$excluded = ''; $excluded = '';
$itemlevel = ($type == 'categoryitem' || $type == 'category' || $type == 'courseitem') ? $depth : ($depth + 1); $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); $instances = $this->modinfo->get_instances_of($grade_object->itemmodule);
if (!empty($instances[$grade_object->iteminstance])) { if (!empty($instances[$grade_object->iteminstance])) {
$cm = $instances[$grade_object->iteminstance]; $cm = $instances[$grade_object->iteminstance];
$gradeitemdata['cmid'] = $cm->id;
if (!$cm->uservisible) { if (!$cm->uservisible) {
// If there is 'availableinfo' text then it is only greyed // If there is 'availableinfo' text then it is only greyed
// out and not entirely hidden. // out and not entirely hidden.
@ -499,6 +507,16 @@ class grade_report_user extends grade_report {
$data['itemname']['celltype'] = 'th'; $data['itemname']['celltype'] = 'th';
$data['itemname']['id'] = $header_row; $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) { if ($this->showfeedback) {
// Copy $class before appending itemcenter as feedback should not be centered // Copy $class before appending itemcenter as feedback should not be centered
$classfeedback = $class; $classfeedback = $class;
@ -513,13 +531,23 @@ class grade_report_user extends grade_report {
// This obliterates the weight because it provides a more informative description. // This obliterates the weight because it provides a more informative description.
if (is_numeric($hint['weight'])) { if (is_numeric($hint['weight'])) {
$data['weight']['content'] = format_float($hint['weight'] * 100.0, 2) . ' %'; $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') { if ($hint['status'] != 'used' && $hint['status'] != 'unknown') {
$data['weight']['content'] .= '<br>' . get_string('aggregationhint' . $hint['status'], 'grades'); $data['weight']['content'] .= '<br>' . get_string('aggregationhint' . $hint['status'], 'grades');
$gradeitemdata['status'] = $hint['status'];
} }
} }
if ($this->showgrade) { 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) { if ($grade_grade->grade_item->needsupdate) {
$data['grade']['class'] = $class.' gradingerror'; $data['grade']['class'] = $class.' gradingerror';
$data['grade']['content'] = get_string('error'); $data['grade']['content'] = get_string('error');
@ -529,11 +557,13 @@ class grade_report_user extends grade_report {
$class .= ' datesubmitted'; $class .= ' datesubmitted';
$data['grade']['class'] = $class; $data['grade']['class'] = $class;
$data['grade']['content'] = get_string('submittedon', 'grades', userdate($grade_grade->get_datesubmitted(), get_string('strftimedatetimeshort'))); $data['grade']['content'] = get_string('submittedon', 'grades', userdate($grade_grade->get_datesubmitted(), get_string('strftimedatetimeshort')));
$gradeitemdata['gradehiddenbydate'] = true;
} else if ($grade_grade->is_hidden()) { } else if ($grade_grade->is_hidden()) {
$data['grade']['class'] = $class.' dimmed_text'; $data['grade']['class'] = $class.' dimmed_text';
$data['grade']['content'] = '-'; $data['grade']['content'] = '-';
if ($this->canviewhidden) { if ($this->canviewhidden) {
$gradeitemdata['graderaw'] = $gradeval;
$data['grade']['content'] = grade_format_gradevalue($gradeval, $data['grade']['content'] = grade_format_gradevalue($gradeval,
$grade_grade->grade_item, $grade_grade->grade_item,
true); true);
@ -543,8 +573,10 @@ class grade_report_user extends grade_report {
$data['grade']['content'] = grade_format_gradevalue($gradeval, $data['grade']['content'] = grade_format_gradevalue($gradeval,
$grade_grade->grade_item, $grade_grade->grade_item,
true); true);
$gradeitemdata['graderaw'] = $gradeval;
} }
$data['grade']['headers'] = "$header_cat $header_row grade"; $data['grade']['headers'] = "$header_cat $header_row grade";
$gradeitemdata['gradeformatted'] = $data['grade']['content'];
} }
// Range // Range
@ -552,6 +584,10 @@ class grade_report_user extends grade_report {
$data['range']['class'] = $class; $data['range']['class'] = $class;
$data['range']['content'] = $grade_grade->grade_item->get_formatted_range(GRADE_DISPLAY_TYPE_REAL, $this->rangedecimals); $data['range']['content'] = $grade_grade->grade_item->get_formatted_range(GRADE_DISPLAY_TYPE_REAL, $this->rangedecimals);
$data['range']['headers'] = "$header_cat $header_row range"; $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 // 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']['content'] = grade_format_gradevalue($gradeval, $grade_grade->grade_item, true, GRADE_DISPLAY_TYPE_PERCENTAGE);
} }
$data['percentage']['headers'] = "$header_cat $header_row percentage"; $data['percentage']['headers'] = "$header_cat $header_row percentage";
$gradeitemdata['percentageformatted'] = $data['percentage']['content'];
} }
// Lettergrade // 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']['content'] = grade_format_gradevalue($gradeval, $grade_grade->grade_item, true, GRADE_DISPLAY_TYPE_LETTER);
} }
$data['lettergrade']['headers'] = "$header_cat $header_row lettergrade"; $data['lettergrade']['headers'] = "$header_cat $header_row lettergrade";
$gradeitemdata['lettergradeformatted'] = $data['lettergrade']['content'];
} }
// Rank // Rank
if ($this->showrank) { if ($this->showrank) {
$gradeitemdata['rank'] = 0;
if ($grade_grade->grade_item->needsupdate) { if ($grade_grade->grade_item->needsupdate) {
$data['rank']['class'] = $class.' gradingerror'; $data['rank']['class'] = $class.' gradingerror';
$data['rank']['content'] = get_string('error'); $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; $rank = $DB->count_records_sql($sql, array($grade_grade->finalgrade, $grade_grade->grade_item->id)) + 1;
$data['rank']['class'] = $class; $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"; $data['rank']['headers'] = "$header_cat $header_row rank";
} }
// Average // Average
if ($this->showaverage) { if ($this->showaverage) {
$gradeitemdata['averageformatted'] = '';
$data['average']['class'] = $class; $data['average']['class'] = $class;
if (!empty($this->gtree->items[$eid]->avg)) { if (!empty($this->gtree->items[$eid]->avg)) {
$data['average']['content'] = $this->gtree->items[$eid]->avg; $data['average']['content'] = $this->gtree->items[$eid]->avg;
$gradeitemdata['averageformatted'] = $this->gtree->items[$eid]->avg;
} else { } else {
$data['average']['content'] = '-'; $data['average']['content'] = '-';
} }
@ -632,15 +678,20 @@ class grade_report_user extends grade_report {
// Feedback // Feedback
if ($this->showfeedback) { if ($this->showfeedback) {
$gradeitemdata['feedback'] = '';
$gradeitemdata['feedbackformat'] = $grade_grade->feedbackformat;
if ($grade_grade->overridden > 0 AND ($type == 'categoryitem' OR $type == 'courseitem')) { if ($grade_grade->overridden > 0 AND ($type == 'categoryitem' OR $type == 'courseitem')) {
$data['feedback']['class'] = $classfeedback.' feedbacktext'; $data['feedback']['class'] = $classfeedback.' feedbacktext';
$data['feedback']['content'] = get_string('overridden', 'grades').': ' . format_text($grade_grade->feedback, $grade_grade->feedbackformat); $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())) { } else if (empty($grade_grade->feedback) or (!$this->canviewhidden and $grade_grade->is_hidden())) {
$data['feedback']['class'] = $classfeedback.' feedbacktext'; $data['feedback']['class'] = $classfeedback.' feedbacktext';
$data['feedback']['content'] = '&nbsp;'; $data['feedback']['content'] = '&nbsp;';
} else { } else {
$data['feedback']['class'] = $classfeedback.' feedbacktext'; $data['feedback']['class'] = $classfeedback.' feedbacktext';
$data['feedback']['content'] = format_text($grade_grade->feedback, $grade_grade->feedbackformat); $data['feedback']['content'] = format_text($grade_grade->feedback, $grade_grade->feedbackformat);
$gradeitemdata['feedback'] = $grade_grade->feedback;
} }
$data['feedback']['headers'] = "$header_cat $header_row 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"; $data['contributiontocoursetotal']['headers'] = "$header_cat $header_row contributiontocoursetotal";
} }
$this->gradeitemsdata[] = $gradeitemdata;
} }
// We collect the aggregation hints whether they are hidden or not. // We collect the aggregation hints whether they are hidden or not.
if ($this->showcontributiontocoursetotal) { if ($this->showcontributiontocoursetotal) {