tripal_stock.admin.inc 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. get_tripal_stock_admin_form_title_set($form);
  17. get_tripal_stock_admin_form_url_set($form);
  18. get_tripal_stock_admin_form_vocabulary_set($form);
  19. get_tripal_stock_admin_form_cleanup_set($form);
  20. return system_settings_form($form);
  21. }
  22. /**
  23. * Implements hook_form_validate(): Validates user input
  24. *
  25. * @param $form
  26. * An array describing the form that was rendered
  27. * @param $form_state
  28. * An array describing the current state of the form including user input
  29. *
  30. * @ingroup tripal_stock
  31. */
  32. function tripal_stock_admin_validate($form, &$form_state) {
  33. global $user; // we need access to the user info
  34. $job_args = array();
  35. variable_set('chado_stock_types_cv', $form_state['values']['stock_types_cv']);
  36. variable_set('chado_stock_prop_types_cv', $form_state['values']['stock_prop_types_cv']);
  37. variable_set('chado_stock_relationship_cv', $form_state['values']['stock_relationship_cv']);
  38. variable_set('chado_stock_url_string', $form_state['values']['chado_stock_url_string']);
  39. switch ($form_state['values']['op']) {
  40. case t('Set Controlled Vacabularies') :
  41. break;
  42. case t('Clean up orphaned stocks') :
  43. tripal_add_job('Cleanup orphaned stocks', 'tripal_stock',
  44. 'tripal_stock_cleanup', $job_args, $user->uid);
  45. break;
  46. case t('Set Stock URLs') :
  47. tripal_add_job('Set Stock URLs', 'tripal_stock',
  48. 'tripal_stock_set_urls', $job_args, $user->uid);
  49. break;
  50. }
  51. }
  52. /**
  53. *
  54. * @param $form
  55. */
  56. function get_tripal_stock_admin_form_title_set(&$form) {
  57. $form['title'] = array(
  58. '#type' => 'fieldset',
  59. '#title' => t('Stock Page Titles'),
  60. '#collapsible' => TRUE,
  61. '#collapsed' => TRUE,
  62. );
  63. $form['title']['desc'] = array(
  64. '#type' => 'markup',
  65. '#value' => t('Each synced stock must have a unique page title, however, stocks
  66. may have the same name if they are of different types or from different
  67. organisms. Therefore, we must be sure that the page titles can uniquely
  68. identify the stock being viewed. Select an option below that will
  69. uniquely identify all stocks on your site.'),
  70. );
  71. $options = array(
  72. 'stock_unique_name' => 'Only stock unique name',
  73. 'stock_name' => 'Only stock name',
  74. 'unique_constraint' => 'Includes stock name, uniquename, type and species',
  75. );
  76. $form['title']['chado_stock_title'] = array(
  77. '#title' => t('Stock Page Titles'),
  78. '#type' => 'radios',
  79. '#description' => t('Choose a title type from the list above that is
  80. guaranteed to be unique for all stocks If in doubt it is safest to choose
  81. the last option as that guarantees uniqueness. Click the
  82. \'Save Configuration\' button at the bottom to save your selection.'),
  83. '#required' => FALSE,
  84. '#options' => $options,
  85. '#default_value' => variable_get('chado_stock_title', 'unique_constraint'),
  86. );
  87. }
  88. /**
  89. *
  90. * @param $form
  91. */
  92. function get_tripal_stock_admin_form_url_set(&$form) {
  93. $form['url'] = array(
  94. '#type' => 'fieldset',
  95. '#title' => t('Stock URL Path'),
  96. '#collapsible' => TRUE,
  97. '#collapsed' => TRUE,
  98. );
  99. $options = array(
  100. 'SID[id]' => '[id]:' . t('The Chado stock_id'),
  101. 'stock' => 'stock:' . t('Chado table name'),
  102. '[genus]' => '[genus]:' . t('Genus to which the stock belongs'),
  103. '[species]' => '[species]:' . t('Species to which the stock belongs'),
  104. '[type]' => '[type]:' . t('The type of stock'),
  105. '[uniquename]' => '[uniquename]:' . t('The stock unique name'),
  106. '[name]' => '[name]:' . t('The stock name'),
  107. 'reset' => t('Reset'),
  108. );
  109. $form['url']['chado_stock_url_string'] = array(
  110. '#title' => 'URL Syntax',
  111. '#type' => 'textfield',
  112. '#description' => t('You may rearrange elements in this text box to
  113. customize the URLs. The available tags include: [id],
  114. [uniquename]. [name], [species], [genus], [type]. You can separate or
  115. include any text between the tags. Click the "Set Stock URLs" button to
  116. reset the URLs for all stock pages. Click the "Save Configuration" button to
  117. simply save this setup. <b>Important</b>: be sure that whatever you choose will always be unique even considering
  118. future data that may be added. If you include the Chado table name, genus, species, type
  119. and uniquename you are guaranteed to have a unique URL. For example stock/[genus]/[species]/[type]/[uniquename]'),
  120. '#size' => 150,
  121. '#default_value' => variable_get('chado_stock_url_string', '/stock/[genus]/[species]/[type]/[uniquename]'),
  122. );
  123. $form['url']['chado_stock_url'] = array(
  124. '#title' => t('URL components'),
  125. '#type' => 'checkboxes',
  126. '#required' => FALSE,
  127. '#options' => $options,
  128. '#description' => t('Click the item above to make it appear in the URL Syntax box'),
  129. '#attributes' => array(
  130. 'onclick' => '
  131. box = $(\'#edit-chado-stock-url-string\');
  132. if (this.value == \'reset\') {
  133. box.val(\'\');
  134. }
  135. else {
  136. box.val(box.val() + "/" + this.value);
  137. }
  138. this.checked = false;
  139. ',
  140. ),
  141. );
  142. $form['url']['button'] = array(
  143. '#type' => 'submit',
  144. '#value' => t('Set Stock URLs'),
  145. );
  146. }
  147. /**
  148. *
  149. * @param $form
  150. */
  151. function get_tripal_stock_admin_form_vocabulary_set(&$form) {
  152. $form['set_cv'] = array(
  153. '#type' => 'fieldset',
  154. '#title' => t('Set Stock Controlled Vocabularies'),
  155. '#collapsible' => TRUE,
  156. '#collapsed' => TRUE,
  157. );
  158. $form['set_cv']['message'] = array(
  159. '#value' => t("This setting allows you to set which chado controlled vocabularies (cv)"
  160. ." are used. Cvs are used to control user input for the type of stock,"
  161. ." any properties they enter for a stock & the types of relationships"
  162. ." between stocks. Only cvs already loaded into chado can be selected here.")
  163. );
  164. // get the list of CVs for the next form element
  165. $sql = "SELECT * FROM {cv} ORDER BY name";
  166. $results = chado_query($sql);
  167. $cv_options = array();
  168. while ($r = db_fetch_object($results)) {
  169. $cv_options[$r->cv_id] = $r->name;
  170. }
  171. $form['set_cv']['stock_types_cv'] = array(
  172. '#type' => 'select',
  173. '#title' => t('Controlled Vocabulary governing Stock Types'),
  174. '#options' => $cv_options,
  175. '#default_value' => variable_get('chado_stock_types_cv', 0)
  176. );
  177. $form['set_cv']['stock_prop_types_cv'] = array(
  178. '#type' => 'select',
  179. '#title' => t('Controlled Vocabulary governing Types of Stock Properties'),
  180. '#description' => t("This cv must contain a cvterm entry where name='synonym'."),
  181. '#options' => $cv_options,
  182. '#default_value' => variable_get('chado_stock_prop_types_cv', 0)
  183. );
  184. $form['set_cv']['stock_relationship_cv'] = array(
  185. '#type' => 'select',
  186. '#title' => t('Controlled Vocabulary governing Types of Relationsips between Stocks'),
  187. '#options' => $cv_options,
  188. '#default_value' => variable_get('chado_stock_relationship_cv', 0)
  189. );
  190. $form['set_cv']['button'] = array(
  191. '#type' => 'submit',
  192. '#value' => t('Set Controlled Vacabularies')
  193. );
  194. }
  195. /**
  196. *
  197. *
  198. * @ingroup tripal_stock
  199. */
  200. function get_tripal_stock_admin_form_cleanup_set(&$form) {
  201. $form['cleanup'] = array(
  202. '#type' => 'fieldset',
  203. '#title' => t('Clean Up'),
  204. '#collapsible' => TRUE,
  205. '#collapsed' => TRUE,
  206. );
  207. $form['cleanup']['description'] = array(
  208. '#type' => 'item',
  209. '#value' => t("With Drupal and Chado residing in different databases ".
  210. "it is possible that nodes in Drupal and stocks in Chado become ".
  211. "\"orphaned\". This can occur if an stock node in Drupal is ".
  212. "deleted but the corresponding chado stock is not and/or vice ".
  213. "versa. Click the button below to resolve these discrepancies."),
  214. '#weight' => 1,
  215. );
  216. $form['cleanup']['button'] = array(
  217. '#type' => 'submit',
  218. '#value' => t('Clean up orphaned stocks'),
  219. '#weight' => 2,
  220. );
  221. }
  222. /**
  223. * Remove orphaned drupal nodes
  224. *
  225. * @param $dummy
  226. * Not Used -kept for backwards compatibility
  227. * @param $job_id
  228. * The id of the tripal job executing this function
  229. *
  230. * @ingroup tripal_stock
  231. */
  232. function tripal_stock_cleanup($dummy = NULL, $job_id = NULL) {
  233. return tripal_core_clean_orphaned_nodes('stock', $job_id);
  234. }