Ejemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function upManual()
 {
     // Adds the static page
     if (Page::findOne(['name' => 'Static page']) === NULL) {
         $page = new Page();
         $page->name = 'Static page';
         $page->parameters = json_encode([['class' => StaticPlugin::className()]]);
         $page->save();
     } else {
         $page = Page::findOne(['name' => 'Static page']);
     }
     // Adds the static page plugin
     // used in the static pages
     if (Plugin::findOne(['namespace' => StaticPlugin::className()]) === NULL) {
         $plugin = new Plugin();
         $plugin->namespace = StaticPlugin::className();
         $plugin->private = TRUE;
         $plugin->save();
     }
     // Adds the basic Page Sections
     $oneColSection = PageSections::findOne(['name' => 'One column']);
     if (is_null($oneColSection)) {
         $section = new PageSections();
         $section->name = 'One column';
         $section->cols = 1;
         $section->cols_sizes = '12';
         $section->save();
     } else {
         $section = $oneColSection;
     }
     // Adds the Static Page Design
     if (PageReference::findOne(['page_id' => $page->id, 'reference_id' => NULL]) === NULL) {
         $pageReference = new PageReference();
         $pageReference->page_id = $page->id;
         $pageReference->save();
         $pageDesign = new PageDesign();
         $pageDesign->page_reference_id = $pageReference->id;
         $pageDesign->section_id = $section->id;
         $pageDesign->plugins = json_encode([[$plugin->id]]);
         $pageDesign->save();
     }
 }
Ejemplo n.º 2
0
 /**
  * Search
  *
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     // Adding inner joins to be able to search authors and editors in the gridView
     $query = StaticPlugin::find()->with('author', 'lastEditor')->innerJoin('user as user_author', 'user_author.id = ' . $this->tableName() . '.author_id')->innerJoin('user as user_editor', 'user_editor.id = ' . $this->tableName() . '.last_editor_id');
     // create data provider
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     // Enable sorting for the related columns
     $addSortAttributes = ['author', 'lastEditor'];
     foreach ($addSortAttributes as $addSortAttribute) {
         $dataProvider->sort->attributes[$addSortAttribute] = ['asc' => [$addSortAttribute => SORT_ASC], 'desc' => [$addSortAttribute => SORT_DESC]];
     }
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'author_id' => $this->author_id, 'last_editor_id' => $this->last_editor_id, 'creation_date' => $this->creation_date, 'update_date' => $this->update_date]);
     $query->andFilterWhere(['like', 'title', $this->title]);
     $query->andFilterWhere(['like', 'url', $this->url]);
     $query->andFilterWhere(['like', 'user_author.username', $this->author]);
     $query->andFilterWhere(['like', 'user_editor.username', $this->lastEditor]);
     return $dataProvider;
 }
Ejemplo n.º 3
0
<?php

use cyneek\yii2\routes\components\Route;
Route::pattern('id', '\\d+');
/**
 * Checks if Static Object Exists
 */
Route::filter('checkStaticPage', function () {
    /** @var \atuin\static_page\models\StaticPlugin $staticPlugin */
    $staticPlugin = \atuin\static_page\models\StaticPlugin::findOne(Route::input('id'));
    if (is_null($staticPlugin)) {
        throw new \yii\web\NotFoundHttpException(Yii::t('admin', "Static page doesn't exist."));
    }
    return TRUE;
});
/**
 * Static Pages
 */
Route::any('pages/static', 'apps/admin/static-page');
Route::any('pages/static/create', 'apps/admin/static-page/create');
Route::any('pages/static/update/{id}', 'apps/admin/static-page/update', ['before' => ['before' => 'checkStaticPage']]);
Route::post('pages/static/delete/{id}', 'apps/admin/static-page/delete', ['before' => ['before' => 'checkStaticPage']]);
Route::get('pages/static/view/{id}', 'apps/admin/static-page/view', ['before' => ['before' => 'checkStaticPage']]);
 private function staticPluginTableName()
 {
     return \atuin\static_page\models\StaticPlugin::tableName();
 }
Ejemplo n.º 5
0
 public function actionView($id)
 {
     /** @var StaticPlugin $staticPlugin */
     $staticPlugin = StaticPlugin::findOne($id);
     return $this->render('view', ['staticPlugin' => $staticPlugin]);
 }