tripal_chado_views_integration_port.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * @file
  4. * This file contains the UI to import/export tripal views integration setups
  5. * between sites
  6. */
  7. /**
  8. * Form: The form to export a particular tripal views integration
  9. *
  10. * No submit is needed since the setup_id is in the path and the export code is
  11. * rendered based on that
  12. *
  13. * @param $form_state
  14. * The state of the form
  15. * @param $setup_id
  16. * The tripal views integration setup id
  17. *
  18. * @ingroup tripal_chado_views
  19. */
  20. function tripal_chado_views_integration_export_form($form, &$form_state, $setup_id) {
  21. $form = [];
  22. $defn_array = tripal_export_views_integration($setup_id);
  23. $t = var_export($defn_array, TRUE);
  24. $t = preg_replace("/\n\s+array/", "array", $t); // move array( to previous line
  25. $t = preg_replace("/true/", "TRUE", $t); // upper case true
  26. $t = preg_replace("/false/", "FALSE", $t); // upper case false
  27. $t = preg_replace("/array\(/", "array (", $t); // put a space between array and paren
  28. $form['export'] = [
  29. '#type' => 'textarea',
  30. '#title' => 'Export',
  31. '#description' => t('Simply copy the provided export into the Import text area on '
  32. . 'another tripal views enabled website to port the integration between websites.'),
  33. '#rows' => 20,
  34. '#value' => $t,
  35. ];
  36. return $form;
  37. }
  38. /**
  39. * Form: Imports a tripal views integration
  40. *
  41. * @ingroup tripal_chado_views
  42. */
  43. function tripal_chado_views_integration_import_form() {
  44. $form = [];
  45. $form['name'] = [
  46. '#type' => 'textfield',
  47. '#title' => 'Name (optional)',
  48. '#description' => t('A human-readable name for your integration.'),
  49. ];
  50. $priorities = [];
  51. foreach (range(-10, 10) as $v) {
  52. $priorities[$v] = (string) $v;
  53. }
  54. $form['views_type']['row_priority'] = [
  55. '#type' => 'select',
  56. '#title' => t('Priority (optional)'),
  57. '#description' => t('The level of priority your Views integration has in relation to the '
  58. . 'default core and module definitions. The views integration definition with the '
  59. . 'lightest priority will be used. For example, if there is a definition created by '
  60. . 'core with a priority of 10 and another by a custom module of 5 and yours is -1 then '
  61. . 'your definition will be used for that table because -1 is lighter than both 5 and 10.'),
  62. '#options' => $priorities,
  63. '#default_value' => -1,
  64. ];
  65. $form['import'] = [
  66. '#type' => 'textarea',
  67. '#title' => 'Import',
  68. '#description' => t('Simply copy the provided export into the text area to port the integration between websites.'),
  69. '#rows' => 20,
  70. ];
  71. $form['submit'] = [
  72. '#type' => 'submit',
  73. '#value' => 'Submit',
  74. ];
  75. return $form;
  76. }
  77. /**
  78. * Submit: Imports a tripal views integration
  79. *
  80. * @param $form
  81. * @param $form_state
  82. *
  83. * @ingroup tripal_chado_views
  84. */
  85. function tripal_chado_views_integration_import_form_submit($form, &$form_state) {
  86. //$defn_array = unserialize($form_state['values']['import']);
  87. // convert the array into a real PHP array
  88. $defn_array = [];
  89. eval("\$defn_array = " . $form_state['values']['import'] . ";");
  90. // Add optional parameters
  91. if ($form_state['values']['name']) {
  92. $defn_array['name'] = $form_state['values']['name'];
  93. }
  94. if ($form_state['values']['row_priority']) {
  95. $defn_array['priority'] = $form_state['values']['row_priority'];
  96. }
  97. // Add the views integration
  98. $success = tripal_add_views_integration($defn_array);
  99. if ($success) {
  100. drupal_set_message(t("Successfully imported %name Integration", ['%name' => $defn_array['name']]));
  101. }
  102. else {
  103. drupal_set_message(t("Unable to import %name Integration", ['%name' => $defn_array['name']]), 'error');
  104. }
  105. }