tripal_pub.admin.inc 6.0 KB

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