Ejemplo n.º 1
0
 /**
  * Constructor
  */
 public function __construct($gtree, $moving = false, $gpr)
 {
     global $USER, $OUTPUT, $COURSE;
     $systemdefault = get_config('moodle', 'grade_report_showcalculations');
     $this->show_calculations = get_user_preferences('grade_report_showcalculations', $systemdefault);
     $this->gtree = $gtree;
     $this->moving = $moving;
     $this->gpr = $gpr;
     $this->deepest_level = $this->get_deepest_level($this->gtree->top_element);
     $this->columns = array(grade_edit_tree_column::factory('name', array('deepest_level' => $this->deepest_level)));
     if ($this->uses_weight) {
         $this->columns[] = grade_edit_tree_column::factory('weight', array('adv' => 'weight'));
     }
     $this->columns[] = grade_edit_tree_column::factory('range');
     // This is not a setting... How do we deal with it?
     $this->columns[] = grade_edit_tree_column::factory('actions');
     if ($this->deepest_level > 1) {
         $this->columns[] = grade_edit_tree_column::factory('select');
     }
     $this->table = new html_table();
     $this->table->id = "grade_edit_tree_table";
     $this->table->attributes['class'] = 'generaltable simple setup-grades';
     if ($this->moving) {
         $this->table->attributes['class'] .= ' moving';
     }
     foreach ($this->columns as $column) {
         if (!($this->moving && $column->hide_when_moving)) {
             $this->table->head[] = $column->get_header_cell();
         }
     }
     $rowcount = 0;
     $this->table->data = $this->build_html_tree($this->gtree->top_element, true, array(), 0, $rowcount);
 }
Ejemplo n.º 2
0
 /**
  * Constructor
  */
 function grade_edit_tree($gtree, $moving = false, $gpr)
 {
     $this->gtree = $gtree;
     $this->moving = $moving;
     $this->gpr = $gpr;
     $this->deepest_level = $this->get_deepest_level($this->gtree->top_element);
     $this->columns = array(grade_edit_tree_column::factory('name', array('deepest_level' => $this->deepest_level)), grade_edit_tree_column::factory('aggregation', array('flag' => true)));
     if ($this->uses_weight) {
         $this->columns[] = grade_edit_tree_column::factory('weight', array('adv' => 'aggregationcoef'));
     }
     if ($this->uses_extra_credit) {
         $this->columns[] = grade_edit_tree_column::factory('extracredit', array('adv' => 'aggregationcoef'));
     }
     $this->columns[] = grade_edit_tree_column::factory('range');
     // This is not a setting... How do we deal with it?
     $this->columns[] = grade_edit_tree_column::factory('aggregateonlygraded', array('flag' => true));
     $this->columns[] = grade_edit_tree_column::factory('aggregatesubcats', array('flag' => true));
     $this->columns[] = grade_edit_tree_column::factory('aggregateoutcomes', array('flag' => true));
     $this->columns[] = grade_edit_tree_column::factory('droplow', array('flag' => true));
     $this->columns[] = grade_edit_tree_column::factory('keephigh', array('flag' => true));
     $this->columns[] = grade_edit_tree_column::factory('multfactor', array('adv' => true));
     $this->columns[] = grade_edit_tree_column::factory('plusfactor', array('adv' => true));
     $this->columns[] = grade_edit_tree_column::factory('actions');
     $this->columns[] = grade_edit_tree_column::factory('select');
 }
Ejemplo n.º 3
0
 public function test_grade_edit_tree_column_range_get_item_cell()
 {
     global $DB, $CFG;
     $this->resetAfterTest(true);
     // Make some things we need.
     $scale = $this->getDataGenerator()->create_scale();
     $course = $this->getDataGenerator()->create_course();
     $assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id));
     $modulecontext = context_module::instance($assign->id);
     // The generator returns a dummy object, lets get the real assign object.
     $assign = new assign($modulecontext, false, false);
     $cm = $assign->get_course_module();
     // Get range column.
     $column = grade_edit_tree_column::factory('range');
     $gradeitemparams = array('itemtype' => 'mod', 'itemmodule' => $cm->modname, 'iteminstance' => $cm->instance, 'courseid' => $cm->course, 'itemnumber' => 0);
     // Lets set the grade to something we know.
     $instance = $assign->get_instance();
     $instance->grade = 70;
     $instance->instance = $instance->id;
     $assign->update_instance($instance);
     $gradeitem = grade_item::fetch($gradeitemparams);
     $cell = $column->get_item_cell($gradeitem, array());
     $this->assertEquals(GRADE_TYPE_VALUE, $gradeitem->gradetype);
     $this->assertEquals(null, $gradeitem->scaleid);
     $this->assertEquals(70.0, (double) $cell->text, "Grade text is 70", 0.01);
     // Now change it to a scale.
     $instance = $assign->get_instance();
     $instance->grade = -$scale->id;
     $instance->instance = $instance->id;
     $assign->update_instance($instance);
     $gradeitem = grade_item::fetch($gradeitemparams);
     $cell = $column->get_item_cell($gradeitem, array());
     // Make the expected scale text.
     $scaleitems = null;
     $scaleitems = explode(',', $scale->scale);
     $scalestring = end($scaleitems) . ' (' . count($scaleitems) . ')';
     $this->assertEquals(GRADE_TYPE_SCALE, $gradeitem->gradetype);
     $this->assertEquals($scale->id, $gradeitem->scaleid);
     $this->assertEquals($scalestring, $cell->text, "Grade text matches scale");
     // Now change it to no grade.
     $instance = $assign->get_instance();
     $instance->grade = 0;
     $instance->instance = $instance->id;
     $assign->update_instance($instance);
     $gradeitem = grade_item::fetch($gradeitemparams);
     $cell = $column->get_item_cell($gradeitem, array());
     $this->assertEquals(GRADE_TYPE_TEXT, $gradeitem->gradetype);
     $this->assertEquals(null, $gradeitem->scaleid);
     $this->assertEquals(' - ', $cell->text, 'Grade text matches empty value of " - "');
 }
Ejemplo n.º 4
0
 /**
  * Constructor
  */
 public function __construct($gtree, $moving = false, $gpr)
 {
     global $USER, $OUTPUT, $COURSE;
     $this->gtree = $gtree;
     $this->moving = $moving;
     $this->gpr = $gpr;
     $this->deepest_level = $this->get_deepest_level($this->gtree->top_element);
     $this->columns = array(grade_edit_tree_column::factory('name', array('deepest_level' => $this->deepest_level)), grade_edit_tree_column::factory('aggregation', array('flag' => true)));
     if ($this->uses_weight) {
         $this->columns[] = grade_edit_tree_column::factory('weight', array('adv' => 'aggregationcoef'));
     }
     if ($this->uses_extra_credit) {
         $this->columns[] = grade_edit_tree_column::factory('extracredit', array('adv' => 'aggregationcoef'));
     }
     $this->columns[] = grade_edit_tree_column::factory('range');
     // This is not a setting... How do we deal with it?
     $this->columns[] = grade_edit_tree_column::factory('aggregateonlygraded', array('flag' => true));
     $this->columns[] = grade_edit_tree_column::factory('aggregatesubcats', array('flag' => true));
     $this->columns[] = grade_edit_tree_column::factory('aggregateoutcomes', array('flag' => true));
     $this->columns[] = grade_edit_tree_column::factory('droplow', array('flag' => true));
     $this->columns[] = grade_edit_tree_column::factory('keephigh', array('flag' => true));
     $this->columns[] = grade_edit_tree_column::factory('multfactor', array('adv' => true));
     $this->columns[] = grade_edit_tree_column::factory('plusfactor', array('adv' => true));
     $this->columns[] = grade_edit_tree_column::factory('actions');
     $this->columns[] = grade_edit_tree_column::factory('select');
     $mode = $USER->gradeediting[$COURSE->id] ? 'advanced' : 'simple';
     $widthstyle = '';
     if ($mode == 'simple') {
         $widthstyle = ' style="width:auto;" ';
     }
     $this->table = new html_table();
     $this->table->id = "grade_edit_tree_table";
     $this->table->cellpadding = 5;
     $this->table->attributes['class'] = 'generaltable ' . $mode;
     $this->table->style = $widthstyle;
     foreach ($this->columns as $column) {
         if (!($this->moving && $column->hide_when_moving) && !$column->is_hidden($mode)) {
             $this->table->head[] = $column->get_header_cell();
         }
     }
     $rowcount = 0;
     $this->table->data = $this->build_html_tree($this->gtree->top_element, true, array(), 0, $rowcount);
 }