date.diff.inc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * @file
  4. * Provide diff field functions for the Date module.
  5. */
  6. /**
  7. * Diff field callback for parsing date fields comparative values.
  8. */
  9. function date_field_diff_view($items, $context) {
  10. $diff_items = array();
  11. $display = $context['display'];
  12. $display['settings']['format_type'] = $context['settings']['format_type'];
  13. $display['settings']['fromto'] = $context['settings']['fromto'];
  14. foreach ($items as $delta => $item) {
  15. $date = date_formatter_process('date_default', $context['entity_type'], $context['entity'], $context['field'], $context['instance'], $context['language'], $item, $display);
  16. switch ($display['settings']['fromto']) {
  17. case 'both':
  18. if ($date['value']['formatted'] != $date['value2']['formatted']) {
  19. $diff_items[$delta] = t('@from to @to', array(
  20. '@from' => $date['value']['formatted'],
  21. '@to' => $date['value2']['formatted'],
  22. ));
  23. }
  24. else {
  25. $diff_items[$delta] = $date['value']['formatted'];
  26. }
  27. break;
  28. case 'value':
  29. case 'value2':
  30. $diff_items[$delta] = $date[$display['settings']['fromto']]['formatted'];
  31. break;
  32. }
  33. }
  34. return $diff_items;
  35. }
  36. /**
  37. * Provide default field comparison options.
  38. */
  39. function date_field_diff_default_options($field_type) {
  40. return array(
  41. 'format_type' => 'long',
  42. 'fromto' => 'both',
  43. );
  44. }
  45. /**
  46. * Provide a form for setting the field comparison options.
  47. */
  48. function date_field_diff_options_form($field_type, $settings) {
  49. $options_form = array();
  50. $form['format_type'] = array(
  51. '#title' => t('Choose how render dates and times'),
  52. '#type' => 'select',
  53. '#options' => date_format_type_options(),
  54. '#default_value' => $settings['format_type'],
  55. '#description' => t('To add or edit options, visit <a href="@date-time-page">Date and time settings</a>.', array('@date-time-page' => url('admin/config/regional/date-time'))),
  56. '#weight' => 0,
  57. );
  58. $form['fromto'] = array(
  59. '#title' => t('Display'),
  60. '#type' => 'select',
  61. '#options' => array(
  62. 'both' => t('Both Start and End dates'),
  63. 'value' => t('Start date only'),
  64. 'value2' => t('End date only'),
  65. ),
  66. '#default_value' => $settings['fromto'],
  67. '#weight' => 1,
  68. );
  69. return $options_form;
  70. }