19declare(strict_types=1);
35use InvalidArgumentException;
65 private readonly
Config $config,
67 private readonly
UI $ui,
73 $this->http_wrapper =
$http_wrapper ?? $this->container->http()->wrapper();
74 $this->
refinery = $refinery ?? $this->container->refinery();
82 $items = array_column(array_map(fn($x) => [$x->id(), $x->content()->title()], $documents), 1, 0);
88 $this->
ui->txt(
'sure_delete_documents_p'),
99 $this->config->legalDocuments()->document()->repository()->deleteDocument(...),
110 $criterion_id = ($this->container->http()->request()->getQueryParams()[
'criterion_id'] ??
null);
111 if (
null === $criterion_id) {
112 throw new InvalidArgumentException(
'Missing query parameter criterion_id.');
114 $criterion_id = (
int) $criterion_id;
116 $criterion = $this->
find(
117 fn($criterion) => $criterion->id() === $criterion_id,
118 $document->criteria()
121 throw new InvalidArgumentException(
'Invalid criterion_id given.');
124 $proc($document, $criterion);
133 $documents = $this->config->legalDocuments()->document()->repository()->select($ids);
134 if (count($documents) !== count($ids)) {
135 throw new InvalidArgumentException(
'List contains invalid documents.');
148 $this->container->refinery()->kindlyTo()->listOf(
149 $this->container->refinery()->kindlyTo()->int()
157 $this->
refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int()),
166 $this->
refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string()),
170 if (current($ids) ===
'ALL_OBJECTS') {
172 foreach ($this->config->legalDocuments()->document()->repository()->all() as $document) {
173 $ids[] = $document->id();
183 return $this->container->http()->wrapper()->post()->retrieve(
185 $this->container->refinery()->byTrying([
187 $this->container->refinery()->always($default)
194 return $this->container->http()->wrapper()->query()->retrieve(
196 $this->container->refinery()->byTrying([
198 $this->container->refinery()->always($default)
206 public function idOrHash(
object $gui, Closure $then): void
208 $with_doc_id = fn($document) => $then($this->
willLinkWith($gui, [
'doc_id' => $document->id()]), $document->content()->title(),
new NumberId($document),
false);
209 $with_hash = fn(
string $hash) => $then($this->
willLinkWith($gui, [
'hash' => $hash]),
'',
new HashId($hash),
true);
219 public function targetWithDoc(
object $gui,
Document $document,
string $cmd,
string $method =
'getLinkTarget'): string
221 $link = $this->
willLinkWith($gui, [
'doc_id' => (
string) $document->
id()]);
222 return $link($cmd, $method);
228 'doc_id' => (
string) $document->
id(),
229 'criterion_id' => (
string) $criterion->
id(),
232 return $link($cmd, $method);
242 $class = is_string($gui) ? $gui : $gui::class;
243 return function (
string $cmd, ?
string $method =
null) use ($gui, $class, $parameters):
string {
244 $method ??= $class === $gui ?
'getLinkTargetByClass' :
'getLinkTarget';
245 $array = $this->container->ctrl()->getParameterArrayByClass($class);
246 foreach ($parameters as $key => $value) {
247 $this->container->ctrl()->setParameterByClass($class, (
string) $key, $value);
249 $link = $this->container->ctrl()->$method($gui, $cmd);
250 foreach ($parameters as $key => $_) {
251 $this->container->ctrl()->setParameterByClass($class, (
string) $key, $array[$key] ??
'');
263 $request = $this->container->http()->request();
264 if ($request->getMethod() !==
'POST') {
270 if (
$data !==
null) {
283 public function find(Closure $predicate, array $array)
285 foreach ($array as $value) {
286 if ($predicate($value)) {
308 $this->
refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int()),
311 $doc_id = current($doc_id) ?:
null;
314 $repo = $this->config->legalDocuments()->document()->repository();
316 return $this->
refinery->kindlyTo()->int()->applyTo(
new Ok($doc_id))->then($repo->find(...));
321 $groups = $this->config->legalDocuments()->document()->conditionGroups($criterion);
322 $group = $this->
ui->create()->input()->field()->switchableGroup($groups->choices(), $this->ui->txt(
'form_criterion'));
323 $value = $criterion ? $criterion->type() : $groups->defaultSelection();
325 $group = $group->withValue($value);
328 $this->
ui->mainTemplate()->setOnScreenMessage(
329 $this->
ui->mainTemplate()::MESSAGE_TYPE_INFO,
330 $this->ui->txt(
'form_criterion_standard_fields_info_text')
333 $title = $this->
ui->create()->input()->field()->text($this->
ui->txt(
'form_document'))->withValue($document->
content()->title())->withDisabled(
true);
335 $section = $this->
ui->create()->input()->field()->section([
338 ], $this->
ui->txt($criterion ?
'form_edit_criterion_head' :
'form_attach_criterion_head'));
340 return $this->
ui->create()->input()->container()->form()->standard($url, [$section]);
345 return $this->container->http()->wrapper()->query()->retrieve(
'hash', $this->container->refinery()->to()->string());
352 public function tabs(array $tabs, array $run_after = []): void
354 foreach ($tabs as $tab) {
356 if (isset($run_after[$tab[0]])) {
357 $run_after[$tab[0]]();
365 $upload = $this->container->upload();
366 $upload->register(
new PreProcessor(
function (
string $content) use (&$value):
void {
370 $result_array = $upload->getResults();
371 if (count($result_array) !== 1 || !current($result_array)->isOk()) {
372 throw new Exception(
'Unexpected upload result.');
383 $this->
ui->mainTemplate()->setContent($this->
render($component));
388 return $this->
ui->create()->button()->primary(
389 $this->
ui->txt(
'add_document_btn_label'),
399 $this->
ui->mainTemplate()->setVariable($variable, $this->
render($component));
405 public function render($component): string
407 if (is_string($component)) {
410 return $this->container->ui()->renderer()->render($component);
419 return $this->
ui->create()
422 ->withButtons($buttons);
427 return $this->
ui->create()->button()->standard(
428 $this->
ui->txt(
'reset_for_all_users'),
437 public function documentForm(Closure $link,
string $title, Closure $document_content,
bool $may_be_new):
Form
439 $field = $this->
ui->create()->input()->field();
440 $edit_link = $link(
'editDocument');
441 $content_title = $may_be_new ?
'form_document' :
'form_document_new';
443 $require = $this->container->refinery()->custom()->constraint(fn($x) => (
bool) $x, $this->
ui->txt(
'title_required'));
445 $section = $field->section([
446 'title' => $field->text($this->ui->txt(
'title'))->withRequired(
true, $require)->withValue($title),
447 'content' => $field->file(
new UploadHandler($link, $document_content, $this->
ui->txt(...)), $this->ui->txt($content_title))->withAcceptedMimeTypes([
450 ])->withRequired($may_be_new),
451 ], $this->ui->txt($may_be_new ?
'form_new_doc_head' :
'form_edit_doc_head'));
453 return $this->
ui->create()->input()->container()->form()->standard($edit_link, [$section]);
462 $update = $this->config->legalDocuments()->document()->repository()->updateDocumentOrder(...);
464 usort($documents, fn($document, $other) => $order_by_document[$document->id()] - $order_by_document[$other->id()]);
467 fn($document,
int $order) => $update(
new NumberId($document), $order),
469 range(10, 10 * count($documents), 10)
482 $to_int = $this->container->refinery()->byTrying([
483 $this->container->refinery()->kindlyTo()->int(),
484 $this->container->refinery()->in()->series([
485 $this->container->refinery()->to()->string(),
486 $this->container->refinery()->custom()->transformation(fn($s) => ltrim($s,
'0') ?:
'0'),
487 $this->container->refinery()->kindlyTo()->int(),
491 $order = $this->container->http()->request()->getParsedBody();
492 if (!is_array($order)) {
493 throw new InvalidArgumentException(
'Invalid order given. List of numbers expected.');
496 $order = array_map($to_int, $order);
497 $document_ids = array_map($to_int, array_keys($order));
498 $order = array_combine($document_ids, array_values($order));
500 $documents = $this->config->legalDocuments()->document()->repository()->all();
502 foreach ($documents as $document) {
503 if (!isset($order[$document->id()])) {
504 $order[$document->id()] = $document->meta()->sorting();
508 return $proc($documents, $order);
515 $this->container->http()->saveResponse($this->container->http()->response()->withBody(
519 $this->container->http()->sendResponse();
520 $this->container->http()->close();
525 if (!$this->config->editable()) {
526 $this->container[
'ilErr']->raiseError($this->container->language()->txt(
'permission_denied'), $this->container[
'ilErr']->WARNING);
532 $message_box = $this->
ui->create()->messageBox()->info(
533 $this->
ui->txt(
'withdrawal_usr_deletion') .
': ' . $this->ui->txt($enabled ?
'enabled' :
'disabled')
540 $this->container->language()->loadLanguageModule(
'administration');
542 $this->container->ctrl()->setParameterByClass(SettingsGUI::class,
'ref_id', (
string)
USER_FOLDER_ID);
543 return $message_box->withLinks([
544 $this->
ui->create()->link()->standard(
545 $this->ui->txt(
'adm_external_setting_edit'),
546 $this->container->ctrl()->getLinkTargetByClass([ilAdministrationGUI::class, ilObjUserFolderGUI::class, SettingsGUI::class],
'show')
558 return (
new ValidHTML())->isTrue($string);
563 return $this->container->rbac()->system()->checkAccess(
'read',
USER_FOLDER_ID);
568 return $this->container->rbac()->system()->checkAccess(
'write',
USER_FOLDER_ID);
571 private function addTab(
string $id,
string $text,
string $link,
bool $can_access =
true): void
574 $this->container->tabs()->addTab(
$id,
$text, $link);
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Customizing of pimple-DIC for ILIAS.
A result encapsulates a value or an error and simplifies the handling of those.
Stream factory which enables the user to create streams without the knowledge of the concrete class.
static ofString(string $string)
Creates a new stream with an initial value.
canWriteUserAdministration()
documentForm(Closure $link, string $title, Closure $document_content, bool $may_be_new)
isValidHTML(string $string)
__construct(private readonly Config $config, private readonly Container $container, private readonly UI $ui, ?Closure $confirmation=null, ?WrapperFactory $http_wrapper=null, ?Factory $refinery=null)
deleteDocumentsConfirmation(string $form_link, string $submit_command, string $cancel_command, array $documents)
withDocumentAndCriterion(Closure $proc)
resetBox(DateTimeImmutable $reset_date, array $buttons=[])
readonly Closure $confirmation
addTab(string $id, string $text, string $link, bool $can_access=true)
isInvalidHTML(string $string)
targetWithDoc(object $gui, Document $document, string $cmd, string $method='getLinkTarget')
find(Closure $predicate, array $array)
@template A
retrieveValueOrDefaultFromQuery(string $key, Transformation $transformation, mixed $default=null)
addDocumentButton(string $add_document_link)
tabs(array $tabs, array $run_after=[])
externalSettingsMessage(bool $enabled)
canReadUserAdministration()
willLinkWith($gui, array $parameters=[])
saveDocumentOrder(array $documents, array $order_by_document)
retrieveValueOrDefaultFromPost(string $key, Transformation $transformation, mixed $default=null)
deleteDocuments(array $documents)
setVariable(string $variable, $component)
withDocumentsAndOrder(Closure $proc)
@template A
withFormData(Form $form, Closure $then)
criterionForm(string $url, Document $document, ?CriterionContent $criterion=null)
idOrHash(object $gui, Closure $then)
WrapperFactory $http_wrapper
resetButton(string $confirm_reset_link)
exitWithJsonResponse($value)
targetWithDocAndCriterion(object $gui, Document $document, Criterion $criterion, string $cmd, string $method='getLinkTarget')
Class ilAdministrationGUI.
Class for date presentation.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
A result encapsulates a value or an error and simplifies the handling of those.
A component is the most general form of an entity in the UI.