AbstractImportCsv.php 2.7 KB

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