19 declare(strict_types=1);
63 private readonly
Config $config,
65 private readonly
UI $ui,
71 $this->http_wrapper = $http_wrapper ?? $this->container->http()->wrapper();
72 $this->
refinery = $refinery ?? $this->container->refinery();
80 $items = array_column(
array_map(fn($x) => [$x->id(), $x->content()->title()], $documents), 1, 0);
86 $this->
ui->txt(
'sure_delete_documents_p'),
97 $this->config->legalDocuments()->document()->repository()->deleteDocument(...),
108 $criterion_id = ($this->container->http()->request()->getQueryParams()[
'criterion_id'] ??
null);
109 if (
null === $criterion_id) {
112 $criterion_id = (
int) $criterion_id;
114 $criterion = $this->
find(
115 fn($criterion) => $criterion->id() === $criterion_id,
116 $document->criteria()
122 $proc($document, $criterion);
131 $documents = $this->config->legalDocuments()->document()->repository()->select($ids);
132 if (count($documents) !== count($ids)) {
146 $this->container->refinery()->kindlyTo()->listOf(
147 $this->container->refinery()->kindlyTo()->int()
168 if (current($ids) ===
'ALL_OBJECTS') {
170 foreach ($this->config->legalDocuments()->document()->repository()->all() as $document) {
171 $ids[] = $document->id();
181 return $this->container->http()->wrapper()->post()->retrieve(
183 $this->container->refinery()->byTrying([
185 $this->container->refinery()->always($default)
192 return $this->container->http()->wrapper()->query()->retrieve(
194 $this->container->refinery()->byTrying([
196 $this->container->refinery()->always($default)
206 $with_doc_id = fn($document) => $then($this->
willLinkWith($gui, [
'doc_id' => $document->id()]), $document->content()->title(),
new NumberId($document),
false);
207 $with_hash = fn(
string $hash) => $then($this->
willLinkWith($gui, [
'hash' => $hash]),
'',
new HashId($hash),
true);
217 public function targetWithDoc(
object $gui,
Document $document,
string $cmd,
string $method =
'getLinkTarget'): string
219 $link = $this->
willLinkWith($gui, [
'doc_id' => (
string) $document->
id()]);
220 return $link($cmd, $method);
226 'doc_id' => (
string) $document->
id(),
227 'criterion_id' => (string) $criterion->
id(),
230 return $link($cmd, $method);
240 $class = is_string($gui) ? $gui : $gui::class;
241 return function (
string $cmd, ?
string $method =
null) use ($gui, $class, $parameters):
string {
242 $method ??= $class === $gui ?
'getLinkTargetByClass' :
'getLinkTarget';
243 $array = $this->container->ctrl()->getParameterArrayByClass($class);
244 foreach ($parameters as $key => $value) {
245 $this->container->ctrl()->setParameterByClass($class, (
string) $key, $value);
247 $link = $this->container->ctrl()->$method($gui, $cmd);
248 foreach ($parameters as $key => $_) {
249 $this->container->ctrl()->setParameterByClass($class, (
string) $key, $array[$key] ??
'');
261 $request = $this->container->http()->request();
262 if ($request->getMethod() !==
'POST') {
283 foreach ($array as $value) {
284 if ($predicate($value)) {
309 $doc_id = current($doc_id) ?:
null;
312 $repo = $this->config->legalDocuments()->document()->repository();
314 return $this->
refinery->kindlyTo()->int()->applyTo(
new Ok($doc_id))->then($repo->find(...));
319 $groups = $this->config->legalDocuments()->document()->conditionGroups($criterion);
320 $group = $this->
ui->create()->input()->field()->switchableGroup($groups->choices(), $this->
ui->txt(
'form_criterion'));
321 $value = $criterion ? $criterion->type() : $groups->defaultSelection();
323 $group = $group->withValue($value);
326 $title = $this->
ui->create()->input()->field()->text($this->
ui->txt(
'form_document'))->
withValue($document->
content()->title())->withDisabled(
true);
328 $section = $this->
ui->create()->input()->field()->section([
331 ], $this->
ui->txt($criterion ?
'form_edit_criterion_head' :
'form_attach_criterion_head'));
333 return $this->
ui->create()->input()->container()->form()->standard($url, [$section]);
338 return $this->container->http()->wrapper()->query()->retrieve(
'hash', $this->container->refinery()->to()->string());
345 public function tabs(array $tabs, array $run_after = []): void
347 foreach ($tabs as $tab) {
349 if (isset($run_after[$tab[0]])) {
350 $run_after[$tab[0]]();
358 $upload = $this->container->upload();
359 $upload->register(
new PreProcessor(
function (
string $content) use (&$value):
void {
363 $result_array = $upload->getResults();
364 if (count($result_array) !== 1 || !current($result_array)->isOk()) {
365 throw new Exception(
'Unexpected upload result.');
376 $this->
ui->mainTemplate()->setContent($this->
render($component));
381 return $this->
ui->create()->button()->primary(
382 $this->
ui->txt(
'add_document_btn_label'),
392 $this->
ui->mainTemplate()->setVariable($variable, $this->
render($component));
398 public function render($component): string
400 if (is_string($component)) {
403 return $this->container->ui()->renderer()->render($component);
412 return $this->
ui->create()
415 ->withButtons($buttons);
420 return $this->
ui->create()->button()->standard(
421 $this->
ui->txt(
'reset_for_all_users'),
432 $edit_link = $link(
'editDocument');
433 $content_title = $may_be_new ?
'form_document' :
'form_document_new';
435 $section = $this->
ui->create()->input()->field()->section([
436 'title' => $this->
ui->create()->input()->field()->text($this->
ui->txt(
'title'))->withRequired(
true)->withValue($title),
437 'content' => $this->
ui->create()->input()->field()->file(
new UploadHandler($link, $document_content, $this->
ui->txt(...)), $this->
ui->txt($content_title))->withAcceptedMimeTypes([
440 ])->withRequired($may_be_new),
441 ], $this->
ui->txt($may_be_new ?
'form_new_doc_head' :
'form_edit_doc_head'));
443 return $this->
ui->create()->input()->container()->form()->standard($edit_link, [$section]);
452 $update = $this->config->legalDocuments()->document()->repository()->updateDocumentOrder(...);
454 usort($documents, fn($document, $other) => $order_by_document[$document->id()] - $order_by_document[$other->id()]);
457 fn($document,
int $order) => $update(
new NumberId($document), $order),
459 range(10, 10 * count($documents), 10)
472 $to_int = $this->container->refinery()->byTrying([
473 $this->container->refinery()->kindlyTo()->int(),
474 $this->container->refinery()->in()->series([
475 $this->container->refinery()->to()->string(),
476 $this->container->refinery()->custom()->transformation(fn($s) => ltrim($s,
'0') ?:
'0'),
477 $this->container->refinery()->kindlyTo()->int(),
481 $order = $this->container->http()->request()->getParsedBody();
482 if (!is_array($order)) {
487 $document_ids =
array_map($to_int, array_keys($order));
488 $order = array_combine($document_ids, array_values($order));
490 $documents = $this->config->legalDocuments()->document()->repository()->all();
492 foreach ($documents as $document) {
493 if (!isset($order[$document->id()])) {
494 $order[$document->id()] = $document->meta()->sorting();
498 return $proc($documents, $order);
505 $this->container->http()->saveResponse($this->container->http()->response()->withBody(
509 $this->container->http()->sendResponse();
510 $this->container->http()->close();
515 if (!$this->config->editable()) {
516 $this->container[
'ilErr']->raiseError($this->container->language()->txt(
'permission_denied'), $this->container[
'ilErr']->WARNING);
522 $message_box = $this->
ui->create()->messageBox()->info(
523 $this->
ui->txt(
'withdrawal_usr_deletion') .
': ' . $this->
ui->txt($enabled ?
'enabled' :
'disabled')
530 return $message_box->withLinks([
531 $this->
ui->create()->link()->standard(
532 $this->
ui->txt(
'adm_external_setting_edit'),
545 return (
new ValidHTML())->isTrue($string);
550 return $this->container->rbac()->system()->checkAccess(
'read',
USER_FOLDER_ID);
555 return $this->container->rbac()->system()->checkAccess(
'write',
USER_FOLDER_ID);
558 private function addTab(
string $id,
string $text,
string $link,
bool $can_access =
true): void
561 $this->container->tabs()->addTab($id, $text, $link);
externalSettingsMessage(bool $enabled)
canReadUserAdministration()
confirmation()
description: > Example for rendering a confirmation message box.
retrieveValueOrDefaultFromQuery(string $key, Transformation $transformation, mixed $default=null)
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)
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
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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)
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
retrieveValueOrDefaultFromPost(string $key, Transformation $transformation, mixed $default=null)
withDocumentAndCriterion(Closure $proc)
addTab(string $id, string $text, string $link, bool $can_access=true)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
documentForm(Closure $link, string $title, Closure $document_content, bool $may_be_new)
willLinkWith($gui, array $parameters=[])
resetButton(string $confirm_reset_link)
WrapperFactory $http_wrapper
__construct(private readonly Config $config, private readonly Container $container, private readonly UI $ui, ?Closure $confirmation=null, ?WrapperFactory $http_wrapper=null, ?Factory $refinery=null)
addDocumentButton(string $add_document_link)