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

Public Member Functions

 __construct (?ilDBInterface $db=null)
 
 getAll ()
 
 findById (int $template_id)
 
 findByContextId (string $context_id)
 
 deleteByIds (array $template_ids)
 
 store (ilMailTemplate $template)
 

Protected Attributes

ilDBInterface $db
 

Detailed Description

Definition at line 21 of file class.ilMailTemplateRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ilMailTemplateRepository::__construct ( ?ilDBInterface  $db = null)

Definition at line 25 of file class.ilMailTemplateRepository.php.

References $DIC.

26  {
27  global $DIC;
28  $this->db = $db ?? $DIC->database();
29  }
global $DIC
Definition: shib_login.php:26

Member Function Documentation

◆ deleteByIds()

ilMailTemplateRepository::deleteByIds ( array  $template_ids)
Parameters
list<int>$template_ids

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

References ilDBConstants\T_INTEGER.

79  : void
80  {
81  if ($template_ids !== []) {
82  $this->db->manipulate(
83  'DELETE FROM mail_man_tpl WHERE ' . $this->db->in('tpl_id', $template_ids, false, ilDBConstants::T_INTEGER)
84  );
85  }
86  }

◆ findByContextId()

ilMailTemplateRepository::findByContextId ( string  $context_id)
Returns
list<ilMailTemplate>

Definition at line 66 of file class.ilMailTemplateRepository.php.

References getAll(), and ilMailTemplate\getContext().

66  : array
67  {
68  return array_values(
69  array_filter(
70  $this->getAll(),
71  static fn(ilMailTemplate $template): bool => $context_id === $template->getContext()
72  )
73  );
74  }
+ Here is the call graph for this function:

◆ findById()

ilMailTemplateRepository::findById ( int  $template_id)

Definition at line 47 of file class.ilMailTemplateRepository.php.

References $res, and ilDBConstants\T_INTEGER.

48  {
49  $res = $this->db->queryF(
50  'SELECT * FROM mail_man_tpl WHERE tpl_id = %s',
52  [$template_id]
53  );
54 
55  if ($this->db->numRows($res) === 1) {
56  $row = $this->db->fetchAssoc($res);
57  return new ilMailTemplate($row);
58  }
59 
60  throw new OutOfBoundsException(sprintf('Could not find template by id: %s', $template_id));
61  }
$res
Definition: ltiservices.php:66

◆ getAll()

ilMailTemplateRepository::getAll ( )
Returns
list<ilMailTemplate>

Definition at line 34 of file class.ilMailTemplateRepository.php.

References $res.

Referenced by findByContextId().

34  : array
35  {
36  $templates = [];
37 
38  $res = $this->db->query('SELECT * FROM mail_man_tpl');
39  while ($row = $this->db->fetchAssoc($res)) {
40  $template = new ilMailTemplate($row);
41  $templates[] = $template;
42  }
43 
44  return $templates;
45  }
$res
Definition: ltiservices.php:66
+ Here is the caller graph for this function:

◆ store()

ilMailTemplateRepository::store ( ilMailTemplate  $template)

Definition at line 88 of file class.ilMailTemplateRepository.php.

References ilMailTemplate\getContext(), ilMailTemplate\getLang(), ilMailTemplate\getMessage(), ilMailTemplate\getSubject(), ilMailTemplate\getTitle(), ilMailTemplate\getTplId(), ilMailTemplate\isDefault(), ilMailTemplate\setTplId(), ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

88  : void
89  {
90  if ($template->getTplId() > 0) {
91  $this->db->update(
92  'mail_man_tpl',
93  [
94  'title' => [ilDBConstants::T_TEXT, $template->getTitle()],
95  'context' => [ilDBConstants::T_TEXT, $template->getContext()],
96  'lang' => [ilDBConstants::T_TEXT, $template->getLang()],
97  'm_subject' => [ilDBConstants::T_TEXT, $template->getSubject()],
98  'm_message' => [ilDBConstants::T_TEXT, $template->getMessage()],
99  'is_default' => [ilDBConstants::T_INTEGER, $template->isDefault()],
100  ],
101  [
102  'tpl_id' => [ilDBConstants::T_INTEGER, $template->getTplId()],
103  ]
104  );
105  } else {
106  $next_id = $this->db->nextId('mail_man_tpl');
107  $this->db->insert('mail_man_tpl', [
108  'tpl_id' => [ilDBConstants::T_INTEGER, $next_id],
109  'title' => [ilDBConstants::T_TEXT, $template->getTitle()],
110  'context' => [ilDBConstants::T_TEXT, $template->getContext()],
111  'lang' => [ilDBConstants::T_TEXT, $template->getLang()],
112  'm_subject' => [ilDBConstants::T_TEXT, $template->getSubject()],
113  'm_message' => [ilDBConstants::T_TEXT, $template->getMessage()],
114  'is_default' => [ilDBConstants::T_INTEGER, $template->isDefault()],
115  ]);
116  $template->setTplId($next_id);
117  }
118  }
setTplId(int $template_id)
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilMailTemplateRepository::$db
protected

Definition at line 23 of file class.ilMailTemplateRepository.php.


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