-
Notifications
You must be signed in to change notification settings - Fork 988
/
SurveyAggregateService.php
105 lines (93 loc) · 2.61 KB
/
SurveyAggregateService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace LimeSurvey\Models\Services;
use LimeSurvey\Models\Services\SurveyAggregateService\{
LanguageSettings,
GeneralSettings,
UrlParams,
TemplateConfiguration
};
use LimeSurvey\Models\Services\Proxy\ProxyExpressionManager;
use LimeSurvey\Models\Services\Exception\{
PersistErrorException,
NotFoundException,
PermissionDeniedException
};
/**
* Survey Aggregate Service
*
* Service class for updating survey settings.
*
* Dependencies are injected to enable mocking.
*/
class SurveyAggregateService
{
private LanguageSettings $languageSettings;
private GeneralSettings $generalSettings;
private UrlParams $urlParams;
private ProxyExpressionManager $proxyExpressionManager;
private TemplateConfiguration $templateConfiguration;
private $restMode = false;
public function __construct(
LanguageSettings $languageSettings,
GeneralSettings $generalSettings,
UrlParams $urlParams,
ProxyExpressionManager $proxyExpressionManager,
TemplateConfiguration $templateConfiguration
) {
$this->languageSettings = $languageSettings;
$this->generalSettings = $generalSettings;
$this->urlParams = $urlParams;
$this->proxyExpressionManager = $proxyExpressionManager;
$this->templateConfiguration = $templateConfiguration;
}
/**
* Set REST Mode
*
* In rest mode we have different expecations about data formats.
* For example datetime objects inputs/output
* as UTC JSON format Y-m-d\TH:i:s.000\Z.
*
* @param bool $restMode
*/
public function setRestMode($restMode)
{
$this->restMode = (bool) $restMode;
$this->generalSettings->setRestMode($this->restMode);
}
public function getRestMode()
{
return $this->restMode;
}
/**
* Update
*
* @param int $surveyId
* @param array $input
* @throws PersistErrorException
* @throws NotFoundException
* @throws PermissionDeniedException
* @return array
*/
public function update($surveyId, $input)
{
$this->languageSettings->update(
$surveyId,
$input
);
$meta = $this->generalSettings->update(
$surveyId,
$input
);
if (!empty($input['url_params'])) {
$this->urlParams->update(
$surveyId,
$input['url_params']
);
}
$this->proxyExpressionManager
->reset($surveyId);
$this->templateConfiguration
->update($surveyId);
return $meta;
}
}