SettingProvider.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. $this->data['proxmoxVPSMinimumVMID'] = main\Core\Models\Whmcs\Configuration::where("setting", "proxmoxVPSMinimumVMID")->value('value');
  32. $this->data['vmsWeight'] = main\Core\Models\ModuleSettings\Model::where("setting", 'vmsWeight')->value("value");
  33. $this->data['cpuWeight'] = main\Core\Models\ModuleSettings\Model::where("setting", "cpuWeight")->value("value");
  34. $this->data['diskWeight'] = main\Core\Models\ModuleSettings\Model::where("setting", 'diskWeight')->value("value");
  35. $this->data['ramWeight'] = main\Core\Models\ModuleSettings\Model::where("setting", 'ramWeight')->value("value");
  36. $this->data['debug'] = main\Core\Models\ModuleSettings\Model::where("setting", 'debug')->value("value");
  37. }
  38. public function update()
  39. {
  40. if(main\Core\Models\Whmcs\Configuration::where("setting", "proxmoxVPSMinimumVMID")->count()){
  41. main\Core\Models\Whmcs\Configuration::where("setting", "proxmoxVPSMinimumVMID")
  42. ->update(['value' => $this->formData['proxmoxVPSMinimumVMID']]);
  43. }else{
  44. main\Core\Models\Whmcs\Configuration::where("setting", "proxmoxVPSMinimumVMID")
  45. ->insert(["setting" => "proxmoxVPSMinimumVMID",'value' => $this->formData['proxmoxVPSMinimumVMID']]);
  46. }
  47. $filable = ["vmsWeight", "cpuWeight", "diskWeight", "ramWeight", 'debug'];
  48. foreach ($filable as $key)
  49. {
  50. $entity = main\Core\Models\ModuleSettings\Model::where("setting", $key)->first();
  51. if (!$entity)
  52. {
  53. $entity = new main\Core\Models\ModuleSettings\Model();
  54. }
  55. $entity->fill(['setting'=> $key, "value" => $this->formData[$key]])
  56. ->save();
  57. }
  58. }
  59. }