Пример #1
0
 public function getResults($filter = null)
 {
     $renderedRewards = [];
     $rewards = Reward::isActive();
     $user = Auth::getUser();
     switch ($filter) {
         case 'qty':
             $rewards->where('inventory', '>', 0);
             break;
         case 'time':
             $rewards->whereNotNull('date_begin');
             $rewards->whereNotNull('date_end');
             break;
         case 'bookmarked':
             $rewards->whereHas('bookmarks', function ($query) use($user) {
                 $query->where('user_id', '=', $user->id);
             });
             break;
         case 'all':
         default:
             $rewards->whereIn('id', function ($query) {
                 $query->select('id')->from(with(new Reward())->getTable())->whereNull('inventory')->orWhere('inventory', '>', 0);
             })->whereIn('id', function ($query) {
                 $query->select('id')->from(with(new Reward())->getTable())->whereNull('date_begin')->whereNull('date_end');
             })->whereIn('id', function ($query) {
                 $query->select('id')->from(with(new Reward())->getTable())->where('date_begin', '<=', date('c'))->where('date_end', '>=', date('c'))->where('is_published', '>', 0)->where('inventory', '>', 0);
             }, 'or');
             break;
     }
     $rewards = $rewards->orderBy('points')->paginate($this->property('limit'));
     foreach ($rewards as $reward) {
         $renderedRewards[] = ['rendered' => View::make('dma.friends::rewardPreview', ['reward' => $reward, 'user' => $user, 'allowRedeem' => LocationManager::enableAction()])->render(), 'id' => $reward->id];
     }
     return ['links' => $rewards->render(), 'rewards' => $renderedRewards];
 }