tripal_chado.publish.inc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. function tripal_chado_publish_form($form, &$form_state) {
  3. $term_id = '';
  4. if (array_key_exists('values', $form_state)) {
  5. $term_id = $form_state['values']['term_id'];
  6. }
  7. $bundles = db_select('tripal_bundle', 'tb')
  8. ->fields('tb')
  9. ->orderBy('label', 'ASC')
  10. ->execute();
  11. $term_ids = array();
  12. $term_ids[] = 'Select a Content Type';
  13. while ($bundle = $bundles->fetchObject()) {
  14. $term_ids[$bundle->term_id] = $bundle->label;
  15. }
  16. $form['term_id'] = array(
  17. '#type' => 'select',
  18. '#title' => 'Content Type',
  19. '#description' => t('Select a content type to publish. Only data that
  20. is mapped to the selected vocabulary term will be published.'),
  21. '#options' => $term_ids,
  22. '#default_value' => $term_id,
  23. '#ajax' => array(
  24. 'callback' => "tripal_chado_publish_form_ajax_callback",
  25. 'wrapper' => "tripal-chado-publish-form",
  26. 'effect' => 'fade',
  27. 'method' => 'replace'
  28. ),
  29. );
  30. // If the user has selected a content type, then we need to
  31. // show some filters.
  32. if ($term_id) {
  33. $form['filters'] = array(
  34. '#type' => 'fieldset',
  35. '#title' => 'Filters',
  36. '#description' => t('Please provide any filters for limiting
  37. the records. Only those that match the filters specified
  38. below will be published. To publish all records of this
  39. type, leave all filters blank.'),
  40. '#collapsed' => TRUE,
  41. '#collapsible' => TRUE,
  42. );
  43. $form['publish_btn'] = array(
  44. '#type' => 'submit',
  45. '#name' => 'publish_btn',
  46. '#value' => 'Publish',
  47. );
  48. }
  49. $form['#prefix'] = '<div id="tripal-chado-publish-form">';
  50. $form['#suffix'] = '</div>';
  51. return $form;
  52. }
  53. /**
  54. *
  55. * @param unknown $form
  56. * @param unknown $form_state
  57. */
  58. function tripal_chado_publish_form_validate($form, &$form_state) {
  59. }
  60. /**
  61. *
  62. * @param unknown $form
  63. * @param unknown $form_state
  64. * @return The
  65. */
  66. function tripal_chado_publish_form_submit($form, &$form_state) {
  67. if ($form_state['clicked_button']['#name'] == 'publish_btn') {
  68. global $user;
  69. $term_id = $form_state['values']['term_id'];
  70. $bundle_name = 'bio_data_' . $term_id;
  71. $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
  72. $args = array(
  73. array('bundle_name' => $bundle_name),
  74. );
  75. $includes = array(
  76. module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.publish'),
  77. );
  78. return tripal_add_job("Publish " . $bundle->label . " records.",
  79. 'tripal_chado', 'tripal_chado_publish_records', $args,
  80. $user->uid, 10, $includes);
  81. }
  82. }
  83. /**
  84. *
  85. */
  86. function tripal_chado_publish_form_ajax_callback($form, $form_state) {
  87. return $form;
  88. }