views_handler_field_chado_tf_boolean.inc 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * @file
  4. * A handler to provide proper displays for booleans.
  5. *
  6. * Allows for display of true/false, yes/no, on/off.
  7. *
  8. * Definition terms:
  9. * - output formats: An array where the first entry is displayed on boolean false
  10. * and the second is displayed on boolean true. An example for sticky is:
  11. * @code
  12. * 'output formats' => array(
  13. * 'sticky' => array('', t('Sticky')),
  14. * ),
  15. * @endcode
  16. *
  17. * @ingroup views_field_handlers
  18. * @ingroup tripal_core
  19. */
  20. class views_handler_field_chado_tf_boolean extends views_handler_field_boolean {
  21. // Changes the rendered value: t='Yes' & f='No'
  22. // Rendered value depends on type of value chosen in options
  23. function render($values) {
  24. $value = $values->{$this->field_alias};
  25. if (!empty($this->options['not'])) {
  26. $value = !$value;
  27. }
  28. if (isset($this->formats[$this->options['type']])) {
  29. return preg_match('/t/', $value) ? $this->formats[$this->options['type']][0] : $this->formats[$this->options['type']][1];
  30. }
  31. else {
  32. return preg_match('/t/', $value) ? $this->formats['yes-no'][0] : $this->formats['yes-no'][1];
  33. }
  34. }
  35. }