sio__annotation_formatter.inc

File

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