ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilPollBlockGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
31 {
32  public static string $block_type = "poll";
34  public static bool $js_init = false;
39 
40  public function __construct()
41  {
42  global $DIC;
43 
44  $this->lng = $DIC->language();
45  $this->ctrl = $DIC->ctrl();
46  $this->user = $DIC->user();
47  $this->access = $DIC->access();
48  $this->ui_factory = $DIC->ui()->factory();
49  $this->ui_renderer = $DIC->ui()->renderer();
50 
52 
53  $this->lng->loadLanguageModule("poll");
54  $this->setRowTemplate("tpl.block.html", "Modules/Poll");
55 
56  $this->comments = new ilPollCommentsHandler(
57  $DIC->notes(),
58  $DIC->http(),
59  $DIC->refinery(),
60  $this->getCommentsRedrawURL()
61  );
62  $this->state = new ilPollStateInfo();
63  }
64 
65  public function getBlockType(): string
66  {
67  return self::$block_type;
68  }
69 
70  protected function isRepositoryObject(): bool
71  {
72  return true;
73  }
74 
75  protected function getRepositoryObjectGUIName(): string
76  {
77  return "ilobjpollgui";
78  }
79 
80  public function setBlock(ilPollBlock $a_block): void
81  {
82  $this->setBlockId((string) $a_block->getId());
83  $this->poll_block = $a_block;
84  }
85 
86  public function executeCommand(): void
87  {
88  $next_class = $this->ctrl->getNextClass();
89  $cmd = $this->ctrl->getCmd("getHTML");
90 
91  switch ($next_class) {
92  default:
93  $this->$cmd();
94  break;
95  }
96  }
97 
98  public function fillRow(array $a_set): void
99  {
100  if ($this->poll_block->getPoll()->getShowComments()) {
101  $this->initJS();
102  }
103 
104  $this->initContentRenderer()->render(
105  $this->tpl,
106  $this->getRefId(),
107  $this->user->getId(),
108  $this->poll_block->getPoll(),
109  $this->getAdminCommands()
110  );
111  }
112 
113  public function getHTML(): string
114  {
115  $this->poll_block->setRefId($this->getRefId());
116  $may_write = $this->access->checkAccess("write", "", $this->getRefId());
117 
118  $poll_obj = $this->poll_block->getPoll();
119  $this->setTitle($poll_obj->getTitle());
120  $this->setData([[$poll_obj]]);
121 
122  $this->ctrl->setParameterByClass(
124  "ref_id",
125  $this->getRefId()
126  );
127 
128  if (
129  !$this->state->isOfflineOrUnavailable($this->poll_block->getPoll()) &&
130  !$this->user->isAnonymous()
131  ) {
132  // notification
133  if (ilNotification::hasNotification(ilNotification::TYPE_POLL, $this->user->getId(), $this->poll_block->getPoll()->getId())) {
134  $this->addBlockCommand(
135  $this->ctrl->getLinkTargetByClass(
136  array("ilrepositorygui", $this->getRepositoryObjectGUIName()),
137  "unsubscribe"
138  ),
139  $this->lng->txt("poll_notification_unsubscribe")
140  );
141  } else {
142  $this->addBlockCommand(
143  $this->ctrl->getLinkTargetByClass(
144  array("ilrepositorygui", $this->getRepositoryObjectGUIName()),
145  "subscribe"
146  ),
147  $this->lng->txt("poll_notification_subscribe")
148  );
149  }
150  }
151 
152  if ($may_write) {
153  // edit
154  $this->addBlockCommand(
155  $this->ctrl->getLinkTargetByClass(
156  array("ilrepositorygui", $this->getRepositoryObjectGUIName()),
157  "render"
158  ),
159  $this->lng->txt("poll_edit_question")
160  );
161  $this->addBlockCommand(
162  $this->ctrl->getLinkTargetByClass(
163  array("ilrepositorygui", $this->getRepositoryObjectGUIName()),
164  "edit"
165  ),
166  $this->lng->txt("settings")
167  );
168  $this->addBlockCommand(
169  $this->ctrl->getLinkTargetByClass(
170  array("ilrepositorygui", $this->getRepositoryObjectGUIName()),
171  "showParticipants"
172  ),
173  $this->lng->txt("poll_result")
174  );
175  }
176 
177  $this->ctrl->clearParametersByClass($this->getRepositoryObjectGUIName());
178 
179  return parent::getHTML();
180  }
181 
183  {
184  $answers = new ilPollAnswersHandler(
185  $this->poll_block->getPoll(),
186  $this->getVoteURL(),
187  'vote'
188  );
190  $this->poll_block->getPoll(),
191  $answers
192  );
193  return new ilPollContentRenderer(
194  $this->lng,
195  $this->ui_factory,
196  $this->ui_renderer,
197  $this->state,
198  $this->comments,
199  $answers,
200  new ilPollAnswersRenderer($this->lng),
201  $results,
202  new ilPollResultsRenderer($this->getRefId())
203  );
204  }
205 
206  protected function initJS(): void
207  {
208  if (!self::$js_init) {
209  $this->main_tpl->addJavaScript("Modules/Poll/js/ilPoll.js");
210  self::$js_init = true;
211  }
212  }
213 
214  protected function getCommentsRedrawURL(): string
215  {
216  return $this->ctrl->getLinkTarget(
217  $this,
218  "getNumberOfCommentsForRedraw",
219  "",
220  true
221  );
222  }
223 
224  protected function getVoteURL(): string
225  {
226  $this->ctrl->setParameterByClass(
228  "ref_id",
229  $this->getRefId()
230  );
231  $url = $this->ctrl->getLinkTargetByClass(
232  array("ilrepositorygui", $this->getRepositoryObjectGUIName()),
233  "vote"
234  );
235  $this->ctrl->clearParametersByClass($this->getRepositoryObjectGUIName());
236 
237  return $url .= "#poll" . $this->poll_block->getPoll()->getID();
238  }
239 
240  public function getNumberOfCommentsForRedraw(): void
241  {
242  $this->comments->getNumberOfCommentsForRedraw();
243  }
244 
245  protected function getLegacyContent(): string
246  {
247  $this->tpl = new ilTemplate(
248  $this->getRowTemplateName(),
249  true,
250  true,
251  $this->getRowTemplateDir()
252  );
253  $this->fillRow(current($this->getData()));
254  return $this->tpl->get();
255  }
256 }
setBlock(ilPollBlock $a_block)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static string $block_type
setBlockId(string $a_block_id="0")
fillRow(array $a_set)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
setRowTemplate(string $a_rowtemplatename, string $a_rowtemplatedir="")
Set Row Template Name.
__construct(VocabulariesInterface $vocabularies)
$url
Definition: ltiregstart.php:35
addBlockCommand(string $a_href, string $a_text, string $a_onclick="", RoundTrip $modal=null)
$results
ilPollCommentsHandler $comments
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
BlockGUI class for polls.
setTitle(string $a_title)
static hasNotification(int $type, int $user_id, int $id)
Check notification status for object and user.
ilPollStateInfo $state
This class represents a block method of a block.
setData(array $a_data)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...