private function get_moodle_grades()
 {
     global $DB, $CFG;
     $grades = $DB->get_records('grade_grades', array('itemid' => $this->course_grade_item->id), 'userid', 'userid, finalgrade');
     if (!is_array($grades)) {
         $grades = array();
     }
     $this->moodle_grades = array();
     if ($this->course_grade_item->gradetype == GRADE_TYPE_SCALE) {
         $pg_scale = new grade_scale(array('id' => $CFG->grade_report_newgradereport_scale));
         $scale_items = $pg_scale->load_items();
         foreach ($this->moodle_students as $st) {
             if (isset($grades[$st->id])) {
                 $fg = (int) $grades[$st->id]->finalgrade;
                 if (isset($scale_items[$fg - 1])) {
                     $this->moodle_grades[$st->id] = $scale_items[$fg - 1];
                 } else {
                     $this->moodle_grades[$st->id] = null;
                 }
             } else {
                 $this->moodle_grades[$st->id] = null;
             }
         }
     } else {
         foreach ($this->moodle_students as $st) {
             if (isset($grades[$st->id])) {
                 $this->moodle_grades[$st->id] = grade_format_gradevalue($grades[$st->id]->finalgrade, $this->course_grade_item, true, $this->course_grade_item->get_displaytype(), null);
             } else {
                 $this->moodle_grades[$st->id] = null;
             }
         }
     }
 }
示例#2
0
 /**
  * Instantiates a grade_scale object from the DB if this item's scaleid variable is set
  *
  * @return grade_scale Returns a grade_scale object or null if no scale used
  */
 public function load_scale()
 {
     if ($this->gradetype != GRADE_TYPE_SCALE) {
         $this->scaleid = null;
     }
     if (!empty($this->scaleid)) {
         //do not load scale if already present
         if (empty($this->scale->id) or $this->scale->id != $this->scaleid) {
             $this->scale = grade_scale::fetch(array('id' => $this->scaleid));
             if (!$this->scale) {
                 debugging('Incorrect scale id: ' . $this->scaleid);
                 $this->scale = null;
                 return null;
             }
             $this->scale->load_items();
         }
         // Until scales are uniformly set to min=0 max=count(scaleitems)-1 throughout Moodle, we
         // stay with the current min=1 max=count(scaleitems)
         $this->grademax = count($this->scale->scale_items);
         $this->grademin = 1;
     } else {
         $this->scale = null;
     }
     return $this->scale;
 }
示例#3
0
 protected function sub_test_scale_one_item()
 {
     $params = new stdClass();
     $params->name = 'unittestscale1i';
     $params->courseid = $this->course->id;
     $params->userid = $this->userid;
     $params->scale = 'Like';
     $params->description = 'This scale is used to like something.';
     $params->timemodified = time();
     $scale = new grade_scale($params, false);
     $scale->load_items();
     $this->assertCount(1, $scale->scale_items);
     $this->assertSame(array('Like'), $scale->scale_items);
     $this->assertSame('Like', $scale->compact_items());
     $scale->insert();
     // Manual grade item with 1 item scale.
     $grade_item = new stdClass();
     $grade_item->courseid = $this->course->id;
     $grade_item->categoryid = $this->grade_categories[0]->id;
     $grade_item->itemname = 'manual grade_item scale_1';
     $grade_item->itemtype = 'manual';
     $grade_item->itemnumber = 0;
     $grade_item->needsupdate = false;
     $grade_item->gradetype = GRADE_TYPE_SCALE;
     $grade_item->scaleid = $scale->id;
     $grade_item->iteminfo = 'Manual grade item used for unit testing';
     $grade_item->timecreated = time();
     $grade_item->timemodified = time();
     $grade_item = new grade_item($grade_item);
     $grade_item->insert();
     $this->assertNotEmpty($grade_item->id);
     $this->assertEquals(1, $grade_item->grademin);
     $this->assertEquals(1, $grade_item->grademax);
 }