* @copyright 2021 DIGITAL RETAIL TECHNOLOGIES SL * @license https://opensource.org/licenses/MIT The MIT License * * Don't forget to prefix your containers with your own identifier * to avoid any conflicts with others containers. */ abstract class RetailcrmAbstractTemplate { /** @var Module|\RetailCRM */ protected $module; protected $smarty; protected $assets; /** @var string */ protected $template; /** @var array */ protected $data; /** @var Context */ protected $context; /** * RetailcrmAbstractTemplate constructor. * * @param Module $module * @param $smarty * @param $assets */ public function __construct(Module $module, $smarty, $assets) { $this->module = $module; $this->smarty = $smarty; $this->assets = $assets; } /** * Returns ISO code of current employee language or default language. * * @return string */ protected function getCurrentLanguageISO() { $langId = 0; global $cookie; if (!empty($this->context) && !empty($this->context->employee)) { $langId = (int) $this->context->employee->id_lang; } elseif ($cookie instanceof Cookie) { $langId = (int) $cookie->id_lang; } else { $langId = (int) Configuration::get('PS_LANG_DEFAULT'); } return (string) Language::getIsoById($langId); } /** * @param $file * * @return mixed * * @throws RuntimeException */ public function render($file) { $this->buildParams(); $this->setTemplate(); if (null === $this->template) { throw new \RuntimeException('Template not be blank'); } // set url post for forms if (empty($this->smarty->getTemplateVars('url_post'))) { $this->data['url_post'] = $this->smarty->getTemplateVars('current') . '&token=' . $this->smarty->getTemplateVars('token'); } $this->smarty->assign($this->data); return $this->module->display($file, "views/templates/admin/$this->template"); } /** * @param $context * * @return self */ public function setContext($context) { if (!empty($context)) { $this->context = $context; } return $this; } abstract protected function buildParams(); abstract protected function setTemplate(); }