ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilManualPlaceholderInputGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
29 {
34  protected array $placeholders = [];
35  protected string $rerenderUrl = '';
36  protected string $rerenderTriggerElementName = '';
37  protected string $instructionText = '';
38  protected string $adviseText = '';
41  protected $value;
42 
43  public function __construct(string $label, string $http_post_param_name, protected string $dependencyElementId)
44  {
45  global $DIC;
46 
47  $this->tpl = $DIC->ui()->mainTemplate();
48  $this->httpState = $DIC->http();
49 
50  parent::__construct($label, $http_post_param_name);
51 
52  $this->tpl->addJavaScript('Services/Mail/js/ilMailComposeFunctions.js');
53  }
54 
55  public function getRerenderUrl(): ?string
56  {
57  return $this->rerenderUrl;
58  }
59 
60  public function getRerenderTriggerElementName(): string
61  {
63  }
64 
65  public function supportsRerenderSignal(string $elementId, string $url): void
66  {
67  $this->rerenderTriggerElementName = $elementId;
68  $this->rerenderUrl = $url;
69  }
70 
71  public function getAdviseText(): string
72  {
73  return $this->adviseText;
74  }
75 
76  public function setAdviseText(string $adviseText): void
77  {
78  $this->adviseText = $adviseText;
79  }
80 
81  public function getInstructionText(): string
82  {
84  }
85 
86  public function setInstructionText(string $instructionText): void
87  {
88  $this->instructionText = $instructionText;
89  }
90 
91  public function addPlaceholder(string $placeholder, string $title): void
92  {
93  $this->placeholders[$placeholder]['placeholder'] = $placeholder;
94  $this->placeholders[$placeholder]['title'] = $title;
95  }
96 
97  public function insert(ilTemplate $a_tpl): void
98  {
99  $html = $this->render();
100 
101  $a_tpl->setCurrentBlock('prop_generic');
102  $a_tpl->setVariable('PROP_GENERIC', $html);
103  $a_tpl->parseCurrentBlock();
104  }
105 
106  public function render(bool $ajax = false): string
107  {
108  $subtpl = new ilTemplate(
109  'tpl.mail_manual_placeholders.html',
110  true,
111  true,
112  'Services/Mail'
113  );
114  $subtpl->setVariable('TXT_USE_PLACEHOLDERS', $this->lng->txt('mail_nacc_use_placeholder'));
115  $subtpl->setVariable('DEPENDENCY_ELM_ID_OUTER', $this->dependencyElementId);
116  if ($this->getAdviseText() !== '') {
117  $subtpl->setVariable('TXT_PLACEHOLDERS_ADVISE', $this->getAdviseText());
118  }
119 
120  foreach ($this->placeholders as $placeholder) {
121  $subtpl->setCurrentBlock('man_placeholder');
122  $subtpl->setVariable('DEPENDENCY_ELM_ID', $this->dependencyElementId);
123  $subtpl->setVariable('PLACEHOLDER', '&lbrace;&lbrace;' . $placeholder['placeholder'] . '&rbrace;&rbrace;');
124  $subtpl->setVariable('PLACEHOLDER_INTERACTION_INFO', sprintf(
125  $this->lng->txt('mail_hint_add_placeholder_x'),
126  '&lbrace;&lbrace;' . $placeholder['placeholder'] . '&rbrace;&rbrace;'
127  ));
128  $subtpl->setVariable('PLACEHOLDER_DESCRIPTION', $placeholder['title']);
129  $subtpl->parseCurrentBlock();
130  }
131 
132  if ($this->getRerenderTriggerElementName() && $this->getRerenderUrl()) {
133  $subtpl->setVariable('RERENDER_URL', $this->getRerenderUrl());
134  $subtpl->setVariable('RERENDER_DEPENDENCY_ELM_ID_OUTER', $this->dependencyElementId);
135  $subtpl->setVariable('RERENDER_TRIGGER_ELM_NAME', $this->getRerenderTriggerElementName());
136  }
137 
138  if ($ajax) {
139  $this->httpState->saveResponse(
140  $this->httpState
141  ->response()
142  ->withBody(Streams::ofString($subtpl->get()))
143  );
144  $this->httpState->sendResponse();
145  $this->httpState->close();
146  }
147 
148  return $subtpl->get();
149  }
150 
151  public function setValueByArray(array $a_values): void
152  {
153  $this->setValue($a_values[$this->getPostVar()] ?? null);
154  }
155 
156  public function setValue($a_value): void
157  {
158  if (is_array($a_value) && $this->getMulti()) {
159  $this->setMultiValues($a_value);
160  $a_value = array_shift($a_value);
161  }
162  $this->value = $a_value;
163  }
164 
165  public function checkInput(): bool
166  {
167  return true;
168  }
169 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
Interface GlobalHttpState.
addPlaceholder(string $placeholder, string $title)
setMultiValues(array $a_values)
Class ilManualPlaceholderInputGUI.
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:546
$url
Definition: ltiregstart.php:35
supportsRerenderSignal(string $elementId, string $url)
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(string $label, string $http_post_param_name, protected string $dependencyElementId)