ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilMailTemplateService Class Reference
+ Inheritance diagram for ilMailTemplateService:
+ Collaboration diagram for ilMailTemplateService:

Public Member Functions

 __construct (protected ilMailTemplateRepository $repository, protected ilMustacheFactory $mustacheFactory)
 
 createNewTemplate (string $contextId, string $title, string $subject, string $message, string $language)
 
 modifyExistingTemplate (int $templateId, string $contextId, string $title, string $subject, string $message, string $language)
 
 loadTemplateForId (int $templateId)
 
 loadTemplatesForContextId (string $contextId)
 
 deleteTemplatesByIds (array $templateIds)
 
 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  $mustacheFactory 
)

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

29  {
30  }

Member Function Documentation

◆ createNewTemplate()

ilMailTemplateService::createNewTemplate ( string  $contextId,
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->mustacheFactory->getBasicEngine()->render($subject, []);
41  } catch (Exception) {
42  throw new TemplateSubjectSyntaxException('Invalid mail template for subject');
43  }
44 
45  try {
46  $this->mustacheFactory->getBasicEngine()->render($message, []);
47  } catch (Exception) {
48  throw new TemplateMessageSyntaxException('Invalid mail template for message');
49  }
50 
51  $template = new ilMailTemplate();
52  $template->setContext($contextId);
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:17
Class ilMailTemplate.
+ Here is the call graph for this function:

◆ deleteTemplatesByIds()

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

Implements ilMailTemplateServiceInterface.

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

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

104  : void
105  {
106  $this->repository->deleteByIds($templateIds);
107  }
repository()
description: > Example for rendering a repository card
Definition: repository.php:17
+ 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 function (ilMailTemplate $template): array {
114  return $template->toArray();
115  }, $templates);
116  }
repository()
description: > Example for rendering a repository card
Definition: repository.php:17
Class ilMailTemplate.
+ Here is the call graph for this function:

◆ loadTemplateForId()

ilMailTemplateService::loadTemplateForId ( int  $templateId)

Implements ilMailTemplateServiceInterface.

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

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

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

◆ loadTemplatesForContextId()

ilMailTemplateService::loadTemplatesForContextId ( string  $contextId)
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($contextId);
102  }
repository()
description: > Example for rendering a repository card
Definition: repository.php:17
+ Here is the call graph for this function:

◆ modifyExistingTemplate()

ilMailTemplateService::modifyExistingTemplate ( int  $templateId,
string  $contextId,
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->mustacheFactory->getBasicEngine()->render($subject, []);
73  } catch (Exception) {
74  throw new TemplateSubjectSyntaxException('Invalid mail template for subject');
75  }
76 
77  try {
78  $this->mustacheFactory->getBasicEngine()->render($message, []);
79  } catch (Exception) {
80  throw new TemplateMessageSyntaxException('Invalid mail template for message');
81  }
82 
83  $template = $this->repository->findById($templateId);
84 
85  $template->setContext($contextId);
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:17
+ Here is the call graph for this function:

◆ setAsContextDefault()

ilMailTemplateService::setAsContextDefault ( ilMailTemplate  $template)

Implements ilMailTemplateServiceInterface.

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

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

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

◆ unsetAsContextDefault()

ilMailTemplateService::unsetAsContextDefault ( ilMailTemplate  $template)

Implements ilMailTemplateServiceInterface.

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

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

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

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