AbstractImportCsv.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Super class of CSV import plugins for phpMyAdmin
  5. *
  6. * @package PhpMyAdmin-Import
  7. * @subpackage CSV
  8. */
  9. namespace PhpMyAdmin\Plugins\Import;
  10. use PhpMyAdmin\Properties\Options\Items\BoolPropertyItem;
  11. use PhpMyAdmin\Properties\Plugins\ImportPluginProperties;
  12. use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup;
  13. use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup;
  14. use PhpMyAdmin\Plugins\ImportPlugin;
  15. use PhpMyAdmin\Properties\Options\Items\TextPropertyItem;
  16. /**
  17. * Super class of the import plugins for the CSV format
  18. *
  19. * @package PhpMyAdmin-Import
  20. * @subpackage CSV
  21. */
  22. abstract class AbstractImportCsv extends ImportPlugin
  23. {
  24. /**
  25. * Sets the import plugin properties.
  26. * Called in the constructor.
  27. *
  28. * @return \PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup object of the plugin
  29. */
  30. protected function setProperties()
  31. {
  32. $importPluginProperties = new ImportPluginProperties();
  33. $importPluginProperties->setOptionsText(__('Options'));
  34. // create the root group that will be the options field for
  35. // $importPluginProperties
  36. // this will be shown as "Format specific options"
  37. $importSpecificOptions = new OptionsPropertyRootGroup(
  38. "Format Specific Options"
  39. );
  40. // general options main group
  41. $generalOptions = new OptionsPropertyMainGroup("general_opts");
  42. // create common items and add them to the group
  43. $leaf = new BoolPropertyItem(
  44. "replace",
  45. __(
  46. 'Update data when duplicate keys found on import (add ON DUPLICATE '
  47. . 'KEY UPDATE)'
  48. )
  49. );
  50. $generalOptions->addProperty($leaf);
  51. $leaf = new TextPropertyItem(
  52. "terminated",
  53. __('Columns separated with:')
  54. );
  55. $leaf->setSize(2);
  56. $generalOptions->addProperty($leaf);
  57. $leaf = new TextPropertyItem(
  58. "enclosed",
  59. __('Columns enclosed with:')
  60. );
  61. $leaf->setSize(2);
  62. $leaf->setLen(2);
  63. $generalOptions->addProperty($leaf);
  64. $leaf = new TextPropertyItem(
  65. "escaped",
  66. __('Columns escaped with:')
  67. );
  68. $leaf->setSize(2);
  69. $leaf->setLen(2);
  70. $generalOptions->addProperty($leaf);
  71. $leaf = new TextPropertyItem(
  72. "new_line",
  73. __('Lines terminated with:')
  74. );
  75. $leaf->setSize(2);
  76. $generalOptions->addProperty($leaf);
  77. // add the main group to the root group
  78. $importSpecificOptions->addProperty($generalOptions);
  79. // set the options for the import plugin property item
  80. $importPluginProperties->setOptions($importSpecificOptions);
  81. $this->properties = $importPluginProperties;
  82. return $generalOptions;
  83. }
  84. }