Révision b720ea3e
Ajouté par Assos Assos il y a plus de 8 ans
drupal7/sites/all/modules/date/date_views/date_views.module | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
|
3 |
/** |
|
4 |
* @file |
|
5 |
* Date Views module. |
|
6 |
*/ |
|
3 | 7 |
|
4 | 8 |
/** |
5 | 9 |
* Implements hook_menu(). |
... | ... | |
11 | 15 |
'description' => 'Configure settings for date views.', |
12 | 16 |
'page callback' => 'drupal_get_form', |
13 | 17 |
'page arguments' => array('date_views_settings'), |
14 |
'access arguments' => array('administer site configuration '),
|
|
18 |
'access arguments' => array('administer site configuration'), |
|
15 | 19 |
'type' => MENU_LOCAL_TASK, |
16 | 20 |
); |
17 | 21 |
|
... | ... | |
86 | 90 |
'file' => 'theme.inc', |
87 | 91 |
'path' => "$path/theme", |
88 | 92 |
); |
89 |
return array( |
|
90 |
'date_nav_title' => $base + array('variables' => array('granularity' => NULL, 'view' => NULL, 'link' => NULL, 'format' => NULL)), |
|
91 |
'date_views_filter_form' => $base + array('template' => 'date-views-filter-form', 'render element' => 'form'), |
|
92 |
'date_calendar_day' => $base + array('variables' => array('date' => NULL)), |
|
93 | 93 |
|
94 |
return array( |
|
95 |
'date_nav_title' => $base + array( |
|
96 |
'variables' => array( |
|
97 |
'granularity' => NULL, |
|
98 |
'view' => NULL, |
|
99 |
'link' => NULL, |
|
100 |
'format' => NULL, |
|
101 |
), |
|
102 |
), |
|
103 |
'date_views_filter_form' => $base + array( |
|
104 |
'template' => 'date-views-filter-form', |
|
105 |
'render element' => 'form', |
|
106 |
), |
|
107 |
'date_calendar_day' => $base + array( |
|
108 |
'variables' => array( |
|
109 |
'date' => NULL, |
|
110 |
), |
|
111 |
), |
|
94 | 112 |
'date_views_pager' => $base + array( |
95 |
'variables' => array('plugin' => NULL, 'input' => NULL), |
|
113 |
'variables' => array( |
|
114 |
'plugin' => NULL, |
|
115 |
'input' => NULL, |
|
116 |
), |
|
96 | 117 |
// Register a pattern so that it can work like all views templates. |
97 | 118 |
'pattern' => 'date_views_pager__', |
98 | 119 |
'template' => 'date-views-pager', |
... | ... | |
100 | 121 |
); |
101 | 122 |
} |
102 | 123 |
|
124 |
/** |
|
125 |
* Implements hook_views_api(). |
|
126 |
*/ |
|
103 | 127 |
function date_views_views_api() { |
104 | 128 |
return array( |
105 | 129 |
'api' => 3, |
... | ... | |
119 | 143 |
} |
120 | 144 |
|
121 | 145 |
/** |
122 |
* Identify all potential date/timestamp fields and cache the data.
|
|
146 |
* Identify all potential date/timestamp fields and cache the data. |
|
123 | 147 |
*/ |
124 | 148 |
function date_views_fields($base = 'node', $reset = FALSE) { |
125 | 149 |
static $fields = array(); |
... | ... | |
141 | 165 |
|
142 | 166 |
/** |
143 | 167 |
* Implements hook_date_views_entities(). |
144 |
* Map extra Views tables to the entity that holds its date fields,
|
|
145 |
* needed for Views tables other than the primary tables identified in entity_info(). |
|
168 |
* |
|
169 |
* Map extra Views tables to the entity that holds its date fields, needed for Views tables other than the primary tables identified in entity_info().
|
|
146 | 170 |
*/ |
147 | 171 |
function date_views_date_views_extra_tables() { |
148 | 172 |
return array( |
... | ... | |
151 | 175 |
} |
152 | 176 |
|
153 | 177 |
/** |
154 |
* Helper function to map entity types to the Views base table they use, |
|
155 |
* to make it easier to infer the entity type from a base table. |
|
178 |
* Helper function to map entity types to the Views base table they use, to make it easier to infer the entity type from a base table. |
|
179 |
* |
|
180 |
* Views has a new handler called views_handler_field_entity() that loads entities. |
|
156 | 181 |
* |
157 |
* Views has a new handler called views_handler_field_entity() that loads |
|
158 |
* entities, and you can use something like the following to get the |
|
159 |
* entity type from a view, but not all our base tables contain the |
|
160 |
* entity information we need, (i.e. revisions) so it won't work here |
|
161 |
* and we resort to creating information from entity_get_info(). |
|
182 |
* And you can use something like the following to get the entity type from a view, but not all our base tables contain the entity information we need, (i.e. revisions). |
|
183 |
* |
|
184 |
* So it won't work here and we resort to creating information from entity_get_info(). |
|
162 | 185 |
* |
163 | 186 |
* // A method to get the entity type for a base table. |
164 | 187 |
* $table_data = views_fetch_data($base_table); |
... | ... | |
193 | 216 |
/** |
194 | 217 |
* Implements hook_date_views_fields(). |
195 | 218 |
* |
196 |
* All modules that create custom fields that use the |
|
197 |
* 'views_handler_field_date' handler can provide |
|
198 |
* additional information here about the type of |
|
199 |
* date they create so the date can be used by |
|
200 |
* the Date API views date argument and date filter. |
|
219 |
* All modules that create custom fields that use the 'views_handler_field_date' handler can provide additional information here about the type of date they create so the date can be used by the Date API views date argument and date filter. |
|
201 | 220 |
*/ |
202 | 221 |
function date_views_date_views_fields($field) { |
203 | 222 |
$values = array( |
... | ... | |
263 | 282 |
case 'year': |
264 | 283 |
$args[$pos] = date_pad($view->date_info->year, 4); |
265 | 284 |
break; |
285 |
|
|
266 | 286 |
case 'week': |
267 | 287 |
$args[$pos] = date_pad($view->date_info->year, 4) . '-W' . date_pad($view->date_info->week); |
268 | 288 |
break; |
289 |
|
|
269 | 290 |
case 'day': |
270 | 291 |
$args[$pos] = date_pad($view->date_info->year, 4) . '-' . date_pad($view->date_info->month) . '-' . date_pad($view->date_info->day); |
271 | 292 |
break; |
293 |
|
|
272 | 294 |
default: |
273 | 295 |
$args[$pos] = date_pad($view->date_info->year, 4) . '-' . date_pad($view->date_info->month); |
274 | 296 |
break; |
... | ... | |
298 | 320 |
// if they use exposed filters. |
299 | 321 |
return url($view->get_url($args), array( |
300 | 322 |
'query' => date_views_querystring($view), |
301 |
'absolute' => $absolute)); |
|
323 |
'absolute' => $absolute, |
|
324 |
) |
|
325 |
); |
|
302 | 326 |
} |
303 | 327 |
|
328 |
/** |
|
329 |
* Identifier of a date block. |
|
330 |
*/ |
|
304 | 331 |
function date_block_identifier($view) { |
305 | 332 |
if (!empty($view->block_identifier)) { |
306 | 333 |
return $view->block_identifier; |
... | ... | |
311 | 338 |
/** |
312 | 339 |
* Implements hook_field_views_data_alter(). |
313 | 340 |
* |
314 |
* Create a Views field for each date column we care about |
|
315 |
* to supplement the generic 'entity_id' and 'revision_id' |
|
316 |
* fields that are automatically created. |
|
341 |
* Create a Views field for each date column we care about to supplement the generic 'entity_id' and 'revision_id' fields that are automatically created. |
|
317 | 342 |
* |
318 |
* Also use friendlier labels to distinguish the start date |
|
319 |
* and end date in listings (for fields that use both). |
|
343 |
* Also use friendlier labels to distinguish the start date and end date in listings (for fields that use both). |
|
320 | 344 |
*/ |
321 | 345 |
function date_views_field_views_data_alter(&$result, $field, $module) { |
322 | 346 |
if ($module == 'date') { |
... | ... | |
336 | 360 |
$result[$table][$column]['field']['is date'] = TRUE; |
337 | 361 |
// Not sure yet if we still need a custom field handler in D7 now that custom formatters are available. |
338 | 362 |
// Might still need it to handle grouping of multiple value dates. |
339 |
//$result[$table][$column]['field']['handler'] = 'date_handler_field_date'; |
|
340 |
//$result[$table][$column]['field']['add fields to query'] = TRUE; |
|
363 |
// $result[$table][$column]['field']['handler'] = 'date_handler_field_date';
|
|
364 |
// $result[$table][$column]['field']['add fields to query'] = TRUE;
|
|
341 | 365 |
} |
342 | 366 |
|
343 | 367 |
// For filters, arguments, and sorts, determine if this column is for |
... | ... | |
395 | 419 |
// translatable string. This is a hack to get it to appear right |
396 | 420 |
// before 'end date' in the listing (i.e., in a non-alphabetical, |
397 | 421 |
// but more user friendly, order). |
398 |
$result[$table][$column]['title'] = t('@label - start date (!name)', array('@label' => $label, '!name' => $field['field_name'])); |
|
399 |
$result[$table][$column]['title short'] = t('@label - start date', array('@label' => $label)); |
|
422 |
$result[$table][$column]['title'] = t('@label - start date (!name)', array( |
|
423 |
'@label' => $label, |
|
424 |
'!name' => $field['field_name'], |
|
425 |
)); |
|
426 |
$result[$table][$column]['title short'] = t('@label - start date', array( |
|
427 |
'@label' => $label, |
|
428 |
)); |
|
400 | 429 |
break; |
430 |
|
|
401 | 431 |
case 'value2': |
402 |
$result[$table][$column]['title'] = t('@label - end date (!name:!column)', array('@label' => $label, '!name' => $field['field_name'], '!column' => $this_column)); |
|
403 |
$result[$table][$column]['title short'] = t('@label - end date:!column', array('@label' => $label, '!column' => $this_column)); |
|
432 |
$result[$table][$column]['title'] = t('@label - end date (!name:!column)', array( |
|
433 |
'@label' => $label, |
|
434 |
'!name' => $field['field_name'], |
|
435 |
'!column' => $this_column, |
|
436 |
)); |
|
437 |
$result[$table][$column]['title short'] = t('@label - end date:!column', array( |
|
438 |
'@label' => $label, |
|
439 |
'!column' => $this_column, |
|
440 |
)); |
|
404 | 441 |
break; |
405 | 442 |
} |
406 | 443 |
} |
... | ... | |
421 | 458 |
} |
422 | 459 |
|
423 | 460 |
/** |
424 |
* The instanceof function makes this work for any handler that was derived |
|
425 |
* from 'views_handler_filter_date' or 'views_handler_argument_date', |
|
426 |
* which includes core date fields like the node updated field. |
|
461 |
* The instanceof function makes this work for any handler that was derived from 'views_handler_filter_date' or 'views_handler_argument_date', which includes core date fields like the node updated field. |
|
427 | 462 |
* |
428 |
* The test for $handler->min_date tells us that this is an argument that |
|
429 |
* not only is derived from the views date handler but also has been processed |
|
430 |
* by the Date Views filter or argument code. |
|
431 |
*/ |
|
463 |
* The test for $handler->min_date tells us that this is an argument that not only is derived from the views date handler but also has been processed by the Date Views filter or argument code. |
|
464 |
*/ |
|
432 | 465 |
function date_views_handler_is_date($handler, $type = 'argument') { |
433 | 466 |
switch ($type) { |
434 | 467 |
case 'filter': |
435 | 468 |
return $handler instanceof views_handler_filter_date && !empty($handler->min_date); |
469 |
|
|
436 | 470 |
case 'argument': |
437 | 471 |
return $handler instanceof views_handler_argument_date && !empty($handler->min_date); |
438 | 472 |
} |
... | ... | |
441 | 475 |
|
442 | 476 |
/** |
443 | 477 |
* Validation hook for exposed filters that use the select widget. |
444 |
* This is to ensure the the user completes all parts of the date
|
|
445 |
* not just some parts. Only needed for the select widget. |
|
478 |
* |
|
479 |
* This is to ensure the the user completes all parts of the date not just some parts. Only needed for the select widget.
|
|
446 | 480 |
*/ |
447 | 481 |
function date_views_select_validate(&$form, &$form_state) { |
448 | 482 |
// If there are no values just return. |
... | ... | |
453 | 487 |
$filled = array(); |
454 | 488 |
$value = drupal_array_get_nested_value($form_state['input'], $form['#parents']); |
455 | 489 |
foreach ($granularity as $part) { |
456 |
if (!empty($value['value'][$part])) {
|
|
490 |
if (isset($value['value']) && is_numeric($value['value'][$part])) {
|
|
457 | 491 |
$filled[] = $part; |
458 | 492 |
} |
459 | 493 |
} |
... | ... | |
464 | 498 |
case 'year': |
465 | 499 |
form_error($form['value'][$part], t('Please choose a year.'), $form_state); |
466 | 500 |
break; |
501 |
|
|
467 | 502 |
case 'month': |
468 | 503 |
form_error($form['value'][$part], t('Please choose a month.'), $form_state); |
469 | 504 |
break; |
505 |
|
|
470 | 506 |
case 'day': |
471 | 507 |
form_error($form['value'][$part], t('Please choose a day.'), $form_state); |
472 | 508 |
break; |
509 |
|
|
473 | 510 |
case 'hour': |
474 | 511 |
form_error($form['value'][$part], t('Please choose an hour.'), $form_state); |
475 | 512 |
break; |
513 |
|
|
476 | 514 |
case 'minute': |
477 | 515 |
form_error($form['value'][$part], t('Please choose a minute.'), $form_state); |
478 | 516 |
break; |
517 |
|
|
479 | 518 |
case 'second': |
480 | 519 |
form_error($form['value'][$part], t('Please choose a second.'), $form_state); |
481 | 520 |
break; |
... | ... | |
487 | 526 |
/** |
488 | 527 |
* Implements hook_date_formatter_view_alter(). |
489 | 528 |
* |
490 |
* If we are displaying a date from a view, see if we have information about |
|
491 |
* which multiple value to display. If so, set the date_id in the entity. |
|
529 |
* If we are displaying a date from a view, see if we have information about which multiple value to display. If so, set the date_id in the entity. |
|
492 | 530 |
*/ |
493 | 531 |
function date_views_date_formatter_pre_view_alter(&$entity, &$variables) { |
494 | 532 |
// Some views have no row index. |
... | ... | |
501 | 539 |
$entity->date_id = 'date.' . $date_item->$date_id . '.' . $field['field_name'] . '.' . $date_item->$date_delta . '.0'; |
502 | 540 |
} |
503 | 541 |
} |
504 |
} |
|
542 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules