ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
ilMailTemplateService Class Reference
+ Inheritance diagram for ilMailTemplateService:
+ Collaboration diagram for ilMailTemplateService:

Public Member Functions

 __construct (protected ilMailTemplateRepository $repository, protected ilMustacheFactory $mustache_factory)
 
 createNewTemplate (string $context_id, string $title, string $subject, string $message, string $language)
 
 modifyExistingTemplate (int $template_id, string $context_id, string $title, string $subject, string $message, string $language)
 
 loadTemplateForId (int $template_id)
 
 loadTemplatesForContextId (string $context_id)
 
 deleteTemplatesByIds (array $template_ids)
 
 listAllTemplatesAsArray ()
 
 unsetAsContextDefault (ilMailTemplate $template)
 
 setAsContextDefault (ilMailTemplate $template)
 

Detailed Description

Definition at line 24 of file class.ilMailTemplateService.php.

Constructor & Destructor Documentation

◆ __construct()

ilMailTemplateService::__construct ( protected ilMailTemplateRepository  $repository,
protected ilMustacheFactory  $mustache_factory 
)

Definition at line 26 of file class.ilMailTemplateService.php.

29  {
30  }

Member Function Documentation

◆ createNewTemplate()

ilMailTemplateService::createNewTemplate ( string  $context_id,
string  $title,
string  $subject,
string  $message,
string  $language 
)

Implements ilMailTemplateServiceInterface.

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

References ILIAS\UI\examples\Deck\repository().

38  : ilMailTemplate {
39  try {
40  $this->mustache_factory->getBasicEngine()->render($subject, []);
41  } catch (Exception) {
42  throw new TemplateSubjectSyntaxException('Invalid mail template for subject');
43  }
44 
45  try {
46  $this->mustache_factory->getBasicEngine()->render($message, []);
47  } catch (Exception) {
48  throw new TemplateMessageSyntaxException('Invalid mail template for message');
49  }
50 
51  $template = new ilMailTemplate();
52  $template->setContext($context_id);
53  $template->setTitle($title);
54  $template->setSubject($subject);
55  $template->setMessage($message);
56  $template->setLang($language);
57 
58  $this->repository->store($template);
59 
60  return $template;
61  }
repository()
description: > Example for rendering a repository card
Definition: repository.php:33
$message
Definition: xapiexit.php:31
+ Here is the call graph for this function:

◆ deleteTemplatesByIds()

ilMailTemplateService::deleteTemplatesByIds ( array  $template_ids)
Parameters
list<int>$template_ids

Implements ilMailTemplateServiceInterface.

Definition at line 104 of file class.ilMailTemplateService.php.

References ILIAS\UI\examples\Deck\repository().

104  : void
105  {
106  $this->repository->deleteByIds($template_ids);
107  }
repository()
description: > Example for rendering a repository card
Definition: repository.php:33
+ Here is the call graph for this function:

◆ listAllTemplatesAsArray()

ilMailTemplateService::listAllTemplatesAsArray ( )
Returns
list<array<string, mixed>>

Implements ilMailTemplateServiceInterface.

Definition at line 109 of file class.ilMailTemplateService.php.

References ILIAS\UI\examples\Deck\repository(), and ilMailTemplate\toArray().

109  : array
110  {
111  $templates = $this->repository->getAll();
112 
113  return array_map(static fn(ilMailTemplate $template): array => $template->toArray(), $templates);
114  }
repository()
description: > Example for rendering a repository card
Definition: repository.php:33
+ Here is the call graph for this function:

◆ loadTemplateForId()

ilMailTemplateService::loadTemplateForId ( int  $template_id)

Implements ilMailTemplateServiceInterface.

Definition at line 94 of file class.ilMailTemplateService.php.

References ILIAS\UI\examples\Deck\repository().

95  {
96  return $this->repository->findById($template_id);
97  }
repository()
description: > Example for rendering a repository card
Definition: repository.php:33
+ Here is the call graph for this function:

◆ loadTemplatesForContextId()

ilMailTemplateService::loadTemplatesForContextId ( string  $context_id)
Returns
list<ilMailTemplate>

Implements ilMailTemplateServiceInterface.

Definition at line 99 of file class.ilMailTemplateService.php.

References ILIAS\UI\examples\Deck\repository().

99  : array
100  {
101  return $this->repository->findByContextId($context_id);
102  }
repository()
description: > Example for rendering a repository card
Definition: repository.php:33
+ Here is the call graph for this function:

◆ modifyExistingTemplate()

ilMailTemplateService::modifyExistingTemplate ( int  $template_id,
string  $context_id,
string  $title,
string  $subject,
string  $message,
string  $language 
)
Exceptions
TemplateSubjectSyntaxException|TemplateMessageSyntaxException

Implements ilMailTemplateServiceInterface.

Definition at line 63 of file class.ilMailTemplateService.php.

References ILIAS\UI\examples\Deck\repository().

70  : void {
71  try {
72  $this->mustache_factory->getBasicEngine()->render($subject, []);
73  } catch (Exception) {
74  throw new TemplateSubjectSyntaxException('Invalid mail template for subject');
75  }
76 
77  try {
78  $this->mustache_factory->getBasicEngine()->render($message, []);
79  } catch (Exception) {
80  throw new TemplateMessageSyntaxException('Invalid mail template for message');
81  }
82 
83  $template = $this->repository->findById($template_id);
84 
85  $template->setContext($context_id);
86  $template->setTitle($title);
87  $template->setSubject($subject);
88  $template->setMessage($message);
89  $template->setLang($language);
90 
91  $this->repository->store($template);
92  }
repository()
description: > Example for rendering a repository card
Definition: repository.php:33
$message
Definition: xapiexit.php:31
+ Here is the call graph for this function:

◆ setAsContextDefault()

ilMailTemplateService::setAsContextDefault ( ilMailTemplate  $template)

Implements ilMailTemplateServiceInterface.

Definition at line 123 of file class.ilMailTemplateService.php.

References ilMailTemplate\getContext(), ilMailTemplate\getTplId(), and ILIAS\UI\examples\Deck\repository().

123  : void
124  {
125  $all_of_context = $this->repository->findByContextId($template->getContext());
126  foreach ($all_of_context as $other_template) {
127  $other_template->setAsDefault(false);
128 
129  if ($template->getTplId() === $other_template->getTplId()) {
130  $other_template->setAsDefault(true);
131  }
132 
133  $this->repository->store($other_template);
134  }
135  }
repository()
description: > Example for rendering a repository card
Definition: repository.php:33
+ Here is the call graph for this function:

◆ unsetAsContextDefault()

ilMailTemplateService::unsetAsContextDefault ( ilMailTemplate  $template)

Implements ilMailTemplateServiceInterface.

Definition at line 116 of file class.ilMailTemplateService.php.

References ILIAS\UI\examples\Deck\repository(), and ilMailTemplate\setAsDefault().

116  : void
117  {
118  $template->setAsDefault(false);
119 
120  $this->repository->store($template);
121  }
repository()
description: > Example for rendering a repository card
Definition: repository.php:33
setAsDefault(bool $is_default)
+ Here is the call graph for this function:

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