public function test_format_number()
 {
     $numinput = array(0, 1, 1.01, '1.010', 1.2345);
     $numoutput = array(0.0, 1.0, 1.01, 1.01, 1.2345);
     for ($i = 0; $i < count($numinput); $i++) {
         $msg = 'format_number() testing ' . $numinput[$i] . ' %s';
         $this->assertEquals(grade_edit_tree::format_number($numinput[$i]), $numoutput[$i], $msg);
     }
 }
Exemple #2
0
 public function get_item_cell($item, $params)
 {
     global $OUTPUT;
     $itemcell = clone $this->itemcell;
     if (!$item->is_raw_used()) {
         $itemcell->text = '&nbsp;';
         return $itemcell;
     }
     $plusfactor = '<label class="accesshide" for="plusfactor_' . $item->id . '">' . get_string('plusfactorvalue', 'grades', $item->itemname) . '</label>
             <input type="text" size="4" id="plusfactor_' . $item->id . '" name="plusfactor_' . $item->id . '" value="' . grade_edit_tree::format_number($item->plusfactor) . '" />';
     $itemcell->text = $plusfactor;
     return $itemcell;
 }
Exemple #3
0
 /**
  * Given a grade_item object, returns a labelled input if an aggregation coefficient (weight or extra credit) applies to it.
  * @param grade_item $item
  * @return string HTML
  */
 static function get_weight_input($item)
 {
     global $OUTPUT;
     if (!is_object($item) || get_class($item) !== 'grade_item') {
         throw new Exception('grade_edit_tree::get_weight_input($item) was given a variable that is not of the required type (grade_item object)');
         return false;
     }
     if ($item->is_course_item()) {
         return '';
     }
     $parent_category = $item->get_parent_category();
     $parent_category->apply_forced_settings();
     $aggcoef = $item->get_coefstring();
     $itemname = $item->itemname;
     if ($item->is_category_item()) {
         // Remember, the parent category of a category item is the category itself.
         $itemname = $parent_category->get_name();
     }
     $str = '';
     if ($aggcoef == 'aggregationcoefweight' || $aggcoef == 'aggregationcoef' || $aggcoef == 'aggregationcoefextraweight') {
         return '<label class="accesshide" for="weight_' . $item->id . '">' . get_string('extracreditvalue', 'grades', $itemname) . '</label>' . '<input type="text" size="6" id="weight_' . $item->id . '" name="weight_' . $item->id . '"
             value="' . grade_edit_tree::format_number($item->aggregationcoef) . '" />';
     } else {
         if ($aggcoef == 'aggregationcoefextraweightsum') {
             $checkboxname = 'weightoverride_' . $item->id;
             $checkboxlbl = html_writer::tag('label', get_string('overrideweightofa', 'grades', $itemname), array('for' => $checkboxname, 'class' => 'accesshide'));
             $checkbox = html_writer::empty_tag('input', array('name' => $checkboxname, 'type' => 'hidden', 'value' => 0));
             $checkbox .= html_writer::empty_tag('input', array('name' => $checkboxname, 'type' => 'checkbox', 'value' => 1, 'id' => $checkboxname, 'class' => 'weightoverride', 'checked' => $item->weightoverride ? 'checked' : null));
             $name = 'weight_' . $item->id;
             $hiddenlabel = html_writer::tag('label', get_string('weightofa', 'grades', $itemname), array('class' => 'accesshide', 'for' => $name));
             $input = html_writer::empty_tag('input', array('type' => 'text', 'size' => 6, 'id' => $name, 'name' => $name, 'value' => grade_edit_tree::format_number($item->aggregationcoef2 * 100.0), 'disabled' => $item->weightoverride ? null : 'disabled'));
             $str .= $checkboxlbl . $checkbox . $hiddenlabel . $input;
             if ($item->aggregationcoef > 0) {
                 $str .= ' ' . html_writer::tag('abbr', get_string('aggregationcoefextrasumabbr', 'grades'), array('title' => get_string('aggregationcoefextrasum', 'grades')));
             }
         }
     }
     return $str;
 }
Exemple #4
0
 public function get_item_cell($item, $params)
 {
     global $OUTPUT;
     $itemcell = clone $this->itemcell;
     if (!$item->is_raw_used()) {
         $itemcell->text = '&nbsp;';
         return $itemcell;
     }
     $plusfactor = '<input type="text" size="4" id="plusfactor_' . $item->id . '" name="plusfactor_' . $item->id . '" value="' . grade_edit_tree::format_number($item->plusfactor) . '" />';
     $itemcell->text = $plusfactor;
     return $itemcell;
 }