4 require_once
'Services/Mail/classes/class.ilMailTemplateContext.php';
19 if(!
$GLOBALS[
'ilDB']->tableExists(
'mail_tpl_ctx'))
24 $persisted_templates =
array();
25 $query =
'SELECT id FROM mail_tpl_ctx WHERE component = ' .
$GLOBALS[
'ilDB']->quote($a_component,
'text');
29 $persisted_templates[] =
$row[
'id'];
32 if(count($persisted_templates))
34 if(count($a_new_templates))
36 foreach($persisted_templates as $id)
38 if(!in_array($id, $a_new_templates))
41 'DELETE FROM mail_tpl_ctx WHERE component = ' .
$GLOBALS[
'ilDB']->quote($a_component,
'text') .
' AND id = ' .
$GLOBALS[
'ilDB']->quote($id,
'text')
43 $GLOBALS[
'ilLog']->write(
"Mail Template XML - Context " . $id .
" in class " . $a_component .
" deleted.");
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.");
61 public static function insertFromXML($a_component, $a_id, $a_class, $a_path)
63 if(!
$GLOBALS[
'ilDB']->tableExists(
'mail_tpl_ctx'))
68 $context = self::getContextInstance($a_component, $a_id, $a_class, $a_path);
71 self::createEntry($context, $a_component, $a_class, $a_path);
82 $contexts = self::getTemplateContexts($a_id);
83 $first_context = current($contexts);
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));
89 return $first_context;
101 if($a_id && !is_array($a_id))
103 $a_id =
array($a_id);
106 $query =
'SELECT * FROM mail_tpl_ctx';
110 $where[] =
$GLOBALS[
'ilDB']->in(
'id', $a_id,
false,
'text');
114 $query .=
' WHERE '. implode(
' AND ', $where);
120 $context = self::getContextInstance(
$row[
'component'],
$row[
'id'],
$row[
'class'],
$row[
'path']);
123 $templates[$context->getId()] = $context;
143 $a_path = $a_component .
'/classes/';
145 $class_file = $a_path .
'class.' . $a_class .
'.php';
147 if(file_exists($class_file))
149 require_once $class_file;
150 if(class_exists($a_class))
152 $context =
new $a_class();
155 if($context->getId() == $a_id)
161 $mess .=
" - context id mismatch";
166 $mess .=
" - does not extend ilMailTemplateContext";
171 $mess =
"- class not found in file";
176 $mess =
" - class file not found";
179 $GLOBALS[
'ilLog']->write(
"Mail Template XML - Context " . $a_id .
" in class " . $a_class .
" (" . $class_file .
") is invalid." . $mess);
190 $query =
"SELECT id FROM mail_tpl_ctx WHERE id = %s";
193 $context_exists = (
$row[
'id'] == $a_context->
getId());
199 'component' =>
array(
'text', $a_component),
200 'class' =>
array(
'text', $a_class),
201 'path' =>
array(
'text', $a_path)
204 $GLOBALS[
'ilLog']->write(
"Mail Template XML - Context " . $a_context->
getId() .
" in class " . $a_class .
" added.");
209 'component' =>
array(
'text', $a_component),
210 'class' =>
array(
'text', $a_class),
211 'path' =>
array(
'text', $a_path)
216 $GLOBALS[
'ilLog']->write(
"Mail Template XML - Context " . $a_context->
getId() .
" in class " . $a_class .
" updated.");
static insertFromXML($a_component, $a_id, $a_class, $a_path)
static clearFromXml($a_component, array $a_new_templates)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
Class ilMailTemplateService.
getId()
Returns a unique (in the context of mail template contexts) id.
static getTemplateContexts($a_id=null)
Returns an array of mail template contexts, the key of each entry matches its id. ...
static createEntry(ilMailTemplateContext $a_context, $a_component, $a_class, $a_path)
Class ilMailTemplateContext.
Create styles array
The data for the language used.
static getContextInstance($a_component, $a_id, $a_class, $a_path)
static getTemplateContextById($a_id)