ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilTermsOfServiceSequentialDocumentEvaluation.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{
11 protected $evaluation;
13 protected $user;
17 protected $possibleDocuments = [];
19 protected $log;
20
28 public function __construct(
33 ) {
34 $this->evaluation = $evaluation;
35 $this->user = $user;
36 $this->log = $log;
37 $this->possibleDocuments = $possibleDocuments;
38 }
39
44 {
45 $clone = clone $this;
46 $clone->user = $user;
47 $clone->evaluation = $clone->evaluation->withContextUser($user);
48
49 return $clone;
50 }
51
55 protected function getMatchingDocuments() : array
56 {
57 if (!array_key_exists((int) $this->user->getId(), $this->matchingDocumentsByUser)) {
58 $this->matchingDocumentsByUser[(int) $this->user->getId()] = [];
59
60 $this->log->debug(sprintf(
61 'Evaluating document for user "%s" (id: %s) ...',
62 $this->user->getLogin(),
63 $this->user->getId()
64 ));
65
66 foreach ($this->possibleDocuments as $document) {
67 if ($this->evaluateDocument($document)) {
68 $this->matchingDocumentsByUser[(int) $this->user->getId()][] = $document;
69 }
70 }
71
72 $this->log->debug(sprintf(
73 '%s matching document(s) found',
74 count($this->matchingDocumentsByUser[(int) $this->user->getId()])
75 ));
76 }
77
78 return $this->matchingDocumentsByUser[(int) $this->user->getId()];
79 }
80
84 public function evaluateDocument(ilTermsOfServiceSignableDocument $document) : bool
85 {
86 return $this->evaluation->evaluate($document);
87 }
88
93 {
94 $matchingDocuments = $this->getMatchingDocuments();
95 if (count($matchingDocuments) > 0) {
96 return $matchingDocuments[0];
97 }
98
100 'Could not find any terms of service document for the passed user (id: %s|login: %s)',
101 $this->user->getId(),
102 $this->user->getLogin()
103 ));
104 }
105
109 public function hasDocument() : bool
110 {
111 return count($this->getMatchingDocuments()) > 0;
112 }
113}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
Component logger with individual log levels by component id.
Interface ilTermsOfServiceSequentialDocumentEvaluation.
evaluateDocument(ilTermsOfServiceSignableDocument $document)
@inheritDoc
withContextUser(ilObjUser $user)
Returns an evaluator like this with the passed context user.ilTermsOfServiceDocumentEvaluation
document()
Determines a document based on the context of the concrete implementation.ilTermsOfServiceSignableDoc...
__construct(ilTermsOfServiceDocumentCriteriaEvaluation $evaluation, ilObjUser $user, ilLogger $log, array $possibleDocuments)
ilTermsOfServiceDocumentLogicalAndCriteriaEvaluation constructor.
Interface ilTermsOfServiceDocumentEvaluation.
Interface ilTermsOfServiceSignableDocument.