Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Posts::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'full_image' => $this->full_image, 'user_created' => $this->user_created, 'user_last_change' => $this->user_last_change, 'publish' => $this->publish]);
     if ($this->created_at) {
         $date_cr = date('d-m-Y', (double) $this->created_at);
     } else {
         $date_cr = '';
     }
     if ($this->updated_at) {
         $date_up = date('d-m-Y', (double) $this->updated_at);
     } else {
         $date_up = '';
     }
     if ($this->category) {
         $categoryArray = explode(",", $this->category);
         $query->andFilterWhere(['in', 'category', $categoryArray]);
     }
     $query->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'intro_text', $this->intro_text])->andFilterWhere(['like', 'full_text', $this->full_text])->andFilterWhere(['like', 'intro_image', $this->intro_image])->andFilterWhere(['like', "date_format(date(from_unixtime(created_at)) ,'%d-%m-%Y' )", $date_cr])->andFilterWhere(['like', "date_format(date(from_unixtime(updated_at)) ,'%d-%m-%Y' )", $date_up]);
     return $dataProvider;
 }
Example #2
0
 /**
  * Find similar Posts by tags
  * @param type $id
  */
 public function findSimilarPosts($id)
 {
     $model = Posts::findOne($id);
     $posts = $this->getPostsbyTags($model->tags);
     $newPosts = [];
     foreach ($posts as $key => $post) {
         if ($post->id != $id) {
             $newPosts[] = $post;
         }
     }
     return $newPosts;
 }
 /**
  * Finds the Posts model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Posts the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Posts::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }