tripal_pub.admin.inc 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. /**
  3. * Administrative settings form
  4. *
  5. * @ingroup tripal_pub
  6. */
  7. function tripal_pub_admin() {
  8. $form = array();
  9. // before proceeding check to see if we have any
  10. // currently processing jobs. If so, we don't want
  11. // to give the opportunity to sync publications
  12. $active_jobs = FALSE;
  13. if (tripal_get_module_active_jobs('tripal_pub')) {
  14. $active_jobs = TRUE;
  15. }
  16. // add the field set for syncing publications
  17. if (!$active_jobs) {
  18. get_tripal_pub_admin_form_select_search_list($form);
  19. get_tripal_pub_admin_form_importing_set($form);
  20. get_tripal_pub_admin_form_cleanup_set($form);
  21. }
  22. else {
  23. $form['notice'] = array(
  24. '#type' => 'fieldset',
  25. '#title' => t('Publication Management Temporarily Unavailable')
  26. );
  27. $form['notice']['message'] = array(
  28. '#value' => t('Currently, publication management jobs are waiting or are running. . Managemment features have been hidden until these jobs complete. Please check back later once these jobs have finished. You can view the status of pending jobs in the Tripal jobs page.'),
  29. );
  30. }
  31. return system_settings_form($form);
  32. }
  33. /**
  34. *
  35. *
  36. * @ingroup tripal_pub
  37. */
  38. function get_tripal_pub_admin_form_importing_set(&$form) {
  39. $form['import'] = array(
  40. '#type' => 'fieldset',
  41. '#title' => t('Import Settings')
  42. );
  43. $form['import']['import_duplicate_check'] = array(
  44. '#type' => 'radios',
  45. '#title' => t('Unique Constraint'),
  46. '#options' => array(
  47. 'title_year' => t('Title and Year'),
  48. 'title_year_media' => t('Title, Year, Media name (e.g. Journal Name, etc.)'),
  49. 'title_year_type' => t('Title, Year, Media type (e.g. Journal, Conference Proceedings, etc.'),
  50. ),
  51. '#description' => t('During import, Tripal will attempt to find duplicate publications.
  52. There are several options for how to find a duplicate publication. Choose the
  53. option that best suits your needs.'),
  54. '#default_value' => variable_get('tripal_pub_import_duplicate_check', 'title_year_media'),
  55. );
  56. }
  57. /**
  58. *
  59. *
  60. * @ingroup tripal_pub
  61. */
  62. function get_tripal_pub_admin_form_cleanup_set(&$form) {
  63. $form['cleanup'] = array(
  64. '#type' => 'fieldset',
  65. '#title' => t('Clean Up')
  66. );
  67. $form['cleanup']['description'] = array(
  68. '#type' => 'item',
  69. '#value' => t("With Drupal and chado residing in different databases ".
  70. "it is possible that nodes in Drupal and publications in Chado become ".
  71. "\"orphaned\". This can occur if an pub node in Drupal is ".
  72. "deleted but the corresponding chado pub is not and/or vice ".
  73. "versa. Click the button below to resolve these discrepancies."),
  74. '#weight' => 1,
  75. );
  76. $form['cleanup']['button'] = array(
  77. '#type' => 'submit',
  78. '#value' => t('Clean up orphaned publications'),
  79. '#weight' => 2,
  80. );
  81. }
  82. /**
  83. *
  84. *
  85. * @ingroup tripal_pub
  86. */
  87. function get_tripal_pub_admin_form_select_search_list(&$form) {
  88. $form['searching'] = array(
  89. '#type' => 'fieldset',
  90. '#title' => t('Searching Options')
  91. );
  92. // get publication properties list
  93. $properties = array();
  94. $properties[] = 'Any Field';
  95. $sql = "
  96. SELECT DISTINCT CVTS.cvterm_id, CVTS.name, CVTS.definition
  97. FROM {cvtermpath} CVTP
  98. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  99. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  100. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  101. WHERE CV.name = 'tripal_pub' and
  102. (CVTO.name = 'Publication Details' or CVTS.name = 'Publication Type') and
  103. NOT CVTS.is_obsolete = 1
  104. ORDER BY CVTS.name ASC
  105. ";
  106. $prop_types = chado_query($sql);
  107. while ($prop = db_fetch_object($prop_types)) {
  108. $properties[$prop->cvterm_id] = $prop->name;
  109. }
  110. $form['searching']['allowed_search_fields'] = array(
  111. '#type' => 'checkboxes',
  112. '#options' => $properties,
  113. '#description' => t("Please select the publication details that users can search by in the publication search form. If none are selected then all fields will be available to the user."),
  114. '#prefix' => '<div style="scroll: auto; border:1px solid #CCCCCC;">',
  115. '#suffix' => '</div>',
  116. '#default_value' => variable_get('tripal_pub_allowed_search_fields', array()),
  117. );
  118. }
  119. /**
  120. *
  121. * @ingroup tripal_pub
  122. */
  123. function tripal_pub_admin_validate($form, &$form_state) {
  124. global $user; // we need access to the user info
  125. $job_args = array();
  126. // set the allowed search fields
  127. $allowed_fields = $form_state['values']['allowed_search_fields'];
  128. foreach ($allowed_fields as $cvterm_id => $selected) {
  129. if (!$selected) {
  130. unset($allowed_fields[$cvterm_id]);
  131. }
  132. }
  133. variable_set('tripal_pub_allowed_search_fields', $allowed_fields);
  134. $import_duplicate_check = $form_state['values']['import_duplicate_check'];
  135. variable_set('tripal_pub_import_duplicate_check', $import_duplicate_check);
  136. // -------------------------------------
  137. // Submit the Cleanup Job if selected
  138. if ($form_state['values']['op'] == t('Clean up orphaned publications')) {
  139. tripal_add_job('Cleanup orphaned publications', 'tripal_pub',
  140. 'tripal_pub_cleanup', $job_args, $user->uid);
  141. }
  142. }
  143. /**
  144. * Remove orphaned drupal nodes
  145. *
  146. * @param $dummy
  147. * Not Used -kept for backwards compatibility
  148. * @param $job_id
  149. * The id of the tripal job executing this function
  150. *
  151. * @ingroup tripal_pub
  152. */
  153. function tripal_pub_cleanup($dummy = NULL, $job_id = NULL) {
  154. return tripal_core_clean_orphaned_nodes('pub', $job_id);
  155. }
  156. /**
  157. *
  158. */
  159. function tripal_pub_set_pub_url($node, $pub_id) {
  160. $node_url = "node/$node->nid";
  161. $url_alias = "pub/$pub_id";
  162. // remove any previous alias
  163. db_query("DELETE FROM {url_alias} WHERE src = '%s'", $node_url);
  164. // add the new alias
  165. path_set_alias($node_url, $url_alias);
  166. return $url_alias;
  167. }