chado_linker__featurepos.inc 4.3 KB

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