4require_once
'Services/Mail/classes/class.ilMailTemplateContext.php';
17 public static function clearFromXml($a_component, array $a_new_templates)
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');
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')) {
77 $first_context = current($contexts);
79 require_once
'Services/Mail/exceptions/class.ilMailException.php';
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);
110 while (
$row =
$DIC->database()->fetchAssoc($set)) {
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";
175 $context_exists = (
$row[
'id'] == $a_context->
getId());
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)
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)
192 'id' => array(
'text', $a_context->
getId())
195 $DIC[
'ilLog']->debug(
"Mail Template XML - Context " . $a_context->
getId() .
" in class " . $a_class .
" updated.");
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
Class ilMailTemplateContext.
getId()
Returns a unique (in the context of mail template contexts) id.
Class ilMailTemplateService.
static getTemplateContextById($a_id)
static getContextInstance($a_component, $a_id, $a_class, $a_path)
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)
static insertFromXML($a_component, $a_id, $a_class, $a_path)
static clearFromXml($a_component, array $a_new_templates)
if(!array_key_exists('StateId', $_REQUEST)) $id
foreach($_POST as $key=> $value) $res