/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { \Session::put('currentSerie', $id); $series = loadSerieWithIdOrTitle($id); if (empty($series)) { flash()->error('That series does not exist.')->important(); return redirect('series'); } elseif (count($series) > 1) { //special case must be caught where multiple series exist with same title but only 1 serie contains exercises // -> redirect immediately $break = false; $serie = null; foreach ($series as $s) { $condition = (SerieContainsExercises($s->id) or $s->makerId == Auth::id()); if ($break and $condition) { return view('series.duplicates', compact('series')); } elseif ($condition) { $break = true; $serie = $s; } } $type = loadType2($serie->tId)[0]; $exercises = loadExercisesFromSerie($serie->id); return view('series.show', compact('serie', 'exercises', 'type')); } elseif (!SerieContainsExercises($series[0]->id) and !isMakerOfSeries($series[0]->id, Auth::id())) { flash()->error('No exercises were found for this series. Come back later...')->important(); return redirect('series/'); } else { $serie = $series[0]; $type = loadType2($serie->tId)[0]; $exercises = loadExercisesFromSerie($serie->id); return view('series.show', compact('serie', 'exercises', 'type')); } }
function returnAccomplishedPercentageSeries($user, $serie) { $allExercises = loadExercisesFromSerie($serie->id); $totalExercises = count($allExercises); $count = 0; foreach ($allExercises as $exercise) { if (userCompletedExercise($exercise->id, $user->id)) { $count += 1; } } return $totalExercises == 0 ? 0 : 100 * $count / $totalExercises; //result in percentage }