ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPollAnswerTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 public function __construct(?object $a_parent_obj, string $a_parent_cmd)
29 {
30 global $DIC;
31
32 $this->ctrl = $DIC->ctrl();
33 $this->lng = $DIC->language();
34
35 $this->setId("ilobjpollaw");
36
37 parent::__construct($a_parent_obj, $a_parent_cmd);
38
39 $this->addColumn($this->lng->txt("poll_sortorder"), "pos");
40 $this->addColumn($this->lng->txt("poll_answer"), "answer");
41 $this->addColumn($this->lng->txt("poll_absolute"), "votes");
42 $this->addColumn($this->lng->txt("poll_percentage"), "percentage");
43
44 $total = $this->getItems();
45
46 $this->setTitle(
47 $this->lng->txt("poll_question") . ": \"" .
48 $a_parent_obj->getObject()->getQuestion() . "\""
49 );
50 $this->setDescription(sprintf($this->lng->txt("poll_population"), $total));
51
52 $this->setRowTemplate("tpl.answer_row.html", "components/ILIAS/Poll");
53 $this->setDefaultOrderField("pos");
54 $this->setDefaultOrderDirection("asc");
55
56 $this->setExportFormats(array(self::EXPORT_CSV, self::EXPORT_EXCEL));
57 }
58
59 public function numericOrdering(string $a_field): bool
60 {
61 return $a_field !== "answer";
62 }
63
64 public function getItems(): int
65 {
66 $data = $this->parent_obj->getObject()->getAnswers();
67 $perc = $this->parent_obj->getObject()->getVotePercentages();
68 $total = (int) ($perc["total"] ?? 0);
69 $perc = (array) ($perc["perc"] ?? []);
70
71 // add current percentages
72 foreach ($data as $idx => $item) {
73 $item_id = (int) ($item['id'] ?? 0);
74 if (!isset($perc[$item_id])) {
75 $data[$idx]["percentage"] = 0;
76 $data[$idx]["votes"] = 0;
77 } else {
78 $data[$idx]["percentage"] = round((float) ($perc[$item_id]["perc"] ?? 0));
79 $data[$idx]["votes"] = (int) ($perc[$item_id]["abs"] ?? 0);
80 }
81 }
82
83 $this->setData($data);
84
85 return $total;
86 }
87
88 protected function fillRow(array $a_set): void
89 {
90 $this->tpl->setVariable("VALUE_POS", (int) ($a_set["pos"] ?? 10) / 10);
91 $this->tpl->setVariable("TXT_ANSWER", nl2br((string) ($a_set["answer"] ?? '')));
92 $this->tpl->setVariable("VALUE_VOTES", (int) ($a_set["votes"] ?? 0));
93 $this->tpl->setVariable("VALUE_PERCENTAGE", (int) ($a_set["percentage"] ?? 0));
94 }
95
96 protected function fillRowCSV(ilCSVWriter $a_csv, array $a_set): void
97 {
98 $a_csv->addColumn((string) ((int) ($a_set["pos"] ?? 10) / 10));
99 $a_csv->addColumn((string) ($a_set["answer"] ?? ''));
100 $a_csv->addColumn((string) ((int) ($a_set["votes"] ?? 0)));
101 $a_csv->addColumn((string) ((int) ($a_set["percentage"] ?? 0)));
102 $a_csv->addRow();
103 }
104
105 protected function fillRowExcel(ilExcel $a_excel, int &$a_row, array $a_set): void
106 {
107 $a_excel->setCell($a_row, 0, (int) ($a_set["pos"] ?? 10) / 10);
108 $a_excel->setCell($a_row, 1, (string) ($a_set["answer"] ?? ''));
109 $a_excel->setCell($a_row, 2, (int) ($a_set["votes"] ?? 0));
110 $a_excel->setCell($a_row, 3, (int) ($a_set["percentage"] ?? 0) . "%");
111 }
112}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addColumn(string $a_col)
setCell(int $a_row, int $col, $value, ?string $datatype=null, bool $disable_strip_tags_for_strings=false)
Set cell value.
TableGUI class for poll answers.
__construct(?object $a_parent_obj, string $a_parent_cmd)
fillRowExcel(ilExcel $a_excel, int &$a_row, array $a_set)
Excel Version of Fill Row.
fillRowCSV(ilCSVWriter $a_csv, array $a_set)
CSV Version of Fill Row.
numericOrdering(string $a_field)
Should this field be sorted numeric?
fillRow(array $a_set)
Standard Version of Fill Row.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
setExportFormats(array $formats)
Set available export formats.
setDescription(string $a_val)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setDefaultOrderField(string $a_defaultorderfield)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setDefaultOrderDirection(string $a_defaultorderdirection)
setData(array $a_data)
Set table data.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26