ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilMailTemplateGUI Class Reference

@ilCtrl_isCalledBy ilMailTemplateGUI: ilObjMailGUI More...

+ Inheritance diagram for ilMailTemplateGUI:
+ Collaboration diagram for ilMailTemplateGUI:

Public Member Functions

 __construct (protected ilObject $parent_object, ?ilGlobalTemplateInterface $tpl=null, ?ilCtrlInterface $ctrl=null, ?ilLanguage $lng=null, ?ilToolbarGUI $toolbar=null, ?ilRbacSystem $rbacsystem=null, ?ilErrorHandling $error=null, ?GlobalHttpState $http=null, ?Factory $ui_factory=null, ?Renderer $ui_renderer=null, ?ilMailTemplateService $template_service=null)
 
 getUnsafeGetCommands ()
 This method must return a list of unsafe GET commands. More...
 
 getSafePostCommands ()
 This method must return a list of safe POST commands. More...
 
 executeCommand ()
 
 unsetAsContextDefault ()
 
 getUnsafeGetCommands ()
 This method must return a list of unsafe GET commands. More...
 
 getSafePostCommands ()
 This method must return a list of safe POST commands. More...
 

Protected Member Functions

 deleteTemplateCommand ()
 

Protected Attributes

ilPropertyFormGUI $form
 
ilGlobalTemplateInterface $tpl
 
ilCtrlInterface $ctrl
 
ilLanguage $lng
 
ilToolbarGUI $toolbar
 
ilRbacSystem $rbacsystem
 
ilErrorHandling $error
 
ilMailTemplateService $service
 
GlobalHttpState $http
 
Refinery $refinery
 
Factory $ui_factory
 
Renderer $ui_renderer
 

Private Member Functions

 isEditingAllowed ()
 
 executeTableActionCommand ()
 
 showTemplatesCommand ()
 
 insertTemplateCommand ()
 
 showInsertTemplateFormCommand (?ilPropertyFormGUI $form=null)
 
 updateTemplateCommand ()
 
 showEditTemplateForm (?ilPropertyFormGUI $form=null)
 
 populateFormWithTemplate (ilPropertyFormGUI $form, ilMailTemplate $template)
 
 confirmDeleteTemplate ()
 
 getAjaxPlaceholdersByIdCommand ()
 
 getTemplateForm (?ilMailTemplate $template=null)
 
 setAsContextDefault ()
 

Detailed Description

@ilCtrl_isCalledBy ilMailTemplateGUI: ilObjMailGUI

Definition at line 30 of file class.ilMailTemplateGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilMailTemplateGUI::__construct ( protected ilObject  $parent_object,
?ilGlobalTemplateInterface  $tpl = null,
?ilCtrlInterface  $ctrl = null,
?ilLanguage  $lng = null,
?ilToolbarGUI  $toolbar = null,
?ilRbacSystem  $rbacsystem = null,
?ilErrorHandling  $error = null,
?GlobalHttpState  $http = null,
?Factory  $ui_factory = null,
?Renderer  $ui_renderer = null,
?ilMailTemplateService  $template_service = null 
)

Definition at line 45 of file class.ilMailTemplateGUI.php.

57 {
58 global $DIC;
59 $this->tpl = $tpl ?? $DIC->ui()->mainTemplate();
60 $this->ctrl = $ctrl ?? $DIC->ctrl();
61 $this->lng = $lng ?? $DIC->language();
62 $this->toolbar = $toolbar ?? $DIC->toolbar();
63 $this->rbacsystem = $rbacsystem ?? $DIC->rbac()->system();
64 $this->error = $error ?? $DIC['ilErr'];
65 $this->http = $http ?? $DIC->http();
66 $this->refinery = $DIC->refinery();
67 $this->ui_factory = $ui_factory ?? $DIC->ui()->factory();
68 $this->ui_renderer = $ui_renderer ?? $DIC->ui()->renderer();
69 $this->service = $template_service ?? $DIC->mail()->textTemplates();
70
71 $this->lng->loadLanguageModule('meta');
72 }
error(string $a_errmsg)
ilGlobalTemplateInterface $tpl
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26

References $DIC, $rbacsystem, $tpl, $ui_factory, $ui_renderer, ILIAS\Repository\ctrl(), error(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and ILIAS\Repository\toolbar().

+ Here is the call graph for this function:

Member Function Documentation

◆ confirmDeleteTemplate()

ilMailTemplateGUI::confirmDeleteTemplate ( )
private

Definition at line 350 of file class.ilMailTemplateGUI.php.

350 : void
351 {
352 if (!$this->isEditingAllowed()) {
353 $this->error->raiseError($this->lng->txt('msg_no_perm_write'), $this->error->WARNING);
354 }
355
356 $template_ids = [];
357 if ($this->http->wrapper()->query()->has('mail_template_tpl_ids')) {
358 $template_ids = $this->http->wrapper()->query()->retrieve(
359 'mail_template_tpl_ids',
360 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string())
361 );
362 if ($template_ids === ['ALL_OBJECTS']) {
363 $template_ids = array_map(
364 static fn(array $template): int => (int) ($template['tpl_id'] ?? 0),
365 $this->service->listAllTemplatesAsArray()
366 );
367 } else {
368 $template_ids = $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
369 ->transform($template_ids);
370 }
371 }
372
373 if (count($template_ids) === 0) {
374 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_FAILURE, $this->lng->txt('select_one'));
375 $this->showTemplatesCommand();
376 return;
377 }
378
379 $confirm = new ilConfirmationGUI();
380 $confirm->setFormAction($this->ctrl->getFormAction($this, 'deleteTemplate'));
381
382 $confirm->setHeaderText($this->lng->txt('mail_tpl_sure_delete_entries'));
383 if (count($template_ids) === 1) {
384 $confirm->setHeaderText($this->lng->txt('mail_tpl_sure_delete_entry'));
385 }
386
387 $confirm->setConfirm($this->lng->txt('confirm'), 'deleteTemplate');
388 $confirm->setCancel($this->lng->txt('cancel'), 'showTemplates');
389
390 foreach ($template_ids as $template_id) {
391 $template = $this->service->loadTemplateForId($template_id);
392 $confirm->addItem('tpl_id[]', (string) $template_id, $template->getTitle());
393 }
394
395 $this->tpl->setContent($confirm->getHTML());
396 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References ILIAS\Repository\ctrl(), error(), ILIAS\FileDelivery\http(), isEditingAllowed(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and showTemplatesCommand().

Referenced by executeTableActionCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteTemplateCommand()

ilMailTemplateGUI::deleteTemplateCommand ( )
protected

Definition at line 398 of file class.ilMailTemplateGUI.php.

398 : void
399 {
400 if (!$this->isEditingAllowed()) {
401 $this->error->raiseError($this->lng->txt('msg_no_perm_write'), $this->error->WARNING);
402 }
403
404 $template_ids = [];
405 if ($this->http->wrapper()->post()->has('tpl_id')) {
406 $template_ids = $this->http->wrapper()->post()->retrieve(
407 'tpl_id',
408 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
409 );
410 }
411 if (count($template_ids) === 0) {
412 $template_id = 0;
413 if ($this->http->wrapper()->query()->has('tpl_id')) {
414 $template_id = $this->http->wrapper()->query()->retrieve('tpl_id', $this->refinery->kindlyTo()->int());
415 }
416 $template_ids = [$template_id];
417 }
418
419 if (count($template_ids) === 0) {
420 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_FAILURE, $this->lng->txt('select_one'));
421 $this->showTemplatesCommand();
422 return;
423 }
424
425 $this->service->deleteTemplatesByIds($template_ids);
426
427 if (count($template_ids) === 1) {
428 $this->tpl->setOnScreenMessage(
429 $this->tpl::MESSAGE_TYPE_SUCCESS,
430 $this->lng->txt('mail_tpl_deleted_s'),
431 true
432 );
433 } else {
434 $this->tpl->setOnScreenMessage(
435 $this->tpl::MESSAGE_TYPE_SUCCESS,
436 $this->lng->txt('mail_tpl_deleted_p'),
437 true
438 );
439 }
440 $this->ctrl->redirect($this, 'showTemplates');
441 }

References ILIAS\Repository\ctrl(), error(), ILIAS\FileDelivery\http(), isEditingAllowed(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and showTemplatesCommand().

+ Here is the call graph for this function:

◆ executeCommand()

ilMailTemplateGUI::executeCommand ( )

Definition at line 91 of file class.ilMailTemplateGUI.php.

91 : void
92 {
93 $cmd = $this->ctrl->getCmd();
94 if (!$cmd || !method_exists($this, $cmd . 'Command')) {
95 $cmd = 'showTemplates';
96 }
97 $verified_command = $cmd . 'Command';
98
99 $this->$verified_command();
100 }

References ILIAS\Repository\ctrl().

+ Here is the call graph for this function:

◆ executeTableActionCommand()

ilMailTemplateGUI::executeTableActionCommand ( )
private

Definition at line 102 of file class.ilMailTemplateGUI.php.

102 : void
103 {
104 $action = $this->http->wrapper()->query()->retrieve(
105 'mail_template_table_action',
106 $this->refinery->kindlyTo()->string()
107 );
108
109 match ($action) {
110 'showEditTemplateForm' => $this->showEditTemplateForm(),
111 'confirmDeleteTemplate' => $this->confirmDeleteTemplate(),
112 'unsetAsContextDefault' => $this->unsetAsContextDefault(),
113 'setAsContextDefault' => $this->setAsContextDefault(),
114 default => $this->ctrl->redirect($this, 'showTemplates'),
115 };
116 }
showEditTemplateForm(?ilPropertyFormGUI $form=null)

References confirmDeleteTemplate(), ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), ILIAS\Repository\refinery(), setAsContextDefault(), showEditTemplateForm(), and unsetAsContextDefault().

+ Here is the call graph for this function:

◆ getAjaxPlaceholdersByIdCommand()

ilMailTemplateGUI::getAjaxPlaceholdersByIdCommand ( )
private

Definition at line 443 of file class.ilMailTemplateGUI.php.

443 : void
444 {
445 $trigger_value = '';
446 if ($this->http->wrapper()->query()->has('triggerValue')) {
447 $trigger_value = $this->http->wrapper()->query()->retrieve(
448 'triggerValue',
449 $this->refinery->kindlyTo()->string()
450 );
451 }
452 $context_id = ilUtil::stripSlashes($trigger_value);
453
454 $placeholders = new ilManualPlaceholderInputGUI(
455 $this->lng->txt('mail_form_placeholders_label'),
456 'm_placeholders',
457 'm_message'
458 );
459 $placeholders->setInstructionText($this->lng->txt('mail_nacc_use_placeholder'));
460 try {
461 $placeholders->setAdviseText(sprintf($this->lng->txt('placeholders_advise'), '<br />'));
462 } catch (Throwable) {
463 $placeholders->setAdviseText($this->lng->txt('placeholders_advise'));
464 }
465
467 foreach ($context->getPlaceholders() as $value) {
468 $placeholders->addPlaceholder($value['placeholder'], $value['label']);
469 }
470
471 $placeholders->render(true);
472 }
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
$context
Definition: webdav.php:31

References $context, ilMailTemplateContextService\getTemplateContextById(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and ilUtil\stripSlashes().

+ Here is the call graph for this function:

◆ getSafePostCommands()

ilMailTemplateGUI::getSafePostCommands ( )

This method must return a list of safe POST commands.

Safe post commands returned by this method will no longer be CSRF protected and will NOT be appended by an ilCtrlToken.

Returns
string[]

Implements ilCtrlSecurityInterface.

Definition at line 86 of file class.ilMailTemplateGUI.php.

86 : array
87 {
88 return [];
89 }

◆ getTemplateForm()

ilMailTemplateGUI::getTemplateForm ( ?ilMailTemplate  $template = null)
private

Definition at line 474 of file class.ilMailTemplateGUI.php.

475 {
476 $form = new ilPropertyFormGUI();
477
478 $title = new ilTextInputGUI($this->lng->txt('mail_template_title'), 'title');
479 $title->setRequired(true);
480 $title->setDisabled(!$this->isEditingAllowed());
481 $form->addItem($title);
482
483 $context = new ilRadioGroupInputGUI($this->lng->txt('mail_template_context'), 'context');
484 $context->setDisabled(!$this->isEditingAllowed());
486
487 if (count($contexts) <= 1) {
488 $this->tpl->setOnScreenMessage(
489 $this->tpl::MESSAGE_TYPE_FAILURE,
490 $this->lng->txt('mail_template_no_context_available'),
491 true
492 );
493 $this->ctrl->redirect($this, 'showTemplates');
494 }
495
496 $context_sort = [];
497 $context_options = [];
498 $generic_context = new ilMailTemplateGenericContext();
499 foreach ($contexts as $ctx) {
500 if ($ctx->getId() !== $generic_context->getId()) {
501 $context_options[$ctx->getId()] = $ctx;
502 $context_sort[$ctx->getId()] = $ctx->getTitle();
503 }
504 }
505 asort($context_sort);
506 $first = null;
507 foreach (array_keys($context_sort) as $id) {
508 $ctx = $context_options[$id];
509 $option = new ilRadioOption($ctx->getTitle(), $ctx->getId());
510 $option->setInfo($ctx->getDescription());
511 $context->addOption($option);
512
513 if (!$first) {
514 $first = $id;
515 }
516 }
517 $context->setValue($first);
518 $context->setRequired(true);
520
521 $hidden = new ilHiddenInputGUI('lang');
522 $hidden->setValue($this->lng->getLangKey());
523 $form->addItem($hidden);
524
525 $subject = new ilTextInputGUI($this->lng->txt('subject'), 'm_subject');
526 $subject->setDisabled(!$this->isEditingAllowed());
527 $subject->setSize(50);
528 $form->addItem($subject);
529
530 $message = new ilTextAreaInputGUI($this->lng->txt('message'), 'm_message');
531 $message->setDisabled(!$this->isEditingAllowed());
532 $message->setRequired(true);
533 $message->setCols(60);
534 $message->setRows(10);
536
537 $placeholders = new ilManualPlaceholderInputGUI(
538 $this->lng->txt('mail_form_placeholders_label'),
539 'm_placeholders',
540 'm_message'
541 );
542 $placeholders->setDisabled(!$this->isEditingAllowed());
543 $placeholders->setInstructionText($this->lng->txt('mail_nacc_use_placeholder'));
544 try {
545 $placeholders->setAdviseText(sprintf($this->lng->txt('placeholders_advise'), '<br />'));
546 } catch (Throwable) {
547 $placeholders->setAdviseText($this->lng->txt('placeholders_advise'));
548 }
549 $placeholders->supportsRerenderSignal(
550 'context',
551 $this->ctrl->getLinkTarget($this, 'getAjaxPlaceholdersById', '', true)
552 );
553 if ($template === null) {
554 $context_id = $generic_context->getId();
555 } else {
556 $context_id = $template->getContext();
557 }
559 foreach ($context->getPlaceholders() as $value) {
560 $placeholders->addPlaceholder($value['placeholder'], $value['label']);
561 }
562 $form->addItem($placeholders);
563 if ($template instanceof ilMailTemplate && $template->getTplId() > 0) {
564 $id = new ilHiddenInputGUI('tpl_id');
565 $form->addItem($id);
566
567 $form->setTitle($this->lng->txt('mail_edit_tpl'));
568 $form->setFormAction($this->ctrl->getFormAction($this, 'updateTemplate'));
569
570 if ($this->isEditingAllowed()) {
571 $form->addCommandButton('updateTemplate', $this->lng->txt('save'));
572 }
573 } else {
574 $form->setTitle($this->lng->txt('mail_create_tpl'));
575 $form->setFormAction($this->ctrl->getFormAction($this, 'insertTemplate'));
576
577 if ($this->isEditingAllowed()) {
578 $form->addCommandButton('insertTemplate', $this->lng->txt('save'));
579 }
580 }
581
582 if ($this->isEditingAllowed()) {
583 $form->addCommandButton('showTemplates', $this->lng->txt('cancel'));
584 } else {
585 $form->addCommandButton('showTemplates', $this->lng->txt('back'));
586 }
587
588 return $form;
589 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
setFormAction(string $a_formaction)
This class represents a hidden form property in a property form.
static getTemplateContexts(?array $a_id=null)
Returns an array of mail template contexts, the key of each entry matches its id.
This class represents a property form user interface.
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a text area property in a property form.
This class represents a text property in a property form.
$message
Definition: xapiexit.php:31

References $context, $form, $id, $message, ilPropertyFormGUI\addCommandButton(), ilPropertyFormGUI\addItem(), ILIAS\Repository\ctrl(), ilMailTemplateContextService\getTemplateContextById(), ilMailTemplateContextService\getTemplateContexts(), ilMailTemplate\getTplId(), isEditingAllowed(), ILIAS\Repository\lng(), ilFormGUI\setFormAction(), and ilPropertyFormGUI\setTitle().

Referenced by insertTemplateCommand(), showEditTemplateForm(), showInsertTemplateFormCommand(), and updateTemplateCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUnsafeGetCommands()

ilMailTemplateGUI::getUnsafeGetCommands ( )

This method must return a list of unsafe GET commands.

Unsafe get commands returned by this method will now be CSRF protected, which means an ilCtrlToken is appended each time a link-target is generated to the class implementing this interface with a command from that list.

Tokens will be validated in

See also
ilCtrlInterface::getCmd(), whereas the fallback command will be used if the CSRF validation fails.
Returns
string[]

Implements ilCtrlSecurityInterface.

Definition at line 79 of file class.ilMailTemplateGUI.php.

79 : array
80 {
81 return [
82 'executeTableAction',
83 ];
84 }

◆ insertTemplateCommand()

ilMailTemplateGUI::insertTemplateCommand ( )
private

Definition at line 152 of file class.ilMailTemplateGUI.php.

152 : void
153 {
154 if (!$this->isEditingAllowed()) {
155 $this->error->raiseError($this->lng->txt('msg_no_perm_write'), $this->error->WARNING);
156 }
157
158 $form = $this->getTemplateForm();
159
160 if (!$form->checkInput()) {
163 return;
164 }
165
166 $generic_context = new ilMailTemplateGenericContext();
167 if ($form->getInput('context') === $generic_context->getId()) {
168 $form->getItemByPostVar('context')->setAlert(
169 $this->lng->txt('mail_template_no_valid_context')
170 );
173 return;
174 }
175
176 try {
177 $this->service->createNewTemplate(
179 $form->getInput('title'),
180 $form->getInput('m_subject'),
181 $form->getInput('m_message'),
182 $form->getInput('lang')
183 );
184
185 $this->tpl->setOnScreenMessage(
186 $this->tpl::MESSAGE_TYPE_SUCCESS,
187 $this->lng->txt('saved_successfully'),
188 true
189 );
190 $this->ctrl->redirect($this, 'showTemplates');
191 } catch (\ILIAS\Mail\Templates\TemplateSubjectSyntaxException) {
192 $form->getItemByPostVar('m_subject')->setAlert($this->lng->txt('mail_template_invalid_tpl_syntax'));
193 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_FAILURE, $this->lng->txt('form_input_not_valid'));
194 } catch (\ILIAS\Mail\Templates\TemplateMessageSyntaxException) {
195 $form->getItemByPostVar('m_message')->setAlert($this->lng->txt('mail_template_invalid_tpl_syntax'));
196 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_FAILURE, $this->lng->txt('form_input_not_valid'));
197 } catch (Exception) {
198 $form->getItemByPostVar('context')->setAlert(
199 $this->lng->txt('mail_template_no_valid_context')
200 );
201 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_FAILURE, $this->lng->txt('form_input_not_valid'));
202 }
203
206 }
showInsertTemplateFormCommand(?ilPropertyFormGUI $form=null)
getTemplateForm(?ilMailTemplate $template=null)
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
getItemByPostVar(string $a_post_var)
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
RFC 822 Email address list validation Utility.

References $form, ilPropertyFormGUI\checkInput(), ILIAS\Repository\ctrl(), error(), ilPropertyFormGUI\getInput(), ilPropertyFormGUI\getItemByPostVar(), ilMailTemplateContextService\getTemplateContextById(), getTemplateForm(), isEditingAllowed(), ILIAS\Repository\lng(), ilPropertyFormGUI\setValuesByPost(), and showInsertTemplateFormCommand().

+ Here is the call graph for this function:

◆ isEditingAllowed()

ilMailTemplateGUI::isEditingAllowed ( )
private

Definition at line 74 of file class.ilMailTemplateGUI.php.

74 : bool
75 {
76 return $this->rbacsystem->checkAccess('write', $this->parent_object->getRefId());
77 }

Referenced by confirmDeleteTemplate(), deleteTemplateCommand(), getTemplateForm(), insertTemplateCommand(), setAsContextDefault(), showTemplatesCommand(), unsetAsContextDefault(), and updateTemplateCommand().

+ Here is the caller graph for this function:

◆ populateFormWithTemplate()

ilMailTemplateGUI::populateFormWithTemplate ( ilPropertyFormGUI  $form,
ilMailTemplate  $template 
)
private

Definition at line 338 of file class.ilMailTemplateGUI.php.

338 : void
339 {
341 'tpl_id' => $template->getTplId(),
342 'title' => $template->getTitle(),
343 'context' => $template->getContext(),
344 'lang' => $template->getLang(),
345 'm_subject' => $template->getSubject(),
346 'm_message' => $template->getMessage(),
347 ]);
348 }
setValuesByArray(array $a_values, bool $a_restrict_to_value_keys=false)

References $form, ilMailTemplate\getContext(), ilMailTemplate\getLang(), ilMailTemplate\getMessage(), ilMailTemplate\getSubject(), ilMailTemplate\getTitle(), ilMailTemplate\getTplId(), and ilPropertyFormGUI\setValuesByArray().

Referenced by showEditTemplateForm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setAsContextDefault()

ilMailTemplateGUI::setAsContextDefault ( )
private

Definition at line 630 of file class.ilMailTemplateGUI.php.

630 : void
631 {
632 if (!$this->isEditingAllowed()) {
633 $this->error->raiseError($this->lng->txt('msg_no_perm_write'), $this->error->WARNING);
634 }
635
636 $template_id = 0;
637 if ($this->http->wrapper()->query()->has('mail_template_tpl_ids')) {
638 $template_id = $this->http->wrapper()->query()->retrieve(
639 'mail_template_tpl_ids',
640 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
641 )[0];
642 }
643
644 if (!is_numeric($template_id) || $template_id < 1) {
645 $this->tpl->setOnScreenMessage(
646 $this->tpl::MESSAGE_TYPE_FAILURE,
647 $this->lng->txt('mail_template_missing_id')
648 );
649 $this->showTemplatesCommand();
650 return;
651 }
652
653 try {
654 $template = $this->service->loadTemplateForId((int) $template_id);
655 $this->service->setAsContextDefault($template);
656 } catch (Exception) {
657 $this->tpl->setOnScreenMessage(
658 $this->tpl::MESSAGE_TYPE_FAILURE,
659 $this->lng->txt('mail_template_missing_id')
660 );
661 $this->showTemplatesCommand();
662 return;
663 }
664
665 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->lng->txt('saved_successfully'), true);
666 $this->ctrl->redirect($this, 'showTemplates');
667 }

References ILIAS\Repository\ctrl(), error(), ILIAS\FileDelivery\http(), isEditingAllowed(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and showTemplatesCommand().

Referenced by executeTableActionCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showEditTemplateForm()

ilMailTemplateGUI::showEditTemplateForm ( ?ilPropertyFormGUI  $form = null)
private

Definition at line 301 of file class.ilMailTemplateGUI.php.

301 : void
302 {
303 if (!($form instanceof ilPropertyFormGUI)) {
304 $template_id = 0;
305 if ($this->http->wrapper()->query()->has('mail_template_tpl_ids')) {
306 $template_id = $this->http->wrapper()->query()->retrieve(
307 'mail_template_tpl_ids',
308 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
309 )[0];
310 }
311
312 if (!is_numeric($template_id) || $template_id < 1) {
313 $this->tpl->setOnScreenMessage(
314 $this->tpl::MESSAGE_TYPE_FAILURE,
315 $this->lng->txt('mail_template_missing_id')
316 );
317 $this->showTemplatesCommand();
318 return;
319 }
320
321 try {
322 $template = $this->service->loadTemplateForId((int) $template_id);
323 $form = $this->getTemplateForm($template);
324 $this->populateFormWithTemplate($form, $template);
325 } catch (Exception) {
326 $this->tpl->setOnScreenMessage(
327 $this->tpl::MESSAGE_TYPE_FAILURE,
328 $this->lng->txt('mail_template_missing_id')
329 );
330 $this->showTemplatesCommand();
331 return;
332 }
333 }
334
335 $this->tpl->setContent($form->getHTML());
336 }
populateFormWithTemplate(ilPropertyFormGUI $form, ilMailTemplate $template)

References $form, ilPropertyFormGUI\getHTML(), getTemplateForm(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), populateFormWithTemplate(), ILIAS\Repository\refinery(), and showTemplatesCommand().

Referenced by executeTableActionCommand(), and updateTemplateCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showInsertTemplateFormCommand()

ilMailTemplateGUI::showInsertTemplateFormCommand ( ?ilPropertyFormGUI  $form = null)
private

Definition at line 208 of file class.ilMailTemplateGUI.php.

208 : void
209 {
210 if (!($form instanceof ilPropertyFormGUI)) {
211 $form = $this->getTemplateForm();
212 }
213
214 $this->tpl->setContent($form->getHTML());
215 }

References $form, ilPropertyFormGUI\getHTML(), and getTemplateForm().

Referenced by insertTemplateCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showTemplatesCommand()

ilMailTemplateGUI::showTemplatesCommand ( )
private

Definition at line 118 of file class.ilMailTemplateGUI.php.

118 : void
119 {
121 if (count($contexts) <= 1) {
122 $this->tpl->setOnScreenMessage(
123 $this->tpl::MESSAGE_TYPE_FAILURE,
124 $this->lng->txt('mail_template_no_context_available')
125 );
126 } elseif ($this->isEditingAllowed()) {
127 $this->toolbar->addComponent(
128 $this->ui_factory->button()->standard(
129 $this->lng->txt('mail_new_template'),
130 $this->ctrl->getLinkTarget($this, 'showInsertTemplateForm')
131 )
132 );
133 }
134
135 $table_uri = (new DataFactory())->uri(
136 ILIAS_HTTP_PATH . '/'
137 . $this->ctrl->getLinkTarget($this, 'executeTableAction')
138 );
139
140 $tbl = new ilMailTemplateTable(
141 $this->http->request(),
142 $this->lng,
143 $this->ui_factory,
144 $table_uri,
145 $this->service,
146 !$this->isEditingAllowed()
147 );
148
149 $this->tpl->setContent($this->ui_renderer->render($tbl->getComponent()));
150 }

References ILIAS\Repository\ctrl(), ilMailTemplateContextService\getTemplateContexts(), ILIAS\FileDelivery\http(), isEditingAllowed(), ILIAS\Repository\lng(), and ILIAS\Repository\toolbar().

Referenced by confirmDeleteTemplate(), deleteTemplateCommand(), setAsContextDefault(), showEditTemplateForm(), unsetAsContextDefault(), and updateTemplateCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unsetAsContextDefault()

ilMailTemplateGUI::unsetAsContextDefault ( )

Definition at line 591 of file class.ilMailTemplateGUI.php.

591 : void
592 {
593 if (!$this->isEditingAllowed()) {
594 $this->error->raiseError($this->lng->txt('msg_no_perm_write'), $this->error->WARNING);
595 }
596
597 $template_id = 0;
598 if ($this->http->wrapper()->query()->has('mail_template_tpl_ids')) {
599 $template_id = $this->http->wrapper()->query()->retrieve(
600 'mail_template_tpl_ids',
601 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
602 )[0];
603 }
604
605 if (!is_numeric($template_id) || $template_id < 1) {
606 $this->tpl->setOnScreenMessage(
607 $this->tpl::MESSAGE_TYPE_FAILURE,
608 $this->lng->txt('mail_template_missing_id')
609 );
610 $this->showTemplatesCommand();
611 return;
612 }
613
614 try {
615 $template = $this->service->loadTemplateForId((int) $template_id);
616 $this->service->unsetAsContextDefault($template);
617 } catch (Exception) {
618 $this->tpl->setOnScreenMessage(
619 $this->tpl::MESSAGE_TYPE_FAILURE,
620 $this->lng->txt('mail_template_missing_id')
621 );
622 $this->showTemplatesCommand();
623 return;
624 }
625
626 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->lng->txt('saved_successfully'), true);
627 $this->ctrl->redirect($this, 'showTemplates');
628 }

References ILIAS\Repository\ctrl(), error(), ILIAS\FileDelivery\http(), isEditingAllowed(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and showTemplatesCommand().

Referenced by executeTableActionCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateTemplateCommand()

ilMailTemplateGUI::updateTemplateCommand ( )
private

Definition at line 217 of file class.ilMailTemplateGUI.php.

217 : void
218 {
219 if (!$this->isEditingAllowed()) {
220 $this->error->raiseError($this->lng->txt('msg_no_perm_write'), $this->error->WARNING);
221 }
222
223 $template_id = 0;
224 if ($this->http->wrapper()->post()->has('tpl_id')) {
225 $template_id = $this->http->wrapper()->post()->retrieve('tpl_id', $this->refinery->kindlyTo()->int());
226 }
227
228 if (!is_numeric($template_id) || $template_id < 1) {
229 $this->tpl->setOnScreenMessage(
230 $this->tpl::MESSAGE_TYPE_FAILURE,
231 $this->lng->txt('mail_template_missing_id')
232 );
233 $this->showTemplatesCommand();
234 return;
235 }
236
237 try {
238 $form = $this->getTemplateForm();
239 if (!$form->checkInput()) {
242 return;
243 }
244
245 $generic_context = new ilMailTemplateGenericContext();
246 if ($form->getInput('context') === $generic_context->getId()) {
247 $form->getItemByPostVar('context')->setAlert(
248 $this->lng->txt('mail_template_no_valid_context')
249 );
252 return;
253 }
254
255 try {
256 $this->service->modifyExistingTemplate(
257 (int) $template_id,
259 $form->getInput('title'),
260 $form->getInput('m_subject'),
261 $form->getInput('m_message'),
262 $form->getInput('lang')
263 );
264
265 $this->tpl->setOnScreenMessage(
266 $this->tpl::MESSAGE_TYPE_SUCCESS,
267 $this->lng->txt('saved_successfully'),
268 true
269 );
270 $this->ctrl->redirect($this, 'showTemplates');
271 } catch (OutOfBoundsException) {
272 $this->tpl->setOnScreenMessage(
273 $this->tpl::MESSAGE_TYPE_FAILURE,
274 $this->lng->txt('mail_template_missing_id')
275 );
276 } catch (\ILIAS\Mail\Templates\TemplateSubjectSyntaxException) {
277 $form->getItemByPostVar('m_subject')->setAlert($this->lng->txt('mail_template_invalid_tpl_syntax'));
278 } catch (\ILIAS\Mail\Templates\TemplateMessageSyntaxException) {
279 $form->getItemByPostVar('m_message')->setAlert($this->lng->txt('mail_template_invalid_tpl_syntax'));
280 } catch (Exception) {
281 $form->getItemByPostVar('context')->setAlert(
282 $this->lng->txt('mail_template_no_valid_context')
283 );
284 $this->tpl->setOnScreenMessage(
285 $this->tpl::MESSAGE_TYPE_FAILURE,
286 $this->lng->txt('form_input_not_valid')
287 );
288 }
289
292 } catch (Exception) {
293 $this->tpl->setOnScreenMessage(
294 $this->tpl::MESSAGE_TYPE_FAILURE,
295 $this->lng->txt('mail_template_missing_id')
296 );
297 $this->showTemplatesCommand();
298 }
299 }

References $form, ilPropertyFormGUI\checkInput(), ILIAS\Repository\ctrl(), error(), ilPropertyFormGUI\getInput(), ilPropertyFormGUI\getItemByPostVar(), ilMailTemplateContextService\getTemplateContextById(), getTemplateForm(), ILIAS\FileDelivery\http(), isEditingAllowed(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), ilPropertyFormGUI\setValuesByPost(), showEditTemplateForm(), and showTemplatesCommand().

+ Here is the call graph for this function:

Field Documentation

◆ $ctrl

ilCtrlInterface ilMailTemplateGUI::$ctrl
protected

Definition at line 34 of file class.ilMailTemplateGUI.php.

◆ $error

ilErrorHandling ilMailTemplateGUI::$error
protected

Definition at line 38 of file class.ilMailTemplateGUI.php.

◆ $form

◆ $http

GlobalHttpState ilMailTemplateGUI::$http
protected

Definition at line 40 of file class.ilMailTemplateGUI.php.

◆ $lng

ilLanguage ilMailTemplateGUI::$lng
protected

Definition at line 35 of file class.ilMailTemplateGUI.php.

◆ $rbacsystem

ilRbacSystem ilMailTemplateGUI::$rbacsystem
protected

Definition at line 37 of file class.ilMailTemplateGUI.php.

Referenced by __construct().

◆ $refinery

Refinery ilMailTemplateGUI::$refinery
protected

Definition at line 41 of file class.ilMailTemplateGUI.php.

◆ $service

ilMailTemplateService ilMailTemplateGUI::$service
protected

Definition at line 39 of file class.ilMailTemplateGUI.php.

◆ $toolbar

ilToolbarGUI ilMailTemplateGUI::$toolbar
protected

Definition at line 36 of file class.ilMailTemplateGUI.php.

◆ $tpl

ilGlobalTemplateInterface ilMailTemplateGUI::$tpl
protected

Definition at line 33 of file class.ilMailTemplateGUI.php.

Referenced by __construct().

◆ $ui_factory

Factory ilMailTemplateGUI::$ui_factory
protected

Definition at line 42 of file class.ilMailTemplateGUI.php.

Referenced by __construct().

◆ $ui_renderer

Renderer ilMailTemplateGUI::$ui_renderer
protected

Definition at line 43 of file class.ilMailTemplateGUI.php.

Referenced by __construct().


The documentation for this class was generated from the following file: