tripal_feature.admin.inc 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. /**
  3. * @file
  4. * Administration of features
  5. */
  6. /**
  7. * Launchpad for feature administration.
  8. *
  9. * @ingroup tripal_feature
  10. */
  11. function tripal_feature_admin_feature_view() {
  12. $output = '';
  13. // set the breadcrumb
  14. $breadcrumb = array();
  15. $breadcrumb[] = l('Home', '<front>');
  16. $breadcrumb[] = l('Administration', 'admin');
  17. $breadcrumb[] = l('Tripal', 'admin/tripal');
  18. $breadcrumb[] = l('Chado', 'admin/tripal/chado');
  19. $breadcrumb[] = l('Features', 'admin/tripal/chado/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/chado/tripal_feature/views/features/enable').'</li>';
  33. $output .= '</ul>';
  34. }
  35. return $output;
  36. }
  37. /**
  38. * Feature Settings page
  39. *
  40. * @ingroup tripal_feature
  41. */
  42. function tripal_feature_admin() {
  43. // FEATURE PAGE TITLES
  44. $form['title'] = array(
  45. '#type' => 'fieldset',
  46. '#title' => t('Feature Page Titles'),
  47. '#collapsible' => TRUE,
  48. '#collapsed' => FALSE,
  49. );
  50. $form['title']['desc'] = array(
  51. '#markup' => t(
  52. 'Each synced feature must have a unique page title, however, features '.
  53. 'may have the same name if they are of different types or from '.
  54. 'different organisms. Therefore, we must be sure that the '.
  55. 'page titles can uniquely identify the feature being viewed. Select '.
  56. 'an option below that will uniquely identify all features on your site.'),
  57. );
  58. $options = array(
  59. 'feature_unique_name' => 'Feature unique name',
  60. 'feature_name' => 'Feature name',
  61. 'unique_constraint' => 'Feature Name, uniquename, type and species',
  62. );
  63. $form['title']['chado_feature_title'] = array(
  64. '#title' => t('Feature Page Titles'),
  65. '#type' => 'radios',
  66. '#description' => t('Choose a title type from the list above that is '.
  67. 'guaranteed to be unique for all features. If in doubt it is safest to '.
  68. 'choose the last option as that guarantees uniqueness. Click the '.
  69. '\'Save Configuration\' button at the bottom to save your selection.'),
  70. '#required' => FALSE,
  71. '#options' => $options,
  72. '#default_value' => variable_get('chado_feature_title', 'unique_constraint'),
  73. );
  74. // FEATURE URL PATHS
  75. $form['url'] = array(
  76. '#type' => 'fieldset',
  77. '#title' => t('Feature URL Path'),
  78. '#collapsible' => TRUE,
  79. '#collapsed' => FALSE,
  80. );
  81. $options = array(
  82. 'SID[id]' => '[id]:' . t('The Chado feature_id'),
  83. 'feature' => 'feature:' . t('Chado table name'),
  84. '[genus]' => '[genus]:' . t('Genus to which the feature belongs'),
  85. '[species]' => '[species]:' . t('Species to which the feature belongs'),
  86. '[type]' => '[type]:' . t('The type of feature'),
  87. '[uniquename]' => '[uniquename]:' . t('The feature unique name'),
  88. '[name]' => '[name]:' . t('The feature name'),
  89. 'reset' => t('Reset'),
  90. );
  91. $form['url']['chado_feature_url_string'] = array(
  92. '#title' => 'URL Syntax',
  93. '#type' => 'textfield',
  94. '#description' => t('You may rearrange elements in this text box to '.
  95. 'customize the URLs. The available tags include: [id], '.
  96. '[uniquename]. [name], [species], [genus], [type]. You can separate or '.
  97. 'include any text between the tags. Click the "Set Feature URLs" button to '.
  98. 'reset the URLs for all feature pages. Click the "Save Configuration" button to '.
  99. 'simply save this setup. <b>Important</b>: be sure that whatever you choose will always be unique even considering '.
  100. 'future data that may be added. If you include the Chado table name, genus, species, type '.
  101. 'and uniquename you are guaranteed to have a unique URL. For example feature/[genus]/[species]/[type]/[uniquename]'),
  102. '#size' => 150,
  103. '#default_value' => variable_get('chado_feature_url_string', '/feature/[genus]/[species]/[type]/[uniquename]'),
  104. );
  105. $form['url']['chado_feature_url'] = array(
  106. '#title' => t('URL components'),
  107. '#type' => 'checkboxes',
  108. '#required' => FALSE,
  109. '#options' => $options,
  110. '#description' => t('Click the item above to make it appear in the URL Syntax box'),
  111. '#attributes' => array(
  112. 'onclick' => '
  113. box = $(\'#edit-chado-feature-url-string\');
  114. if (this.value == \'reset\') {
  115. box.val(\'\');
  116. }
  117. else {
  118. box.val(box.val() + "/" + this.value);
  119. }
  120. this.checked = false;
  121. ',
  122. ),
  123. );
  124. $form['url']['button'] = array(
  125. '#type' => 'submit',
  126. '#value' => t('Set Feature URLs'),
  127. );
  128. // FEATURE BROWSER
  129. $form['browser'] = array(
  130. '#type' => 'fieldset',
  131. '#title' => t('Feature Browser'),
  132. '#collapsible' => TRUE,
  133. '#collapsed' => FALSE,
  134. );
  135. $form['browser']['browser_desc'] = array(
  136. '#markup' => t('A feature browser can be added to an organism page to allow users to quickly ' .
  137. 'access a feature. This will most likely not be the ideal mechanism for accessing feature ' .
  138. 'information, especially for large sites, but it will alow users exploring the site (such ' .
  139. 'as students) to better understand the data types available on the site.'),
  140. );
  141. $form['browser']['feature_types'] = array(
  142. '#title' => t('Feature Types'),
  143. '#type' => 'textarea',
  144. '#description' => t("Enter the Sequence Ontology (SO) terms for the feature types that " .
  145. "will be shown in the feature browser."),
  146. '#default_value' => variable_get('chado_browser_feature_types', 'gene mRNA'),
  147. );
  148. $form['browser']['set_browse_button'] = array(
  149. '#type' => 'submit',
  150. '#value' => t('Set Browser'),
  151. '#weight' => 2,
  152. );
  153. // FEATURE SUMMARY REPORT
  154. $form['summary'] = array(
  155. '#type' => 'fieldset',
  156. '#title' => t('Feature Summary Report'),
  157. '#collapsible' => TRUE,
  158. '#collapsed' => FALSE,
  159. );
  160. $form['summary']['feature_mapping'] = array(
  161. '#title' => 'Map feature types',
  162. '#description' => t('You may specify which Sequence Ontology (SO) terms to show in the ' .
  163. 'feature summary report by listing them in the following text area. Enter one per line. ' .
  164. 'If left blank, all SO terms for all features will be shown in the report. Only those terms ' .
  165. 'listed below will be shown in the report. Terms will appear in the report in the same order listed. To rename a ' .
  166. 'SO term to be more human readable form, use an \'=\' sign after the SO term (e.g. \'polypeptide = Protein\')'),
  167. '#type' => 'textarea',
  168. '#rows' => 15,
  169. '#default_value' => variable_get('tripal_feature_summary_report_mapping', ''),
  170. );
  171. $form['summary']['set_summary_button'] = array(
  172. '#type' => 'submit',
  173. '#value' => t('Set Summary'),
  174. '#weight' => 2,
  175. );
  176. return system_settings_form($form);
  177. }
  178. /**
  179. * Validate the feature settings forms
  180. *
  181. * @ingroup tripal_feature
  182. */
  183. function tripal_feature_admin_validate($form, &$form_state) {
  184. global $user; // we need access to the user info
  185. $job_args = array();
  186. variable_set('chado_browser_feature_types', $form_state['values']['feature_types']);
  187. switch ($form_state['values']['op']) {
  188. case t('Set Summary') :
  189. variable_set('tripal_feature_summary_report_mapping', $form_state['values']['feature_mapping']);
  190. break;
  191. case t('Set Feature URLs') :
  192. variable_set('chado_feature_url', $form_state['values']['feature_url']);
  193. tripal_add_job('Set Feature URLs', 'tripal_feature',
  194. 'tripal_feature_set_urls', $job_args, $user->uid);
  195. break;
  196. }
  197. }