views_handler_field_stockprop_all.inc 2.7 KB

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