so__transcript_formatter.inc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. class so__transcript_formatter extends ChadoFieldFormatter {
  3. // The default lable for this field.
  4. public static $default_label = 'Transcript';
  5. // The list of field types for which this formatter is appropriate.
  6. public static $field_types = array('so__transcript');
  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. $headers = array('Transcript Name', 'Identifier', 'Type', 'Location');
  15. $rows = array();
  16. foreach ($items as $delta => $item) {
  17. if (!$item['value']) {
  18. continue;
  19. }
  20. $transcript = $item['value'];
  21. // Get the field values
  22. $feature_name = $transcript['schema:name'];
  23. $feature_uname = $transcript['data:0842'];
  24. $loc = $transcript['SO:0000735'];
  25. $type = $transcript['rdfs:type'];
  26. // Add a link i there is an entity.
  27. if (array_key_exists('entity', $item['value']) and $item['value']['entity']) {
  28. list($entity_type, $entity_id) = explode(':', $item['value']['entity']);
  29. $feature_name = l($feature_name, "bio_data/" . $entity_id, array('attributes' => array('target' => "_blank")));
  30. }
  31. $rows[] = array($feature_name, $feature_uname, $type, $loc);
  32. }
  33. $table = array(
  34. 'header' => $headers,
  35. 'rows' => $rows,
  36. 'attributes' => array(
  37. 'id' => 'tripal_feature-table-transcripts-object',
  38. 'class' => 'tripal-data-table'
  39. ),
  40. 'sticky' => FALSE,
  41. 'caption' => "",
  42. 'colgroups' => array(),
  43. 'empty' => 'This feature has no transcripts',
  44. );
  45. $content = theme_table($table);
  46. // once we have our table array structure defined, we call Drupal's theme_table()
  47. // function to generate the table.
  48. if (count($items) > 0) {
  49. $element[0] = array(
  50. '#type' => 'markup',
  51. '#markup' => $content,
  52. );
  53. }
  54. }
  55. }