tripal_stock.admin.inc 9.3 KB

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