tripal_feature.admin.inc 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /**
  3. * @file
  4. * Administration of features
  5. */
  6. /**
  7. * Launchpad for feature administration.
  8. *
  9. * @ingroup tripal_legacy_feature
  10. */
  11. function tripal_feature_admin_feature_view() {
  12. $output = '';
  13. // set the breadcrumb
  14. $breadcrumb = [];
  15. $breadcrumb[] = l('Home', '<front>');
  16. $breadcrumb[] = l('Administration', 'admin');
  17. $breadcrumb[] = l('Tripal', 'admin/tripal');
  18. $breadcrumb[] = l('Chado', 'admin/tripal/legacy');
  19. $breadcrumb[] = l('Features', 'admin/tripal/legacy/tripal_feature');
  20. drupal_set_breadcrumb($breadcrumb);
  21. // Add the view
  22. $view = views_embed_view('tripal_feature_admin_features', 'default');
  23. if (isset($view)) {
  24. $output .= $view;
  25. }
  26. else {
  27. $output .= '<p>The Feature module uses primarily views to provide an '
  28. . 'administrative interface. Currently one or more views needed for this '
  29. . 'administrative interface are disabled. <strong>Click each of the following links to '
  30. . 'enable the pertinent views</strong>:</p>';
  31. $output .= '<ul>';
  32. $output .= '<li>' . l('Features View', 'admin/tripal/legacy/tripal_feature/views/features/enable') . '</li>';
  33. $output .= '</ul>';
  34. }
  35. // Add a summary chart.
  36. //-----------------------------------
  37. $output .= theme('tripal_feature_bar_chart_type_organism_summary');
  38. drupal_add_js('
  39. Drupal.behaviors.tripalFeature_moveAdminSummaryChart = {
  40. attach: function (context, settings) {
  41. jQuery("#tripal-feature-admin-summary").insertBefore( jQuery(".view-filters") );
  42. }};
  43. ', 'inline');
  44. return $output;
  45. }
  46. /**
  47. * Feature Settings page
  48. *
  49. * @ingroup tripal_legacy_feature
  50. */
  51. function tripal_feature_admin() {
  52. // FEATURE PAGE TITLES
  53. // Using the Chado Node: Title & Path API
  54. $details = [
  55. 'module' => 'tripal_feature',
  56. 'content_type' => 'chado_feature',
  57. // An array of options to use under "Page Titles"
  58. // the key should be the token and the value should be the human-readable option
  59. 'options' => [
  60. '[feature.name]' => 'Feature Name Only',
  61. '[feature.uniquename]' => 'Feature Unique Name Only',
  62. // there should always be one options matching the unique constraint.
  63. '[feature.name], [feature.uniquename] ([feature.type_id>cvterm.name]) [feature.organism_id>organism.genus] [feature.organism_id>organism.species]' => 'Unique Contraint: Includes the name, uniquename, type and scientific name',
  64. ],
  65. // the token indicating the unique constraint in the options array
  66. 'unique_option' => '[feature.name], [feature.uniquename] ([feature.type_id>cvterm.name]) [feature.organism_id>organism.genus] [feature.organism_id>organism.species]',
  67. ];
  68. // This call adds the configuration form to your current form
  69. // This sub-form handles it's own validation & submit
  70. chado_add_admin_form_set_title($form, $form_state, $details);
  71. // FEATURE NODE URL
  72. // Using the Chado Node: Title & Path API
  73. $details = [
  74. 'module' => 'tripal_feature',
  75. 'content_type' => 'chado_feature',
  76. // An array of options to use under "Page URL"
  77. // the key should be the token and the value should be the human-readable option
  78. 'options' => [
  79. '/feature/[feature.feature_id]' => 'Feature ID',
  80. // there should always be one options matching the unique constraint.
  81. '/feature/[feature.organism_id>organism.genus]/[feature.organism_id>organism.species]/[feature.type_id>cvterm.name]/[feature.uniquename]' => 'Unique Contraint: Includes the name, uniquename, type and scientific name',
  82. ],
  83. ];
  84. // This call adds the configuration form to your current form
  85. // This sub-form handles it's own validation & submit
  86. chado_add_admin_form_set_url($form, $form_state, $details);
  87. // FEATURE BROWSER
  88. $form['browser'] = [
  89. '#type' => 'fieldset',
  90. '#title' => t('Feature Browser'),
  91. '#collapsible' => TRUE,
  92. '#collapsed' => TRUE,
  93. ];
  94. $form['browser']['browser_desc'] = [
  95. '#markup' => t('A feature browser can be added to an organism page to allow users to quickly ' .
  96. 'access a feature. This will most likely not be the ideal mechanism for accessing feature ' .
  97. 'information, especially for large sites, but it will alow users exploring the site (such ' .
  98. 'as students) to better understand the data types available on the site.'),
  99. ];
  100. $form['browser']['feature_types'] = [
  101. '#title' => t('Feature Types'),
  102. '#type' => 'textarea',
  103. '#description' => t("Enter the Sequence Ontology (SO) terms for the feature types that " .
  104. "will be shown in the feature browser."),
  105. '#default_value' => variable_get('chado_browser_feature_types', 'gene mRNA'),
  106. ];
  107. $form['browser']['set_browse_button'] = [
  108. '#type' => 'submit',
  109. '#value' => t('Set Browser'),
  110. '#weight' => 2,
  111. ];
  112. // FEATURE SUMMARY REPORT
  113. $form['summary'] = [
  114. '#type' => 'fieldset',
  115. '#title' => t('Feature Summary Report'),
  116. '#collapsible' => TRUE,
  117. '#collapsed' => TRUE,
  118. ];
  119. $form['summary']['feature_mapping'] = [
  120. '#title' => 'Map feature types',
  121. '#description' => t('You may specify which Sequence Ontology (SO) terms to show in the ' .
  122. 'feature summary report by listing them in the following text area. Enter one per line. ' .
  123. 'If left blank, all SO terms for all features will be shown in the report. Only those terms ' .
  124. 'listed below will be shown in the report. Terms will appear in the report in the same order listed. To rename a ' .
  125. 'SO term to be more human readable form, use an \'=\' sign after the SO term (e.g. \'polypeptide = Protein\')'),
  126. '#type' => 'textarea',
  127. '#rows' => 15,
  128. '#default_value' => variable_get('tripal_feature_summary_report_mapping', ''),
  129. ];
  130. $form['summary']['set_summary_button'] = [
  131. '#type' => 'submit',
  132. '#value' => t('Set Summary'),
  133. '#weight' => 2,
  134. ];
  135. return system_settings_form($form);
  136. }
  137. /**
  138. * Validate the feature settings forms
  139. *
  140. * @ingroup tripal_legacy_feature
  141. */
  142. function tripal_feature_admin_validate($form, &$form_state) {
  143. global $user; // we need access to the user info
  144. $job_args = [];
  145. variable_set('chado_browser_feature_types', $form_state['values']['feature_types']);
  146. switch ($form_state['values']['op']) {
  147. case t('Set Summary') :
  148. variable_set('tripal_feature_summary_report_mapping', $form_state['values']['feature_mapping']);
  149. break;
  150. }
  151. }
  152. /**
  153. * USort function for the admin summary chart.
  154. * Not meant to be called directly.
  155. */
  156. function tripal_feature_admin_summary_sort($a, $b) {
  157. if ($a['total_features'] == $b['total_features']) {
  158. return 0;
  159. }
  160. return $b['total_features'] - $a['total_features'];
  161. }