views_handler_field_profile_date.inc

  1. 3.x modules/profile/views_handler_field_profile_date.inc
  2. 2.x modules/profile/views_handler_field_profile_date.inc

Definition of views_handler_field_profile_date.

File

modules/profile/views_handler_field_profile_date.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_field_profile_date.
  5. */
  6. /**
  7. * Field handler display a profile date
  8. *
  9. * The dates are stored serialized, which makes them mostly useless from
  10. * SQL. About all we can do is unserialize and display them.
  11. *
  12. * @ingroup views_field_handlers
  13. */
  14. class views_handler_field_profile_date extends views_handler_field_date {
  15. function options_form(&$form, &$form_state) {
  16. parent::options_form($form, $form_state);
  17. // we can't do "time ago" so remove it from the form.
  18. unset($form['date_format']['#options']['time ago']);
  19. }
  20. /**
  21. * Display a profile field of type 'date'
  22. */
  23. function render($values) {
  24. $value = $this->get_value($values);
  25. if (!$value) {
  26. return;
  27. }
  28. $value = unserialize($value);
  29. $format = $this->options['date_format'];
  30. switch ($format) {
  31. case 'custom':
  32. $format = $this->options['custom_date_format'];
  33. break;
  34. case 'small':
  35. $format = variable_get('date_format_short', 'm/d/Y - H:i');
  36. break;
  37. case 'medium':
  38. $format = variable_get('date_format_medium', 'D, m/d/Y - H:i');
  39. break;
  40. case 'large':
  41. $format = variable_get('date_format_long', 'l, F j, Y - H:i');
  42. break;
  43. }
  44. // Note: Avoid PHP's date() because it does not handle dates before
  45. // 1970 on Windows. This would make the date field useless for e.g.
  46. // birthdays.
  47. // But we *can* deal with non-year stuff:
  48. $date = gmmktime(0, 0, 0, $value['month'], $value['day'], $value['year']);
  49. $replace = array(
  50. // day
  51. 'd' => sprintf('%02d', $value['day']),
  52. 'D' => NULL,
  53. 'l' => NULL,
  54. 'N' => NULL,
  55. 'S' => gmdate('S', $date),
  56. 'w' => NULL,
  57. 'j' => $value['day'],
  58. // month
  59. 'F' => gmdate('F', $date),
  60. 'm' => sprintf('%02d', $value['month']),
  61. 'M' => gmdate('M', $date),
  62. 'n' => gmdate('n', $date),
  63. 'Y' => $value['year'],
  64. 'y' => substr($value['year'], 2, 2),
  65. // kill time stuff
  66. 'a' => NULL,
  67. 'A' => NULL,
  68. 'g' => NULL,
  69. 'G' => NULL,
  70. 'h' => NULL,
  71. 'H' => NULL,
  72. 'i' => NULL,
  73. 's' => NULL,
  74. ':' => NULL,
  75. 'T' => NULL,
  76. ' - ' => NULL,
  77. ':' => NULL,
  78. );
  79. return strtr($format, $replace);
  80. }
  81. }