tripal_analysis.admin.inc 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. /**
  3. * @file
  4. * Contains functions displaying administrative pages and forms
  5. */
  6. /**
  7. * Administration page callbacks for the Tripal Analysis module
  8. *
  9. * We have defined a hook_get_settings() function. When a sub-module
  10. * is enabled, we'll look for this function to provide a form for the
  11. * administrative setting.
  12. *
  13. * @return
  14. * A form API array describing an administrative form
  15. *
  16. * @ingroup tripal_analysis
  17. */
  18. function tripal_analysis_admin() {
  19. // Create a new administrative form. We'll add main functions to the form
  20. // first (Sync, Reindex, Clean, Taxonify). Thereafter, any sub-module that
  21. // has a setting will be added.
  22. $form = array();
  23. // Add sub-module settings. Pull all sub-module information from
  24. // {tripal_analysis} table
  25. $sql = "SELECT modulename FROM {tripal_analysis}";
  26. $result = db_query($sql);
  27. $counter = 0; //keep track of the number of sub-modules
  28. while ($data = $result->fetchObject()) {
  29. // Check if the hook_get_settings() function is already defined.
  30. $func = $data->modulename . "_get_settings";
  31. $functions = get_defined_functions();
  32. $settings;
  33. foreach ($functions['user'] as $function) {
  34. if ($function == $func) {
  35. $settings = $func();
  36. }
  37. }
  38. // Add sub-module's specific settings to the administrative view
  39. if ($settings) {
  40. // Define a fieldset for the sub-module
  41. $form["field$counter"] = array(
  42. '#type' => 'fieldset',
  43. '#title' => "$settings->title",
  44. '#collapsible' => TRUE
  45. );
  46. $form["field$counter"]["$settings->title"] = $settings->form;
  47. }
  48. $counter++;
  49. }
  50. if($counter == 0) {
  51. $form['nothing'] = array(
  52. '#markup' => t('There are currently no settings to configure. However, analysis extension modules may add items here when they are installed.')
  53. );
  54. }
  55. return system_settings_form($form);
  56. }
  57. /**
  58. * Displays the Set Drupal Taxonomy for Analysis Features From
  59. *
  60. * @param $form
  61. * The administrative form as it is currently
  62. *
  63. * @return
  64. * A form API array describing an administrative form
  65. *
  66. * @ingroup tripal_analysis
  67. */
  68. function get_tripal_analysis_admin_form_taxonomy_set(&$form) {
  69. $form['taxonify'] = array(
  70. '#type' => 'fieldset',
  71. '#title' => t('Assign Drupal Taxonomy to Analysis Features')
  72. );
  73. // get the list of analyses
  74. $sql = "SELECT * FROM {analysis} ORDER BY name";
  75. $lib_rset = chado_query($sql);
  76. // iterate through all of the libraries
  77. $lib_boxes = array();
  78. while ($analysis = $lib_rset->fetchObject()) {
  79. $lib_boxes[$analysis->analysis_id] = "$analysis->name";
  80. }
  81. $form['taxonify']['description'] = array(
  82. '#type' => 'item',
  83. '#value' => t("Drupal allows for assignment of \"taxonomy\" or catagorical terms to " .
  84. "nodes. These terms allow for advanced filtering during searching. This option allows " .
  85. "for setting taxonomy only for features that belong to the selected analyses below. All other features will be unaffected. To set taxonomy for all features in the site see the Feature Administration page."),
  86. '#weight' => 1,
  87. );
  88. $form['taxonify']['tx-analyses'] = array(
  89. '#title' => t('Analyses'),
  90. '#type' => t('checkboxes'),
  91. '#description' => t("Check the analyses whose features you want to reset taxonomy. Note: this list contains all analyses, even those that may not be synced."),
  92. '#required' => FALSE,
  93. '#prefix' => '<div id="lib_boxes">',
  94. '#suffix' => '</div>',
  95. '#options' => $lib_boxes,
  96. '#weight' => 2
  97. );
  98. $form['taxonify']['tx-button'] = array(
  99. '#type' => 'submit',
  100. '#value' => t('Set Feature Taxonomy'),
  101. '#weight' => 3
  102. );
  103. }
  104. /**
  105. * The "Reindex Analysis Nodes" form
  106. *
  107. * @param $form
  108. * The administrative form as it is currently
  109. *
  110. * @return
  111. * A form API array describing an administrative form
  112. *
  113. * @ingroup tripal_analysis
  114. */
  115. function get_tripal_analysis_admin_form_reindex_set(&$form) {
  116. // define the fieldsets
  117. $form['reindex'] = array(
  118. '#type' => 'fieldset',
  119. '#title' => t('Reindex Analysis Features')
  120. );
  121. // get the list of libraries
  122. $sql = "SELECT * FROM {analysis} ORDER BY name";
  123. $lib_rset = chado_query($sql);
  124. // iterate through all of the libraries
  125. $lib_boxes = array();
  126. while ($analysis = $lib_rset->fetchObject()) {
  127. $lib_boxes[$analysis->analysis_id] = "$analysis->name";
  128. }
  129. $form['reindex']['description'] = array(
  130. '#type' => 'item',
  131. '#value' => t("This option allows for reindexing of only those features that belong to the selected analyses below. All other features will be unaffected. To reindex all features in the site see the Feature Administration page."),
  132. '#weight' => 1,
  133. );
  134. $form['reindex']['re-analyses'] = array(
  135. '#title' => t('Libraries'),
  136. '#type' => t('checkboxes'),
  137. '#description' => t("Check the analyses whoee features you want to reindex. Note: this list contains all analyses, even those that may not be synced."),
  138. '#required' => FALSE,
  139. '#prefix' => '<div id="lib_boxes">',
  140. '#suffix' => '</div>',
  141. '#options' => $lib_boxes,
  142. '#weight' => 2,
  143. );
  144. $form['reindex']['re-button'] = array(
  145. '#type' => 'submit',
  146. '#value' => t('Reindex Features'),
  147. '#weight' => 3,
  148. );
  149. }
  150. /**
  151. * Validate the administrative form
  152. * @todo Stephen: Why is validate used rather then submit?
  153. *
  154. * @param $form
  155. * The form API array of the form to be validated
  156. * @form_state
  157. * The user submitted values
  158. *
  159. * @ingroup tripal_analysis
  160. */
  161. function tripal_analysis_admin_validate($form, &$form_state) {
  162. global $user; // we need access to the user info
  163. $job_args = array();
  164. // -------------------------------------
  165. // Submit the Reindex Job if selected
  166. if ($form_state['values']['op'] == t('Reindex Features')) {
  167. global $user; // we need access to the user info
  168. $job_args = array();
  169. $analyses = $form_state['values']['re-analyses'];
  170. foreach ($analyses as $analysis_id) {
  171. if ($analysis_id and preg_match("/^\d+$/i", $analysis_id)) {
  172. // get the analysis info
  173. $sql = "SELECT * FROM {analysis} WHERE analysis_id = :analysis_id";
  174. $analysis = chado_query($sql, array(':analysis_id' => $analysis_id))->fetchObject();
  175. $job_args[0] = $analysis_id;
  176. tripal_add_job("Reindex features for analysis: $analysis->name", 'tripal_analysis',
  177. 'tripal_analysis_reindex_features', $job_args, $user->uid);
  178. }
  179. }
  180. }
  181. // -------------------------------------
  182. // Submit the Taxonomy Job if selected
  183. if ($form_state['values']['op'] == t('Set Feature Taxonomy')) {
  184. global $user; // we need access to the user info
  185. $job_args = array();
  186. $analyses = $form_state['values']['tx-analyses'];
  187. foreach ($analyses as $analysis_id) {
  188. if ($analysis_id and preg_match("/^\d+$/i", $analysis_id)) {
  189. // get the analysis info
  190. $sql = "SELECT * FROM {analysis} WHERE analysis_id = :analysis_id";
  191. $analysis = chado_query($sql, array(':analysis_id' => $analysis_id))->fetchObject();
  192. $job_args[0] = $analysis_id;
  193. tripal_add_job("Set taxonomy for features in analysis: $analysis->name", 'tripal_analysis',
  194. 'tripal_analysis_taxonify_features', $job_args, $user->uid);
  195. }
  196. }
  197. }
  198. }