SchemaPdf.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * PDF schema export code
  4. */
  5. declare(strict_types=1);
  6. namespace PhpMyAdmin\Plugins\Schema;
  7. use PhpMyAdmin\Plugins\Schema\Pdf\PdfRelationSchema;
  8. use PhpMyAdmin\Plugins\SchemaPlugin;
  9. use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup;
  10. use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup;
  11. use PhpMyAdmin\Properties\Options\Items\BoolPropertyItem;
  12. use PhpMyAdmin\Properties\Options\Items\SelectPropertyItem;
  13. use PhpMyAdmin\Properties\Plugins\SchemaPluginProperties;
  14. /**
  15. * Handles the schema export for the PDF format
  16. */
  17. class SchemaPdf extends SchemaPlugin
  18. {
  19. public function __construct()
  20. {
  21. $this->setProperties();
  22. }
  23. /**
  24. * Sets the schema export PDF properties
  25. *
  26. * @return void
  27. */
  28. protected function setProperties()
  29. {
  30. $schemaPluginProperties = new SchemaPluginProperties();
  31. $schemaPluginProperties->setText('PDF');
  32. $schemaPluginProperties->setExtension('pdf');
  33. $schemaPluginProperties->setMimeType('application/pdf');
  34. // create the root group that will be the options field for
  35. // $schemaPluginProperties
  36. // this will be shown as "Format specific options"
  37. $exportSpecificOptions = new OptionsPropertyRootGroup(
  38. 'Format Specific Options'
  39. );
  40. // specific options main group
  41. $specificOptions = new OptionsPropertyMainGroup('general_opts');
  42. // add options common to all plugins
  43. $this->addCommonOptions($specificOptions);
  44. // create leaf items and add them to the group
  45. $leaf = new BoolPropertyItem(
  46. 'all_tables_same_width',
  47. __('Same width for all tables')
  48. );
  49. $specificOptions->addProperty($leaf);
  50. $leaf = new SelectPropertyItem(
  51. 'orientation',
  52. __('Orientation')
  53. );
  54. $leaf->setValues(
  55. [
  56. 'L' => __('Landscape'),
  57. 'P' => __('Portrait'),
  58. ]
  59. );
  60. $specificOptions->addProperty($leaf);
  61. $leaf = new SelectPropertyItem(
  62. 'paper',
  63. __('Paper size')
  64. );
  65. $leaf->setValues($this->getPaperSizeArray());
  66. $specificOptions->addProperty($leaf);
  67. $leaf = new BoolPropertyItem(
  68. 'show_grid',
  69. __('Show grid')
  70. );
  71. $specificOptions->addProperty($leaf);
  72. $leaf = new BoolPropertyItem(
  73. 'with_doc',
  74. __('Data dictionary')
  75. );
  76. $specificOptions->addProperty($leaf);
  77. $leaf = new SelectPropertyItem(
  78. 'table_order',
  79. __('Order of the tables')
  80. );
  81. $leaf->setValues(
  82. [
  83. '' => __('None'),
  84. 'name_asc' => __('Name (Ascending)'),
  85. 'name_desc' => __('Name (Descending)'),
  86. ]
  87. );
  88. $specificOptions->addProperty($leaf);
  89. // add the main group to the root group
  90. $exportSpecificOptions->addProperty($specificOptions);
  91. // set the options for the schema export plugin property item
  92. $schemaPluginProperties->setOptions($exportSpecificOptions);
  93. $this->properties = $schemaPluginProperties;
  94. }
  95. /**
  96. * Exports the schema into PDF format.
  97. *
  98. * @param string $db database name
  99. *
  100. * @return bool Whether it succeeded
  101. */
  102. public function exportSchema($db)
  103. {
  104. $export = new PdfRelationSchema($db);
  105. $export->showOutput();
  106. return true;
  107. }
  108. }