MDL-55308 mod_feedback: Convert analysis chart to the new library
Part of MDL-54987 epic.
This commit is contained in:
committed by
Dan Poltawski
parent
08501958d3
commit
7cd65bcb76
@@ -78,11 +78,9 @@ echo '<div>';
|
||||
if ($check_anonymously) {
|
||||
// Print the items in an analysed form.
|
||||
foreach ($items as $item) {
|
||||
echo "<table class=\"analysis itemtype_{$item->typ}\">";
|
||||
$itemobj = feedback_get_item_class($item->typ);
|
||||
$printnr = ($feedback->autonumbering && $item->itemnr) ? ($item->itemnr . '.') : '';
|
||||
$itemobj->print_analysed($item, $printnr, $mygroupid);
|
||||
echo '</table>';
|
||||
}
|
||||
} else {
|
||||
echo $OUTPUT->heading_with_help(get_string('insufficient_responses_for_this_group', 'feedback'),
|
||||
|
||||
@@ -152,6 +152,7 @@ class feedback_item_info extends feedback_item_base {
|
||||
}
|
||||
|
||||
public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
|
||||
echo "<table class=\"analysis itemtype_{$item->typ}\">";
|
||||
$analysed_item = $this->get_analysed($item, $groupid, $courseid);
|
||||
$data = $analysed_item->data;
|
||||
if (is_array($data)) {
|
||||
@@ -170,6 +171,7 @@ class feedback_item_info extends feedback_item_base {
|
||||
echo '</td></tr>';
|
||||
}
|
||||
}
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
public function excelprint_item(&$worksheet, $row_offset,
|
||||
|
||||
@@ -207,6 +207,7 @@ class feedback_item_multichoice extends feedback_item_base {
|
||||
$analysed_item = $this->get_analysed($item, $groupid, $courseid);
|
||||
if ($analysed_item) {
|
||||
$itemname = $analysed_item[1];
|
||||
echo "<table class=\"analysis itemtype_{$item->typ}\">";
|
||||
echo '<tr><th colspan="2" align="left">';
|
||||
echo $itemnr . ' ';
|
||||
if (strval($item->label) !== '') {
|
||||
@@ -214,32 +215,32 @@ class feedback_item_multichoice extends feedback_item_base {
|
||||
}
|
||||
echo $itemname;
|
||||
echo '</th></tr>';
|
||||
|
||||
echo "</table>";
|
||||
$analysed_vals = $analysed_item[2];
|
||||
$pixnr = 0;
|
||||
$count = 0;
|
||||
$data = [];
|
||||
foreach ($analysed_vals as $val) {
|
||||
$intvalue = $pixnr % 10;
|
||||
$pix = $OUTPUT->pix_url('multichoice/' . $intvalue, 'feedback');
|
||||
$pixspacer = $OUTPUT->pix_url('spacer');
|
||||
$pixnr++;
|
||||
$pixwidth = max(2, intval($val->quotient * FEEDBACK_MAX_PIX_LENGTH));
|
||||
$pixwidthspacer = FEEDBACK_MAX_PIX_LENGTH + 1 - $pixwidth;
|
||||
$quotient = format_float($val->quotient * 100, 2);
|
||||
$str_quotient = '';
|
||||
if ($val->quotient > 0) {
|
||||
$str_quotient = ' ('. $quotient . ' %)';
|
||||
}
|
||||
echo '<tr>';
|
||||
echo '<td class="optionname">' .
|
||||
format_text(trim($val->answertext), FORMAT_HTML, array('noclean' => true, 'para' => false)).':
|
||||
</td>
|
||||
<td class="optioncount" style="width:'.FEEDBACK_MAX_PIX_LENGTH.';">
|
||||
<img class="feedback_bar_image" alt="'.$intvalue.'" src="'.$pix.'" width="'.$pixwidth.'" />'.
|
||||
'<img class="feedback_bar_image" alt="" src="'.$pixspacer.'" width="'.$pixwidthspacer.'" />
|
||||
'.$val->answercount.$str_quotient.'
|
||||
</td>';
|
||||
echo '</tr>';
|
||||
$answertext = format_text(trim($val->answertext), FORMAT_HTML,
|
||||
array('noclean' => true, 'para' => false));
|
||||
|
||||
$data['labels'][$count] = $answertext;
|
||||
$data['series'][$count] = $val->answercount;
|
||||
$data['series_labels'][$count] = $str_quotient;
|
||||
$count++;
|
||||
}
|
||||
$chart = new \core\chart_bar();
|
||||
$chart->set_horizontal(true);
|
||||
$series = new \core\chart_series(format_string(get_string("responses", "feedback")), $data['series']);
|
||||
$series->set_labels($data['series_labels']);
|
||||
$chart->add_series($series);
|
||||
$chart->set_labels($data['labels']);
|
||||
|
||||
echo $OUTPUT->render($chart);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -178,6 +178,7 @@ class feedback_item_multichoicerated extends feedback_item_base {
|
||||
global $OUTPUT;
|
||||
$analysed_item = $this->get_analysed($item, $groupid, $courseid);
|
||||
if ($analysed_item) {
|
||||
echo "<table class=\"analysis itemtype_{$item->typ}\">";
|
||||
echo '<tr><th colspan="2" align="left">';
|
||||
echo $itemnr . ' ';
|
||||
if (strval($item->label) !== '') {
|
||||
@@ -185,34 +186,35 @@ class feedback_item_multichoicerated extends feedback_item_base {
|
||||
}
|
||||
echo $analysed_item[1];
|
||||
echo '</th></tr>';
|
||||
echo '</table>';
|
||||
$analysed_vals = $analysed_item[2];
|
||||
$pixnr = 0;
|
||||
$avg = 0.0;
|
||||
$count = 0;
|
||||
$data = [];
|
||||
foreach ($analysed_vals as $val) {
|
||||
$intvalue = $pixnr % 10;
|
||||
$pix = $OUTPUT->pix_url('multichoice/' . $intvalue, 'feedback');
|
||||
$pixspacer = $OUTPUT->pix_url('spacer');
|
||||
$pixnr++;
|
||||
$pixwidth = intval($val->quotient * FEEDBACK_MAX_PIX_LENGTH);
|
||||
$pixwidthspacer = FEEDBACK_MAX_PIX_LENGTH + 1 - $pixwidth;
|
||||
|
||||
$avg += $val->avg;
|
||||
$quotient = format_float($val->quotient * 100, 2);
|
||||
echo '<tr>';
|
||||
echo '<td class="optionname">';
|
||||
echo '<span class="weight">('.$val->value.') </span>'.
|
||||
format_text(trim($val->answertext), FORMAT_HTML, array('noclean' => true, 'para' => false)).':</td>';
|
||||
echo '<td class="optionvalue" style="width: '.FEEDBACK_MAX_PIX_LENGTH.'">';
|
||||
echo '<img class="feedback_bar_image" alt="'.$intvalue.'" src="'.$pix.'" width="'.$pixwidth.'" />';
|
||||
echo '<img class="feedback_bar_image" alt="" src="'.$pixspacer.'" width="'.$pixwidthspacer.'" /> ';
|
||||
echo $val->answercount;
|
||||
$answertext = format_text(trim($val->answertext), FORMAT_HTML,
|
||||
array('noclean' => true, 'para' => false));
|
||||
if ($val->quotient > 0) {
|
||||
echo ' ('.$quotient.' %)';
|
||||
$str_quotient = ' ('.$quotient.' %)';
|
||||
} else {
|
||||
echo '';
|
||||
$str_quotient = '';
|
||||
}
|
||||
echo '</td></tr>';
|
||||
|
||||
$data['labels'][$count] = $answertext;
|
||||
$data['series'][$count] = $val->answercount;
|
||||
$data['series_labels'][$count] = $str_quotient;
|
||||
$count++;
|
||||
}
|
||||
$chart = new \core\chart_bar();
|
||||
$chart->set_horizontal(true);
|
||||
$series = new \core\chart_series(format_string(get_string("responses", "feedback")), $data['series']);
|
||||
$series->set_labels($data['series_labels']);
|
||||
$chart->add_series($series);
|
||||
$chart->set_labels($data['labels']);
|
||||
echo $OUTPUT->render($chart);
|
||||
|
||||
$avg = format_float($avg, 2);
|
||||
echo '<tr><td align="left" colspan="2"><b>';
|
||||
echo get_string('average', 'feedback').': '.$avg.'</b>';
|
||||
|
||||
@@ -142,6 +142,7 @@ class feedback_item_numeric extends feedback_item_base {
|
||||
$values = $this->get_analysed($item, $groupid, $courseid);
|
||||
|
||||
if (isset($values->data) AND is_array($values->data)) {
|
||||
echo "<table class=\"analysis itemtype_{$item->typ}\">";
|
||||
echo '<tr><th colspan="2" align="left">';
|
||||
echo $itemnr . ' ';
|
||||
if (strval($item->label) !== '') {
|
||||
@@ -164,6 +165,7 @@ class feedback_item_numeric extends feedback_item_base {
|
||||
echo '<tr><td colspan="2"><b>';
|
||||
echo get_string('average', 'feedback').': '.$avg;
|
||||
echo '</b></td></tr>';
|
||||
echo '</table>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -133,6 +133,7 @@ class feedback_item_textarea extends feedback_item_base {
|
||||
public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
|
||||
$values = feedback_get_group_values($item, $groupid, $courseid);
|
||||
if ($values) {
|
||||
echo "<table class=\"analysis itemtype_{$item->typ}\">";
|
||||
echo '<tr><th colspan="2" align="left">';
|
||||
echo $itemnr . ' ';
|
||||
if (strval($item->label) !== '') {
|
||||
@@ -148,6 +149,7 @@ class feedback_item_textarea extends feedback_item_base {
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
echo '</table>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -129,6 +129,7 @@ class feedback_item_textfield extends feedback_item_base {
|
||||
public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
|
||||
$values = feedback_get_group_values($item, $groupid, $courseid);
|
||||
if ($values) {
|
||||
echo "<table class=\"analysis itemtype_{$item->typ}\">";
|
||||
echo '<tr><th colspan="2" align="left">';
|
||||
echo $itemnr . ' ';
|
||||
if (strval($item->label) !== '') {
|
||||
@@ -142,6 +143,7 @@ class feedback_item_textfield extends feedback_item_base {
|
||||
echo str_replace("\n", '<br />', $value->value);
|
||||
echo '</td></tr>';
|
||||
}
|
||||
echo '</table>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user