ILIAS  trunk Revision v11.0_alpha-2645-g16283d3b3f8
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,)
 
 table (object $gui, ?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...
 

Detailed Description

Definition at line 45 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 
)
Parameters
array<string,Closure(CriterionContent)Component $content_as_component

Definition at line 53 of file ProvideDocument.php.

59  {
60  }

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 197 of file ProvideDocument.php.

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

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

197  : bool
198  {
199  return !$this->any(static fn($x) => !$predicate($x), $array);
200  }
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 187 of file ProvideDocument.php.

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

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

187  : bool
188  {
189  return $this->find($predicate, $array)->isOk();
190  }
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 83 of file ProvideDocument.php.

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

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

83  : Result
84  {
85  return $this->find(
86  fn(Document $document): bool => $this->documentMatches($document, $user),
87  $this->document_repository->all()
88  );
89  }
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 117 of file ProvideDocument.php.

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

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

◆ contentAsComponent()

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

Definition at line 145 of file ProvideDocument.php.

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

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

145  : Component
146  {
147  return $this->content_as_component[$content->type()]($content);
148  }
+ 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 91 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().

91  : bool
92  {
93  return $this->all(
94  fn($c) => $this->toCondition($c->content())->eval($user),
95  $document->criteria()
96  );
97  }
all(Closure $predicate, array $array)
A
$c
Definition: deliver.php:25
+ 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 171 of file ProvideDocument.php.

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

171  : Result
172  {
173  foreach ($array as $x) {
174  if ($predicate($x)) {
175  return new Ok($x);
176  }
177  }
178 
179  return new Error('Not found.');
180  }
+ Here is the caller graph for this function:

◆ hash()

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

Definition at line 104 of file ProvideDocument.php.

104  : string
105  {
106  return bin2hex(openssl_random_pseudo_bytes((int) floor(255 / 2)));
107  }

◆ repository()

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

Definition at line 99 of file ProvideDocument.php.

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

99  : DocumentRepository
100  {
101  return $this->document_repository;
102  }
+ Here is the caller graph for this function:

◆ table()

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

Definition at line 62 of file ProvideDocument.php.

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

62  : DocumentTable
63  {
64  return new DocumentTable(
65  fn($criterion) => $this->toCondition($criterion)->asComponent(),
66  $this->document_repository,
67  new UI(
68  $this->id,
69  $this->container->ui(),
70  $this->container->language()
71  ),
72  new DocumentModal($this->container->ui(), $this->contentAsComponent(...)),
73  $gui,
74  $edit_links,
75  $this->container->http()->request(),
76  new Factory(),
77  $this->container->ctrl(),
78  $this->container->ui()->renderer(),
79  $this->container->user()
80  );
81  }
+ Here is the call graph for this function:

◆ toCondition()

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

Definition at line 109 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().

109  : Condition
110  {
111  return $this->conditions->choices()[$content->type()]->withCriterion($content);
112  }
+ 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 150 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().

150  : Result
151  {
152  return $b->then(function (CriterionContent $b) use ($a) {
153  $a = $a->content();
154  if ($a->equals($b)) {
155  return new Error(self::CRITERION_ALREADY_EXISTS);
156  }
157  $a = $this->toCondition($a);
158  if ($a->knownToNeverMatchWith($this->toCondition($b))) {
159  return new Error(self::CRITERION_WOULD_NEVER_MATCH);
160  }
161  return new Ok($b);
162  });
163  }
$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 136 of file ProvideDocument.php.

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

136  : Result
137  {
138  return array_reduce(
139  $criteria,
140  $this->validateAgainst(...),
141  new Ok($content)
142  );
143  }
+ Here is the call graph for this function:

Field Documentation

◆ 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: