ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ILIAS\LegalDocuments\Provide\ProvideDocument Class Reference
+ Collaboration diagram for ILIAS\LegalDocuments\Provide\ProvideDocument:

Public Member Functions

 __construct (private readonly string $id, private readonly DocumentRepository $document_repository, private readonly SelectionMap $conditions, private readonly array $content_as_component, private readonly Container $container, ?Closure $create_table_gui=null)
 
 table (object $gui, string $command, ?EditLinks $edit_links=null)
 
 chooseDocumentFor (ilObjUser $user)
 
 documentMatches (Document $document, ilObjUser $user)
 
 repository ()
 
 hash ()
 
 toCondition (CriterionContent $content)
 
 conditionGroups (?CriterionContent $criterion=null)
 
 validateCriteriaContent (array $criteria, CriterionContent $content)
 
 contentAsComponent (DocumentContent $content)
 

Data Fields

const CRITERION_ALREADY_EXISTS = 'Criterion already exists.'
 
const CRITERION_WOULD_NEVER_MATCH = 'Criterion would never match.'
 

Private Member Functions

 validateAgainst (Result $b, Criterion $a)
 
 find (Closure $predicate, array $array)
 A More...
 
 any (Closure $predicate, array $array)
 A More...
 
 all (Closure $predicate, array $array)
 A More...
 

Private Attributes

readonly Closure $create_table_gui
 

Detailed Description

Definition at line 47 of file ProvideDocument.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\LegalDocuments\Provide\ProvideDocument::__construct ( private readonly string  $id,
private readonly DocumentRepository  $document_repository,
private readonly SelectionMap  $conditions,
private readonly array  $content_as_component,
private readonly Container  $container,
?Closure  $create_table_gui = null 
)
Parameters
array<string,Closure(DocumentContent)Component> $content_as_component
null|Closure(object,string,TableInterface)Table $create_table_gui

Definition at line 59 of file ProvideDocument.php.

66  {
67  $this->create_table_gui = $create_table_gui ?? fn($gui, $command, $t) => new Table($gui, $command, $t);
68  }

Member Function Documentation

◆ all()

ILIAS\LegalDocuments\Provide\ProvideDocument::all ( Closure  $predicate,
array  $array 
)
private

A

Parameters
Closure(A)bool $predicate
list<A>$array

Definition at line 202 of file ProvideDocument.php.

References ILIAS\LegalDocuments\Provide\ProvideDocument\any().

Referenced by ILIAS\LegalDocuments\Provide\ProvideDocument\documentMatches().

202  : bool
203  {
204  return !$this->any(static fn($x) => !$predicate($x), $array);
205  }
any(Closure $predicate, array $array)
A
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ any()

ILIAS\LegalDocuments\Provide\ProvideDocument::any ( Closure  $predicate,
array  $array 
)
private

A

Parameters
Closure(A)bool $predicate
list<A>$array

Definition at line 192 of file ProvideDocument.php.

References ILIAS\LegalDocuments\Provide\ProvideDocument\find().

Referenced by ILIAS\LegalDocuments\Provide\ProvideDocument\all().

192  : bool
193  {
194  return $this->find($predicate, $array)->isOk();
195  }
find(Closure $predicate, array $array)
A
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ chooseDocumentFor()

ILIAS\LegalDocuments\Provide\ProvideDocument::chooseDocumentFor ( ilObjUser  $user)

Definition at line 88 of file ProvideDocument.php.

References ILIAS\LegalDocuments\Provide\ProvideDocument\documentMatches(), and ILIAS\LegalDocuments\Provide\ProvideDocument\find().

Referenced by ILIAS\LegalDocuments\test\Provide\ProvideDocumentTest\testChooseDocumentFor().

88  : Result
89  {
90  return $this->find(
91  fn(Document $document): bool => $this->documentMatches($document, $user),
92  $this->document_repository->all()
93  );
94  }
documentMatches(Document $document, ilObjUser $user)
find(Closure $predicate, array $array)
A
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ conditionGroups()

ILIAS\LegalDocuments\Provide\ProvideDocument::conditionGroups ( ?CriterionContent  $criterion = null)
Returns
SelectionMap<Group>

Definition at line 122 of file ProvideDocument.php.

References ILIAS\LegalDocuments\SelectionMap\choices(), and ILIAS\LegalDocuments\ConditionDefinition\formGroup().

122  : SelectionMap
123  {
124  $selected = $criterion ? [
125  $criterion->type() => $criterion->arguments()
126  ] : [];
127 
128  $choices = $this->conditions->choices();
129  $groups = array_combine(array_keys($choices), array_map(
130  fn(ConditionDefinition $condition, string $key) => $condition->formGroup($selected[$key] ?? []),
131  array_values($choices),
132  array_keys($choices)
133  ));
134 
135  return new SelectionMap($groups, $this->conditions->defaultSelection());
136  }
+ Here is the call graph for this function:

◆ contentAsComponent()

ILIAS\LegalDocuments\Provide\ProvideDocument::contentAsComponent ( DocumentContent  $content)

Definition at line 150 of file ProvideDocument.php.

References ILIAS\LegalDocuments\Value\DocumentContent\type().

Referenced by ILIAS\LegalDocuments\Provide\ProvideDocument\table().

150  : Component
151  {
152  return $this->content_as_component[$content->type()]($content);
153  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ documentMatches()

ILIAS\LegalDocuments\Provide\ProvideDocument::documentMatches ( Document  $document,
ilObjUser  $user 
)

Definition at line 96 of file ProvideDocument.php.

References $c, ILIAS\LegalDocuments\Provide\ProvideDocument\all(), ILIAS\LegalDocuments\Value\Document\criteria(), and ILIAS\LegalDocuments\Provide\ProvideDocument\toCondition().

Referenced by ILIAS\LegalDocuments\Provide\ProvideDocument\chooseDocumentFor().

96  : bool
97  {
98  return $this->all(
99  fn($c) => $this->toCondition($c->content())->eval($user),
100  $document->criteria()
101  );
102  }
all(Closure $predicate, array $array)
A
$c
Definition: deliver.php:9
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find()

ILIAS\LegalDocuments\Provide\ProvideDocument::find ( Closure  $predicate,
array  $array 
)
private

A

Parameters
Closure(A)bool $predicate
list<A>$array
Returns
Result

Definition at line 176 of file ProvideDocument.php.

Referenced by ILIAS\LegalDocuments\Provide\ProvideDocument\any(), and ILIAS\LegalDocuments\Provide\ProvideDocument\chooseDocumentFor().

176  : Result
177  {
178  foreach ($array as $x) {
179  if ($predicate($x)) {
180  return new Ok($x);
181  }
182  }
183 
184  return new Error('Not found.');
185  }
+ Here is the caller graph for this function:

◆ hash()

ILIAS\LegalDocuments\Provide\ProvideDocument::hash ( )

Definition at line 109 of file ProvideDocument.php.

109  : string
110  {
111  return bin2hex(openssl_random_pseudo_bytes((int) floor(255 / 2)));
112  }

◆ repository()

ILIAS\LegalDocuments\Provide\ProvideDocument::repository ( )

Definition at line 104 of file ProvideDocument.php.

Referenced by ILIAS\LegalDocuments\SlotConstructor\history().

104  : DocumentRepository
105  {
106  return $this->document_repository;
107  }
+ Here is the caller graph for this function:

◆ table()

ILIAS\LegalDocuments\Provide\ProvideDocument::table ( object  $gui,
string  $command,
?EditLinks  $edit_links = null 
)

Definition at line 70 of file ProvideDocument.php.

References ILIAS\LegalDocuments\Provide\ProvideDocument\$create_table_gui, ILIAS\LegalDocuments\Provide\ProvideDocument\contentAsComponent(), and ILIAS\LegalDocuments\Provide\ProvideDocument\toCondition().

70  : Component
71  {
72  $t = new DocumentTable(
73  fn($criterion) => $this->toCondition($criterion)->asComponent(),
74  $this->document_repository,
75  new UI($this->id, $this->container->ui(), $this->container->language()),
76  new DocumentModal($this->container->ui(), $this->contentAsComponent(...))
77  );
78 
79  if ($edit_links !== null) {
80  $t = new EditableDocumentTable($t, $edit_links);
81  }
82 
83  $table = ($this->create_table_gui)($gui, $command, $t);
84 
85  return $this->container->ui()->factory()->legacy($table->getHTML());
86  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:

◆ toCondition()

ILIAS\LegalDocuments\Provide\ProvideDocument::toCondition ( CriterionContent  $content)

Definition at line 114 of file ProvideDocument.php.

References ILIAS\LegalDocuments\Value\CriterionContent\type().

Referenced by ILIAS\LegalDocuments\Provide\ProvideDocument\documentMatches(), ILIAS\LegalDocuments\Provide\ProvideDocument\table(), and ILIAS\LegalDocuments\Provide\ProvideDocument\validateAgainst().

114  : Condition
115  {
116  return $this->conditions->choices()[$content->type()]->withCriterion($content);
117  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validateAgainst()

ILIAS\LegalDocuments\Provide\ProvideDocument::validateAgainst ( Result  $b,
Criterion  $a 
)
private

Definition at line 155 of file ProvideDocument.php.

References ILIAS\LegalDocuments\Value\Criterion\content(), ILIAS\Data\Result\then(), and ILIAS\LegalDocuments\Provide\ProvideDocument\toCondition().

Referenced by ILIAS\LegalDocuments\Provide\ProvideDocument\validateCriteriaContent().

155  : Result
156  {
157  return $b->then(function (CriterionContent $b) use ($a) {
158  $a = $a->content();
159  if ($a->equals($b)) {
160  return new Error(self::CRITERION_ALREADY_EXISTS);
161  }
162  $a = $this->toCondition($a);
163  if ($a->knownToNeverMatchWith($this->toCondition($b))) {
164  return new Error(self::CRITERION_WOULD_NEVER_MATCH);
165  }
166  return new Ok($b);
167  });
168  }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validateCriteriaContent()

ILIAS\LegalDocuments\Provide\ProvideDocument::validateCriteriaContent ( array  $criteria,
CriterionContent  $content 
)
Parameters
list<Criterion>$criteria

Definition at line 141 of file ProvideDocument.php.

References ILIAS\LegalDocuments\Provide\ProvideDocument\validateAgainst().

141  : Result
142  {
143  return array_reduce(
144  $criteria,
145  $this->validateAgainst(...),
146  new Ok($content)
147  );
148  }
+ Here is the call graph for this function:

Field Documentation

◆ $create_table_gui

readonly Closure ILIAS\LegalDocuments\Provide\ProvideDocument::$create_table_gui
private

◆ CRITERION_ALREADY_EXISTS

const ILIAS\LegalDocuments\Provide\ProvideDocument::CRITERION_ALREADY_EXISTS = 'Criterion already exists.'

◆ CRITERION_WOULD_NEVER_MATCH

const ILIAS\LegalDocuments\Provide\ProvideDocument::CRITERION_WOULD_NEVER_MATCH = 'Criterion would never match.'

The documentation for this class was generated from the following file: