HookIntegrationsWrapper.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace ModulesGarden\Servers\ProxmoxCloudVps\Core\Hook;
  3. use \ModulesGarden\Servers\ProxmoxCloudVps\Core\ModuleConstants;
  4. class HookIntegrationsWrapper
  5. {
  6. use \ModulesGarden\Servers\ProxmoxCloudVps\Core\Traits\IsAdmin;
  7. use \ModulesGarden\Servers\ProxmoxCloudVps\Core\Traits\Lang;
  8. use \ModulesGarden\Servers\ProxmoxCloudVps\Core\Traits\Smarty;
  9. protected $integrations = [];
  10. protected $templateName = 'integrationsWrapper';
  11. protected $templateDirectory = null;
  12. public function __construct ($integrations = [])
  13. {
  14. if (is_array($integrations))
  15. {
  16. $this->integrations = $integrations;
  17. }
  18. $this->templateDirectory = ModuleConstants::getTemplateDir() . DIRECTORY_SEPARATOR
  19. . ($this->isAdmin() ? 'admin' : 'client' . DIRECTORY_SEPARATOR . 'default') . DIRECTORY_SEPARATOR
  20. . DIRECTORY_SEPARATOR . 'controlers';
  21. }
  22. public function getHtml()
  23. {
  24. foreach ($this->integrations as $key => $integration)
  25. {
  26. if (!$integration['htmlData'] || $integration ['htmlData'] === '' || !is_string($integration ['htmlData'])
  27. || !$integration['integrationDetails'] || !is_object($integration ['integrationDetails']))
  28. {
  29. unset($this->integrations[$key]);
  30. }
  31. }
  32. if (!$this->integrations)
  33. {
  34. return null;
  35. }
  36. $smarty = $this->getSmarty();
  37. $integrationHtml = $smarty->view($this->templateName, $this->getWrapperData(), $this->templateDirectory);
  38. return $integrationHtml;
  39. }
  40. protected function getWrapperData()
  41. {
  42. return [
  43. 'integrations' => $this->integrations
  44. ];
  45. }
  46. }