tripal_stock.admin.inc 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <?php
  2. /**
  3. * @file
  4. * @todo Add file header description
  5. */
  6. /**
  7. * Purpose: Provide administration options for chado_stocks
  8. *
  9. * @return
  10. * Form array (as described by the drupal form api)
  11. *
  12. * @ingroup tripal_stock
  13. */
  14. function tripal_stock_admin() {
  15. $form = array();
  16. /*
  17. // before proceeding check to see if we have any
  18. // currently processing jobs.
  19. $active_jobs = FALSE;
  20. if (tripal_get_module_active_jobs('tripal_stock')) {
  21. $active_jobs = TRUE;
  22. }
  23. if ($active_jobs) {
  24. $form['notice'] = array(
  25. '#type' => 'fieldset',
  26. '#title' => t('Stock Management Temporarily Unavailable'),
  27. '#collapsible' => FALSE,
  28. '#collapsed' => FALSE,
  29. );
  30. $form['notice']['message'] = array(
  31. '#value' => t("Currently, jobs are waiting or ".
  32. "are running. Managemment features have been hidden until these ".
  33. "jobs complete. Please check back later once these jobs have ".
  34. "finished. You can view the status of pending jobs in the Tripal ".
  35. "jobs page."),
  36. );
  37. return system_settings_form($form);
  38. }
  39. */
  40. get_tripal_stock_admin_form_title_set($form);
  41. get_tripal_stock_admin_form_url_set($form);
  42. get_tripal_stock_admin_form_vocabulary_set($form);
  43. get_tripal_stock_admin_form_cleanup_set($form);
  44. return system_settings_form($form);
  45. }
  46. /**
  47. * Implements hook_form_validate(): Validates user input
  48. *
  49. * @param $form
  50. * An array describing the form that was rendered
  51. * @param $form_state
  52. * An array describing the current state of the form including user input
  53. *
  54. * @ingroup tripal_stock
  55. */
  56. function tripal_stock_admin_validate($form, &$form_state) {
  57. global $user; // we need access to the user info
  58. $job_args = array();
  59. switch ($form_state['values']['op']) {
  60. case t('Set Controlled Vacabularies') :
  61. variable_set('chado_stock_types_cv', $form_state['values']['stock_types_cv']);
  62. variable_set('chado_stock_prop_types_cv', $form_state['values']['stock_prop_types_cv']);
  63. variable_set('chado_stock_relationship_cv', $form_state['values']['stock_relationship_cv']);
  64. break;
  65. case t('Clean up orphaned stocks') :
  66. tripal_add_job('Cleanup orphaned stocks', 'tripal_stock',
  67. 'tripal_stock_cleanup', $job_args, $user->uid);
  68. break;
  69. case t('Set Stock URLs') :
  70. variable_set('chado_stock_url', $form_state['values']['stock_url']);
  71. tripal_add_job('Set Stock URLs', 'tripal_stock',
  72. 'tripal_stock_set_urls', $job_args, $user->uid);
  73. break;
  74. }
  75. }
  76. /**
  77. *
  78. * @param $form
  79. */
  80. function get_tripal_stock_admin_form_title_set(&$form) {
  81. $form['title'] = array(
  82. '#type' => 'fieldset',
  83. '#title' => t('Stock Page Titles'),
  84. '#collapsible' => TRUE,
  85. '#collapsed' => TRUE,
  86. );
  87. $form['title']['desc'] = array(
  88. '#type' => 'markup',
  89. '#value' => t('Each synced stock must have a unique page title, however, stocks
  90. may have the same name if they are of different types or from different
  91. organisms. Therefore, we must be sure that the page titles can uniquely
  92. identify the stock being viewed. Select an option below that will
  93. uniquely identify all stocks on your site.'),
  94. );
  95. $options = array(
  96. 'stock_unique_name' => 'Only stock unique name',
  97. 'stock_name' => 'Only stock name',
  98. 'unique_constraint' => 'Includes stock name, uniquename, type and species',
  99. );
  100. $form['title']['chado_stock_title'] = array(
  101. '#title' => t('Stock Page Titles'),
  102. '#type' => 'radios',
  103. '#description' => t('Choose a title type from the list above that is
  104. guaranteed to be unique for all stocks If in doubt it is safest to choose
  105. the last option as that guarantees uniqueness. Click the
  106. \'Save Configuration\' button at the bottom to save your selection.'),
  107. '#required' => FALSE,
  108. '#options' => $options,
  109. '#default_value' => variable_get('chado_stock_title', 'unique_constraint'),
  110. );
  111. }
  112. /**
  113. *
  114. * @param $form
  115. */
  116. function get_tripal_stock_admin_form_url_set(&$form) {
  117. $form['url'] = array(
  118. '#type' => 'fieldset',
  119. '#title' => t('Stock URL Path'),
  120. '#collapsible' => TRUE,
  121. '#collapsed' => TRUE,
  122. );
  123. $form['url']['desc'] = array(
  124. '#type' => 'markup',
  125. '#value' => t('Each synced stock will have a unique URL which consists of
  126. the site domain followed by a unique identifer: for example
  127. http://my-tripal-site.org/SID1034, where the element just after the final
  128. slash is the unique identifier for the stock.'),
  129. );
  130. $options = array(
  131. 'internal ID' => 'Internal ID (Uses the Chado stock_id. Please set the ID Prefix below)',
  132. 'stock_unique_name' => 'Stock unique name',
  133. 'stock_name' => 'Stock name',
  134. 'genus_species_uqname' => 'Genus + species + unique name (e.g. http://your.site.url/[genus]/[genus]_[species]/[unique name]',
  135. 'genus_species_name' => 'Genus + species + name (e.g. http://your.site.url/[genus]/[genus]_[species]/[name]',
  136. 'genus_species_type_uname' => 'Genus + species + type + unique name (e.g. http://your.site.url/[genus]/[genus]_[species]/[type]/[unique name]',
  137. );
  138. $form['url']['chado_stock_url'] = array(
  139. '#title' => t('Unique Identifier'),
  140. '#type' => 'radios',
  141. '#description' => t('Choose an identifier type from the list above that is
  142. guaranteed to be unique for all stocks. If in doubt it is safest to choose the
  143. internal ID. Click the \'Save Configuration\' button at the bottom to save
  144. your selection Click the \'Set Stock URLs\' button to submit a job to reset
  145. the URLs for all synced stocks.'),
  146. '#required' => FALSE,
  147. '#options' => $options,
  148. '#default_value' => variable_get('chado_stock_url', 'internal ID'),
  149. );
  150. $form['url']['chado_stock_accession_prefix'] = array(
  151. '#title' => t('ID Prefix'),
  152. '#type' => t('textfield'),
  153. '#description' => t("If you choose an Internal ID above you must also enter
  154. an ID prefix. This prefix will be prepended to the internal ID number
  155. (e.g. ID38294). if you chose to use the stock name or unique name then
  156. this prfix is not used"),
  157. '#required' => TRUE,
  158. '#default_value' => variable_get('chado_stock_accession_prefix', 'SID'),
  159. );
  160. $form['url']['button'] = array(
  161. '#type' => 'submit',
  162. '#value' => t('Set Stock URLs'),
  163. );
  164. }
  165. /**
  166. *
  167. * @param $form
  168. */
  169. function get_tripal_stock_admin_form_vocabulary_set(&$form) {
  170. $form['set_cv'] = array(
  171. '#type' => 'fieldset',
  172. '#title' => t('Set Stock Controlled Vocabularies'),
  173. '#collapsible' => TRUE,
  174. '#collapsed' => TRUE,
  175. );
  176. $form['set_cv']['message'] = array(
  177. '#value' => t("This setting allows you to set which chado controlled vocabularies (cv)"
  178. ." are used. Cvs are used to control user input for the type of stock,"
  179. ." any properties they enter for a stock & the types of relationships"
  180. ." between stocks. Only cvs already loaded into chado can be selected here.")
  181. );
  182. // get the list of CVs for the next form element
  183. $sql = "SELECT * FROM {cv} ORDER BY name";
  184. $results = chado_query($sql);
  185. $cv_options = array();
  186. while ($r = db_fetch_object($results)) {
  187. $cv_options[$r->cv_id] = $r->name;
  188. }
  189. $form['set_cv']['stock_types_cv'] = array(
  190. '#type' => 'select',
  191. '#title' => t('Controlled Vocabulary governing Stock Types'),
  192. '#options' => $cv_options,
  193. '#default_value' => variable_get('chado_stock_types_cv', 0)
  194. );
  195. $form['set_cv']['stock_prop_types_cv'] = array(
  196. '#type' => 'select',
  197. '#title' => t('Controlled Vocabulary governing Types of Stock Properties'),
  198. '#description' => t("This cv must contain a cvterm entry where name='synonym'."),
  199. '#options' => $cv_options,
  200. '#default_value' => variable_get('chado_stock_prop_types_cv', 0)
  201. );
  202. $form['set_cv']['stock_relationship_cv'] = array(
  203. '#type' => 'select',
  204. '#title' => t('Controlled Vocabulary governing Types of Relationsips between Stocks'),
  205. '#options' => $cv_options,
  206. '#default_value' => variable_get('chado_stock_relationship_cv', 0)
  207. );
  208. $form['set_cv']['button'] = array(
  209. '#type' => 'submit',
  210. '#value' => t('Set Controlled Vacabularies')
  211. );
  212. }
  213. /**
  214. *
  215. *
  216. * @ingroup tripal_stock
  217. */
  218. function get_tripal_stock_admin_form_cleanup_set(&$form) {
  219. $form['cleanup'] = array(
  220. '#type' => 'fieldset',
  221. '#title' => t('Clean Up'),
  222. '#collapsible' => TRUE,
  223. '#collapsed' => TRUE,
  224. );
  225. $form['cleanup']['description'] = array(
  226. '#type' => 'item',
  227. '#value' => t("With Drupal and Chado residing in different databases ".
  228. "it is possible that nodes in Drupal and stocks in Chado become ".
  229. "\"orphaned\". This can occur if an stock node in Drupal is ".
  230. "deleted but the corresponding chado stock is not and/or vice ".
  231. "versa. Click the button below to resolve these discrepancies."),
  232. '#weight' => 1,
  233. );
  234. $form['cleanup']['button'] = array(
  235. '#type' => 'submit',
  236. '#value' => t('Clean up orphaned stocks'),
  237. '#weight' => 2,
  238. );
  239. }
  240. /**
  241. * Remove orphaned drupal nodes
  242. *
  243. * @param $dummy
  244. * Not Used -kept for backwards compatibility
  245. * @param $job_id
  246. * The id of the tripal job executing this function
  247. *
  248. * @ingroup tripal_stock
  249. */
  250. function tripal_stock_cleanup($dummy = NULL, $job_id = NULL) {
  251. return tripal_core_clean_orphaned_nodes('stock', $job_id);
  252. }