go__gene_expression_formatter.inc 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. class go__gene_expression_formatter extends TripalFieldFormatter {
  3. // The default lable for this field.
  4. public static $label = 'Gene expression';
  5. // The list of field types for which this formatter is appropriate.
  6. public static $field_types = array('go__gene_expression');
  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. }
  15. /**
  16. *
  17. * @see TripalFieldFormatter::view()
  18. */
  19. public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
  20. // Get the settings
  21. $settings = $display['settings'];
  22. $content = '';
  23. $rows = array();
  24. foreach ($items as $delta => $item) {
  25. if (!$item['value']) {
  26. continue;
  27. }
  28. // Iterate through all of the children of the $item['value']. Add each
  29. // one as an independent row in the table.
  30. foreach ($item['value'] as $key => $value) {
  31. // If this key is the name, then we want to link to the entity if one
  32. // exists.
  33. if ($key == 'name') {
  34. if (array_key_exists('entity', $item['value']) and $item['value']['$entity_id']) {
  35. list($entity_type, $entity_id) = explode(':', $item['value']['entity']);
  36. $value = l($value, "bio_data/" . $entity_id, array('attributes' => array('target' => "_blank")));
  37. }
  38. }
  39. // If this key is the publication then we want to get the citation
  40. // and link to the pub if an entity exits.
  41. if ($key == 'publication') {
  42. $pub = $value['Citation'];
  43. if (array_key_exists('publication', $item) and array_key_exists('entity', $item['publication'][0])) {
  44. $entity_id = $item['publication'][0]['entity_id'];
  45. $title = $item['value']['publication']['Title'];
  46. $link = l($title, 'bio_data/' . $entity_id);
  47. $pub = preg_replace("/$title/", $link, $pub);
  48. }
  49. $value = $pub;
  50. }
  51. // Add the item as a new row.
  52. $rows[] = array(
  53. array(
  54. 'data' => ucfirst(str_replace('_', ' ', $key)),
  55. 'header' => TRUE,
  56. 'width' => '20%',
  57. ),
  58. $value
  59. );
  60. }
  61. }
  62. $table = array(
  63. 'header' => array(),
  64. 'rows' => $rows,
  65. 'attributes' => array(
  66. 'id' => 'tripal_linker-table-expression-object',
  67. 'class' => 'tripal-data-table'
  68. ),
  69. 'sticky' => FALSE,
  70. 'caption' => "",
  71. 'colgroups' => array(),
  72. 'empty' => 'There is no curated expression data.',
  73. );
  74. $content = theme_table($table);
  75. if (count($items) > 0) {
  76. // once we have our table array structure defined, we call Drupal's theme_table()
  77. // function to generate the table.
  78. $element[0] = array(
  79. '#type' => 'markup',
  80. '#markup' => $content,
  81. );
  82. }
  83. }
  84. }