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