コード例 #1
0
 public function down()
 {
     $this->dropTable(Rubric::tableName());
     $this->dropTable(RubricTranslate::tableName());
     $this->dropTable(Post::tableName());
     $this->dropTable(PostTranslate::tableName());
 }
コード例 #2
0
 public function down()
 {
     $this->addColumn(\tpoxa\cmars\models\Post::tableName(), 'section_id', 'INT NOT NULL');
     $this->dropColumn(\tpoxa\cmars\models\Post::tableName(), 'app_id');
     $this->dropColumn(\tpoxa\cmars\models\Rubric::tableName(), 'app_id');
     return true;
 }
コード例 #3
0
ファイル: Rubric.php プロジェクト: tpoxa/cmars
 public static function getRubricsForSelect($app_id = 0)
 {
     $sections = [];
     $sql = "SELECT s.id, st.title\n                FROM " . Rubric::tableName() . " as s\n                LEFT JOIN " . RubricTranslate::tableName() . " as st\n                   ON s.id = st.rubric_id\n                WHERE st.language = :lang and s.app_id = :app_id\n                    \n        ";
     $models = RubricTranslate::findBySql($sql, [':lang' => Yii::$app->language, ':app_id' => $app_id])->all();
     foreach ($models as $model) {
         $sections[$model->id] = $model->title;
     }
     return $sections;
 }
コード例 #4
0
ファイル: RubricSearch.php プロジェクト: tpoxa/cmars
 public function search($params)
 {
     $query = Rubric::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $this->recordsPerPage]]);
     $query->andWhere(['app_id' => \Yii::$app->getModule('cms')->app_id]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->leftJoin(RubricTranslate::tableName() . ' as tr ', '' . Rubric::tableName() . '.id = tr.rubric_id AND tr.language = \'' . Yii::$app->language . '\'');
     $query->andWhere(['like', 'tr.title', $this->title]);
     $query->andWhere(['like', Rubric::tableName() . '.name', $this->name]);
     return $dataProvider;
 }
コード例 #5
0
ファイル: RubricsController.php プロジェクト: tpoxa/cmars
 protected function findModel($id)
 {
     if (is_array($id)) {
         $model = Rubric::find()->where(['id' => $id])->all();
     } else {
         $model = Rubric::findOne($id);
     }
     if ($model !== null) {
         return $model;
     } else {
         throw new HttpException(404);
     }
 }
コード例 #6
0
ファイル: PostsController.php プロジェクト: tpoxa/cmars
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $model->setScenario('admin-edit-page-static');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $lang = $this->prepareLang(Yii::$app->request->post());
         $translate = $this->getTranslateModel($model->id, $lang);
         if ($translate->load(Yii::$app->request->post()) && $translate->save()) {
             Yii::$app->session->setFlash('success', Yii::t('posts', 'Post \'{id}\' successfully updated', ['id' => $model->id]));
         }
         return $this->redirect(['index']);
     } else {
         $translates = [];
         foreach (Yii::$app->params['languages'] as $lang => $val) {
             $translates[] = $this->getTranslateModel($id, $lang);
         }
         $postStatuses = Post::getStatusArray();
         return $this->render('create', ['model' => $model, 'translates' => $translates, 'postStatuses' => $postStatuses, 'rubrics' => Rubric::getRubricsForSelect($model->app_id)]);
     }
 }