chado_linker__featurepos.inc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. class chado_linker__featurepos extends TripalField {
  3. // The default lable for this field.
  4. public static $default_label = 'Map positions';
  5. // The default description for this field.
  6. public static $default_description = 'Map position of a sequence.';
  7. // Add any default settings elements. If you override the globalSettingsForm()
  8. // or the instanceSettingsForm() functions then you need to be sure that
  9. // any settings you want those functions to manage are listed in this
  10. // array.
  11. public static $default_settings = array(
  12. 'chado_table' => '',
  13. 'chado_column' => '',
  14. 'base_table' => '',
  15. );
  16. // Set this to the name of the storage backend that by default will support
  17. // this field.
  18. public static $default_storage = 'field_chado_storage';
  19. /**
  20. * @see TripalField::formatter_settings_summary()
  21. */
  22. public function formatter_settings_summary($field, $instance,
  23. $view_mode) {
  24. }
  25. /**
  26. * @see TripalField::formatter_settings_form()
  27. */
  28. public function formatter_settings_form($field, $instance,
  29. $view_mode, $form, &$form_state) {
  30. }
  31. /**
  32. * @see TripalField::formatterView()
  33. */
  34. public function formatterView(&$element, $entity_type, $entity, $langcode, $items, $display) {
  35. // Get the settings
  36. $settings = $display['settings'];
  37. $rows = array();
  38. $headers = array('Map', 'Mapped Feature', 'Position');
  39. foreach ($items as $delta => $item) {
  40. if (!$item['value']) {
  41. continue;
  42. }
  43. $val = $item['value'];
  44. $map_name = $val['map_name'];
  45. $mapped_feature_name = $val['mapped_feature_name'];
  46. $position = $val['position'];
  47. $rows[] = array(
  48. $map_name,
  49. $mapped_feature_name,
  50. $position
  51. );
  52. }
  53. // the $table array contains the headers and rows array as well as other
  54. // options for controlling the display of the table. Additional
  55. // documentation can be found here:
  56. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  57. $table = array(
  58. 'header' => $headers,
  59. 'rows' => $rows,
  60. 'attributes' => array(
  61. 'id' => 'tripal_feature-table-map-positions',
  62. 'class' => 'tripal-data-table'
  63. ),
  64. 'sticky' => FALSE,
  65. 'caption' => '',
  66. 'colgroups' => array(),
  67. 'empty' => 'This record is not found on any map.',
  68. );
  69. // once we have our table array structure defined, we call Drupal's theme_table()
  70. // function to generate the table.
  71. if (count($items) > 0) {
  72. $element[0] = array(
  73. '#type' => 'markup',
  74. '#markup' => theme_table($table),
  75. );
  76. }
  77. }
  78. /**
  79. * @see TripalField::load()
  80. */
  81. public function load($entity, $details = array()) {
  82. $record = $details['record'];
  83. $settings = $this->field['settings'];
  84. $field_name = $this->field['field_name'];
  85. $field_type = $this->field['type'];
  86. // Set some defaults for the empty record.
  87. $entity->{$field_name}['und'][0] = array(
  88. 'value' => array(),
  89. );
  90. $options = array(
  91. 'return_array' => TRUE,
  92. 'include_fk' => array(
  93. 'srcfeature_id' => array(
  94. 'type_id' => 1,
  95. ),
  96. 'feature_id' => array(
  97. 'type_id' => 1
  98. ),
  99. )
  100. );
  101. $feature = chado_expand_var($record, 'table', 'featurepos', $options);
  102. // iterate through the results and add them to our featureposes array
  103. $featureposes = array();
  104. if (isset($feature->featurepos->feature_id)) {
  105. foreach ($feature->featurepos->feature_id AS $featurepos) {
  106. $featuremap_id = $featurepos->featuremap_id;
  107. $featuremap = chado_generate_var('featuremap', array('featuremap_id' => $featuremap_id));
  108. $map_feature_id = $featurepos->map_feature_id;
  109. $map_feature = chado_generate_var('feature', array('feature_id' => $map_feature_id));
  110. $mappos = $featurepos->mappos;
  111. $featureposes [] = array (
  112. 'map_name' => $featuremap->name,
  113. 'mapped_feature_name' => $map_feature->name,
  114. 'position' => $mappos
  115. );
  116. }
  117. }
  118. $i = 0;
  119. foreach ($featureposes as $position) {
  120. $entity->{$field_name}['und'][$i]['value'] = $position;
  121. $i++;
  122. }
  123. }
  124. /**
  125. * We don't want a widget so override this function.
  126. */
  127. public static function widgetInfo() {
  128. return array();
  129. }
  130. }