ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
ilMailTemplateGUI Class Reference

ilMailTemplateGUI: ilObjMailGUI More...

+ 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)
 
 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 $ui_factory
 
Renderer $ui_renderer
 

Private Member Functions

 isEditingAllowed ()
 

Detailed Description

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.

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

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  }
ilGlobalTemplateInterface $tpl
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26
+ Here is the call graph for this function:

Member Function Documentation

◆ confirmDeleteTemplate()

ilMailTemplateGUI::confirmDeleteTemplate ( )
protected

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

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

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

◆ deleteTemplate()

ilMailTemplateGUI::deleteTemplate ( )
protected

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

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

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

◆ executeCommand()

ilMailTemplateGUI::executeCommand ( )

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

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

79  : void
80  {
81  $cmd = $this->ctrl->getCmd();
82 
83  if ($this->http->wrapper()->query()->has('mail_template_table_action')) {
84  $cmd = $this->http->wrapper()->query()->retrieve(
85  'mail_template_table_action',
86  $this->refinery->kindlyTo()->string()
87  );
88  }
89  if (!$cmd || !method_exists($this, $cmd)) {
90  $cmd = 'showTemplates';
91  }
92  $this->$cmd();
93  }
static http()
Fetches the global http state from ILIAS.
+ Here is the call graph for this function:

◆ getAjaxPlaceholdersById()

ilMailTemplateGUI::getAjaxPlaceholdersById ( )

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

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

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

◆ getTemplateForm()

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

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

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

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

408  {
409  $form = new ilPropertyFormGUI();
410 
411  $title = new ilTextInputGUI($this->lng->txt('mail_template_title'), 'title');
412  $title->setRequired(true);
413  $title->setDisabled(!$this->isEditingAllowed());
414  $form->addItem($title);
415 
416  $context = new ilRadioGroupInputGUI($this->lng->txt('mail_template_context'), 'context');
417  $context->setDisabled(!$this->isEditingAllowed());
419 
420  if (count($contexts) <= 1) {
421  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('mail_template_no_context_available'), true);
422  $this->ctrl->redirect($this, 'showTemplates');
423  }
424 
425  $context_sort = [];
426  $context_options = [];
427  $generic_context = new ilMailTemplateGenericContext();
428  foreach ($contexts as $ctx) {
429  if ($ctx->getId() !== $generic_context->getId()) {
430  $context_options[$ctx->getId()] = $ctx;
431  $context_sort[$ctx->getId()] = $ctx->getTitle();
432  }
433  }
434  asort($context_sort);
435  $first = null;
436  foreach (array_keys($context_sort) as $id) {
437  $ctx = $context_options[$id];
438  $option = new ilRadioOption($ctx->getTitle(), $ctx->getId());
439  $option->setInfo($ctx->getDescription());
440  $context->addOption($option);
441 
442  if (!$first) {
443  $first = $id;
444  }
445  }
446  $context->setValue($first);
447  $context->setRequired(true);
449 
450  $hidden = new ilHiddenInputGUI('lang');
451  $hidden->setValue($this->lng->getLangKey());
452  $form->addItem($hidden);
453 
454  $subject = new ilTextInputGUI($this->lng->txt('subject'), 'm_subject');
455  $subject->setDisabled(!$this->isEditingAllowed());
456  $subject->setSize(50);
457  $form->addItem($subject);
458 
459  $message = new ilTextAreaInputGUI($this->lng->txt('message'), 'm_message');
460  $message->setDisabled(!$this->isEditingAllowed());
461  $message->setRequired(true);
462  $message->setCols(60);
463  $message->setRows(10);
465 
466  $placeholders = new ilManualPlaceholderInputGUI(
467  $this->lng->txt('mail_form_placeholders_label'),
468  'm_placeholders',
469  'm_message'
470  );
471  $placeholders->setDisabled(!$this->isEditingAllowed());
472  $placeholders->setInstructionText($this->lng->txt('mail_nacc_use_placeholder'));
473  try {
474  $placeholders->setAdviseText(sprintf($this->lng->txt('placeholders_advise'), '<br />'));
475  } catch (Throwable) {
476  $placeholders->setAdviseText($this->lng->txt('placeholders_advise'));
477  }
478  $placeholders->supportsRerenderSignal(
479  'context',
480  $this->ctrl->getLinkTarget($this, 'getAjaxPlaceholdersById', '', true)
481  );
482  if ($template === null) {
483  $context_id = $generic_context->getId();
484  } else {
485  $context_id = $template->getContext();
486  }
488  foreach ($context->getPlaceholders() as $value) {
489  $placeholders->addPlaceholder($value['placeholder'], $value['label']);
490  }
491  $form->addItem($placeholders);
492  if ($template instanceof ilMailTemplate && $template->getTplId() > 0) {
493  $id = new ilHiddenInputGUI('tpl_id');
494  $form->addItem($id);
495 
496  $form->setTitle($this->lng->txt('mail_edit_tpl'));
497  $form->setFormAction($this->ctrl->getFormAction($this, 'updateTemplate'));
498 
499  if ($this->isEditingAllowed()) {
500  $form->addCommandButton('updateTemplate', $this->lng->txt('save'));
501  }
502  } else {
503  $form->setTitle($this->lng->txt('mail_create_tpl'));
504  $form->setFormAction($this->ctrl->getFormAction($this, 'insertTemplate'));
505 
506  if ($this->isEditingAllowed()) {
507  $form->addCommandButton('insertTemplate', $this->lng->txt('save'));
508  }
509  }
510 
511  if ($this->isEditingAllowed()) {
512  $form->addCommandButton('showTemplates', $this->lng->txt('cancel'));
513  } else {
514  $form->addCommandButton('showTemplates', $this->lng->txt('back'));
515  }
516 
517  return $form;
518  }
This class represents an option in a radio group.
$context
Definition: webdav.php:31
setInfo(string $a_info)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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 hidden form property in a property form.
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:23
This class represents a text area property in a property form.
$message
Definition: xapiexit.php:31
setDisabled(bool $a_disabled)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insertTemplate()

ilMailTemplateGUI::insertTemplate ( )
protected

Definition at line 119 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().

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

◆ isEditingAllowed()

ilMailTemplateGUI::isEditingAllowed ( )
private

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

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

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

◆ populateFormWithTemplate()

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

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

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

Referenced by showEditTemplateForm().

279  : void
280  {
281  $form->setValuesByArray([
282  'tpl_id' => $template->getTplId(),
283  'title' => $template->getTitle(),
284  'context' => $template->getContext(),
285  'lang' => $template->getLang(),
286  'm_subject' => $template->getSubject(),
287  'm_message' => $template->getMessage(),
288  ]);
289  }
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 553 of file class.ilMailTemplateGUI.php.

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

553  : void
554  {
555  if (!$this->isEditingAllowed()) {
556  $this->error->raiseError($this->lng->txt('msg_no_perm_write'), $this->error->WARNING);
557  }
558 
559  $template_id = 0;
560  if ($this->http->wrapper()->query()->has('mail_template_tpl_ids')) {
561  $template_id = $this->http->wrapper()->query()->retrieve(
562  'mail_template_tpl_ids',
563  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
564  )[0];
565  }
566 
567  if (!is_numeric($template_id) || $template_id < 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) $template_id);
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 248 of file class.ilMailTemplateGUI.php.

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

Referenced by updateTemplate().

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

◆ showInsertTemplateForm()

ilMailTemplateGUI::showInsertTemplateForm ( ?ilPropertyFormGUI  $form = null)
protected

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

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

Referenced by insertTemplate().

171  : void
172  {
173  if (!($form instanceof ilPropertyFormGUI)) {
174  $form = $this->getTemplateForm();
175  }
176 
177  $this->tpl->setContent($form->getHTML());
178  }
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 95 of file class.ilMailTemplateGUI.php.

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

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

95  : void
96  {
98  if (count($contexts) <= 1) {
99  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('mail_template_no_context_available'));
100  } elseif ($this->isEditingAllowed()) {
101  $this->toolbar->addComponent($this->ui_factory->button()->standard(
102  $this->lng->txt('mail_new_template'),
103  $this->ctrl->getLinkTarget($this, 'showInsertTemplateForm')
104  ));
105  }
106 
107  $tbl = new ilMailTemplateTable(
108  $this->http->request(),
109  $this->lng,
111  new DataFactory(),
113  !$this->isEditingAllowed()
114  );
115 
116  $this->tpl->setContent($this->ui_renderer->render($tbl->getComponent()));
117  }
static getTemplateContexts(?array $a_id=null)
Returns an array of mail template contexts, the key of each entry matches its id. ...
static http()
Fetches the global http state from ILIAS.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilMailTemplateService $service
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unsetAsContextDefault()

ilMailTemplateGUI::unsetAsContextDefault ( )

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

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

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

◆ updateTemplate()

ilMailTemplateGUI::updateTemplate ( )
protected

Definition at line 180 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().

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

ilPropertyFormGUI ilMailTemplateGUI::$form
protected

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

Referenced by getTemplateForm().

◆ $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.

Referenced by showTemplates().

◆ $rbacsystem

ilRbacSystem ilMailTemplateGUI::$rbacsystem
protected

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

◆ $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.

Referenced by showTemplates().

◆ $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.

◆ $ui_factory

Factory ilMailTemplateGUI::$ui_factory
protected

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

Referenced by showTemplates().

◆ $ui_renderer

Renderer ilMailTemplateGUI::$ui_renderer
protected

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


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