HookIntegratorView.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\Core\Hook;
  3. use ModulesGarden\ProxmoxAddon\Core\App\Controllers\Instances\Http\Integration;
  4. use ModulesGarden\ProxmoxAddon\Core\DependencyInjection;
  5. use \ModulesGarden\ProxmoxAddon\Core\UI\Traits\RequestObjectHandler;
  6. /**
  7. * class HookIntegratorView
  8. * Prepares a views basing on /App/Integrations/Admin/ & /App/Integrations/Client controlers
  9. * to be injected on WHMCS subpages
  10. */
  11. class HookIntegratorView
  12. {
  13. use RequestObjectHandler;
  14. use \ModulesGarden\ProxmoxAddon\Core\Traits\Lang;
  15. use \ModulesGarden\ProxmoxAddon\Core\Traits\Smarty;
  16. /**
  17. * @var null|string|\ModulesGarden\ProxmoxAddon\Core\UI\View
  18. * integration data
  19. */
  20. protected $view = null;
  21. /**
  22. * @var null|string
  23. * HTML integration code
  24. */
  25. protected $HTMLData = null;
  26. public function __construct($view, $integration)
  27. {
  28. $this->view = $view;
  29. }
  30. /**
  31. * returns string/HTML integration code
  32. */
  33. public function getHTML()
  34. {
  35. $this->viewToHtml();
  36. return $this->HTMLData;
  37. }
  38. /**
  39. * transforms integration data to string to be integrated in WHMCS template
  40. */
  41. protected function viewToHtml()
  42. {
  43. if ($this->view instanceof \ModulesGarden\ProxmoxAddon\Core\UI\View)
  44. {
  45. $resp = $this->view->getResponse();
  46. $integrationPageController = DependencyInjection::call(Integration::class);
  47. $integrationPageController->setControllerResult($resp);
  48. $this->HTMLData = $integrationPageController->execute();
  49. return true;
  50. }
  51. if (is_string($this->view))
  52. {
  53. $this->HTMLData = $this->view;
  54. return true;
  55. }
  56. $this->HTMLData = '';
  57. }
  58. }