ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilMailTemplateGUI Class Reference

Class ilMailTemplateGUI. More...

+ Collaboration diagram for ilMailTemplateGUI:

Public Member Functions

 __construct (protected ilObject $parentObject, ilGlobalTemplateInterface $tpl=null, ilCtrlInterface $ctrl=null, ilLanguage $lng=null, ilToolbarGUI $toolbar=null, ilRbacSystem $rbacsystem=null, ilErrorHandling $error=null, GlobalHttpState $http=null, Factory $uiFactory=null, Renderer $uiRenderer=null, ilMailTemplateService $templateService=null)
 
 executeCommand ()
 
 getAjaxPlaceholdersById ()
 
 unsetAsContextDefault ()
 
 setAsContextDefault ()
 

Protected Member Functions

 showTemplates ()
 
 insertTemplate ()
 
 showInsertTemplateForm (ilPropertyFormGUI $form=null)
 
 updateTemplate ()
 
 showEditTemplateForm (ilPropertyFormGUI $form=null)
 
 populateFormWithTemplate (ilPropertyFormGUI $form, ilMailTemplate $template)
 
 confirmDeleteTemplate ()
 
 deleteTemplate ()
 
 getTemplateForm (ilMailTemplate $template=null)
 

Protected Attributes

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

Private Member Functions

 isEditingAllowed ()
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilMailTemplateGUI::__construct ( protected ilObject  $parentObject,
ilGlobalTemplateInterface  $tpl = null,
ilCtrlInterface  $ctrl = null,
ilLanguage  $lng = null,
ilToolbarGUI  $toolbar = null,
ilRbacSystem  $rbacsystem = null,
ilErrorHandling  $error = null,
GlobalHttpState  $http = null,
Factory  $uiFactory = null,
Renderer  $uiRenderer = null,
ilMailTemplateService  $templateService = null 
)

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

References $DIC, ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and ILIAS\Repository\toolbar().

59  {
60  global $DIC;
61  $this->tpl = $tpl ?? $DIC->ui()->mainTemplate();
62  $this->ctrl = $ctrl ?? $DIC->ctrl();
63  $this->lng = $lng ?? $DIC->language();
64  $this->toolbar = $toolbar ?? $DIC->toolbar();
65  $this->rbacsystem = $rbacsystem ?? $DIC->rbac()->system();
66  $this->error = $error ?? $DIC['ilErr'];
67  $this->http = $http ?? $DIC->http();
68  $this->refinery = $DIC->refinery();
69  $this->uiFactory = $uiFactory ?? $DIC->ui()->factory();
70  $this->uiRenderer = $uiRenderer ?? $DIC->ui()->renderer();
71  $this->service = $templateService ?? $DIC->mail()->textTemplates();
72 
73  $this->lng->loadLanguageModule('meta');
74  }
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:25
+ Here is the call graph for this function:

Member Function Documentation

◆ confirmDeleteTemplate()

ilMailTemplateGUI::confirmDeleteTemplate ( )
protected

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

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

293  : void
294  {
295  if (!$this->isEditingAllowed()) {
296  $this->error->raiseError($this->lng->txt('msg_no_perm_write'), $this->error->WARNING);
297  }
298 
299  $templateIds = [];
300  if ($this->http->wrapper()->post()->has('tpl_id')) {
301  $templateIds = $this->http->wrapper()->post()->retrieve(
302  'tpl_id',
303  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
304  );
305  }
306  if (count($templateIds) === 0 && $this->http->wrapper()->query()->has('tpl_id')) {
307  $templateIds = [$this->http->wrapper()->query()->retrieve(
308  'tpl_id',
309  $this->refinery->kindlyTo()->int()
310  )];
311  }
312 
313  if (0 === count($templateIds)) {
314  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'));
315  $this->showTemplates();
316  return;
317  }
318 
319  $confirm = new ilConfirmationGUI();
320  $confirm->setFormAction($this->ctrl->getFormAction($this, 'deleteTemplate'));
321 
322  $confirm->setHeaderText($this->lng->txt('mail_tpl_sure_delete_entries'));
323  if (1 === count($templateIds)) {
324  $confirm->setHeaderText($this->lng->txt('mail_tpl_sure_delete_entry'));
325  }
326 
327  $confirm->setConfirm($this->lng->txt('confirm'), 'deleteTemplate');
328  $confirm->setCancel($this->lng->txt('cancel'), 'showTemplates');
329 
330  foreach ($templateIds as $templateId) {
331  $template = $this->service->loadTemplateForId($templateId);
332  $confirm->addItem('tpl_id[]', (string) $templateId, $template->getTitle());
333  }
334 
335  $this->tpl->setContent($confirm->getHTML());
336  }
static http()
Fetches the global http state from ILIAS.
+ Here is the call graph for this function:

◆ deleteTemplate()

ilMailTemplateGUI::deleteTemplate ( )
protected

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

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

338  : void
339  {
340  if (!$this->isEditingAllowed()) {
341  $this->error->raiseError($this->lng->txt('msg_no_perm_write'), $this->error->WARNING);
342  }
343 
344  $templateIds = [];
345  if ($this->http->wrapper()->post()->has('tpl_id')) {
346  $templateIds = $this->http->wrapper()->post()->retrieve(
347  'tpl_id',
348  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
349  );
350  }
351  if (count($templateIds) === 0) {
352  $templateId = 0;
353  if ($this->http->wrapper()->query()->has('tpl_id')) {
354  $templateId = $this->http->wrapper()->query()->retrieve('tpl_id', $this->refinery->kindlyTo()->int());
355  }
356  $templateIds = [$templateId];
357  }
358 
359  if (0 === count($templateIds)) {
360  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'));
361  $this->showTemplates();
362  return;
363  }
364 
365  $this->service->deleteTemplatesByIds($templateIds);
366 
367  if (1 === count($templateIds)) {
368  $this->tpl->setOnScreenMessage('success', $this->lng->txt('mail_tpl_deleted_s'), true);
369  } else {
370  $this->tpl->setOnScreenMessage('success', $this->lng->txt('mail_tpl_deleted_p'), true);
371  }
372  $this->ctrl->redirect($this, 'showTemplates');
373  }
static http()
Fetches the global http state from ILIAS.
+ Here is the call graph for this function:

◆ executeCommand()

ilMailTemplateGUI::executeCommand ( )

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

References ILIAS\Repository\ctrl().

81  : void
82  {
83  $cmd = $this->ctrl->getCmd();
84  if (!$cmd || !method_exists($this, $cmd)) {
85  $cmd = 'showTemplates';
86  }
87  $this->$cmd();
88  }
+ Here is the call graph for this function:

◆ getAjaxPlaceholdersById()

ilMailTemplateGUI::getAjaxPlaceholdersById ( )
Exceptions
ilMailException

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

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

378  : void
379  {
380  $triggerValue = '';
381  if ($this->http->wrapper()->query()->has('triggerValue')) {
382  $triggerValue = $this->http->wrapper()->query()->retrieve(
383  'triggerValue',
384  $this->refinery->kindlyTo()->string()
385  );
386  }
387  $contextId = ilUtil::stripSlashes($triggerValue);
388 
389  $placeholders = new ilManualPlaceholderInputGUI(
390  $this->lng->txt('mail_form_placeholders_label'),
391  'm_placeholders',
392  'm_message'
393  );
394  $placeholders->setInstructionText($this->lng->txt('mail_nacc_use_placeholder'));
395  try {
396  $placeholders->setAdviseText(sprintf($this->lng->txt('placeholders_advise'), '<br />'));
397  } catch (Throwable) {
398  $placeholders->setAdviseText($this->lng->txt('placeholders_advise'));
399  }
400 
402  foreach ($context->getPlaceholders() as $value) {
403  $placeholders->addPlaceholder($value['placeholder'], $value['label']);
404  }
405 
406  $placeholders->render(true);
407  }
$context
Definition: webdav.php:31
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
Class ilManualPlaceholderInputGUI.
static http()
Fetches the global http state from ILIAS.
+ Here is the call graph for this function:

◆ getTemplateForm()

ilMailTemplateGUI::getTemplateForm ( ilMailTemplate  $template = null)
protected
Parameters
ilMailTemplate | null$template
Exceptions
ilMailException

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

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

Referenced by insertTemplate(), showEditTemplateForm(), showInsertTemplateForm(), and updateTemplate().

414  {
415  $form = new ilPropertyFormGUI();
416 
417  $title = new ilTextInputGUI($this->lng->txt('mail_template_title'), 'title');
418  $title->setRequired(true);
419  $title->setDisabled(!$this->isEditingAllowed());
420  $form->addItem($title);
421 
422  $context = new ilRadioGroupInputGUI($this->lng->txt('mail_template_context'), 'context');
423  $context->setDisabled(!$this->isEditingAllowed());
425 
426  if (count($contexts) <= 1) {
427  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('mail_template_no_context_available'), true);
428  $this->ctrl->redirect($this, 'showTemplates');
429  }
430 
431  $context_sort = [];
432  $context_options = [];
433  $generic_context = new ilMailTemplateGenericContext();
434  foreach ($contexts as $ctx) {
435  if ($ctx->getId() !== $generic_context->getId()) {
436  $context_options[$ctx->getId()] = $ctx;
437  $context_sort[$ctx->getId()] = $ctx->getTitle();
438  }
439  }
440  asort($context_sort);
441  $first = null;
442  foreach (array_keys($context_sort) as $id) {
443  $ctx = $context_options[$id];
444  $option = new ilRadioOption($ctx->getTitle(), $ctx->getId());
445  $option->setInfo($ctx->getDescription());
446  $context->addOption($option);
447 
448  if (!$first) {
449  $first = $id;
450  }
451  }
452  $context->setValue($first);
453  $context->setRequired(true);
455 
456  $hidden = new ilHiddenInputGUI('lang');
457  $hidden->setValue($this->lng->getLangKey());
458  $form->addItem($hidden);
459 
460  $subject = new ilTextInputGUI($this->lng->txt('subject'), 'm_subject');
461  $subject->setDisabled(!$this->isEditingAllowed());
462  $subject->setSize(50);
463  $form->addItem($subject);
464 
465  $message = new ilTextAreaInputGUI($this->lng->txt('message'), 'm_message');
466  $message->setDisabled(!$this->isEditingAllowed());
467  $message->setRequired(true);
468  $message->setCols(60);
469  $message->setRows(10);
470  $form->addItem($message);
471 
472  $placeholders = new ilManualPlaceholderInputGUI(
473  $this->lng->txt('mail_form_placeholders_label'),
474  'm_placeholders',
475  'm_message'
476  );
477  $placeholders->setDisabled(!$this->isEditingAllowed());
478  $placeholders->setInstructionText($this->lng->txt('mail_nacc_use_placeholder'));
479  try {
480  $placeholders->setAdviseText(sprintf($this->lng->txt('placeholders_advise'), '<br />'));
481  } catch (Throwable) {
482  $placeholders->setAdviseText($this->lng->txt('placeholders_advise'));
483  }
484  $placeholders->supportsRerenderSignal(
485  'context',
486  $this->ctrl->getLinkTarget($this, 'getAjaxPlaceholdersById', '', true)
487  );
488  if ($template === null) {
489  $context_id = $generic_context->getId();
490  } else {
491  $context_id = $template->getContext();
492  }
494  foreach ($context->getPlaceholders() as $value) {
495  $placeholders->addPlaceholder($value['placeholder'], $value['label']);
496  }
497  $form->addItem($placeholders);
498  if ($template instanceof ilMailTemplate && $template->getTplId() > 0) {
499  $id = new ilHiddenInputGUI('tpl_id');
500  $form->addItem($id);
501 
502  $form->setTitle($this->lng->txt('mail_edit_tpl'));
503  $form->setFormAction($this->ctrl->getFormAction($this, 'updateTemplate'));
504 
505  if ($this->isEditingAllowed()) {
506  $form->addCommandButton('updateTemplate', $this->lng->txt('save'));
507  }
508  } else {
509  $form->setTitle($this->lng->txt('mail_create_tpl'));
510  $form->setFormAction($this->ctrl->getFormAction($this, 'insertTemplate'));
511 
512  if ($this->isEditingAllowed()) {
513  $form->addCommandButton('insertTemplate', $this->lng->txt('save'));
514  }
515  }
516 
517  if ($this->isEditingAllowed()) {
518  $form->addCommandButton('showTemplates', $this->lng->txt('cancel'));
519  } else {
520  $form->addCommandButton('showTemplates', $this->lng->txt('back'));
521  }
522 
523  return $form;
524  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$context
Definition: webdav.php:31
setInfo(string $a_info)
Class ilMailTemplate.
Class ilManualPlaceholderInputGUI.
static getTemplateContexts(?array $a_id=null)
Returns an array of mail template contexts, the key of each entry matches its id. ...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a property in a property form.
setFormAction(string $a_formaction)
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
This class represents a text area property in a property form.
setDisabled(bool $a_disabled)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insertTemplate()

ilMailTemplateGUI::insertTemplate ( )
protected
Exceptions
ilMailException

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

References ilPropertyFormGUI\checkInput(), ILIAS\Repository\ctrl(), ILIAS\Survey\Mode\getId(), ilPropertyFormGUI\getInput(), ilPropertyFormGUI\getItemByPostVar(), ilMailTemplateContextService\getTemplateContextById(), getTemplateForm(), isEditingAllowed(), ILIAS\Repository\lng(), ilPropertyFormGUI\setValuesByPost(), and showInsertTemplateForm().

117  : void
118  {
119  if (!$this->isEditingAllowed()) {
120  $this->error->raiseError($this->lng->txt('msg_no_perm_write'), $this->error->WARNING);
121  }
122 
123  $form = $this->getTemplateForm();
124 
125  if (!$form->checkInput()) {
128  return;
129  }
130 
131  $generic_context = new ilMailTemplateGenericContext();
132  if ($form->getInput('context') === $generic_context->getId()) {
133  $form->getItemByPostVar('context')->setAlert(
134  $this->lng->txt('mail_template_no_valid_context')
135  );
138  return;
139  }
140 
141  try {
142  $this->service->createNewTemplate(
144  $form->getInput('title'),
145  $form->getInput('m_subject'),
146  $form->getInput('m_message'),
147  $form->getInput('lang')
148  );
149 
150  $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
151  $this->ctrl->redirect($this, 'showTemplates');
152  } catch (\ILIAS\Mail\Templates\TemplateSubjectSyntaxException) {
153  $form->getItemByPostVar('m_subject')->setAlert($this->lng->txt('mail_template_invalid_tpl_syntax'));
154  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
155  } catch (\ILIAS\Mail\Templates\TemplateMessageSyntaxException) {
156  $form->getItemByPostVar('m_message')->setAlert($this->lng->txt('mail_template_invalid_tpl_syntax'));
157  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
158  } catch (Exception) {
159  $form->getItemByPostVar('context')->setAlert(
160  $this->lng->txt('mail_template_no_valid_context')
161  );
162  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
163  }
164 
167  }
getItemByPostVar(string $a_post_var)
Interface Observer Contains several chained tasks and infos about them.
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-...
RFC 822 Email address list validation Utility.
showInsertTemplateForm(ilPropertyFormGUI $form=null)
+ Here is the call graph for this function:

◆ isEditingAllowed()

ilMailTemplateGUI::isEditingAllowed ( )
private

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

Referenced by confirmDeleteTemplate(), deleteTemplate(), getTemplateForm(), insertTemplate(), setAsContextDefault(), showTemplates(), unsetAsContextDefault(), and updateTemplate().

76  : bool
77  {
78  return $this->rbacsystem->checkAccess('write', $this->parentObject->getRefId());
79  }
+ Here is the caller graph for this function:

◆ populateFormWithTemplate()

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

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

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

Referenced by showEditTemplateForm().

281  : void
282  {
283  $form->setValuesByArray([
284  'tpl_id' => $template->getTplId(),
285  'title' => $template->getTitle(),
286  'context' => $template->getContext(),
287  'lang' => $template->getLang(),
288  'm_subject' => $template->getSubject(),
289  'm_message' => $template->getMessage(),
290  ]);
291  }
setValuesByArray(array $a_values, bool $a_restrict_to_value_keys=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setAsContextDefault()

ilMailTemplateGUI::setAsContextDefault ( )

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

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

556  : void
557  {
558  if (!$this->isEditingAllowed()) {
559  $this->error->raiseError($this->lng->txt('msg_no_perm_write'), $this->error->WARNING);
560  }
561 
562  $templateId = 0;
563  if ($this->http->wrapper()->query()->has('tpl_id')) {
564  $templateId = $this->http->wrapper()->query()->retrieve('tpl_id', $this->refinery->kindlyTo()->int());
565  }
566 
567  if (!is_numeric($templateId) || $templateId < 1) {
568  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('mail_template_missing_id'));
569  $this->showTemplates();
570  return;
571  }
572 
573  try {
574  $template = $this->service->loadTemplateForId((int) $templateId);
575  $this->service->setAsContextDefault($template);
576  } catch (Exception) {
577  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('mail_template_missing_id'));
578  $this->showTemplates();
579  return;
580  }
581 
582  $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
583  $this->ctrl->redirect($this, 'showTemplates');
584  }
static http()
Fetches the global http state from ILIAS.
+ Here is the call graph for this function:

◆ showEditTemplateForm()

ilMailTemplateGUI::showEditTemplateForm ( ilPropertyFormGUI  $form = null)
protected

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

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

Referenced by updateTemplate().

250  : void
251  {
252  if (!($form instanceof ilPropertyFormGUI)) {
253  $templateId = 0;
254  if ($this->http->wrapper()->query()->has('tpl_id')) {
255  $templateId = $this->http->wrapper()->query()->retrieve(
256  'tpl_id',
257  $this->refinery->kindlyTo()->int()
258  );
259  }
260 
261  if (!is_numeric($templateId) || $templateId < 1) {
262  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('mail_template_missing_id'));
263  $this->showTemplates();
264  return;
265  }
266 
267  try {
268  $template = $this->service->loadTemplateForId((int) $templateId);
269  $form = $this->getTemplateForm($template);
270  $this->populateFormWithTemplate($form, $template);
271  } catch (Exception) {
272  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('mail_template_missing_id'));
273  $this->showTemplates();
274  return;
275  }
276  }
277 
278  $this->tpl->setContent($form->getHTML());
279  }
getTemplateForm(ilMailTemplate $template=null)
static http()
Fetches the global http state from ILIAS.
populateFormWithTemplate(ilPropertyFormGUI $form, ilMailTemplate $template)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showInsertTemplateForm()

ilMailTemplateGUI::showInsertTemplateForm ( ilPropertyFormGUI  $form = null)
protected
Parameters
ilPropertyFormGUI | null$form
Exceptions
ilMailException

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

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

Referenced by insertTemplate().

173  : void
174  {
175  if (!($form instanceof ilPropertyFormGUI)) {
176  $form = $this->getTemplateForm();
177  }
178 
179  $this->tpl->setContent($form->getHTML());
180  }
getTemplateForm(ilMailTemplate $template=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showTemplates()

ilMailTemplateGUI::showTemplates ( )
protected

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

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

Referenced by confirmDeleteTemplate(), deleteTemplate(), setAsContextDefault(), showEditTemplateForm(), unsetAsContextDefault(), and updateTemplate().

90  : void
91  {
93  if (count($contexts) <= 1) {
94  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('mail_template_no_context_available'));
95  } elseif ($this->isEditingAllowed()) {
96  $this->toolbar->addComponent($this->uiFactory->button()->standard(
97  $this->lng->txt('mail_new_template'),
98  $this->ctrl->getLinkTarget($this, 'showInsertTemplateForm')
99  ));
100  }
101 
102  $tbl = new ilMailTemplateTableGUI(
103  $this,
104  'showTemplates',
105  $this->uiFactory,
106  $this->uiRenderer,
107  !$this->isEditingAllowed()
108  );
109  $tbl->setData($this->service->listAllTemplatesAsArray());
110 
111  $this->tpl->setContent($tbl->getHTML());
112  }
Class ilMailTemplateTableGUI.
static getTemplateContexts(?array $a_id=null)
Returns an array of mail template contexts, the key of each entry matches its id. ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unsetAsContextDefault()

ilMailTemplateGUI::unsetAsContextDefault ( )

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

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

526  : void
527  {
528  if (!$this->isEditingAllowed()) {
529  $this->error->raiseError($this->lng->txt('msg_no_perm_write'), $this->error->WARNING);
530  }
531 
532  $templateId = 0;
533  if ($this->http->wrapper()->query()->has('tpl_id')) {
534  $templateId = $this->http->wrapper()->query()->retrieve('tpl_id', $this->refinery->kindlyTo()->int());
535  }
536 
537  if (!is_numeric($templateId) || $templateId < 1) {
538  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('mail_template_missing_id'));
539  $this->showTemplates();
540  return;
541  }
542 
543  try {
544  $template = $this->service->loadTemplateForId((int) $templateId);
545  $this->service->unsetAsContextDefault($template);
546  } catch (Exception) {
547  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('mail_template_missing_id'));
548  $this->showTemplates();
549  return;
550  }
551 
552  $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
553  $this->ctrl->redirect($this, 'showTemplates');
554  }
static http()
Fetches the global http state from ILIAS.
+ Here is the call graph for this function:

◆ updateTemplate()

ilMailTemplateGUI::updateTemplate ( )
protected

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

References ilPropertyFormGUI\checkInput(), ILIAS\Repository\ctrl(), ILIAS\Survey\Mode\getId(), ilPropertyFormGUI\getInput(), ilPropertyFormGUI\getItemByPostVar(), ilMailTemplateContextService\getTemplateContextById(), getTemplateForm(), ILIAS\FileDelivery\http(), isEditingAllowed(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), ilPropertyFormGUI\setValuesByPost(), showEditTemplateForm(), and showTemplates().

182  : void
183  {
184  if (!$this->isEditingAllowed()) {
185  $this->error->raiseError($this->lng->txt('msg_no_perm_write'), $this->error->WARNING);
186  }
187 
188  $templateId = 0;
189  if ($this->http->wrapper()->post()->has('tpl_id')) {
190  $templateId = $this->http->wrapper()->post()->retrieve('tpl_id', $this->refinery->kindlyTo()->int());
191  }
192 
193  if (!is_numeric($templateId) || $templateId < 1) {
194  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('mail_template_missing_id'));
195  $this->showTemplates();
196  return;
197  }
198 
199  try {
200  $form = $this->getTemplateForm();
201  if (!$form->checkInput()) {
203  $this->showEditTemplateForm($form);
204  return;
205  }
206 
207  $genericContext = new ilMailTemplateGenericContext();
208  if ($form->getInput('context') === $genericContext->getId()) {
209  $form->getItemByPostVar('context')->setAlert(
210  $this->lng->txt('mail_template_no_valid_context')
211  );
213  $this->showEditTemplateForm($form);
214  return;
215  }
216 
217  try {
218  $this->service->modifyExistingTemplate(
219  (int) $templateId,
221  $form->getInput('title'),
222  $form->getInput('m_subject'),
223  $form->getInput('m_message'),
224  $form->getInput('lang')
225  );
226 
227  $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
228  $this->ctrl->redirect($this, 'showTemplates');
229  } catch (OutOfBoundsException) {
230  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('mail_template_missing_id'));
231  } catch (\ILIAS\Mail\Templates\TemplateSubjectSyntaxException) {
232  $form->getItemByPostVar('m_subject')->setAlert($this->lng->txt('mail_template_invalid_tpl_syntax'));
233  } catch (\ILIAS\Mail\Templates\TemplateMessageSyntaxException) {
234  $form->getItemByPostVar('m_message')->setAlert($this->lng->txt('mail_template_invalid_tpl_syntax'));
235  } catch (Exception) {
236  $form->getItemByPostVar('context')->setAlert(
237  $this->lng->txt('mail_template_no_valid_context')
238  );
239  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
240  }
241 
243  $this->showEditTemplateForm($form);
244  } catch (Exception) {
245  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('mail_template_missing_id'));
246  $this->showTemplates();
247  }
248  }
showEditTemplateForm(ilPropertyFormGUI $form=null)
getItemByPostVar(string $a_post_var)
Interface Observer Contains several chained tasks and infos about them.
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-...
static http()
Fetches the global http state from ILIAS.
RFC 822 Email address list validation Utility.
+ Here is the call graph for this function:

Field Documentation

◆ $ctrl

ilCtrlInterface ilMailTemplateGUI::$ctrl
protected

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

◆ $error

ilErrorHandling ilMailTemplateGUI::$error
protected

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

◆ $form

ilPropertyFormGUI ilMailTemplateGUI::$form
protected

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

Referenced by getTemplateForm().

◆ $http

GlobalHttpState ilMailTemplateGUI::$http
protected

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

◆ $lng

ilLanguage ilMailTemplateGUI::$lng
protected

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

◆ $rbacsystem

ilRbacSystem ilMailTemplateGUI::$rbacsystem
protected

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

◆ $refinery

Refinery ilMailTemplateGUI::$refinery
protected

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

◆ $service

ilMailTemplateService ilMailTemplateGUI::$service
protected

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

◆ $toolbar

ilToolbarGUI ilMailTemplateGUI::$toolbar
protected

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

◆ $tpl

ilGlobalTemplateInterface ilMailTemplateGUI::$tpl
protected

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

◆ $uiFactory

Factory ilMailTemplateGUI::$uiFactory
protected

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

◆ $uiRenderer

Renderer ilMailTemplateGUI::$uiRenderer
protected

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


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