コード例 #1
0
ファイル: EntryListing.php プロジェクト: vigm/advancedMD
 /**
  * Given various filters and permissions, sets up an entries Query\Builder
  * to be passed on to the caller to optionally add more filtering to
  */
 protected function setupEntries()
 {
     $entries = ee('Model')->get('ChannelEntry')->filter('site_id', $this->site_id);
     // We need to filter by Channel first (if necissary) as that will
     // impact the entry count for the perpage filter
     $channel_id = $this->channel_filter->value();
     // If we have a selected channel filter, and we are not an admin, we
     // first need to ensure it is in the list of assigned channels. If it
     // is we will filter by that id. If not we throw an error.
     $channel = NULL;
     if ($channel_id) {
         if ($this->is_admin || in_array($channel_id, $this->allowed_channels)) {
             $entries->filter('channel_id', $channel_id);
             $channel = ee('Model')->get('Channel', $channel_id)->first();
             $channel_name = $channel->channel_title;
         } else {
             show_error(lang('unauthorized_access'));
         }
     } else {
         if (!$this->is_admin) {
             if (empty($this->allowed_channels)) {
                 show_error(lang('no_channels'));
             }
             $entries->filter('channel_id', 'IN', $this->allowed_channels);
         }
     }
     if ($this->category_filter->value()) {
         $entries->with('Categories')->filter('Categories.cat_id', $this->category_filter->value());
     }
     if ($this->status_filter->value()) {
         $entries->filter('status', $this->status_filter->value());
     }
     if (!empty($this->search_value)) {
         $entries->filter('title', 'LIKE', '%' . $this->search_value . '%');
     }
     $filter_values = $this->filters->values();
     if (!empty($filter_values['filter_by_date'])) {
         if (is_array($filter_values['filter_by_date'])) {
             $entries->filter('entry_date', '>=', $filter_values['filter_by_date'][0]);
             $entries->filter('entry_date', '<', $filter_values['filter_by_date'][1]);
         } else {
             $entries->filter('entry_date', '>=', $this->now - $filter_values['filter_by_date']);
         }
     }
     $entries->with('Autosaves', 'Categories', 'Author', 'Channel');
     $this->entries = $entries;
 }