2015-03-18 14:47:15 +01:00
|
|
|
<?php namespace App\Http\Controllers;
|
2015-03-20 19:18:24 +01:00
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundException;
|
2015-03-18 14:47:15 +01:00
|
|
|
use Response;
|
|
|
|
use App\Referent;
|
|
|
|
use App\ConfigJeu;
|
|
|
|
use App\Oeuvre;
|
|
|
|
use Cookie;
|
2015-03-20 18:55:56 +01:00
|
|
|
|
2015-03-18 14:47:15 +01: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 18:55:56 +01:00
|
|
|
return view('frontend/memo_level');
|
|
|
|
}
|
|
|
|
public function chooseDifPuzzle() {
|
|
|
|
return view('frontend/puzzle_level');
|
2015-03-18 14:47:15 +01: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 15:06:07 +01:00
|
|
|
$params = json_decode($configjeu->parametres);
|
|
|
|
$bloc = $params->{"m".$niveau};
|
2015-03-18 14:47:15 +01:00
|
|
|
} else {
|
|
|
|
$oes = Oeuvre::orderByRaw("RAND()")->take(8)->get();
|
2015-03-18 15:06:07 +01:00
|
|
|
if($niveau == 1) {$bloc = 2;} elseif($niveau == 2){$bloc = 3;} else {$bloc = 4;}
|
2015-03-18 14:47:15 +01:00
|
|
|
}
|
|
|
|
|
2015-03-18 15:06:07 +01:00
|
|
|
|
|
|
|
return view('frontend/memo', ['oeuvres' => $oes, 'niveau' => $niveau, 'nbBloc'=>$bloc]);
|
2015-03-18 14:47:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function playPuzzle($niveau) {
|
2015-03-20 18:55:56 +01: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 14:47:15 +01:00
|
|
|
$nbTab = 3;
|
|
|
|
$dimension = 2;
|
|
|
|
}
|
2015-03-20 18:55:56 +01:00
|
|
|
return view('frontend/puzzle', ['oeuvres' => $oes, 'dimension' => $dimension, 'nbTab' => $nbTab, 'niveau' => $niveau]);
|
2015-03-18 14:47:15 +01:00
|
|
|
}
|
|
|
|
|
2015-03-20 18:55:56 +01:00
|
|
|
public function index() {
|
|
|
|
$res = User::referents()->get();
|
|
|
|
return view('home', ['referent' => $res]);
|
2015-03-18 14:47:15 +01:00
|
|
|
}
|
2015-03-20 18:59:24 +01:00
|
|
|
|
|
|
|
public function setRecords($idTrophee) {
|
|
|
|
|
2015-03-20 20:19:22 +01:00
|
|
|
$cookie = Cookie::get('trophee');
|
|
|
|
$values = json_decode($cookie);
|
2015-03-20 18:59:24 +01:00
|
|
|
|
2015-03-20 20:19:22 +01:00
|
|
|
if (!is_array($values))
|
2015-03-20 18:59:24 +01:00
|
|
|
$values = [0, 0, 0];
|
|
|
|
|
|
|
|
switch ($idTrophee) {
|
|
|
|
|
|
|
|
case '1':
|
2015-03-20 20:19:22 +01:00
|
|
|
$values[0] += 1;
|
2015-03-20 18:59:24 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '2':
|
2015-03-20 20:19:22 +01:00
|
|
|
$values[1] += 1;
|
2015-03-20 18:59:24 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '3':
|
2015-03-20 20:19:22 +01:00
|
|
|
$values[2] += 1;
|
2015-03-20 18:59:24 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-03-20 19:51:35 +01:00
|
|
|
|
2015-03-20 19:53:40 +01:00
|
|
|
return Response::make('all good!')->withCookie(Cookie::forever('trophee', json_encode($values)));
|
2015-03-20 18:59:24 +01:00
|
|
|
}
|
|
|
|
|
2015-03-18 14:47:15 +01:00
|
|
|
}
|