Ejemplo n.º 1
0
 public static function pagination($id)
 {
     $url_actual = "http://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
     $url_actual = explode('?', $url_actual);
     $pag = Round::join('rb_team as te', 'te.id', '=', 'rb_rounds.team_id')->join('rb_stages as st', 'st.id', '=', 'rb_rounds.stage_id')->where('rb_rounds.challenge_id', '=', $id)->select('te.name as teamName', 'te.robot_name', 'rb_rounds.*', 'st.name as stageName')->orderBy('rb_rounds.id', 'ASC')->paginate(env('PAG'));
     $pag->setPath($url_actual[0]);
     return $pag;
 }
 public function getSortableRounds($sort = 'date', $direction = 'asc', $userId = null)
 {
     if (!in_array($sort, ['user_name', 'date', 'course_name', 'tee_type_name', 'strokes'])) {
         $sort = 'date';
     }
     $rounds = Round::join('users', 'users.id', '=', 'rounds.user_id')->join('scores', 'scores.round_id', '=', 'rounds.id')->join('tee_sets', 'tee_sets.id', '=', 'rounds.tee_set_id')->join('tee_types', 'tee_types.id', '=', 'tee_sets.tee_type_id')->join('courses', 'courses.id', '=', 'tee_sets.course_id')->select('rounds.id', 'rounds.date', 'rounds.user_id', 'users.name as user_name', DB::raw('sum(scores.strokes) as strokes'), DB::raw('sum(scores.putts) as putts'), 'tee_types.name as tee_type_name', 'courses.slug as course_slug', 'courses.name as course_name');
     if ($userId) {
         $rounds->where('users.id', '=', $userId);
     }
     return $rounds->orderBy($sort, $direction)->groupBy('rounds.id', 'users.id', 'tee_types.id', 'courses.id')->paginate(10);
 }
 public function getUserBestRounds($courseId, $userId)
 {
     return Round::join('scores', 'scores.round_id', '=', 'rounds.id')->join('tee_sets', 'tee_sets.id', '=', 'rounds.tee_set_id')->join('courses', 'courses.id', '=', 'tee_sets.course_id')->where('courses.id', '=', $courseId)->where('rounds.user_id', $userId)->select('rounds.id', 'rounds.date', 'rounds.user_id', 'courses.slug as course_slug', 'courses.name as course_name', DB::raw('sum(scores.strokes) as total_strokes'))->groupBy('rounds.id', 'courses.id')->orderBy('total_strokes', 'asc')->orderBy('rounds.date', 'desc')->take(5)->get();
 }