tripal_pub.admin.inc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * Implementation of tripal_pub_form().
  4. *
  5. * This form takes the following information:A Publication Title,Volume title,Volume,Series Name,
  6. * Issue,Publication Year,Pages where the Article is located, Miniref,Type-Id, if the article is Obsolete,
  7. * Publishing company,Pubplication Place and a Uniquename for the the instance. It then puts the
  8. * infromation into the Chado_project database table based on its 'pub_id'.
  9. *
  10. *
  11. * @return $form
  12. * An array of menu items '$form'
  13. *
  14. */
  15. function tripal_pub_configuration_form() {
  16. $cv_options = tripal_cv_get_cv_options();
  17. //Creating Fieldset for multiple fields in form
  18. $form['node_form'] = array(
  19. '#type' => 'fieldset',
  20. '#title' => t('Create/Edit Publication Settings'),
  21. );
  22. $form['node_form']['tripal_pub_types_cv'] = array(
  23. '#type' => 'select',
  24. '#title' => t('Controlled Vocabularies'),
  25. '#options' => $cv_options,
  26. '#default_value' => variable_get('tripal_pub_types_cv', 0),
  27. '#description' => 'Set the controlled vocabulary to pull publication type options from. Terms in this vocabulary will be available is the Publication Type select box on both the create and edit pages.',
  28. );
  29. $form['pubmed'] = array(
  30. '#type' => 'fieldset',
  31. '#title' => t('Create Nodes via PubMed Search'),
  32. );
  33. $form['pubmed']['description'] = array(
  34. '#type' => 'item',
  35. '#value' => 'Publication nodes are created based on the results of a PubMed publication search using '
  36. .'the keywords entered below. No content is created until the sync is clicked below and the registered tripal job is '
  37. .'run. This script attempts to only load new publications (ones which don\'t already have nodes from a previous search) '
  38. .'by comparing the pub_id thus if a publication is added manually which also appears in the pubmed search it will likely '
  39. .'get added twice.'
  40. );
  41. //define form elements for the node's title and body.
  42. $form['pubmed']['unique_name'] = array(
  43. '#type' => 'textfield',
  44. '#title' => t('Search Keywords'),
  45. '#description' => t('Specific search terms. Must be seperated by a single space.'),
  46. '#required' => FALSE,
  47. '#default_value' => variable_get('unique_name', NULL)
  48. );
  49. //define form elements for the node's title and body.
  50. /**
  51. $form['set']['time_interval'] = array(
  52. '#type' => 'textfield',
  53. '#title' => t('Time Search Interval (Minutes)'),
  54. '#description'=>t(' The “Search Interval” set here determines when a drupal cron job should
  55. schedule a tripal job. As such, in reality the time until publications are sync’d is “Search Interval”
  56. + time remaining until drupal cron is run + time between drupal cron run and next tripal jobs run'),
  57. '#required' => FALSE,
  58. '#default_value' => variable_get('time_interval', NULL)
  59. );
  60. */
  61. $form['pubmed']['sync_info'] = array(
  62. '#type' => 'submit',
  63. '#title' => t('Sync Publications Jobs'),
  64. '#value' => t('Sync'),
  65. );
  66. $form['submit'] = array(
  67. '#type' => 'submit',
  68. '#weight' => 10,
  69. '#value' => t('Save Configuration')
  70. );
  71. return $form;
  72. }
  73. /*
  74. * Pub Configuration-Form
  75. * This form submit uses variable_set to set the vocabularies that are used, as well as the
  76. * unique_name and time interval that was entered by the user. If the user selects the option
  77. * to Sync Publicatin Jobs, the 'tripal_add_job' function is called, and a tripal job
  78. * will be added.
  79. *
  80. * @param $form
  81. * -The submitted form containing the user entered infromation
  82. * @param $form_state
  83. * -Is the state of the form: i.e what button was pressed, what infromation was entered,etc.
  84. * The key is the 'values'
  85. */
  86. function tripal_pub_configuration_form_submit($form, $form_state) {
  87. global $user; //needed to make the current users details available so access of user id is available
  88. if ($form_state['values']['op'] == t('Save Configuration')) {
  89. variable_set('tripal_pub_types_cv', $form_state['values']['tripal_pub_types_cv']);
  90. variable_set('unique_name', $form_state['values']['unique_name'] );
  91. }
  92. //adding a tripal job if the user selects to Sync the Publications
  93. if ($form_state['values']['op'] == t('Sync')) {
  94. variable_set('unique_name', $form_state['values']['unique_name'] );
  95. $job_args = array($form_state['values']['unique_name']);
  96. $job_id = tripal_add_job('Search & Load PubMed Publications', 'tripal_pub', 'tripal_pub_search_load_pubmed_publications', $job_args, $user->uid);
  97. }
  98. }