ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTermsOfServiceSequentialDocumentEvaluation.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
9 {
11  protected $evaluation;
12 
14  protected $user;
15 
17  protected $matchingDocuments = null;
18 
20  protected $possibleDocuments = [];
21 
23  protected $log;
24 
32  public function __construct(
35  \ilLogger $log,
36  array $possibleDocuments
37  ) {
38  $this->evaluation = $evaluation;
39  $this->user = $user;
40  $this->log = $log;
41  $this->possibleDocuments = $possibleDocuments;
42  }
43 
47  protected function getMatchingDocuments() : array
48  {
49  if (null === $this->matchingDocuments) {
50  $this->matchingDocuments = [];
51 
52  $this->log->debug(sprintf(
53  'Evaluating document for user "%s" (id: %s) ...',
54  $this->user->getLogin(),
55  $this->user->getId()
56  ));
57 
58  foreach ($this->possibleDocuments as $document) {
59  if ($this->evaluation->evaluate($document)) {
60  $this->matchingDocuments[] = $document;
61  }
62  }
63 
64  $this->log->debug(sprintf(
65  '%s matching document(s) found',
66  count($this->matchingDocuments)
67  ));
68  }
69 
71  }
72 
77  {
79  if (count($matchingDocuments) > 0) {
80  return $matchingDocuments[0];
81  }
82 
83  throw new \ilTermsOfServiceNoSignableDocumentFoundException(sprintf(
84  'Could not find any terms of service document for the passed user (id: %s|login: %s)',
85  $this->user->getId(),
86  $this->user->getLogin()
87  ));
88  }
89 
93  public function hasDocument() : bool
94  {
95  return count($this->getMatchingDocuments()) > 0;
96  }
97 }
Interface ilTermsOfServiceSequentialDocumentEvaluation.
Interface ilTermsOfServiceDocumentEvaluation.
__construct(\ilTermsOfServiceDocumentCriteriaEvaluation $evaluation, \ilObjUser $user, \ilLogger $log, array $possibleDocuments)
ilTermsOfServiceDocumentLogicalAndCriteriaEvaluation constructor.
user()
Definition: user.php:4
Interface ilTermsOfServiceSignableDocument.
Component logger with individual log levels by component id.