admin.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <?php
  2. /************************************************************************
  3. *
  4. */
  5. function tripal_feature_admin () {
  6. // before proceeding check to see if we have any
  7. // currently processing jobs. If so, we don't want
  8. // to give the opportunity to sync libraries
  9. $active_jobs = FALSE;
  10. if(tripal_get_module_active_jobs('tripal_feature')){
  11. $active_jobs = TRUE;
  12. }
  13. if(!$active_jobs){
  14. $form['chado_feature_accession_prefix'] = array (
  15. '#title' => t('Accession Prefix'),
  16. '#type' => t('textfield'),
  17. '#description' => t("Accession numbers for features consist of the ".
  18. "chado feature_id and a site specific prefix. Set the prefix that ".
  19. "will be incorporated in front of each feature_id to form a unique ".
  20. "accession number for this site."),
  21. '#required' => TRUE,
  22. '#default_value' => variable_get('chado_feature_accession_prefix','ID'),
  23. );
  24. $form['chado_feature_types'] = array(
  25. '#title' => t('Feature Types'),
  26. '#type' => 'textarea',
  27. '#description' => t('Enter the names of the sequence types that the ".
  28. "site will support with independent pages. Pages for these data ".
  29. "types will be built automatically for features that exist in the ".
  30. "chado database. The names listed here should be spearated by ".
  31. "spaces or entered separately on new lines. The names must match ".
  32. "exactly (spelling and case) with terms in the sequence ontology'),
  33. '#required' => TRUE,
  34. '#default_value' => variable_get('chado_feature_types','EST contig'),
  35. );
  36. $form['browser'] = array(
  37. '#type' => 'fieldset',
  38. '#title' => t('Feature Browser')
  39. );
  40. $allowedoptions1 = array (
  41. 'show_feature_browser' => "Show the feature browser on the organism page. The browser loads when page loads. This may be slow for large sites.",
  42. 'hide_feature_browser' => "Hide the feature browser on the organism page. Disables the feature browser completely.",
  43. );
  44. // $allowedoptions ['allow_feature_browser'] = "Allow loading of the feature browsing through AJAX. For large sites the initial page load will be quick with the feature browser loading afterwards.";
  45. $form['browser']['browse_features'] = array(
  46. '#title' => 'Feature Browser on Organism Page',
  47. '#description' => 'A feature browser can be added to an organism page to allow users to quickly '.
  48. 'access a feature. This will most likely not be the ideal mechanism for accessing feature '.
  49. 'information, especially for large sites, but it will alow users exploring the site (such '.
  50. 'as students) to better understand the data types available on the site.',
  51. '#type' => 'radios',
  52. '#options' => $allowedoptions1,
  53. '#default_value'=>variable_get('tripal_feature_browse_setting', 'show_feature_browser'),
  54. );
  55. $form['browser']['set_browse_button'] = array(
  56. '#type' => 'submit',
  57. '#value' => t('Set Browser'),
  58. '#weight' => 2,
  59. );
  60. $form['summary'] = array(
  61. '#type' => 'fieldset',
  62. '#title' => t('Feature Summary')
  63. );
  64. $allowedoptions2 ['show_feature_summary'] = "Show the feature summary on the organism page. The summary loads when page loads.";
  65. $allowedoptions2 ['hide_feature_summary'] = "Hide the feature summary on the organism page. Disables the feature summary.";
  66. $form['summary']['feature_summary'] = array(
  67. '#title' => 'Feature Summary on Organism Page',
  68. '#description' => 'A feature summary can be added to an organism page to allow users to see the '.
  69. 'type and quantity of features available for the organism.',
  70. '#type' => 'radios',
  71. '#options' => $allowedoptions2,
  72. '#default_value'=>variable_get('tripal_feature_summary_setting', 'show_feature_summary'),
  73. );
  74. $form['summary']['set_summary_button'] = array(
  75. '#type' => 'submit',
  76. '#value' => t('Set Summary'),
  77. '#weight' => 2,
  78. );
  79. get_tripal_feature_admin_form_sync_set($form);
  80. get_tripal_feature_admin_form_taxonomy_set($form);
  81. get_tripal_feature_admin_form_reindex_set($form);
  82. get_tripal_feature_admin_form_cleanup_set($form);
  83. } else {
  84. $form['notice'] = array(
  85. '#type' => 'fieldset',
  86. '#title' => t('Feature Management Temporarily Unavailable')
  87. );
  88. $form['notice']['message'] = array(
  89. '#value' => t('Currently, feature management jobs are waiting or ".
  90. "are running. Managemment features have been hidden until these ".
  91. "jobs complete. Please check back later once these jobs have ".
  92. "finished. You can view the status of pending jobs in the Tripal ".
  93. "jobs page.'),
  94. );
  95. }
  96. return system_settings_form($form);
  97. }
  98. /************************************************************************
  99. *
  100. */
  101. function tripal_feature_admin_validate($form, &$form_state) {
  102. global $user; // we need access to the user info
  103. $job_args = array();
  104. // if the user wants to sync up the chado features then
  105. // add the job to the management queue
  106. if ($form_state['values']['op'] == t('Sync all Features')) {
  107. tripal_add_job('Sync all features','tripal_feature',
  108. 'tripal_feature_sync_features',$job_args,$user->uid);
  109. }
  110. if ($form_state['values']['op'] == t('Set/Reset Taxonomy for all feature nodes')) {
  111. tripal_add_job('Set all feature taxonomy','tripal_feature',
  112. 'tripal_features_set_taxonomy',$job_args,$user->uid);
  113. }
  114. if ($form_state['values']['op'] == t('Reindex all feature nodes')) {
  115. tripal_add_job('Reindex all features','tripal_feature',
  116. 'tripal_features_reindex',$job_args,$user->uid);
  117. }
  118. if ($form_state['values']['op'] == t('Clean up orphaned features')) {
  119. tripal_add_job('Cleanup orphaned features','tripal_feature',
  120. 'tripal_features_cleanup',$job_args,$user->uid);
  121. }
  122. if ($form_state['values']['op'] == t('Set Browser')) {
  123. variable_set('tripal_feature_browse_setting',$form_state['values']['browse_features']);
  124. }
  125. if ($form_state['values']['op'] == t('Set Summary')) {
  126. variable_set('tripal_feature_summary_setting',$form_state['values']['feature_summary']);
  127. }
  128. }
  129. /************************************************************************
  130. *
  131. */
  132. function get_tripal_feature_admin_form_cleanup_set(&$form) {
  133. $form['cleanup'] = array(
  134. '#type' => 'fieldset',
  135. '#title' => t('Clean Up')
  136. );
  137. $form['cleanup']['description'] = array(
  138. '#type' => 'item',
  139. '#value' => t("With Drupal and chado residing in different databases ".
  140. "it is possible that nodes in Drupal and features in Chado become ".
  141. "\"orphaned\". This can occur if a feature node in Drupal is ".
  142. "deleted but the corresponding chado feature is not and/or vice ".
  143. "versa. The Cleanup function will also remove nodes for features ".
  144. "that are not in the list of allowed feature types as specified ".
  145. "above. This is helpful when a feature type needs to be ".
  146. "removed but was previously present as Drupal nodes. ".
  147. "Click the button below to resolve these discrepancies."),
  148. '#weight' => 1,
  149. );
  150. $form['cleanup']['button'] = array(
  151. '#type' => 'submit',
  152. '#value' => t('Clean up orphaned features'),
  153. '#weight' => 2,
  154. );
  155. }
  156. /************************************************************************
  157. *
  158. */
  159. function get_tripal_feature_admin_form_reindex_set(&$form) {
  160. $form['reindex'] = array(
  161. '#type' => 'fieldset',
  162. '#title' => t('Reindex')
  163. );
  164. $form['reindex']['description'] = array(
  165. '#type' => 'item',
  166. '#value' => t("Reindexing of nodes is important when content for nodes ".
  167. "is updated external to drupal, such as external uploads to chado. ".
  168. "Features need to be reindexed to ensure that updates to features ".
  169. "are searchable. Depending on the number of features this may take ".
  170. "quite a while. Click the button below to begin reindexing of ".
  171. "features."),
  172. '#weight' => 1,
  173. );
  174. $form['reindex']['button'] = array(
  175. '#type' => 'submit',
  176. '#value' => t('Reindex all feature nodes'),
  177. '#weight' => 2,
  178. );
  179. }
  180. /************************************************************************
  181. *
  182. */
  183. function get_tripal_feature_admin_form_taxonomy_set (&$form) {
  184. $form['taxonomy'] = array(
  185. '#type' => 'fieldset',
  186. '#title' => t('Set Taxonomy')
  187. );
  188. $form['taxonomy']['description'] = array(
  189. '#type' => 'item',
  190. '#value' => t("Drupal allows for assignment of \"taxonomy\" or ".
  191. "catagorical terms to nodes. These terms allow for advanced ".
  192. "filtering during searching."),
  193. '#weight' => 1,
  194. );
  195. $tax_options = array (
  196. 'organism' => t('Organism name'),
  197. 'feature_type' => t('Feature Type (e.g. EST, mRNA, etc.)'),
  198. 'analysis' => t('Analysis Name'),
  199. 'library' => t('Library Name'),
  200. );
  201. $form['taxonomy']['tax_classes'] = array (
  202. '#title' => t('Available Taxonomic Classes'),
  203. '#type' => t('checkboxes'),
  204. '#description' => t("Please select the class of terms to assign to ".
  205. "chado features"),
  206. '#required' => FALSE,
  207. '#prefix' => '<div id="taxclass_boxes">',
  208. '#suffix' => '</div>',
  209. '#options' => $tax_options,
  210. '#weight' => 2,
  211. '#default_value' => variable_get('tax_classes',''),
  212. );
  213. $form['taxonomy']['button'] = array(
  214. '#type' => 'submit',
  215. '#value' => t('Set/Reset Taxonomy for all feature nodes'),
  216. '#weight' => 3,
  217. );
  218. }
  219. /************************************************************************
  220. *
  221. */
  222. function get_tripal_feature_admin_form_sync_set (&$form) {
  223. // get the list of organisms which will be synced.
  224. $feature_sql = "SELECT * FROM {Feature} WHERE uniquename = '%s' and organism_id = %d";
  225. $previous_db = tripal_db_set_active('chado');
  226. $feature = db_fetch_object(db_query($feature_sql,$node->title,$node->organism_id));
  227. tripal_db_set_active($previous_db);
  228. // define the fieldsets
  229. $form['sync'] = array(
  230. '#type' => 'fieldset',
  231. '#title' => t('Sync Features')
  232. );
  233. $form['sync']['description'] = array(
  234. '#type' => 'item',
  235. '#value' => t("Click the 'Sync all Features' button to create Drupal ".
  236. "content for features in chado. Only features of the types listed ".
  237. "above in the Feature Types box will be synced. Depending on the ".
  238. "number of features in the chado database this may take a long ".
  239. "time to complete. "),
  240. '#weight' => 1,
  241. );
  242. $orgs = tripal_organism_get_synced();
  243. $org_list = '';
  244. foreach($orgs as $org){
  245. $org_list .= "$org->genus $org->species, ";
  246. }
  247. $form['sync']['description2'] = array(
  248. '#type' => 'item',
  249. '#value' => "Only features for the following organisms will be synced: ".
  250. " $org_list",
  251. '#weight' => 1,
  252. );
  253. $form['sync']['button'] = array(
  254. '#type' => 'submit',
  255. '#value' => t('Sync all Features'),
  256. '#weight' => 3,
  257. );
  258. }