ILIAS  release_8 Revision v8.24
class.ilTermsOfServiceLogicalAndDocumentCriteriaEvaluation.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
28 protected ilObjUser $user;
29 protected ilLogger $log;
30
31 public function __construct(
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}
Component logger with individual log levels by component id.
User class.
evaluate(ilTermsOfServiceSignableDocument $document)
Evaluates a document for the context given by the concrete implementation.
withContextUser(ilObjUser $user)
Returns a criteria evaluator like this with the passed context user.
__construct(ilTermsOfServiceCriterionTypeFactoryInterface $criterionTypeFactory, ilObjUser $user, ilLogger $log)
Interface ilTermsOfServiceSignableDocument.