public function down() { $this->dropTable(Rubric::tableName()); $this->dropTable(RubricTranslate::tableName()); $this->dropTable(Post::tableName()); $this->dropTable(PostTranslate::tableName()); }
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; }
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; }
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; }
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); } }
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)]); } }