コード例 #1
0
ファイル: Page.php プロジェクト: modernkernel/yii2-skeleton
 /**
  * @return mixed|null
  */
 public function getPageTitle()
 {
     $data = PageData::find()->select('title')->where(['id_page' => $this->id, 'language' => Yii::$app->language, 'status' => PageData::STATUS_ACTIVE])->one();
     if (!$data) {
         $data = PageData::find()->select('title')->where(['id_page' => $this->id, 'status' => PageData::STATUS_ACTIVE])->one();
     }
     return isset($data) ? $data->title : 'unknown';
 }
コード例 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = PageData::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id_page' => $this->id_page, 'status' => $this->status, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'language', $this->language])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'keywords', $this->keywords]);
     return $dataProvider;
 }
コード例 #3
0
 /**
  * sitemap
  * @return string
  */
 public function actionSitemap()
 {
     /* header */
     Yii::$app->response->format = Response::FORMAT_RAW;
     $headers = Yii::$app->response->headers;
     $headers->add('Content-Type', 'application/xml');
     /* ok */
     $query = PageData::find()->select(['id_page', 'language', 'updated_at'])->where(['status' => PageData::STATUS_ACTIVE]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count()]);
     $pages->setPageSize(Yii::$app->params['sitemapPageSize']);
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     return $this->renderPartial('sitemap', ['models' => $models]);
 }
コード例 #4
0
 /**
  * Finds the PageData model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id_page
  * @param string $language
  * @return PageData the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id_page, $language)
 {
     if (($model = PageData::findOne(['id_page' => $id_page, 'language' => $language])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #5
0
ファイル: update.php プロジェクト: modernkernel/yii2-skeleton
echo \common\widgets\FlickrUploadWidget::widget();
?>
                        </div>
                        <!-- /.tab-pane -->
                    </div>
                    <!-- /.tab-content -->
                </div>

                <?php 
echo $form->field($model, 'keywords')->textInput(['maxlength' => true]);
?>
                <?php 
echo $form->field($model, 'thumbnail')->textInput(['maxlength' => false, 'placeholder' => Yii::t('app', 'Must be at least 160x90 pixels and at most 1920x1080 pixels')]);
?>
                <?php 
echo $form->field($model, 'status')->dropDownList(PageData::getStatusOption());
?>
                <?php 
echo $form->field($model->page, 'show_description')->dropDownList(Core::getYesNoOption());
?>
                <?php 
echo $form->field($model->page, 'show_update_date')->dropDownList(Core::getYesNoOption());
?>
                <div class="form-group">
                    <p class="pull-left">
                        <?php 
echo Html::submitButton($model->scenario == 'create' ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->scenario == 'create' ? 'btn btn-success' : 'btn btn-primary']);
?>
                    </p>
                    <?php 
if (count($languages) > 0) {
コード例 #6
0
 /**
  * sitemap
  * @return mixed
  */
 public function actionSitemap()
 {
     /* header response */
     Yii::$app->response->format = Response::FORMAT_RAW;
     $headers = Yii::$app->response->headers;
     $headers->add('Content-Type', 'application/xml');
     /* begin */
     $sitemaps = [];
     /* blog sitemap */
     $query = Blog::find()->where(['status' => Blog::STATUS_PUBLISHED]);
     $countQuery = clone $query;
     $pagination = new Pagination(['totalCount' => $countQuery->count()]);
     $pagination->setPageSize(Yii::$app->params['sitemapPageSize']);
     $pages = $pagination->getPageCount();
     if ($pages > 0) {
         for ($i = 0; $i < $pages; $i++) {
             $sitemaps[] = Yii::$app->urlManager->createAbsoluteUrl(['/blog/sitemap', 'page' => $i + 1]);
         }
     }
     /* page sitemap */
     $query = PageData::find()->where(['status' => PageData::STATUS_ACTIVE]);
     $countQuery = clone $query;
     $pagination = new Pagination(['totalCount' => $countQuery->count()]);
     $pagination->setPageSize(Yii::$app->params['sitemapPageSize']);
     $pages = $pagination->getPageCount();
     if ($pages > 0) {
         for ($i = 0; $i < $pages; $i++) {
             $sitemaps[] = Yii::$app->urlManager->createAbsoluteUrl(['/page/sitemap', 'page' => $i + 1]);
         }
     }
     /* load modules sitemap */
     $modules = scandir(\Yii::$app->vendorPath . '/modernkernel');
     foreach ($modules as $module) {
         if (!preg_match('/[\\.]+/', $module)) {
             $moduleName = str_ireplace('yii2-', '', $module);
             if (method_exists(Yii::$app->getModule($moduleName), 'sitemap')) {
                 $sitemaps = array_merge($sitemaps, Yii::$app->getModule($moduleName)->sitemap());
             }
         }
     }
     return $this->renderPartial('sitemap', ['sitemaps' => $sitemaps]);
 }
コード例 #7
0
 /**
  * @return array|bool|mixed
  */
 public function getImageObject()
 {
     $key = 'cache_page_image_object_' . $this->id_page . '-' . $this->language;
     $img = Yii::$app->cache->get($key);
     if ($img === false) {
         $doc = new DOMDocument();
         $doc->loadHTML($this->content);
         $tags = $doc->getElementsByTagName('img');
         $img = [];
         foreach ($tags as $i => $tag) {
             $img['url'] = $tag->getAttribute('src');
             $img['width'] = $tag->getAttribute('width');
             $img['height'] = $tag->getAttribute('height');
             break;
         }
         /* cache */
         $sql = (new Query())->select('updated_at')->from(PageData::tableName())->where(['id_page' => $this->id_page, 'language' => $this->language])->createCommand()->rawSql;
         $dependency = new DbDependency();
         $dependency->sql = $sql;
         Yii::$app->cache->set($key, $img, 0, $dependency);
     }
     return $img;
 }
コード例 #8
0
ファイル: index.php プロジェクト: modernkernel/yii2-skeleton
//$this->registerJs($js);
//$css=file_get_contents(__DIR__.'/index.css');
//$this->registerCss($css);
?>
<div class="page-index">
    <div class="box box-primary">
        <div class="box-body">
            <?php 
Pjax::begin();
?>
    <?php 
echo GridView::widget(['options' => ['class' => 'grid-view table-responsive'], 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id_page', ['attribute' => 'language', 'value' => function ($model) {
    return Message::getLocaleList()[$model->language];
}, 'filter' => Message::getLocaleList()], 'title', 'description', ['attribute' => 'status', 'value' => function ($model) {
    return $model->statusText;
}, 'filter' => PageData::getStatusOption()], ['class' => 'yii\\grid\\ActionColumn']]]);
?>
            <?php 
Pjax::end();
?>

            <p>
                <?php 
echo Html::a(Yii::t('app', 'Add new Page'), ['/page/create'], ['class' => 'btn btn-success']);
?>
            </p>
        </div>
        <!-- Loading (remove the following to stop the loading)-->
        <div class="overlay grid-view-overlay hidden">
            <i class="fa fa-refresh fa-spin"></i>
        </div>