profiles.php
5.88 KB
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
<?php
/**
* @copyright Copyright (c) 2009-2020 Ryan Demmer. All rights reserved
* @license GNU/GPL 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* JCE is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses
*/
defined('JPATH_PLATFORM') or die;
require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/profiles.php';
class JceModelProfiles extends JModelList
{
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
*
* @see JControllerLegacy
* @since 1.6
*/
public function __construct($config = array())
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = array(
'id', 'id',
'name', 'name',
'checked_out', 'checked_out',
'checked_out_time', 'checked_out_time',
'published', 'published',
'ordering', 'ordering',
);
}
parent::__construct($config);
}
/**
* Method to auto-populate the model state.
*
* @param string $ordering An optional ordering field.
* @param string $direction An optional direction (asc|desc).
*
* @return void
*
* @note Calling getState in this method will result in recursion.
* @since 1.6
*/
protected function populateState($ordering = null, $direction = null)
{
// Load the filter state.
$this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));
// Load the parameters.
$params = JComponentHelper::getParams('com_jce');
$this->setState('params', $params);
// List state information.
parent::populateState($ordering, $direction);
}
/**
* Method to get a store id based on model configuration state.
*
* This is necessary because the model is used by the component and
* different modules that might need different sets of data or different
* ordering requirements.
*
* @param string $id A prefix for the store id.
*
* @return string A store id.
*
* @since 1.6
*/
protected function getStoreId($id = '')
{
// Compile the store id.
$id .= ':' . $this->getState('filter.search');
return parent::getStoreId($id);
}
/**
* Build an SQL query to load the list data.
*
* @return JDatabaseQuery
*
* @since 1.6
*/
protected function getListQuery()
{
// Create a new query object.
$db = $this->getDbo();
$query = $db->getQuery(true);
$user = JFactory::getUser();
// Select the required fields from the table.
$query->select(
$this->getState(
'list.select',
'id, name, description, ordering, published, checked_out, checked_out_time'
)
);
$query->from($db->quoteName('#__wf_profiles'));
$query->where('(' . $db->quoteName('published') . ' IN (0, 1))');
// Filter by search in title
$search = $this->getState('filter.search');
if (!empty($search)) {
if (stripos($search, 'id:') === 0) {
$query->where($db->quoteName('id') . ' = ' . (int) substr($search, 3));
} else {
$search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%'));
$query->where('(' . $db->quoteName('name') . ' LIKE ' . $search . ' OR ' . $db->quoteName('description') . ' LIKE ' . $search . ')');
}
}
// Add the list ordering clause.
$listOrder = $this->getState('list.ordering', 'ordering');
$listDirn = $this->getState('list.direction', 'ASC');
$query->order($db->escape($listOrder . ' ' . $listDirn));
return $query;
}
public function repair()
{
$file = __DIR__ . '/profiles.xml';
if (!is_file($file)) {
$this->setError(JText::_('WF_PROFILES_REPAIR_ERROR'));
return false;
}
$xml = simplexml_load_file($file);
if (!$xml) {
$this->setError(JText::_('WF_PROFILES_REPAIR_ERROR'));
return false;
}
foreach ($xml->profiles->children() as $profile) {
$groups = JceProfilesHelper::getUserGroups((int) $profile->children('area'));
$table = JTable::getInstance('Profiles', 'JceTable');
foreach ($profile->children() as $item) {
switch ((string) $item->getName()) {
case 'description':
$table->description = JText::_((string) $item);
case 'types':
$table->types = implode(',', $groups);
break;
case 'area':
$table->area = (int) $item;
break;
case 'rows':
$table->rows = (string) $item;
break;
case 'plugins':
$table->plugins = (string) $item;
break;
default:
$key = $item->getName();
$table->$key = (string) $item;
break;
}
}
// Check the data.
if (!$table->check()) {
$this->setError($table->getError());
return false;
}
// Store the data.
if (!$table->store()) {
$this->setError($table->getError());
return false;
}
}
return true;
}
}