views_handler_field_stockprop_all.inc 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * @file
  4. * Field handler allowing all properties for a given stock to be displayed in a single cell
  5. *
  6. * @ingroup tripal_stock
  7. * @ingroup views_field_handlers
  8. */
  9. class views_handler_field_stockprop_all extends views_handler_field_prerender_list {
  10. function init(&$view, $options) {
  11. parent::init($view, $options);
  12. }
  13. /**
  14. * Add this term to the query
  15. */
  16. function query() {
  17. $this->add_additional_fields();
  18. }
  19. function pre_render($values) {
  20. $this->aliases['properties'] = 'properties';
  21. $this->aliases['stock_id'] = 'stock_id';
  22. $this->field_alias = $this->aliases['stock_id'];
  23. //for each stock in this view page
  24. foreach ($values as $result) {
  25. if (!empty($result->{$this->aliases['properties']})) {
  26. // all properties for the current stock
  27. $properties = $result->{$this->aliases['properties']};
  28. foreach ($properties as $property) {
  29. // Add property to the list of items to be rendered
  30. $this->items[$property->stock_id][$property->stockprop_id]['stock_id'] = $property->stock_id;
  31. $this->items[$property->stock_id][$property->stockprop_id]['stockprop_id'] = $property->stockprop_id;
  32. $this->items[$property->stock_id][$property->stockprop_id]['type_id'] = $property->type_id;
  33. $this->items[$property->stock_id][$property->stockprop_id]['type_name'] = check_plain($property->type_name);
  34. $this->items[$property->stock_id][$property->stockprop_id]['value'] = check_plain($property->value);
  35. $this->items[$property->stock_id][$property->stockprop_id]['rank'] = $property->rank;
  36. }
  37. }
  38. }
  39. }
  40. function render_item($count, $item) {
  41. return $item['value'] . ' (' . $item['type_name'] . ')';
  42. }
  43. function document_self_tokens(&$tokens) {
  44. $tokens['[' . $this->options['id'] . '-stock_id' . ']'] = t('The Stock ID.');
  45. $tokens['[' . $this->options['id'] . '-stockprop_id' . ']'] = t('The Property ID.');
  46. $tokens['[' . $this->options['id'] . '-type_id' . ']'] = t('The Property Type ID.');
  47. $tokens['[' . $this->options['id'] . '-type_name' . ']'] = t('The Property Type.');
  48. $tokens['[' . $this->options['id'] . '-value' . ']'] = t('The Value of the Property.');
  49. $tokens['[' . $this->options['id'] . '-rank' . ']'] = t('The Rank of the Property.');
  50. }
  51. function add_self_tokens(&$tokens, $item) {
  52. $tokens['[' . $this->options['id'] . '-stock_id' . ']'] = $item['stock_id'];
  53. $tokens['[' . $this->options['id'] . '-stockprop_id' . ']'] = $item['stockprop_id'];
  54. $tokens['[' . $this->options['id'] . '-type_id' . ']'] = $item['type_id'];
  55. $tokens['[' . $this->options['id'] . '-type_name' . ']'] = $item['type_name'];
  56. $tokens['[' . $this->options['id'] . '-value' . ']'] = $item['value'];
  57. $tokens['[' . $this->options['id'] . '-rank' . ']'] = $item['rank'];
  58. }
  59. }