HookIntegratorView.php 1.8 KB

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