ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilMailTemplateContextService Class Reference

Class ilMailTemplateContextService. More...

+ Collaboration diagram for ilMailTemplateContextService:

Static Public Member Functions

static clearFromXml (string $a_component, array $a_new_templates)
 
static insertFromXML (string $a_component, string $a_id, string $a_class, ?string $a_path)
 
static getTemplateContextById (string $a_id)
 
static getTemplateContexts (?array $a_id=null)
 Returns an array of mail template contexts, the key of each entry matches its id. More...
 

Static Protected Member Functions

static getContextInstance (string $a_component, string $a_id, string $a_class, ?string $a_path, bool $isCreationContext=false)
 
static createEntry (ilMailTemplateContext $a_context, string $a_component, string $a_class, ?string $a_path)
 

Detailed Description

Member Function Documentation

◆ clearFromXml()

static ilMailTemplateContextService::clearFromXml ( string  $a_component,
array  $a_new_templates 
)
static
Parameters
string[]$a_new_templates

Definition at line 29 of file class.ilMailTemplateContextService.php.

References $DIC, and $id.

Referenced by ilMailTemplateContextDefinitionProcessor\endTag().

29  : void
30  {
31  global $DIC;
32  if (!$DIC->database()->tableExists('mail_tpl_ctx')) {
33  return;
34  }
35  $persisted_templates = [];
36  $query = 'SELECT id FROM mail_tpl_ctx WHERE component = ' . $DIC->database()->quote($a_component, 'text');
37  $set = $DIC->database()->query($query);
38  while ($row = $DIC->database()->fetchAssoc($set)) {
39  $persisted_templates[] = $row['id'];
40  }
41 
42  if ($persisted_templates !== []) {
43  if ($a_new_templates !== []) {
44  foreach ($persisted_templates as $id) {
45  if (!in_array($id, $a_new_templates, true)) {
46  $DIC->database()->manipulate(
47  'DELETE FROM mail_tpl_ctx WHERE component = ' . $DIC->database()->quote(
48  $a_component,
49  'text'
50  ) . ' AND id = ' . $DIC->database()->quote($id, 'text')
51  );
52  }
53  }
54  } else {
55  $DIC->database()->manipulate(
56  'DELETE FROM mail_tpl_ctx WHERE component = ' . $DIC->database()->quote(
57  $a_component,
58  'text'
59  )
60  );
61  }
62  }
63  }
global $DIC
Definition: feed.php:28
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the caller graph for this function:

◆ createEntry()

static ilMailTemplateContextService::createEntry ( ilMailTemplateContext  $a_context,
string  $a_component,
string  $a_class,
?string  $a_path 
)
staticprotected

Definition at line 150 of file class.ilMailTemplateContextService.php.

References $DIC, $res, and ilMailTemplateContext\getId().

155  : void {
156  global $DIC;
157 
158  $query = "SELECT id FROM mail_tpl_ctx WHERE id = %s";
159  $res = $DIC->database()->queryF($query, ['text'], [$a_context->getId()]);
160  $row = $DIC->database()->fetchAssoc($res);
161  $row_id = $row['id'] ?? null;
162  $context_exists = ($row_id === $a_context->getId());
163 
164  if (!$context_exists) {
165  $DIC->database()->insert('mail_tpl_ctx', [
166  'id' => ['text', $a_context->getId()],
167  'component' => ['text', $a_component],
168  'class' => ['text', $a_class],
169  'path' => ['text', $a_path]
170  ]);
171  } else {
172  $DIC->database()->update('mail_tpl_ctx', [
173  'component' => ['text', $a_component],
174  'class' => ['text', $a_class],
175  'path' => ['text', $a_path]
176  ], [
177  'id' => ['text', $a_context->getId()]
178  ]);
179  }
180  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

◆ getContextInstance()

static ilMailTemplateContextService::getContextInstance ( string  $a_component,
string  $a_id,
string  $a_class,
?string  $a_path,
bool  $isCreationContext = false 
)
staticprotected

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

References $context.

130  if (!$a_path) {
131  $a_path = $a_component . '/classes/';
132  }
133  $class_file = $a_path . 'class.' . $a_class . '.php';
134 
135  if (class_exists($a_class) && file_exists($class_file)) {
136  if ($isCreationContext) {
137  $reflClass = new ReflectionClass($a_class);
138  $context = $reflClass->newInstanceWithoutConstructor();
139  } else {
140  $context = new $a_class();
141  }
142 
143  if (($context instanceof ilMailTemplateContext) && $context->getId() === $a_id) {
144  return $context;
145  }
146  }
147  return null;
148  }
$context
Definition: webdav.php:31
Class ilMailTemplateContext.

◆ getTemplateContextById()

static ilMailTemplateContextService::getTemplateContextById ( string  $a_id)
static
Exceptions
ilMailException

Definition at line 82 of file class.ilMailTemplateContextService.php.

Referenced by ilMailTemplateGUI\getAjaxPlaceholdersById(), ilMailFormGUI\getTemplateDataById(), ilMailTemplateGUI\getTemplateForm(), ilMailTemplateGUI\insertTemplate(), ilMail\replacePlaceholders(), ilExAssignmentReminder\sentReminderPlaceholders(), ilObjSurvey\sentReminderPlaceholders(), ilMailFormGUI\showForm(), and ilMailTemplateGUI\updateTemplate().

83  {
84  $contexts = self::getTemplateContexts([$a_id]);
85  $first_context = current($contexts);
86  if (!($first_context instanceof ilMailTemplateContext) || $first_context->getId() !== $a_id) {
87  throw new ilMailException(sprintf("Could not find a mail template context with id: %s", $a_id));
88  }
89 
90  return $first_context;
91  }
Class ilMailTemplateContext.
+ Here is the caller graph for this function:

◆ getTemplateContexts()

static ilMailTemplateContextService::getTemplateContexts ( ?array  $a_id = null)
static

Returns an array of mail template contexts, the key of each entry matches its id.

Parameters
string[]$a_id
Returns
ilMailTemplateContext[]

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

References $context, and $DIC.

Referenced by ilMailTemplateTableGUI\__construct(), ilMailTemplateGUI\getTemplateForm(), and ilMailTemplateGUI\showTemplates().

98  : array
99  {
100  global $DIC;
101  $templates = [];
102 
103  $query = 'SELECT * FROM mail_tpl_ctx';
104  $where = [];
105  if (is_array($a_id) && count($a_id)) {
106  $where[] = $DIC->database()->in('id', $a_id, false, 'text');
107  }
108  if ($where !== []) {
109  $query .= ' WHERE ' . implode(' AND ', $where);
110  }
111 
112  $set = $DIC->database()->query($query);
113  while ($row = $DIC->database()->fetchAssoc($set)) {
114  $context = self::getContextInstance($row['component'], $row['id'], $row['class'], $row['path']);
115  if ($context instanceof ilMailTemplateContext) {
116  $templates[$context->getId()] = $context;
117  }
118  }
119 
120  return $templates;
121  }
$context
Definition: webdav.php:31
global $DIC
Definition: feed.php:28
Class ilMailTemplateContext.
+ Here is the caller graph for this function:

◆ insertFromXML()

static ilMailTemplateContextService::insertFromXML ( string  $a_component,
string  $a_id,
string  $a_class,
?string  $a_path 
)
static

Definition at line 65 of file class.ilMailTemplateContextService.php.

References $context, and $DIC.

Referenced by ilMailTemplateContextDefinitionProcessor\beginTag().

65  : void
66  {
67  global $DIC;
68 
69  if (!$DIC->database()->tableExists('mail_tpl_ctx')) {
70  return;
71  }
72 
73  $context = self::getContextInstance($a_component, $a_id, $a_class, $a_path, true);
74  if ($context instanceof ilMailTemplateContext) {
75  self::createEntry($context, $a_component, $a_class, $a_path);
76  }
77  }
$context
Definition: webdav.php:31
global $DIC
Definition: feed.php:28
Class ilMailTemplateContext.
+ Here is the caller graph for this function:

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