19 declare(strict_types=1);
48 private readonly
string $parent_class,
49 private readonly
Config $config,
50 private readonly
Closure $after_document_deletion,
53 $this->container = $container ??
$GLOBALS[
'DIC'];
54 $this->container->language()->loadLanguageModule(
'ldoc');
56 $this->config->legalDocuments()->id(),
57 $this->container->ui(),
58 $this->container->language()
65 $cmd = $this->container->ctrl()->getCmd(
'documents');
67 throw new Exception(
'Unknown command: ' . $cmd);
74 if (!$this->
admin->canReadUserAdministration()) {
75 $this->container[
'ilErr']->raiseError($this->container->language()->txt(
'permission_denied'), $this->container[
'ilErr']->WARNING);
77 $this->container->tabs()->activateTab(
'history');
78 $this->
admin->setContent($this->config->legalDocuments()->history()->table(
89 $auto->setSearchFields([
'login',
'firstname',
'lastname',
'email']);
90 $auto->enableFieldSearchableCheck(
false);
91 $auto->setMoreLinkAvailable(
true);
93 if ($this->container->http()->wrapper()->query()->has(
'fetchall')) {
97 if ($this->container->http()->wrapper()->query()->has(
'term')) {
99 $this->container->http()->wrapper()->query()->retrieve(
'term', $this->container->refinery()->kindlyTo()->string())
103 ->withHeader(ResponseHeader::CONTENT_TYPE,
'application/json')
104 ->withBody(Streams::ofString($auto->getList($query)));
105 $this->container->http()->saveResponse(
$response);
108 $this->container->http()->sendResponse();
109 $this->container->http()->close();
119 $this->
admin->requireEditable();
120 $this->
ctrlTo(
'setParameterByClass',
'hash', $this->config->legalDocuments()->document()->hash());
121 $this->
ctrlTo(
'redirectByClass',
'editDocument');
126 $this->
admin->requireEditable();
127 $this->container->tabs()->clearTargets();
128 $this->container->tabs()->setBackTarget($this->container->language()->txt(
'back'), $this->
ctrlTo(
'getLinkTargetByClass',
'documents'));
130 $document = $this->
admin->currentDocument()->value();
132 $this->container->language()->loadLanguageModule(
'meta');
134 $url = $this->
admin->targetWithDoc($this, $document,
'addCriterion',
'getFormAction');
135 $form = $this->
admin->criterionForm(
$url, $document);
137 $form = $this->
admin->withFormData($form,
function (array $x) use ($document) {
139 $this->
returnWithResult($this->config->legalDocuments()->document()->validateCriteriaContent($document->criteria(), $content)->map(
140 fn() => $this->config->legalDocuments()->document()->repository()->createCriterion($document, $content)
141 ),
'doc_crit_attached',
'documents');
144 $this->
admin->setContent($form);
149 $this->
admin->requireEditable();
151 $this->container->language()->loadLanguageModule(
'meta');
152 $url = $this->
admin->targetWithDocAndCriterion($this, $document, $criterion,
'editCriterion',
'getFormAction');
153 $form = $this->
admin->criterionForm(
$url, $document, $criterion->
content());
154 $form = $this->
admin->withFormData($form,
function (array
$data) use ($document, $criterion) {
156 $criteria = array_filter($document->
criteria(), fn(
Criterion $other) => $other->
id() !== $criterion->
id());
157 $this->
returnWithResult($this->config->legalDocuments()->document()->validateCriteriaContent($criteria, $content)->map(
158 fn() => $this->config->legalDocuments()->document()->repository()->updateCriterionContent($criterion->
id(), $content)
159 ),
'doc_crit_changed',
'documents');
162 $this->container->tabs()->clearTargets();
163 $this->container->tabs()->setBackTarget($this->container->language()->txt(
'back'), $this->
ctrlTo(
'getLinkTargetByClass',
'documents'));
164 $condition = $this->config->legalDocuments()->document()->toCondition($criterion->
content());
165 $this->container->ui()->mainTemplate()->setTitle(join(
' - ', [$document->
content()->title(), $condition->definition()->translatedType()]));
166 $this->
admin->setContent($form);
172 $this->
admin->requireEditable();
174 $this->config->legalDocuments()->document()->repository()->deleteCriterion($criterion->
id());
181 $this->
admin->requireEditable();
183 $raw_content = $this->
admin->uploadContent();
184 $sanitised_value = trim((
new HTMLPurifier())->purify($raw_content));
185 if ($this->
admin->isInvalidHTML($sanitised_value)) {
186 $sanitised_value = nl2br($sanitised_value);
189 $this->config->legalDocuments()->document()->repository()->updateDocumentContent($id,
new DocumentContent(
'html', $title, $sanitised_value));
190 $this->
admin->exitWithJsonResponse([
'status' => 1]);
196 $this->container->language()->loadLanguageModule(
'meta');
197 $this->container->tabs()->activateTab(
'documents');
199 if ($this->config->editable()) {
200 $this->container->toolbar()->addStickyItem($this->
admin->addDocumentButton($this->ctrlTo(
'getLinkTargetByClass',
'addDocument')));
204 $this->
admin->setContent($this->config->legalDocuments()->document()->table($this, __FUNCTION__, $edit_links));
209 $documents = $this->
admin->retrieveDocuments();
210 if ($documents === []) {
211 $this->
ui->mainTemplate()->setOnScreenMessage(
'failure', $this->
ui->txt(
'select_at_least_one_object'),
true);
212 $this->
ctrlTo(
'redirectByClass',
'documents');
224 $this->
admin->requireEditable();
225 $docs = $this->
admin->retrieveDocuments();
226 $this->
admin->deleteDocuments($docs);
227 ($this->after_document_deletion)();
228 $this->
returnWithMessage(count($docs) === 1 ?
'deleted_documents_s' :
'deleted_documents_p',
'documents');
233 $this->
admin->requireEditable();
234 $this->container->tabs()->clearTargets();
236 $content = fn() => $this->config->legalDocuments()->document()->repository()->findId($id)->map(fn(
$d) =>
$d->content());
237 $form = $this->
admin->documentForm($link, $title, $content, $may_be_new);
238 $form = $this->
admin->withFormData($form,
function (
$data) use ($id) {
239 $this->config->legalDocuments()->document()->repository()->updateDocumentTitle($id,
$data[0][
'title']);
243 $this->container->tabs()->setBackTarget($this->container->language()->txt(
'back'), $this->
ctrlTo(
'getLinkTargetByClass',
'documents'));
244 $this->container->tabs()->activateTab(
'documents');
245 $this->
admin->setContent($form);
251 $this->
admin->requireEditable();
253 $this->
admin->withDocumentsAndOrder($this->
admin->saveDocumentOrder(...));
256 $this->
ui->mainTemplate()->setOnScreenMessage(
'failure', $this->
ui->txt(
'ldoc_order_invalid'),
true);
257 $this->
ctrlTo(
'redirectByClass',
'documents');
265 public function tabs(array $run_after = []): void
268 $this->
tab(
'documents', $this->
ui->txt(
'agreement_documents_tab_label')),
269 $this->
tab(
'history', $this->
ui->txt(
'acceptance_history'), $this->
admin->canReadUserAdministration()),
273 private function tab(
string $cmd,
string $label,
bool $can_access =
true): array
275 return [$cmd, $label, $this->
ctrlTo(
'getLinkTargetByClass', $cmd), $can_access];
283 private function ctrlTo(
string $method, ...$args)
285 $path = [$this->parent_class, self::class];
286 if ($method ===
'setParameterByClass') {
289 return $this->container->ctrl()->$method(
$path, ...$args);
295 return $reflection->hasMethod($cmd)
296 && $reflection->getMethod($cmd)->isPublic()
297 && (string) $reflection->getMethod($cmd)->getReturnType() ===
'void' 298 && $reflection->getMethod($cmd)->getNumberOfParameters() === 0;
306 $this->
admin->requireEditable();
307 $this->container->tabs()->activateTab(
'documents');
308 $this->
admin->setContent($this->
admin->deleteDocumentsConfirmation(
309 $this->ctrlTo(
'getFormActionByClass',
'ignored'),
321 if (!is_string($error)) {
325 return match ($error) {
326 ProvideDocument::CRITERION_ALREADY_EXISTS => $this->
ui->txt(
'criterion_assignment_must_be_unique'),
327 ProvideDocument::CRITERION_WOULD_NEVER_MATCH => $this->
ui->txt(
'criterion_assignment_cannot_match'),
334 $this->
ui->mainTemplate()->setOnScreenMessage(
'success', $this->
ui->txt($message),
true);
335 $this->
ctrlTo(
'redirectByClass', $command);
340 if ($result->isOk()) {
341 $this->
ui->mainTemplate()->setOnScreenMessage(
'success', $this->
ui->txt($success_message),
true);
346 $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)
A result encapsulates a value or an error and simplifies the handling of those.
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