Passed
Pull Request — master (#175)
by
unknown
08:11
created

ClientConfigurationManager::setConfigurationPid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
namespace EWW\Dpf\Configuration;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager;
18
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
19
use TYPO3\CMS\Extbase\Object\ObjectManager;
20
use EWW\Dpf\Domain\Repository\ClientRepository;
21
22
class ClientConfigurationManager
23
{
24
25
	/**
26
     * objectManager
27
     *
28
     * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
29
     * @inject
30
     */
31
    protected $objectManager;
32
33
    /**
34
     * clientRepository
35
     *
36
     * @var \EWW\Dpf\Domain\Repository\ClientRepository
37
     * @inject
38
     */
39
    protected $clientRepository;
40
41
    /**
42
     * settings
43
     *
44
     * @var array
45
     */
46
    protected $settings = array();
47
48
49
    /**
50
     * settings
51
     *
52
     * @var \EWW\Dpf\Domain\Model\Client
53
     */
54
    protected $client = NULL;
55
56
    /**
57
     * extensionConfiguration
58
     *
59
     * @var array
60
     */
61
    protected $extensionConfiguration = array();
62
63
    public function __construct()
64
    {
65
        $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class);
66
        $clientRepository = $objectManager->get(ClientRepository::class);
67
68
		if (TYPO3_MODE === 'BE')
0 ignored issues
show
introduced by
The condition EWW\Dpf\Configuration\TYPO3_MODE === 'BE' is always true.
Loading history...
69
		{
70
            $selectedPageId = (int) \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id');
71
            if ($selectedPageId)
72
            {
73
                $this->client = $clientRepository->findAll()->current();
74
75
                $configurationManager = $objectManager->get(BackendConfigurationManager::class);
76
                $settings = $configurationManager->getConfiguration(NULL,NULL);
77
                $this->settings = $settings; //['settings'];
78
            }
79
80
		}
81
		else
82
		{
83
            $this->client = $clientRepository->findAll()->current();
84
85
            $configurationManager = $objectManager->get(ConfigurationManager::class);
86
    		$this->settings = $configurationManager->getConfiguration(
87
            	\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS
88
        	);
89
90
        }
91
92
        $this->extensionConfiguration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['dpf']);
93
    }
94
95
    public function setConfigurationPid($pid) {
96
        $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class);
97
        $clientRepository = $objectManager->get(ClientRepository::class);
98
99
        $this->client = $clientRepository->findAllByPid($pid)->current();
100
    }
101
102
103
    /**
104
     * Get setting from client or extension configuration.
105
     *
106
     * @var array
107
     */
108
    public function getSetting($settingName, $extConfig = NULL)
109
    {
110
        $setting = NULL;
111
        if ($this->client) {
112
            $setting = trim($this->client->{"get".ucfirst($settingName)}());
113
        }
114
115
        // use global extConfig if client settings is empty
116
        if (empty($setting) && $extConfig) {
117
            $setting = trim($this->extensionConfiguration[$extConfig]);
118
        }
119
120
        return $setting;
121
    }
122
123
124
    public function getOwnerId()
125
    {
126
        return $this->getSetting("ownerId");
127
    }
128
129
    public function getSwordHost()
130
    {
131
    	return $this->getSetting("swordHost","swordHost");
132
    }
133
134
	public function getSwordUser()
135
    {
136
    	return $this->getSetting("swordUser","swordUser");
137
    }
138
139
	public function getSwordPassword()
140
    {
141
    	return $this->getSetting("swordPassword","swordPassword");
142
    }
143
144
	public function getSwordCollectionNamespace()
145
    {
146
    	return $this->getSetting("swordCollectionNamespace","swordCollectionNamespace");
147
    }
148
149
	public function getFedoraHost()
150
    {
151
    	return $this->getSetting("fedoraHost","fedoraHost");
152
    }
153
154
	public function getFedoraUser()
155
    {
156
    	return $this->getSetting("fedoraUser","fedoraUser");
157
    }
158
159
	public function getFedoraPassword()
160
    {
161
    	return $this->getSetting("fedoraPassword","fedoraPassword");
162
    }
163
164
	public function getElasticSearchHost()
165
    {
166
    	return $this->getSetting("elasticSearchHost","elasticSearchHost");
167
    }
168
169
	public function getElasticSearchPort()
170
    {
171
    	return $this->getSetting("elasticSearchPort","elasticSearchPort");
172
    }
173
174
	public function getUploadDirectory()
175
    {
176
    	return $this->getSetting("uploadDirectory","uploadDirectory");
177
    }
178
179
	public function getUploadDomain()
180
    {
181
    	return $this->getSetting("uploadDomain","uploadDomain");
182
    }
183
184
}
185