views_handler_field_chado_tf_boolean.inc 1.1 KB

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