/
PluginQuestionAttributeProvider.php
51 lines (41 loc) · 1.62 KB
/
PluginQuestionAttributeProvider.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
<?php
namespace LimeSurvey\Models\Services;
/**
* Provides question attribute definitions from plugins
*/
class PluginQuestionAttributeProvider extends QuestionAttributeProvider
{
/** @inheritdoc */
public function getDefinitions($options = [])
{
/** @var string question type */
$questionType = self::getQuestionType($options);
if (empty($questionType)) {
return [];
}
return $this->getAttributesFromPlugin($questionType);
}
/**
* Returns the question attributes added by plugins ('newQuestionAttributes' event) for
* the specified question type.
*
* @param string $questionType the question type to retrieve the attributes for.
*
* @return array<string,array> the question attributes added by plugins
*/
protected function getAttributesFromPlugin($questionType)
{
$event = new \LimeSurvey\PluginManager\PluginEvent('newQuestionAttributes');
$result = App()->getPluginManager()->dispatchEvent($event);
$allPluginAttributes = (array) $result->get('questionAttributes');
if (empty($allPluginAttributes)) {
return [];
}
$questionAttributeHelper = new QuestionAttributeHelper();
// Filter to get this question type attributes
$questionTypeAttributes = $questionAttributeHelper->filterAttributesByQuestionType($allPluginAttributes, $questionType);
// Complete category if missing
$questionTypeAttributes = $questionAttributeHelper->fillMissingCategory($questionTypeAttributes, gT('Plugin'));
return $questionTypeAttributes;
}
}