MainForm.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /**********************************************************************
  3. * ProxmoxVPS developed. (26.03.19)
  4. * *
  5. *
  6. * CREATED BY MODULESGARDEN -> http://modulesgarden.com
  7. * CONTACT -> contact@modulesgarden.com
  8. *
  9. *
  10. * This software is furnished under a license and may be used and copied
  11. * only in accordance with the terms of such license and with the
  12. * inclusion of the above copyright notice. This software or any other
  13. * copies thereof may not be provided or otherwise made available to any
  14. * other person. No title to and ownership of the software is hereby
  15. * transferred.
  16. *
  17. *
  18. **********************************************************************/
  19. namespace ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Admin\Product\Forms;
  20. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Admin\Product\Buttons\VirtualizationChangButton;
  21. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Admin\Product\Providers\ProductProvider;
  22. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Admin\Product\Sections\AdminNotificationSection;
  23. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Admin\Product\Sections\BackupSection;
  24. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Admin\Product\Sections\ClientNotificationSection;
  25. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Admin\Product\Sections\ConsoleSection;
  26. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Admin\Product\Sections\CpuPrioritySection;
  27. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Admin\Product\Sections\FirewallOptionSection;
  28. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Admin\Product\Sections\FirewallSection;
  29. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Admin\Product\Sections\HighAvailabilityClusterSection;
  30. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Admin\Product\Sections\LoadBalancerSection;
  31. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Admin\Product\Sections\Lxc;
  32. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Admin\Product\Sections\MainSection;
  33. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Admin\Product\Sections\MiscellaneousSection;
  34. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Admin\Product\Sections\Qemu;
  35. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Admin\Product\Sections\UserSection;
  36. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\AdminArea;
  37. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\MainContainer;
  38. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\Fields\Switcher;
  39. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\FormIntegration;
  40. class MainForm extends FormIntegration implements AdminArea
  41. {
  42. public function initContent()
  43. {
  44. /**
  45. *
  46. */
  47. $this->initIds('mainForm');
  48. $this->setProvider(new ProductProvider($this->getRequestValue('id')));
  49. $this->addSection(new VirtualizationChangButton());
  50. $this->dataProvider->initData();
  51. /**
  52. *
  53. */
  54. $isQemu = !$this->dataProvider->getValueById('customconfigoption[virtualization]') || $this->dataProvider->getValueById('customconfigoption[virtualization]') == "qemu";
  55. /**
  56. * Main Section
  57. */
  58. $section = new MainSection();
  59. $section->setMainContainer($this->mainContainer);
  60. $this->addSection($section);
  61. if ($isQemu)
  62. {
  63. // KVM
  64. $this->addSection((new Qemu\DefaultConfigurationSection())->enableToggler())
  65. ->addSection((new Qemu\ServerSection())->enableToggler())
  66. ->addSection((new Qemu\NetworkSection())->enableToggler())
  67. ->addSection((new Qemu\DiskSection())->enableToggler())
  68. ->addSection((new Qemu\DiskSpeedSection())->enableTogglerAndHide())
  69. ->addSection((new Qemu\AdditonalDisk())->enableToggler())
  70. ->addSection((new Qemu\AdditonalDiskSpeedSection())->enableToggler())
  71. ->addSection((new BackupSection())->enableToggler())
  72. ->addSection((new Qemu\BootSection())->enableTogglerAndHide())
  73. ->addSection((new FirewallSection())->enableTogglerAndHide())
  74. ->addSection((new FirewallOptionSection())->enableTogglerAndHide())
  75. ->addSection((new Qemu\CloudInitSection())->enableTogglerAndHide())
  76. ->addSection((new Qemu\GuestAgentSection())->enableTogglerAndHide())
  77. ->addSection((new UserSection())->enableTogglerAndHide())
  78. ->addSection((new MiscellaneousSection())->enableTogglerAndHide())
  79. ->addSection((new LoadBalancerSection())->enableTogglerAndHide())
  80. ->addSection((new Qemu\ConfigurationSection())->enableTogglerAndHide())
  81. ->addSection((new Qemu\AdvancedSection())->enableTogglerAndHide())
  82. ->addSection((new HighAvailabilityClusterSection())->enableTogglerAndHide())
  83. ->addSection((new ConsoleSection())->enableTogglerAndHide())
  84. ->addSection((new Qemu\ClientAreaSection())->enableToggler())
  85. ->addSection((new Qemu\ConfigurableOptionUnitsSection())->enableToggler());
  86. }
  87. else
  88. {
  89. //LXC
  90. $this->addSection((new Lxc\DefaultConfigurationSection())->enableToggler())
  91. ->addSection((new Lxc\ServerSection())->enableToggler())
  92. ->addSection((new Lxc\MountPointSection())->enableToggler())
  93. ->addSection((new BackupSection())->enableToggler())
  94. ->addSection((new Lxc\NetworkSection())->enableToggler())
  95. ->addSection((new FirewallSection())->enableTogglerAndHide())
  96. ->addSection((new FirewallOptionSection())->enableTogglerAndHide())
  97. ->addSection((new UserSection())->enableTogglerAndHide())
  98. ->addSection((new MiscellaneousSection())->enableTogglerAndHide())
  99. ->addSection((new LoadBalancerSection())->enableTogglerAndHide())
  100. ->addSection((new Lxc\ConfigurationSection())->enableTogglerAndHide())
  101. ->addSection((new HighAvailabilityClusterSection())->enableTogglerAndHide())
  102. ->addSection((new ConsoleSection())->enableTogglerAndHide())
  103. ->addSection((new Lxc\ClientAreaSection())->enableToggler())
  104. ->addSection((new Lxc\ConfigurableOptionUnitsSection())->enableToggler());
  105. }
  106. $this->addSection((new CpuPrioritySection())->enableToggler());
  107. $this->loadDataToForm();
  108. }
  109. public function getSwitcherFields()
  110. {
  111. $this->setMainContainer(new MainContainer());
  112. $this->runInitContentProcess();
  113. $fieldNames = [];
  114. foreach ($this->getSections() as $section)
  115. {
  116. foreach ($section->getSections() as $s)
  117. {
  118. foreach ($s->getFields() as $field)
  119. {
  120. if (!$field instanceof Switcher)
  121. {
  122. continue;
  123. }
  124. $name = str_replace(["customconfigoption[", "]"], ["", ""], $field->getName());
  125. $fieldNames[] = $name;
  126. }
  127. }
  128. }
  129. return array_unique($fieldNames);
  130. }
  131. }