tripal_chado.publish.inc 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. function tripal_chado_publish_form_validate($form, &$form_state) {
  54. }
  55. function tripal_chado_publish_form_submit($form, &$form_state) {
  56. if ($form_state['clicked_button']['#name'] == 'publish_btn') {
  57. global $user;
  58. $term_id = $form_state['values']['term_id'];
  59. $bundle_name = 'bio_data_' . $term_id;
  60. $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
  61. $args = array(
  62. array('bundle_name' => $bundle_name),
  63. );
  64. $includes = array(
  65. module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.publish'),
  66. );
  67. return tripal_add_job("Publish " . $bundle->label . " records.",
  68. 'tripal_chado', 'tripal_chado_publish_records', $args,
  69. $user->uid, 10, $includes);
  70. }
  71. }
  72. /**
  73. *
  74. */
  75. function tripal_chado_publish_form_ajax_callback($form, $form_state) {
  76. return $form;
  77. }