ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTermsOfServiceLogicalAndDocumentCriteriaEvaluation.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 {
28  protected ilObjUser $user;
29  protected ilLogger $log;
30 
31  public function __construct(
33  ilObjUser $user,
34  ilLogger $log
35  ) {
36  $this->criterionTypeFactory = $criterionTypeFactory;
37  $this->user = $user;
38  $this->log = $log;
39  }
40 
42  {
43  $clone = clone $this;
44  $clone->user = $user;
45 
46  return $clone;
47  }
48 
49  public function evaluate(ilTermsOfServiceSignableDocument $document): bool
50  {
51  $this->log->debug(sprintf(
52  'Evaluating criteria for document "%s" (id: %s) and user "%s" (id: %s)',
53  $document->title(),
54  $document->id(),
55  $this->user->getLogin(),
56  $this->user->getId()
57  ));
58 
59  foreach ($document->criteria() as $criterionAssignment) {
60  $criterionType = $this->criterionTypeFactory->findByTypeIdent($criterionAssignment->getCriterionId(), true);
61 
62  $result = $criterionType->evaluate($this->user, $criterionAssignment->getCriterionValue());
63 
64  $this->log->debug(sprintf(
65  'Criterion of type "%s", configured with %s evaluated: %s',
66  $criterionType->getTypeIdent(),
67  var_export($criterionAssignment->getCriterionValue()->toJson(), true),
68  var_export($result, true)
69  ));
70 
71  if (!$result) {
72  return false;
73  }
74  }
75 
76  return true;
77  }
78 }
evaluate(ilTermsOfServiceSignableDocument $document)
Evaluates a document for the context given by the concrete implementation.
__construct(ilTermsOfServiceCriterionTypeFactoryInterface $criterionTypeFactory, ilObjUser $user, ilLogger $log)
withContextUser(ilObjUser $user)
Returns a criteria evaluator like this with the passed context user.
Interface ilTermsOfServiceSignableDocument.