source: sipes/modules_contrib/date/includes/date_api_fields.inc @ 92213c1

stableversion-3.0
Last change on this file since 92213c1 was 177a560, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se agrego el directorio de modulos contribuidos de drupal

  • Propiedad mode establecida a 100755
File size: 6.3 KB
Línea 
1<?php
2/**
3 * @file
4 * Identification for fields the Date handlers can use.
5 */
6
7/**
8 *  Identify all potential date/timestamp fields.
9 *
10 *  @return
11 *    array with fieldname, type, and table.
12 *  @see date_api_date_api_fields() which implements
13 *    the hook_date_api_fields() for the core date fields.
14 */
15function _date_api_fields($base = 'node') {
16  // Make sure $base is never empty.
17  if (empty($base)) {
18    $base = 'node';
19  }
20  $cid = 'date_api_fields_'. $base;
21  cache_clear_all($cid, 'cache_views');
22
23  $all_fields = date_api_views_fetch_fields($base, 'field');
24  $fields = array();
25  foreach ((array) $all_fields as $name => $val) {
26    $fromto = array();
27    $tmp = explode('.', $name);
28    $field_name = $tmp[1];
29    $table_name = $tmp[0];
30    $alias = str_replace('.', '_', $name);
31
32    if (!$handler = views_get_handler($table_name, $field_name, 'field')) {
33      continue;
34    }
35
36    $handler_name = $handler->definition['handler'];
37    $type = '';
38
39    // For cck fields, get the date type.
40    $custom = array();
41    if (isset($handler->content_field)) {
42      if ($handler->content_field['type'] == 'date') {
43        $type = 'cck_string';
44      }
45      elseif ($handler->content_field['type'] == 'datestamp') {
46        $type = 'cck_timestamp';
47      }
48      elseif ($handler->content_field['type'] == 'datetime') {
49        $type = 'cck_datetime';
50      }
51    }
52
53    // Allow custom modules to provide date fields.
54    // The is_a() function makes this work for any handler
55    // that was derived from 'views_handler_field_date'.
56    // Unfortunately is_a() is deprecated in PHP 5.2, so we need
57    // a more convoluted test.
58    elseif ((version_compare(PHP_VERSION, '5.2', '<') && is_a($handler, 'views_handler_field_date')) || ($handler instanceof views_handler_field_date)) {
59      foreach (module_implements('date_api_fields') as $module) {
60        $function = $module .'_date_api_fields';
61        if ($custom = $function("$table_name.$field_name")) {
62          $type = 'custom';
63          break;
64        }
65      }
66    }
67
68    // Don't do anything if this is not a date field we can handle.
69    if (!empty($type)) {
70
71      // Handling for simple timestamp fields
72      $fromto = array($alias, $alias);
73      $tz_handling = 'site';
74      $related_fields = array();
75      $timezone_field = '';
76      $offset_field = '';
77      $rrule_field = '';
78      $delta_field = '';
79      $granularity = array('year', 'month', 'day', 'hour', 'minute');
80
81      // Handling for content field dates
82      if (isset($handler->content_field['tz_handling'])) {
83        $tz_handling = $handler->content_field['tz_handling'];
84        $db_info = content_database_info($handler->content_field);
85        if ($tz_handling == 'date') {
86          $offset_field = $table_name .'.'. $db_info['columns']['offset']['column'];
87        }
88        $related_fields = array(
89          $table_name .'.'. $field_name
90          );
91        if (isset($db_info['columns']['value2']['column'])) {
92          $related_fields = array_merge($related_fields, array($table_name .'.'. $db_info['columns']['value2']['column']));
93        }
94        if (isset($db_info['columns']['timezone']['column'])) {
95          $related_fields = array_merge($related_fields, array($table_name .'.'. $db_info['columns']['timezone']['column']));
96          $timezone_field = $table_name .'.'. $db_info['columns']['timezone']['column'];
97        }
98        if (isset($db_info['columns']['rrule']['column'])) {
99          $related_fields = array_merge($related_fields, array($table_name .'.'. $db_info['columns']['rrule']['column']));
100          $rrule_field = $table_name .'.'. $db_info['columns']['rrule']['column'];
101        }
102      }
103      // Get the delta value into the query.
104      if (!empty($handler->content_field['multiple'])) {
105        array_push($related_fields, "$table_name.delta");
106        $delta_field = $table_name .'_delta';
107      }
108
109      // Handling for cck fromto dates
110      if (isset($handler->content_field)) {
111        switch ($handler->content_field['type']) {
112          case 'date':
113          case 'datetime':
114          case 'datestamp':
115            $db_info = content_database_info($handler->content_field);
116            $fromto = array(
117              $table_name .'_'. $db_info['columns']['value']['column'],
118              $table_name .'_'. (!empty($handler->content_field['todate']) ? $db_info['columns']['value2']['column'] : $db_info['columns']['value']['column']),
119              );
120            break;
121        }
122        $granularity = !empty($handler->content_field['granularity']) ? $handler->content_field['granularity'] : array('year', 'month', 'day', 'hour', 'minute');
123      }
124
125      // CCK fields append a column name to the field, others do not
126      // need a real field_name with no column name appended for cck date formatters
127      switch ($type) {
128        case 'cck_string':
129          $sql_type = DATE_ISO;
130          break;
131        case 'cck_datetime':
132          $sql_type = DATE_DATETIME;
133          break;
134        default:
135          $sql_type = DATE_UNIX;
136          break;
137      }
138      $fields['name'][$name] = array(
139        'type' => $type,
140        'sql_type' => $sql_type,
141        'label' => $val['group'] .': '. $val['title'],
142        'granularity' => $granularity,
143        'fullname' => $name,
144        'table_name' => $table_name,
145        'field_name' => $field_name,
146        'query_name' => $alias,
147        'fromto' => $fromto,
148        'tz_handling' => $tz_handling,
149        'offset_field' => $offset_field,
150        'timezone_field' => $timezone_field,
151        'rrule_field' => $rrule_field,
152        'related_fields' => $related_fields,
153        'delta_field' => $delta_field,
154      );
155
156      // Allow the custom fields to over-write values.
157      if (!empty($custom)) {
158        foreach ($custom as $key => $val) {
159          $fields['name'][$name][$key] = $val;
160        }
161      }
162      if (isset($handler->content_field)) {
163        if (drupal_substr($field_name, -1) == '2') {
164          $len = (drupal_strlen($field_name) - 7);
165        }
166        else {
167          $len = (drupal_strlen($field_name) - 6);
168        }
169        $fields['name'][$name]['real_field_name'] = drupal_substr($field_name, 0, $len);
170      }
171      else {
172        $fields['name'][$name]['real_field_name'] = $field_name;
173      }
174      $fields['alias'][$alias] = $fields['name'][$name];
175    }
176  }
177  cache_set($cid, $fields, 'cache_views');
178  return $fields;
179}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.