public $deepest_level;
- public $uses_extra_credit = false;
-
public $uses_weight = false;
+ /** @var bool indicates if tree has categories with aggregation method other than Natural. */
+ protected $uses_non_natural = false;
+
public $table;
public $categories = array();
$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)));
+ $this->columns = array(grade_edit_tree_column::factory('name', array('deepest_level' => $this->deepest_level)));
+
+ if ($this->uses_non_natural) {
+ $this->columns[] = grade_edit_tree_column::factory('aggregation', array('flag' => true));
+ }
if ($this->uses_weight) {
$this->columns[] = grade_edit_tree_column::factory('weight', array('adv' => 'weight'));
}
- 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('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('plusfactor', array('adv' => true));*/
$this->columns[] = grade_edit_tree_column::factory('actions');
- $this->columns[] = grade_edit_tree_column::factory('select');
+
+ 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";
/**
* Given a grade_item object, returns a labelled input if an aggregation coefficient (weight or extra credit) applies to it.
* @param grade_item $item
- * @param string type "extra" or "weight": the type of the column hosting the weight input
* @return string HTML
*/
- static function get_weight_input($item, $type) {
+ static function get_weight_input($item) {
global $OUTPUT;
if (!is_object($item) || get_class($item) !== 'grade_item') {
$parent_category->apply_forced_settings();
$aggcoef = $item->get_coefstring();
- if ((($aggcoef == 'aggregationcoefweight' || $aggcoef == 'aggregationcoef') && $type == 'weight') ||
- ($aggcoef == 'aggregationcoefextraweight' && $type == 'extra')) {
+ $str = '';
+
+ if ($aggcoef == 'aggregationcoefweight' || $aggcoef == 'aggregationcoef' || $aggcoef == 'aggregationcoefextraweight') {
return '<label class="accesshide" for="weight_'.$item->id.'">'.
get_string('extracreditvalue', 'grades', $item->itemname).'</label>'.
'<input type="text" size="6" id="weight_'.$item->id.'" name="weight_'.$item->id.'"
value="'.grade_edit_tree::format_number($item->aggregationcoef).'" />';
- } elseif (($aggcoef == 'aggregationcoefextrasum' || $aggcoef == 'aggregationcoefextraweightsum') && $type == 'extra') {
- $checked = ($item->aggregationcoef > 0) ? 'checked="checked"' : '';
- return '<input type="hidden" name="extracredit_'.$item->id.'" value="0" />
- <label class="accesshide" for="extracredit_'.$item->id.'">'.
- get_string('extracreditvalue', 'grades', $item->itemname).'</label>
- <input type="checkbox" id="extracredit_'.$item->id.'" name="extracredit_'.$item->id.'" value="1" '."$checked />\n";
- } else if ($aggcoef == 'aggregationcoefextraweightsum' && $type == 'weight') {
+ } else if ($aggcoef == 'aggregationcoefextraweightsum') {
$label = '';
if ($item->weightoverride && $parent_category->aggregation == GRADE_AGGREGATE_SUM) {
- $label = get_string('adjusted', 'grades');
+ $label = ' '.get_string('adjusted', 'grades');
}
$name = 'weight_' . $item->id;
)
);
- return $hiddenlabel . $input . $label;
- } else {
- return '';
+ $str .= $hiddenlabel . $input . $label;
+
+ if ($item->aggregationcoef > 0) {
+ $str .= ' ' . html_writer::tag('abbr', get_string('aggregationcoefextrasumabbr', 'grades'),
+ array('title' => get_string('aggregationcoefextrasum', 'grades')));
+ }
}
+
+ return $str;
}
//Trims trailing zeros
$level++;
$coefstring = $element['object']->get_coefstring();
if ($element['type'] == 'category') {
- if ($coefstring == 'aggregationcoefweight' || $coefstring == 'aggregationcoefextraweightsum') {
- $this->uses_weight = true;
+ if ($element['object']->aggregation != GRADE_AGGREGATE_SUM) {
+ $this->uses_non_natural = true;
}
- if ($coefstring == 'aggregationcoefextraweight' || $coefstring == 'aggregationcoefextraweightsum' || $coefstring == 'aggregationcoefextrasum') {
- $this->uses_extra_credit = true;
+
+ if ($coefstring == 'aggregationcoefweight' || $coefstring == 'aggregationcoefextraweightsum' ||
+ $coefstring == 'aggregationcoefextraweight') {
+ $this->uses_weight = true;
}
foreach($element['children'] as $child_el) {
}
$options = grade_helper::get_aggregation_strings();
-
- $visible = explode(',', $CFG->grade_aggregations_visible);
- foreach ($options as $constant => $string) {
- if (!in_array($constant, $visible) && $constant != $category->aggregation) {
- unset($options[$constant]);
- }
- }
-
- if ($this->forced) {
- $aggregation = $options[$category->aggregation];
- } else {
- $attributes = array();
- $attributes['id'] = 'aggregation_'.$category->id;
- $attributes['class'] = 'ignoredirty';
- $aggregation = html_writer::label(get_string('aggregation', 'grades'), 'aggregation_'.$category->id, false, array('class' => 'accesshide'));
- $aggregation .= html_writer::select($options, 'aggregation_'.$category->id, $category->aggregation, null, $attributes);
- $action = new component_action('change', 'update_category_aggregation', array('courseid' => $params['id'], 'category' => $category->id, 'sesskey' => sesskey()));
- $OUTPUT->add_action_handler($action, 'aggregation_'.$category->id);
- }
+ $aggregation = $options[$category->aggregation];
$categorycell = clone($this->categorycell);
$categorycell->attributes['class'] .= ' ' . $levelclass;
}
}
-class grade_edit_tree_column_extracredit extends grade_edit_tree_column {
-
- public function get_header_cell() {
- global $OUTPUT;
- $headercell = clone($this->headercell);
- $headercell->text = get_string('aggregationcoefextra', 'grades').$OUTPUT->help_icon('aggregationcoefextra', 'grades');
- return $headercell;
- }
-
- public function get_category_cell($category, $levelclass, $params) {
- $item = $category->get_grade_item();
- $categorycell = clone($this->categorycell);
- $categorycell->attributes['class'] .= ' ' . $levelclass;
- $categorycell->text = grade_edit_tree::get_weight_input($item, 'extra');
- return $categorycell;
- }
-
- public function get_item_cell($item, $params) {
- if (empty($params['element'])) {
- throw new Exception('Array key (element) missing from 2nd param of grade_edit_tree_column_weightorextracredit::get_item_cell($item, $params)');
- }
-
- $itemcell = clone($this->itemcell);
- $itemcell->text = ' ';
-
- if (!in_array($params['element']['object']->itemtype, array('courseitem', 'categoryitem', 'category'))) {
- $itemcell->text = grade_edit_tree::get_weight_input($item, 'extra');
- }
-
- return $itemcell;
- }
-
- public function is_hidden($mode='simple') {
- global $CFG;
- if ($mode == 'simple') {
- return strstr($CFG->grade_item_advanced, 'aggregationcoef');
- } elseif ($mode == 'advanced') {
- return false;
- }
- }
-}
-
class grade_edit_tree_column_weight extends grade_edit_tree_column {
public function get_header_cell() {
$item = $category->get_grade_item();
$categorycell = clone($this->categorycell);
$categorycell->attributes['class'] .= ' ' . $levelclass;
- $categorycell->text = grade_edit_tree::get_weight_input($item, 'weight');
+ $categorycell->text = grade_edit_tree::get_weight_input($item);
return $categorycell;
}
$itemcell->text = ' ';
if (!in_array($params['element']['object']->itemtype, array('courseitem', 'categoryitem', 'category'))) {
- $itemcell->text = grade_edit_tree::get_weight_input($item, 'weight');
+ $itemcell->text = grade_edit_tree::get_weight_input($item);
}
return $itemcell;
$grademax = ' - ';
} else if ($parent_cat->aggregation == GRADE_AGGREGATE_SUM) {
$grademax = format_float($item->grademax, $item->get_decimals());
- } elseif ($item->gradetype == GRADE_TYPE_SCALE) {
+ } else if ($item->gradetype == GRADE_TYPE_SCALE) {
$scale = $DB->get_record('scale', array('id' => $item->scaleid));
$scale_items = null;
if (empty($scale)) { //if the item is using a scale that's been removed
$scale_items = explode(',', $scale->scale);
}
$grademax = end($scale_items) . ' (' . count($scale_items) . ')';
- } elseif ($item->is_external_item()) {
- $grademax = format_float($item->grademax, $item->get_decimals());
} else {
- $grademax = '<label class="accesshide" for="grademax'.$item->id.'">'.get_string('grademax', 'grades').'</label>
- <input type="text" size="6" id="grademax'.$item->id.'" name="grademax_'.$item->id.'" value="'.
- format_float($item->grademax, $item->get_decimals()).'" />';
+ $grademax = format_float($item->grademax, $item->get_decimals());
}
$itemcell = clone($this->itemcell);