views_handler_field_stock_dbxref_all.inc 4.2 KB

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