ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilMailTemplatePlaceholderResolver.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
8 {
12  protected $context;
13 
17  protected $message;
18 
24  public function __construct(ilMailTemplateContext $context, $a_message)
25  {
26  $this->context = $context;
27  $this->message = $a_message;
28  }
29 
37  public function resolve(ilObjUser $user = null, $a_context_params = array(), $replace_empty = true)
38  {
40 
41  foreach ($this->context->getPlaceholders() as $key => $ph_definition) {
42  $result = $this->context->resolvePlaceholder($key, $a_context_params, $user);
43  if (!$replace_empty && strlen($result) == 0) {
44  continue;
45  }
46 
47  $startTag = '\[IF_' . strtoupper($key) . '\]';
48  $endTag = '\[\/IF_' . strtoupper($key) . '\]';
49 
50  if (strlen($result) > 0) {
51  $message = str_replace('[' . $ph_definition['placeholder'] . ']', $result, $message);
52 
53  if (array_key_exists('supportsCondition', $ph_definition) && $ph_definition['supportsCondition']) {
54  $message = preg_replace('/' . $startTag . '(.*?)' . $endTag . '/imsU', '$1', $message);
55  }
56  } else {
57  $message = preg_replace('/[[:space:]]{1,1}\[' . $ph_definition['placeholder'] . '\][[:space:]]{1,1}/ims', ' ', $message);
58  $message = preg_replace('/\[' . $ph_definition['placeholder'] . '\]/ims', '', $message);
59 
60  if (array_key_exists('supportsCondition', $ph_definition) && $ph_definition['supportsCondition']) {
61  $message = preg_replace('/' . $startTag . '.*?' . $endTag . '/imsU', '', $message);
62  }
63  }
64  }
65 
66  return $message;
67  }
68 }
resolve(ilObjUser $user=null, $a_context_params=array(), $replace_empty=true)
$result
__construct(ilMailTemplateContext $context, $a_message)
ilMailTemplateProcessor constructor.
Class ilMailTemplateContext.
$user
Definition: migrateto20.php:57
$key
Definition: croninfo.php:18