ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilMailTemplateContextService Class Reference

Class ilMailTemplateContextService. More...

+ Collaboration diagram for ilMailTemplateContextService:

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 ilMailTemplateContextService::clearFromXml (   $a_component,
array  $a_new_templates 
)
static
Parameters
string$a_component
array$a_new_templates

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

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

Referenced by ilObjDefReader\handlerEndTag().

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

◆ createEntry()

static ilMailTemplateContextService::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 170 of file class.ilMailTemplateContextService.php.

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

171  {
172  global $DIC;
173 
174  $query = "SELECT id FROM mail_tpl_ctx WHERE id = %s";
175  $res = $DIC->database()->queryF($query, array('text'), array($a_context->getId()));
176  $row = $DIC->database()->fetchAssoc($res);
177  $context_exists = ($row['id'] == $a_context->getId());
178 
179  if (!$context_exists) {
180  $DIC->database()->insert('mail_tpl_ctx', array(
181  'id' => array('text', $a_context->getId()),
182  'component' => array('text', $a_component),
183  'class' => array('text', $a_class),
184  'path' => array('text', $a_path)
185  ));
186 
187  $DIC['ilLog']->debug("Mail Template XML - Context " . $a_context->getId() . " in class " . $a_class . " added.");
188  } else {
189  $DIC->database()->update('mail_tpl_ctx', array(
190  'component' => array('text', $a_component),
191  'class' => array('text', $a_class),
192  'path' => array('text', $a_path)
193  ), array(
194  'id' => array('text', $a_context->getId())
195  ));
196 
197  $DIC['ilLog']->debug("Mail Template XML - Context " . $a_context->getId() . " in class " . $a_class . " updated.");
198  }
199  }
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
$row
+ Here is the call graph for this function:

◆ getContextInstance()

static ilMailTemplateContextService::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 130 of file class.ilMailTemplateContextService.php.

References $context, and $DIC.

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

◆ getTemplateContextById()

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

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

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

◆ getTemplateContexts()

static ilMailTemplateContextService::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 92 of file class.ilMailTemplateContextService.php.

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

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

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

◆ insertFromXML()

static ilMailTemplateContextService::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 57 of file class.ilMailTemplateContextService.php.

References $context, and $DIC.

Referenced by ilObjDefReader\handlerBeginTag().

58  {
59  global $DIC;
60 
61  if (!$DIC->database()->tableExists('mail_tpl_ctx')) {
62  return;
63  }
64 
65  $context = self::getContextInstance($a_component, $a_id, $a_class, $a_path);
66  if ($context instanceof ilMailTemplateContext) {
67  self::createEntry($context, $a_component, $a_class, $a_path);
68  }
69  }
$context
Definition: webdav.php:25
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: