tripal_pub.admin.inc 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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_default_type($form);
  21. get_tripal_pub_admin_form_cleanup_set($form);
  22. }
  23. else {
  24. $form['notice'] = array(
  25. '#type' => 'fieldset',
  26. '#title' => t('Publication Management Temporarily Unavailable')
  27. );
  28. $form['notice']['message'] = array(
  29. '#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.'),
  30. );
  31. }
  32. return system_settings_form($form);
  33. }
  34. /**
  35. *
  36. * @param $form
  37. */
  38. function get_tripal_pub_admin_form_default_type(&$form) {
  39. // get the list of publication types. In the Tripal publication
  40. // ontologies these are all grouped under the term 'Publication Type'
  41. // we want the default to be 'Journal Article'
  42. $sql = "
  43. SELECT CVTS.cvterm_id, CVTS.name
  44. FROM {cvtermpath} CVTP
  45. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  46. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  47. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  48. WHERE CV.name = 'tripal_pub' and CVTO.name = 'Publication Type' and
  49. NOT CVTS.is_obsolete = 1
  50. ORDER BY CVTS.name ASC
  51. ";
  52. $results = chado_query($sql);
  53. $pub_types = array();
  54. while ($pub_type = db_fetch_object($results)) {
  55. $pub_types[$pub_type->cvterm_id] = $pub_type->name;
  56. if (strcmp($pub_type->name,"Journal Article") == 0) {
  57. $d_type_id = $pub_type->cvterm_id;
  58. }
  59. }
  60. // override the default by using the stored variable
  61. $d_type_id = variable_get('tripal_pub_default_type', $d_type_id);
  62. $form['default_type'] = array(
  63. '#type' => 'fieldset',
  64. '#title' => t('Default Publication Type'),
  65. );
  66. $form['default_type']['type_id'] = array(
  67. '#type' => 'select',
  68. '#title' => t('Publication Type'),
  69. '#options' => $pub_types,
  70. '#description' => t('Please set a default publiation type used for manual entry of a new publication. This is useful in the event that someone is manually adding the same
  71. publication repetitively'),
  72. '#default_value' => $d_type_id
  73. );
  74. }
  75. /**
  76. *
  77. *
  78. * @ingroup tripal_pub
  79. */
  80. function get_tripal_pub_admin_form_importing_set(&$form) {
  81. $form['import'] = array(
  82. '#type' => 'fieldset',
  83. '#title' => t('Import Settings')
  84. );
  85. $form['import']['import_duplicate_check'] = array(
  86. '#type' => 'radios',
  87. '#title' => t('Unique Constraint'),
  88. '#options' => array(
  89. 'title_year' => t('Title and Year'),
  90. 'title_year_media' => t('Title, Year, Media name (e.g. Journal Name, etc.)'),
  91. 'title_year_type' => t('Title, Year, Media type (e.g. Journal, Conference Proceedings, etc.'),
  92. ),
  93. '#description' => t('During import, Tripal will attempt to find duplicate publications.
  94. There are several options for how to find a duplicate publication. Choose the
  95. option that best suits your needs.'),
  96. '#default_value' => variable_get('tripal_pub_import_duplicate_check', 'title_year_media'),
  97. );
  98. }
  99. /**
  100. *
  101. *
  102. * @ingroup tripal_pub
  103. */
  104. function get_tripal_pub_admin_form_cleanup_set(&$form) {
  105. $form['cleanup'] = array(
  106. '#type' => 'fieldset',
  107. '#title' => t('Clean Up')
  108. );
  109. $form['cleanup']['description'] = array(
  110. '#type' => 'item',
  111. '#value' => t("With Drupal and chado residing in different databases ".
  112. "it is possible that nodes in Drupal and publications in Chado become ".
  113. "\"orphaned\". This can occur if an pub node in Drupal is ".
  114. "deleted but the corresponding chado pub is not and/or vice ".
  115. "versa. Click the button below to resolve these discrepancies."),
  116. '#weight' => 1,
  117. );
  118. $form['cleanup']['button'] = array(
  119. '#type' => 'submit',
  120. '#value' => t('Clean up orphaned publications'),
  121. '#weight' => 2,
  122. );
  123. }
  124. /**
  125. *
  126. *
  127. * @ingroup tripal_pub
  128. */
  129. function get_tripal_pub_admin_form_select_search_list(&$form) {
  130. $form['searching'] = array(
  131. '#type' => 'fieldset',
  132. '#title' => t('Searching Options')
  133. );
  134. // get publication properties list
  135. $properties = array();
  136. $properties[] = 'Any Field';
  137. $sql = "
  138. SELECT DISTINCT CVTS.cvterm_id, CVTS.name, CVTS.definition
  139. FROM {cvtermpath} CVTP
  140. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  141. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  142. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  143. WHERE CV.name = 'tripal_pub' and
  144. (CVTO.name = 'Publication Details' or CVTS.name = 'Publication Type') and
  145. NOT CVTS.is_obsolete = 1
  146. ORDER BY CVTS.name ASC
  147. ";
  148. $prop_types = chado_query($sql);
  149. while ($prop = db_fetch_object($prop_types)) {
  150. $properties[$prop->cvterm_id] = $prop->name;
  151. }
  152. $form['searching']['allowed_search_fields'] = array(
  153. '#type' => 'checkboxes',
  154. '#options' => $properties,
  155. '#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."),
  156. '#prefix' => '<div style="scroll: auto; border:1px solid #CCCCCC;">',
  157. '#suffix' => '</div>',
  158. '#default_value' => variable_get('tripal_pub_allowed_search_fields', array()),
  159. );
  160. }
  161. /**
  162. *
  163. * @ingroup tripal_pub
  164. */
  165. function tripal_pub_admin_validate($form, &$form_state) {
  166. global $user; // we need access to the user info
  167. $job_args = array();
  168. // set the allowed search fields
  169. $allowed_fields = $form_state['values']['allowed_search_fields'];
  170. foreach ($allowed_fields as $cvterm_id => $selected) {
  171. if (!$selected) {
  172. unset($allowed_fields[$cvterm_id]);
  173. }
  174. }
  175. variable_set('tripal_pub_allowed_search_fields', $allowed_fields);
  176. $import_duplicate_check = $form_state['values']['import_duplicate_check'];
  177. variable_set('tripal_pub_import_duplicate_check', $import_duplicate_check);
  178. $default_type = $form_state['values']['type_id'];
  179. variable_set('tripal_pub_default_type', $default_type);
  180. // -------------------------------------
  181. // Submit the Cleanup Job if selected
  182. if ($form_state['values']['op'] == t('Clean up orphaned publications')) {
  183. tripal_add_job('Cleanup orphaned publications', 'tripal_pub',
  184. 'tripal_pub_cleanup', $job_args, $user->uid);
  185. }
  186. }
  187. /**
  188. * Remove orphaned drupal nodes
  189. *
  190. * @param $dummy
  191. * Not Used -kept for backwards compatibility
  192. * @param $job_id
  193. * The id of the tripal job executing this function
  194. *
  195. * @ingroup tripal_pub
  196. */
  197. function tripal_pub_cleanup($dummy = NULL, $job_id = NULL) {
  198. return tripal_core_clean_orphaned_nodes('pub', $job_id);
  199. }
  200. /**
  201. *
  202. */
  203. function tripal_pub_set_pub_url($node, $pub_id) {
  204. $node_url = "node/$node->nid";
  205. $url_alias = "pub/$pub_id";
  206. // remove any previous alias
  207. db_query("DELETE FROM {url_alias} WHERE src = '%s'", $node_url);
  208. // add the new alias
  209. path_set_alias($node_url, $url_alias);
  210. return $url_alias;
  211. }