source: sipes/0.3-modules/services_views/services_views.resource.inc @ 9a34bd5

version-3.0
Last change on this file since 9a34bd5 was 9a34bd5, checked in by Sipes Apn <root@…>, 7 años ago

se agrego el modulo de servicios views

  • Propiedad mode establecida a 100755
File size: 4.7 KB
Línea 
1<?php
2/**
3 * @file
4 * Callbacks for services module resource hooks.
5 */
6
7/**
8 * Callback for retrieving views resources.
9 *
10 * @param $view_name
11 *   String. The views name.
12 * @param $display_id
13 *   String (optional). The views display name.
14 * @param $offset
15 *   Integer (optional). An offset integer for paging.
16 * @param $limit
17 *   Integer (optional). A limit integer for paging.
18 * @param $args
19 *   Array (optional). A list of arguments to pass to the view.
20 * @param $theme_output
21 *   String (optional). Whether to return the raw data results (FALSE), the entire views object ('view') or themed results ('theme').
22 * @param $args
23 *   Array (optional). A list of exposed filters to pass to the view.
24 *
25 * @return
26 *  Array. The views return.
27 */
28function services_views_retrieve($view_name, $display_id = 'default', $args = array(), $offset = 0, $limit = 0, $theme_output = FALSE, $filters = array()) {
29  $result = array();
30  $view = views_get_view($view_name);
31  $view->set_display($display_id);
32  // Put all arguments and filters and then execute.
33  $view->set_arguments($args, FALSE);
34  $view->set_exposed_input($filters);
35  $offset = (int) $offset;
36  if ($offset) {
37    $view->set_offset($offset);
38  }
39  // Support for Views 2
40  $limit = (int) $limit;
41  if ($limit) {
42    if (method_exists($view, 'set_use_pager')) {
43      // If offset is set we can't have a user pager.
44      if (empty($offset)) {
45        $view->set_use_pager(TRUE);
46        $view->set_items_per_page($limit);
47      }
48      else {
49        // Disable the user pager.
50        $view->set_use_pager(FALSE);
51      }
52    }
53    else {
54      $view->set_items_per_page($limit);
55    }
56  }
57  if (!($theme_output)) {
58    $view->pre_execute();
59    $row_plugin = $view->display_handler->get_option('row_plugin');
60    // If row plugin is node, then we should load each node
61    if ($row_plugin == 'node') {
62      $view->execute();
63      $result = $view->result;
64      $nodes = array();
65      foreach ($view->result as $row) {
66        $nodes[] = services_node_load(node_load($row->nid));
67      }
68      $result = $nodes;
69    }
70    elseif ($row_plugin == 'fields') {
71
72      $fields = $view->field;
73      $view->execute();
74      $item = new stdClass();
75      $labels = array();
76      $no_permitidas= array (
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      $permitidas= array (
127        "a",
128        "e",
129        "i",
130        "o",
131        "u",
132        "A",
133        "E",
134        "I",
135        "O",
136        "U",
137        "n",
138        "N",
139        "A",
140        "A",
141        "I",
142        "O",
143        "U",
144        "A™",
145        "A ",
146        "A",
147        "A",
148        "A",
149        "A",
150        "s",
151        "S",
152        "A",
153        "e",
154        "A",
155        "AÂŽ",
156        "A",
157        "A",
158        "A",
159        "AZ",
160        "A",
161        "A",
162        "u",
163        "A",
164        "A",
165        "A",
166        "A",
167        "_",
168        "O",
169        "A",
170        "A",
171        "A",
172        "_",
173        "_",
174        "A",
175      );
176      foreach ($view->result as $index => $row) {
177        $item = new stdClass();
178        foreach ($fields as $field_id => $field) {
179          if (!$field->options['exclude']) {
180            if (!isset($labels[$field_id])) {
181              if (!empty($field->options['label'])) {
182                $field_label = strtolower($field->options['label']);
183              }
184              elseif ($field->field_alias) {
185                $field_label = $field->field_alias;
186              }
187              else {
188                $field_label = $field_id;
189              }
190              //$field_label = check_plain($field_label);
191              $labels[$field_id] = str_replace($no_permitidas, $permitidas, $field_label);
192            }
193            $field->pre_render($row);
194            $item->{$labels[$field_id]} = $field->render($row);
195          }
196        }
197        $items[] = $item;
198      }
199      if ($items) {
200        $result = $items;
201      }
202
203    }
204
205  }
206  elseif ($theme_output == 'view') {
207    $view->set_display($display_id);
208    $view->execute();
209    return $view;
210  }
211  else {
212    // We want to keep the result an array.
213    $result[] = $view->preview($display_id);
214  }
215  return $result;
216}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.