1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Base sort handler for a ldap attributes.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
*
|
10
|
*/
|
11
|
class ldap_views_handler_sort_attribute extends ldap_views_handler_sort {
|
12
|
|
13
|
/**
|
14
|
*
|
15
|
*/
|
16
|
public function option_definition() {
|
17
|
$options = parent::option_definition();
|
18
|
$options['attribute_name'] = ['default' => ''];
|
19
|
return $options;
|
20
|
}
|
21
|
|
22
|
/**
|
23
|
*
|
24
|
*/
|
25
|
public function options_form(&$form, &$form_state) {
|
26
|
$ldap_data = new LdapQuery(ldap_views_get_qid($this->view));
|
27
|
if (empty($ldap_data)) {
|
28
|
$form['attribute_name'] = [
|
29
|
'#markup' => 'You must select a valid LDAP search (Advanced::Query settings)',
|
30
|
];
|
31
|
return;
|
32
|
}
|
33
|
|
34
|
parent::options_form($form, $form_state);
|
35
|
$options = [];
|
36
|
foreach ($ldap_data->attributes as $attribute) {
|
37
|
$options[$attribute] = $attribute;
|
38
|
}
|
39
|
$form['attribute_name'] = [
|
40
|
'#type' => 'select',
|
41
|
'#title' => t('Attribute name'),
|
42
|
'#description' => t('The attribute name from LDAP response'),
|
43
|
'#options' => $options,
|
44
|
'#default_value' => $this->options['attribute_name'],
|
45
|
'#required' => TRUE,
|
46
|
];
|
47
|
}
|
48
|
|
49
|
/**
|
50
|
* Called to add the sort to a query.
|
51
|
*/
|
52
|
public function query() {
|
53
|
$this->query->add_orderby($this->table, $this->options['attribute_name'], $this->options['order']);
|
54
|
}
|
55
|
|
56
|
}
|