-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhelper.php
239 lines (204 loc) · 5.89 KB
/
helper.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<?php
/**
* @version 3.0 stable $Id: default.php yannick berges
* @package Joomla
* @copyright (C) 2018 Berges Yannick - www.com3elles.com
* @license GNU/GPL v2
*
* special thanks to my master Marc Studer
** special thanks to Shane for helping
*
* JOOMLA admin module by Com3elles is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
**/
//blocage des accès directs sur ce script
\defined('_JEXEC') or die;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Component\Actionlogs\Administrator\Helper\ActionlogsHelper;
use Joomla\Component\Actionlogs\Administrator\Model\ActionlogsModel;
use Joomla\Database\ParameterType;
use Joomla\Module\Quickicon\Administrator\Event\QuickIconsEvent;
use Joomla\Registry\Registry;
use Joomla\CMS\Router\Route;
abstract class modDashboardHelper
{
public static function getItems($data)
{
// recuperation utilisateur connecté
$user = Factory::getUser();
$userid = $user->id;
$catids = $data->catidlist ?? [];
$limit = $data->count;
$nom_statut = $data->TypofBlock;
// recupere la connexion à la BD
$db = Factory::getDbo();
$query = $db->getQuery(true);
$query
->select(
$db->quoteName(
array(
'a.id',
'a.title',
'a.created',
'a.created_by',
'a.modified',
'a.modified_by',
'a.featured',
'a.state',
'a.catid',
'b.name'
)
)
)
->select($db->quoteName('c.title', 'category'))
->from($db->quoteName('#__content', 'a'))
->join(
'LEFT',
$db->quoteName('#__users', 'b') . 'ON' . $db->quoteName('a.created_by') . '=' . $db->quoteName('b.id')
) // récup utilisateur
->join(
'LEFT',
$db->quoteName('#__categories', 'c') . 'ON' . $db->quoteName('a.catid') . '=' . $db->quoteName('c.id') // récup catégorie
);
// ici en fonction du statut
switch ($nom_statut)
{
case ('fb'):
$featured = 1;
$query
->where($db->quoteName('a.featured') . '= :feature')
->bind(':feature', $featured, ParameterType::INTEGER);
break;
case ('pb'):
$state = 1;
$query
->where($db->quoteName('a.state') . '= :state')
->bind(':state', $state, ParameterType::INTEGER);
break;
case ('upb'):
$state = 0;
$query
->where($db->quoteName('a.state') . '= :state')
->bind(':state', $state, ParameterType::INTEGER);
break;
case ('ab'):
$state = 2;
$query
->where($db->quoteName('a.state') . '= :state')
->bind(':state', $state, ParameterType::INTEGER);
break;
case ('tb'):
$state = -2;
$query
->where($db->quoteName('a.state') . '= :state')
->bind(':state', $state, ParameterType::INTEGER);
break;
}
//ici la catégorie
if (!empty($catids))
{
$query->whereIn($db->quoteName('a.catid'), $catids, ParameterType::LARGE_OBJECT);
}
//ici order
$query->order('a.modified DESC')
//ici la limite
->setLimit($limit);
$db->setQuery($query);
$items = $db->loadObjectList();
foreach ($items as $item)
{
$item->link = Route::_('index.php?option=com_content&task=article.edit&id=' . $item->id);
}
return $items;
}
public static function getUseritem(&$params)
{
$user = Factory::getUser();
$userid = $user->id;
//recupére la connexion à la BD
$db = Factory::getDbo();
$queryUseritem = 'SELECT id, title, catid, created, created_by, modified, modified_by, state FROM #__content WHERE created_by = ' . $user->id . ' ORDER BY modified DESC LIMIT 50';
$db->setQuery($queryUseritem);
$itemsUseritem = $db->loadObjectList();
foreach ($itemsUseritem as &$itemUseritem)
{
$itemUseritem->link = Route::_('index.php?option=com_content&task=article.edit&id=' . $itemUseritem->id);
switch ($itemUseritem->state)
{
case 0:
$itemUseritem->state = JText::_('JUNPUBLISHED');
break;
case 1:
$itemUseritem->state = JText::_('JPUBLISHED');
break;
case 2:
$itemUseritem->state = JText::_('JARCHIVED');
break;
case -2:
$itemUseritem->state = JText::_('JTRASHED');
break;
}
}
return $itemsUseritem;
}
public static function getIconFromPlugins(Registry $params, CMSApplication $application = null)
{
$key = (string) $params;
$context = (string) $params->get('context', 'update_quickicon');
$application = Factory::getApplication();
PluginHelper::importPlugin('quickicon');
$buttons[$key] = [];
$arrays = (array) $application->triggerEvent(
'onGetIcons',
new QuickIconsEvent('onGetIcons', ['context' => $context])
);
foreach ($arrays as $response)
{
if (!\is_array($response))
{
continue;
}
foreach ($response as $icon)
{
$default = array(
'link' => null,
'image' => null,
'text' => null,
'name' => null,
'linkadd' => null,
'access' => true,
'class' => null,
'group' => 'MOD_QUICKICON',
);
$icon = array_merge($default, $icon);
if (!\is_null($icon['link']) && !\is_null($icon['text']))
{
$buttons[$key][] = $icon;
}
}
}
return $buttons[$key];
}
public static function getActionlogList(&$params)
{
/** @var ActionlogsModelActionlogs $model */
$model = new ActionlogsModel(['ignore_request' => true]);
// Set the Start and Limit
$model->setState('list.start', 0);
$model->setState('list.limit', $params->get('count', 5));
$model->setState('list.ordering', 'a.id');
$model->setState('list.direction', 'DESC');
$rows = $model->getItems();
// Load all actionlog plugins language files
ActionlogsHelper::loadActionLogPluginsLanguage();
foreach ($rows as $row)
{
$row->message = ActionlogsHelper::getHumanReadableLogMessage($row);
}
return $rows;
}
}