ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilPollUserTableGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
23 
30 {
31  protected array $answer_ids = [];
32  protected string $rendered_checked_icon;
33 
34  public function __construct(object $a_parent_obj, string $a_parent_cmd)
35  {
36  global $DIC;
37 
38  $this->ctrl = $DIC->ctrl();
39  $this->lng = $DIC->language();
40  $ilCtrl = $DIC->ctrl();
41  $lng = $DIC->language();
42  $ui_factory = $DIC->ui()->factory();
43  $ui_renderer = $DIC->ui()->renderer();
44 
45  $lng->loadLanguageModule('poll');
46 
47  $this->rendered_checked_icon = $ui_renderer->render(
48  $ui_factory->symbol()->icon()->custom(
49  ilUtil::getImagePath('icon_ok.svg'),
50  $lng->txt('poll_answer_selected_alt_text'),
51  Icon::MEDIUM
52  )
53  );
54 
55  $this->setId("ilobjpollusr");
56 
57  parent::__construct($a_parent_obj, $a_parent_cmd);
58 
59  $this->addColumn($lng->txt("login"), "login");
60  $this->addColumn($lng->txt("lastname"), "lastname");
61  $this->addColumn($lng->txt("firstname"), "firstname");
62 
63  foreach ($this->getParentObject()->getObject()->getAnswers() as $answer) {
64  $this->answer_ids[] = (int) ($answer["id"] ?? 0);
65  $this->addColumn((string) ($answer["answer"] ?? ''), "answer" . (int) ($answer["id"] ?? 0));
66  }
67 
68  $this->getItems($this->answer_ids);
69 
70  $this->setTitle(
71  $this->lng->txt("poll_question") . ": \"" .
72  $this->getParentObject()->getObject()->getQuestion() . "\""
73  );
74 
75  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
76  $this->setRowTemplate("tpl.user_row.html", "Modules/Poll");
77  $this->setDefaultOrderField("login");
78  $this->setDefaultOrderDirection("asc");
79 
80  $this->setExportFormats(array(self::EXPORT_CSV, self::EXPORT_EXCEL));
81  }
82 
83  protected function getItems(array $a_answer_ids): void
84  {
85  $data = [];
86 
87  foreach ($this->getParentObject()->getObject()->getVotesByUsers() as $user_id => $vote) {
88  $answers = (array) ($vote["answers"] ?? []);
89  unset($vote["answers"]);
90 
91  foreach ($a_answer_ids as $answer_id) {
92  $vote["answer" . $answer_id] = in_array($answer_id, $answers);
93  }
94 
95  $data[] = $vote;
96  }
97 
98  $this->setData($data);
99  }
100 
101  protected function fillRow(array $a_set): void
102  {
103  $this->tpl->setCurrentBlock("answer_bl");
104  foreach ($this->answer_ids as $answer_id) {
105  if ($a_set["answer" . $answer_id]) {
106  $this->tpl->setVariable("ANSWER", $this->rendered_checked_icon);
107  } else {
108  $this->tpl->setVariable("ANSWER", "&nbsp;");
109  }
110  $this->tpl->parseCurrentBlock();
111  }
112 
113  $this->tpl->setVariable("LOGIN", (string) ($a_set["login"] ?? ''));
114  $this->tpl->setVariable("FIRSTNAME", (string) ($a_set["firstname"] ?? ''));
115  $this->tpl->setVariable("LASTNAME", (string) ($a_set["lastname"] ?? ''));
116  }
117 
118  protected function fillRowCSV(ilCSVWriter $a_csv, array $a_set): void
119  {
120  $a_csv->addColumn((string) ($a_set["login"] ?? ''));
121  $a_csv->addColumn((string) ($a_set["lastname"] ?? ''));
122  $a_csv->addColumn((string) ($a_set["firstname"] ?? ''));
123  foreach ($this->answer_ids as $answer_id) {
124  if ($a_set["answer" . $answer_id]) {
125  $a_csv->addColumn('1');
126  } else {
127  $a_csv->addColumn('');
128  }
129  }
130  $a_csv->addRow();
131  }
132 
133  protected function fillRowExcel(ilExcel $a_excel, int &$a_row, array $a_set): void
134  {
135  $a_excel->setCell($a_row, 0, (string) ($a_set["login"] ?? ''));
136  $a_excel->setCell($a_row, 1, (string) ($a_set["lastname"] ?? ''));
137  $a_excel->setCell($a_row, 2, (string) ($a_set["firstname"] ?? ''));
138 
139  $col = 2;
140  foreach ($this->answer_ids as $answer_id) {
141  if ($a_set["answer" . $answer_id]) {
142  $a_excel->setCell($a_row, ++$col, true);
143  } else {
144  $a_excel->setCell($a_row, ++$col, false);
145  }
146  }
147  }
148 }
setData(array $a_data)
addColumn(string $a_col)
setExportFormats(array $formats)
Set available export formats.
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...
setFormAction(string $a_form_action, bool $a_multipart=false)
fillRowExcel(ilExcel $a_excel, int &$a_row, array $a_set)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
loadLanguageModule(string $a_module)
Load language module.
setCell(int $a_row, int $a_col, $a_value, ?string $a_datatype=null)
Set cell value.
ilLanguage $lng
setId(string $a_val)
__construct(object $a_parent_obj, string $a_parent_cmd)
global $DIC
Definition: feed.php:28
getItems(array $a_answer_ids)
setDefaultOrderField(string $a_defaultorderfield)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
fillRowCSV(ilCSVWriter $a_csv, array $a_set)
setDefaultOrderDirection(string $a_defaultorderdirection)
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
__construct(Container $dic, ilPlugin $plugin)
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)
TableGUI class for poll users.