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. * The form to export a particular tripal views integration
  9. */
  10. function tripal_views_integration_export_form($form_state, $setup_id) {
  11. $form = array();
  12. $defn_array = tripal_views_integration_export_entry($setup_id);
  13. $t = var_export($defn_array, TRUE);
  14. $t = preg_replace("/\n\s+array/", "array", $t); // move array( to previous line
  15. $t = preg_replace("/true/", "TRUE", $t); // upper case true
  16. $t = preg_replace("/false/", "FALSE", $t); // upper case false
  17. $t = preg_replace("/array\(/", "array (", $t); // put a space between array and paren
  18. $form['export'] = array(
  19. '#type' => 'textarea',
  20. '#title' => 'Export',
  21. '#description' => t('Simply copy the provided export into the Import text area on '
  22. . 'another tripal views enabled website to port the integration between websites.'),
  23. '#rows' => 20,
  24. '#value' => $t,
  25. );
  26. return $form;
  27. }
  28. /**
  29. * Imports a tripal views integration
  30. */
  31. function tripal_views_integration_import_form() {
  32. $form = array();
  33. $form['name'] = array(
  34. '#type' => 'textfield',
  35. '#title' => 'Name (optional)',
  36. '#description' => t('A human-readable name for your integration.')
  37. );
  38. $priorities = array();
  39. foreach (range(-10, 10) as $v) {
  40. $priorities[$v] = (string) $v;
  41. }
  42. $form['views_type']['row_priority'] = array(
  43. '#type' => 'select',
  44. '#title' => t('Priority (optional)'),
  45. '#description' => t('The level of priority your Views integration has in relation to the '
  46. .'default core and module definitions. The views integration definition with the '
  47. .'lightest priority will be used. For example, if there is a definition created by '
  48. .'core with a priority of 10 and another by a custom module of 5 and yours is -1 then '
  49. .'you definition will be used for that table because -1 is lighter then both 5 and 10.'),
  50. '#options' => $priorities,
  51. '#default_value' => -1,
  52. );
  53. $form['import'] = array(
  54. '#type' => 'textarea',
  55. '#title' => 'Import',
  56. '#description' => t('Simply copy the provided export into the text area to port the integration between websites.'),
  57. '#rows' => 20,
  58. );
  59. $form['submit'] = array(
  60. '#type' => 'submit',
  61. '#value' => 'Submit'
  62. );
  63. return $form;
  64. }
  65. /**
  66. * Imports a tripal views integration
  67. */
  68. function tripal_views_integration_import_form_submit($form, &$form_state) {
  69. //$defn_array = unserialize($form_state['values']['import']);
  70. // convert the array into a real PHP array
  71. $defn_array = array();
  72. eval("\$defn_array = " . $form_state['values']['import'] . ";");
  73. // Add optional parameters
  74. if ($form_state['values']['name']) {
  75. $defn_array['name'] = $form_state['values']['name'];
  76. }
  77. if ($form_state['values']['row_priority']) {
  78. $defn_array['priority'] = $form_state['values']['row_priority'];
  79. }
  80. // Add the views integration
  81. $success = tripal_views_integration_add_entry($defn_array);
  82. if ($success) {
  83. drupal_set_message(t("Successfully imported %name Integration", array('%name' => $defn_array['name'])));
  84. }
  85. else {
  86. drupal_set_message(t("Unable to import %name Integration", array('%name' => $defn_array['name'])), 'error');
  87. }
  88. }