views_handler_field_stock_dbxref_all.inc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_stock_dbxref_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['dbxref'] = 'dbxref';
  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['dbxref']})) {
  23. // all dbxrefs including the current stock
  24. $dbxrefs = $result->{$this->aliases['dbxref']};
  25. foreach ($dbxrefs as $dbxref) {
  26. // Add dbxref to the list of items to be rendered
  27. $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['stock_id'] = $dbxref->stock_id;
  28. $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['stock_dbxref_id'] = $dbxref->stock_dbxref_id;
  29. $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['dbxref_id'] = $dbxref->dbxref_id;
  30. $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['is_current'] = $dbxref->is_current;
  31. $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['db_id'] = $dbxref->db_id;
  32. $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['db_name'] = $dbxref->db_name;
  33. $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['urlprefix'] = $dbxref->urlprefix;
  34. $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['accession'] = $dbxref->accession;
  35. $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['version'] = $dbxref->version;
  36. $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['description'] = $dbxref->description;
  37. }
  38. }
  39. }
  40. }
  41. function render_item($count, $item) {
  42. if (!empty($item['urlprefix'])) {
  43. return l($item['accession'],$item['urlprefix'].$item['accession']).' ('.$item['db_name'].')';
  44. } else {
  45. return $item['accession'].' ('.$item['db_name'].')';
  46. }
  47. }
  48. function document_self_tokens(&$tokens) {
  49. $tokens['[' . $this->options['id'] . '-stock_id' . ']'] = t('The Stock ID.');
  50. $tokens['[' . $this->options['id'] . '-stock_dbxref_id' . ']'] = t('Stock Database Reference ID');
  51. $tokens['[' . $this->options['id'] . '-dbxref_id' . ']'] = t('Database Reference ID');
  52. $tokens['[' . $this->options['id'] . '-is_current' . ']'] = t('Is Current');
  53. $tokens['[' . $this->options['id'] . '-db_id' . ']'] = t('Database ID');
  54. $tokens['[' . $this->options['id'] . '-db_name' . ']'] = t('Database Name');
  55. $tokens['[' . $this->options['id'] . '-urlprefix' . ']'] = t('URL Prefix');
  56. $tokens['[' . $this->options['id'] . '-accession' . ']'] = t('Accession');
  57. $tokens['[' . $this->options['id'] . '-version' . ']'] = t('Version');
  58. $tokens['[' . $this->options['id'] . '-description' . ']'] = t('Description');
  59. }
  60. function add_self_tokens(&$tokens, $item) {
  61. $tokens['[' . $this->options['id'] . '-stock_id' . ']'] = $item['stock_id'];
  62. $tokens['[' . $this->options['id'] . '-stock_dbxref_id' . ']'] = $item['stock_dbxref_id'];
  63. $tokens['[' . $this->options['id'] . '-dbxref_id' . ']'] = $item['dbxref_id'];
  64. $tokens['[' . $this->options['id'] . '-is_current' . ']'] = $item['is_current'];
  65. $tokens['[' . $this->options['id'] . '-db_id' . ']'] = $item['db_id'];
  66. $tokens['[' . $this->options['id'] . '-db_name' . ']'] = $item['db_name'];
  67. $tokens['[' . $this->options['id'] . '-urlprefix' . ']'] = $item['urlprefix'];
  68. $tokens['[' . $this->options['id'] . '-accession' . ']'] = $item['accession'];
  69. $tokens['[' . $this->options['id'] . '-version' . ']'] = $item['version'];
  70. $tokens['[' . $this->options['id'] . '-description' . ']'] = $item['description'];
  71. }
  72. }