views_handler_field_stockprop_all.inc 2.7 KB

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