Beispiel #1
0
 public function fetch($page = 1, $take = 10, $callback = null)
 {
     if (is_null($callback)) {
         $callback = function (&$model, $host) {
             $model = $model->with('items')->mycollections();
         };
     }
     $list = parent::fetch($page, $take, $callback);
     $host = $this;
     $list->each(function ($collection) use($host) {
         $collection->items->each(function ($item) use($host) {
             $host->setCollectionItemLinks($item);
         });
     });
     return $list;
 }
Beispiel #2
0
 public function fetch($page = 1, $take = 10, $callback = null)
 {
     if (is_null($callback)) {
         $callback = function (&$model, $host) {
             $model = $model->with(array('contentmetas', 'categories', 'author' => function ($query) {
                 $query->select('users.id', 'users.username');
             }))->where(function ($query) use($host) {
                 $query->where('content_type', '=', $host->getContentType())->where('lang', '=', $host->getLocale());
                 if ($host->is_guest()) {
                     $dateTime = new \DateTime();
                     $now = $dateTime->format('Y-m-d H:i:s');
                     // $query->where('status','=','published');
                     $query->where('publish_date', '<', $now);
                     $query->where('status', '=', 'published');
                 } else {
                     if (!$host->is_moderator()) {
                         //fetch only content belongs to user
                         $query->where('author_id', '=', $host->getAuthorId());
                     }
                 }
             });
         };
     }
     $result = parent::fetch($page, $take, $callback);
     if ($result) {
         $host = $this;
         $result->each(function ($item) use($host) {
             $host->prepareContentItem($item);
         });
     }
     return $result;
 }