AbstractImportCsv.php 2.9 KB

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