19 declare(strict_types=1);
47 private readonly
string $parent_class,
48 private readonly
Config $config,
49 private readonly
Closure $after_document_deletion,
52 $this->container = $container ??
$GLOBALS[
'DIC'];
53 $this->container->language()->loadLanguageModule(
'ldoc');
55 $this->config->legalDocuments()->id(),
56 $this->container->ui(),
57 $this->container->language()
64 $cmd = $this->container->ctrl()->getCmd(
'documents');
66 throw new Exception(
'Unknown command: ' . $cmd);
73 if (!$this->
admin->canReadUserAdministration()) {
74 $this->container[
'ilErr']->raiseError($this->container->language()->txt(
'permission_denied'), $this->container[
'ilErr']->WARNING);
76 $this->container->tabs()->activateTab(
'history');
77 $this->
admin->setContent($this->config->legalDocuments()->history()->table(
88 $auto->setSearchFields([
'login',
'firstname',
'lastname',
'email']);
89 $auto->enableFieldSearchableCheck(
false);
90 $auto->setMoreLinkAvailable(
true);
92 if ($this->container->http()->wrapper()->query()->has(
'fetchall')) {
96 if ($this->container->http()->wrapper()->query()->has(
'term')) {
98 $this->container->http()->wrapper()->query()->retrieve(
'term', $this->container->refinery()->kindlyTo()->string())
102 ->withHeader(ResponseHeader::CONTENT_TYPE,
'application/json')
103 ->withBody(Streams::ofString($auto->getList($query)));
104 $this->container->http()->saveResponse(
$response);
107 $this->container->http()->sendResponse();
108 $this->container->http()->close();
118 $this->
admin->requireEditable();
119 $this->
ctrlTo(
'setParameterByClass',
'hash', $this->config->legalDocuments()->document()->hash());
120 $this->
ctrlTo(
'redirectByClass',
'editDocument');
125 $this->
admin->requireEditable();
126 $this->container->tabs()->clearTargets();
127 $this->container->tabs()->setBackTarget($this->container->language()->txt(
'back'), $this->
ctrlTo(
'getLinkTargetByClass',
'documents'));
129 $document = $this->
admin->currentDocument()->value();
131 $this->container->language()->loadLanguageModule(
'meta');
133 $url = $this->
admin->targetWithDoc($this, $document,
'addCriterion',
'getFormAction');
134 $form = $this->
admin->criterionForm(
$url, $document);
136 $form = $this->
admin->withFormData($form,
function (array $x) use ($document) {
138 $this->
returnWithResult($this->config->legalDocuments()->document()->validateCriteriaContent($document->criteria(), $content)->map(
139 fn() => $this->config->legalDocuments()->document()->repository()->createCriterion($document, $content)
140 ),
'doc_crit_attached',
'documents');
143 $this->
admin->setContent($form);
148 $this->
admin->requireEditable();
150 $this->container->language()->loadLanguageModule(
'meta');
151 $url = $this->
admin->targetWithDocAndCriterion($this, $document, $criterion,
'editCriterion',
'getFormAction');
152 $form = $this->
admin->criterionForm(
$url, $document, $criterion->
content());
153 $form = $this->
admin->withFormData($form,
function (array
$data) use ($document, $criterion) {
155 $criteria = array_filter($document->
criteria(), fn(
Criterion $other) => $other->
id() !== $criterion->
id());
156 $this->
returnWithResult($this->config->legalDocuments()->document()->validateCriteriaContent($criteria, $content)->map(
157 fn() => $this->config->legalDocuments()->document()->repository()->updateCriterionContent($criterion->
id(), $content)
158 ),
'doc_crit_changed',
'documents');
161 $this->container->tabs()->clearTargets();
162 $this->container->tabs()->setBackTarget($this->container->language()->txt(
'back'), $this->
ctrlTo(
'getLinkTargetByClass',
'documents'));
163 $condition = $this->config->legalDocuments()->document()->toCondition($criterion->
content());
164 $this->container->ui()->mainTemplate()->setTitle(join(
' - ', [$document->
content()->title(), $condition->definition()->translatedType()]));
165 $this->
admin->setContent($form);
171 $this->
admin->requireEditable();
173 $this->config->legalDocuments()->document()->repository()->deleteCriterion($criterion->
id());
180 $this->
admin->requireEditable();
182 $raw_content = $this->
admin->uploadContent();
183 $sanitised_value = trim((
new HTMLPurifier())->purify($raw_content));
184 if ($this->
admin->isInvalidHTML($sanitised_value)) {
185 $sanitised_value = nl2br($sanitised_value);
188 $this->config->legalDocuments()->document()->repository()->updateDocumentContent($id,
new DocumentContent(
'html', $title, $sanitised_value));
189 $this->
admin->exitWithJsonResponse([
'status' => 1]);
195 $this->container->language()->loadLanguageModule(
'meta');
196 $this->container->tabs()->activateTab(
'documents');
198 if ($this->config->editable()) {
199 $this->container->toolbar()->addStickyItem($this->
admin->addDocumentButton($this->ctrlTo(
'getLinkTargetByClass',
'addDocument')));
203 $this->
admin->setContent($this->config->legalDocuments()->document()->table($this, __FUNCTION__, $edit_links));
208 $documents = $this->
admin->retrieveDocuments();
209 if ($documents === []) {
210 $this->
ui->mainTemplate()->setOnScreenMessage(
'failure', $this->
ui->txt(
'select_at_least_one_object'),
true);
211 $this->
ctrlTo(
'redirectByClass',
'documents');
223 $this->
admin->requireEditable();
224 $docs = $this->
admin->retrieveDocuments();
225 $this->
admin->deleteDocuments($docs);
226 ($this->after_document_deletion)();
227 $this->
returnWithMessage(count($docs) === 1 ?
'deleted_documents_s' :
'deleted_documents_p',
'documents');
232 $this->
admin->requireEditable();
233 $this->container->tabs()->clearTargets();
235 $content = fn() => $this->config->legalDocuments()->document()->repository()->findId($id)->map(fn(
$d) =>
$d->content());
236 $form = $this->
admin->documentForm($link, $title, $content, $may_be_new);
237 $form = $this->
admin->withFormData($form,
function (
$data) use ($id) {
238 $this->config->legalDocuments()->document()->repository()->updateDocumentTitle($id,
$data[0][
'title']);
242 $this->container->tabs()->setBackTarget($this->container->language()->txt(
'back'), $this->
ctrlTo(
'getLinkTargetByClass',
'documents'));
243 $this->container->tabs()->activateTab(
'documents');
244 $this->
admin->setContent($form);
250 $this->
admin->requireEditable();
252 $this->
admin->withDocumentsAndOrder($this->
admin->saveDocumentOrder(...));
255 $this->
ui->mainTemplate()->setOnScreenMessage(
'failure', $this->
ui->txt(
'ldoc_order_invalid'),
true);
256 $this->
ctrlTo(
'redirectByClass',
'documents');
264 public function tabs(array $run_after = []): void
267 $this->
tab(
'documents', $this->
ui->txt(
'agreement_documents_tab_label')),
268 $this->
tab(
'history', $this->
ui->txt(
'acceptance_history'), $this->
admin->canReadUserAdministration()),
275 private function tab(
string $cmd,
string $label,
bool $can_access =
true): array
277 return [$cmd, $label, $this->
ctrlTo(
'getLinkTargetByClass', $cmd), $can_access];
285 private function ctrlTo(
string $method, ...$args)
287 $path = [$this->parent_class, self::class];
288 if ($method ===
'setParameterByClass') {
291 return $this->container->ctrl()->$method(
$path, ...$args);
297 return $reflection->hasMethod($cmd)
298 && $reflection->getMethod($cmd)->isPublic()
299 && (string) $reflection->getMethod($cmd)->getReturnType() ===
'void' 300 && $reflection->getMethod($cmd)->getNumberOfParameters() === 0;
308 $this->
admin->requireEditable();
309 $this->container->tabs()->activateTab(
'documents');
310 $this->
admin->setContent($this->
admin->deleteDocumentsConfirmation(
311 $this->ctrlTo(
'getFormActionByClass',
'ignored'),
323 if (!is_string($error)) {
327 return match ($error) {
328 ProvideDocument::CRITERION_ALREADY_EXISTS => $this->
ui->txt(
'criterion_assignment_must_be_unique'),
329 ProvideDocument::CRITERION_WOULD_NEVER_MATCH => $this->
ui->txt(
'criterion_assignment_cannot_match'),
336 $this->
ui->mainTemplate()->setOnScreenMessage(
'success', $this->
ui->txt($message),
true);
337 $this->
ctrlTo(
'redirectByClass', $command);
342 if ($result->isOk()) {
343 $this->
ui->mainTemplate()->setOnScreenMessage(
'success', $this->
ui->txt($success_message),
true);
348 $this->
ctrlTo(
'redirectByClass', $target);
tab(string $cmd, string $label, bool $can_access=true)
deleteDocumentsConfirmation(array $documents)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
ctrlTo(string $method,... $args)
returnWithMessage(string $message, string $command)
Customizing of pimple-DIC for ILIAS.
readonly Container $container
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
criterionErrorMessage($error)
returnWithResult(Result $result, string $success_message, string $target)
tabs(array $run_after=[])
error()
Get the encapsulated error.
__construct(private readonly string $parent_class, private readonly Config $config, private readonly Closure $after_document_deletion, ?Container $container=null)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
readonly Administration $admin