Permalink
Browse files

Merge branch 'MDL-37153_24' of https://github.com/pauln/moodle into M…

…OODLE_24_STABLE
  • Loading branch information...
2 parents 49e3cda + 3e2821e commit 7bd19d562dce619a3ec52974e1e7a3c418e0b28f @marinaglancy marinaglancy committed Oct 10, 2013
Showing with 33 additions and 3 deletions.
  1. +33 −3 mod/assign/locallib.php
@@ -77,6 +77,9 @@ class assign {
/** @var stdClass the assignment record that contains the global settings for this assign instance */
private $instance;
+ /** @var stdClass the grade_item record for this assign instance's primary grade item. */
+ private $gradeitem;
+
/** @var context the context of the course module for this assign instance (or just the course if we are
creating a new one) */
private $context;
@@ -951,6 +954,29 @@ public function get_instance() {
}
/**
+ * Get the primary grade item for this assign instance.
+ *
+ * @return stdClass The grade_item record
+ */
+ public function get_grade_item() {
+ if ($this->gradeitem) {
+ return $this->gradeitem;
+ }
+ $instance = $this->get_instance();
+ $params = array('itemtype' => 'mod',
+ 'itemmodule' => 'assign',
+ 'iteminstance' => $instance->id,
+ 'courseid' => $instance->course,
+ 'itemnumber' => 0);
+ $this->gradeitem = grade_item::fetch($params);
+ if (!$this->gradeitem) {
+ throw new coding_exception('Improper use of the assignment class. ' .
+ 'Cannot load the grade item.');
+ }
+ return $this->gradeitem;
+ }
+
+ /**
* Get the context of the current course
* @return mixed context|null The course context
*/
@@ -1046,11 +1072,15 @@ public function display_grade($grade, $editing, $userid=0, $modified=0) {
$o .= '<input type="hidden" name="grademodified_' . $userid . '" value="' . $modified . '"/>';
if ($grade == -1 || $grade === null) {
$o .= '-';
- return $o;
} else {
- $o .= format_float(($grade),2) .'&nbsp;/&nbsp;'. format_float($this->get_instance()->grade,2);
- return $o;
+ $item = $this->get_grade_item();
+ $o .= grade_format_gradevalue($grade, $item);
+ if ($item->get_displaytype() == GRADE_DISPLAY_TYPE_REAL) {
+ // If displaying the raw grade, also display the total value.
+ $o .= '&nbsp;/&nbsp;' . format_float($this->get_instance()->grade, 2);
+ }
}
+ return $o;
}
} else {

0 comments on commit 7bd19d5

Please sign in to comment.