go__gene_expression_formatter.inc

File

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