Projet

Général

Profil

Paste
Télécharger (4,18 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ldap / ldap_query / ldap_query.theme.inc @ 91af538d

1
<?php
2

    
3
/**
4
 * @file
5
 * Theming functions for ldap_query module.
6
 */
7

    
8
/**
9
 * Returns HTML for ldap servers list.
10
 *
11
 * @param $variables
12
 *   An associative array containing:
13
 *   - ldap_queries: an array of one or more ldap server configurations.
14
 *   - actions:  true or false indicating include update, delete, etc. links
15
 *   - type:  'table', 'list', etc for style to render
16
 *
17
 * @ingroup themeable
18
 */
19
function theme_ldap_query_list($variables) {
20
  /** @var array $ldap_queries */
21
  /** @var bool $actions */
22
  /** @var string $type */
23
  extract($variables);
24

    
25
  $table = [
26
    'header' => [t('Name'), t('Base DN'), t('Filter'), t('Attributes'), t('Enabled')],
27
    'attributes' => ['id' => 'ldap_queries', 'class' => 'data'],
28
    'colgroups' => [],
29
    'sticky' => FALSE,
30
    'empty' => '',
31
    'caption' => 'LDAP Queries',
32
  ];
33

    
34
  if ($actions) {
35
    $table['header'][] = "Operations";
36
  }
37

    
38
  if (count($ldap_queries)) {
39
    foreach ($ldap_queries as $qid => $ldap_query) {
40
      $row = [
41
        $ldap_query->name,
42
        $ldap_query->base_dn_str,
43
        $ldap_query->filter,
44
        $ldap_query->attributes_str,
45
        ($ldap_query->status == 1) ? "Yes" : "No",
46
      ];
47
      if ($actions) {
48
        $admin = new LdapQueryAdmin($ldap_query->qid);
49
        $row[] = join(' | ', $admin->getActions());
50
      }
51
      $table['rows'][] = $row;
52
    }
53
  }
54
  else {
55
    $table['rows'] = [];
56
  }
57
  $output = theme('table', $table);
58

    
59
  return $output;
60
}
61

    
62
/**
63
 * Returns HTML for ldap server.
64
 *
65
 * @param $variables
66
 *   An associative array containing:
67
 *   - ldap_query_config: an array of one or more ldap server configurations.
68
 *   - actions:  true or false indicating include update, delete, etc. links
69
 *   - type:  'table', 'list', etc for style to render
70
 *
71
 * @ingroup themeable
72
 *
73
 * @return string
74
 */
75
function theme_ldap_query($variables) {
76
  /** @var array $ldap_query */
77
  /** @var bool $actions */
78
  /** @var string $type */
79
  extract($variables);
80

    
81
  ldap_servers_module_load_include('php', 'ldap_query', 'LdapQuery.class');
82
  $properties = [];
83
  foreach (LdapQuery::fields() as $field_id => $field) {
84
    $value = $ldap_query->{$field['property_name']};
85
    if (is_scalar($value)) {
86
      $properties[] = $field_id . " = " . $value;
87
    }
88
  }
89

    
90
  if ($actions) {
91
    $admin = new LdapQueryAdmin($ldap_query->sid);
92
    $properties = join(' | ', $admin->getActions());
93
  }
94

    
95
  $output = theme_item_list(
96
    [
97
      'items' => $properties,
98
      'type' => 'ul',
99
      'title' => 'Query Properties',
100
      'attributes' => [],
101
    ]
102
    );
103

    
104
  return $output;
105
}
106

    
107
/**
108
 * @param $variables
109
 *
110
 * @return string
111
 */
112
function theme_ldap_query_results($variables) {
113
  // $ldap_query, $results, $show_query.
114
  /** @var array $ldap_query */
115
  /** @var array $results */
116
  /** @var mixed $show_query */
117
  extract($variables);
118

    
119
  $query = theme('ldap_query', ['ldap_query' => $ldap_query]);
120
  $results_text = t('LDAP Query Results: count=%count', ['%count' => $results['count']]);
121

    
122
  if (!$results['count']) {
123
    return $query . '<br/>' . $results_text;
124
  }
125

    
126
  $table = [
127
    'header' => ['DN'],
128
    'attributes' => ['id' => 'ldap_query_resultset', 'class' => 'data'],
129
    'colgroups' => [],
130
    'sticky' => FALSE,
131
    'empty' => '',
132
    'caption' => $results_text,
133
  ];
134
  unset($results['count']);
135

    
136
  $attributes_display = [];
137
  // Searching on all attributes.
138
  if (isset($results[0]) && $results[0]) {
139
    foreach ($results[0] as $k => $v) {
140
      if (is_numeric($k)) {
141
        $attributes_display[] = $v;
142
      }
143
    }
144
  }
145

    
146
  foreach ($attributes_display as $attr) {
147
    $table['header'][] = $attr;
148
  }
149

    
150
  foreach ($results as $i => $entry) {
151
    $row = [$entry['dn']];
152
    foreach ($attributes_display as $i => $attr_name) {
153
      // drupal_strtolower($attr_name);
154
      $attr_name = ldap_server_massage_text($attr_name, 'attr_name', LDAP_SERVER_MASSAGE_QUERY_ARRAY);
155
      if (!isset($entry[$attr_name])) {
156
        $row[] = 'no data';
157
      }
158
      elseif (is_array($entry[$attr_name])) {
159
        unset($entry[$attr_name]['count']);
160
        $row[] = join("<br/>", $entry[$attr_name]);
161
      }
162
      else {
163
        $row[] = $entry[$attr_name];
164
      }
165
    }
166
    unset($entry['count']);
167
    $table['rows'][] = $row;
168
  }
169
  return $query . '<br/>' . theme_table($table);
170

    
171
}