chado_linker__cvterm_formatter.inc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. class chado_linker__cvterm_formatter extends TripalFieldFormatter {
  3. // The default lable for this field.
  4. public static $label = 'Annotations';
  5. // The list of field types for which this formatter is appropriate.
  6. public static $field_types = array('chado_linker__cvterm');
  7. // The list of default settings for this formatter.
  8. public static $settings = array();
  9. /**
  10. *
  11. * @see TripalFieldFormatter::settingsForm()
  12. */
  13. public function settingsForm($view_mode, $form, &$form_state) {
  14. $headers = array('Term', 'Definition', 'Is Not', 'Reference');
  15. $rows = array();
  16. $chado_table = $this->field['settings']['chado_table'];
  17. foreach ($items as $delta => $item) {
  18. if ($item['chado-' . $chado_table . '__cvterm_id']) {
  19. $cvterm = chado_generate_var('cvterm', array('cvterm_id' => $item['chado-' . $chado_table . '__cvterm_id']));
  20. $dbxref = $cvterm->dbxref_id;
  21. // Build the accession.
  22. $accession = $dbxref->db_id->name . ':' . $dbxref->accession;
  23. if ($dbxref->db_id->urlprefix) {
  24. $accession = l($accession, tripal_get_dbxref_url($dbxref), array('attributes' => array('target' => '_blank')));
  25. }
  26. // Build the publication reference.
  27. $pub_ref = '';
  28. $pub_id = $item['chado-' . $chado_table . '__pub_id'];
  29. if ($pub_id) {
  30. $pub = chado_generate_var('pub', array('pub_id' => $pub_id));
  31. $pub_ref = $pub->title;
  32. }
  33. $rows[] = array(
  34. $accession,
  35. $cvterm->definition,
  36. $item['chado-' . $chado_table . '__is_not'] ? 'Yes' : '',
  37. '',
  38. );
  39. }
  40. }
  41. // the $table array contains the headers and rows array as well as other
  42. // options for controlling the display of the table. Additional
  43. // documentation can be found here:
  44. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  45. $table = array(
  46. 'header' => $headers,
  47. 'rows' => $rows,
  48. 'attributes' => array(
  49. 'id' => "$chado_table-table-terms",
  50. 'class' => 'tripal-data-table'
  51. ),
  52. 'caption' => '',
  53. 'sticky' => FALSE,
  54. 'colgroups' => array(),
  55. 'empty' => 'There are no annotations of this type',
  56. );
  57. if (count($items) > 0) {
  58. $element[0] = array(
  59. '#type' => 'markup',
  60. '#markup' => theme_table($table),
  61. );
  62. }
  63. }
  64. /**
  65. *
  66. * @see TripalFieldFormatter::view()
  67. */
  68. public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
  69. }
  70. }