19 declare(strict_types=1);
29 public static function clearFromXml(
string $a_component, array $a_new_templates): void
32 if (!$DIC->database()->tableExists(
'mail_tpl_ctx')) {
35 $persisted_templates = [];
36 $query =
'SELECT id FROM mail_tpl_ctx WHERE component = ' . $DIC->database()->quote($a_component,
'text');
37 $set = $DIC->database()->query($query);
38 while ($row = $DIC->database()->fetchAssoc($set)) {
39 $persisted_templates[] = $row[
'id'];
42 if ($persisted_templates !== []) {
43 if ($a_new_templates !== []) {
44 foreach ($persisted_templates as
$id) {
45 if (!in_array($id, $a_new_templates,
true)) {
46 $DIC->database()->manipulate(
47 'DELETE FROM mail_tpl_ctx WHERE component = ' . $DIC->database()->quote(
50 ) .
' AND id = ' . $DIC->database()->quote($id,
'text')
55 $DIC->database()->manipulate(
56 'DELETE FROM mail_tpl_ctx WHERE component = ' . $DIC->database()->quote(
65 public static function insertFromXML(
string $a_component,
string $a_id,
string $a_class, ?
string $a_path): void
69 if (!$DIC->database()->tableExists(
'mail_tpl_ctx')) {
73 $context = self::getContextInstance($a_component, $a_id, $a_class, $a_path,
true);
75 self::createEntry(
$context, $a_component, $a_class, $a_path);
84 $contexts = self::getTemplateContexts([$a_id]);
85 $first_context = current($contexts);
87 throw new ilMailException(sprintf(
"Could not find a mail template context with id: %s", $a_id));
90 return $first_context;
103 $query =
'SELECT * FROM mail_tpl_ctx';
105 if (is_array($a_id) && count($a_id)) {
106 $where[] = $DIC->database()->in(
'id', $a_id,
false,
'text');
109 $query .=
' WHERE ' . implode(
' AND ', $where);
112 $set = $DIC->database()->query($query);
113 while ($row = $DIC->database()->fetchAssoc($set)) {
114 $context = self::getContextInstance($row[
'component'], $row[
'id'], $row[
'class'], $row[
'path']);
128 bool $isCreationContext =
false 131 $a_path = $a_component .
'/classes/';
133 $class_file = $a_path .
'class.' . $a_class .
'.php';
135 if (class_exists($a_class) && file_exists($class_file)) {
136 if ($isCreationContext) {
138 $context = $reflClass->newInstanceWithoutConstructor();
158 $query =
"SELECT id FROM mail_tpl_ctx WHERE id = %s";
159 $res = $DIC->database()->queryF($query, [
'text'], [$a_context->
getId()]);
160 $row = $DIC->database()->fetchAssoc(
$res);
161 $row_id = $row[
'id'] ?? null;
162 $context_exists = ($row_id === $a_context->
getId());
164 if (!$context_exists) {
165 $DIC->database()->insert(
'mail_tpl_ctx', [
166 'id' => [
'text', $a_context->
getId()],
167 'component' => [
'text', $a_component],
168 'class' => [
'text', $a_class],
169 'path' => [
'text', $a_path]
172 $DIC->database()->update(
'mail_tpl_ctx', [
173 'component' => [
'text', $a_component],
174 'class' => [
'text', $a_class],
175 'path' => [
'text', $a_path]
177 'id' => [
'text', $a_context->
getId()]
Class ilMailTemplateContextService.
static insertFromXML(string $a_component, string $a_id, string $a_class, ?string $a_path)
static getContextInstance(string $a_component, string $a_id, string $a_class, ?string $a_path, bool $isCreationContext=false)
static getTemplateContextById(string $a_id)
static getTemplateContexts(?array $a_id=null)
Returns an array of mail template contexts, the key of each entry matches its id. ...
Class ilMailTemplateContext.
static createEntry(ilMailTemplateContext $a_context, string $a_component, string $a_class, ?string $a_path)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
static clearFromXml(string $a_component, array $a_new_templates)