ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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_component
string[]$a_new_templates

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

References $DIC, $id, and $query.

Referenced by ilMailTemplateContextDefinitionProcessor\endTag().

30  : void
31  {
32  global $DIC;
33  if (!$DIC->database()->tableExists('mail_tpl_ctx')) {
34  return;
35  }
36  $persisted_templates = [];
37  $query = 'SELECT id FROM mail_tpl_ctx WHERE component = ' . $DIC->database()->quote($a_component, 'text');
38  $set = $DIC->database()->query($query);
39  while ($row = $DIC->database()->fetchAssoc($set)) {
40  $persisted_templates[] = $row['id'];
41  }
42 
43  if (count($persisted_templates)) {
44  if (count($a_new_templates)) {
45  foreach ($persisted_templates as $id) {
46  if (!in_array($id, $a_new_templates, true)) {
47  $DIC->database()->manipulate(
48  'DELETE FROM mail_tpl_ctx WHERE component = ' . $DIC->database()->quote(
49  $a_component,
50  'text'
51  ) . ' AND id = ' . $DIC->database()->quote($id, 'text')
52  );
53  }
54  }
55  } else {
56  $DIC->database()->manipulate(
57  'DELETE FROM mail_tpl_ctx WHERE component = ' . $DIC->database()->quote(
58  $a_component,
59  'text'
60  )
61  );
62  }
63  }
64  }
global $DIC
Definition: feed.php:28
$query
$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 153 of file class.ilMailTemplateContextService.php.

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

158  : void {
159  global $DIC;
160 
161  $query = "SELECT id FROM mail_tpl_ctx WHERE id = %s";
162  $res = $DIC->database()->queryF($query, ['text'], [$a_context->getId()]);
163  $row = $DIC->database()->fetchAssoc($res);
164  $row_id = $row['id'] ?? null;
165  $context_exists = ($row_id === $a_context->getId());
166 
167  if (!$context_exists) {
168  $DIC->database()->insert('mail_tpl_ctx', [
169  'id' => ['text', $a_context->getId()],
170  'component' => ['text', $a_component],
171  'class' => ['text', $a_class],
172  'path' => ['text', $a_path]
173  ]);
174  } else {
175  $DIC->database()->update('mail_tpl_ctx', [
176  'component' => ['text', $a_component],
177  'class' => ['text', $a_class],
178  'path' => ['text', $a_path]
179  ], [
180  'id' => ['text', $a_context->getId()]
181  ]);
182  }
183  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
$query
+ 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 126 of file class.ilMailTemplateContextService.php.

References $context.

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

◆ getTemplateContextById()

static ilMailTemplateContextService::getTemplateContextById ( string  $a_id)
static
Parameters
string$a_id
Returns
ilMailTemplateContext
Exceptions
ilMailException

Definition at line 85 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().

86  {
87  $contexts = self::getTemplateContexts([$a_id]);
88  $first_context = current($contexts);
89  if (!($first_context instanceof ilMailTemplateContext) || $first_context->getId() !== $a_id) {
90  throw new ilMailException(sprintf("Could not find a mail template context with id: %s", $a_id));
91  }
92 
93  return $first_context;
94  }
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 101 of file class.ilMailTemplateContextService.php.

References $context, $DIC, and $query.

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

101  : array
102  {
103  global $DIC;
104  $templates = [];
105 
106  $query = 'SELECT * FROM mail_tpl_ctx';
107  $where = [];
108  if (is_array($a_id) && count($a_id)) {
109  $where[] = $DIC->database()->in('id', $a_id, false, 'text');
110  }
111  if (count($where)) {
112  $query .= ' WHERE ' . implode(' AND ', $where);
113  }
114 
115  $set = $DIC->database()->query($query);
116  while ($row = $DIC->database()->fetchAssoc($set)) {
117  $context = self::getContextInstance($row['component'], $row['id'], $row['class'], $row['path']);
118  if ($context instanceof ilMailTemplateContext) {
119  $templates[$context->getId()] = $context;
120  }
121  }
122 
123  return $templates;
124  }
$context
Definition: webdav.php:29
global $DIC
Definition: feed.php:28
Class ilMailTemplateContext.
$query
+ 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 66 of file class.ilMailTemplateContextService.php.

References $context, and $DIC.

Referenced by ilMailTemplateContextDefinitionProcessor\beginTag().

66  : void
67  {
68  global $DIC;
69 
70  if (!$DIC->database()->tableExists('mail_tpl_ctx')) {
71  return;
72  }
73 
74  $context = self::getContextInstance($a_component, $a_id, $a_class, $a_path, true);
75  if ($context instanceof ilMailTemplateContext) {
76  self::createEntry($context, $a_component, $a_class, $a_path);
77  }
78  }
$context
Definition: webdav.php:29
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: