tripal_organism.admin.inc 8.1 KB

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