sio__annotation_formatter.inc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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::view()
  10. */
  11. public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
  12. $headers = array('Term', 'Name', 'Definition');
  13. $rows = array();
  14. $field_table = $this->instance['settings']['chado_table'];
  15. $schema = chado_get_schema($field_table);
  16. $vocabulary_term = tripal_get_chado_semweb_term('cvterm', 'cv_id');
  17. $accession_term = tripal_get_chado_semweb_term('dbxref', 'accession');
  18. $definition_term = tripal_get_chado_semweb_term('cvterm', 'definition');
  19. $name_term = tripal_get_chado_semweb_term('cvterm', 'name');
  20. if (array_key_exists('is_not', $schema['fields'])) {
  21. $negation_term = chado_get_semweb_term($field_table, 'is_not');
  22. }
  23. $chado_table = $this->instance['settings']['chado_table'];
  24. foreach ($items as $delta => $item) {
  25. if (!empty($item['chado-' . $chado_table . '__cvterm_id'])) {
  26. $cvterm = chado_generate_var('cvterm', array('cvterm_id' => $item['chado-' . $chado_table . '__cvterm_id']));
  27. $dbxref = $cvterm->dbxref_id;
  28. // Build the accession.
  29. $accession = $dbxref->db_id->name . ':' . $dbxref->accession;
  30. if ($dbxref->db_id->urlprefix) {
  31. $accession = l($accession, chado_get_dbxref_url($dbxref), array('attributes' => array('target' => '_blank')));
  32. }
  33. $row = array(
  34. $accession,
  35. $item['value'][$name_term],
  36. $item['value'][$definition_term],
  37. );
  38. if (array_key_exists('is_not', $schema['fields'])) {
  39. if ($negation_term == FALSE) {
  40. $row[1] = 'NOT ' . $row[1];
  41. }
  42. }
  43. $rows[] = $row;
  44. }
  45. }
  46. // Theme the results in a talbe.
  47. $caption = 'This record has the following annotations.';
  48. $table = array(
  49. 'header' => $headers,
  50. 'rows' => $rows,
  51. 'attributes' => array(
  52. 'id' => "$chado_table-table-terms",
  53. 'class' => 'tripal-data-table'
  54. ),
  55. 'caption' => $caption,
  56. 'sticky' => FALSE,
  57. 'colgroups' => array(),
  58. 'empty' => 'There are no annotations of this type',
  59. );
  60. if (count($items) > 0) {
  61. $element[0] = array(
  62. '#type' => 'markup',
  63. '#markup' => theme_table($table),
  64. );
  65. }
  66. }
  67. }