From 3ba5211190685ea69631301528d84a52c71b1fa5 Mon Sep 17 00:00:00 2001 From: Paul Kerspe Date: Sun, 9 Apr 2017 13:21:40 +0200 Subject: [PATCH] fixed https://github.com/pkerspe/yii2-simple-cms/issues/10: subpage teaser function added and also integrated new tease_name, teaser_text fields to be used in subpage teaser list --- .idea/copyright/profiles_settings.xml | 3 + .idea/sqldialects.xml | 6 + .idea/webResources.xml | 14 + Backend.php | 2 +- controllers/backend/DefaultController.php | 2 +- controllers/frontend/ShowController.php | 455 +++++++++++----------- models/CmsPageContent.php | 71 ++-- views/show/page.php | 31 +- widgets/CmsSubpageTeaserWidget.php | 120 +++--- 9 files changed, 371 insertions(+), 333 deletions(-) create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/sqldialects.xml create mode 100644 .idea/webResources.xml diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml new file mode 100644 index 0000000..d1f65f1 --- /dev/null +++ b/.idea/sqldialects.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/webResources.xml b/.idea/webResources.xml new file mode 100644 index 0000000..42f9baf --- /dev/null +++ b/.idea/webResources.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Backend.php b/Backend.php index 8c5ac0f..b1a4eb7 100644 --- a/Backend.php +++ b/Backend.php @@ -63,7 +63,7 @@ protected function getModuleComponents() { public function getLanguageManager(){ if($this->languageManager == null || $this->languageManager == '' ){ - throw new InvalidConfigException("Module is not condfigured correctly, need to provide name of a configured languageManager compoenent"); + throw new InvalidConfigException("Module is not condfigured correctly, need to provide name of a configured languageManager component"); } $configuredLangManager = $this->languageManager; return Yii::$app->$configuredLangManager; diff --git a/controllers/backend/DefaultController.php b/controllers/backend/DefaultController.php index db3db8c..d1d3d71 100644 --- a/controllers/backend/DefaultController.php +++ b/controllers/backend/DefaultController.php @@ -773,7 +773,7 @@ public function actionDeleteHierarchyItemJson($hierarchyItemId = -1) } /** - * internal helper class for slim representation of an hierarhcy item + * internal helper class for slim representation of an hierarchy item * * @author Paul Kerspe * diff --git a/controllers/frontend/ShowController.php b/controllers/frontend/ShowController.php index 4f29578..dbb46f3 100644 --- a/controllers/frontend/ShowController.php +++ b/controllers/frontend/ShowController.php @@ -10,241 +10,250 @@ */ namespace schallschlucker\simplecms\controllers\frontend; -use Yii; -use yii\helpers\Url; -use yii\helpers\FileHelper; -use yii\web\Controller; -use schallschlucker\simplecms\models\CmsAdministrationMainTreeViewForm; -use schallschlucker\simplecms\models\MenuItemAndContentForm; +use schallschlucker\simplecms\controllers\backend\DefaultController; use schallschlucker\simplecms\models\CmsDocument; +use schallschlucker\simplecms\models\CmsHierarchyItem; use schallschlucker\simplecms\models\CmsMenuItem; use schallschlucker\simplecms\models\CmsPageContent; -use schallschlucker\simplecms\models\CmsHierarchyItem; -use schallschlucker\simplecms\models\CmsMaintenanceForm; -use schallschlucker\simplecms\controllers\backend\SettingsAndMaintenanceController; -use yii\db\Expression; -use yii\web\NotFoundHttpException; +use Yii; use yii\base\View; -use schallschlucker\simplecms\controllers\backend\DefaultController; +use yii\helpers\FileHelper; +use yii\web\Controller; +use yii\web\NotFoundHttpException; /** * The default controller of the CMS frontend to provide actions for displaying content/documents * Default action is actionIndex, which renders an all in one administration mask for creating and maintaining the page tree. * * @menuLabel CMS Frontend Controller - * @menuIcon + * @menuIcon */ -class ShowController extends Controller { - - public $defaultAction = 'homepage'; - - /** - * @menuLabel display root content page - * @menuIcon - */ - public function actionHomepage() { - $currentLanguageId = Yii::$app->controller->module->getLanguageManager()->getLanguageIdForString(Yii::$app->language); - $pageContent = null; - $isFallback = false; - - $menuItemForRoot = CmsMenuItem::findOne(['cms_hierarchy_item_id' => DefaultController::$ROOT_HIERARCHY_ITEM_ID , 'language' => $currentLanguageId]); - if($menuItemForRoot == null){ - $menuItemForRoot = CmsMenuItem::findOne(['cms_hierarchy_item_id' => DefaultController::$ROOT_HIERARCHY_ITEM_ID]); - $isFallback = true; - } - - if($menuItemForRoot != null) - $pageContent = CmsPageContent::findOne(['id' => $menuItemForRoot->page_content_id]); - - if($pageContent == null) - throw new NotFoundHttpException('No content could be found for the given id',404); - - Yii::$app->view->params['currentHierarchyItemId'] = $menuItemForRoot->cmsHierarchyItem->id; - - if(Yii::$app->controller->module->assembleBreadcrumbInformation){ +class ShowController extends Controller +{ + + public $defaultAction = 'homepage'; + + /** + * @menuLabel display root content page + * @menuIcon + */ + public function actionHomepage() + { + $currentLanguageId = Yii::$app->controller->module->getLanguageManager()->getLanguageIdForString(Yii::$app->language); + $pageContent = null; + $isFallback = false; + + $menuItemForRoot = CmsMenuItem::findOne(['cms_hierarchy_item_id' => DefaultController::$ROOT_HIERARCHY_ITEM_ID, 'language' => $currentLanguageId]); + if ($menuItemForRoot == null) { + $menuItemForRoot = CmsMenuItem::findOne(['cms_hierarchy_item_id' => DefaultController::$ROOT_HIERARCHY_ITEM_ID]); + $isFallback = true; + } + + if ($menuItemForRoot != null) + $pageContent = CmsPageContent::findOne(['id' => $menuItemForRoot->page_content_id]); + + if ($pageContent == null) + throw new NotFoundHttpException('No content could be found for the given id', 404); + + Yii::$app->view->params['currentHierarchyItemId'] = $menuItemForRoot->cmsHierarchyItem->id; + + if (Yii::$app->controller->module->assembleBreadcrumbInformation) { Yii::$app->view->params['breadcrumbHierarchyItemPath'] = []; - } - - return $this->render ( 'page', [ - 'pageContentModel' => $pageContent, - 'isfallbacklanguage' => $isFallback, + } + + return $this->render('page', [ + 'pageContentModel' => $pageContent, + 'isfallbacklanguage' => $isFallback, + 'hierarchyItem' => CmsHierarchyItem::find(DefaultController::$ROOT_HIERARCHY_ITEM_ID)->one(), 'renderTopMenuNavbar' => Yii::$app->controller->module->renderTopMenuNavbar, - ] ); - } - - /** - * show the page for a given cms menu item id - * @menuLabel __HIDDEN__ - * @param integer $menuItemId - * @throws NotFoundHttpException an exception when the menu with the given id does not exists or does not have a linked page content - * @return View - */ - public function actionPage($menuItemId) { - $menuItemId = intval($menuItemId); - $menuItem = CmsMenuItem::find()->where(['id' => $menuItemId])->with('pageContent')->with('cmsHierarchyItem')->one(); - return $this->renderPage($menuItem); - } - - /** - * show the page for the given alias name - * @menuLabel __HIDDEN__ - * @param String $menuItemAlias - * @return View - */ - public function actionAlias($menuItemAlias){ - $menuItemAlias = preg_replace('/[^a-zA-Z0-9_\-]/', '', $menuItemAlias); - - $menuItem = CmsMenuItem::find()->where(['alias' => $menuItemAlias, ])->with('pageContent')->with('cmsHierarchyItem')->one(); - return $this->renderPage($menuItem); - } - - /** - * - * @param CmsMenuItem $menuItem - * @menuLabel __HIDDEN__ - * @throws NotFoundHttpException - * @return View - */ - private function renderPage($menuItem){ - $isFallback = false; - if($menuItem == null){ - throw new NotFoundHttpException('No menu could be found for the given menu id',404); - } - if($menuItem->cmsHierarchyItem->display_state === CmsHierarchyItem::DISPLAYSTATE_UNPUBLISHED){ - throw new NotFoundHttpException('You dont have the rights to access this item',403); - } - - $pageContent = $menuItem->pageContent; - if($pageContent == null){ - throw new NotFoundHttpException('No page content could be found for the menu id',404); - } - //set meta tags if needed - if($pageContent->meta_keywords != null && trim($pageContent->meta_keywords) != '') - $this->view->registerMetaTag(['name' => 'keywords','content' => $pageContent->meta_keywords]); - if($pageContent->description != null && trim($pageContent->description) != '') - $this->view->registerMetaTag(['name' => 'description','content' => $pageContent->description]); - - //set title tag either by htmlTitle Attribute if any or using the name of the menu item - $pageTitle = Yii::$app->controller->module->htmlTitlePrefix; - $pageTitle .= (isset($pageContent->html_title) && $pageContent->html_title != "") ? $pageContent->html_title : $menuItem->name; - $pageTitle .= Yii::$app->controller->module->htmlTitleSuffix; - $this->view->title = $pageTitle; - - Yii::$app->view->params['currentHierarchyItemId'] = $menuItem->cms_hierarchy_item_id; - - if(Yii::$app->controller->module->assembleBreadcrumbInformation){ - $breadcrumbArray = []; - Yii::beginProfile(__METHOD__,'CMS-BREADCRUMB-NAVIGATION'); - //check if item is root already, if not recurse through route back to route - if($menuItem->cms_hierarchy_item_id != DefaultController::$ROOT_HIERARCHY_ITEM_ID){ - $tempMenuItemInPath = $menuItem; - $breadcrumbArray[$tempMenuItemInPath->cms_hierarchy_item_id] = $tempMenuItemInPath; - $hierarchyItem = $tempMenuItemInPath->cmsHierarchyItem; - while ($hierarchyItem->parent_id != DefaultController::$ROOT_HIERARCHY_ITEM_ID){ - /* @var $parentCmsHierarchyItem CmsHierarchyItem */ - $parentCmsHierarchyItem = $hierarchyItem->getParent()->with('cmsMenus')->one(); - $cmsMenuItem = $parentCmsHierarchyItem->cmsMenus[0]; - $hierarchyItem = $cmsMenuItem->cmsHierarchyItem; - $breadcrumbArray[$parentCmsHierarchyItem->id] = $cmsMenuItem; //FIXME: get correct lang version - } - } - Yii::endProfile(__METHOD__); - Yii::$app->view->params['breadcrumbHierarchyItemPath'] = $breadcrumbArray; - } - return $this->render ( 'page', [ - 'pageContentModel' => $pageContent, - 'isfallbacklanguage' => $isFallback, + ]); + } + + /** + * show the page for a given cms menu item id + * + * @menuLabel __HIDDEN__ + * @param integer $menuItemId + * @throws NotFoundHttpException an exception when the menu with the given id does not exists or does not have a linked page content + * @return View + */ + public function actionPage($menuItemId) + { + $menuItemId = intval($menuItemId); + $menuItem = CmsMenuItem::find()->where(['id' => $menuItemId])->with('pageContent')->with('cmsHierarchyItem')->one(); + return $this->renderPage($menuItem); + } + + /** + * show the page for the given alias name + * + * @menuLabel __HIDDEN__ + * @param String $menuItemAlias + * @return View + */ + public function actionAlias($menuItemAlias) + { + $menuItemAlias = preg_replace('/[^a-zA-Z0-9_\-]/', '', $menuItemAlias); + + $menuItem = CmsMenuItem::find()->where(['alias' => $menuItemAlias,])->with('pageContent')->with('cmsHierarchyItem')->one(); + return $this->renderPage($menuItem); + } + + /** + * show the page for a given page content id + * + * @menuLabel __HIDDEN__ + * @param integer $pageContentId the cmsPageContent item id to be displayed + * @throws NotFoundHttpException an exception when the page content with the given id does not exists or does not have a linked page content + * @return View + */ + public function actionContent($pageContentId) + { + $isFallback = false; + $pageContentId = intval($pageContentId); + $pageContent = CmsPageContent::findOne(['id' => $pageContentId]); + if ($pageContent == null) { + throw new NotFoundHttpException('No page content could be found for the menu id', 404); + } + + return $this->render('page', [ + 'pageContentModel' => $pageContent, + 'isfallbacklanguage' => $isFallback, + ]); + } + + /** + * send data of document to browser directly + * + * (either by sending redirect url to let apache handle the request + * [if the file is located in the web directory or a folder below the web directory], + * or by sending file via php [if the file is not located within the web directory folder structure]) + * + * @menuLabel __HIDDEN__ + * @param integer $documentId + * @throws NotFoundHttpException + */ + public function actionFileData($documentId) + { + $isWebaccessableFile = false; + $documentModel = CmsDocument::findOne($documentId); + if ($documentModel == null) { + throw new NotFoundHttpException('Document could not be found', 404); + } + + $filePath = FileHelper::normalizePath($documentModel->file_path . DIRECTORY_SEPARATOR . $documentModel->file_name); + $webRootFolder = Yii::getAlias('@webroot'); + $isWebaccessableFile = (stripos($filePath, $webRootFolder) === 0); + + //check if item is in web folder, then redirect, or send file instead if not + if ($isWebaccessableFile) { + $webPath = substr($filePath, strlen($webRootFolder)); + Yii::$app->response->redirect($webPath); + } else { + Yii::$app->response->sendFile($filePath, $documentModel->file_name, ['mimeType' => $documentModel->mime_type, 'inline' => true])->send(); + } + } + + /** + * display the document in the chosen presentation style (Inline, Window or send as download response) + * + * @menuLabel __HIDDEN__ + * @param integer $documentId + * @throws NotFoundHttpException + * @return void|string + */ + public function actionDocument($documentId) + { + $documentId = intval($documentId); + $documentModel = CmsDocument::findOne($documentId); + if ($documentModel == null) { + throw new NotFoundHttpException('Document could not be found', 404); + } + $filePath = $documentModel->file_path . DIRECTORY_SEPARATOR . $documentModel->file_name; + if (file_exists($filePath)) { + + switch ($documentModel->presentation_style) { + case CmsDocument::PRESENTATION_STYLE_DOWNLOAD: + Yii::$app->response->sendFile($filePath, $documentModel->file_name, ['mimeType' => $documentModel->mime_type, 'inline' => false])->send(); + return; + + case CmsDocument::PRESENTATION_STYLE_WINDOW: + Yii::$app->response->sendFile($filePath, $documentModel->file_name, ['mimeType' => $documentModel->mime_type, 'inline' => true])->send(); + return; + + case CmsDocument::PRESENTATION_STYLE_EMBEDED: + return $this->render('document', [ + 'documentModel' => $documentModel + ]); + break; + + default: + break; + } + } else { + throw new NotFoundHttpException('Document could not be found, invalid path', 404); + } + } + + /** + * + * @param CmsMenuItem $menuItem + * @menuLabel __HIDDEN__ + * @throws NotFoundHttpException + * @return View + */ + private function renderPage($menuItem) + { + $isFallback = false; + if ($menuItem == null) { + throw new NotFoundHttpException('No menu could be found for the given menu id', 404); + } + if ($menuItem->cmsHierarchyItem->display_state === CmsHierarchyItem::DISPLAYSTATE_UNPUBLISHED) { + throw new NotFoundHttpException('You dont have the rights to access this item', 403); + } + + $pageContent = $menuItem->pageContent; + if ($pageContent == null) { + throw new NotFoundHttpException('No page content could be found for the menu id', 404); + } + //set meta tags if needed + if ($pageContent->meta_keywords != null && trim($pageContent->meta_keywords) != '') + $this->view->registerMetaTag(['name' => 'keywords', 'content' => $pageContent->meta_keywords]); + if ($pageContent->description != null && trim($pageContent->description) != '') + $this->view->registerMetaTag(['name' => 'description', 'content' => $pageContent->description]); + + //set title tag either by htmlTitle Attribute if any or using the name of the menu item + $pageTitle = Yii::$app->controller->module->htmlTitlePrefix; + $pageTitle .= (isset($pageContent->html_title) && $pageContent->html_title != "") ? $pageContent->html_title : $menuItem->name; + $pageTitle .= Yii::$app->controller->module->htmlTitleSuffix; + $this->view->title = $pageTitle; + + Yii::$app->view->params['currentHierarchyItemId'] = $menuItem->cms_hierarchy_item_id; + + if (Yii::$app->controller->module->assembleBreadcrumbInformation) { + $breadcrumbArray = []; + Yii::beginProfile(__METHOD__, 'CMS-BREADCRUMB-NAVIGATION'); + //check if item is root already, if not recurse through route back to route + if ($menuItem->cms_hierarchy_item_id != DefaultController::$ROOT_HIERARCHY_ITEM_ID) { + $tempMenuItemInPath = $menuItem; + $breadcrumbArray[$tempMenuItemInPath->cms_hierarchy_item_id] = $tempMenuItemInPath; + $hierarchyItem = $tempMenuItemInPath->cmsHierarchyItem; + while ($hierarchyItem->parent_id != DefaultController::$ROOT_HIERARCHY_ITEM_ID) { + /* @var $parentCmsHierarchyItem CmsHierarchyItem */ + $parentCmsHierarchyItem = $hierarchyItem->getParent()->with('cmsMenus')->one(); + $cmsMenuItem = $parentCmsHierarchyItem->cmsMenus[0]; + $hierarchyItem = $cmsMenuItem->cmsHierarchyItem; + $breadcrumbArray[$parentCmsHierarchyItem->id] = $cmsMenuItem; //FIXME: get correct lang version + } + } + Yii::endProfile(__METHOD__); + Yii::$app->view->params['breadcrumbHierarchyItemPath'] = $breadcrumbArray; + } + return $this->render('page', [ + 'pageContentModel' => $pageContent, + 'isfallbacklanguage' => $isFallback, + 'hierarchyItem' => $menuItem->cmsHierarchyItem, 'renderTopMenuNavbar' => Yii::$app->controller->module->renderTopMenuNavbar - ] ); - } - - /** - * show the page for a given page content id - * @menuLabel __HIDDEN__ - * @param integer $pageContentId the cmsPageContent item id to be displayed - * @throws NotFoundHttpException an exception when the page content with the given id does not exists or does not have a linked page content - * @return View - */ - public function actionContent($pageContentId){ - $isFallback = false; - $pageContentId = intval($pageContentId); - $pageContent = CmsPageContent::findOne(['id' => $pageContentId]); - if($pageContent == null){ - throw new NotFoundHttpException('No page content could be found for the menu id',404); - } - - return $this->render ( 'page', [ - 'pageContentModel' => $pageContent, - 'isfallbacklanguage' => $isFallback, - ] ); - } - - /** - * send data of document to browser directly - * - * (either by sending redirect url to let apache handle the request - * [if the file is located in the web directory or a folder below the web directory], - * or by sending file via php [if the file is not located within the web directory folder structure]) - * @menuLabel __HIDDEN__ - * @param unknown $documentId - * @throws NotFoundHttpException - */ - public function actionFileData($documentId){ - $isWebaccessableFile = false; - $documentModel = CmsDocument::findOne($documentId); - if($documentModel == null){ - throw new NotFoundHttpException('Document could not be found',404); - } - - $filePath = FileHelper::normalizePath($documentModel->file_path.DIRECTORY_SEPARATOR.$documentModel->file_name); - $webRootFolder = Yii::getAlias('@webroot'); - $isWebaccessableFile = (stripos($filePath, $webRootFolder) === 0); - - //check if item is in web folder, then redirect, or send file instead if not - if($isWebaccessableFile){ - $webPath = substr($filePath, strlen($webRootFolder)); - Yii::$app->response->redirect($webPath); - } else { - Yii::$app->response->sendFile($filePath,$documentModel->file_name,['mimeType' => $documentModel->mime_type, 'inline' => true])->send(); - } - } - - /** - * display the document in the chosen presentation style (Inline, Window or send as download response) - * @menuLabel __HIDDEN__ - * @param unknown $documentId - * @throws NotFoundHttpException - * @return void|string - */ - public function actionDocument($documentId){ - $documentId = intval($documentId); - $documentModel = CmsDocument::findOne($documentId); - if($documentModel == null){ - throw new NotFoundHttpException('Document could not be found',404); - } - $filePath = $documentModel->file_path.DIRECTORY_SEPARATOR.$documentModel->file_name; - if(file_exists($filePath)){ - - switch($documentModel->presentation_style){ - case CmsDocument::PRESENTATION_STYLE_DOWNLOAD: - Yii::$app->response->sendFile($filePath,$documentModel->file_name,['mimeType' => $documentModel->mime_type, 'inline' => false])->send(); - return; - - case CmsDocument::PRESENTATION_STYLE_WINDOW: - Yii::$app->response->sendFile($filePath,$documentModel->file_name,['mimeType' => $documentModel->mime_type, 'inline' => true])->send(); - return; - - case CmsDocument::PRESENTATION_STYLE_EMBEDED: - return $this->render ( 'document', [ - 'documentModel' => $documentModel - ] ); - break; - - default: - break; - } - } else { - throw new NotFoundHttpException('Document could not be found, invalid path',404); - } - } + ]); + } } diff --git a/models/CmsPageContent.php b/models/CmsPageContent.php index a9d8254..01656e1 100644 --- a/models/CmsPageContent.php +++ b/models/CmsPageContent.php @@ -20,22 +20,23 @@ * This is the model class for table "cms_page_content". * * @property integer $id - * @property integer $language the language id of this page content - * @property string $html_title value to override the html title tag. If empy the menu item name will be used instead. Title will be prefixed/suffixed with configured string from module config is set (check Frontnend module parameters htmlTitlePrefix and htmlTitleSuffix) - * @property string $metatags_general metatags to be rendered in the frontend view page - * @property string $meta_keywords keywords to be used in the search as well as in the metatags in the frontend - * @property string $description a short description of the contents of this page. Used in Metatags as well as to display a preview of the page content in the search results or teaser lists - * @property string $content the content of this page (HTML) - * @property string $javascript additional javascript to be rendered on the bottom of the page html source - * @property string $css additional css definitions to be rendered on top of the page in the head section - * @property string $modification_datetime last modification date and time of the page content element - * @property integer $modification_userid user id of the user who modified the page content element for the last time - * @property string $created_datetime creation date and time of the page content element - * @property integer $createdby_userid user id of the user who created the page content element - * @property string $teaser_text some teaser text (max 500 chars) for the page that can be used in widgets - * @property integer $teaser_image_id the id of the teaser image media item to be displayed e.g. in sub page list widgets - * @property string $teaser_name Name of the teaser to be displayed e.g. as link text - * @property string $teaser_link Custom link for the teaser if we do not want to link to the page itsself + * @property integer $language the language id of this page content + * @property string $html_title value to override the html title tag. If empy the menu item name will be used instead. Title will be prefixed/suffixed with configured string from module config is set (check Frontnend module parameters htmlTitlePrefix and htmlTitleSuffix) + * @property string $metatags_general metatags to be rendered in the frontend view page + * @property string $meta_keywords keywords to be used in the search as well as in the metatags in the frontend + * @property string $description a short description of the contents of this page. Used in Metatags as well as to display a preview of the page content in the search results or teaser lists + * @property string $content the content of this page (HTML) + * @property boolean $render_subpage_teasers Should the cms render a list of subpage teasers below the content area? + * @property string $javascript additional javascript to be rendered on the bottom of the page html source + * @property string $css additional css definitions to be rendered on top of the page in the head section + * @property string $modification_datetime last modification date and time of the page content element + * @property integer $modification_userid user id of the user who modified the page content element for the last time + * @property string $created_datetime creation date and time of the page content element + * @property integer $createdby_userid user id of the user who created the page content element + * @property string $teaser_text some teaser text (max 500 chars) for the page that can be used in widgets + * @property integer $teaser_image_id the id of the teaser image media item to be displayed e.g. in sub page list widgets + * @property string $teaser_name Name of the teaser to be displayed e.g. as link text + * @property string $teaser_link Custom link for the teaser if we do not want to link to the page itsself * * @property CmsMenuItem[] $cmsMenuItems */ @@ -85,7 +86,8 @@ public function rules() 'language', 'modification_userid', 'createdby_userid', - 'teaser_image_id' + 'teaser_image_id', + 'render_subpage_teasers' ], 'integer' ], @@ -133,23 +135,24 @@ public function rules() public function attributeLabels() { return [ - 'id' => Yii::t('simplecms', 'ID'), - 'language' => Yii::t('simplecms', 'Language'), - 'html_title' => Yii::t('simplecms', 'HTML Title'), - 'metatags_general' => Yii::t('simplecms', 'Metatags General'), - 'meta_keywords' => Yii::t('simplecms', 'Meta Keywords'), - 'description' => Yii::t('simplecms', 'Description'), - 'content' => Yii::t('simplecms', 'Content'), - 'javascript' => Yii::t('simplecms', 'Javascript'), - 'css' => Yii::t('simplecms', 'Css'), - 'modification_datetime' => Yii::t('simplecms', 'Modification Datetime'), - 'modification_userid' => Yii::t('simplecms', 'Modification Userid'), - 'created_datetime' => Yii::t('simplecms', 'Created Datetime'), - 'createdby_userid' => Yii::t('simplecms', 'Createdby Userid'), - 'teaser_image_id' => Yii::t('simplecms', 'Teaser Image'), - 'teaser_text' => Yii::t('simplecms', 'Teaser Text'), - 'teaser_name' => Yii::t('simplecms', 'Teaser Name'), - 'teaser_link' => Yii::t('simplecms', 'Teaser Link'), + 'id' => Yii::t('simplecms', 'ID'), + 'language' => Yii::t('simplecms', 'Language'), + 'html_title' => Yii::t('simplecms', 'HTML Title'), + 'metatags_general' => Yii::t('simplecms', 'Metatags General'), + 'meta_keywords' => Yii::t('simplecms', 'Meta Keywords'), + 'description' => Yii::t('simplecms', 'Description'), + 'content' => Yii::t('simplecms', 'Content'), + 'javascript' => Yii::t('simplecms', 'Javascript'), + 'css' => Yii::t('simplecms', 'Css'), + 'modification_datetime' => Yii::t('simplecms', 'Modification Datetime'), + 'modification_userid' => Yii::t('simplecms', 'Modification Userid'), + 'created_datetime' => Yii::t('simplecms', 'Created Datetime'), + 'createdby_userid' => Yii::t('simplecms', 'Createdby Userid'), + 'render_subpage_teasers' => Yii::t('simplecms', 'Render Subpage Tesaers'), + 'teaser_image_id' => Yii::t('simplecms', 'Teaser Image'), + 'teaser_text' => Yii::t('simplecms', 'Teaser Text'), + 'teaser_name' => Yii::t('simplecms', 'Teaser Name'), + 'teaser_link' => Yii::t('simplecms', 'Teaser Link'), ]; } diff --git a/views/show/page.php b/views/show/page.php index 89f1aa1..ada5506 100644 --- a/views/show/page.php +++ b/views/show/page.php @@ -1,33 +1,38 @@ true,'enableHoverDropDown'=>true]); +if ($renderTopMenuNavbar) { + $widget = new CmsBootstrapNavbarWidget(['displayRootItem' => true, 'enableHoverDropDown' => true]); echo $widget->run(); } -if($pageContentModel->css != null && $pageContentModel->css != ''){ - $this->registerCss ( $pageContentModel->css,[],'cmsCustonCssCode' ); +if ($pageContentModel->css != null && $pageContentModel->css != '') { + $this->registerCss($pageContentModel->css, [], 'cmsCustonCssCode'); } -if($isfallbacklanguage){ - echo '

'.Yii::t('simplecms', 'The page could not be found in the requested language, displaying fallback language instead').'

'; +if ($isfallbacklanguage) { + echo '

' . Yii::t('simplecms', 'The page could not be found in the requested language, displaying fallback language instead') . '

'; } if (Yii::$app->controller->module->showBreadcrumbs) { - $this->params['breadcrumbs'][] = ['label'=>\Yii::t('app', Yii::$app->controller->module->rootBreadcrumb), 'url'=>['/docs']]; - $this->params['breadcrumbs'][] = $this->title; + $this->params['breadcrumbs'][] = ['label' => \Yii::t('app', Yii::$app->controller->module->rootBreadcrumb), 'url' => ['/docs']]; + $this->params['breadcrumbs'][] = $this->title; } echo $pageContentModel->content; -if($pageContentModel->javascript != null && trim($pageContentModel->javascript) != ''){ - $this->registerJs ( $pageContentModel->javascript, View::POS_END, 'cmsCustomPageJavascript' ); +if ($pageContentModel->render_subpage_teasers && !empty($hierarchyItem)) { + $subpageWidget = new \schallschlucker\simplecms\widgets\CmsSubpageTeaserWidget(['cmsHierarchyItem' => $hierarchyItem]); + echo $subpageWidget->run(); +} + +if ($pageContentModel->javascript != null && trim($pageContentModel->javascript) != '') { + $this->registerJs($pageContentModel->javascript, View::POS_END, 'cmsCustomPageJavascript'); } ?> \ No newline at end of file diff --git a/widgets/CmsSubpageTeaserWidget.php b/widgets/CmsSubpageTeaserWidget.php index 5f80bbc..8431cf5 100644 --- a/widgets/CmsSubpageTeaserWidget.php +++ b/widgets/CmsSubpageTeaserWidget.php @@ -9,83 +9,81 @@ */ namespace schallschlucker\simplecms\widgets; -use Yii; -use yii\base\Widget; -use yii\helpers\Html; -use schallschlucker\simplecms\controllers\backend\CmsHierarchyController; -use schallschlucker\simplecms\controllers\backend\DefaultController; -use yii\helpers\Url; -use schallschlucker\simplecms\controllers\frontend\NavigationController; -use schallschlucker\simplecms\models\SimpleHierarchyItem; -use schallschlucker\simplecms\Frontend; -use schallschlucker\simplecms\models\CmsMenuItem; use schallschlucker\simplecms\models\CmsHierarchyItem; +use schallschlucker\simplecms\models\CmsMenuItem; use schallschlucker\simplecms\models\CmsPageContent; +use Yii; +use yii\base\Widget; + /** * A widget to render a tabular listing of subpage teasers (sub pages (if any) of the menu item id given in the parameter). * The following parameters are supported: - * @param $cmsHierarchyItem CmsHierarchyItem required: the hierarchy item to render the subpage teasers for + * + * @param $cmsHierarchyItem CmsHierarchyItem required: the hierarchy item to render the subpage teasers for * @param $propertiesToRender string optional: a comma separated list of property names to render for each subpage. Will be displayed in the order of appearance in the csv-string. If not provided a default set of properies will be rendered */ -class CmsSubpageTeaserWidget extends Widget { +class CmsSubpageTeaserWidget extends Widget +{ + + public $propertiesToRender = null; + /* @var $cmsHierarchyItem CmsHierarchyItem */ + public $cmsHierarchyItem = null; + public $renderCreationDate = false; - public $propertiesToRender = null; - /* @var $cmsHierarchyItem CmsHierarchyItem */ - public $cmsHierarchyItem = null; - public $renderCreationDate = false; + public function init() + { + parent::init(); + } - public function init() { - parent::init (); - } + public function renderSubpageTeasers(&$widgetHtml) + { + /* @var $cmsHierarchyItem CmsHierarchyItem */ + $cmsHierarchyItem = $this->cmsHierarchyItem; + $cmsChildHierarchyItems = $cmsHierarchyItem->getCmsHierarchyItems()->where(['display_state' => CmsHierarchyItem::DISPLAYSTATE_PUBLISHED_VISIBLE_IN_NAVIGATION])->with('cmsMenus')->orderBy("position asc")->all(); - public function renderSubpageTeasers(&$widgetHtml){ - /* @var $cmsHierarchyItem CmsHierarchyItem */ - $cmsHierarchyItem = $this->cmsHierarchyItem; - $cmsChildHierarchyItems = $cmsHierarchyItem->getCmsHierarchyItems()->where(['display_state' => CmsHierarchyItem::DISPLAYSTATE_PUBLISHED_VISIBLE_IN_NAVIGATION])->orderBy("position asc")->all(); + if (count($cmsChildHierarchyItems) > 0) { + $widgetHtml .= '' . PHP_EOL; + } + return $widgetHtml; + } - public function run() { - $widgetHtml = '
'.PHP_EOL; + public function run() + { + $widgetHtml = '
' . PHP_EOL; - $this->renderSubpageTeasers($widgetHtml); + $this->renderSubpageTeasers($widgetHtml); - $widgetHtml .= '
'.PHP_EOL; - return $widgetHtml; - } + $widgetHtml .= '
' . PHP_EOL; + return $widgetHtml; + } } \ No newline at end of file