ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTermsOfServiceTableDataProviderFactory.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 $db;
12
13 const CONTEXT_ACCEPTANCE_HISTORY = 'acceptance_history';
14 const CONTEXT_DOCUMENTS = 'documents';
15
23 {
24 switch ($context) {
26 $this->validateConfiguration(array('db'));
27 return new \ilTermsOfServiceAcceptanceHistoryProvider($this->getDatabaseAdapter());
28
30 return new \ilTermsOfServiceDocumentTableDataProvider();
31
32 default:
33 throw new \InvalidArgumentException('Provider not supported');
34 }
35 }
36
41 protected function validateConfiguration(array $mandatoryMemberVariables)
42 {
43 foreach ($mandatoryMemberVariables as $member) {
44 if (null == $this->{$member}) {
45 $exception = $this->getExceptionByMember($member);
46 throw $exception;
47 }
48 }
49 }
50
56 protected function getExceptionByMember($member)
57 {
58 switch ($member) {
59 case 'db':
60 return new \ilTermsOfServiceMissingDatabaseAdapterException(
61 'Incomplete factory configuration. Please inject a database adapter.'
62 );
63
64 default:
65 throw new \InvalidArgumentException("Exception for member {$member} not supported");
66 }
67 }
68
72 public function setDatabaseAdapter($db)
73 {
74 $this->db = $db;
75 }
76
80 public function getDatabaseAdapter()
81 {
82 return $this->db;
83 }
84}
An exception for terminatinating execution or to throw for unit testing.
Interface ilTermsOfServiceTableDataProvider.
$context
Definition: webdav.php:25