ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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 50 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
null|Closure(object,string,TableInterface)Table $create_table_gui
array<ConditionDefinition>$conditions
array<string,Closure(CriterionContent)Component $content_as_component

Definition at line 63 of file ProvideDocument.php.

70  {
71  $this->create_table_gui = $create_table_gui ?? fn($gui, $command, $t) => new Table($gui, $command, $t);
72  }

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

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

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

206  : bool
207  {
208  return !$this->any(static fn($x) => !$predicate($x), $array);
209  }
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 196 of file ProvideDocument.php.

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

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

196  : bool
197  {
198  return $this->find($predicate, $array)->isOk();
199  }
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 92 of file ProvideDocument.php.

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

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

92  : Result
93  {
94  return $this->find(
95  fn(Document $document): bool => $this->documentMatches($document, $user),
96  $this->document_repository->all()
97  );
98  }
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 126 of file ProvideDocument.php.

References ILIAS\LTI\ToolProvider\$key, ILIAS\LegalDocuments\SelectionMap\choices(), and ILIAS\LegalDocuments\ConditionDefinition\formGroup().

126  : SelectionMap
127  {
128  $selected = $criterion ? [
129  $criterion->type() => $criterion->arguments()
130  ] : [];
131 
132  $choices = $this->conditions->choices();
133  $groups = array_combine(array_keys($choices), array_map(
134  fn(ConditionDefinition $condition, string $key) => $condition->formGroup($selected[$key] ?? []),
135  array_values($choices),
136  array_keys($choices)
137  ));
138 
139  return new SelectionMap($groups, $this->conditions->defaultSelection());
140  }
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the call graph for this function:

◆ contentAsComponent()

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

Definition at line 154 of file ProvideDocument.php.

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

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

154  : Component
155  {
156  return $this->content_as_component[$content->type()]($content);
157  }
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 100 of file ProvideDocument.php.

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

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

100  : bool
101  {
102  return $this->all(
103  fn($c) => $this->toCondition($c->content())->eval($user),
104  $document->criteria()
105  );
106  }
all(Closure $predicate, array $array)
A
+ 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 180 of file ProvideDocument.php.

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

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

◆ hash()

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

Definition at line 113 of file ProvideDocument.php.

113  : string
114  {
115  return bin2hex(openssl_random_pseudo_bytes((int) floor(255 / 2)));
116  }

◆ repository()

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

Definition at line 108 of file ProvideDocument.php.

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

109  {
110  return $this->document_repository;
111  }
+ 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 74 of file ProvideDocument.php.

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

74  : Component
75  {
76  $t = new DocumentTable(
77  fn($criterion) => $this->toCondition($criterion)->asComponent(),
78  $this->document_repository,
79  new UI($this->id, $this->container->ui(), $this->container->language()),
80  new DocumentModal($this->container->ui(), $this->contentAsComponent(...))
81  );
82 
83  if ($edit_links !== null) {
84  $t = new EditableDocumentTable($t, $edit_links);
85  }
86 
87  $table = ($this->create_table_gui)($gui, $command, $t);
88 
89  return $this->container->ui()->factory()->legacy($table->getHTML());
90  }
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 118 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().

118  : Condition
119  {
120  return $this->conditions->choices()[$content->type()]->withCriterion($content);
121  }
+ 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 159 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().

159  : Result
160  {
161  return $b->then(function (CriterionContent $b) use ($a) {
162  $a = $a->content();
163  if ($a->equals($b)) {
164  return new Error(self::CRITERION_ALREADY_EXISTS);
165  }
166  $a = $this->toCondition($a);
167  if ($a->knownToNeverMatchWith($this->toCondition($b))) {
168  return new Error(self::CRITERION_WOULD_NEVER_MATCH);
169  }
170  return new Ok($b);
171  });
172  }
$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 145 of file ProvideDocument.php.

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

145  : Result
146  {
147  return array_reduce(
148  $criteria,
149  $this->validateAgainst(...),
150  new Ok($content)
151  );
152  }
+ 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: