1
|
|
|
<?php |
2
|
|
|
namespace Redaxscript\Admin\View\Helper; |
3
|
|
|
|
4
|
|
|
use Redaxscript\Admin; |
5
|
|
|
use Redaxscript\Html; |
6
|
|
|
use Redaxscript\Module; |
7
|
|
|
use function array_replace_recursive; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* helper class to create the admin dashboard |
11
|
|
|
* |
12
|
|
|
* @since 4.1.0 |
13
|
|
|
* |
14
|
|
|
* @package Redaxscript |
15
|
|
|
* @category View |
16
|
|
|
* @author Henry Ruhs |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
class Dashboard extends Admin\View\ViewAbstract |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* options of the panel |
23
|
|
|
* |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
protected $_optionArray = |
28
|
|
|
[ |
29
|
|
|
'className' => |
30
|
|
|
[ |
31
|
|
|
'list' => 'rs-admin-list-dashboard', |
32
|
|
|
'item' => 'rs-admin-item-dashboard' |
33
|
|
|
] |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* init the class |
38
|
|
|
* |
39
|
|
|
* @since 4.1.0 |
40
|
|
|
* |
41
|
|
|
* @param array $optionArray options of the dashboard |
42
|
|
|
* |
43
|
|
|
* @return self |
44
|
|
|
*/ |
45
|
|
|
|
46
|
|
|
public function init(array $optionArray = []) : self |
47
|
|
|
{ |
48
|
|
|
$this->_optionArray = array_replace_recursive($this->_optionArray, $optionArray); |
49
|
|
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* render the view |
54
|
|
|
* |
55
|
|
|
* @since 4.1.0 |
56
|
|
|
* |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
|
|
|
60
|
|
|
public function render() : string |
61
|
|
|
{ |
62
|
|
|
$output = Module\Hook::trigger('adminDashboardStart'); |
63
|
|
|
$outputItem = null; |
64
|
|
|
$dashboardArray = Module\Hook::collect('adminDashboard'); |
65
|
|
|
|
66
|
|
|
/* html element */ |
67
|
|
|
|
68
|
|
|
$element = new Html\Element(); |
69
|
|
|
$listElement = $element->copy()->init('ul', |
70
|
|
|
[ |
71
|
|
|
'class' => $this->_optionArray['className']['list'] |
72
|
|
|
]); |
73
|
|
|
$itemElement = $element->copy()->init('li', |
74
|
|
|
[ |
75
|
|
|
'class' => $this->_optionArray['className']['item'] |
76
|
|
|
]); |
77
|
|
|
|
78
|
|
|
/* collect item output */ |
79
|
|
|
|
80
|
|
|
foreach ($dashboardArray as $moduleArray) |
81
|
|
|
{ |
82
|
|
|
foreach ($moduleArray as $valueArray) |
83
|
|
|
{ |
84
|
|
|
$outputItem .= $itemElement |
85
|
|
|
->copy() |
86
|
|
|
->attr('data-column', $valueArray['column'] ? : 1) |
87
|
|
|
->html($valueArray['content']); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/* collect output */ |
92
|
|
|
|
93
|
|
|
if ($outputItem) |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
$output .= $listElement->html($outputItem); |
96
|
|
|
} |
97
|
|
|
$output .= Module\Hook::trigger('adminDashboardEnd'); |
98
|
|
|
return $output; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: