WhmcsParams.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace ModulesGarden\Servers\ProxmoxVps\Core\UI\Traits;
  3. use function \ModulesGarden\Servers\ProxmoxVps\Core\Helper\di;
  4. /**
  5. * WhmcsParams related functions
  6. *
  7. * @author Sławomir Miśkowicz <slawomir@modulesgarden.com>
  8. */
  9. trait WhmcsParams
  10. {
  11. /**
  12. *
  13. * @var type ModulesGarden\Servers\ProxmoxVps\Core\Helper\WhmcsParams
  14. */
  15. private $whmcsParams = null;
  16. public function initWhmcsParams()
  17. {
  18. if ($this->whmcsParams === null)
  19. {
  20. $this->whmcsParams = di('whmcsParams');
  21. }
  22. }
  23. protected function getWhmcsParamByKey($key, $default = false)
  24. {
  25. $this->initWhmcsParams();
  26. return $this->whmcsParams->getParamByKey($key, $default);
  27. }
  28. public function getWhmcsParamsByKeys(array $keys = [], $default = false)
  29. {
  30. $selectedParams = [];
  31. foreach ($keys as $key)
  32. {
  33. $selectedParams[$key] = $this->getWhmcsParamByKey($key, $default);
  34. }
  35. return $selectedParams;
  36. }
  37. protected function isWhmcsConfigOption($key)
  38. {
  39. $this->initWhmcsParams();
  40. return isset($this->whmcsParams->getParamByKey('configoptions')[$key]);
  41. }
  42. protected function getWhmcsConfigOption($key, $default = false)
  43. {
  44. $this->initWhmcsParams();
  45. if($this->isWhmcsConfigOption($key)){
  46. return $this->whmcsParams->getParamByKey('configoptions')[$key];
  47. }
  48. return $default;
  49. }
  50. protected function isWhmcsCustomField($key)
  51. {
  52. $this->initWhmcsParams();
  53. return isset($this->whmcsParams->getParamByKey('customfields')[$key]);
  54. }
  55. protected function getWhmcsCustomField($key, $default = false)
  56. {
  57. $this->initWhmcsParams();
  58. if($this->isWhmcsCustomField($key)){
  59. return $this->whmcsParams->getParamByKey('customfields')[$key];
  60. }
  61. return $default;
  62. }
  63. }