ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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;
12
14 protected $user;
15
17 protected $matchingDocuments = null;
18
20 protected $possibleDocuments = [];
21
23 protected $log;
24
32 public function __construct(
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
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}
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.
__construct(ilTermsOfServiceDocumentCriteriaEvaluation $evaluation, ilObjUser $user, ilLogger $log, array $possibleDocuments)
ilTermsOfServiceDocumentLogicalAndCriteriaEvaluation constructor.
Interface ilTermsOfServiceDocumentEvaluation.
Interface ilTermsOfServiceSignableDocument.