SettingProvider.php 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxAddon product developed. (Sep 12, 2018)
  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\ProxmoxAddon\App\UI\Settings\Providers;
  20. use ModulesGarden\ProxmoxAddon as main;
  21. /**
  22. * Description of SettingProvider
  23. *
  24. * @author Pawel Kopec <pawelk@modulesgardne.com>
  25. */
  26. class SettingProvider extends main\Core\UI\Widget\Forms\DataProviders\BaseDataProvider
  27. {
  28. public function read()
  29. {
  30. $this->data = [];
  31. //console proxy
  32. $moduleSettings = new main\App\Repositories\ModuleSettingRepository();
  33. $this->data = $moduleSettings->all();
  34. $this->data['proxmoxVPSMinimumVMID'] = main\Core\Models\Whmcs\Configuration::where("setting", "proxmoxVPSMinimumVMID")->value('value');
  35. $this->data['vmsWeight'] = main\Core\Models\ModuleSettings\Model::where("setting", 'vmsWeight')->value("value");
  36. $this->data['cpuWeight'] = main\Core\Models\ModuleSettings\Model::where("setting", "cpuWeight")->value("value");
  37. $this->data['diskWeight'] = main\Core\Models\ModuleSettings\Model::where("setting", 'diskWeight')->value("value");
  38. $this->data['ramWeight'] = main\Core\Models\ModuleSettings\Model::where("setting", 'ramWeight')->value("value");
  39. $this->data['debug'] = main\Core\Models\ModuleSettings\Model::where("setting", 'debug')->value("value");
  40. }
  41. public function update()
  42. {
  43. if($this->formData['consoleHost'] && !$this->formData['consoleApiKey'] ){
  44. return (new main\Core\UI\ResponseTemplates\HtmlDataJsonResponse())->setMessageAndTranslate('The API Key field cannot be empty')
  45. ->setStatusError()
  46. ->setCallBackFunction($this->callBackFunction);
  47. }
  48. if(main\Core\Models\Whmcs\Configuration::where("setting", "proxmoxVPSMinimumVMID")->count()){
  49. main\Core\Models\Whmcs\Configuration::where("setting", "proxmoxVPSMinimumVMID")
  50. ->update(['value' => $this->formData['proxmoxVPSMinimumVMID']]);
  51. }else{
  52. main\Core\Models\Whmcs\Configuration::where("setting", "proxmoxVPSMinimumVMID")
  53. ->insert(["setting" => "proxmoxVPSMinimumVMID",'value' => $this->formData['proxmoxVPSMinimumVMID']]);
  54. }
  55. $filable = ["vmsWeight", "cpuWeight", "diskWeight", "ramWeight", 'debug'];
  56. foreach ($filable as $key)
  57. {
  58. $entity = main\Core\Models\ModuleSettings\Model::where("setting", $key)->first();
  59. if (!$entity)
  60. {
  61. $entity = new main\Core\Models\ModuleSettings\Model();
  62. }
  63. $entity->fill(['setting'=> $key, "value" => $this->formData[$key]])
  64. ->save();
  65. }
  66. //console proxy
  67. $moduleSettings = new main\App\Repositories\ModuleSettingRepository();
  68. $moduleSettings->fillAndSave($this->formData);
  69. return (new main\Core\UI\ResponseTemplates\HtmlDataJsonResponse())->setMessageAndTranslate('changesHasBeenSaved')
  70. ->setStatusSuccess()
  71. ->setCallBackFunction($this->callBackFunction);
  72. }
  73. }