tripal_organism.admin.inc 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <?php
  2. /**
  3. *
  4. */
  5. function tripal_organism_admin_organism_view() {
  6. $output = '';
  7. // set the breadcrumb
  8. $breadcrumb = array();
  9. $breadcrumb[] = l('Home', '<front>');
  10. $breadcrumb[] = l('Administration', 'admin');
  11. $breadcrumb[] = l('Tripal', 'admin/tripal');
  12. $breadcrumb[] = l('Chado', 'admin/tripal/chado');
  13. $breadcrumb[] = l('Organisms', 'admin/tripal/chado/tripal_organism');
  14. drupal_set_breadcrumb($breadcrumb);
  15. // Add the view
  16. $view = views_embed_view('tripal_organism_admin_organisms','default');
  17. if (isset($view)) {
  18. $output .= $view;
  19. }
  20. else {
  21. $output .= '<p>The Organism module uses primarily views to provide an '
  22. . 'administrative interface. Currently one or more views needed for this '
  23. . 'administrative interface are disabled. <strong>Click each of the following links to '
  24. . 'enable the pertinent views</strong>:</p>';
  25. $output .= '<ul>';
  26. $output .= '<li>'.l('Organisms View', 'admin/tripal/chado/tripal_organism/views/organisms/enable').'</li>';
  27. $output .= '</ul>';
  28. }
  29. return $output;
  30. }
  31. /**
  32. * Administrative settings for chado_orgnism
  33. *
  34. * @ingroup tripal_organism
  35. */
  36. function tripal_organism_admin() {
  37. $form = array();
  38. get_tripal_organism_admin_form_reindex_set($form);
  39. get_tripal_organism_admin_form_taxonomy_set($form);
  40. return system_settings_form($form);
  41. }
  42. /**
  43. *
  44. *
  45. * @ingroup tripal_organism
  46. */
  47. function get_tripal_organism_admin_form_taxonomy_set(&$form) {
  48. $form['taxonify'] = array(
  49. '#type' => 'fieldset',
  50. '#title' => t('Assign Drupal Taxonomy to Organism Features')
  51. );
  52. // get the list of libraries
  53. $sql = "SELECT * FROM {Organism} ORDER BY genus,species";
  54. $org_rset = chado_query($sql);
  55. // iterate through all of the libraries
  56. $org_boxes = array();
  57. foreach ($org_rset as $organism) {
  58. $org_boxes[$organism->organism_id] = "$organism->genus $organism->species";
  59. }
  60. $form['taxonify']['description'] = array(
  61. '#type' => 'item',
  62. '#value' => t(
  63. "Drupal allows for assignment of \"taxonomy\" or catagorical terms to " .
  64. "nodes. These terms allow for advanced filtering during searching. This option allows " .
  65. "for setting taxonomy only for features that belong to the selected organisms below. All " .
  66. "other features will be unaffected. To set taxonomy for all features in the site see the Feature Administration page."),
  67. '#weight' => 1,
  68. );
  69. $form['taxonify']['tx-organisms'] = array(
  70. '#title' => t('Organisms'),
  71. '#type' => t('checkboxes'),
  72. '#description' => t("Check the organisms whose features you want to reset taxonomy. Note: this list contains all organisms, even those that may not be synced."),
  73. '#required' => FALSE,
  74. '#prefix' => '<div id="lib_boxes">',
  75. '#suffix' => '</div>',
  76. '#options' => $org_boxes,
  77. '#weight' => 2
  78. );
  79. $form['taxonify']['tx-button'] = array(
  80. '#type' => 'submit',
  81. '#value' => t('Set Feature Taxonomy'),
  82. '#weight' => 3
  83. );
  84. }
  85. /**
  86. *
  87. * @ingroup tripal_organism
  88. */
  89. function get_tripal_organism_admin_form_reindex_set(&$form) {
  90. // define the fieldsets
  91. $form['reindex'] = array(
  92. '#type' => 'fieldset',
  93. '#title' => t('Reindex Organism Features')
  94. );
  95. // get the list of libraries
  96. $sql = "SELECT * FROM {Organism} ORDER BY genus,species";
  97. $org_rset = chado_query($sql);
  98. // iterate through all of the libraries
  99. $org_boxes = array();
  100. foreach ($org_rset as $organism) {
  101. $org_boxes[$organism->organism_id] = "$organism->genus $organism->species";
  102. }
  103. $form['reindex']['description'] = array(
  104. '#type' => 'item',
  105. '#value' => t("This option allows for reindexing of only those features that belong to the selected organisms below. All other features will be unaffected. To reindex all features in the site see the Feature Administration page."),
  106. '#weight' => 1,
  107. );
  108. $form['reindex']['re-organisms'] = array(
  109. '#title' => t('Organisms'),
  110. '#type' => t('checkboxes'),
  111. '#description' => t("Check the organisms whose features you want to reindex. Note: this list contains all organisms, even those that may not be synced."),
  112. '#required' => FALSE,
  113. '#prefix' => '<div id="lib_boxes">',
  114. '#suffix' => '</div>',
  115. '#options' => $org_boxes,
  116. '#weight' => 2,
  117. );
  118. $form['reindex']['re-button'] = array(
  119. '#type' => 'submit',
  120. '#value' => t('Reindex Features'),
  121. '#weight' => 3,
  122. );
  123. }
  124. /**
  125. *
  126. * @ingroup tripal_organism
  127. */
  128. function tripal_organism_admin_validate($form, &$form_state) {
  129. global $user; // we need access to the user info
  130. $job_args = array();
  131. // -------------------------------------
  132. // Submit the Reindex Job if selected
  133. if ($form_state['values']['op'] == t('Reindex Features')) {
  134. $organisms = $form_state['values']['re-organisms'];
  135. foreach ($organisms as $organism_id) {
  136. if ($organism_id and preg_match("/^\d+$/i" , $organism_id)) {
  137. // get the organism info
  138. $sql = "SELECT * FROM {organism} WHERE organism_id = :organism_id";
  139. $organism = chado_query($sql, array(':organism_id' => $organism_id))->fetchObject();
  140. $job_args[0] = $organism_id;
  141. tripal_add_job("Reindex features for organism: $organism->genus " .
  142. "$organism->species", 'tripal_organism' ,
  143. 'tripal_organism_reindex_features', $job_args, $user->uid);
  144. }
  145. }
  146. }
  147. // -------------------------------------
  148. // Submit the taxonomy Job if selected
  149. if ($form_state['values']['op'] == t('Set Feature Taxonomy')) {
  150. $organisms = $form_state['values']['tx-organisms'];
  151. foreach ($organisms as $organism_id) {
  152. if ($organism_id and preg_match("/^\d+$/i", $organism_id)) {
  153. // get the organism info
  154. $sql = "SELECT * FROM {organism} WHERE organism_id = :organism_id";
  155. $organism = chado_query($sql, array(':organism_id' => $organism_id))->fetchObject();
  156. $job_args[0] = $organism_id;
  157. tripal_add_job("Set taxonomy for features in organism: " .
  158. "$organism->genus $organism->species" , 'tripal_organism',
  159. 'tripal_organism_taxonify_features', $job_args, $user->uid);
  160. }
  161. }
  162. }
  163. }
  164. /**
  165. *
  166. * @ingroup tripal_organism
  167. */
  168. function tripal_organism_reindex_features($organism_id = NULL, $job_id = NULL) {
  169. $i = 0;
  170. if (!$organism_id) {
  171. return;
  172. }
  173. $sql = "
  174. SELECT *
  175. FROM {feature}
  176. WHERE organism_id = :organism_id
  177. ORDER BY feature_id";
  178. $results = chado_query($sql, array(':organism_id' => $organism_id));
  179. // load into ids array
  180. $count = 0;
  181. $ids = array();
  182. foreach ($results as $id) {
  183. $ids[$count] = $id->feature_id;
  184. $count++;
  185. }
  186. $interval = intval($count * 0.01);
  187. foreach ($ids as $feature_id) {
  188. // update the job status every 1% features
  189. if ($job_id and $i % $interval == 0) {
  190. tripal_job_set_progress($job_id , intval(($i/$count)*100));
  191. }
  192. $i++;
  193. }
  194. }
  195. /**
  196. *
  197. * @ingroup tripal_organism
  198. */
  199. function tripal_organism_taxonify_features($organism_id = NULL, $job_id = NULL) {
  200. $i = 0;
  201. if (!$organism_id) {
  202. return;
  203. }
  204. $sql = "
  205. SELECT *
  206. FROM {feature}
  207. WHERE organism_id = :organism_id
  208. ORDER BY feature_id
  209. ";
  210. $results = chado_query($sql, array(':organism_id' => $organism_id));
  211. // load into ids array
  212. $count = 0;
  213. $ids = array();
  214. foreach ($results as $id) {
  215. $ids[$count] = $id->feature_id;
  216. $count++;
  217. }
  218. // make sure our vocabularies are set before proceeding
  219. tripal_feature_set_vocabulary();
  220. // use this SQL for getting the nodes
  221. $nsql = "SELECT * FROM {chado_feature} CF " .
  222. " INNER JOIN {node} N ON N.nid = CF.nid " .
  223. "WHERE feature_id = :feature_id";
  224. // iterate through the features and set the taxonomy
  225. $interval = intval($count * 0.01);
  226. foreach ($ids as $feature_id) {
  227. // update the job status every 1% features
  228. if ($job_id and $i % $interval == 0) {
  229. tripal_job_set_progress($job_id, intval(($i/$count)*100));
  230. }
  231. $node = db_query($nsql, array(':feature_id' => $feature_id))->fetchObject();
  232. tripal_feature_set_taxonomy($node, $feature_id);
  233. $i++;
  234. }
  235. }