tripal_pub.admin.inc 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <?php
  2. /**
  3. *
  4. */
  5. function tripal_pub_admin_pub_view() {
  6. $output = '';
  7. // set the breadcrumb
  8. $breadcrumb = array();
  9. $breadcrumb[] = l('Home', '<front>');
  10. $breadcrumb[] = l('Administration', 'admin');
  11. $breadcrumb[] = l('Tripal', 'admin/tripal');
  12. $breadcrumb[] = l('Chado', 'admin/tripal/chado');
  13. $breadcrumb[] = l('Publications', 'admin/tripal/chado/tripal_pub');
  14. drupal_set_breadcrumb($breadcrumb);
  15. // Add the view
  16. $view = views_embed_view('tripal_pub_admin_publications','default');
  17. if (isset($view)) {
  18. $output .= $view;
  19. }
  20. else {
  21. $output .= '<p>The Publications module uses primarily views to provide an '
  22. . 'administrative interface. Currently one or more views needed for this '
  23. . 'administrative interface are disabled. <strong>Click each of the following links to '
  24. . 'enable the pertinent views</strong>:</p>';
  25. $output .= '<ul>';
  26. $output .= '<li>'.l('Publications View', 'admin/tripal/chado/tripal_pub/views/pubs/enable').'</li>';
  27. $output .= '</ul>';
  28. }
  29. return $output;
  30. }
  31. /**
  32. * Administrative settings form
  33. *
  34. * @ingroup tripal_pub
  35. */
  36. function tripal_pub_admin() {
  37. $form = array();
  38. // before proceeding check to see if we have any
  39. // currently processing jobs. If so, we don't want
  40. // to give the opportunity to sync publications
  41. $active_jobs = FALSE;
  42. if (tripal_get_module_active_jobs('tripal_pub')) {
  43. $active_jobs = TRUE;
  44. }
  45. // add the field set for syncing publications
  46. if (!$active_jobs) {
  47. get_tripal_pub_admin_form_select_search_list($form);
  48. get_tripal_pub_admin_form_importing_set($form);
  49. get_tripal_pub_admin_form_default_type($form);
  50. get_tripal_pub_admin_form_cleanup_set($form);
  51. }
  52. else {
  53. $form['notice'] = array(
  54. '#type' => 'fieldset',
  55. '#title' => t('Publication Management Temporarily Unavailable')
  56. );
  57. $form['notice']['message'] = array(
  58. '#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.'),
  59. );
  60. }
  61. return system_settings_form($form);
  62. }
  63. /**
  64. *
  65. * @param $form
  66. */
  67. function get_tripal_pub_admin_form_default_type(&$form) {
  68. // get the list of publication types. In the Tripal publication
  69. // ontologies these are all grouped under the term 'Publication Type'
  70. // we want the default to be 'Journal Article'
  71. $sql = "
  72. SELECT
  73. CVTS.cvterm_id, CVTS.name
  74. FROM {cvtermpath} CVTP
  75. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  76. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  77. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  78. WHERE CV.name = 'tripal_pub' AND CVTO.name = 'Publication Type' AND
  79. NOT CVTS.is_obsolete = 1
  80. ORDER BY CVTS.name ASC
  81. ";
  82. $results = chado_query($sql);
  83. $pub_types = array();
  84. while ($pub_type = $results->fetchObject()) {
  85. $pub_types[$pub_type->cvterm_id] = $pub_type->name;
  86. if (strcmp($pub_type->name,"Journal Article") == 0) {
  87. $d_type_id = $pub_type->cvterm_id;
  88. }
  89. }
  90. // override the default by using the stored variable
  91. $d_type_id = variable_get('tripal_pub_default_type', $d_type_id);
  92. $form['default_type'] = array(
  93. '#type' => 'fieldset',
  94. '#title' => t('Default Publication Type'),
  95. );
  96. $form['default_type']['type_id'] = array(
  97. '#type' => 'select',
  98. '#title' => t('Publication Type'),
  99. '#options' => $pub_types,
  100. '#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
  101. publication repetitively'),
  102. '#default_value' => $d_type_id
  103. );
  104. }
  105. /**
  106. *
  107. *
  108. * @ingroup tripal_pub
  109. */
  110. function get_tripal_pub_admin_form_importing_set(&$form) {
  111. $form['import'] = array(
  112. '#type' => 'fieldset',
  113. '#title' => t('Import Settings')
  114. );
  115. $form['import']['import_duplicate_check'] = array(
  116. '#type' => 'radios',
  117. '#title' => t('Unique Constraint'),
  118. '#options' => array(
  119. 'title_year' => t('Title and Year'),
  120. 'title_year_media' => t('Title, Year, Media name (e.g. Journal Name, etc.)'),
  121. 'title_year_type' => t('Title, Year, Media type (e.g. Journal, Conference Proceedings, etc.'),
  122. ),
  123. '#description' => t('During import, Tripal will attempt to find duplicate publications.
  124. There are several options for how to find a duplicate publication. Choose the
  125. option that best suits your needs.'),
  126. '#default_value' => variable_get('tripal_pub_import_duplicate_check', 'title_year_media'),
  127. );
  128. }
  129. /**
  130. *
  131. *
  132. * @ingroup tripal_pub
  133. */
  134. function get_tripal_pub_admin_form_cleanup_set(&$form) {
  135. $form['cleanup'] = array(
  136. '#type' => 'fieldset',
  137. '#title' => t('Clean Up')
  138. );
  139. $form['cleanup']['description'] = array(
  140. '#type' => 'item',
  141. '#value' => t("With Drupal and chado residing in different databases ".
  142. "it is possible that nodes in Drupal and publications in Chado become ".
  143. "\"orphaned\". This can occur if an pub node in Drupal is ".
  144. "deleted but the corresponding chado pub is not and/or vice ".
  145. "versa. Click the button below to resolve these discrepancies."),
  146. '#weight' => 1,
  147. );
  148. $form['cleanup']['button'] = array(
  149. '#type' => 'submit',
  150. '#value' => t('Clean up orphaned publications'),
  151. '#weight' => 2,
  152. );
  153. }
  154. /**
  155. *
  156. *
  157. * @ingroup tripal_pub
  158. */
  159. function get_tripal_pub_admin_form_select_search_list(&$form) {
  160. $form['searching'] = array(
  161. '#type' => 'fieldset',
  162. '#title' => t('Searching Options')
  163. );
  164. // get publication properties list
  165. $properties = array();
  166. $properties[] = 'Any Field';
  167. $sql = "
  168. SELECT DISTINCT CVTS.cvterm_id, CVTS.name, CVTS.definition
  169. FROM {cvtermpath} CVTP
  170. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  171. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  172. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  173. WHERE CV.name = 'tripal_pub' and
  174. (CVTO.name = 'Publication Details' or CVTS.name = 'Publication Type') and
  175. NOT CVTS.is_obsolete = 1
  176. ORDER BY CVTS.name ASC
  177. ";
  178. $prop_types = chado_query($sql);
  179. while ($prop = $prop_types->fetchObject()) {
  180. $properties[$prop->cvterm_id] = $prop->name;
  181. }
  182. $form['searching']['allowed_search_fields'] = array(
  183. '#type' => 'checkboxes',
  184. '#options' => $properties,
  185. '#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."),
  186. '#prefix' => '<div style="scroll: auto; border:1px solid #CCCCCC;">',
  187. '#suffix' => '</div>',
  188. '#default_value' => variable_get('tripal_pub_allowed_search_fields', array()),
  189. );
  190. }
  191. /**
  192. *
  193. * @ingroup tripal_pub
  194. */
  195. function tripal_pub_admin_validate($form, &$form_state) {
  196. global $user; // we need access to the user info
  197. $job_args = array();
  198. // set the allowed search fields
  199. $allowed_fields = $form_state['values']['allowed_search_fields'];
  200. foreach ($allowed_fields as $cvterm_id => $selected) {
  201. if (!$selected) {
  202. unset($allowed_fields[$cvterm_id]);
  203. }
  204. }
  205. variable_set('tripal_pub_allowed_search_fields', $allowed_fields);
  206. $import_duplicate_check = $form_state['values']['import_duplicate_check'];
  207. variable_set('tripal_pub_import_duplicate_check', $import_duplicate_check);
  208. $default_type = $form_state['values']['type_id'];
  209. variable_set('tripal_pub_default_type', $default_type);
  210. // -------------------------------------
  211. // Submit the Cleanup Job if selected
  212. if ($form_state['values']['op'] == t('Clean up orphaned publications')) {
  213. tripal_add_job('Cleanup orphaned publications', 'tripal_pub',
  214. 'tripal_pub_cleanup', $job_args, $user->uid);
  215. }
  216. }
  217. /**
  218. * Remove orphaned drupal nodes
  219. *
  220. * @param $dummy
  221. * Not Used -kept for backwards compatibility
  222. * @param $job_id
  223. * The id of the tripal job executing this function
  224. *
  225. * @ingroup tripal_pub
  226. */
  227. function tripal_pub_cleanup($dummy = NULL, $job_id = NULL) {
  228. return tripal_core_clean_orphaned_nodes('pub', $job_id);
  229. }
  230. /**
  231. *
  232. */
  233. function tripal_pub_set_pub_url($node, $pub_id) {
  234. $node_url = "node/$node->nid";
  235. $url_alias = "pub/$pub_id";
  236. // remove any previous alias
  237. db_query("DELETE FROM {url_alias} WHERE source = :source", array(':source' => $node_url));
  238. // add the new alias
  239. $path_alias = array("source" => $node_url, "alias" => $url_alias);
  240. path_save($path_alias);
  241. return $url_alias;
  242. }