ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMailTemplatePlaceholderResolver.php
Go to the documentation of this file.
1 <?php declare(strict_types=1);
2 /* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
9 {
11  protected $context;
12 
14  protected $message = '';
15 
21  public function __construct(ilMailTemplateContext $context, string $a_message)
22  {
23  $this->context = $context;
24  $this->message = $a_message;
25  }
26 
33  public function resolve(
34  ilObjUser $user = null,
35  array $contextParameters = [],
36  bool $replaceEmptyPlaceholders = true
37  ) : string {
39 
40  foreach ($this->context->getPlaceholders() as $key => $ph_definition) {
41  $result = $this->context->resolvePlaceholder($key, $contextParameters, $user);
42  if (!$replaceEmptyPlaceholders && 0 === strlen($result)) {
43  continue;
44  }
45 
46  $startTag = '\[IF_' . strtoupper($key) . '\]';
47  $endTag = '\[\/IF_' . strtoupper($key) . '\]';
48 
49  if (strlen($result) > 0) {
50  $message = str_replace('[' . $ph_definition['placeholder'] . ']', $result, $message);
51 
52  if (array_key_exists('supportsCondition', $ph_definition) && $ph_definition['supportsCondition']) {
53  $message = preg_replace('/' . $startTag . '(.*?)' . $endTag . '/imsU', '$1', $message);
54  }
55  } else {
56  $message = preg_replace(
57  '/[[:space:]]{1,1}\[' . $ph_definition['placeholder'] . '\][[:space:]]{1,1}/ims',
58  ' ',
59  $message
60  );
61  $message = preg_replace('/\[' . $ph_definition['placeholder'] . '\]/ims', '', $message);
62 
63  if (array_key_exists('supportsCondition', $ph_definition) && $ph_definition['supportsCondition']) {
64  $message = preg_replace('/' . $startTag . '.*?' . $endTag . '/imsU', '', $message);
65  }
66  }
67  }
68 
69  return $message;
70  }
71 }
$result
__construct(ilMailTemplateContext $context, string $a_message)
ilMailTemplateProcessor constructor.
Class ilMailTemplateContext.
resolve(ilObjUser $user=null, array $contextParameters=[], bool $replaceEmptyPlaceholders=true)
Class ilMailTemplatePlaceholderResolver.