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