ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
ilMailTemplateService Class Reference
+ Inheritance diagram for ilMailTemplateService:
+ Collaboration diagram for ilMailTemplateService:

Public Member Functions

 __construct (protected ilMailTemplateRepository $repository, protected TemplateEngineFactoryInterface $template_engine_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)
 
 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 25 of file class.ilMailTemplateService.php.

Constructor & Destructor Documentation

◆ __construct()

ilMailTemplateService::__construct ( protected ilMailTemplateRepository  $repository,
protected TemplateEngineFactoryInterface  $template_engine_factory 
)

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

30 {
31 }

Member Function Documentation

◆ createNewTemplate()

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

Implements ilMailTemplateServiceInterface.

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

40 try {
41 $this->template_engine_factory->getBasicEngine()->render($subject, []);
42 } catch (Exception) {
43 throw new TemplateSubjectSyntaxException('Invalid mail template for subject');
44 }
45
46 try {
47 $this->template_engine_factory->getBasicEngine()->render($message, []);
48 } catch (Exception) {
49 throw new TemplateMessageSyntaxException('Invalid mail template for message');
50 }
51
52 $template = new ilMailTemplate();
53 $template->setContext($context_id);
54 $template->setTitle($title);
55 $template->setSubject($subject);
56 $template->setMessage($message);
57 $template->setLang($language);
58
59 $this->repository->store($template);
60
61 return $template;
62 }

◆ deleteTemplatesByIds()

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

Implements ilMailTemplateServiceInterface.

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

105 : void
106 {
107 $this->repository->deleteByIds($template_ids);
108 }

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

+ Here is the call graph for this function:

◆ listAllTemplatesAsArray()

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

Implements ilMailTemplateServiceInterface.

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

110 : array
111 {
112 $templates = $this->repository->getAll();
113
114 return array_map(static fn(ilMailTemplate $template): array => $template->toArray(), $templates);
115 }

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

+ Here is the call graph for this function:

◆ loadTemplateForId()

ilMailTemplateService::loadTemplateForId ( int  $template_id)

Implements ilMailTemplateServiceInterface.

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

96 {
97 return $this->repository->findById($template_id);
98 }

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

+ Here is the call graph for this function:

◆ loadTemplatesForContextId()

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

Implements ilMailTemplateServiceInterface.

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

100 : array
101 {
102 return $this->repository->findByContextId($context_id);
103 }

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

+ 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 64 of file class.ilMailTemplateService.php.

71 : void {
72 try {
73 $this->template_engine_factory->getBasicEngine()->render($subject, []);
74 } catch (Exception) {
75 throw new TemplateSubjectSyntaxException('Invalid mail template for subject');
76 }
77
78 try {
79 $this->template_engine_factory->getBasicEngine()->render($message, []);
80 } catch (Exception) {
81 throw new TemplateMessageSyntaxException('Invalid mail template for message');
82 }
83
84 $template = $this->repository->findById($template_id);
85
86 $template->setContext($context_id);
87 $template->setTitle($title);
88 $template->setSubject($subject);
89 $template->setMessage($message);
90 $template->setLang($language);
91
92 $this->repository->store($template);
93 }

◆ setAsContextDefault()

ilMailTemplateService::setAsContextDefault ( ilMailTemplate  $template)

Implements ilMailTemplateServiceInterface.

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

124 : void
125 {
126 $all_of_context = $this->repository->findByContextId($template->getContext());
127 foreach ($all_of_context as $other_template) {
128 $other_template->setAsDefault(false);
129
130 if ($template->getTplId() === $other_template->getTplId()) {
131 $other_template->setAsDefault(true);
132 }
133
134 $this->repository->store($other_template);
135 }
136 }

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

+ Here is the call graph for this function:

◆ unsetAsContextDefault()

ilMailTemplateService::unsetAsContextDefault ( ilMailTemplate  $template)

Implements ilMailTemplateServiceInterface.

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

117 : void
118 {
119 $template->setAsDefault(false);
120
121 $this->repository->store($template);
122 }
setAsDefault(bool $is_default)

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

+ Here is the call graph for this function:

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