ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTermsOfServiceLogicalAndDocumentCriteriaEvaluation.php
Go to the documentation of this file.
1 <?php declare(strict_types=1);
2 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
9 {
13  protected $user;
15  protected $log;
16 
23  public function __construct(
27  ) {
28  $this->criterionTypeFactory = $criterionTypeFactory;
29  $this->user = $user;
30  $this->log = $log;
31  }
32 
37  {
38  $clone = clone $this;
39  $clone->user = $user;
40 
41  return $clone;
42  }
43 
47  public function evaluate(ilTermsOfServiceSignableDocument $document) : bool
48  {
49  $this->log->debug(sprintf(
50  'Evaluating criteria for document "%s" (id: %s) and user "%s" (id: %s)',
51  $document->title(),
52  $document->id(),
53  $this->user->getLogin(),
54  $this->user->getId()
55  ));
56 
57  foreach ($document->criteria() as $criterionAssignment) {
58  $criterionType = $this->criterionTypeFactory->findByTypeIdent($criterionAssignment->getCriterionId(), true);
59 
60  $result = $criterionType->evaluate($this->user, $criterionAssignment->getCriterionValue());
61 
62  $this->log->debug(sprintf(
63  'Criterion of type "%s", configured with %s evaluated: %s',
64  $criterionType->getTypeIdent(),
65  var_export($criterionAssignment->getCriterionValue()->toJson(), true),
66  var_export($result, true)
67  ));
68 
69  if (!$result) {
70  return false;
71  }
72  }
73 
74  return true;
75  }
76 }
evaluate(ilTermsOfServiceSignableDocument $document)
Evaluates a document for the context given by the concrete implementation.bool
$result
user()
Definition: user.php:4
__construct(ilTermsOfServiceCriterionTypeFactoryInterface $criterionTypeFactory, ilObjUser $user, ilLogger $log)
ilTermsOfServiceDocumentLogicalAndCriteriaEvaluation constructor.
withContextUser(ilObjUser $user)
Returns a criteria evaluator like this with the passed context user.ilTermsOfServiceDocumentCriteriaE...
Interface ilTermsOfServiceSignableDocument.
Component logger with individual log levels by component id.