sio__annotation_formatter.inc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. class sio__annotation_formatter extends ChadoFieldFormatter {
  3. // The default lable for this field.
  4. public static $default_label = 'Chado Annotation';
  5. // The list of field types for which this formatter is appropriate.
  6. public static $field_types = array('chado_linker__cvterm');
  7. /**
  8. *
  9. * @see TripalFieldFormatter::settingsForm()
  10. */
  11. public function settingsForm($view_mode, $form, &$form_state) {
  12. $headers = array('Term', 'Definition', 'Is Not', 'Reference');
  13. $rows = array();
  14. $chado_table = $this->instance['settings']['chado_table'];
  15. foreach ($items as $delta => $item) {
  16. if ($item['chado-' . $chado_table . '__cvterm_id']) {
  17. $cvterm = chado_generate_var('cvterm', array('cvterm_id' => $item['chado-' . $chado_table . '__cvterm_id']));
  18. $dbxref = $cvterm->dbxref_id;
  19. // Build the accession.
  20. $accession = $dbxref->db_id->name . ':' . $dbxref->accession;
  21. if ($dbxref->db_id->urlprefix) {
  22. $accession = l($accession, tripal_get_dbxref_url($dbxref), array('attributes' => array('target' => '_blank')));
  23. }
  24. // Build the publication reference.
  25. $pub_ref = '';
  26. $pub_id = $item['chado-' . $chado_table . '__pub_id'];
  27. if ($pub_id) {
  28. $pub = chado_generate_var('pub', array('pub_id' => $pub_id));
  29. $pub_ref = $pub->title;
  30. }
  31. $rows[] = array(
  32. $accession,
  33. $cvterm->definition,
  34. $item['chado-' . $chado_table . '__is_not'] ? 'Yes' : '',
  35. '',
  36. );
  37. }
  38. }
  39. // the $table array contains the headers and rows array as well as other
  40. // options for controlling the display of the table. Additional
  41. // documentation can be found here:
  42. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  43. $table = array(
  44. 'header' => $headers,
  45. 'rows' => $rows,
  46. 'attributes' => array(
  47. 'id' => "$chado_table-table-terms",
  48. 'class' => 'tripal-data-table'
  49. ),
  50. 'caption' => '',
  51. 'sticky' => FALSE,
  52. 'colgroups' => array(),
  53. 'empty' => 'There are no annotations of this type',
  54. );
  55. if (count($items) > 0) {
  56. $element[0] = array(
  57. '#type' => 'markup',
  58. '#markup' => theme_table($table),
  59. );
  60. }
  61. }
  62. /**
  63. *
  64. * @see TripalFieldFormatter::view()
  65. */
  66. public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
  67. $headers = array('Term', 'Definition', 'Is Not');
  68. $rows = array();
  69. dpm($items);
  70. $chado_table = $this->instance['settings']['chado_table'];
  71. foreach ($items as $delta => $item) {
  72. if ($item['chado-' . $chado_table . '__cvterm_id']) {
  73. $cvterm = chado_generate_var('cvterm', array('cvterm_id' => $item['chado-' . $chado_table . '__cvterm_id']));
  74. $dbxref = $cvterm->dbxref_id;
  75. // Build the accession.
  76. $accession = $dbxref->db_id->name . ':' . $dbxref->accession;
  77. if ($dbxref->db_id->urlprefix) {
  78. $accession = l($accession, tripal_get_dbxref_url($dbxref), array('attributes' => array('target' => '_blank')));
  79. }
  80. $rows[] = array(
  81. $accession,
  82. $cvterm->definition,
  83. $item['chado-' . $chado_table . '__is_not'] ? 'Yes' : '',
  84. );
  85. }
  86. }
  87. // the $table array contains the headers and rows array as well as other
  88. // options for controlling the display of the table. Additional
  89. // documentation can be found here:
  90. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  91. $table = array(
  92. 'header' => $headers,
  93. 'rows' => $rows,
  94. 'attributes' => array(
  95. 'id' => "$chado_table-table-terms",
  96. 'class' => 'tripal-data-table'
  97. ),
  98. 'caption' => 'This record is associated with the following annotations:',
  99. 'sticky' => FALSE,
  100. 'colgroups' => array(),
  101. 'empty' => 'There are no annotations of this type',
  102. );
  103. if (count($items) > 0) {
  104. $element[0] = array(
  105. '#type' => 'markup',
  106. '#markup' => theme_table($table),
  107. );
  108. }
  109. }
  110. }