ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilPollUserTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(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 }
setData(array $a_data)
addColumn(string $a_col)
setExportFormats(array $formats)
Set available export formats.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
loadLanguageModule(string $a_module)
Load language module.
ilLanguage $lng
setId(string $a_val)
__construct(object $a_parent_obj, string $a_parent_cmd)
setCell(int $a_row, int $col, $value, ?string $datatype=null, bool $disable_strip_tags_for_strings=false)
Set cell value.
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)
global $DIC
Definition: shib_login.php:26
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
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.