tripal_pub.admin.inc 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /**
  3. * @file
  4. * Administration of publications
  5. */
  6. /**
  7. * Admin launchpad
  8. *
  9. * @ingroup tripal_legacy_pub
  10. */
  11. function tripal_pub_admin_pub_view() {
  12. $output = '';
  13. // set the breadcrumb
  14. $breadcrumb = [];
  15. $breadcrumb[] = l('Home', '<front>');
  16. $breadcrumb[] = l('Administration', 'admin');
  17. $breadcrumb[] = l('Tripal', 'admin/tripal');
  18. $breadcrumb[] = l('Chado', 'admin/tripal/legacy');
  19. $breadcrumb[] = l('Publications', 'admin/tripal/legacy/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/legacy/tripal_pub/views/pubs/enable') . '</li>';
  33. $output .= '</ul>';
  34. }
  35. return $output;
  36. }
  37. /**
  38. * Administrative settings form
  39. *
  40. * @ingroup tripal_legacy_pub
  41. */
  42. function tripal_pub_admin() {
  43. $form = [];
  44. // If your module is using the Chado Node: Title & Path API to allow custom titles
  45. // for your node type then you need to add the configuration form for this functionality.
  46. $details = [
  47. 'module' => 'tripal_pub',
  48. // the name of the MODULE implementing the content type
  49. 'content_type' => 'chado_pub',
  50. // the name of the content type
  51. // An array of options to use under "Page Titles"
  52. // the key should be the token and the value should be the human-readable option
  53. 'options' => [
  54. '[pub.title]' => 'Publication Title',
  55. // there should always be one options matching the unique constraint.
  56. '[pub.uniquename]' => 'Unique Contraint: Citation of the Publication.',
  57. ],
  58. // the token indicating the unique constraint in the options array
  59. 'unique_option' => '[pub.uniquename]',
  60. ];
  61. // This call adds the configuration form to your current form
  62. // This sub-form handles it's own validation & submit
  63. chado_add_admin_form_set_title($form, $form_state, $details);
  64. // -----------------------------------------
  65. // add the field set for syncing publications
  66. $form['import'] = [
  67. '#type' => 'fieldset',
  68. '#title' => t('Import Settings'),
  69. '#description' => t('During import, Tripal will attempt to find duplicate publications,
  70. and will not try to insert a publication that already exists in the database. It can
  71. find duplicates using the title, year, series name (e.g. Journal Name) and media type
  72. (e.g. Journal Article etc.).
  73. There are several options for how to find a duplicate publication. Choose the
  74. option that best suits your needs.'),
  75. ];
  76. $form['import']['import_duplicate_check'] = [
  77. '#type' => 'radios',
  78. '#title' => t('Unique Constraint'),
  79. '#options' => [
  80. 'title_year' => t('Title and Year'),
  81. 'title_year_media' => t('Title, Year, Media name (e.g. Journal Name, etc.)'),
  82. 'title_year_type' => t('Title, Year, Media type (e.g. Journal, Conference Proceedings, etc.'),
  83. ],
  84. '#default_value' => variable_get('tripal_pub_import_duplicate_check', 'title_year_media'),
  85. ];
  86. // -----------------------------------------
  87. // get the list of publication types. In the Tripal publication
  88. // ontologies these are all grouped under the term 'Publication Type'
  89. // we want the default to be 'Journal Article'
  90. $d_type_id = '';
  91. $sql = "
  92. SELECT
  93. CVTS.cvterm_id, CVTS.name
  94. FROM {cvtermpath} CVTP
  95. INNER JOIN {cvterm} CVTS ON CVTP.subject_id = CVTS.cvterm_id
  96. INNER JOIN {cvterm} CVTO ON CVTP.object_id = CVTO.cvterm_id
  97. INNER JOIN {cv} ON CVTO.cv_id = CV.cv_id
  98. WHERE CV.name = 'tripal_pub' AND CVTO.name = 'Publication Type' AND
  99. NOT CVTS.is_obsolete = 1
  100. ORDER BY CVTS.name ASC
  101. ";
  102. $results = chado_query($sql);
  103. $pub_types = [];
  104. while ($pub_type = $results->fetchObject()) {
  105. $pub_types[$pub_type->cvterm_id] = $pub_type->name;
  106. if (strcmp($pub_type->name, "Journal Article") == 0) {
  107. $d_type_id = $pub_type->cvterm_id;
  108. }
  109. }
  110. // override the default by using the stored variable
  111. $d_type_id = variable_get('tripal_pub_default_type', $d_type_id);
  112. $form['default_type'] = [
  113. '#type' => 'fieldset',
  114. '#title' => t('Default Publication Type'),
  115. ];
  116. $form['default_type']['type_id'] = [
  117. '#type' => 'select',
  118. '#title' => t('Publication Type'),
  119. '#options' => $pub_types,
  120. '#description' => t('Please set a default publication type used for manual entry of a new
  121. publication. This is useful in the event that someone is manually adding the same
  122. publication type repetitively'),
  123. '#default_value' => $d_type_id,
  124. ];
  125. return system_settings_form($form);
  126. }
  127. /**
  128. * Validate the admin settings form
  129. *
  130. * @ingroup tripal_legacy_pub
  131. */
  132. function tripal_pub_admin_validate($form, &$form_state) {
  133. global $user; // we need access to the user info
  134. $job_args = [];
  135. $import_duplicate_check = $form_state['values']['import_duplicate_check'];
  136. variable_set('tripal_pub_import_duplicate_check', $import_duplicate_check);
  137. $default_type = $form_state['values']['type_id'];
  138. variable_set('tripal_pub_default_type', $default_type);
  139. }
  140. /**
  141. * Set the URL for a publication
  142. *
  143. * @param $node
  144. * The publication node from pub_load().
  145. * @param $pub_id
  146. * The chado pub_id of the publication to set the url for
  147. *
  148. * @return
  149. * The url alias set
  150. *
  151. * @ingroup tripal_legacy_pub
  152. */
  153. function tripal_pub_set_pub_url($node, $pub_id) {
  154. $node_url = "node/$node->nid";
  155. $url_alias = "pub/$pub_id";
  156. // remove any previous alias
  157. db_query("DELETE FROM {url_alias} WHERE source = :source", [':source' => $node_url]);
  158. // add the new alias
  159. $path_alias = ["source" => $node_url, "alias" => $url_alias];
  160. path_save($path_alias);
  161. return $url_alias;
  162. }