ILIAS  release_8 Revision v8.24
class.ilChatroomAdminSmileyGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
30{
31 protected ?ilPropertyFormGUI $form_gui = null;
32
33 public function executeDefault(string $requestedMethod): void
34 {
35 $this->view();
36 }
37
42 public function view(): void
43 {
44 ilChatroom::checkUserPermissions('read', $this->gui->getRefId());
45
46 $this->gui->switchToVisibleMode();
47
49
50 $this->editSmiliesObject();
51 }
52
53 public static function _checkSetup(): bool
54 {
55 global $DIC;
56 $main_tpl = $DIC->ui()->mainTemplate();
57
59
60 if (!is_dir($path)) {
61 $main_tpl->setOnScreenMessage('info', $DIC->language()->txt('chat_smilies_dir_not_exists'));
63
64 if (!is_dir($path)) {
65 $main_tpl->setOnScreenMessage('failure', $DIC->language()->txt('chat_smilies_dir_not_available'));
66 return false;
67 }
68
69 $smilies = [
70 'icon_smile.gif',
71 'icon_wink.gif',
72 'icon_laugh.gif',
73 'icon_sad.gif',
74 'icon_shocked.gif',
75 'icon_tongue.gif',
76 'icon_cool.gif',
77 'icon_eek.gif',
78 'icon_angry.gif',
79 'icon_flush.gif',
80 'icon_idea.gif',
81 'icon_thumbup.gif',
82 'icon_thumbdown.gif',
83 ];
84
85 foreach ($smilies as $smiley) {
86 copy("templates/default/images/emoticons/$smiley", $path . "/$smiley");
87 }
88
90
91 $main_tpl->setOnScreenMessage('success', $DIC->language()->txt('chat_smilies_initialized'));
92 }
93
94 if (!is_writable($path)) {
95 $main_tpl->setOnScreenMessage('info', $DIC->language()->txt('chat_smilies_dir_not_writable'));
96 }
97
98 return true;
99 }
100
101 public static function _getSmileyDir(bool $withBaseDir = true): string
102 {
103 $path = 'chatroom/smilies';
104
105 if ($withBaseDir) {
107 }
108
109 return $path;
110 }
111
112 private static function _insertDefaultValues(): void
113 {
114 $values = [
115 ["icon_smile.gif", ":)\n:-)\n:smile:"],
116 ["icon_wink.gif", ";)\n;-)\n:wink:"],
117 ["icon_laugh.gif", ":D\n:-D\n:laugh:\n:grin:\n:biggrin:"],
118 ["icon_sad.gif", ":(\n:-(\n:sad:"],
119 ["icon_shocked.gif", ":o\n:-o\n:shocked:"],
120 ["icon_tongue.gif", ":p\n:-p\n:tongue:"],
121 ["icon_cool.gif", ":cool:"],
122 ["icon_eek.gif", ":eek:"],
123 ["icon_angry.gif", ":||\n:-||\n:angry:"],
124 ["icon_flush.gif", ":flush:"],
125 ["icon_idea.gif", ":idea:"],
126 ["icon_thumbup.gif", ":thumbup:"],
127 ["icon_thumbdown.gif", ":thumbdown:"],
128 ];
129
130 foreach ($values as $val) {
131 ilChatroomSmilies::_storeSmiley($val[1], $val[0]);
132 }
133 }
134
139 public function editSmiliesObject(): void
140 {
141 if (!$this->rbacsystem->checkAccess('read', $this->gui->getRefId())) {
142 $this->ilias->raiseError(
143 $this->ilLng->txt('msg_no_perm_read'),
144 $this->ilias->error_obj->MESSAGE
145 );
146 }
147
148 ilChatroomSmilies::_checkSetup();
149
150 if (null === $this->form_gui) {
151 $this->form_gui = $this->initSmiliesForm();
152 }
153
155
156 $tpl_smilies = new ilTemplate(
157 'tpl.chatroom_edit_smilies.html',
158 true,
159 true,
160 'Modules/Chatroom'
161 );
162 $tpl_smilies->setVariable('SMILEY_TABLE', $table);
163 $tpl_smilies->setVariable('SMILEY_FORM', $this->form_gui->getHTML());
164
165 $this->mainTpl->setContent($tpl_smilies->get());
166 }
167
169 {
170 global $DIC;
171
172 $this->form_gui = new ilPropertyFormGUI();
173
174 if ($this->http->wrapper()->query()->has('_table_nav')) {
175 $this->ilCtrl->setParameter(
176 $this->gui,
177 '_table_nav',
178 $this->http->wrapper()->query()->retrieve('_table_nav', $this->refinery->kindlyTo()->string())
179 );
180 }
181 $this->form_gui->setFormAction($this->ilCtrl->getFormAction($this->gui, 'smiley-uploadSmileyObject'));
182
183 $sec_l = new ilFormSectionHeaderGUI();
184
185 $sec_l->setTitle($this->ilLng->txt('chatroom_add_smiley'));
186 $this->form_gui->addItem($sec_l);
187
188 $inp = new ilImageFileInputGUI(
189 $this->ilLng->txt('chatroom_image_path'),
190 'chatroom_image_path'
191 );
192 $inp->setSuffixes(['jpg', 'jpeg', 'png', 'gif', 'svg']);
193
194 $inp->setRequired(true);
195 $this->form_gui->addItem($inp);
196
197 $inp = new ilTextAreaInputGUI(
198 $this->ilLng->txt('chatroom_smiley_keywords'),
199 'chatroom_smiley_keywords'
200 );
201
202 $inp->setRequired(true);
203 $inp->setUseRte(false);
204 $inp->setInfo($this->ilLng->txt('chatroom_smiley_keywords_one_per_line_note'));
205 $this->form_gui->addItem($inp);
206
207
208 if ($this->rbacsystem->checkAccess('write', $this->gui->getRefId())) {
209 $this->form_gui->addCommandButton(
210 'smiley-uploadSmileyObject',
211 $DIC->language()->txt('chatroom_upload_smiley')
212 );
213 }
214
215 return $this->form_gui;
216 }
217
222 public function showEditSmileyEntryFormObject(): void
223 {
224 $this->gui->switchToVisibleMode();
225
226 if (!$this->rbacsystem->checkAccess('read', $this->gui->getRefId())) {
227 $this->ilias->raiseError(
228 $this->ilLng->txt('msg_no_perm_read'),
229 $this->ilias->error_obj->MESSAGE
230 );
231 }
232
233 $smileyId = $this->getRequestValue('smiley_id', $this->refinery->kindlyTo()->int());
234
235 if (null === $this->form_gui) {
236 $this->form_gui = $this->initSmiliesEditForm($this->getSmileyFormDataById($smileyId));
237 }
238
239 $tpl_form = new ilTemplate(
240 'tpl.chatroom_edit_smilies.html',
241 true,
242 true,
243 'Modules/Chatroom'
244 );
245
246 $tpl_form->setVariable('SMILEY_FORM', $this->form_gui->getHTML());
247
248 $this->mainTpl->setContent($tpl_form->get());
249 }
250
255 protected function getSmileyFormDataById(int $smileyId): array
256 {
257 $smiley = ilChatroomSmilies::_getSmiley($smileyId);
258
259 return [
260 'chatroom_smiley_id' => $smiley['smiley_id'],
261 'chatroom_smiley_keywords' => $smiley['smiley_keywords'],
262 'chatroom_current_smiley_image_path' => $smiley['smiley_fullpath'],
263 ];
264 }
265
270 public function initSmiliesEditForm(array $form_data): ilPropertyFormGUI
271 {
272 $this->form_gui = new ilPropertyFormGUI();
273 $this->form_gui->setValuesByArray($form_data);
274
275 if ($this->http->wrapper()->query()->has('_table_nav')) {
276 $this->ilCtrl->setParameter(
277 $this->gui,
278 '_table_nav',
279 $this->http->wrapper()->query()->retrieve('_table_nav', $this->refinery->kindlyTo()->string())
280 );
281 }
282
283 $this->ilCtrl->saveParameter($this->gui, 'smiley_id');
284 $this->form_gui->setFormAction($this->ilCtrl->getFormAction($this->gui, 'smiley-updateSmiliesObject'));
285
286 $sec_l = new ilFormSectionHeaderGUI();
287
288 $sec_l->setTitle($this->ilLng->txt('chatroom_edit_smiley'));
289 $this->form_gui->addItem($sec_l);
290
292 $this->ilLng->txt('chatroom_current_smiley_image_path'),
293 'chatroom_current_smiley_image_path'
294 );
295
296 $inp->setValue($form_data['chatroom_current_smiley_image_path']);
297 $this->form_gui->addItem($inp);
298
299 $inp = new ilImageFileInputGUI(
300 $this->ilLng->txt('chatroom_image_path'),
301 'chatroom_image_path'
302 );
303 $inp->setSuffixes(['jpg', 'jpeg', 'png', 'gif', 'svg']);
304
305 $inp->setRequired(false);
306 $inp->setInfo($this->ilLng->txt('chatroom_smiley_image_only_if_changed'));
307 $this->form_gui->addItem($inp);
308
309 $inp = new ilTextAreaInputGUI(
310 $this->ilLng->txt('chatroom_smiley_keywords'),
311 'chatroom_smiley_keywords'
312 );
313
314 $inp->setValue($form_data['chatroom_smiley_keywords']);
315 $inp->setUseRte(false);
316 $inp->setRequired(true);
317 $inp->setInfo($this->ilLng->txt('chatroom_smiley_keywords_one_per_line_note'));
318 $this->form_gui->addItem($inp);
319
320 $inp = new ilHiddenInputGUI('chatroom_smiley_id');
321
322 $this->form_gui->addItem($inp);
323 $this->form_gui->addCommandButton(
324 'smiley-updateSmiliesObject',
325 $this->ilLng->txt('submit')
326 );
327 $this->form_gui->addCommandButton('smiley', $this->ilLng->txt('cancel'));
328
329 return $this->form_gui;
330 }
331
336 public function showDeleteSmileyFormObject(): void
337 {
338 $this->gui->switchToVisibleMode();
339
340 if (!$this->rbacsystem->checkAccess('write', $this->gui->getRefId())) {
341 $this->ilias->raiseError(
342 $this->ilLng->txt('msg_no_perm_write'),
343 $this->ilias->error_obj->MESSAGE
344 );
345 }
346
347 $smileyId = $this->getRequestValue('smiley_id', $this->refinery->kindlyTo()->int());
348
349 $smiley = ilChatroomSmilies::_getSmiley($smileyId);
350
351 $confirmation = new ilConfirmationGUI();
352 $confirmation->setFormAction($this->ilCtrl->getFormAction($this->gui, 'smiley'));
353 $confirmation->setHeaderText($this->ilLng->txt('chatroom_confirm_delete_smiley'));
354 $confirmation->setConfirm($this->ilLng->txt('confirm'), 'smiley-deleteSmileyObject');
355 $confirmation->setCancel($this->ilLng->txt('cancel'), 'smiley');
356 $confirmation->addItem(
357 'chatroom_smiley_id',
358 (string) $smiley['smiley_id'],
359 ilUtil::img($smiley['smiley_fullpath'], $smiley['smiley_keywords']) . ' ' . $smiley['smiley_keywords']
360 );
361
362 $this->mainTpl->setContent($confirmation->getHTML());
363 }
364
365 public function deleteSmileyObject(): void
366 {
367 if (!$this->rbacsystem->checkAccess('write', $this->gui->getRefId())) {
368 $this->ilias->raiseError(
369 $this->ilLng->txt('msg_no_perm_write'),
370 $this->ilias->error_obj->MESSAGE
371 );
372 }
373
374 $smileyId = $this->getRequestValue(
375 'chatroom_smiley_id',
376 $this->refinery->kindlyTo()->int()
377 );
378
379 ilChatroomSmilies::_deleteSmiley($smileyId);
380
381 $this->ilCtrl->redirect($this->gui, 'smiley');
382 }
383
384 public function updateSmiliesObject(): void
385 {
386 if (!$this->rbacsystem->checkAccess('write', $this->gui->getRefId())) {
387 $this->ilias->raiseError(
388 $this->ilLng->txt('msg_no_perm_write'),
389 $this->ilias->error_obj->MESSAGE
390 );
391 }
392
393 $smileyId = $this->getRequestValue('smiley_id', $this->refinery->kindlyTo()->int());
394
395 $this->initSmiliesEditForm($this->getSmileyFormDataById($smileyId));
396
398 $this->getRequestValue('chatroom_smiley_keywords', $this->refinery->kindlyTo()->string(), '')
399 ));
400
401 $atLeastOneKeywordGiven = count($keywords) > 0;
402
403 $isFormValid = $this->form_gui->checkInput();
404 if (!$atLeastOneKeywordGiven || !$isFormValid) {
405 $errorShown = !$isFormValid;
406 if (!$atLeastOneKeywordGiven && !$errorShown) {
407 $this->mainTpl->setOnScreenMessage('failure', $this->ilLng->txt('form_input_not_valid'));
408 }
409
410 $this->form_gui->setValuesByPost();
411
413 return;
414 }
415
416 $data = [];
417 $data['smiley_keywords'] = implode("\n", $keywords);
418 $data['smiley_id'] = $smileyId;
419
420 if ($this->upload->hasUploads() && !$this->upload->hasBeenProcessed()) {
421 $this->upload->process();
422
424 $result = array_values($this->upload->getResults())[0];
425 if ($result && $result->isOK()) {
426 $this->upload->moveOneFileTo(
427 $result,
429 \ILIAS\FileUpload\Location::WEB,
430 $result->getName(),
431 true
432 );
433
434 $data['smiley_path'] = $result->getName();
435 }
436 }
437
438 ilChatroomSmilies::_updateSmiley($data);
439
440 $this->mainTpl->setOnScreenMessage('success', $this->ilLng->txt('saved_successfully'), true);
441 $this->ilCtrl->redirect($this->gui, 'smiley');
442 }
443
448 public function deleteMultipleObject(): void
449 {
450 $this->gui->switchToVisibleMode();
451
452 if (!$this->rbacsystem->checkAccess('write', $this->gui->getRefId())) {
453 $this->ilias->raiseError(
454 $this->ilLng->txt('msg_no_perm_write'),
455 $this->ilias->error_obj->MESSAGE
456 );
457 }
458
459 $ids = $this->getRequestValue(
460 'smiley_id',
461 $this->refinery->kindlyTo()->listOf(
462 $this->refinery->kindlyTo()->int()
463 ),
464 []
465 );
466 if ($ids === []) {
467 $this->mainTpl->setOnScreenMessage('info', $this->ilLng->txt('select_one'), true);
468 $this->ilCtrl->redirect($this->gui, 'smiley');
469 }
470
471 $smilies = ilChatroomSmilies::_getSmiliesById($ids);
472 if ($smilies === []) {
473 $this->mainTpl->setOnScreenMessage('info', $this->ilLng->txt('select_one'), true);
474 $this->ilCtrl->redirect($this->gui, 'smiley');
475 }
476
477 $confirmation = new ilConfirmationGUI();
478 $confirmation->setFormAction($this->ilCtrl->getFormAction($this->gui, 'smiley'));
479 $confirmation->setHeaderText($this->ilLng->txt('chatroom_confirm_delete_smiley'));
480 $confirmation->setConfirm($this->ilLng->txt('confirm'), 'smiley-confirmedDeleteMultipleObject');
481 $confirmation->setCancel($this->ilLng->txt('cancel'), 'smiley');
482
483 foreach ($smilies as $s) {
484 $confirmation->addItem(
485 'sel_ids[]',
486 (string) $s['smiley_id'],
487 ilUtil::img($s['smiley_fullpath'], $s['smiley_keywords']) . ' ' . $s['smiley_keywords']
488 );
489 }
490
491 $this->mainTpl->setContent($confirmation->getHTML());
492 }
493
494 public function confirmedDeleteMultipleObject(): void
495 {
496 if (!$this->rbacsystem->checkAccess('write', $this->gui->getRefId())) {
497 $this->ilias->raiseError(
498 $this->ilLng->txt('msg_no_perm_write'),
499 $this->ilias->error_obj->MESSAGE
500 );
501 }
502
503 $ids = $this->getRequestValue(
504 'sel_ids',
505 $this->refinery->kindlyTo()->listOf(
506 $this->refinery->kindlyTo()->int()
507 ),
508 []
509 );
510
511 if ($ids === []) {
512 $this->ilCtrl->redirect($this->gui, 'smiley');
513 }
514
515 ilChatroomSmilies::_deleteMultipleSmilies($ids);
516
517 $this->ilCtrl->redirect($this->gui, 'smiley');
518 }
519
520 public function uploadSmileyObject(): void
521 {
522 if (!$this->rbacsystem->checkAccess('write', $this->gui->getRefId())) {
523 $this->ilias->raiseError(
524 $this->ilLng->txt('msg_no_perm_write'),
525 $this->ilias->error_obj->MESSAGE
526 );
527 }
528
529 $this->initSmiliesForm();
530
532 $this->getRequestValue(
533 'chatroom_smiley_keywords',
534 $this->refinery->kindlyTo()->string(),
535 ''
536 )
537 ));
538
539 $atLeastOneKeywordGiven = count($keywords) > 0;
540
541 $isFormValid = $this->form_gui->checkInput();
542 if (!$atLeastOneKeywordGiven || !$isFormValid) {
543 $errorShown = !$isFormValid;
544 if (!$atLeastOneKeywordGiven && !$errorShown) {
545 $this->mainTpl->setOnScreenMessage('failure', $this->ilLng->txt('form_input_not_valid'));
546 }
547
548 $this->form_gui->setValuesByPost();
549
550 $this->view();
551 return;
552 }
553
554 $pathinfo = pathinfo($_FILES['chatroom_image_path']['name']);
555 $target_file = md5(time() . $pathinfo['basename']) . '.' . $pathinfo['extension'];
556
557 if ($this->upload->hasUploads() && !$this->upload->hasBeenProcessed()) {
558 $this->upload->process();
559
561 $result = array_values($this->upload->getResults())[0];
562 if ($result && $result->isOK()) {
563 $this->upload->moveOneFileTo(
564 $result,
566 \ILIAS\FileUpload\Location::WEB,
567 $target_file,
568 true
569 );
570
571 ilChatroomSmilies::_storeSmiley(implode("\n", $keywords), $target_file);
572 }
573 }
574
575 $this->mainTpl->setOnScreenMessage('success', $this->ilLng->txt('saved_successfully'), true);
576 $this->ilCtrl->redirect($this->gui, 'smiley');
577 }
578}
Class ilChatroomAdminSmileyGUI Provides methods to show, add, edit and delete smilies consisting of i...
showDeleteSmileyFormObject()
Shows DeleteSmileyForm Prepares DeleteSmileyForm and displays it.
executeDefault(string $requestedMethod)
showEditSmileyEntryFormObject()
Shows EditSmileyEntryForm Prepares EditSmileyEntryForm and displays it.
view()
Switches GUI to visible mode and calls editSmiliesObject method which prepares and displays the table...
editSmiliesObject()
Shows existing smilies table Prepares existing smilies table and displays it.
static _getSmileyDir(bool $withBaseDir=true)
deleteMultipleObject()
Shows confirmation view for deleting multiple smilies Prepares confirmation view for deleting multipl...
Class ilChatroomGUIHandler.
getRequestValue(string $key, Transformation $trafo, $default=null)
Class ilChatroomSmiliesCurrentSmileyFormElement Simple form element that displays an image; does not ...
static _getExistingSmiliesTable(ilChatroomObjectGUI $a_ref)
static _prepareKeywords(string $words)
Trims given keywords and returns them in one array.
static checkUserPermissions($permissions, int $ref_id, bool $send_info=true)
Checks user permissions by given array and ref_id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
@inheritDoc
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
@inheritDoc
saveParameter(object $a_gui_obj, $a_parameter)
@inheritDoc
getFormAction(object $a_gui_obj, string $a_fallback_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static getWebspaceDir(string $mode="filesystem")
get webspace directory
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a property form user interface.
special template class to simplify handling of ITX/PEAR
This class represents a text area property in a property form.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static img(string $a_src, ?string $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
global $DIC
Definition: feed.php:28
$path
Definition: ltiservices.php:32
static http()
Fetches the global http state from ILIAS.
Class ChatMainBarProvider \MainMenu\Provider.
header include for all ilias files.