1
|
|
|
<?php |
2
|
|
|
namespace Redaxscript\Modules\Reporter; |
3
|
|
|
|
4
|
|
|
use Redaxscript\Filesystem; |
5
|
|
|
use Redaxscript\Html; |
6
|
|
|
use Redaxscript\Model; |
7
|
|
|
use Redaxscript\Module; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Reports on the dashboard |
11
|
|
|
* |
12
|
|
|
* @since 4.1.0 |
13
|
|
|
* |
14
|
|
|
* @package Redaxscript |
15
|
|
|
* @category Modules |
16
|
|
|
* @author Henry Ruhs |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
class Reporter extends Module\Metadata |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* array of the module |
23
|
|
|
* |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
protected static $_moduleArray = |
28
|
|
|
[ |
29
|
|
|
'name' => 'Reporter', |
30
|
|
|
'alias' => 'Reporter', |
31
|
|
|
'author' => 'Redaxmedia', |
32
|
|
|
'description' => 'Reports on the dashboard', |
33
|
|
|
'version' => '4.1.0' |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* array of the option |
38
|
|
|
* |
39
|
|
|
* @var array |
40
|
|
|
*/ |
41
|
|
|
|
42
|
|
|
protected $_optionArray = |
43
|
|
|
[ |
44
|
|
|
'className' => |
45
|
|
|
[ |
46
|
|
|
'title' => 'rs-admin-title-dashboard', |
47
|
|
|
'text' => 'rs-admin-text-dashboard' |
48
|
|
|
] |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* adminDashboard |
53
|
|
|
* |
54
|
|
|
* @since 4.1.0 |
55
|
|
|
* |
56
|
|
|
* @return array |
57
|
|
|
*/ |
58
|
|
|
|
59
|
|
|
public function adminDashboard() : array |
60
|
|
|
{ |
61
|
|
|
$this->setDashboard($this->_renderDashboard('categories')); |
62
|
|
|
$this->setDashboard($this->_renderDashboard('articles')); |
63
|
|
|
$this->setDashboard($this->_renderDashboard('extras')); |
64
|
|
|
$this->setDashboard($this->_renderDashboard('comments')); |
65
|
|
|
$this->setDashboard($this->_renderDashboard('users')); |
66
|
|
|
$this->setDashboard($this->_renderDashboard('groups')); |
67
|
|
|
$this->setDashboard($this->_renderDashboard('modules')); |
68
|
|
|
$this->setDashboard($this->_renderDashboard('languages')); |
69
|
|
|
$this->setDashboard($this->_renderDashboard('templates')); |
70
|
|
|
return $this->getDashboardArray(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* renderDashboard |
75
|
|
|
* |
76
|
|
|
* @since 4.1.0 |
77
|
|
|
* |
78
|
|
|
* @param string type |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
|
|
|
82
|
|
|
protected function _renderDashboard(string $type = null) : string |
83
|
|
|
{ |
84
|
|
|
$categoryModel = new Model\Category(); |
85
|
|
|
$articleModel = new Model\Article(); |
86
|
|
|
$extraModel = new Model\Extra(); |
87
|
|
|
$commentModel = new Model\Comment(); |
88
|
|
|
$userModel = new Model\User(); |
89
|
|
|
$groupModel = new Model\Group(); |
90
|
|
|
$moduleModel = new Model\Module(); |
91
|
|
|
$filesystem = new Filesystem\Filesystem(); |
92
|
|
|
$divider = '/'; |
93
|
|
|
|
94
|
|
|
/* html element */ |
95
|
|
|
|
96
|
|
|
$element = new Html\Element(); |
97
|
|
|
$titleElement = $element |
98
|
|
|
->copy() |
99
|
|
|
->init('h3', |
100
|
|
|
[ |
101
|
|
|
'class' => $this->_optionArray['className']['title'] |
102
|
|
|
]); |
103
|
|
|
$textElement = $element |
104
|
|
|
->copy() |
105
|
|
|
->init('span', |
106
|
|
|
[ |
107
|
|
|
'class' => $this->_optionArray['className']['text'] |
108
|
|
|
]); |
109
|
|
|
|
110
|
|
|
/* handle type */ |
111
|
|
|
|
112
|
|
|
if ($type === 'categories') |
113
|
|
|
{ |
114
|
|
|
$titleElement->text($categoryModel->query()->where('status', 1)->count() . $divider . $categoryModel->query()->count()); |
115
|
|
|
$textElement->text($this->_language->get('_reporter')['categories_publish']); |
116
|
|
|
} |
117
|
|
|
if ($type === 'articles') |
118
|
|
|
{ |
119
|
|
|
$titleElement->text($articleModel->query()->where('status', 1)->count() . $divider . $articleModel->query()->count()); |
120
|
|
|
$textElement->text($this->_language->get('_reporter')['articles_publish']); |
121
|
|
|
} |
122
|
|
|
if ($type === 'extras') |
123
|
|
|
{ |
124
|
|
|
$titleElement->text($extraModel->query()->where('status', 1)->count() . $divider . $extraModel->query()->count()); |
125
|
|
|
$textElement->text($this->_language->get('_reporter')['extras_publish']); |
126
|
|
|
} |
127
|
|
|
if ($type === 'comments') |
128
|
|
|
{ |
129
|
|
|
$titleElement->text($commentModel->query()->where('status', 1)->count() . $divider . $commentModel->query()->count()); |
130
|
|
|
$textElement->text($this->_language->get('_reporter')['comments_publish']); |
131
|
|
|
} |
132
|
|
|
if ($type === 'users') |
133
|
|
|
{ |
134
|
|
|
$titleElement->text($userModel->query()->where('status', 1)->count() . $divider . $userModel->query()->count()); |
135
|
|
|
$textElement->text($this->_language->get('_reporter')['users_enable']); |
136
|
|
|
} |
137
|
|
|
if ($type === 'groups') |
138
|
|
|
{ |
139
|
|
|
$titleElement->text($groupModel->query()->where('status', 1)->count() . $divider . $groupModel->query()->count()); |
140
|
|
|
$textElement->text($this->_language->get('_reporter')['groups_enable']); |
141
|
|
|
} |
142
|
|
|
if ($type === 'modules') |
143
|
|
|
{ |
144
|
|
|
$titleElement->text($moduleModel->query()->count() . $divider . $filesystem->init('modules')->countIterator()); |
145
|
|
|
$textElement->text($this->_language->get('_reporter')['modules_install']); |
146
|
|
|
} |
147
|
|
|
if ($type === 'languages') |
148
|
|
|
{ |
149
|
|
|
$titleElement->text($filesystem->init('languages')->countIterator()); |
150
|
|
|
$textElement->text($this->_language->get('_reporter')['languages_install']); |
151
|
|
|
} |
152
|
|
|
if ($type === 'templates') |
153
|
|
|
{ |
154
|
|
|
$titleElement->text($filesystem->init('templates', false, |
155
|
|
|
[ |
156
|
|
|
'admin', |
157
|
|
|
'console', |
158
|
|
|
'install' |
159
|
|
|
])->countIterator()); |
160
|
|
|
$textElement->text($this->_language->get('_reporter')['templates_install']); |
161
|
|
|
} |
162
|
|
|
return $titleElement . $textElement; |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|