ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilMailTemplateService Class Reference

Class ilMailTemplateService. More...

+ Collaboration diagram for ilMailTemplateService:

Static Public Member Functions

static clearFromXml ($a_component, array $a_new_templates)
 
static insertFromXML ($a_component, $a_id, $a_class, $a_path)
 
static getTemplateContextById ($a_id)
 
static getTemplateContexts ($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 ($a_component, $a_id, $a_class, $a_path)
 
static createEntry (ilMailTemplateContext $a_context, $a_component, $a_class, $a_path)
 

Detailed Description

Member Function Documentation

◆ clearFromXml()

static ilMailTemplateService::clearFromXml (   $a_component,
array  $a_new_templates 
)
static
Parameters
string$a_component
array$a_new_templates

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

References $DIC, $id, $query, $row, and array.

Referenced by ilObjDefReader\handlerEndTag().

18  {
19  global $DIC;
20 
21  if (!$DIC->database()->tableExists('mail_tpl_ctx')) {
22  return;
23  }
24 
25  $persisted_templates = array();
26  $query = 'SELECT id FROM mail_tpl_ctx WHERE component = ' . $DIC->database()->quote($a_component, 'text');
27  $set = $DIC->database()->query($query);
28  while ($row = $DIC->database()->fetchAssoc($set)) {
29  $persisted_templates[] = $row['id'];
30  }
31 
32  if (count($persisted_templates)) {
33  if (count($a_new_templates)) {
34  foreach ($persisted_templates as $id) {
35  if (!in_array($id, $a_new_templates)) {
36  $DIC->database()->manipulate(
37  'DELETE FROM mail_tpl_ctx WHERE component = ' . $DIC->database()->quote($a_component, 'text') . ' AND id = ' . $DIC->database()->quote($id, 'text')
38  );
39  $DIC['ilLog']->debug("Mail Template XML - Context " . $id . " in class " . $a_component . " deleted.");
40  }
41  }
42  } else {
43  $DIC->database()->manipulate('DELETE FROM mail_tpl_ctx WHERE component = ' . $DIC->database()->quote($a_component, 'text'));
44  $DIC['ilLog']->debug("Mail Template XML - All contexts deleted for " . $a_component . " as component is inactive.");
45  }
46  }
47  }
global $DIC
Definition: saml.php:7
if(!array_key_exists('StateId', $_REQUEST)) $id
$query
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ createEntry()

static ilMailTemplateService::createEntry ( ilMailTemplateContext  $a_context,
  $a_component,
  $a_class,
  $a_path 
)
staticprotected
Parameters
ilMailTemplateContext$a_context
string$a_component
string$a_class
string$a_path

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

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

169  {
170  global $DIC;
171 
172  $query = "SELECT id FROM mail_tpl_ctx WHERE id = %s";
173  $res = $DIC->database()->queryF($query, array('text'), array($a_context->getId()));
174  $row = $DIC->database()->fetchAssoc($res);
175  $context_exists = ($row['id'] == $a_context->getId());
176 
177  if (!$context_exists) {
178  $DIC->database()->insert('mail_tpl_ctx', array(
179  'id' => array('text', $a_context->getId()),
180  'component' => array('text', $a_component),
181  'class' => array('text', $a_class),
182  'path' => array('text', $a_path)
183  ));
184 
185  $DIC['ilLog']->debug("Mail Template XML - Context " . $a_context->getId() . " in class " . $a_class . " added.");
186  } else {
187  $DIC->database()->update('mail_tpl_ctx', array(
188  'component' => array('text', $a_component),
189  'class' => array('text', $a_class),
190  'path' => array('text', $a_path)
191  ), array(
192  'id' => array('text', $a_context->getId())
193  ));
194 
195  $DIC['ilLog']->debug("Mail Template XML - Context " . $a_context->getId() . " in class " . $a_class . " updated.");
196  }
197  }
global $DIC
Definition: saml.php:7
getId()
Returns a unique (in the context of mail template contexts) id.
foreach($_POST as $key=> $value) $res
$query
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ getContextInstance()

static ilMailTemplateService::getContextInstance (   $a_component,
  $a_id,
  $a_class,
  $a_path 
)
staticprotected
Parameters
string$a_component
string$a_id
string$a_class
string$a_path
Returns
null|ilMailTemplateContext

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

References $DIC.

129  {
130  global $DIC;
131 
132  $mess = '';
133 
134  if (!$a_path) {
135  $a_path = $a_component . '/classes/';
136  }
137  $class_file = $a_path . 'class.' . $a_class . '.php';
138 
139  if (file_exists($class_file)) {
140  require_once $class_file;
141  if (class_exists($a_class)) {
142  $context = new $a_class();
143  if ($context instanceof ilMailTemplateContext) {
144  if ($context->getId() == $a_id) {
145  return $context;
146  } else {
147  $mess .= " - context id mismatch";
148  }
149  } else {
150  $mess .= " - does not extend ilMailTemplateContext";
151  }
152  } else {
153  $mess = "- class not found in file";
154  }
155  } else {
156  $mess = " - class file not found";
157  }
158 
159  $DIC['ilLog']->debug("Mail Template XML - Context " . $a_id . " in class " . $a_class . " (" . $class_file . ") is invalid." . $mess);
160  }
global $DIC
Definition: saml.php:7
Class ilMailTemplateContext.

◆ getTemplateContextById()

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

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

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

75  {
76  $contexts = self::getTemplateContexts($a_id);
77  $first_context = current($contexts);
78  if (!($first_context instanceof ilMailTemplateContext) || $first_context->getId() != $a_id) {
79  require_once 'Services/Mail/exceptions/class.ilMailException.php';
80  throw new ilMailException(sprintf("Could not find a mail template context with id: %s", $a_id));
81  }
82  return $first_context;
83  }
Class ilMailException.
Class ilMailTemplateContext.
+ Here is the caller graph for this function:

◆ getTemplateContexts()

static ilMailTemplateService::getTemplateContexts (   $a_id = null)
static

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

Parameters
null | string | array$a_id
Returns
ilMailTemplateContext[]

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

References $DIC, $query, $row, and array.

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

91  {
92  global $DIC;
93 
94  $templates = array();
95 
96  if ($a_id && !is_array($a_id)) {
97  $a_id = array($a_id);
98  }
99 
100  $query = 'SELECT * FROM mail_tpl_ctx';
101  $where = array();
102  if ($a_id) {
103  $where[] = $DIC->database()->in('id', $a_id, false, 'text');
104  }
105  if (count($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  }
global $DIC
Definition: saml.php:7
Class ilMailTemplateContext.
$query
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ insertFromXML()

static ilMailTemplateService::insertFromXML (   $a_component,
  $a_id,
  $a_class,
  $a_path 
)
static
Parameters
string$a_component
string$a_id
string$a_class
string$a_path

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

References $DIC.

Referenced by ilObjDefReader\handlerBeginTag().

56  {
57  global $DIC;
58 
59  if (!$DIC->database()->tableExists('mail_tpl_ctx')) {
60  return;
61  }
62 
63  $context = self::getContextInstance($a_component, $a_id, $a_class, $a_path);
64  if ($context instanceof ilMailTemplateContext) {
65  self::createEntry($context, $a_component, $a_class, $a_path);
66  }
67  }
global $DIC
Definition: saml.php:7
Class ilMailTemplateContext.
+ Here is the caller graph for this function:

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