getExtensionName(); } return self::getAssetService()->getAsset('img/' . $path, $extensionId); } /** * Expects a relative url to the css as path * if extension name is omitted the current extension is used * * @param string $path * @param string $extensionId * @return string */ public static function css($path, $extensionId = null) { if (is_null($extensionId)) { $extensionId = \Context::getInstance()->getExtensionName(); } return self::getAssetService()->getAsset('css/' . $path, $extensionId); } /** * Expects a relative url to the java script as path * if extension name is omitted the current extension is used * * @param string $path * @param string $extensionId * @return string */ public static function js($path, $extensionId = null) { if (is_null($extensionId)) { $extensionId = \Context::getInstance()->getExtensionName(); } return self::getAssetService()->getAsset('js/' . $path, $extensionId); } /** * Expects a relative url to the template that is to be included as path * if extension name is omitted the current extension is used * * @param string $path * @param string $extensionId * @param array $data bind additional data to the context */ public static function inc($path, $extensionId = null, $data = []) { $context = \Context::getInstance(); if ($extensionId !== null && $extensionId !== $context->getExtensionName()) { // template is within different extension, change context $formerContext = $context->getExtensionName(); $context->setExtensionName($extensionId); } if (!empty($data)) { \RenderContext::pushContext($data); } $absPath = Layout::getThemeTemplate(Theme::CONTEXT_BACKOFFICE, $path) ?? self::getTemplate($path, $extensionId); if (file_exists($absPath)) { include($absPath); } else { \common_Logger::w('Failed to include "' . $absPath . '" in template'); } // restore context if (isset($formerContext)) { $context->setExtensionName($formerContext); } } /** * @param $path * @param null $extensionId * @return string */ public static function getTemplate($path, $extensionId = null) { $extensionId = is_null($extensionId) ? \Context::getInstance()->getExtensionName() : $extensionId; $ext = \common_ext_ExtensionsManager::singleton()->getExtensionById($extensionId); return $ext->getConstant('DIR_VIEWS') . 'templates' . DIRECTORY_SEPARATOR . $path; } /** * @FIXME get_data and has_data should be used exclusively inside templates (not namespaced) * @return array|bool */ public static function getMessages() { $messages = []; if (has_data('errorMessage')) { $messages['error'] = get_data('errorMessage'); } if (has_data('message')) { $messages['info'] = get_data('message'); } return !!count($messages) ? $messages : false; } /** * @return AssetService * @throws \common_Exception * @throws \oat\oatbox\service\ServiceNotFoundException */ private static function getAssetService() { return ServiceManager::getServiceManager()->get(AssetService::SERVICE_ID); } }