ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPollBlockGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\UI\Factory as UIFactory;
22use ILIAS\UI\Renderer as UIRenderer;
23use ILIAS\Refinery\Factory as Refinery;
24use ILIAS\Data\Factory as DataFactory;
25use ILIAS\Poll\Image\I\FactoryInterface as ilPollImageFactoryInterface;
26use ILIAS\Poll\Image\Factory as ilPollImageFactory;
27
35{
36 public static string $block_type = "poll";
38 public static bool $js_init = false;
39 protected UIFactory $ui_factory;
40 protected UIRenderer $ui_renderer;
41 protected Refinery $refinery;
42 protected DataFactory $data_factory;
45 protected ilPollImageFactoryInterface $poll_image_factory;
46
47 public function __construct()
48 {
49 global $DIC;
50
51 $this->lng = $DIC->language();
52 $this->ctrl = $DIC->ctrl();
53 $this->user = $DIC->user();
54 $this->access = $DIC->access();
55 $this->ui_factory = $DIC->ui()->factory();
56 $this->ui_renderer = $DIC->ui()->renderer();
57 $this->data_factory = new DataFactory();
58 $this->refinery = $DIC->refinery();
59
61
62 $this->lng->loadLanguageModule("poll");
63 $this->setRowTemplate("tpl.block.html", "components/ILIAS/Poll");
64 $this->poll_image_factory = new ilPollImageFactory();
65 $this->comments = new ilPollCommentsHandler(
66 $DIC->notes(),
67 $DIC->http(),
68 $DIC->refinery(),
69 $this->getCommentsRedrawURL()
70 );
71 $this->state = new ilPollStateInfo();
72 }
73
74 public function getBlockType(): string
75 {
76 return self::$block_type;
77 }
78
79 protected function isRepositoryObject(): bool
80 {
81 return true;
82 }
83
84 protected function getRepositoryObjectGUIName(): string
85 {
86 return "ilobjpollgui";
87 }
88
89 public function setBlock(ilPollBlock $a_block): void
90 {
91 $this->setBlockId((string) $a_block->getId());
92 $this->poll_block = $a_block;
93 }
94
95 public function executeCommand(): void
96 {
97 $next_class = $this->ctrl->getNextClass();
98 $cmd = $this->ctrl->getCmd("getHTML");
99
100 switch ($next_class) {
101 default:
102 $this->$cmd();
103 break;
104 }
105 }
106
107 public function fillRow(array $a_set): void
108 {
109 if ($this->poll_block->getPoll()->getShowComments()) {
110 $this->initJS();
111 }
112
113 $this->initContentRenderer()->render(
114 $this->tpl,
115 $this->getRefId(),
116 $this->user->getId(),
117 $this->poll_block->getPoll(),
118 $this->getAdminCommands()
119 );
120 }
121
122 public function getHTML(): string
123 {
124 $this->poll_block->setRefId($this->getRefId());
125 $may_write = $this->access->checkAccess("write", "", $this->getRefId());
126
127 $poll_obj = $this->poll_block->getPoll();
128 $this->setTitle($poll_obj->getTitle());
129 $this->setData([[$poll_obj]]);
130
131 $this->ctrl->setParameterByClass(
133 "ref_id",
134 $this->getRefId()
135 );
136
137 if (
138 !$this->state->isOfflineOrUnavailable($this->poll_block->getPoll()) &&
139 !$this->user->isAnonymous()
140 ) {
141 // notification
142 if (ilNotification::hasNotification(ilNotification::TYPE_POLL, $this->user->getId(), $this->poll_block->getPoll()->getId())) {
143 $this->addBlockCommand(
144 $this->ctrl->getLinkTargetByClass(
145 array("ilrepositorygui", $this->getRepositoryObjectGUIName()),
146 "unsubscribe"
147 ),
148 $this->lng->txt("poll_notification_unsubscribe")
149 );
150 } else {
151 $this->addBlockCommand(
152 $this->ctrl->getLinkTargetByClass(
153 array("ilrepositorygui", $this->getRepositoryObjectGUIName()),
154 "subscribe"
155 ),
156 $this->lng->txt("poll_notification_subscribe")
157 );
158 }
159 }
160
161 if ($may_write) {
162 // edit
163 $this->addBlockCommand(
164 $this->ctrl->getLinkTargetByClass(
165 array("ilrepositorygui", $this->getRepositoryObjectGUIName()),
166 "render"
167 ),
168 $this->lng->txt("poll_edit_question")
169 );
170 $this->addBlockCommand(
171 $this->ctrl->getLinkTargetByClass(
172 array("ilrepositorygui", $this->getRepositoryObjectGUIName()),
173 "edit"
174 ),
175 $this->lng->txt("settings")
176 );
177 $this->addBlockCommand(
178 $this->ctrl->getLinkTargetByClass(
179 array("ilrepositorygui", $this->getRepositoryObjectGUIName()),
180 "showParticipants"
181 ),
182 $this->lng->txt("poll_result")
183 );
184 }
185
186 $this->ctrl->clearParametersByClass($this->getRepositoryObjectGUIName());
187
188 return parent::getHTML();
189 }
190
192 {
193 $answers = new ilPollAnswersHandler(
194 $this->poll_block->getPoll(),
195 $this->getVoteURL(),
196 'vote'
197 );
199 $this->poll_block->getPoll(),
200 $answers
201 );
202 return new ilPollContentRenderer(
203 $this->lng,
204 $this->ui_factory,
205 $this->ui_renderer,
206 $this->refinery,
207 $this->state,
208 $this->comments,
209 $answers,
211 $this->lng,
212 $this->refinery
213 ),
214 $results,
216 $this->getRefId(),
217 $this->refinery,
218 $this->data_factory,
219 $this->ui_factory,
220 $this->ui_renderer,
221 $this->lng
222 ),
223 $this->poll_image_factory
224 );
225 }
226
227 protected function initJS(): void
228 {
229 if (!self::$js_init) {
230 $this->main_tpl->addJavaScript("assets/js/ilPoll.js");
231 self::$js_init = true;
232 }
233 }
234
235 protected function getCommentsRedrawURL(): string
236 {
237 return $this->ctrl->getLinkTarget(
238 $this,
239 "getNumberOfCommentsForRedraw",
240 "",
241 true
242 );
243 }
244
245 protected function getVoteURL(): string
246 {
247 $this->ctrl->setParameterByClass(
249 "ref_id",
250 $this->getRefId()
251 );
252 $url = $this->ctrl->getLinkTargetByClass(
253 array("ilrepositorygui", $this->getRepositoryObjectGUIName()),
254 "vote"
255 );
256 $this->ctrl->clearParametersByClass($this->getRepositoryObjectGUIName());
257
258 return $url .= "#poll" . $this->poll_block->getPoll()->getID();
259 }
260
261 public function getNumberOfCommentsForRedraw(): void
262 {
263 $this->comments->getNumberOfCommentsForRedraw();
264 }
265
266 protected function getLegacyContent(): string
267 {
268 $this->tpl = new ilTemplate(
269 $this->getRowTemplateName(),
270 true,
271 true,
272 $this->getRowTemplateDir()
273 );
274 $this->fillRow(current($this->getData()));
275 return $this->tpl->get();
276 }
277}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
This class represents a block method of a block.
setData(array $a_data)
setTitle(string $a_title)
addBlockCommand(string $a_href, string $a_text, string $a_onclick="", ?RoundTrip $modal=null)
setBlockId(string $a_block_id="0")
setRowTemplate(string $a_rowtemplatename, string $a_rowtemplatedir="")
Set Row Template Name.
static hasNotification(int $type, int $user_id, int $id)
Check notification status for object and user.
BlockGUI class for polls.
getLegacyContent()
Get legacy content.
ilPollCommentsHandler $comments
DataFactory $data_factory
setBlock(ilPollBlock $a_block)
isRepositoryObject()
Returns whether block has a corresponding repository object.
static string $block_type
ilPollStateInfo $state
ilPollImageFactoryInterface $poll_image_factory
Custom block for polls.
special template class to simplify handling of ITX/PEAR
An entity that renders components to a string output.
Definition: Renderer.php:31
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$results
global $DIC
Definition: shib_login.php:26
$url
Definition: shib_logout.php:68