ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilMailTemplateService Class Reference

Class ilMailTemplateService. More...

+ Collaboration diagram for ilMailTemplateService:

Public Member Functions

 __construct (\ilMailTemplateRepository $repository)
 ilMailTemplateService constructor. More...
 
 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)
 

Protected Attributes

 $repository
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilMailTemplateService::__construct ( \ilMailTemplateRepository  $repository)

ilMailTemplateService constructor.

Parameters
ilMailTemplateRepository$repository

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

References $repository, and repository().

19  {
20  $this->repository = $repository;
21  }
repository()
Definition: repository.php:5
+ Here is the call graph for this function:

Member Function Documentation

◆ createNewTemplate()

ilMailTemplateService::createNewTemplate ( string  $contextId,
string  $title,
string  $subject,
string  $message,
string  $language 
)
Parameters
string$contextId
string$title
string$subject
string$message
string$language
Returns

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

References $template, and repository().

37  : \ilMailTemplate {
38  $template = new \ilMailTemplate();
39  $template->setContext($contextId);
40  $template->setTitle($title);
41  $template->setSubject($subject);
42  $template->setMessage($message);
43  $template->setLang($language);
44 
45  $this->repository->store($template);
46 
47  return $template;
48  }
$template
Class ilMailTemplate.
catch(Exception $e) $message
repository()
Definition: repository.php:5
+ Here is the call graph for this function:

◆ deleteTemplatesByIds()

ilMailTemplateService::deleteTemplatesByIds ( array  $templateIds)
Parameters
array$templateIds

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

References repository().

99  {
100  $this->repository->deleteByIds($templateIds);
101  }
repository()
Definition: repository.php:5
+ Here is the call graph for this function:

◆ listAllTemplatesAsArray()

ilMailTemplateService::listAllTemplatesAsArray ( )
Returns
array[]

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

References $template, repository(), and ilMailTemplate\toArray().

106  : array
107  {
108  $templates = $this->repository->getAll();
109 
110  $templates = array_map(function (\ilMailTemplate $template) {
111  return $template->toArray();
112  }, $templates);
113 
114  return $templates;
115  }
$template
Class ilMailTemplate.
repository()
Definition: repository.php:5
+ Here is the call graph for this function:

◆ loadTemplateForId()

ilMailTemplateService::loadTemplateForId ( int  $templateId)
Parameters
int$templateId
Returns

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

References repository().

82  {
83  return $this->repository->findById($templateId);
84  }
Class ilMailTemplate.
repository()
Definition: repository.php:5
+ Here is the call graph for this function:

◆ loadTemplatesForContextId()

ilMailTemplateService::loadTemplatesForContextId ( string  $contextId)
Parameters
string$contextId
Returns
[]

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

References repository().

90  : array
91  {
92  return $this->repository->findByContextId($contextId);
93  }
repository()
Definition: repository.php:5
+ Here is the call graph for this function:

◆ modifyExistingTemplate()

ilMailTemplateService::modifyExistingTemplate ( int  $templateId,
string  $contextId,
string  $title,
string  $subject,
string  $message,
string  $language 
)
Parameters
int$templateId
string$contextId
string$title
string$subject
string$message
string$language

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

References $template, and repository().

65  {
66  $template = $this->repository->findById($templateId);
67 
68  $template->setContext($contextId);
69  $template->setTitle($title);
70  $template->setSubject($subject);
71  $template->setMessage($message);
72  $template->setLang($language);
73 
74  $this->repository->store($template);
75  }
$template
catch(Exception $e) $message
repository()
Definition: repository.php:5
+ Here is the call graph for this function:

◆ setAsContextDefault()

ilMailTemplateService::setAsContextDefault ( \ilMailTemplate  $template)
Parameters
\ilMailTemplate$template

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

References ilMailTemplate\getContext(), ilMailTemplate\getTplId(), and repository().

131  {
132  $allOfContext = $this->repository->findByContextId($template->getContext());
133  foreach ($allOfContext as $otherTemplate) {
134  $otherTemplate->setAsDefault(false);
135 
136  if ((int) $template->getTplId() === (int) $otherTemplate->getTplId()) {
137  $otherTemplate->setAsDefault(true);
138  }
139 
140  $this->repository->store($otherTemplate);
141  }
142  }
$template
repository()
Definition: repository.php:5
+ Here is the call graph for this function:

◆ unsetAsContextDefault()

ilMailTemplateService::unsetAsContextDefault ( \ilMailTemplate  $template)
Parameters
\ilMailTemplate$template

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

References repository(), and ilMailTemplate\setAsDefault().

121  {
122  $template->setAsDefault(false);
123 
124  $this->repository->store($template);
125  }
$template
repository()
Definition: repository.php:5
+ Here is the call graph for this function:

Field Documentation

◆ $repository

ilMailTemplateService::$repository
protected

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

Referenced by __construct().


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