HookIntegrationsWrapper.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\Core\Hook;
  3. use \ModulesGarden\ProxmoxAddon\Core\ModuleConstants;
  4. class HookIntegrationsWrapper
  5. {
  6. use \ModulesGarden\ProxmoxAddon\Core\Traits\IsAdmin;
  7. use \ModulesGarden\ProxmoxAddon\Core\Traits\Lang;
  8. use \ModulesGarden\ProxmoxAddon\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. }
  21. public function getHtml()
  22. {
  23. foreach ($this->integrations as $key => $integration)
  24. {
  25. if (!$integration['htmlData'] || $integration ['htmlData'] === '' || !is_string($integration ['htmlData']) || !$integration['integrationDetails'] || !is_object($integration ['integrationDetails']))
  26. {
  27. unset($this->integrations[$key]);
  28. }
  29. }
  30. if (!$this->integrations)
  31. {
  32. return null;
  33. }
  34. $smarty = $this->getSmarty();
  35. $integrationHtml = $smarty->view($this->templateName, $this->getWrapperData(), $this->templateDirectory);
  36. return $integrationHtml;
  37. }
  38. protected function getWrapperData()
  39. {
  40. return [
  41. 'integrations' => $this->integrations
  42. ];
  43. }
  44. }