/** * Produce a collection of Activities based on recommendations and filters */ private function getResults($filterstr = null) { $perpage = 12; if ($filterstr && $filterstr != 'all') { $filters = json_decode($filterstr, true); if ($filters && is_array($filters['categories'])) { $results = Activity::isActive()->byCategory($filters['categories'])->paginate($perpage); } else { $results = Activity::isActive()->paginate($perpage); } } else { $results = Activity::isActive()->paginate($perpage); } $this->page['activities'] = $results; $this->page['hasLinks'] = $results->hasMorePages() || $results->currentPage() > 1; $this->page['links'] = $results->render(); }
/** * Produce a collection of Activities based on recommendations and filters */ private function getResults($filterstr = null) { $user = Auth::getUser(); $perpage = 12; $dayNames = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']; $restrictions = []; if ($filterstr && $filterstr != 'all') { $filters = json_decode($filterstr, true); if ($filters && is_array($filters['categories'])) { $results = Activity::isActive()->ignored($user)->byCategory($filters['categories'])->paginate($perpage); } else { $results = Activity::isActive()->ignored($user)->paginate($perpage); } } else { $results = Activity::isActive()->ignored($user)->paginate($perpage); } foreach ($results as $index => $result) { $string = ''; $type = $result->time_restriction; $time = $result->time_restriction_data; if ($type == 1) { $days = []; foreach ($time['days'] as $key => $value) { if ($value > 0) { $days[] .= $dayNames[$key - 1]; } } $len = count($days); switch ($len) { case 0: break; case 1: $string = $days[0]; break; case 2: $string = implode(' and ', $days); break; default: $last = array_pop($days); $string = implode(', ', $days) . ' and ' . $last; } $string .= ' at '; $string .= strtolower($time['start_time'] . '–' . $time['end_time']); } elseif ($type == 2) { $start = date('M j, Y', strtotime($result->date_begin)); $end = date('M j, Y', strtotime($result->date_end)); if ($start == $end) { $start = date('M j, Y g:i a', strtotime($result->date_begin)); $end = date('M j, Y g:i a', strtotime($result->date_end)); if ($start == $end) { $string = $start; } else { $end = date('g:i a', strtotime($result->date_end)); } } if (!$string) { $string = $start . ' to ' . $end; } } $restrictions[$index] = $string; } $this->page['activities'] = $results; $this->page['activity_count'] = $results->count(); $this->page['restrictions'] = $restrictions; $this->page['hasLinks'] = $results->hasMorePages() || $results->currentPage() > 1; $this->page['links'] = $results->render(); }
/** * Determine if an activity is capable of being completed * * @param Activity * An activity model * * @return boolean * returns true if an activity can be completed by the user */ public static function canComplete(Activity $activity, User $user) { if (!$activity->isActive()) { return false; } // Check activity lockout if ($activity->activity_lockout && ($pivot = $user->activities()->where('activity_id', $activity->id)->first())) { $time = Carbon::now(); $lastTime = $pivot->pivot->created_at; if ($time->diffInMinutes($lastTime) < $activity->activity_lockout) { $x = $time->diffInMinutes($lastTime->addMinutes($activity->activity_lockout)); $message = self::convertToHoursMins($x, '%d hours and %02d minutes'); Session::put('activityError', Lang::get('dma.friends::lang.activities.lockout', ['x' => $message])); return false; } } switch ($activity->time_restriction) { case Activity::TIME_RESTRICT_NONE: return true; case Activity::TIME_RESTRICT_HOURS: if ($activity->time_restriction_data) { $now = Carbon::now(); $start = self::convertTime($activity->time_restriction_data['start_time']); $end = self::convertTime($activity->time_restriction_data['end_time']); $start_time = Carbon::now(); $start_time->setTime($start['hour'], $start['minutes']); $end_time = Carbon::now(); $end_time->setTime($end['hour'], $start['minutes']); $day = date('w'); // Sunday is on the end of the week and date sets sunday as 0 if ($day == 0) { $day = 7; } if ($activity->time_restriction_data['days'][$day] !== false && $now->gte($start_time) && $now->lte($end_time)) { return true; } else { Session::put('activityError', Lang::get('dma.friends::lang.activities.notAvailable')); } } break; case Activity::TIME_RESTRICT_DAYS: $now = new DateTime('now'); if ($now >= $activity->date_begin && $now <= $activity->date_end) { return true; } else { Session::put('activityError', Lang::get('dma.friends::lang.activities.notAvailable')); } break; } return false; }