chado_views_handler_field_date.inc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * @file
  4. * A chado wrapper for the views_handler_field_date.
  5. *
  6. * Handles fields which may be aggregated during the chado join process. This field
  7. * will render an aggregated field as a pre_rendered list and will dynamically detect
  8. * whether the field is aggregated or not.
  9. */
  10. class chado_views_handler_field_date extends views_handler_field_date {
  11. function init(&$view, $options) {
  12. include_once('chado_wrapper_functions.inc');
  13. parent::init($view, $options);
  14. }
  15. /**
  16. * Defines the defaults for the options form
  17. */
  18. function option_definition() {
  19. $options = parent::option_definition();
  20. $options['type'] = array('default' => 'separator');
  21. $options['separator'] = array('default' => ', ');
  22. return $options;
  23. }
  24. /**
  25. * Defines the options form (form available to admin when they add a field to a view)
  26. */
  27. function options_form(&$form, &$form_state) {
  28. parent::options_form($form, $form_state);
  29. $form['type'] = array(
  30. '#type' => 'radios',
  31. '#title' => t('Display type'),
  32. '#options' => array(
  33. 'ul' => t('Unordered list'),
  34. 'ol' => t('Ordered list'),
  35. 'separator' => t('Simple separator'),
  36. ),
  37. '#default_value' => $this->options['type'],
  38. );
  39. $form['separator'] = array(
  40. '#type' => 'textfield',
  41. '#title' => t('Separator'),
  42. '#default_value' => $this->options['separator'],
  43. '#process' => array('views_process_dependency'),
  44. '#dependency' => array('radio:options[type]' => array('separator')),
  45. );
  46. }
  47. /**
  48. * Determines whether the current field is aggregated or not
  49. * Note: The parent::query() takes care of adding the field to the query, etc.
  50. */
  51. function query() {
  52. parent::query();
  53. $this->aggregated = chado_wrapper_is_aggregated_by_join($this);
  54. }
  55. /**
  56. * Splits the aggregated values up for use in rendering
  57. */
  58. function pre_render(&$values) {
  59. // further check the results to see if this field is a postgresql array
  60. $this->aggregated = chado_wrapper_is_aggregated_by_result($this, $values);
  61. // Split Aggregated Results
  62. chado_wrapper_split_array_agg_results($this, $values);
  63. }
  64. /**
  65. * Render the field.
  66. *
  67. * Note: Checks to see if we have an array or simple field. If we have an array, then
  68. * split it up and render each part using the parent render functionality.
  69. *
  70. * @param $values
  71. * The values retrieved from the database.
  72. */
  73. function render($values) {
  74. // Check the format of the date is a UNIX timestamp and otherwise convert
  75. if (!is_array($values->{$this->field_alias})) {
  76. if (!preg_match('/^\d+$/', $values->{$this->field_alias})) {
  77. $values->{$this->field_alias} = strtotime($values->{$this->field_alias});
  78. }
  79. }
  80. else {
  81. if (!preg_match('/^\d+$/', $values->{$this->field_alias}[0])) {
  82. foreach ($values->{$this->field_alias} as $k => $v) {
  83. $values->{$this->field_alias}[$k] = strtotime($v);
  84. }
  85. }
  86. }
  87. // render the items
  88. return chado_wrapper_render_items($this, $values);
  89. }
  90. function parent_render($val) {
  91. return parent::render($val);
  92. }
  93. }