ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPollUserTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29{
30 protected array $answer_ids = [];
31 protected string $rendered_checked_icon;
32
33 public function __construct(object $a_parent_obj, string $a_parent_cmd)
34 {
35 global $DIC;
36
37 $this->ctrl = $DIC->ctrl();
38 $this->lng = $DIC->language();
39 $ilCtrl = $DIC->ctrl();
40 $lng = $DIC->language();
41 $ui_factory = $DIC->ui()->factory();
42 $ui_renderer = $DIC->ui()->renderer();
43
44 $lng->loadLanguageModule('poll');
45
46 $this->rendered_checked_icon = $ui_renderer->render(
47 $ui_factory->symbol()->icon()->custom(
48 ilUtil::getImagePath('standard/icon_ok.svg'),
49 $lng->txt('poll_answer_selected_alt_text'),
50 Icon::MEDIUM
51 )
52 );
53
54 $this->setId("ilobjpollusr");
55
56 parent::__construct($a_parent_obj, $a_parent_cmd);
57
58 $this->addColumn($lng->txt("login"), "login");
59 $this->addColumn($lng->txt("lastname"), "lastname");
60 $this->addColumn($lng->txt("firstname"), "firstname");
61
62 foreach ($this->getParentObject()->getObject()->getAnswers() as $answer) {
63 $this->answer_ids[] = (int) ($answer["id"] ?? 0);
64 $this->addColumn((string) ($answer["answer"] ?? ''), "answer" . (int) ($answer["id"] ?? 0));
65 }
66
67 $this->getItems($this->answer_ids);
68
69 $this->setTitle(
70 $this->lng->txt("poll_question") . ": \"" .
71 $this->getParentObject()->getObject()->getQuestion() . "\""
72 );
73
74 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
75 $this->setRowTemplate("tpl.user_row.html", "components/ILIAS/Poll");
76 $this->setDefaultOrderField("login");
77 $this->setDefaultOrderDirection("asc");
78
79 $this->setExportFormats(array(self::EXPORT_CSV, self::EXPORT_EXCEL));
80 }
81
82 protected function getItems(array $a_answer_ids): void
83 {
84 $data = [];
85
86 foreach ($this->getParentObject()->getObject()->getVotesByUsers() as $user_id => $vote) {
87 $answers = (array) ($vote["answers"] ?? []);
88 unset($vote["answers"]);
89
90 foreach ($a_answer_ids as $answer_id) {
91 $vote["answer" . $answer_id] = in_array($answer_id, $answers);
92 }
93
94 $data[] = $vote;
95 }
96
97 $this->setData($data);
98 }
99
100 protected function fillRow(array $a_set): void
101 {
102 $this->tpl->setCurrentBlock("answer_bl");
103 foreach ($this->answer_ids as $answer_id) {
104 if ($a_set["answer" . $answer_id]) {
105 $this->tpl->setVariable("ANSWER", $this->rendered_checked_icon);
106 } else {
107 $this->tpl->setVariable("ANSWER", "&nbsp;");
108 }
109 $this->tpl->parseCurrentBlock();
110 }
111
112 $this->tpl->setVariable("LOGIN", (string) ($a_set["login"] ?? ''));
113 $this->tpl->setVariable("FIRSTNAME", (string) ($a_set["firstname"] ?? ''));
114 $this->tpl->setVariable("LASTNAME", (string) ($a_set["lastname"] ?? ''));
115 }
116
117 protected function fillRowCSV(ilCSVWriter $a_csv, array $a_set): void
118 {
119 $a_csv->addColumn((string) ($a_set["login"] ?? ''));
120 $a_csv->addColumn((string) ($a_set["lastname"] ?? ''));
121 $a_csv->addColumn((string) ($a_set["firstname"] ?? ''));
122 foreach ($this->answer_ids as $answer_id) {
123 if ($a_set["answer" . $answer_id]) {
124 $a_csv->addColumn('1');
125 } else {
126 $a_csv->addColumn('');
127 }
128 }
129 $a_csv->addRow();
130 }
131
132 protected function fillRowExcel(ilExcel $a_excel, int &$a_row, array $a_set): void
133 {
134 $a_excel->setCell($a_row, 0, (string) ($a_set["login"] ?? ''));
135 $a_excel->setCell($a_row, 1, (string) ($a_set["lastname"] ?? ''));
136 $a_excel->setCell($a_row, 2, (string) ($a_set["firstname"] ?? ''));
137
138 $col = 2;
139 foreach ($this->answer_ids as $answer_id) {
140 if ($a_set["answer" . $answer_id]) {
141 $a_excel->setCell($a_row, ++$col, true);
142 } else {
143 $a_excel->setCell($a_row, ++$col, false);
144 }
145 }
146 }
147}
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.
loadLanguageModule(string $a_module)
Load language module.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
TableGUI class for poll users.
fillRow(array $a_set)
Standard Version of Fill Row.
fillRowCSV(ilCSVWriter $a_csv, array $a_set)
CSV Version of Fill Row.
fillRowExcel(ilExcel $a_excel, int &$a_row, array $a_set)
Excel Version of Fill Row.
__construct(object $a_parent_obj, string $a_parent_cmd)
getItems(array $a_answer_ids)
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.
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.
ilLanguage $lng
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
This describes how an icon could be modified during construction of UI.
Definition: Icon.php:29
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26