tripal_views_integration_port.inc

  1. 2.x tripal_views/includes/tripal_views_integration_port.inc
  2. 1.x tripal_views/includes/tripal_views_integration_port.inc

This file contains the UI to import/export tripal views integration setups between sites

File

tripal_views/includes/tripal_views_integration_port.inc
View source
  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_views
  19. */
  20. function tripal_views_integration_export_form($form, &$form_state, $setup_id) {
  21. $form = array();
  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'] = array(
  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_views
  42. */
  43. function tripal_views_integration_import_form() {
  44. $form = array();
  45. $form['name'] = array(
  46. '#type' => 'textfield',
  47. '#title' => 'Name (optional)',
  48. '#description' => t('A human-readable name for your integration.')
  49. );
  50. $priorities = array();
  51. foreach (range(-10, 10) as $v) {
  52. $priorities[$v] = (string) $v;
  53. }
  54. $form['views_type']['row_priority'] = array(
  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. .'you definition will be used for that table because -1 is lighter then both 5 and 10.'),
  62. '#options' => $priorities,
  63. '#default_value' => -1,
  64. );
  65. $form['import'] = array(
  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'] = array(
  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_views
  84. */
  85. function tripal_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 = 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", array('%name' => $defn_array['name'])));
  101. }
  102. else {
  103. drupal_set_message(t("Unable to import %name Integration", array('%name' => $defn_array['name'])), 'error');
  104. }
  105. }