Beispiel #1
0
 /**
  * Setup additional filters
  */
 public function setupFilters()
 {
     if (in_array('entry_files', $this->filters)) {
         $fileSelector = (new \yii\db\Query())->select(["id"])->from('file')->where('file.object_model=content.object_model AND file.object_id=content.object_id')->limit(1);
         $fileSelectorSql = Yii::$app->db->getQueryBuilder()->build($fileSelector)[0];
         $this->activeQuery->andWhere('(' . $fileSelectorSql . ') IS NOT NULL');
     }
     // Setup Post specific filters
     if (in_array('posts_links', $this->filters)) {
         $this->activeQuery->leftJoin('post', 'content.object_id=post.id AND content.object_model=:postModel', ['postModel' => \humhub\modules\post\models\Post::className()]);
         $this->activeQuery->andWhere("post.url is not null");
     }
     // Only apply archived filter when we should load more than one entry
     if ($this->limit != 1) {
         if (!in_array('entry_archived', $this->filters)) {
             $this->activeQuery->andWhere("(content.archived != 1 OR content.archived IS NULL)");
         }
     }
     // Show only mine items
     if (in_array('entry_mine', $this->filters) && $this->user !== null) {
         $this->activeQuery->andWhere(['content.created_by' => $this->user->id]);
     }
     // Show only items where the current user is involed
     if (in_array('entry_userinvoled', $this->filters) && $this->user !== null) {
         $this->activeQuery->leftJoin('user_follow', 'content.object_model=user_follow.object_model AND content.object_id=user_follow.object_id AND user_follow.user_id = :userId', ['userId' => $this->user->id]);
         $this->activeQuery->andWhere("user_follow.id IS NOT NULL");
     }
     if (in_array('model_posts', $this->filters)) {
         $this->activeQuery->andWhere(["content.object_model" => \humhub\modules\post\models\Post::className()]);
     }
     // Visibility filters
     if (in_array('visibility_private', $this->filters)) {
         $this->activeQuery->andWhere(['content.visibility' => Content::VISIBILITY_PRIVATE]);
     }
     if (in_array('visibility_public', $this->filters)) {
         $this->activeQuery->andWhere(['content.visibility' => Content::VISIBILITY_PUBLIC]);
     }
 }