ILIAS  release_8 Revision v8.24
class.ilPollAnswerTableGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
28{
29 public function __construct(?object $a_parent_obj, string $a_parent_cmd)
30 {
31 global $DIC;
32
33 $this->ctrl = $DIC->ctrl();
34 $this->lng = $DIC->language();
35
36 $this->setId("ilobjpollaw");
37
38 parent::__construct($a_parent_obj, $a_parent_cmd);
39
40 $this->addColumn($this->lng->txt("poll_sortorder"), "pos");
41 $this->addColumn($this->lng->txt("poll_answer"), "answer");
42 $this->addColumn($this->lng->txt("poll_absolute"), "votes");
43 $this->addColumn($this->lng->txt("poll_percentage"), "percentage");
44
45 $total = $this->getItems();
46
47 $this->setTitle(
48 $this->lng->txt("poll_question") . ": \"" .
49 $a_parent_obj->getObject()->getQuestion() . "\""
50 );
51 $this->setDescription(sprintf($this->lng->txt("poll_population"), $total));
52
53 if ($total) {
54 $this->addCommandButton("confirmDeleteAllVotes", $this->lng->txt("poll_delete_votes"));
55 }
56
57 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, $a_parent_cmd));
58 $this->setRowTemplate("tpl.answer_row.html", "Modules/Poll");
59 $this->setDefaultOrderField("pos");
60 $this->setDefaultOrderDirection("asc");
61
62 $this->setExportFormats(array(self::EXPORT_CSV, self::EXPORT_EXCEL));
63 }
64
65 public function numericOrdering(string $a_field): bool
66 {
67 return $a_field !== "answer";
68 }
69
70 public function getItems(): int
71 {
72 $data = $this->parent_obj->getObject()->getAnswers();
73 $perc = $this->parent_obj->getObject()->getVotePercentages();
74 $total = (int) ($perc["total"] ?? 0);
75 $perc = (array) ($perc["perc"] ?? []);
76
77 // add current percentages
78 foreach ($data as $idx => $item) {
79 $item_id = (int) ($item['id'] ?? 0);
80 if (!isset($perc[$item_id])) {
81 $data[$idx]["percentage"] = 0;
82 $data[$idx]["votes"] = 0;
83 } else {
84 $data[$idx]["percentage"] = round((float) ($perc[$item_id]["perc"] ?? 0));
85 $data[$idx]["votes"] = (int) ($perc[$item_id]["abs"] ?? 0);
86 }
87 }
88
89 $this->setData($data);
90
91 return $total;
92 }
93
94 protected function fillRow(array $a_set): void
95 {
96 $this->tpl->setVariable("VALUE_POS", (int) ($a_set["pos"] ?? 10) / 10);
97 $this->tpl->setVariable("TXT_ANSWER", nl2br((string) ($a_set["answer"] ?? '')));
98 $this->tpl->setVariable("VALUE_VOTES", (int) ($a_set["votes"] ?? 0));
99 $this->tpl->setVariable("VALUE_PERCENTAGE", (int) ($a_set["percentage"] ?? 0));
100 }
101
102 protected function fillRowCSV(ilCSVWriter $a_csv, array $a_set): void
103 {
104 $a_csv->addColumn((string) ((int) ($a_set["pos"] ?? 10) / 10));
105 $a_csv->addColumn((string) ($a_set["answer"] ?? ''));
106 $a_csv->addColumn((string) ((int) ($a_set["votes"] ?? 0)));
107 $a_csv->addColumn((string) ((int) ($a_set["percentage"] ?? 0)));
108 $a_csv->addRow();
109 }
110
111 protected function fillRowExcel(ilExcel $a_excel, int &$a_row, array $a_set): void
112 {
113 $a_excel->setCell($a_row, 0, (int) ($a_set["pos"] ?? 10) / 10);
114 $a_excel->setCell($a_row, 1, (string) ($a_set["answer"] ?? ''));
115 $a_excel->setCell($a_row, 2, (int) ($a_set["votes"] ?? 0));
116 $a_excel->setCell($a_row, 3, (int) ($a_set["percentage"] ?? 0) . "%");
117 }
118}
addColumn(string $a_col)
setCell(int $a_row, int $a_col, $a_value, ?string $a_datatype=null)
Set cell value.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__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.
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
setDescription(string $a_val)
setFormAction(string $a_form_action, bool $a_multipart=false)
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.
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc