ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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 $dependencyElementId;
38  protected string $instructionText = '';
39  protected string $adviseText = '';
42  protected $value;
43 
44  public function __construct(string $label, string $dependencyElementId)
45  {
46  global $DIC;
47 
48  $this->tpl = $DIC->ui()->mainTemplate();
49  $this->httpState = $DIC->http();
50 
51  $this->dependencyElementId = $dependencyElementId;
52 
53  parent::__construct($label);
54 
55  $this->tpl->addJavaScript('Services/Mail/js/ilMailComposeFunctions.js');
56  }
57 
58  public function getRerenderUrl(): ?string
59  {
60  return $this->rerenderUrl;
61  }
62 
63  public function getRerenderTriggerElementName(): string
64  {
66  }
67 
68  public function supportsRerenderSignal(string $elementId, string $url): void
69  {
70  $this->rerenderTriggerElementName = $elementId;
71  $this->rerenderUrl = $url;
72  }
73 
74  public function getAdviseText(): string
75  {
76  return $this->adviseText;
77  }
78 
79  public function setAdviseText(string $adviseText): void
80  {
81  $this->adviseText = $adviseText;
82  }
83 
84  public function getInstructionText(): string
85  {
87  }
88 
89  public function setInstructionText(string $instructionText): void
90  {
91  $this->instructionText = $instructionText;
92  }
93 
94  public function addPlaceholder(string $placeholder, string $title): void
95  {
96  $this->placeholders[$placeholder]['placeholder'] = $placeholder;
97  $this->placeholders[$placeholder]['title'] = $title;
98  }
99 
100  public function insert(ilTemplate $a_tpl): void
101  {
102  $html = $this->render();
103 
104  $a_tpl->setCurrentBlock('prop_generic');
105  $a_tpl->setVariable('PROP_GENERIC', $html);
106  $a_tpl->parseCurrentBlock();
107  }
108 
109  public function render(bool $ajax = false): string
110  {
111  $subtpl = new ilTemplate(
112  'tpl.mail_manual_placeholders.html',
113  true,
114  true,
115  'Services/Mail'
116  );
117  $subtpl->setVariable('TXT_USE_PLACEHOLDERS', $this->lng->txt('mail_nacc_use_placeholder'));
118  $subtpl->setVariable('DEPENDENCY_ELM_ID_OUTER', $this->dependencyElementId);
119  if ($this->getAdviseText()) {
120  $subtpl->setVariable('TXT_PLACEHOLDERS_ADVISE', $this->getAdviseText());
121  }
122 
123  if (count($this->placeholders) > 0) {
124  foreach ($this->placeholders as $placeholder) {
125  $subtpl->setCurrentBlock('man_placeholder');
126  $subtpl->setVariable('DEPENDENCY_ELM_ID', $this->dependencyElementId);
127  $subtpl->setVariable('PLACEHOLDER', '[' . $placeholder['placeholder'] . ']');
128  $subtpl->setVariable('PLACEHOLDER_INTERACTION_INFO', sprintf(
129  $this->lng->txt('mail_hint_add_placeholder_x'),
130  '[' . $placeholder['placeholder'] . ']'
131  ));
132  $subtpl->setVariable('PLACEHOLDER_DESCRIPTION', $placeholder['title']);
133  $subtpl->parseCurrentBlock();
134  }
135  }
136 
137  if ($this->getRerenderTriggerElementName() && $this->getRerenderUrl()) {
138  $subtpl->setVariable('RERENDER_URL', $this->getRerenderUrl());
139  $subtpl->setVariable('RERENDER_TRIGGER_ELM_NAME', $this->getRerenderTriggerElementName());
140  }
141 
142  if ($ajax) {
143  $this->httpState->saveResponse(
144  $this->httpState
145  ->response()
146  ->withBody(Streams::ofString($subtpl->get()))
147  );
148  $this->httpState->sendResponse();
149  $this->httpState->close();
150  }
151 
152  return $subtpl->get();
153  }
154 
155  public function setValueByArray(array $a_values): void
156  {
157  $this->setValue($a_values[$this->getPostVar()] ?? null);
158  }
159 
160  public function setValue($a_value): void
161  {
162  if (is_array($a_value) && $this->getMulti()) {
163  $this->setMultiValues($a_value);
164  $a_value = array_shift($a_value);
165  }
166  $this->value = $a_value;
167  }
168 
169  public function checkInput(): bool
170  {
171  return true;
172  }
173 }
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(string $label, string $dependencyElementId)
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
supportsRerenderSignal(string $elementId, string $url)
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
__construct(Container $dic, ilPlugin $plugin)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$url