/templates/) to the "global" TWIG template which contains HTML, JS inline, JS files, CSS inline, CSS files. Should not be used to often as JS/CSS files would be duplicated making browser parsing time way longer. */ const GLOBAL_TEMPLATE_REL_PATH = null; /** @var string|null HTML_TEMPLATE_REL_PATH Relative path (from /templates/) to the HTML template */ const HTML_TEMPLATE_REL_PATH = null; /** @var array JS_FILES_REL_PATH Relative paths (from /) to the JS files */ const JS_FILES_REL_PATH = []; /** @var string|null JS_TEMPLATE_REL_PATH Relative path (from /templates/) to the JS template */ const JS_TEMPLATE_REL_PATH = null; /** @var array CSS_FILES_REL_PATH Relative paths (from /) to the CSS files */ const CSS_FILES_REL_PATH = []; /** @var string|null CSS_TEMPLATE_REL_PATH Relative path (from /templates/) to the CSS template */ const CSS_TEMPLATE_REL_PATH = null; /** @var string ENUM_BLOCK_FILES_TYPE_JS */ const ENUM_BLOCK_FILES_TYPE_JS = 'js'; /** @var string ENUM_BLOCK_FILES_TYPE_CSS */ const ENUM_BLOCK_FILES_TYPE_CSS = 'css'; /** * @inheritDoc */ public static function GetGlobalTemplateRelPath() { return static::GLOBAL_TEMPLATE_REL_PATH; } /** * @inheritDoc */ public static function GetHtmlTemplateRelPath() { return static::HTML_TEMPLATE_REL_PATH; } /** * @inheritDoc */ public static function GetJsTemplateRelPath() { return static::JS_TEMPLATE_REL_PATH; } /** * @inheritDoc */ public static function GetJsFilesRelPaths() { return static::JS_FILES_REL_PATH; } /** * @inheritDoc */ public static function GetCssTemplateRelPath() { return static::CSS_TEMPLATE_REL_PATH; } /** * @inheritDoc */ public static function GetCssFilesRelPaths() { return static::CSS_FILES_REL_PATH; } /** @var string $sId */ protected $sId; /** * UIBlock constructor. * * @param string|null $sId */ public function __construct($sId = null) { $this->sId = ($sId !== null) ? $sId : $this->GenerateId(); } /** * Return a unique ID for the block * * @return string */ protected function GenerateId() { return uniqid(static::BLOCK_CODE.'-'); } /** * @inheritDoc */ public function GetId() { return $this->sId; } /** * @inheritDoc * @return \Combodo\iTop\Application\UI\UIBlock[] */ public function GetSubBlocks() { return []; } /** * @inheritDoc * @throws \Exception */ public function GetJsFilesUrlRecursively($bAbsoluteUrl = false) { return $this->GetFilesUrlRecursively(static::ENUM_BLOCK_FILES_TYPE_JS, $bAbsoluteUrl); } /** * @inheritDoc * @throws \Exception */ public function GetCssFilesUrlRecursively($bAbsoluteUrl = false) { return $this->GetFilesUrlRecursively(static::ENUM_BLOCK_FILES_TYPE_CSS, $bAbsoluteUrl); } /** * Return an array of the URL of the block $sFilesType and its sub blocks. * URL is relative unless the $bAbsoluteUrl is set to true. * * @param string $sFilesType (see static::ENUM_BLOCK_FILES_TYPE_JS, static::ENUM_BLOCK_FILES_TYPE_CSS) * @param bool $bAbsoluteUrl * * @return array * @throws \Exception */ protected function GetFilesUrlRecursively($sFilesType, $bAbsoluteUrl = false) { $aFiles = []; $sFilesRelPathMethodName = 'Get'.ucfirst($sFilesType).'FilesRelPaths'; $sFilesAbsUrlMethodName = 'Get'.ucfirst($sFilesType).'FilesUrlRecursively'; // Files from the block itself foreach($this::$sFilesRelPathMethodName() as $sFilePath) { $aFiles[] = (($bAbsoluteUrl === true) ? utils::GetAbsoluteUrlAppRoot() : '').$sFilePath; } // Files from its sub blocks foreach($this->GetSubBlocks() as $sSubBlockName => $oSubBlock) { $aFiles = array_merge( $aFiles, call_user_func_array([$oSubBlock, $sFilesAbsUrlMethodName], [$bAbsoluteUrl]) ); } return $aFiles; } }