ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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...
 

Protected Member Functions

 getContextInstance ($a_component, $a_id, $a_class, $a_path)
 

Static Protected Member Functions

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 $GLOBALS, $query, and $row.

Referenced by ilObjDefReader\handlerEndTag().

18  {
19  if(!$GLOBALS['ilDB']->tableExists('mail_tpl_ctx'))
20  {
21  return;
22  }
23 
24  $persisted_templates = array();
25  $query = 'SELECT id FROM mail_tpl_ctx WHERE component = ' . $GLOBALS['ilDB']->quote($a_component, 'text');
26  $set = $GLOBALS['ilDB']->query($query);
27  while($row = $GLOBALS['ilDB']->fetchAssoc($set))
28  {
29  $persisted_templates[] = $row['id'];
30  }
31 
32  if(count($persisted_templates))
33  {
34  if(count($a_new_templates))
35  {
36  foreach($persisted_templates as $id)
37  {
38  if(!in_array($id, $a_new_templates))
39  {
40  $GLOBALS['ilDB']->manipulate(
41  'DELETE FROM mail_tpl_ctx WHERE component = ' . $GLOBALS['ilDB']->quote($a_component, 'text') . ' AND id = ' . $GLOBALS['ilDB']->quote($id, 'text')
42  );
43  $GLOBALS['ilLog']->write("Mail Template XML - Context " . $id . " in class " . $a_component . " deleted.");
44  }
45  }
46  }
47  else
48  {
49  $GLOBALS['ilDB']->manipulate('DELETE FROM mail_tpl_ctx WHERE component = ' . $GLOBALS['ilDB']->quote($a_component, 'text'));
50  $GLOBALS['ilLog']->write("Mail Template XML - All contexts deleted for " . $a_component . " as component is inactive.");
51  }
52  }
53  }
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
+ 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 188 of file class.ilMailTemplateService.php.

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

189  {
190  $query = "SELECT id FROM mail_tpl_ctx WHERE id = %s";
191  $res = $GLOBALS['ilDB']->queryF($query, array('text'), array($a_context->getId()));
192  $row = $GLOBALS['ilDB']->fetchAssoc($res);
193  $context_exists = ($row['id'] == $a_context->getId());
194 
195  if(!$context_exists)
196  {
197  $GLOBALS['ilDB']->insert('mail_tpl_ctx', array(
198  'id' => array('text', $a_context->getId()),
199  'component' => array('text', $a_component),
200  'class' => array('text', $a_class),
201  'path' => array('text', $a_path)
202  ));
203 
204  $GLOBALS['ilLog']->write("Mail Template XML - Context " . $a_context->getId() . " in class " . $a_class . " added.");
205  }
206  else
207  {
208  $GLOBALS['ilDB']->update('mail_tpl_ctx', array(
209  'component' => array('text', $a_component),
210  'class' => array('text', $a_class),
211  'path' => array('text', $a_path)
212  ), array(
213  'id' => array('text', $a_context->getId())
214  ));
215 
216  $GLOBALS['ilLog']->write("Mail Template XML - Context " . $a_context->getId() . " in class " . $a_class . " updated.");
217  }
218  }
getId()
Returns a unique (in the context of mail template contexts) id.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
+ Here is the call graph for this function:

◆ getContextInstance()

ilMailTemplateService::getContextInstance (   $a_component,
  $a_id,
  $a_class,
  $a_path 
)
protected
Parameters
string$a_component
string$a_id
string$a_class
string$a_path

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

References $GLOBALS.

138  {
139  $mess = '';
140 
141  if(!$a_path)
142  {
143  $a_path = $a_component . '/classes/';
144  }
145  $class_file = $a_path . 'class.' . $a_class . '.php';
146 
147  if(file_exists($class_file))
148  {
149  require_once $class_file;
150  if(class_exists($a_class))
151  {
152  $context = new $a_class();
153  if($context instanceof ilMailTemplateContext)
154  {
155  if($context->getId() == $a_id)
156  {
157  return $context;
158  }
159  else
160  {
161  $mess .= " - context id mismatch";
162  }
163  }
164  else
165  {
166  $mess .= " - does not extend ilMailTemplateContext";
167  }
168  }
169  else
170  {
171  $mess = "- class not found in file";
172  }
173  }
174  else
175  {
176  $mess = " - class file not found";
177  }
178 
179  $GLOBALS['ilLog']->write("Mail Template XML - Context " . $a_id . " in class " . $a_class . " (" . $class_file . ") is invalid." . $mess);
180  }
Class ilMailTemplateContext.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276

◆ getTemplateContextById()

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

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

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

81  {
82  $contexts = self::getTemplateContexts($a_id);
83  $first_context = current($contexts);
84  if(!($first_context instanceof ilMailTemplateContext) || $first_context->getId() != $a_id)
85  {
86  require_once 'Services/Mail/exceptions/class.ilMailException.php';
87  throw new ilMailException(sprintf("Could not find a mail template context with id: %s", $a_id));
88  }
89  return $first_context;
90  }
ILIAS Exception for Service Mail.
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 97 of file class.ilMailTemplateService.php.

References $GLOBALS, $query, and $row.

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

98  {
99  $templates = array();
100 
101  if($a_id && !is_array($a_id))
102  {
103  $a_id = array($a_id);
104  }
105 
106  $query = 'SELECT * FROM mail_tpl_ctx';
107  $where = array();
108  if($a_id)
109  {
110  $where[] = $GLOBALS['ilDB']->in('id', $a_id, false, 'text');
111  }
112  if(count($where))
113  {
114  $query .= ' WHERE '. implode(' AND ', $where);
115  }
116 
117  $set = $GLOBALS['ilDB']->query($query);
118  while($row = $GLOBALS['ilDB']->fetchAssoc($set))
119  {
120  $context = self::getContextInstance($row['component'], $row['id'], $row['class'], $row['path']);
121  if($context instanceof ilMailTemplateContext)
122  {
123  $templates[$context->getId()] = $context;
124  }
125  }
126 
127  return $templates;
128  }
Class ilMailTemplateContext.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
+ 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 61 of file class.ilMailTemplateService.php.

References $GLOBALS.

Referenced by ilObjDefReader\handlerBeginTag().

62  {
63  if(!$GLOBALS['ilDB']->tableExists('mail_tpl_ctx'))
64  {
65  return;
66  }
67 
68  $context = self::getContextInstance($a_component, $a_id, $a_class, $a_path);
69  if($context instanceof ilMailTemplateContext)
70  {
71  self::createEntry($context, $a_component, $a_class, $a_path);
72  }
73  }
Class ilMailTemplateContext.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
+ Here is the caller graph for this function:

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