19 declare(strict_types=1);
57 private readonly
Config $config,
59 private readonly
UI $ui,
70 $items = array_column(
array_map(fn($x) => [$x->id(), $x->content()->title()], $documents), 1, 0);
76 $this->
ui->txt(
'sure_delete_documents_p'),
87 $this->config->legalDocuments()->document()->repository()->deleteDocument(...),
98 $criterion_id = ($this->container->http()->request()->getQueryParams()[
'criterion_id'] ?? null);
99 if (null === $criterion_id) {
102 $criterion_id = (
int) $criterion_id;
104 $criterion = $this->
find(
105 fn($criterion) => $criterion->id() === $criterion_id,
106 $document->criteria()
112 $proc($document, $criterion);
121 $documents = $this->config->legalDocuments()->document()->repository()->select($ids);
122 if (count($documents) !== count($ids)) {
134 $r = $this->container->refinery();
135 return $this->container->http()->wrapper()->post()->retrieve(
'ids', $this->container->refinery()->byTrying([
136 $r->in()->series([
$r->null(),
$r->always([])]),
137 $r->to()->listOf(
$r->kindlyTo()->int())
146 $with_doc_id = fn($document) => $then($this->
willLinkWith($gui, [
'doc_id' => $document->id()]), $document->content()->title(),
new NumberId($document),
false);
147 $with_hash = fn(
string $hash) => $then($this->
willLinkWith($gui, [
'hash' => $hash]),
'',
new HashId($hash),
true);
157 public function targetWithDoc(
object $gui,
Document $document,
string $cmd,
string $method =
'getLinkTarget'): string
159 $link = $this->
willLinkWith($gui, [
'doc_id' => (
string) $document->
id()]);
160 return $link($cmd, $method);
166 'doc_id' => (
string) $document->
id(),
167 'criterion_id' => (string) $criterion->
id(),
170 return $link($cmd, $method);
180 $class = is_string($gui) ? $gui : $gui::class;
181 return function (
string $cmd, ?
string $method = null) use ($gui, $class, $parameters):
string {
182 $method ??= $class === $gui ?
'getLinkTargetByClass' :
'getLinkTarget';
183 $array = $this->container->ctrl()->getParameterArrayByClass($class);
184 foreach ($parameters as $key => $value) {
185 $this->container->ctrl()->setParameterByClass($class, (
string) $key, $value);
187 $link = $this->container->ctrl()->$method($gui, $cmd);
188 foreach ($parameters as $key => $_) {
189 $this->container->ctrl()->setParameterByClass($class, (
string) $key, $array[$key] ??
'');
201 $request = $this->container->http()->request();
202 if ($request->getMethod() !==
'POST') {
208 if (
$data !== null) {
223 foreach ($array as $value) {
224 if ($predicate($value)) {
237 $repo = $this->config->legalDocuments()->document()->repository();
238 $doc_id = $this->container->http()->request()->getQueryParams()[
'doc_id'] ?? null;
239 return $this->container->refinery()->kindlyTo()->int()->applyTo(
new Ok($doc_id))->then($repo->find(...));
244 $groups = $this->config->legalDocuments()->document()->conditionGroups($criterion);
245 $group = $this->
ui->create()->input()->field()->switchableGroup($groups->choices(), $this->
ui->txt(
'form_criterion'));
246 $value = $criterion ? $criterion->type() : $groups->defaultSelection();
248 $group = $group->withValue($value);
251 $title = $this->
ui->create()->input()->field()->text($this->
ui->txt(
'form_document'))->
withValue($document->
content()->title())->withDisabled(
true);
253 $section = $this->
ui->create()->input()->field()->section([
256 ], $this->
ui->txt($criterion ?
'form_edit_criterion_head' :
'form_attach_criterion_head'));
258 return $this->
ui->create()->input()->container()->form()->standard($url, [$section]);
263 return $this->container->http()->wrapper()->query()->retrieve(
'hash', $this->container->refinery()->to()->string());
270 public function tabs(array $tabs, array $run_after = []): void
272 foreach ($tabs as $tab) {
274 if (isset($run_after[$tab[0]])) {
275 $run_after[$tab[0]]();
283 $upload = $this->container->upload();
284 $upload->register(
new PreProcessor(
function (
string $content) use (&$value):
void {
288 $result_array = $upload->getResults();
289 if (count($result_array) !== 1 || !current($result_array)->isOk()) {
290 throw new Exception(
'Unexpected upload result.');
301 $this->
ui->mainTemplate()->setContent($this->
render($component));
306 return $this->
ui->create()->button()->primary(
307 $this->
ui->txt(
'add_document_btn_label'),
317 $this->
ui->mainTemplate()->setVariable($variable, $this->
render($component));
323 public function render($component): string
325 if (is_string($component)) {
328 return $this->container->ui()->renderer()->render($component);
337 return $this->
ui->create()
340 ->withButtons($buttons);
345 return $this->
ui->create()->button()->standard(
346 $this->
ui->txt(
'reset_for_all_users'),
357 $edit_link = $link(
'editDocument');
358 $content_title = $may_be_new ?
'form_document' :
'form_document_new';
360 $section = $this->
ui->create()->input()->field()->section([
361 'title' => $this->
ui->create()->input()->field()->text($this->
ui->txt(
'title'))->withRequired(
true)->withValue($title),
362 'content' => $this->
ui->create()->input()->field()->file(
new UploadHandler($link, $document_content, $this->
ui->txt(...)), $this->
ui->txt($content_title))->withAcceptedMimeTypes([
365 ])->withRequired($may_be_new),
366 ], $this->
ui->txt($may_be_new ?
'form_new_doc_head' :
'form_edit_doc_head'));
368 return $this->
ui->create()->input()->container()->form()->standard($edit_link, [$section]);
377 $update = $this->config->legalDocuments()->document()->repository()->updateDocumentOrder(...);
379 usort($documents, fn($document, $other) => $order_by_document[$document->id()] - $order_by_document[$other->id()]);
382 fn($document,
int $order) => $update(
new NumberId($document), $order),
384 range(10, 10 * count($documents), 10)
397 $to_int = $this->container->refinery()->byTrying([
398 $this->container->refinery()->kindlyTo()->int(),
399 $this->container->refinery()->in()->series([
400 $this->container->refinery()->to()->string(),
401 $this->container->refinery()->custom()->transformation(fn($s) => ltrim($s,
'0') ?:
'0'),
402 $this->container->refinery()->kindlyTo()->int(),
406 $order = $this->container->http()->request()->getParsedBody()[
'order'] ?? null;
407 if (!is_array($order)) {
412 $document_ids =
array_map($to_int, array_keys($order));
413 $order = array_combine($document_ids, array_values($order));
415 $documents = $this->config->legalDocuments()->document()->repository()->all();
417 foreach ($documents as $document) {
418 if (!isset($order[$document->id()])) {
419 $order[$document->id()] = $document->meta()->sorting();
423 return $proc($documents, $order);
430 $this->container->http()->saveResponse($this->container->http()->response()->withBody(
434 $this->container->http()->sendResponse();
435 $this->container->http()->close();
440 if (!$this->config->editable()) {
441 $this->container[
'ilErr']->raiseError($this->container->language()->txt(
'permission_denied'), $this->container[
'ilErr']->WARNING);
447 $message_box = $this->
ui->create()->messageBox()->info(
448 $this->
ui->txt(
'withdrawal_usr_deletion') .
': ' . $this->
ui->txt($enabled ?
'enabled' :
'disabled')
455 return $message_box->withLinks([
456 $this->
ui->create()->link()->standard(
457 $this->
ui->txt(
'adm_external_setting_edit'),
470 return (
new ValidHTML())->isTrue($string);
475 return $this->container->rbac()->system()->checkAccess(
'read',
USER_FOLDER_ID);
480 return $this->container->rbac()->system()->checkAccess(
'write',
USER_FOLDER_ID);
483 private function addTab(
string $id,
string $text,
string $link,
bool $can_access =
true): void
486 $this->container->tabs()->addTab($id, $text, $link);
externalSettingsMessage(bool $enabled)
canReadUserAdministration()
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ilObjUser $user=null,)
confirmation()
description: > Example for rendering a confirmation message box.
setVariable(string $variable, $component)
criterionForm(string $url, Document $document, ?CriterionContent $criterion=null)
deleteDocumentsConfirmation(string $form_link, string $submit_command, string $cancel_command, array $documents)
exitWithJsonResponse($value)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
targetWithDoc(object $gui, Document $document, string $cmd, string $method='getLinkTarget')
withFormData(Form $form, Closure $then)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
tabs(array $tabs, array $run_after=[])
canWriteUserAdministration()
isInvalidHTML(string $string)
Customizing of pimple-DIC for ILIAS.
withDocumentsAndOrder(Closure $proc)
A
deleteDocuments(array $documents)
find(Closure $predicate, array $array)
A
isValidHTML(string $string)
idOrHash(object $gui, Closure $then)
A result encapsulates a value or an error and simplifies the handling of those.
saveDocumentOrder(array $documents, array $order_by_document)
__construct(private readonly Config $config, private readonly Container $container, private readonly UI $ui, ?Closure $confirmation=null)
resetBox(DateTimeImmutable $reset_date, array $buttons=[])
readonly Closure $confirmation
static ofString(string $string)
Creates a new stream with an initial value.
targetWithDocAndCriterion(object $gui, Document $document, Criterion $criterion, string $cmd, string $method='getLinkTarget')
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
withDocumentAndCriterion(Closure $proc)
addTab(string $id, string $text, string $link, bool $can_access=true)
documentForm(Closure $link, string $title, Closure $document_content, bool $may_be_new)
willLinkWith($gui, array $parameters=[])
resetButton(string $confirm_reset_link)
addDocumentButton(string $add_document_link)