|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Superdesk Web Publisher Templates System. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright 2015 Sourcefabric z.ú. and contributors. |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please see the |
|
9
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* @copyright 2015 Sourcefabric z.ú |
|
12
|
|
|
* @license http://www.superdesk.org/license |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace SWP\Component\TemplatesSystem\Gimme\Widget; |
|
16
|
|
|
|
|
17
|
|
|
use SWP\Component\TemplatesSystem\Gimme\Model\WidgetModelInterface; |
|
18
|
|
|
|
|
19
|
|
|
abstract class AbstractWidgetHandler implements WidgetHandlerInterface |
|
20
|
|
|
{ |
|
21
|
|
|
protected static $expectedParameters = []; |
|
22
|
|
|
|
|
23
|
|
|
protected $widgetModel; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @return array |
|
27
|
|
|
*/ |
|
28
|
1 |
|
public static function getExpectedParameters() |
|
29
|
|
|
{ |
|
30
|
1 |
|
return static::$expectedParameters; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* AbstractWidgetHandler constructor. |
|
35
|
|
|
* |
|
36
|
|
|
* @param WidgetModelInterface $widgetModel |
|
37
|
|
|
*/ |
|
38
|
4 |
|
public function __construct(WidgetModelInterface $widgetModel) |
|
39
|
|
|
{ |
|
40
|
4 |
|
$this->widgetModel = $widgetModel; |
|
41
|
4 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param $name |
|
45
|
|
|
* |
|
46
|
|
|
* @return string |
|
47
|
|
|
*/ |
|
48
|
3 |
|
protected function getModelParameter($name) |
|
49
|
|
|
{ |
|
50
|
3 |
|
if (isset($this->widgetModel->getParameters()[$name])) { |
|
51
|
3 |
|
return $this->widgetModel->getParameters()[$name]; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
// Get default value |
|
55
|
|
|
if (isset(self::getExpectedParameters()[$name])) { |
|
56
|
|
|
$parameterMetaData = self::getExpectedParameters()[$name]; |
|
57
|
|
|
if (is_array($parameterMetaData) && isset($parameterMetaData['default'])) { |
|
58
|
|
|
return $parameterMetaData['default']; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Check if widget should be rendered. |
|
67
|
|
|
* |
|
68
|
|
|
* @return bool |
|
69
|
|
|
*/ |
|
70
|
1 |
|
public function isVisible() |
|
71
|
|
|
{ |
|
72
|
1 |
|
return $this->widgetModel->getVisible(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Returns associative array with all expected parameters and their values. |
|
77
|
|
|
* |
|
78
|
|
|
* @return array |
|
79
|
|
|
*/ |
|
80
|
1 |
|
protected function getAllParametersWithValue() |
|
81
|
|
|
{ |
|
82
|
1 |
|
$all = array(); |
|
83
|
1 |
|
foreach (self::getExpectedParameters() as $key => $value) { |
|
84
|
1 |
|
$all[$key] = $this->getModelParameter($key); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
1 |
|
return $all; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|