4 require_once
'Services/Mail/classes/class.ilMailTemplateContext.php';
21 if (!$DIC->database()->tableExists(
'mail_tpl_ctx')) {
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'];
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')
39 $DIC[
'ilLog']->debug(
"Mail Template XML - Context " . $id .
" in class " . $a_component .
" deleted.");
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.");
55 public static function insertFromXML($a_component, $a_id, $a_class, $a_path)
59 if (!$DIC->database()->tableExists(
'mail_tpl_ctx')) {
63 $context = self::getContextInstance($a_component, $a_id, $a_class, $a_path);
65 self::createEntry($context, $a_component, $a_class, $a_path);
76 $contexts = self::getTemplateContexts($a_id);
77 $first_context = current($contexts);
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));
82 return $first_context;
96 if ($a_id && !is_array($a_id)) {
100 $query =
'SELECT * FROM mail_tpl_ctx';
103 $where[] = $DIC->database()->in(
'id', $a_id,
false,
'text');
106 $query .=
' WHERE ' . implode(
' AND ', $where);
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']);
113 $templates[$context->getId()] = $context;
135 $a_path = $a_component .
'/classes/';
137 $class_file = $a_path .
'class.' . $a_class .
'.php';
139 if (file_exists($class_file)) {
140 require_once $class_file;
141 if (class_exists($a_class)) {
142 $context =
new $a_class();
144 if ($context->getId() == $a_id) {
147 $mess .=
" - context id mismatch";
150 $mess .=
" - does not extend ilMailTemplateContext";
153 $mess =
"- class not found in file";
156 $mess =
" - class file not found";
159 $DIC[
'ilLog']->debug(
"Mail Template XML - Context " . $a_id .
" in class " . $a_class .
" (" . $class_file .
") is invalid." . $mess);
172 $query =
"SELECT id FROM mail_tpl_ctx WHERE id = %s";
174 $row = $DIC->database()->fetchAssoc(
$res);
175 $context_exists = (
$row[
'id'] == $a_context->
getId());
177 if (!$context_exists) {
178 $DIC->database()->insert(
'mail_tpl_ctx',
array(
180 'component' =>
array(
'text', $a_component),
181 'class' =>
array(
'text', $a_class),
182 'path' =>
array(
'text', $a_path)
185 $DIC[
'ilLog']->debug(
"Mail Template XML - Context " . $a_context->
getId() .
" in class " . $a_class .
" added.");
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)
195 $DIC[
'ilLog']->debug(
"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)
Class ilMailTemplateService.
if(!array_key_exists('StateId', $_REQUEST)) $id
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. ...
foreach($_POST as $key=> $value) $res
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)