Completed
Push — master ( a52438...bf8826 )
by Henry
06:30
created

includes/Admin/View/Helper/Dashboard.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 array $_optionArray =
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_ARRAY, expecting T_FUNCTION or T_CONST
Loading history...
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