Skip to content

Commit

Permalink
MDL-15680 Committing the small refactorings required for the implemen…
Browse files Browse the repository at this point in the history
…tation of the weights interface
  • Loading branch information
nicolasconnault committed Oct 13, 2008
1 parent 4cbdb49 commit c833e8c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 36 deletions.
48 changes: 12 additions & 36 deletions grade/report/grader/lib.php
Expand Up @@ -251,7 +251,7 @@ function setup_sortitemid() {
// this is the first sort, i.e. by last name
if (!isset($SESSION->gradeuserreport->sortitemid)) {
if ($this->sortitemid == 'firstname' || $this->sortitemid == 'lastname') {
$this->sortorder = $SESSION->gradeuserreport->sort = 'ASC';
$this->sortorder = $SESSION->gradeuserreport->sort = 'ASC';
} else {
$this->sortorder = $SESSION->gradeuserreport->sort = 'DESC';
}
Expand Down Expand Up @@ -672,7 +672,7 @@ function get_studentshtml() {
$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 ');
Expand Down Expand Up @@ -768,7 +768,7 @@ function get_studentshtml() {
$hidden = ' hidden ';
}

$gradepass = ' gradefail ';
$gradepass = ' gradefail ';
if ($grade->is_passed($item)) {
$gradepass = ' gradepass ';
} elseif (is_null($grade->is_passed($item))) {
Expand Down Expand Up @@ -932,8 +932,8 @@ function get_avghtml($grouponly=false) {
// find sums of all grade items in course
$SQL = "SELECT g.itemid, SUM(g.finalgrade) AS sum
FROM {$CFG->prefix}grade_items gi
JOIN {$CFG->prefix}grade_grades g ON g.itemid = gi.id
JOIN {$CFG->prefix}user u ON u.id = g.userid
JOIN {$CFG->prefix}grade_grades g ON g.itemid = gi.id
JOIN {$CFG->prefix}user u ON u.id = g.userid
JOIN {$CFG->prefix}role_assignments ra ON ra.userid = u.id
$groupsql
WHERE gi.courseid = $this->courseid
Expand Down Expand Up @@ -967,7 +967,7 @@ function get_avghtml($grouponly=false) {
FROM {$CFG->prefix}grade_items gi
CROSS JOIN {$CFG->prefix}user u
JOIN {$CFG->prefix}role_assignments ra ON ra.userid = u.id
LEFT OUTER JOIN {$CFG->prefix}grade_grades g ON (g.itemid = gi.id AND g.userid = u.id AND g.finalgrade IS NOT NULL)
LEFT OUTER JOIN {$CFG->prefix}grade_grades g ON (g.itemid = gi.id AND g.userid = u.id AND g.finalgrade IS NOT NULL)
$groupsql
WHERE gi.courseid = $this->courseid
AND ra.roleid in ($this->gradebookroles)
Expand Down Expand Up @@ -1073,46 +1073,22 @@ function get_rangehtml() {
foreach ($this->gtree->items as $itemid=>$unused) {
$item =& $this->gtree->items[$itemid];

// Determine which display type to use for this average
if ($USER->gradeediting[$this->courseid]) {
$displaytype = GRADE_DISPLAY_TYPE_REAL;

} else if ($rangesdisplaytype == GRADE_REPORT_PREFERENCE_INHERIT) { // no ==0 here, please resave report and user prefs
$displaytype = $item->get_displaytype();

} else {
$displaytype = $rangesdisplaytype;
}

// Override grade_item setting if a display preference (not default) was set for the averages
if ($rangesdecimalpoints == GRADE_REPORT_PREFERENCE_INHERIT) {
$decimalpoints = $item->get_decimals();

} else {
$decimalpoints = $rangesdecimalpoints;
}

if ($displaytype == GRADE_DISPLAY_TYPE_PERCENTAGE) {
$grademin = "0 %";
$grademax = "100 %";

} else {
$grademin = grade_format_gradevalue($item->grademin, $item, true, $displaytype, $decimalpoints);
$grademax = grade_format_gradevalue($item->grademax, $item, true, $displaytype, $decimalpoints);
}

$hidden = '';
if ($item->is_hidden()) {
$hidden = ' hidden ';
}

$scalehtml .= '<th class="header c'.$columncount++.' range"><span class="rangevalues'.$hidden.'">'. $grademin.'&ndash;'. $grademax.'</span></th>';
$formatted_range = $item->get_formatted_range($rangesdisplaytype, $rangesdecimalpoints);

$scalehtml .= '<th class="header c'.$columncount++.' range"><span class="rangevalues'.$hidden.'">'. $formatted_range .'</span></th>';

}
$scalehtml .= '</tr>';
}
return $scalehtml;
}

/**
* Builds and return the HTML row of ranges for each column (i.e. range).
* @return string HTML
Expand All @@ -1135,7 +1111,7 @@ function get_iconshtml() {
foreach ($this->gtree->items as $itemid=>$unused) {
// emulate grade element
$item =& $this->gtree->items[$itemid];

$eid = $this->gtree->get_item_eid($item);
$element = $this->gtree->locate_element($eid);

Expand Down
42 changes: 42 additions & 0 deletions lib/grade/grade_item.php
Expand Up @@ -1866,5 +1866,47 @@ function get_decimals() {
return $this->decimals;
}
}

/**
* Returns a string representing the range of grademin - grademax for this grade item.
* @param int $rangesdisplaytype
* @param int $rangesdecimalpoints
* @return string
*/
function get_formatted_range($rangesdisplaytype=null, $rangesdecimalpoints=null) {

global $USER;

// Determine which display type to use for this average
if ($USER->gradeediting[$this->courseid]) {
$displaytype = GRADE_DISPLAY_TYPE_REAL;

} else if ($rangesdisplaytype == GRADE_REPORT_PREFERENCE_INHERIT) { // no ==0 here, please resave report and user prefs
$displaytype = $this->get_displaytype();

} else {
$displaytype = $rangesdisplaytype;
}

// Override grade_item setting if a display preference (not default) was set for the averages
if ($rangesdecimalpoints == GRADE_REPORT_PREFERENCE_INHERIT) {
$decimalpoints = $this->get_decimals();

} else {
$decimalpoints = $rangesdecimalpoints;
}

if ($displaytype == GRADE_DISPLAY_TYPE_PERCENTAGE) {
$grademin = "0 %";
$grademax = "100 %";

} else {
$grademin = grade_format_gradevalue($this->grademin, $this, true, $displaytype, $decimalpoints);
$grademax = grade_format_gradevalue($this->grademax, $this, true, $displaytype, $decimalpoints);
}

return $grademin.'&ndash;'. $grademax;
}

}
?>

0 comments on commit c833e8c

Please sign in to comment.