tripal_pub.admin.inc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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_cleanup_set($form);
  20. }
  21. else {
  22. $form['notice'] = array(
  23. '#type' => 'fieldset',
  24. '#title' => t('Publication Management Temporarily Unavailable')
  25. );
  26. $form['notice']['message'] = array(
  27. '#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.'),
  28. );
  29. }
  30. return system_settings_form($form);
  31. }
  32. /**
  33. *
  34. *
  35. * @ingroup tripal_pub
  36. */
  37. function get_tripal_pub_admin_form_cleanup_set(&$form) {
  38. $form['cleanup'] = array(
  39. '#type' => 'fieldset',
  40. '#title' => t('Clean Up')
  41. );
  42. $form['cleanup']['description'] = array(
  43. '#type' => 'item',
  44. '#value' => t("With Drupal and chado residing in different databases ".
  45. "it is possible that nodes in Drupal and publications in Chado become ".
  46. "\"orphaned\". This can occur if an pub node in Drupal is ".
  47. "deleted but the corresponding chado pub is not and/or vice ".
  48. "versa. Click the button below to resolve these discrepancies."),
  49. '#weight' => 1,
  50. );
  51. $form['cleanup']['button'] = array(
  52. '#type' => 'submit',
  53. '#value' => t('Clean up orphaned publications'),
  54. '#weight' => 2,
  55. );
  56. }
  57. /**
  58. *
  59. *
  60. * @ingroup tripal_pub
  61. */
  62. function get_tripal_pub_admin_form_select_search_list(&$form) {
  63. $form['searching'] = array(
  64. '#type' => 'fieldset',
  65. '#title' => t('Searching Options')
  66. );
  67. // get publication properties list
  68. $properties = array();
  69. $properties[] = 'Any Field';
  70. $sql = "
  71. SELECT DISTINCT CVTS.cvterm_id, CVTS.name, CVTS.definition
  72. FROM {cvtermpath} CVTP
  73. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  74. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  75. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  76. WHERE CV.name = 'tripal_pub' and
  77. (CVTO.name = 'Publication Details' or CVTS.name = 'Publication Type') and
  78. NOT CVTS.is_obsolete = 1
  79. ORDER BY CVTS.name ASC
  80. ";
  81. $prop_types = chado_query($sql);
  82. while ($prop = db_fetch_object($prop_types)) {
  83. $properties[$prop->cvterm_id] = $prop->name;
  84. }
  85. $form['searching']['allowed_search_fields'] = array(
  86. '#type' => 'checkboxes',
  87. '#options' => $properties,
  88. '#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."),
  89. '#prefix' => '<div style="scroll: auto; border:1px solid #CCCCCC;">',
  90. '#suffix' => '</div>',
  91. '#default_value' => variable_get('tripal_pub_allowed_search_fields', array()),
  92. );
  93. }
  94. /**
  95. *
  96. * @ingroup tripal_pub
  97. */
  98. function tripal_pub_admin_validate($form, &$form_state) {
  99. global $user; // we need access to the user info
  100. $job_args = array();
  101. // set the allowed search fields
  102. $allowed_fields = $form_state['values']['allowed_search_fields'];
  103. foreach ($allowed_fields as $cvterm_id => $selected) {
  104. if (!$selected) {
  105. unset($allowed_fields[$cvterm_id]);
  106. }
  107. }
  108. variable_set('tripal_pub_allowed_search_fields', $allowed_fields);
  109. // -------------------------------------
  110. // Submit the Cleanup Job if selected
  111. if ($form_state['values']['op'] == t('Clean up orphaned publications')) {
  112. tripal_add_job('Cleanup orphaned publications', 'tripal_pub',
  113. 'tripal_pub_cleanup', $job_args, $user->uid);
  114. }
  115. }
  116. /**
  117. * Remove orphaned drupal nodes
  118. *
  119. * @param $dummy
  120. * Not Used -kept for backwards compatibility
  121. * @param $job_id
  122. * The id of the tripal job executing this function
  123. *
  124. * @ingroup tripal_pub
  125. */
  126. function tripal_pub_cleanup($dummy = NULL, $job_id = NULL) {
  127. return tripal_core_clean_orphaned_nodes('pub', $job_id);
  128. }
  129. /**
  130. *
  131. */
  132. function tripal_pub_set_pub_url($node, $pub_id) {
  133. $node_url = "node/$node->nid";
  134. $url_alias = "pub/$pub_id";
  135. // remove any previous alias
  136. db_query("DELETE FROM {url_alias} WHERE src = '%s'", $node_url);
  137. // add the new alias
  138. path_set_alias($node_url, $url_alias);
  139. return $url_alias;
  140. }