tripal_analysis.admin.inc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * @file
  4. * Contains functions displaying administrative pages and forms.
  5. *
  6. * @ingroup tripal_analysis
  7. */
  8. /**
  9. * Landing page for administration. Ensures Views are enabled & if not provides links to do so.
  10. *
  11. * @ingroup tripal_analysis
  12. */
  13. function tripal_analysis_admin_analysis_view() {
  14. $output = '';
  15. // set the breadcrumb
  16. $breadcrumb = array();
  17. $breadcrumb[] = l('Home', '<front>');
  18. $breadcrumb[] = l('Administration', 'admin');
  19. $breadcrumb[] = l('Tripal', 'admin/tripal');
  20. $breadcrumb[] = l('Chado', 'admin/tripal/chado');
  21. $breadcrumb[] = l('Analysis', 'admin/tripal/chado/tripal_analysis');
  22. drupal_set_breadcrumb($breadcrumb);
  23. // Add the view
  24. $view = views_embed_view('tripal_analysis_admin_analyses','default');
  25. if (isset($view)) {
  26. $output .= $view;
  27. }
  28. else {
  29. $output .= '<p>The Analysis module uses primarily views to provide an '
  30. . 'administrative interface. Currently one or more views needed for this '
  31. . 'administrative interface are disabled. <strong>Click each of the following links to '
  32. . 'enable the pertinent views</strong>:</p>';
  33. $output .= '<ul>';
  34. $output .= '<li>'.l('Analysis View', 'admin/tripal/chado/tripal_analysis/views/analyses/enable').'</li>';
  35. $output .= '</ul>';
  36. }
  37. return $output;
  38. }
  39. /**
  40. * Administration page callbacks for the Tripal Analysis module
  41. *
  42. * We have defined a hook_get_settings() function. When a sub-module
  43. * is enabled, we'll look for this function to provide a form for the
  44. * administrative setting.
  45. *
  46. * @return
  47. * A form API array describing an administrative form
  48. *
  49. * @ingroup tripal_analysis
  50. */
  51. function tripal_analysis_admin() {
  52. // Create a new administrative form. We'll add main functions to the form
  53. // first (Sync, Reindex, Clean, Taxonify). Thereafter, any sub-module that
  54. // has a setting will be added.
  55. $form = array();
  56. // Add sub-module settings. Pull all sub-module information from
  57. // {tripal_analysis} table
  58. $sql = "SELECT modulename FROM {tripal_analysis}";
  59. $result = db_query($sql);
  60. $counter = 0; //keep track of the number of sub-modules
  61. while ($data = $result->fetchObject()) {
  62. // Check if the hook_get_settings() function is already defined.
  63. $func = $data->modulename . "_get_settings";
  64. $functions = get_defined_functions();
  65. $settings;
  66. foreach ($functions['user'] as $function) {
  67. if ($function == $func) {
  68. $settings = $func();
  69. }
  70. }
  71. // Add sub-module's specific settings to the administrative view
  72. if ($settings) {
  73. // Define a fieldset for the sub-module
  74. $form["field$counter"] = array(
  75. '#type' => 'fieldset',
  76. '#title' => "$settings->title",
  77. '#collapsible' => TRUE
  78. );
  79. $form["field$counter"]["$settings->title"] = $settings->form;
  80. }
  81. $counter++;
  82. }
  83. if($counter == 0) {
  84. $form['nothing'] = array(
  85. '#markup' => t('There are currently no settings to configure. However, analysis extension modules may add items here when they are installed.')
  86. );
  87. }
  88. return system_settings_form($form);
  89. }
  90. /**
  91. * Validate the administrative form
  92. * @todo Stephen: Why is validate used rather then submit?
  93. *
  94. * @param $form
  95. * The form API array of the form to be validated
  96. * @form_state
  97. * The user submitted values
  98. *
  99. * @ingroup tripal_analysis
  100. */
  101. function tripal_analysis_admin_validate($form, &$form_state) {
  102. global $user; // we need access to the user info
  103. $job_args = array();
  104. // -------------------------------------
  105. // Submit the Reindex Job if selected
  106. if ($form_state['values']['op'] == t('Reindex Features')) {
  107. global $user; // we need access to the user info
  108. $job_args = array();
  109. $analyses = $form_state['values']['re-analyses'];
  110. foreach ($analyses as $analysis_id) {
  111. if ($analysis_id and preg_match("/^\d+$/i", $analysis_id)) {
  112. // get the analysis info
  113. $sql = "SELECT * FROM {analysis} WHERE analysis_id = :analysis_id";
  114. $analysis = chado_query($sql, array(':analysis_id' => $analysis_id))->fetchObject();
  115. $job_args[0] = $analysis_id;
  116. tripal_add_job("Reindex features for analysis: $analysis->name", 'tripal_analysis',
  117. 'tripal_analysis_reindex_features', $job_args, $user->uid);
  118. }
  119. }
  120. }
  121. // -------------------------------------
  122. // Submit the Taxonomy Job if selected
  123. if ($form_state['values']['op'] == t('Set Feature Taxonomy')) {
  124. global $user; // we need access to the user info
  125. $job_args = array();
  126. $analyses = $form_state['values']['tx-analyses'];
  127. foreach ($analyses as $analysis_id) {
  128. if ($analysis_id and preg_match("/^\d+$/i", $analysis_id)) {
  129. // get the analysis info
  130. $sql = "SELECT * FROM {analysis} WHERE analysis_id = :analysis_id";
  131. $analysis = chado_query($sql, array(':analysis_id' => $analysis_id))->fetchObject();
  132. $job_args[0] = $analysis_id;
  133. tripal_add_job("Set taxonomy for features in analysis: $analysis->name", 'tripal_analysis',
  134. 'tripal_analysis_taxonify_features', $job_args, $user->uid);
  135. }
  136. }
  137. }
  138. }