/**
  * renders a page view from the database
  *
  * @param $id
  * @param null $pageName
  * @param null $parentLeave
  *
  * @return string
  * @throws HttpException
  */
 public function actionPage($id, $pageName = null, $parentLeave = null)
 {
     Url::remember();
     \Yii::$app->session['__crudReturnUrl'] = null;
     // Set layout
     $this->layout = '@app/views/layouts/main';
     // Get active Tree object, allow access to invisible pages
     // @todo: improve handling, using also roles
     $pageQuery = Tree::find()->where([Tree::ATTR_ID => $id, Tree::ATTR_ACTIVE => Tree::ACTIVE, Tree::ATTR_ACCESS_DOMAIN => \Yii::$app->language]);
     // Show disabled pages for admins
     if (!\Yii::$app->user->can('pages')) {
         $pageQuery->andWhere([Tree::ATTR_DISABLED => Tree::NOT_DISABLED]);
     }
     // get page
     $page = $pageQuery->one();
     if ($page !== null) {
         // Set page title
         $this->view->title = $page->page_title;
         // Register default SEO meta tags
         $this->view->registerMetaTag(['name' => 'keywords', 'content' => $page->default_meta_keywords]);
         $this->view->registerMetaTag(['name' => 'description', 'content' => $page->default_meta_description]);
         if (\Yii::$app->user->isGuest) {
             Yii::$app->response->headers->set('Expires', gmdate('D, d M Y H:i:s \\G\\M\\T', time() + (getenv("HTTP_EXPIRES") !== null ? getenv("HTTP_EXPIRES") : 0)));
         }
         // Render view
         return $this->render($page->view, ['page' => $page]);
     } else {
         throw new HttpException(404, \Yii::t('app', 'Page not found.') . ' [ID: ' . $id . ']');
     }
 }
Example #2
0
 /**
  * @param array $additionalParams
  *
  * @return null|string
  */
 public function createUrl($additionalParams = [])
 {
     $leave = Tree::find()->where(['id' => $this->id])->one();
     if ($leave === null) {
         Yii::error("Tree node with id=" . $this->id . " not found.");
         return null;
     }
     // TODO merged request and additional params, URL rule has therefore to be updated/extended
     if ($leave->route !== null) {
         if ($additionalParams) {
             // merge with $params
         }
         return self::getSluggedUrl($leave);
     } elseif ($leave->route !== null) {
         return \Yii::$app->urlManager->createUrl([$leave->route]);
     }
 }
Example #3
0
/**
 * Wrapper templates
 */
$headerTemplate = <<<HTML
<div class="row">
    <div class="col-sm-6" id="pages-detail-heading">
        {heading}
    </div>
    <div class="col-sm-6" id="pages-detail-search">
        {search}
    </div>
</div>
HTML;
$mainTemplate = <<<HTML
<div class="row">
    <div class="col-md-4" id="pages-detail-wrapper">
        <div class="box boy-body">
        {wrapper}
        </div>
    </div>
    <div class="col-md-8" id="pages-detail-panel">
        {detail}
    </div>
</div>
HTML;
/** @var Tree $queryTree */
$queryTree = Tree::find()->where([Tree::ATTR_ACCESS_DOMAIN => [\Yii::$app->language, Yii::$app->user->can(Tree::GLOBAL_ACCESS_PERMISSION) ? Tree::GLOBAL_ACCESS_DOMAIN : '']])->orderBy('root, lft');
/**
 * Render tree view
 */
echo TreeView::widget(['query' => $queryTree, 'isAdmin' => true, 'softDelete' => false, 'displayValue' => 1, 'wrapperTemplate' => '{header}{footer}{tree}', 'headingOptions' => ['label' => 'Nodes'], 'treeOptions' => ['style' => 'height:auto; min-height:400px'], 'headerTemplate' => $headerTemplate, 'mainTemplate' => $mainTemplate]);
Example #4
0
$title = Inflector::titleize($this->context->module->id);
\dmstr\modules\pages\assets\PagesAsset::register($this);
?>

<?php 
/**
 * Output TreeView widget
 */
// Wrapper templates
$headerTemplate = <<<HTML
<div class="row">
    <div class="col-sm-6" id="pages-detail-heading">
        {heading}
    </div>
    <div class="col-sm-6" id="pages-detail-search">
        {search}
    </div>
</div>
HTML;
$mainTemplate = <<<HTML
<div class="row">
    <div class="col-md-4" id="pages-detail-wrapper">
        {wrapper}
    </div>
    <div class="col-md-8" id="pages-detail-panel">
        {detail}
    </div>
</div>
HTML;
echo TreeView::widget(['query' => Tree::find()->addOrderBy('root, lft')->andWhere([Tree::ATTR_ACCESS_DOMAIN => \Yii::$app->language]), 'isAdmin' => true, 'softDelete' => false, 'displayValue' => 1, 'wrapperTemplate' => "{header}{footer}{tree}", 'headingOptions' => ['label' => $title . '-Module'], 'treeOptions' => ['style' => 'height:600px'], 'headerTemplate' => $headerTemplate, 'mainTemplate' => $mainTemplate]);
 /**
  * @return array
  */
 private function resolveFallbackPage($pageId)
 {
     $original = Tree::find()->where(['id' => $pageId])->one();
     $fallback = Tree::find()->where(['domain_id' => $original->domain_id, 'access_domain' => \Yii::$app->language])->one();
     return $fallback;
 }