diff --git a/SRC/app/Http/Controllers/GameController.php b/SRC/app/Http/Controllers/GameController.php index d3722a0..d1eb1a6 100755 --- a/SRC/app/Http/Controllers/GameController.php +++ b/SRC/app/Http/Controllers/GameController.php @@ -5,7 +5,6 @@ use App\Referent; use App\ConfigJeu; use App\Oeuvre; use Cookie; - class GameController extends Controller { /** @@ -24,10 +23,8 @@ class GameController extends Controller { * @return Response */ public function chooseDifMemo() { - return view('frontend/memo_level'); - } - public function chooseDifPuzzle() { - return view('frontend/puzzle_level'); + $nbOr = Cookie::get('referent'); + return view('frontend/memo_level', ['nbOr' => $nbOr]); } public function playMemo($niveau) { @@ -46,30 +43,98 @@ class GameController extends Controller { return view('frontend/memo', ['oeuvres' => $oes, 'niveau' => $niveau, 'nbBloc'=>$bloc]); } + public function chooseDifPuzzle() { + return view('frontend/puzzle_level'); + } public function playPuzzle($niveau) { - try { - $idRef = Cookie::get('referent'); - $ref = Referent::findOrFail($idRef); - $configjeu = $ref->configjeu()->where('actifPuzzle', '=', '1')->firstOrFail(); - if(count($configjeu->oeuvres->count()) >= 1) { - $oes = $configjeu->oeuvres()->select('image')->get(); - $params = json_decode($configjeu->parametres); - $nbTab = $params->pt; - $dimension = $params->{"p" . $niveau}; - if(!(isset($dimension) && is_numeric($dimension))) throw new ModelNotFoundException(); - } else throw new ModelNotFoundException(); - } catch(ModelNotFoundException $e) { - $oes = Oeuvre::orderByRaw("RAND()")->take(5)->select('image')->get(); + $idRef = Cookie::get('referent'); + $ref = Referent::find($idRef); + + $configjeu = $ref->configjeu()->where('actifPuzzle', '=', '1')->first(); + + if($configjeu && count($configjeu->oeuvres) >= 1) { + $oes = $configjeu->oeuvres; + $params = json_decode($configjeu->parametres); + $nbTab = $params->pt; + $dimension = $params->{ "p".$niveau}; + + } else { + $oes = Oeuvre::orderByRaw("RAND()")->take(5)->get(); $nbTab = 3; $dimension = 2; } - return view('frontend/puzzle', ['oeuvres' => $oes, 'dimension' => $dimension, 'nbTab' => $nbTab, 'niveau' => $niveau]); + + return view('frontend/puzzle', ['oeuvres' => $oes, 'dimension' => $dimension, 'nbTab' => $nbTab]); + + } + public function index() + { + $res = User::referents()->get(); + return view('home',['referent' => $res]); + } + + public function findReferents($reg) { + + $res = User::referents()->name($reg)->get(); + return Response::json($res->toArray()); + } + + /** + * Show referent games + * + * @param String $id + * @return Response + */ + public function showReferentGames($id) + { + $listeOeuvre = $ListeOeuvre = ListeOeuvre::ofUser($id)->activeListOeuvre()->first(); + if($listeOeuvre == '') + $games = []; + else + $games = $listeOeuvre->jeux()->get(); + + return view('referent_games', ['games' => $games]); } - public function index() { - $res = User::referents()->get(); - return view('home', ['referent' => $res]); + /** + * Show one referent game + * + * @param String $id + * @param String $idGame + * @return Response + */ + public function showOneReferentGame($id, $idGame) + { + return view('one_referent_game', ['referent' => $id, 'game' => $idGame]); } + + public function setRecords($idTrophee) { + + $values = Cookie::get('trophee'); + + if ($values === false) + $values = [0, 0, 0]; + + switch ($idTrophee) { + + case '1': + $values[0]++; + break; + + case '2': + $values[1]++; + break; + + case '3': + $values[2]++; + break; + + default: + break; + } + $response->withCookie(Cookie::forever('trophee', $values)); + } + } diff --git a/SRC/app/Http/routes.php b/SRC/app/Http/routes.php index c0a86fe..8982cbd 100755 --- a/SRC/app/Http/routes.php +++ b/SRC/app/Http/routes.php @@ -21,7 +21,7 @@ Route::get('api/searchOeuvres', 'APIController@searchOeuvres'); //API FOR IMAGE RESIZE Route::get('/image/{size}/{url}', 'ImageController@getImage'); -Route::get('/setRecords/{idTrophee}','GameController@setRecords') +Route::get('/setRecords/{idTrophee}','GameController@setRecords'); // LOGIN RESET