Révision 32700c57
Ajouté par Assos Assos il y a environ 5 ans
drupal7/sites/all/modules/ldap/ldap_query/LdapQueryAdmin.class.php | ||
---|---|---|
2 | 2 |
|
3 | 3 |
/** |
4 | 4 |
* @file |
5 |
* LDAP Query Admin Class |
|
6 |
* |
|
5 |
* LDAP Query Admin Class. |
|
7 | 6 |
*/ |
8 | 7 |
|
9 | 8 |
module_load_include('php', 'ldap_query', 'LdapQuery.class'); |
10 |
|
|
9 |
/** |
|
10 |
* |
|
11 |
*/ |
|
11 | 12 |
class LdapQueryAdmin extends LdapQuery { |
12 | 13 |
|
13 | 14 |
/** |
14 |
* @param string $sid either 'all' or the ldap server sid |
|
15 |
* @param $type = 'all', 'enabled' |
|
15 |
* @param string $sid |
|
16 |
* either 'all' or the ldap server sid. |
|
17 |
* @param $type |
|
18 |
* = 'all', 'enabled' |
|
16 | 19 |
*/ |
17 | 20 |
public static function getLdapQueryObjects($sid = 'all', $type = 'enabled', $class = 'LdapQuery') { |
18 |
$queries = array();
|
|
21 |
$queries = [];
|
|
19 | 22 |
if (module_exists('ctools')) { |
20 | 23 |
ctools_include('export'); |
21 | 24 |
$select = ctools_export_load_object('ldap_query', 'all'); |
... | ... | |
28 | 31 |
} |
29 | 32 |
catch (Exception $e) { |
30 | 33 |
drupal_set_message(t('query index query failed. Message = %message, query= %query', |
31 |
array('%message' => $e->getMessage(), '%query' => $e->query_string)), 'error');
|
|
32 |
return array();
|
|
34 |
['%message' => $e->getMessage(), '%query' => $e->query_string]), 'error');
|
|
35 |
return [];
|
|
33 | 36 |
} |
34 | 37 |
} |
35 | 38 |
foreach ($select as $result) { |
... | ... | |
46 | 49 |
|
47 | 50 |
} |
48 | 51 |
|
49 |
function __construct($qid) { |
|
52 |
/** |
|
53 |
* |
|
54 |
*/ |
|
55 |
public function __construct($qid) { |
|
50 | 56 |
parent::__construct($qid); |
51 | 57 |
} |
52 | 58 |
|
59 |
/** |
|
60 |
* |
|
61 |
*/ |
|
53 | 62 |
protected function populateFromDrupalForm($op, $values) { |
54 | 63 |
|
55 | 64 |
foreach ($this->fields() as $field_id => $field) { |
... | ... | |
66 | 75 |
$this->inDatabase = ($op == 'edit'); |
67 | 76 |
} |
68 | 77 |
|
78 |
/** |
|
79 |
* |
|
80 |
*/ |
|
69 | 81 |
public function save($op) { |
70 | 82 |
|
71 | 83 |
$op = $this->inDatabase ? 'edit' : 'insert'; |
72 | 84 |
|
73 |
if (module_exists('ctools')) { // add or edit with ctolls |
|
85 |
// Add or edit with ctolls. |
|
86 |
if (module_exists('ctools')) { |
|
74 | 87 |
|
75 | 88 |
ctools_include('export'); |
76 | 89 |
$ctools_values = clone $this; |
77 | 90 |
|
78 | 91 |
foreach ($this->fields() as $field_id => $field) { |
79 | 92 |
$value = $this->{$field['property_name']}; |
80 |
if (isset($field['exportable']) && $field['exportable'] === FALSE) { // field not exportable |
|
93 |
// Field not exportable. |
|
94 |
if (isset($field['exportable']) && $field['exportable'] === FALSE) { |
|
81 | 95 |
unset($ctools_values->{$field['property_name']}); |
82 | 96 |
} |
83 |
elseif (isset($field['schema']) && $field['property_name'] != $field_id) { // field in property with different name |
|
97 |
// Field in property with different name. |
|
98 |
elseif (isset($field['schema']) && $field['property_name'] != $field_id) { |
|
84 | 99 |
$ctools_values->{$field_id} = $value; |
85 | 100 |
unset($ctools_values->{$field['property_name']}); |
86 | 101 |
} |
87 | 102 |
else { |
88 |
// do nothing. property is already in cloned objecat |
|
89 |
|
|
103 |
// Do nothing. property is already in cloned objecat. |
|
90 | 104 |
} |
91 | 105 |
} |
92 | 106 |
|
93 |
// Populate our object with ctool's properties. copying all properties for backward compatibility |
|
107 |
// Populate our object with ctool's properties. copying all properties for backward compatibility.
|
|
94 | 108 |
$object = ctools_export_crud_new('ldap_query'); |
95 | 109 |
|
96 | 110 |
foreach ($object as $property_name => $value) { |
... | ... | |
99 | 113 |
} |
100 | 114 |
} |
101 | 115 |
$result = ctools_export_crud_save('ldap_query', $ctools_values); |
102 |
ctools_export_load_object_reset('ldap_query'); // ctools_export_crud_save doesn't invalidate cache |
|
116 |
// ctools_export_crud_save doesn't invalidate cache. |
|
117 |
ctools_export_load_object_reset('ldap_query'); |
|
103 | 118 |
} |
104 | 119 |
else { |
105 |
$values = array();
|
|
120 |
$values = [];
|
|
106 | 121 |
foreach ($this->fields() as $field_id => $field) { |
107 | 122 |
if (isset($field['schema'])) { |
108 | 123 |
$values[$field_id] = $this->{$field['property_name']}; |
109 | 124 |
} |
110 | 125 |
} |
111 |
if ($op == 'edit') { // edit w/o ctools |
|
126 |
// Edit w/o ctools. |
|
127 |
if ($op == 'edit') { |
|
112 | 128 |
$result = drupal_write_record('ldap_query', $values, 'qid'); |
113 | 129 |
} |
114 |
else { // insert |
|
130 |
// Insert. |
|
131 |
else { |
|
115 | 132 |
$result = drupal_write_record('ldap_query', $values); |
116 | 133 |
} |
117 | 134 |
} |
... | ... | |
124 | 141 |
} |
125 | 142 |
} |
126 | 143 |
|
144 |
/** |
|
145 |
* |
|
146 |
*/ |
|
127 | 147 |
public function delete($qid) { |
128 | 148 |
if ($qid == $this->qid) { |
129 | 149 |
$this->inDatabase = FALSE; |
... | ... | |
138 | 158 |
} |
139 | 159 |
} |
140 | 160 |
|
161 |
/** |
|
162 |
* |
|
163 |
*/ |
|
141 | 164 |
public function getActions() { |
142 |
$switch = ($this->status ) ? 'disable' : 'enable';
|
|
143 |
$actions = array();
|
|
165 |
$switch = ($this->status) ? 'disable' : 'enable'; |
|
166 |
$actions = [];
|
|
144 | 167 |
$actions[] = l(t('edit'), LDAP_QUERY_MENU_BASE_PATH . '/query/edit/' . $this->qid); |
145 | 168 |
if (property_exists($this, 'type')) { |
146 | 169 |
if ($this->type == 'Overridden') { |
147 |
$actions[] = l(t('revert'), LDAP_QUERY_MENU_BASE_PATH . '/query/delete/' . $this->qid);
|
|
170 |
$actions[] = l(t('revert'), LDAP_QUERY_MENU_BASE_PATH . '/query/delete/' . $this->qid); |
|
148 | 171 |
} |
149 | 172 |
if ($this->type == 'Normal') { |
150 |
$actions[] = l(t('delete'), LDAP_QUERY_MENU_BASE_PATH . '/query/delete/' . $this->qid);
|
|
173 |
$actions[] = l(t('delete'), LDAP_QUERY_MENU_BASE_PATH . '/query/delete/' . $this->qid); |
|
151 | 174 |
} |
152 | 175 |
} |
153 | 176 |
else { |
154 |
$actions[] = l(t('delete'), LDAP_QUERY_MENU_BASE_PATH . '/query/delete/' . $this->qid);
|
|
177 |
$actions[] = l(t('delete'), LDAP_QUERY_MENU_BASE_PATH . '/query/delete/' . $this->qid); |
|
155 | 178 |
} |
156 | 179 |
$actions[] = l(t('test'), LDAP_QUERY_MENU_BASE_PATH . '/query/test/' . $this->qid); |
157 | 180 |
$actions[] = l($switch, LDAP_QUERY_MENU_BASE_PATH . '/query/' . $switch . '/' . $this->qid); |
158 | 181 |
return $actions; |
159 | 182 |
} |
160 | 183 |
|
184 |
/** |
|
185 |
* |
|
186 |
*/ |
|
161 | 187 |
public function drupalForm($op) { |
162 | 188 |
$form['#prefix'] = t('<p>Setup an LDAP query to be used by other modules |
163 | 189 |
such as LDAP Feeds.</p>'); |
164 | 190 |
|
165 |
$form['basic'] = array(
|
|
191 |
$form['basic'] = [
|
|
166 | 192 |
'#type' => 'fieldset', |
167 | 193 |
'#title' => t('Basic LDAP Query Settings'), |
168 | 194 |
'#collapsible' => TRUE, |
169 | 195 |
'#collapsed' => FALSE, |
170 |
);
|
|
196 |
];
|
|
171 | 197 |
|
172 |
$form['query'] = array(
|
|
198 |
$form['query'] = [
|
|
173 | 199 |
'#type' => 'fieldset', |
174 | 200 |
'#title' => t('Query'), |
175 | 201 |
'#collapsible' => TRUE, |
176 | 202 |
'#collapsed' => FALSE, |
177 |
);
|
|
203 |
];
|
|
178 | 204 |
|
179 |
$form['query_advanced'] = array(
|
|
205 |
$form['query_advanced'] = [
|
|
180 | 206 |
'#type' => 'fieldset', |
181 | 207 |
'#title' => t('Advanced Query Settings'), |
182 | 208 |
'#collapsible' => TRUE, |
183 | 209 |
'#collapsed' => TRUE, |
184 |
); |
|
185 |
|
|
210 |
]; |
|
186 | 211 |
|
187 | 212 |
foreach ($this->fields() as $field_id => $field) { |
188 | 213 |
$field_group = isset($field['form']['field_group']) ? $field['form']['field_group'] : FALSE; |
... | ... | |
191 | 216 |
$form_item['#default_value'] = $this->{$field['property_name']}; |
192 | 217 |
if ($field_group) { |
193 | 218 |
$form[$field_group][$field_id] = $form_item; |
194 |
unset($form[$field_group][$field_id]['field_group']); // sirrelevant to form api |
|
219 |
// Sirrelevant to form api. |
|
220 |
unset($form[$field_group][$field_id]['field_group']); |
|
195 | 221 |
} |
196 | 222 |
else { |
197 | 223 |
$form[$field_id] = $form_item; |
... | ... | |
211 | 237 |
|
212 | 238 |
$form['basic']['sid']['#options'] = $server_options; |
213 | 239 |
|
214 |
$form['submit'] = array(
|
|
240 |
$form['submit'] = [
|
|
215 | 241 |
'#type' => 'submit', |
216 | 242 |
'#value' => t('Save Query'), |
217 |
);
|
|
243 |
];
|
|
218 | 244 |
|
219 | 245 |
$action = ($op == 'add') ? 'Add' : 'Update'; |
220 |
$form['submit'] = array(
|
|
246 |
$form['submit'] = [
|
|
221 | 247 |
'#type' => 'submit', |
222 | 248 |
'#value' => $action, |
223 | 249 |
'#weight' => 100, |
224 |
);
|
|
250 |
];
|
|
225 | 251 |
|
226 | 252 |
return $form; |
227 | 253 |
} |
228 | 254 |
|
229 |
|
|
230 |
public function drupalFormValidate($op, $values) { |
|
231 |
$errors = array(); |
|
255 |
/** |
|
256 |
* |
|
257 |
*/ |
|
258 |
public function drupalFormValidate($op, $values) { |
|
259 |
$errors = []; |
|
232 | 260 |
|
233 | 261 |
if ($op == 'delete') { |
234 | 262 |
if (!$this->qid) { |
... | ... | |
242 | 270 |
return $errors; |
243 | 271 |
} |
244 | 272 |
|
273 |
/** |
|
274 |
* |
|
275 |
*/ |
|
245 | 276 |
protected function validate($op) { |
246 |
$errors = array();
|
|
277 |
$errors = [];
|
|
247 | 278 |
if ($op == 'add') { |
248 | 279 |
$ldap_queries = $this->getLdapQueryObjects('all', 'all'); |
249 | 280 |
if (count($ldap_queries)) { |
250 | 281 |
foreach ($ldap_queries as $qid => $ldap_query) { |
251 | 282 |
if ($this->qid == $ldap_query->qid) { |
252 |
$errors['qid'] = t('An LDAP Query with the name %qid already exists.', array('%qid' => $this->qid));
|
|
283 |
$errors['qid'] = t('An LDAP Query with the name %qid already exists.', ['%qid' => $this->qid]);
|
|
253 | 284 |
} |
254 | 285 |
} |
255 | 286 |
} |
... | ... | |
258 | 289 |
return $errors; |
259 | 290 |
} |
260 | 291 |
|
292 |
/** |
|
293 |
* |
|
294 |
*/ |
|
261 | 295 |
public function drupalFormSubmit($op, $values) { |
262 | 296 |
|
263 | 297 |
$this->populateFromDrupalForm($op, $values); |
... | ... | |
265 | 299 |
if ($op == 'delete') { |
266 | 300 |
$this->delete($this); |
267 | 301 |
} |
268 |
else { // add or edit |
|
302 |
// Add or edit. |
|
303 |
else { |
|
269 | 304 |
try { |
270 | 305 |
$save_result = $this->save($op); |
271 | 306 |
} |
... | ... | |
276 | 311 |
} |
277 | 312 |
} |
278 | 313 |
|
314 |
/** |
|
315 |
* |
|
316 |
*/ |
|
279 | 317 |
protected function arrayToLines($array) { |
280 | 318 |
$lines = ""; |
281 | 319 |
if (is_array($array)) { |
... | ... | |
287 | 325 |
return $lines; |
288 | 326 |
} |
289 | 327 |
|
290 |
|
|
291 |
|
|
328 |
/** |
|
329 |
* |
|
330 |
*/ |
|
292 | 331 |
protected function arrayToCsv($array) { |
293 | 332 |
return join(",", $array); |
294 | 333 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules