tripal_analysis.admin.inc 8.3 KB

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