views_handler_field_stock_dbxref_all.inc 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Field handler allowing all database references for a given stock to be displayed in a single cell
  4. *
  5. * This handler only deals with database references joined to the stock through stock_dbxref. For
  6. * the database reference joined to the stock by stock.dbxref_id simply join to the dbxref table.
  7. *
  8. * @ingroup tripal_stock
  9. * @ingroup views_field_handlers
  10. */
  11. class views_handler_field_stock_dbxref_all extends views_handler_field_prerender_list {
  12. function init(&$view, $options) {
  13. parent::init($view, $options);
  14. }
  15. /**
  16. * Add this term to the query
  17. */
  18. function query() {
  19. $this->add_additional_fields();
  20. }
  21. function pre_render($values) {
  22. $this->aliases['dbxref'] = 'dbxref';
  23. $this->aliases['stock_id'] = 'stock_id';
  24. $this->field_alias = $this->aliases['stock_id'];
  25. //for each stock in this view page
  26. foreach ($values as $result) {
  27. if (!empty($result->{$this->aliases['dbxref']})) {
  28. // all dbxrefs including the current stock
  29. $dbxrefs = $result->{$this->aliases['dbxref']};
  30. foreach ($dbxrefs as $dbxref) {
  31. // Add dbxref to the list of items to be rendered
  32. $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['stock_id'] = $dbxref->stock_id;
  33. $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['stock_dbxref_id'] = $dbxref->stock_dbxref_id;
  34. $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['dbxref_id'] = $dbxref->dbxref_id;
  35. $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['is_current'] = $dbxref->is_current;
  36. $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['db_id'] = $dbxref->db_id;
  37. $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['db_name'] = $dbxref->db_name;
  38. $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['urlprefix'] = $dbxref->urlprefix;
  39. $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['accession'] = $dbxref->accession;
  40. $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['version'] = $dbxref->version;
  41. $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['description'] = $dbxref->description;
  42. }
  43. }
  44. }
  45. }
  46. function render_item($count, $item) {
  47. if (!empty($item['urlprefix'])) {
  48. return l($item['accession'],$item['urlprefix'].$item['accession']).' ('.$item['db_name'].')';
  49. } else {
  50. return $item['accession'].' ('.$item['db_name'].')';
  51. }
  52. }
  53. function document_self_tokens(&$tokens) {
  54. $tokens['[' . $this->options['id'] . '-stock_id' . ']'] = t('The Stock ID.');
  55. $tokens['[' . $this->options['id'] . '-stock_dbxref_id' . ']'] = t('Stock Database Reference ID');
  56. $tokens['[' . $this->options['id'] . '-dbxref_id' . ']'] = t('Database Reference ID');
  57. $tokens['[' . $this->options['id'] . '-is_current' . ']'] = t('Is Current');
  58. $tokens['[' . $this->options['id'] . '-db_id' . ']'] = t('Database ID');
  59. $tokens['[' . $this->options['id'] . '-db_name' . ']'] = t('Database Name');
  60. $tokens['[' . $this->options['id'] . '-urlprefix' . ']'] = t('URL Prefix');
  61. $tokens['[' . $this->options['id'] . '-accession' . ']'] = t('Accession');
  62. $tokens['[' . $this->options['id'] . '-version' . ']'] = t('Version');
  63. $tokens['[' . $this->options['id'] . '-description' . ']'] = t('Description');
  64. }
  65. function add_self_tokens(&$tokens, $item) {
  66. $tokens['[' . $this->options['id'] . '-stock_id' . ']'] = $item['stock_id'];
  67. $tokens['[' . $this->options['id'] . '-stock_dbxref_id' . ']'] = $item['stock_dbxref_id'];
  68. $tokens['[' . $this->options['id'] . '-dbxref_id' . ']'] = $item['dbxref_id'];
  69. $tokens['[' . $this->options['id'] . '-is_current' . ']'] = $item['is_current'];
  70. $tokens['[' . $this->options['id'] . '-db_id' . ']'] = $item['db_id'];
  71. $tokens['[' . $this->options['id'] . '-db_name' . ']'] = $item['db_name'];
  72. $tokens['[' . $this->options['id'] . '-urlprefix' . ']'] = $item['urlprefix'];
  73. $tokens['[' . $this->options['id'] . '-accession' . ']'] = $item['accession'];
  74. $tokens['[' . $this->options['id'] . '-version' . ']'] = $item['version'];
  75. $tokens['[' . $this->options['id'] . '-description' . ']'] = $item['description'];
  76. }
  77. }