ILIAS  trunk Revision v11.0_alpha-1851-ga8564da6fed
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilMailTemplateContextService Class Reference
+ 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 Private 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

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

Member Function Documentation

◆ clearFromXml()

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

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

References $DIC, and $id.

Referenced by ilMailTemplateContextDefinitionProcessor\endTag().

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

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

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

154  : void {
155  global $DIC;
156 
157  $query = 'SELECT id FROM mail_tpl_ctx WHERE id = %s';
158  $res = $DIC->database()->queryF($query, ['text'], [$a_context->getId()]);
159  $row = $DIC->database()->fetchAssoc($res);
160  $row_id = $row['id'] ?? null;
161  $context_exists = ($row_id === $a_context->getId());
162 
163  if ($context_exists) {
164  $DIC->database()->update('mail_tpl_ctx', [
165  'component' => ['text', $a_component],
166  'class' => ['text', $a_class],
167  'path' => ['text', $a_path]
168  ], [
169  'id' => ['text', $a_context->getId()]
170  ]);
171  } else {
172  $DIC->database()->insert('mail_tpl_ctx', [
173  'id' => ['text', $a_context->getId()],
174  'component' => ['text', $a_component],
175  'class' => ['text', $a_class],
176  'path' => ['text', $a_path]
177  ]);
178  }
179  }
$res
Definition: ltiservices.php:66
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:22
+ 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 
)
staticprivate
Parameters
class-string$a_class

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

References $context, and null.

130  if (class_exists($a_class)) {
131  if ($isCreationContext) {
132  $reflClass = new ReflectionClass($a_class);
133  $context = $reflClass->newInstanceWithoutConstructor();
134  } else {
135  $context = new $a_class();
136  }
137 
138  if (($context instanceof ilMailTemplateContext) && $context->getId() === $a_id) {
139  return $context;
140  }
141  }
142 
143  return null;
144  }
$context
Definition: webdav.php:31
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ getTemplateContextById()

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

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

80  {
81  $contexts = self::getTemplateContexts([$a_id]);
82  $first_context = current($contexts);
83  if (!($first_context instanceof ilMailTemplateContext) || $first_context->getId() !== $a_id) {
84  throw new ilMailException(sprintf('Could not find a mail template context with id: %s', $a_id));
85  }
86 
87  return $first_context;
88  }
+ 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
array<string, ilMailTemplateContext>

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

References $context, and $DIC.

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

95  : array
96  {
97  global $DIC;
98  $templates = [];
99 
100  $query = 'SELECT * FROM mail_tpl_ctx';
101  $where = [];
102  if (is_array($a_id) && count($a_id)) {
103  $where[] = $DIC->database()->in('id', $a_id, false, 'text');
104  }
105  if ($where !== []) {
106  $query .= ' WHERE ' . implode(' AND ', $where);
107  }
108 
109  $set = $DIC->database()->query($query);
110  while ($row = $DIC->database()->fetchAssoc($set)) {
111  $context = self::getContextInstance($row['component'], $row['id'], $row['class'], $row['path']);
112  if ($context instanceof ilMailTemplateContext) {
113  $templates[$context->getId()] = $context;
114  }
115  }
116 
117  return $templates;
118  }
$context
Definition: webdav.php:31
global $DIC
Definition: shib_login.php:22
+ 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 62 of file class.ilMailTemplateContextService.php.

References $context, and $DIC.

Referenced by ilMailTemplateContextDefinitionProcessor\beginTag().

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

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