-
Notifications
You must be signed in to change notification settings - Fork 451
/
AbstractSurvey.php
50 lines (41 loc) · 1.22 KB
/
AbstractSurvey.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
<?php
namespace Concrete\Core\SiteInformation;
use Concrete\Core\SiteInformation\Question\QuestionInterface;
abstract class AbstractSurvey implements SurveyInterface
{
/**
* @return QuestionInterface[]
*/
abstract public function getQuestions(): array;
abstract public function getSaverNamespace(): string;
public function getResult($question)
{
/**
* @var $question QuestionInterface|string
*/
$saver = $this->getSaver();
$results = $saver->getResults();
$key = $question::getKey();
return $results[$key] ?? null;
}
public function render(): string
{
$results = $this->getSaver()->getResults();
$output = '';
foreach ($this->getQuestions() as $question) {
$output .= $question->getTag($results)->render();
}
return $output;
}
public function getSaver(): SaverInterface
{
$fieldKeys = [];
foreach ($this->getQuestions() as $question) {
$fieldKeys[] = $question->getKey();
}
return app(DatabaseConfigSaver::class, [
'fieldKeys' => $fieldKeys,
'namespace' => $this->getSaverNamespace()
]);
}
}