Merge branch 'wip-MDL-53557-master' of https://github.com/marinaglancy/moodle
This commit is contained in:
@@ -142,7 +142,7 @@ class feedback_item_info extends feedback_item_base {
|
||||
if (!isset($value->value)) {
|
||||
return '';
|
||||
}
|
||||
return userdate($value->value);
|
||||
return $item->presentation == 1 ? userdate($value->value) : $value->value;
|
||||
}
|
||||
|
||||
public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
|
||||
|
||||
@@ -19,21 +19,12 @@ require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
|
||||
|
||||
class feedback_item_numeric extends feedback_item_base {
|
||||
protected $type = "numeric";
|
||||
public $sep_dec, $sep_thous;
|
||||
private $commonparams;
|
||||
private $item_form;
|
||||
private $item;
|
||||
|
||||
public 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;
|
||||
}
|
||||
}
|
||||
|
||||
public function build_editform($item, $feedback, $cm) {
|
||||
@@ -58,17 +49,13 @@ class feedback_item_numeric extends feedback_item_base {
|
||||
|
||||
$range_from_to = explode('|', $item->presentation);
|
||||
if (isset($range_from_to[0]) AND is_numeric($range_from_to[0])) {
|
||||
$range_from = str_replace(FEEDBACK_DECIMAL,
|
||||
$this->sep_dec,
|
||||
floatval($range_from_to[0]));
|
||||
$range_from = $this->format_float($range_from_to[0]);
|
||||
} else {
|
||||
$range_from = '-';
|
||||
}
|
||||
|
||||
if (isset($range_from_to[1]) AND is_numeric($range_from_to[1])) {
|
||||
$range_to = str_replace(FEEDBACK_DECIMAL,
|
||||
$this->sep_dec,
|
||||
floatval($range_from_to[1]));
|
||||
$range_to = $this->format_float($range_from_to[1]);
|
||||
} else {
|
||||
$range_to = '-';
|
||||
}
|
||||
@@ -152,7 +139,7 @@ class feedback_item_numeric extends feedback_item_base {
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
$avg = $counter > 0 ? $avg / $counter : 0;
|
||||
$avg = $counter > 0 ? $avg / $counter : null;
|
||||
$analysed->data = $data;
|
||||
$analysed->avg = $avg;
|
||||
}
|
||||
@@ -182,14 +169,14 @@ class feedback_item_numeric extends feedback_item_base {
|
||||
|
||||
foreach ($values->data as $value) {
|
||||
echo '<tr><td colspan="2" valign="top" align="left">';
|
||||
echo '- '.number_format($value, 2, $this->sep_dec, $this->sep_thous);
|
||||
echo '- '.$this->format_float($value);
|
||||
echo '</td></tr>';
|
||||
}
|
||||
|
||||
if (isset($values->avg)) {
|
||||
$avg = number_format($values->avg, 2, $this->sep_dec, $this->sep_thous);
|
||||
$avg = format_float($values->avg, 2);
|
||||
} else {
|
||||
$avg = number_format(0, 2, $this->sep_dec, $this->sep_thous);
|
||||
$avg = '-';
|
||||
}
|
||||
echo '<tr><td align="left" colspan="2"><b>';
|
||||
echo get_string('average', 'feedback').': '.$avg;
|
||||
@@ -208,16 +195,23 @@ class feedback_item_numeric extends feedback_item_base {
|
||||
$data = $analysed_item->data;
|
||||
if (is_array($data)) {
|
||||
|
||||
//mittelwert anzeigen
|
||||
// Export average.
|
||||
$worksheet->write_string($row_offset,
|
||||
2,
|
||||
get_string('average', 'feedback'),
|
||||
$xls_formats->value_bold);
|
||||
|
||||
$worksheet->write_number($row_offset + 1,
|
||||
2,
|
||||
$analysed_item->avg,
|
||||
$xls_formats->value_bold);
|
||||
if (isset($analysed_item->avg)) {
|
||||
$worksheet->write_number($row_offset + 1,
|
||||
2,
|
||||
$analysed_item->avg,
|
||||
$xls_formats->value_bold);
|
||||
} else {
|
||||
$worksheet->write_string($row_offset + 1,
|
||||
2,
|
||||
'',
|
||||
$xls_formats->value_bold);
|
||||
}
|
||||
$row_offset++;
|
||||
}
|
||||
$row_offset++;
|
||||
@@ -245,14 +239,14 @@ class feedback_item_numeric extends feedback_item_base {
|
||||
if (isset($range_from_to[0]) AND is_numeric($range_from_to[0])) {
|
||||
$range_from = floatval($range_from_to[0]);
|
||||
} else {
|
||||
$range_from = 0;
|
||||
$range_from = '-';
|
||||
}
|
||||
|
||||
//get the max-value
|
||||
if (isset($range_from_to[1]) AND is_numeric($range_from_to[1])) {
|
||||
$range_to = floatval($range_from_to[1]);
|
||||
} else {
|
||||
$range_to = 0;
|
||||
$range_to = '-';
|
||||
}
|
||||
|
||||
$requiredmark = ($item->required == 1) ? $strrequiredmark : '';
|
||||
@@ -276,17 +270,17 @@ class feedback_item_numeric extends feedback_item_base {
|
||||
switch(true) {
|
||||
case ($range_from === '-' AND is_numeric($range_to)):
|
||||
echo ' ('.get_string('maximal', 'feedback').
|
||||
': '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_to).')';
|
||||
': '.$this->format_float($range_to).')';
|
||||
break;
|
||||
case (is_numeric($range_from) AND $range_to === '-'):
|
||||
echo ' ('.get_string('minimal', 'feedback').
|
||||
': '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_from).')';
|
||||
': '.$this->format_float($range_from).')';
|
||||
break;
|
||||
case ($range_from === '-' AND $range_to === '-'):
|
||||
break;
|
||||
default:
|
||||
echo ' ('.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_from).
|
||||
' - '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_to).')';
|
||||
echo ' ('.$this->format_float($range_from).
|
||||
' - '.$this->format_float($range_to).')';
|
||||
break;
|
||||
}
|
||||
echo '</span>';
|
||||
@@ -307,6 +301,22 @@ class feedback_item_numeric extends feedback_item_base {
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the float nicely in the localized format
|
||||
*
|
||||
* Similar to format_float() but automatically calculates the number of decimal places
|
||||
*
|
||||
* @param float $value The float to print
|
||||
* @return string
|
||||
*/
|
||||
protected function format_float($value) {
|
||||
if (!is_numeric($value)) {
|
||||
return null;
|
||||
}
|
||||
$decimal = is_int($value) ? 0 : strcspn(strrev($value), '.');
|
||||
return format_float($value, $decimal);
|
||||
}
|
||||
|
||||
/**
|
||||
* print the item at the complete-page of feedback
|
||||
*
|
||||
@@ -329,14 +339,14 @@ class feedback_item_numeric extends feedback_item_base {
|
||||
if (isset($range_from_to[0]) AND is_numeric($range_from_to[0])) {
|
||||
$range_from = floatval($range_from_to[0]);
|
||||
} else {
|
||||
$range_from = 0;
|
||||
$range_from = '-';
|
||||
}
|
||||
|
||||
//get the max-value
|
||||
if (isset($range_from_to[1]) AND is_numeric($range_from_to[1])) {
|
||||
$range_to = floatval($range_from_to[1]);
|
||||
} else {
|
||||
$range_to = 0;
|
||||
$range_to = '-';
|
||||
}
|
||||
|
||||
$requiredmark = ($item->required == 1) ? $strrequiredmark : '';
|
||||
@@ -350,17 +360,17 @@ class feedback_item_numeric extends feedback_item_base {
|
||||
switch(true) {
|
||||
case ($range_from === '-' AND is_numeric($range_to)):
|
||||
echo ' ('.get_string('maximal', 'feedback').
|
||||
': '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_to).')';
|
||||
': '.$this->format_float($range_to).')';
|
||||
break;
|
||||
case (is_numeric($range_from) AND $range_to === '-'):
|
||||
echo ' ('.get_string('minimal', 'feedback').
|
||||
': '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_from).')';
|
||||
': '.$this->format_float($range_from).')';
|
||||
break;
|
||||
case ($range_from === '-' AND $range_to === '-'):
|
||||
break;
|
||||
default:
|
||||
echo ' ('.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_from).
|
||||
' - '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_to).')';
|
||||
echo ' ('.$this->format_float($range_from).
|
||||
' - '.$this->format_float($range_to).')';
|
||||
break;
|
||||
}
|
||||
echo '</span>';
|
||||
@@ -405,13 +415,13 @@ class feedback_item_numeric extends feedback_item_base {
|
||||
if (isset($range_from_to[0]) AND is_numeric($range_from_to[0])) {
|
||||
$range_from = floatval($range_from_to[0]);
|
||||
} else {
|
||||
$range_from = 0;
|
||||
$range_from = '-';
|
||||
}
|
||||
//get the max-value
|
||||
if (isset($range_from_to[1]) AND is_numeric($range_from_to[1])) {
|
||||
$range_to = floatval($range_from_to[1]);
|
||||
} else {
|
||||
$range_to = 0;
|
||||
$range_to = '-';
|
||||
}
|
||||
$requiredmark = ($item->required == 1) ? $strrequiredmark : '';
|
||||
|
||||
@@ -424,17 +434,17 @@ class feedback_item_numeric extends feedback_item_base {
|
||||
switch(true) {
|
||||
case ($range_from === '-' AND is_numeric($range_to)):
|
||||
echo ' ('.get_string('maximal', 'feedback').
|
||||
': '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_to).')';
|
||||
': '.$this->format_float($range_to).')';
|
||||
break;
|
||||
case (is_numeric($range_from) AND $range_to === '-'):
|
||||
echo ' ('.get_string('minimal', 'feedback').
|
||||
': '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_from).')';
|
||||
': '.$this->format_float($range_from).')';
|
||||
break;
|
||||
case ($range_from === '-' AND $range_to === '-'):
|
||||
break;
|
||||
default:
|
||||
echo ' ('.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_from).
|
||||
' - '.str_replace(FEEDBACK_DECIMAL, $this->sep_dec, $range_to).')';
|
||||
echo ' ('.$this->format_float($range_from).
|
||||
' - '.$this->format_float($range_to).')';
|
||||
break;
|
||||
}
|
||||
echo '</div>';
|
||||
@@ -443,7 +453,7 @@ class feedback_item_numeric extends feedback_item_base {
|
||||
echo '<div class="feedback_item_presentation_'.$align.'">';
|
||||
echo $OUTPUT->box_start('generalbox boxalign'.$align);
|
||||
if (is_numeric($value)) {
|
||||
$str_num_value = number_format($value, 2, $this->sep_dec, $this->sep_thous);
|
||||
$str_num_value = $this->format_float($value);
|
||||
} else {
|
||||
$str_num_value = ' ';
|
||||
}
|
||||
@@ -453,7 +463,7 @@ class feedback_item_numeric extends feedback_item_base {
|
||||
}
|
||||
|
||||
public function check_value($value, $item) {
|
||||
$value = str_replace($this->sep_dec, FEEDBACK_DECIMAL, $value);
|
||||
$value = unformat_float($value, true);
|
||||
//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;
|
||||
@@ -499,7 +509,7 @@ class feedback_item_numeric extends feedback_item_base {
|
||||
}
|
||||
|
||||
public function create_value($data) {
|
||||
$data = str_replace($this->sep_dec, FEEDBACK_DECIMAL, $data);
|
||||
$data = unformat_float($data, true);
|
||||
|
||||
if (is_numeric($data)) {
|
||||
$data = floatval($data);
|
||||
@@ -520,14 +530,14 @@ class feedback_item_numeric extends feedback_item_base {
|
||||
}
|
||||
|
||||
public function get_presentation($data) {
|
||||
$num1 = str_replace($this->sep_dec, FEEDBACK_DECIMAL, $data->numericrangefrom);
|
||||
$num1 = unformat_float($data->numericrangefrom, true);
|
||||
if (is_numeric($num1)) {
|
||||
$num1 = floatval($num1);
|
||||
} else {
|
||||
$num1 = '-';
|
||||
}
|
||||
|
||||
$num2 = str_replace($this->sep_dec, FEEDBACK_DECIMAL, $data->numericrangeto);
|
||||
$num2 = unformat_float($data->numericrangeto, true);
|
||||
if (is_numeric($num2)) {
|
||||
$num2 = floatval($num2);
|
||||
} else {
|
||||
@@ -554,11 +564,11 @@ class feedback_item_numeric extends feedback_item_base {
|
||||
}
|
||||
|
||||
public function value_type() {
|
||||
return PARAM_FLOAT;
|
||||
return PARAM_TEXT;
|
||||
}
|
||||
|
||||
public function clean_input_value($value) {
|
||||
$value = str_replace($this->sep_dec, FEEDBACK_DECIMAL, $value);
|
||||
$value = unformat_float($value, true);
|
||||
if (!is_numeric($value)) {
|
||||
if ($value == '') {
|
||||
return null; //an empty string should be null
|
||||
@@ -566,6 +576,6 @@ class feedback_item_numeric extends feedback_item_base {
|
||||
return clean_param($value, PARAM_TEXT); //we have to know the value if it is wrong
|
||||
}
|
||||
}
|
||||
return clean_param($value, $this->value_type());
|
||||
return clean_param($value, PARAM_FLOAT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,13 +44,13 @@ class feedback_numeric_form extends feedback_item_form {
|
||||
'rangefrom',
|
||||
get_string('numeric_range_from', 'feedback'),
|
||||
array('size'=>10, 'maxlength'=>10));
|
||||
$mform->setType('rangefrom', PARAM_INT);
|
||||
$mform->setType('rangefrom', PARAM_RAW);
|
||||
|
||||
$mform->addElement('text',
|
||||
'rangeto',
|
||||
get_string('numeric_range_to', 'feedback'),
|
||||
array('size'=>10, 'maxlength'=>10));
|
||||
$mform->setType('rangeto', PARAM_INT);
|
||||
$mform->setType('rangeto', PARAM_RAW);
|
||||
|
||||
parent::definition();
|
||||
$this->set_data($item);
|
||||
@@ -62,19 +62,13 @@ class feedback_numeric_form extends feedback_item_form {
|
||||
return false;
|
||||
}
|
||||
|
||||
$itemobj = new feedback_item_numeric();
|
||||
|
||||
$num1 = str_replace($itemobj->sep_dec, FEEDBACK_DECIMAL, $item->rangefrom);
|
||||
if (is_numeric($num1)) {
|
||||
$num1 = floatval($num1);
|
||||
} else {
|
||||
$num1 = unformat_float($item->rangefrom, true);
|
||||
if ($num1 === false || $num1 === null) {
|
||||
$num1 = '-';
|
||||
}
|
||||
|
||||
$num2 = str_replace($itemobj->sep_dec, FEEDBACK_DECIMAL, $item->rangeto);
|
||||
if (is_numeric($num2)) {
|
||||
$num2 = floatval($num2);
|
||||
} else {
|
||||
$num2 = unformat_float($item->rangeto, true);
|
||||
if ($num2 === false || $num2 === null) {
|
||||
$num2 = '-';
|
||||
}
|
||||
|
||||
|
||||
@@ -156,7 +156,8 @@ $string['mapcourses_help'] = 'Once you have selected the relevant course(s) from
|
||||
you can associate them with this feedback using map course(s). Multiple courses may be selected by holding down the Apple or Ctrl key whilst clicking on the course names. A course may be disassociated from a feedback at any time.';
|
||||
$string['mappedcourses'] = 'Mapped courses';
|
||||
$string['max_args_exceeded'] = 'Max 6 arguments can be handled, too many arguments for';
|
||||
$string['maximal'] = 'maximal';
|
||||
$string['minimal'] = 'minimum';
|
||||
$string['maximal'] = 'maximum';
|
||||
$string['messageprovider:message'] = 'Feedback reminder';
|
||||
$string['messageprovider:submission'] = 'Feedback notifications';
|
||||
$string['mode'] = 'Mode';
|
||||
|
||||
@@ -62,6 +62,7 @@ Feature: Test creating different types of feedback questions
|
||||
And I add a "Numeric answer" question to the feedback with:
|
||||
| Question | this is a numeric answer |
|
||||
| Label | numeric |
|
||||
| Range from | 0 |
|
||||
| Range to | 100 |
|
||||
And I add a "Short text answer" question to the feedback with:
|
||||
| Question | this is a short text answer |
|
||||
@@ -124,8 +125,8 @@ Feature: Test creating different types of feedback questions
|
||||
And I should see "1 (50.00 %)" in the "option l (1):" "table_row"
|
||||
And I should see "1 (50.00 %)" in the "option m (5):" "table_row"
|
||||
And I should see "Average: 3.00" in the "(multichoice4)" "table"
|
||||
And I should see "35.00" in the "(numeric)" "table"
|
||||
And I should see "71.00" in the "(numeric)" "table"
|
||||
And I should see "35" in the "(numeric)" "table"
|
||||
And I should see "71" in the "(numeric)" "table"
|
||||
And I should see "Average: 53.00" in the "(numeric)" "table"
|
||||
And I should see "no way" in the "(shorttext)" "table"
|
||||
And I should see "hello" in the "(shorttext)" "table"
|
||||
|
||||
Reference in New Issue
Block a user