Merge branch 'MDL-37153_master' of https://github.com/pauln/moodle
authorMarina Glancy <marina@moodle.com>
Thu, 10 Oct 2013 01:52:28 +0000 (12:52 +1100)
committerMarina Glancy <marina@moodle.com>
Thu, 10 Oct 2013 01:52:28 +0000 (12:52 +1100)
1  2 
mod/assign/locallib.php

diff --combined mod/assign/locallib.php
@@@ -77,6 -77,9 +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)
       */
          return $this->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.
       *
                  $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 {
      public function can_view_group_submission($groupid) {
          global $USER;
  
 -        if (!is_enrolled($this->get_course_context(), $USER->id)) {
 -            return false;
 -        }
          if (has_capability('mod/assign:grade', $this->context)) {
              return true;
          }
 +        if (!is_enrolled($this->get_course_context(), $USER->id)) {
 +            return false;
 +        }
          $members = $this->get_submission_group_members($groupid, true);
          foreach ($members as $member) {
              if ($member->id == $USER->id) {
      public function can_view_submission($userid) {
          global $USER;
  
 -        if (is_siteadmin()) {
 -            return true;
 -        }
 -        if (!is_enrolled($this->get_course_context(), $userid)) {
 +        if (!$this->is_active_user($userid) && !has_capability('moodle/course:viewsuspendedusers', $this->context)) {
              return false;
          }
 -        if ($userid == $USER->id && has_capability('mod/assign:submit', $this->context)) {
 +        if (has_capability('mod/assign:grade', $this->context)) {
              return true;
          }
 -        if (!$this->is_active_user($userid) && !has_capability('moodle/course:viewsuspendedusers', $this->context)) {
 +        if (!is_enrolled($this->get_course_context(), $userid)) {
              return false;
          }
 -        if (has_capability('mod/assign:grade', $this->context)) {
 +        if ($userid == $USER->id && has_capability('mod/assign:submit', $this->context)) {
              return true;
          }
          return false;