コード例 #1
0
ファイル: PostController.php プロジェクト: tampaphp/app-cms
 /**
  * Lists all Post models on specific post type.
  * If there is user, the action will generate list of all Post models based on user.
  *
  * @param integer     $post_type
  * @param null|string $user
  *
  * @throws \yii\web\ForbiddenHttpException
  * @throws \yii\web\NotFoundHttpException
  * @return mixed
  */
 public function actionIndex($post_type, $user = null)
 {
     $postType = $this->findPostType($post_type);
     $searchModel = new PostSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $post_type, $user);
     if (!Yii::$app->user->can($postType->post_type_permission)) {
         throw new ForbiddenHttpException(Yii::t('writesdown', 'You are not allowed to perform this action.'));
     }
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'postType' => $postType, 'user' => $user]);
 }
コード例 #2
0
ファイル: Media.php プロジェクト: writesdown/app-cms
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = MediaModel::find();
     $query->innerJoinWith(['mediaAuthor' => function ($query) {
         /* @var $query \yii\db\ActiveQuery */
         return $query->from(['user' => User::tableName()]);
     }])->from(['media' => $this->tableName()]);
     $query->leftJoin(['post' => Post::tableName()], 'media.post_id = post.id');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->setSort(['attributes' => ArrayHelper::merge($dataProvider->sort->attributes, ['username' => ['asc' => ['username' => SORT_ASC], 'desc' => ['username' => SORT_DESC], 'label' => 'Author', 'value' => 'username']]), 'defaultOrder' => ['id' => SORT_DESC]]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['media.id' => $this->id, 'media.author' => $this->author, 'post_id' => $this->post_id, 'media.comment_count' => $this->comment_count]);
     $query->andFilterWhere(['like', 'media.title', $this->title])->andFilterWhere(['like', 'media.excerpt', $this->excerpt])->andFilterWhere(['like', 'media.content', $this->content])->andFilterWhere(['like', 'media.password', $this->password])->andFilterWhere(['like', 'media.slug', $this->slug])->andFilterWhere(['like', 'mime_type', $this->mime_type])->andFilterWhere(['like', 'media.comment_status', $this->comment_status])->andFilterWhere(['like', 'media.date', $this->date])->andFilterWhere(['like', 'media.modified', $this->modified])->andFilterWhere(['like', 'post.title', $this->post_title])->andFilterWhere(['like', 'user.username', $this->username]);
     return $dataProvider;
 }
コード例 #3
0
ファイル: Media.php プロジェクト: ochiem/app-cms
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = MediaModel::find()->from(['media' => $this->tableName()]);
     $query->innerJoinWith(['mediaAuthor' => function ($query) {
         /* @var $query \yii\db\ActiveQuery */
         return $query->from(['author' => User::tableName()]);
     }]);
     $query->leftJoin(['post' => Post::tableName()], 'media.media_post_id = post.id');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->setSort(['attributes' => ArrayHelper::merge($dataProvider->sort->attributes, ['username' => ['asc' => ['username' => SORT_ASC], 'desc' => ['username' => SORT_DESC], 'label' => 'Author', 'value' => 'username']]), 'defaultOrder' => ['id' => SORT_DESC]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'media_author' => $this->media_author, 'media_post_id' => $this->media_post_id, 'media_comment_count' => $this->media_comment_count]);
     $query->andFilterWhere(['like', 'media_title', $this->media_title])->andFilterWhere(['like', 'media_excerpt', $this->media_excerpt])->andFilterWhere(['like', 'media_content', $this->media_content])->andFilterWhere(['like', 'media_password', $this->media_password])->andFilterWhere(['like', 'media_slug', $this->media_slug])->andFilterWhere(['like', 'media_mime_type', $this->media_mime_type])->andFilterWhere(['like', 'media_comment_status', $this->media_comment_status])->andFilterWhere(['like', 'media_date', $this->media_date])->andFilterWhere(['like', 'media_modified', $this->media_modified])->andFilterWhere(['like', 'post.post_title', $this->post_title])->andFilterWhere(['like', 'author.username', $this->username]);
     return $dataProvider;
 }
コード例 #4
0
ファイル: PostComment.php プロジェクト: hdushku/app-cms
 /**
  * Creates data provider instance with search query applied
  *
  * @param array    $params
  *
  * @param int      $post_type
  * @param int|null $post_id
  *
  * @return ActiveDataProvider
  */
 public function search($params, $post_type, $post_id = null)
 {
     $query = PostCommentModel::find();
     $query->innerJoinWith(['commentPost' => function ($query) {
         /* @var $query \yii\db\ActiveQuery */
         return $query->from(['post' => Post::tableName()]);
     }]);
     $query->andWhere(['post.post_type' => $post_type]);
     if ($post_id) {
         $query->andWhere(['post.id' => $post_id]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'comment_post_id' => $this->comment_post_id, 'comment_parent' => $this->comment_parent, 'comment_user_id' => $this->comment_user_id]);
     $query->andFilterWhere(['like', 'comment_author', $this->comment_author])->andFilterWhere(['like', 'comment_author_email', $this->comment_author_email])->andFilterWhere(['like', 'comment_author_url', $this->comment_author_url])->andFilterWhere(['like', 'comment_author_ip', $this->comment_author_ip])->andFilterWhere(['like', 'comment_content', $this->comment_content])->andFilterWhere(['like', 'comment_approved', $this->comment_approved])->andFilterWhere(['like', 'comment_agent', $this->comment_agent])->andFilterWhere(['like', 'comment_date', $this->comment_date])->andFilterWhere(['like', 'post.post_title', $this->post_title]);
     return $dataProvider;
 }
コード例 #5
0
ファイル: PostController.php プロジェクト: hdushku/npai
 /**
  * Lists all Post models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new PostSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }