Skip to content

Commit

Permalink
MDL-55308 mod_feedback: Convert analysis chart to the new library
Browse files Browse the repository at this point in the history
Part of MDL-54987 epic.
  • Loading branch information
lameze authored and danpoltawski committed Jul 25, 2016
1 parent 0850195 commit 7cd65bc
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 39 deletions.
2 changes: 0 additions & 2 deletions mod/feedback/analysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,9 @@
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'),
Expand Down
2 changes: 2 additions & 0 deletions mod/feedback/item/info/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public function get_printval($item, $value) {
}

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)) {
Expand All @@ -170,6 +171,7 @@ public function print_analysed($item, $itemnr = '', $groupid = false, $courseid
echo '</td></tr>';
}
}
echo '</table>';
}

public function excelprint_item(&$worksheet, $row_offset,
Expand Down
37 changes: 19 additions & 18 deletions mod/feedback/item/multichoice/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,39 +207,40 @@ public function print_analysed($item, $itemnr = '', $groupid = false, $courseid
$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) !== '') {
echo '('. format_string($item->label).') ';
}
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);
}
}

Expand Down
40 changes: 21 additions & 19 deletions mod/feedback/item/multichoicerated/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,41 +178,43 @@ public function print_analysed($item, $itemnr = '', $groupid = false, $courseid
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) !== '') {
echo '('. format_string($item->label).') ';
}
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>';
Expand Down
2 changes: 2 additions & 0 deletions mod/feedback/item/numeric/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public function print_analysed($item, $itemnr = '', $groupid = false, $courseid
$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) !== '') {
Expand All @@ -164,6 +165,7 @@ public function print_analysed($item, $itemnr = '', $groupid = false, $courseid
echo '<tr><td colspan="2"><b>';
echo get_string('average', 'feedback').': '.$avg;
echo '</b></td></tr>';
echo '</table>';
}
}

Expand Down
2 changes: 2 additions & 0 deletions mod/feedback/item/textarea/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public function get_printval($item, $value) {
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) !== '') {
Expand All @@ -148,6 +149,7 @@ public function print_analysed($item, $itemnr = '', $groupid = false, $courseid
echo '</td>';
echo '</tr>';
}
echo '</table>';
}
}

Expand Down
2 changes: 2 additions & 0 deletions mod/feedback/item/textfield/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public function get_printval($item, $value) {
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) !== '') {
Expand All @@ -142,6 +143,7 @@ public function print_analysed($item, $itemnr = '', $groupid = false, $courseid
echo str_replace("\n", '<br />', $value->value);
echo '</td></tr>';
}
echo '</table>';
}
}

Expand Down

0 comments on commit 7cd65bc

Please sign in to comment.