tripal_pub.admin.inc 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. /**
  3. * @file
  4. * Administration of publications
  5. */
  6. /**
  7. * Admin launchpad
  8. *
  9. * @ingroup tripal_pub
  10. */
  11. function tripal_pub_admin_pub_view() {
  12. $output = '';
  13. // set the breadcrumb
  14. $breadcrumb = array();
  15. $breadcrumb[] = l('Home', '<front>');
  16. $breadcrumb[] = l('Administration', 'admin');
  17. $breadcrumb[] = l('Tripal', 'admin/tripal');
  18. $breadcrumb[] = l('Chado', 'admin/tripal/chado');
  19. $breadcrumb[] = l('Publications', 'admin/tripal/chado/tripal_pub');
  20. drupal_set_breadcrumb($breadcrumb);
  21. // Add the view
  22. $view = views_embed_view('tripal_pub_admin_publications','default');
  23. if (isset($view)) {
  24. $output .= $view;
  25. }
  26. else {
  27. $output .= '<p>The Publications module uses primarily views to provide an '
  28. . 'administrative interface. Currently one or more views needed for this '
  29. . 'administrative interface are disabled. <strong>Click each of the following links to '
  30. . 'enable the pertinent views</strong>:</p>';
  31. $output .= '<ul>';
  32. $output .= '<li>'.l('Publications View', 'admin/tripal/chado/tripal_pub/views/pubs/enable').'</li>';
  33. $output .= '</ul>';
  34. }
  35. return $output;
  36. }
  37. /**
  38. * Administrative settings form
  39. *
  40. * @ingroup tripal_pub
  41. */
  42. function tripal_pub_admin() {
  43. $form = array();
  44. // -----------------------------------------
  45. // add in the fields for selecting which fields are used when search for pubs
  46. $form['searching'] = array(
  47. '#type' => 'fieldset',
  48. '#title' => t('Searching Options'),
  49. '#description' => t("The list of checkboxes below indicate which fields a user
  50. can search with when using the publication search tool. Check the fields that you want
  51. to allow users to search with. Click the 'Save configuration' button below to save changes."),
  52. );
  53. // get publication properties list
  54. $properties = array();
  55. $properties[] = 'Any Field';
  56. $sql = "
  57. SELECT DISTINCT CVTS.cvterm_id, CVTS.name, CVTS.definition
  58. FROM {cvtermpath} CVTP
  59. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  60. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  61. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  62. WHERE CV.name = 'tripal_pub' and
  63. (CVTO.name = 'Publication Details' or CVTS.name = 'Publication Type') and
  64. NOT CVTS.is_obsolete = 1
  65. ORDER BY CVTS.name ASC
  66. ";
  67. $prop_types = chado_query($sql);
  68. while ($prop = $prop_types->fetchObject()) {
  69. $properties[$prop->cvterm_id] = $prop->name;
  70. }
  71. $form['searching']['allowed_search_fields'] = array(
  72. '#type' => 'checkboxes',
  73. '#options' => $properties,
  74. '#prefix' => '<div style="scroll: auto; border:1px solid #CCCCCC;">',
  75. '#suffix' => '</div>',
  76. '#default_value' => variable_get('tripal_pub_allowed_search_fields', array()),
  77. );
  78. // -----------------------------------------
  79. // add the field set for syncing publications
  80. $form['import'] = array(
  81. '#type' => 'fieldset',
  82. '#title' => t('Import Settings'),
  83. '#description' => t('During import, Tripal will attempt to find duplicate publications,
  84. and will not try to insert a publication that already exists in the database. It can
  85. find duplicates using the title, year, series name (e.g. Journal Name) and media type
  86. (e.g. Journal Article etc.).
  87. There are several options for how to find a duplicate publication. Choose the
  88. option that best suits your needs.'),
  89. );
  90. $form['import']['import_duplicate_check'] = array(
  91. '#type' => 'radios',
  92. '#title' => t('Unique Constraint'),
  93. '#options' => array(
  94. 'title_year' => t('Title and Year'),
  95. 'title_year_media' => t('Title, Year, Media name (e.g. Journal Name, etc.)'),
  96. 'title_year_type' => t('Title, Year, Media type (e.g. Journal, Conference Proceedings, etc.'),
  97. ),
  98. '#default_value' => variable_get('tripal_pub_import_duplicate_check', 'title_year_media'),
  99. );
  100. // -----------------------------------------
  101. // get the list of publication types. In the Tripal publication
  102. // ontologies these are all grouped under the term 'Publication Type'
  103. // we want the default to be 'Journal Article'
  104. $sql = "
  105. SELECT
  106. CVTS.cvterm_id, CVTS.name
  107. FROM {cvtermpath} CVTP
  108. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  109. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  110. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  111. WHERE CV.name = 'tripal_pub' AND CVTO.name = 'Publication Type' AND
  112. NOT CVTS.is_obsolete = 1
  113. ORDER BY CVTS.name ASC
  114. ";
  115. $results = chado_query($sql);
  116. $pub_types = array();
  117. while ($pub_type = $results->fetchObject()) {
  118. $pub_types[$pub_type->cvterm_id] = $pub_type->name;
  119. if (strcmp($pub_type->name,"Journal Article") == 0) {
  120. $d_type_id = $pub_type->cvterm_id;
  121. }
  122. }
  123. // override the default by using the stored variable
  124. $d_type_id = variable_get('tripal_pub_default_type', $d_type_id);
  125. $form['default_type'] = array(
  126. '#type' => 'fieldset',
  127. '#title' => t('Default Publication Type'),
  128. );
  129. $form['default_type']['type_id'] = array(
  130. '#type' => 'select',
  131. '#title' => t('Publication Type'),
  132. '#options' => $pub_types,
  133. '#description' => t('Please set a default publiation type used for manual entry of a new
  134. publication. This is useful in the event that someone is manually adding the same
  135. publication type repetitively'),
  136. '#default_value' => $d_type_id
  137. );
  138. return system_settings_form($form);
  139. }
  140. /**
  141. * Validate the admin settings form
  142. *
  143. * @ingroup tripal_pub
  144. */
  145. function tripal_pub_admin_validate($form, &$form_state) {
  146. global $user; // we need access to the user info
  147. $job_args = array();
  148. // set the allowed search fields
  149. $allowed_fields = $form_state['values']['allowed_search_fields'];
  150. foreach ($allowed_fields as $cvterm_id => $selected) {
  151. if (!$selected) {
  152. unset($allowed_fields[$cvterm_id]);
  153. }
  154. }
  155. variable_set('tripal_pub_allowed_search_fields', $allowed_fields);
  156. $import_duplicate_check = $form_state['values']['import_duplicate_check'];
  157. variable_set('tripal_pub_import_duplicate_check', $import_duplicate_check);
  158. $default_type = $form_state['values']['type_id'];
  159. variable_set('tripal_pub_default_type', $default_type);
  160. }
  161. /**
  162. * Set the URL for a publication
  163. *
  164. * @param $node
  165. * The publication node from pub_load().
  166. * @param $pub_id
  167. * The chado pub_id of the publication to set the url for
  168. *
  169. * @return
  170. * The url alias set
  171. *
  172. * @ingroup tripal_pub
  173. */
  174. function tripal_pub_set_pub_url($node, $pub_id) {
  175. $node_url = "node/$node->nid";
  176. $url_alias = "pub/$pub_id";
  177. // remove any previous alias
  178. db_query("DELETE FROM {url_alias} WHERE source = :source", array(':source' => $node_url));
  179. // add the new alias
  180. $path_alias = array("source" => $node_url, "alias" => $url_alias);
  181. path_save($path_alias);
  182. return $url_alias;
  183. }