This repository has been archived on 2021-09-15. You can view files and clone it, but cannot push or open issues or pull requests.
ModuleWeb/SRC/app/Http/Controllers/GameController.php

105 lines
3.0 KiB
PHP
Raw Normal View History

2015-03-18 13:47:15 +00:00
<?php namespace App\Http\Controllers;
2015-03-20 18:18:24 +00:00
use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundException;
2015-03-18 13:47:15 +00:00
use Response;
use App\Referent;
use App\ConfigJeu;
use App\Oeuvre;
use Cookie;
2015-03-20 17:55:56 +00:00
2015-03-18 13:47:15 +00:00
class GameController extends Controller {
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Show the application dashboard to the user.
*
* @return Response
*/
public function chooseDifMemo() {
2015-03-20 17:55:56 +00:00
return view('frontend/memo_level');
}
public function chooseDifPuzzle() {
return view('frontend/puzzle_level');
2015-03-18 13:47:15 +00:00
}
public function playMemo($niveau) {
$idRef = Cookie::get('referent');
$configjeu = Referent::find($idRef)->configjeu()->where('actifMemo', '=', '1')->first();
if($configjeu && count($configjeu->oeuvres) >= 1) {
$oes = $configjeu->oeuvres;
2015-03-18 14:06:07 +00:00
$params = json_decode($configjeu->parametres);
$bloc = $params->{"m".$niveau};
2015-03-18 13:47:15 +00:00
} else {
$oes = Oeuvre::orderByRaw("RAND()")->take(8)->get();
2015-03-18 14:06:07 +00:00
if($niveau == 1) {$bloc = 2;} elseif($niveau == 2){$bloc = 3;} else {$bloc = 4;}
2015-03-18 13:47:15 +00:00
}
2015-03-18 14:06:07 +00:00
return view('frontend/memo', ['oeuvres' => $oes, 'niveau' => $niveau, 'nbBloc'=>$bloc]);
2015-03-18 13:47:15 +00:00
}
public function playPuzzle($niveau) {
2015-03-20 17:55:56 +00:00
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();
2015-03-18 13:47:15 +00:00
$nbTab = 3;
$dimension = 2;
}
2015-03-20 17:55:56 +00:00
return view('frontend/puzzle', ['oeuvres' => $oes, 'dimension' => $dimension, 'nbTab' => $nbTab, 'niveau' => $niveau]);
2015-03-18 13:47:15 +00:00
}
2015-03-20 17:55:56 +00:00
public function index() {
$res = User::referents()->get();
return view('home', ['referent' => $res]);
2015-03-18 13:47:15 +00:00
}
2015-03-20 17:59:24 +00:00
public function setRecords($idTrophee) {
$values = Cookie::get('trophee');
if ($values === false)
$values = [0, 0, 0];
switch ($idTrophee) {
case '1':
2015-03-20 18:28:49 +00:00
$values[0] = intval($values[0]) + 1;
2015-03-20 17:59:24 +00:00
break;
case '2':
2015-03-20 18:28:49 +00:00
$values[1] = intval($values[1]) + 1;
2015-03-20 17:59:24 +00:00
break;
case '3':
2015-03-20 18:28:49 +00:00
$values[2] = intval($values[2]) + 1;;
2015-03-20 17:59:24 +00:00
break;
default:
break;
}
2015-03-20 18:51:35 +00:00
return Response::make('all good!')->withCookie(Cookie::forever('trophee', $values));
2015-03-20 17:59:24 +00:00
}
2015-03-18 13:47:15 +00:00
}