so__transcript_formatter.inc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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::settingsForm()
  10. */
  11. public function settingsForm($view_mode, $form, &$form_state) {
  12. }
  13. /**
  14. *
  15. * @see TripalFieldFormatter::view()
  16. */
  17. public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
  18. // Get the settings
  19. $settings = $display['settings'];
  20. $headers = array('Transcript Name', 'Identifier', 'Type', 'Location');
  21. $rows = array();
  22. foreach ($items as $delta => $item) {
  23. if (!$item['value']) {
  24. continue;
  25. }
  26. $transcript = $item['value'];
  27. // Get the field values
  28. $feature_name = $transcript['schema:name'];
  29. $feature_uname = $transcript['data:0842'];
  30. $loc = $transcript['SO:0000735'];
  31. $type = $transcript['rdfs:type'];
  32. // Add a link i there is an entity.
  33. if (array_key_exists('entity', $item['value']) and $item['value']['entity']) {
  34. list($entity_type, $entity_id) = explode(':', $item['value']['entity']);
  35. $feature_name = l($feature_name, "bio_data/" . $entity_id, array('attributes' => array('target' => "_blank")));
  36. }
  37. $rows[] = array($feature_name, $feature_uname, $type, $loc);
  38. }
  39. $table = array(
  40. 'header' => $headers,
  41. 'rows' => $rows,
  42. 'attributes' => array(
  43. 'id' => 'tripal_feature-table-transcripts-object',
  44. 'class' => 'tripal-data-table'
  45. ),
  46. 'sticky' => FALSE,
  47. 'caption' => "",
  48. 'colgroups' => array(),
  49. 'empty' => 'This feature has no transcripts',
  50. );
  51. $content = theme_table($table);
  52. // once we have our table array structure defined, we call Drupal's theme_table()
  53. // function to generate the table.
  54. if (count($items) > 0) {
  55. $element[0] = array(
  56. '#type' => 'markup',
  57. '#markup' => $content,
  58. );
  59. }
  60. }
  61. }