tripal_pub.admin.inc

  1. 2.x tripal_pub/includes/tripal_pub.admin.inc
  2. 3.x legacy/tripal_pub/includes/tripal_pub.admin.inc
  3. 1.x tripal_pub/includes/tripal_pub.admin.inc

Administration of publications

File

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