示例#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;
 }
示例#2
0
 /**
  * Get Posts by one tag 
  * @param type $tag (e.g : tag1 )
  * @return type
  */
 public function getPostsbyTag($tag)
 {
     return Posts::find()->where('FIND_IN_SET(:tag, tags)', [':tag' => $tag])->all();
 }
 public function actionUserposts($userid)
 {
     $posts = Posts::find()->where(['user_created' => $userid])->all();
     $PostModel = new Posts();
     $userModel = new $PostModel->module->userModel();
     $user = $userModel::findOne(['id' => $userid]);
     if ($user) {
         $username = $user->{$PostModel->module->userNameField};
         $dataProvider = new ArrayDataProvider(['allModels' => $posts, 'sort' => ['attributes' => ['id']], 'pagination' => ['pageSize' => 20]]);
         return $this->render('userposts', ['dataProvider' => $dataProvider, 'username' => $username]);
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }