Exemplo n.º 1
0
 public function down()
 {
     $this->dropTable(Rubric::tableName());
     $this->dropTable(RubricTranslate::tableName());
     $this->dropTable(Post::tableName());
     $this->dropTable(PostTranslate::tableName());
 }
Exemplo n.º 2
0
 public function search($params)
 {
     $query = Post::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(PostTranslate::tableName() . ' as tr ', '' . Post::tableName() . '.id = tr.post_id AND tr.language = \'' . Yii::$app->language . '\'');
     $query->andWhere(['like', 'tr.title', $this->title]);
     $this->addCondition($query, 'alias', true);
     $this->addCondition($query, 'views', true);
     $this->addCondition($query, 'status', true);
     $this->addCondition($query, 'author_id', true);
     return $dataProvider;
 }
Exemplo n.º 3
0
 protected function getTranslateModel($id, $lang)
 {
     $translate = PostTranslate::find()->where(['post_id' => $id, 'language' => $lang])->one();
     if (!$translate) {
         $translate = new PostTranslate();
         $translate->post_id = $id;
         $translate->language = $lang;
     }
     return $translate;
 }
Exemplo n.º 4
0
Arquivo: Post.php Projeto: tpoxa/cmars
 public static function getPostByAlias($alias)
 {
     if ($alias) {
         $sql = "SELECT p.id, pt.full_text, pt.title, pt.meta_title,\n                    pt.meta_descriptions, pt.meta_keywords, pt.preview_text\n                FROM " . Post::tableName() . " as p\n                LEFT JOIN " . PostTranslate::tableName() . " as pt\n                   ON p.id = pt.post_id\n                WHERE pt.language = :lang\n                    AND p.alias = :alias AND p.app_id =:app_id ";
         return PostTranslate::findBySql($sql, [':lang' => Yii::$app->language, ':alias' => $alias, ':app_id' => \Yii::$app->getModule('cms')->app_id])->one();
         $serch = new PostSearch();
         $serch->search([]);
     }
     return false;
 }