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);
118 $documents = $this->config->legalDocuments()->document()->repository()->select($ids);
119 if (count($documents) !== count($ids)) {
128 $r = $this->container->refinery();
129 return $this->container->http()->wrapper()->post()->retrieve(
'ids', $this->container->refinery()->byTrying([
130 $r->in()->series([
$r->null(),
$r->always([])]),
131 $r->to()->listOf(
$r->kindlyTo()->int())
140 $with_doc_id = fn($document) => $then($this->
willLinkWith($gui, [
'doc_id' => $document->id()]), $document->content()->title(),
new NumberId($document),
false);
141 $with_hash = fn(
string $hash) => $then($this->
willLinkWith($gui, [
'hash' => $hash]),
'',
new HashId($hash),
true);
151 public function targetWithDoc(
object $gui, $document,
string $cmd,
string $method =
'getLinkTarget'): string
153 $link = $this->
willLinkWith($gui, [
'doc_id' => (
string) $document->id()]);
154 return $link($cmd, $method);
160 'doc_id' => (
string) $document->id(),
161 'criterion_id' => (string) $criterion->id(),
164 return $link($cmd, $method);
172 $class = is_string($gui) ? $gui : get_class($gui);
173 return function (
string $cmd, ?
string $method = null) use ($gui, $class, $parameters):
string {
174 $method ??= $class === $gui ?
'getLinkTargetByClass' :
'getLinkTarget';
175 $array = $this->container->ctrl()->getParameterArrayByClass($class);
176 foreach ($parameters as
$key => $value) {
177 $this->container->ctrl()->setParameterByClass($class,
$key, $value);
179 $link = $this->container->ctrl()->$method($gui, $cmd);
180 foreach ($parameters as
$key => $_) {
181 $this->container->ctrl()->setParameterByClass($class,
$key, $array[
$key] ??
'');
193 $request = $this->container->http()->request();
194 if ($request->getMethod() !==
'POST') {
197 $form = $form->withRequest($request);
198 $data = $form->getData();
200 if (
$data !== null) {
215 foreach ($array as $value) {
216 if ($predicate($value)) {
229 $repo = $this->config->legalDocuments()->document()->repository();
230 $doc_id = $this->container->http()->request()->getQueryParams()[
'doc_id'] ?? null;
231 return $this->container->refinery()->kindlyTo()->int()->applyTo(
new Ok($doc_id))->
then($repo->find(...));
236 $groups = $this->config->legalDocuments()->document()->conditionGroups($criterion);
237 $group = $this->
ui->create()->input()->field()->switchableGroup($groups->choices(), $this->
ui->txt(
'form_criterion'));
238 $value = $criterion ? $criterion->type() : $groups->defaultSelection();
240 $group = $group->withValue($value);
243 $title = $this->
ui->create()->input()->field()->text($this->
ui->txt(
'form_document'))->
withValue($document->
content()->title())->withDisabled(
true);
245 $section = $this->
ui->create()->input()->field()->section([
248 ], $this->
ui->txt($criterion ?
'form_edit_criterion_head' :
'form_attach_criterion_head'));
250 return $this->
ui->create()->input()->container()->form()->standard($url, [$section]);
255 return $this->container->http()->wrapper()->query()->retrieve(
'hash', $this->container->refinery()->to()->string());
262 public function tabs(array $tabs, array $run_after = []): void
264 foreach ($tabs as $tab) {
266 if (isset($run_after[$tab[0]])) {
267 $run_after[$tab[0]]();
275 $upload = $this->container->upload();
276 $upload->register(
new PreProcessor(
function (
string $content) use (&$value):
void {
280 $result_array = $upload->getResults();
281 if (count($result_array) !== 1 || !current($result_array)->isOk()) {
282 throw new Exception(
'Unexpected upload result.');
293 $this->
ui->mainTemplate()->setContent($this->
render($component));
298 return $this->
ui->create()->button()->primary(
299 $this->
ui->txt(
'add_document_btn_label'),
309 $this->
ui->mainTemplate()->setVariable($variable, $this->
render($component));
315 public function render($component): string
317 if (is_string($component)) {
320 return $this->container->ui()->renderer()->render($component);
329 return $this->
ui->create()
332 ->withButtons($buttons);
337 return $this->
ui->create()->button()->standard(
338 $this->
ui->txt(
'reset_for_all_users'),
349 $edit_link = $link(
'editDocument');
350 $content_title = $may_be_new ?
'form_document' :
'form_document_new';
352 $section = $this->
ui->create()->input()->field()->section([
353 'title' => $this->
ui->create()->input()->field()->text($this->
ui->txt(
'title'))->withRequired(
true)->withValue($title),
354 'content' => $this->
ui->create()->input()->field()->file(
new UploadHandler($link, $document_content, $this->
ui->txt(...)), $this->
ui->txt($content_title))->withAcceptedMimeTypes([
357 ])->withRequired($may_be_new),
358 ], $this->
ui->txt($may_be_new ?
'form_new_doc_head' :
'form_edit_doc_head'));
360 return $this->
ui->create()->input()->container()->form()->standard($edit_link, [$section]);
369 $update = $this->config->legalDocuments()->document()->repository()->updateDocumentOrder(...);
371 usort($documents, fn($document, $other) => $order_by_document[$document->id()] - $order_by_document[$other->id()]);
374 fn($document,
int $order) => $update(
new NumberId($document), $order),
376 range(10, 10 * count($documents), 10)
386 $to_int = $this->container->refinery()->byTrying([
387 $this->container->refinery()->kindlyTo()->int(),
388 $this->container->refinery()->in()->series([
389 $this->container->refinery()->to()->string(),
390 $this->container->refinery()->custom()->transformation(fn($s) => ltrim($s,
'0') ?:
'0'),
391 $this->container->refinery()->kindlyTo()->int(),
395 $order = $this->container->http()->request()->getParsedBody()[
'order'] ?? null;
396 if (!is_array($order)) {
400 $order = array_map($to_int, $order);
401 $document_ids = array_map($to_int, array_keys($order));
402 $order = array_combine($document_ids, array_values($order));
404 $documents = $this->config->legalDocuments()->document()->repository()->all();
406 foreach ($documents as $document) {
407 if (!isset($order[$document->id()])) {
408 $order[$document->id()] = $document->meta()->sorting();
412 return $proc($documents, $order);
419 $this->container->http()->saveResponse($this->container->http()->response()->withBody(
423 $this->container->http()->sendResponse();
424 $this->container->http()->close();
429 if (!$this->config->editable()) {
430 $this->container[
'ilErr']->raiseError($this->container->language()->txt(
'permission_denied'), $this->container[
'ilErr']->WARNING);
436 return $this->
ui->create()->messageBox()->info(
437 $this->
ui->txt(
'withdrawal_usr_deletion') .
': ' . $this->
ui->txt($enabled ?
'enabled' :
'disabled')
439 $this->
ui->create()->link()->standard(
440 $this->
ui->txt(
'adm_external_setting_edit'),
453 return (
new ValidHTML())->isTrue($string);
458 return $this->container->rbac()->system()->checkAccess(
'read',
USER_FOLDER_ID);
461 private function addTab(
string $id,
string $text,
string $link,
bool $can_access =
true): void
464 $this->container->tabs()->addTab($id, $text, $link);
externalSettingsMessage(bool $enabled)
then(callable $f)
Get a new result from the callable or do nothing if this is an error.
canReadUserAdministration()
setVariable(string $variable, $component)
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...
A result encapsulates a value or an error and simplifies the handling of those.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
tabs(array $tabs, array $run_after=[])
targetWithDocAndCriterion(object $gui, $document, $criterion, string $cmd, string $method='getLinkTarget')
isInvalidHTML(string $string)
Customizing of pimple-DIC for ILIAS.
withDocumentsAndOrder(Closure $proc)
deleteDocuments(array $documents)
withFormData($form, Closure $then)
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)
criterionForm(string $url, Document $document, $criterion=null)
resetBox(DateTimeImmutable $reset_date, array $buttons=[])
readonly Closure $confirmation
targetWithDoc(object $gui, $document, string $cmd, string $method='getLinkTarget')
static ofString(string $string)
Creates a new stream with an initial value.
withDocumentAndCriterion(Closure $proc)
addTab(string $id, string $text, string $link, bool $can_access=true)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
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)