class feedback_item_numeric extends feedback_item_base {
var $type = "numeric";
- function init() {
+ var $sep_dec, $sep_thous;
+ function init() {
+ $this->sep_dec = get_string('separator_decimal', 'feedback');
+ if(substr($this->sep_dec, 0, 2) == '[['){
+ $this->sep_dec = FEEDBACK_DECIMAL;
+ }
+
+ $this->sep_thous = get_string('separator_thousand', 'feedback');
+ if(substr($this->sep_thous, 0, 2) == '[['){
+ $this->sep_thous = FEEDBACK_THOUSAND;
+ }
}
function show_edit($item) {
$item_form->itemname->setValue($item->name);
$range_from_to = explode('|',$item->presentation);
- $range_from = isset($range_from_to[0]) ? intval($range_from_to[0]) : 0;
- $range_to = isset($range_from_to[1]) ? intval($range_from_to[1]) : 0;
+ $range_from = (isset($range_from_to[0]) AND is_numeric($range_from_to[0])) ? str_replace(FEEDBACK_DECIMAL, $this->sep_dec, floatval($range_from_to[0])) : '-';
+ $range_to = (isset($range_from_to[1]) AND is_numeric($range_from_to[1])) ? str_replace(FEEDBACK_DECIMAL, $this->sep_dec, floatval($range_from_to[1])) : '-';
+
$item_form->selectfrom->setValue($range_from);
$item_form->selectto->setValue($range_to);
}
function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
- $sep_dec = get_string('separator_decimal', 'feedback');
- if(substr($sep_dec, 0, 2) == '[['){
- $sep_dec = FEEDBACK_DECIMAL;
- }
-
- $sep_thous = get_string('separator_thousand', 'feedback');
- if(substr($sep_thous, 0, 2) == '[['){
- $sep_thous = FEEDBACK_THOUSAND;
- }
// $values = feedback_get_group_values($item, $groupid, $courseid);
$values = $this->get_analysed($item, $groupid, $courseid);
// $itemnr++;
echo '<tr><th colspan="2" align="left">'. $itemnr . ' ' . $item->name .'</th></tr>';
foreach($values->data as $value) {
- echo '<tr><td colspan="2" valign="top" align="left">- ' . $value . '</td></tr>';
+ echo '<tr><td colspan="2" valign="top" align="left">- ' . number_format($value, 2, $this->sep_dec, $this->sep_thous) . '</td></tr>';
}
//echo '</table>';
if(isset($values->avg)) {
- $avg = number_format($values->avg, 2, $sep_dec, $sep_thous);
+ $avg = number_format($values->avg, 2, $this->sep_dec, $this->sep_thous);
} else {
- $avg = number_format(0, 2, $sep_dec, $sep_thous);
+ $avg = number_format(0, 2, $this->sep_dec, $this->sep_thous);
}
echo '<tr><td align="left" colspan="2"><b>'.get_string('average', 'feedback').': '.$avg.'</b></td></tr>';
}
//get the range
$range_from_to = explode('|',$item->presentation);
//get the min-value
- $range_from = isset($range_from_to[0]) ? intval($range_from_to[0]) : 0;
+ $range_from = (isset($range_from_to[0]) AND is_numeric($range_from_to[0])) ? floatval($range_from_to[0]) : 0;
//get the max-value
- $range_to = isset($range_from_to[1]) ? intval($range_from_to[1]) : 0;
+ $range_to = (isset($range_from_to[1]) AND is_numeric($range_from_to[1])) ? floatval($range_from_to[1]) : 0;
if($highlightrequire AND (!$this->check_value($value, $item))) {
$highlight = 'bgcolor="#FFAAAA" class="missingrequire"';
}else {
<?php
echo format_text($item->name . $requiredmark, true, false, false);
switch(true) {
- case ($range_from === 0 AND $range_to > 0):
- echo ' ('.get_string('maximal', 'feedback').': '.$range_to.')';
+ case ($range_from === '-' AND is_numeric($range_to)):
+ echo ' ('.get_string('maximal', 'feedback').': '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_to).')';
break;
- case ($range_from > 0 AND $range_to === 0):
- echo ' ('.get_string('minimal', 'feedback').': '.$range_from.')';
+ case (is_numeric($range_from) AND $range_to === '-'):
+ echo ' ('.get_string('minimal', 'feedback').': '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_from).')';
break;
- case ($range_from === 0 AND $range_to === 0):
+ case ($range_from === '-' AND $range_to === '-'):
break;
default:
- echo ' ('.$range_from.'-'.$range_to.')';
+ echo ' ('.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_from).' - '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_to).')';
break;
}
?>
if($readonly){
// print_simple_box_start($align);
print_box_start('generalbox boxalign'.$align);
- echo $value ? $value : ' ';
+ echo (is_numeric($value)) ? number_format($value, 2, $this->sep_dec, $this->sep_thous) : ' ';
// print_simple_box_end();
print_box_end();
}else {
}
function check_value($value, $item) {
+ $value = str_replace($this->sep_dec, FEEDBACK_DECIMAL, $value);
//if the item is not required, so the check is true if no value is given
if((!isset($value) OR $value == '') AND $item->required != 1) return true;
if(!is_numeric($value))return false;
$range_from_to = explode('|',$item->presentation);
- $range_from = isset($range_from_to[0]) ? intval($range_from_to[0]) : 0;
- $range_to = isset($range_from_to[1]) ? intval($range_from_to[1]) : 0;
+ $range_from = (isset($range_from_to[0]) AND is_numeric($range_from_to[0])) ? floatval($range_from_to[0]) : '-';
+ $range_to = (isset($range_from_to[1]) AND is_numeric($range_from_to[1])) ? floatval($range_from_to[1]) : '-';
switch(true) {
- case ($range_from === 0 AND $range_to > 0):
- if(intval($value) <= $range_to) return true;
+ case ($range_from === '-' AND is_numeric($range_to)):
+ if(floatval($value) <= $range_to) return true;
break;
- case ($range_from > 0 AND $range_to === 0):
- if(intval($value) >= $range_from) return true;
+ case (is_numeric($range_from) AND $range_to === '-'):
+ if(floatval($value) >= $range_from) return true;
break;
- case ($range_from === 0 AND $range_to === 0):
+ case ($range_from === '-' AND $range_to === '-'):
return true;
break;
default:
- if(intval($value) >= $range_from AND intval($value) <= $range_to) return true;
+ if(floatval($value) >= $range_from AND floatval($value) <= $range_to) return true;
break;
}
}
function create_value($data) {
- if($data AND $data != '') {
- $data = intval($data);
+ $data = str_replace($this->sep_dec, FEEDBACK_DECIMAL, $data);
+
+ if(is_numeric($data)) {
+ $data = floatval($data);
}else {
$data = '';
}
}
function get_presentation($data) {
- return $data->numericrangefrom . '|'. $data->numericrangeto;
+ $num1 = str_replace($this->sep_dec, FEEDBACK_DECIMAL, $data->numericrangefrom);
+ if(is_numeric($num1)) {
+ $num1 = floatval($num1);
+ }else {
+ $num1 = '-';
+ }
+
+ $num2 = str_replace($this->sep_dec, FEEDBACK_DECIMAL, $data->numericrangeto);
+ if(is_numeric($num2)) {
+ $num2 = floatval($num2);
+ }else {
+ $num2 = '-';
+ }
+
+ if($num1 === '-' OR $num2 === '-') {
+ return $num1 . '|'. $num2;
+ }
+
+ if($num1 > $num2) {
+ return $num2 . '|'. $num1;
+ }else {
+ return $num1 . '|'. $num2;
+ }
}
function get_hasvalue() {