tripal_pub.admin.inc 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. // -----------------------------------------
  39. // add in the fields for selecting which fields are used when search for pubs
  40. $form['searching'] = array(
  41. '#type' => 'fieldset',
  42. '#title' => t('Searching Options'),
  43. '#description' => t("The list of checkboxes below indicate which fields a user
  44. can search with when using the publication search tool. Check the fields that you want
  45. to allow users to search with. Click the 'Save configuration' button below to save changes."),
  46. );
  47. // get publication properties list
  48. $properties = array();
  49. $properties[] = 'Any Field';
  50. $sql = "
  51. SELECT DISTINCT CVTS.cvterm_id, CVTS.name, CVTS.definition
  52. FROM {cvtermpath} CVTP
  53. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  54. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  55. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  56. WHERE CV.name = 'tripal_pub' and
  57. (CVTO.name = 'Publication Details' or CVTS.name = 'Publication Type') and
  58. NOT CVTS.is_obsolete = 1
  59. ORDER BY CVTS.name ASC
  60. ";
  61. $prop_types = chado_query($sql);
  62. while ($prop = $prop_types->fetchObject()) {
  63. $properties[$prop->cvterm_id] = $prop->name;
  64. }
  65. $form['searching']['allowed_search_fields'] = array(
  66. '#type' => 'checkboxes',
  67. '#options' => $properties,
  68. '#prefix' => '<div style="scroll: auto; border:1px solid #CCCCCC;">',
  69. '#suffix' => '</div>',
  70. '#default_value' => variable_get('tripal_pub_allowed_search_fields', array()),
  71. );
  72. // -----------------------------------------
  73. // add the field set for syncing publications
  74. $form['import'] = array(
  75. '#type' => 'fieldset',
  76. '#title' => t('Import Settings'),
  77. '#description' => t('During import, Tripal will attempt to find duplicate publications,
  78. and will not try to insert a publication that already exists in the database. It can
  79. find duplicates using the title, year, series name (e.g. Journal Name) and media type
  80. (e.g. Journal Article etc.).
  81. There are several options for how to find a duplicate publication. Choose the
  82. option that best suits your needs.'),
  83. );
  84. $form['import']['import_duplicate_check'] = array(
  85. '#type' => 'radios',
  86. '#title' => t('Unique Constraint'),
  87. '#options' => array(
  88. 'title_year' => t('Title and Year'),
  89. 'title_year_media' => t('Title, Year, Media name (e.g. Journal Name, etc.)'),
  90. 'title_year_type' => t('Title, Year, Media type (e.g. Journal, Conference Proceedings, etc.'),
  91. ),
  92. '#default_value' => variable_get('tripal_pub_import_duplicate_check', 'title_year_media'),
  93. );
  94. // -----------------------------------------
  95. // get the list of publication types. In the Tripal publication
  96. // ontologies these are all grouped under the term 'Publication Type'
  97. // we want the default to be 'Journal Article'
  98. $sql = "
  99. SELECT
  100. CVTS.cvterm_id, CVTS.name
  101. FROM {cvtermpath} CVTP
  102. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  103. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  104. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  105. WHERE CV.name = 'tripal_pub' AND CVTO.name = 'Publication Type' AND
  106. NOT CVTS.is_obsolete = 1
  107. ORDER BY CVTS.name ASC
  108. ";
  109. $results = chado_query($sql);
  110. $pub_types = array();
  111. while ($pub_type = $results->fetchObject()) {
  112. $pub_types[$pub_type->cvterm_id] = $pub_type->name;
  113. if (strcmp($pub_type->name,"Journal Article") == 0) {
  114. $d_type_id = $pub_type->cvterm_id;
  115. }
  116. }
  117. // override the default by using the stored variable
  118. $d_type_id = variable_get('tripal_pub_default_type', $d_type_id);
  119. $form['default_type'] = array(
  120. '#type' => 'fieldset',
  121. '#title' => t('Default Publication Type'),
  122. );
  123. $form['default_type']['type_id'] = array(
  124. '#type' => 'select',
  125. '#title' => t('Publication Type'),
  126. '#options' => $pub_types,
  127. '#description' => t('Please set a default publiation type used for manual entry of a new
  128. publication. This is useful in the event that someone is manually adding the same
  129. publication type repetitively'),
  130. '#default_value' => $d_type_id
  131. );
  132. return system_settings_form($form);
  133. }
  134. /**
  135. *
  136. * @ingroup tripal_pub
  137. */
  138. function tripal_pub_admin_validate($form, &$form_state) {
  139. global $user; // we need access to the user info
  140. $job_args = array();
  141. // set the allowed search fields
  142. $allowed_fields = $form_state['values']['allowed_search_fields'];
  143. foreach ($allowed_fields as $cvterm_id => $selected) {
  144. if (!$selected) {
  145. unset($allowed_fields[$cvterm_id]);
  146. }
  147. }
  148. variable_set('tripal_pub_allowed_search_fields', $allowed_fields);
  149. $import_duplicate_check = $form_state['values']['import_duplicate_check'];
  150. variable_set('tripal_pub_import_duplicate_check', $import_duplicate_check);
  151. $default_type = $form_state['values']['type_id'];
  152. variable_set('tripal_pub_default_type', $default_type);
  153. }
  154. /**
  155. *
  156. */
  157. function tripal_pub_set_pub_url($node, $pub_id) {
  158. $node_url = "node/$node->nid";
  159. $url_alias = "pub/$pub_id";
  160. // remove any previous alias
  161. db_query("DELETE FROM {url_alias} WHERE source = :source", array(':source' => $node_url));
  162. // add the new alias
  163. $path_alias = array("source" => $node_url, "alias" => $url_alias);
  164. path_save($path_alias);
  165. return $url_alias;
  166. }