2015-02-24 11:50:17 +01:00
|
|
|
<?php namespace App\Http\Controllers;
|
|
|
|
|
2015-03-14 14:36:03 +01:00
|
|
|
use App\Referent;
|
|
|
|
use App\ConfigJeu;
|
2015-03-15 02:23:26 +01:00
|
|
|
use App\Auteur;
|
|
|
|
use App\Domaine;
|
2015-03-14 14:36:03 +01:00
|
|
|
use App\Oeuvre;
|
2015-03-15 02:23:26 +01:00
|
|
|
use App\Matiere;
|
|
|
|
use App\Technique;
|
2015-02-24 11:50:17 +01:00
|
|
|
use Input;
|
|
|
|
use Request;
|
|
|
|
use Response;
|
2015-02-26 15:07:34 +01:00
|
|
|
use Session;
|
2015-03-02 12:21:42 +01:00
|
|
|
use Config;
|
|
|
|
use File;
|
2015-03-14 14:36:03 +01:00
|
|
|
use Auth;
|
2015-03-24 11:36:37 +01:00
|
|
|
use Hash;
|
2015-02-24 11:50:17 +01:00
|
|
|
|
|
|
|
class ReferentController extends Controller {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new controller instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the application dashboard to the user.
|
|
|
|
*
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
2015-03-14 14:36:03 +01:00
|
|
|
|
|
|
|
$me = Auth::user();
|
|
|
|
$listeoeuvres = $me ->configjeu;
|
|
|
|
return view('backend/ref_home', ['me' => $me, 'meslistes' => $listeoeuvres]);
|
2015-02-24 11:50:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* updateUser an user informations in database.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function update()
|
|
|
|
{
|
|
|
|
$idUser = Input::get('idUser');
|
2015-03-14 14:36:03 +01:00
|
|
|
$user = Referent::find($idUser);
|
|
|
|
$user->prenom = Input::get('prenom');
|
|
|
|
$user->email = Input::get('email');
|
|
|
|
$user->nom = Input::get('nom');
|
2015-03-24 11:36:37 +01:00
|
|
|
$passwd = Input::get('password');
|
|
|
|
$passwd_conf = Input::get('password_confirm');
|
2015-03-14 14:36:03 +01:00
|
|
|
|
2015-03-24 11:36:37 +01:00
|
|
|
|
|
|
|
if($passwd == $passwd_conf) //verifie les donnees pareils
|
|
|
|
{
|
|
|
|
if (strlen($passwd) >= 6) //verifie la longueur de chaine
|
|
|
|
{
|
|
|
|
$user->motdepasse = Hash::make('secret'); // encrypt le mot de passe
|
|
|
|
$user->save(); //sauvegarde le mot de passe
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return redirect('/referent')->with('erreur', 'Mot de passe inferieur à 6 caractères.');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return redirect('/referent')->with('erreur', 'Mot de passe incorrect.');
|
|
|
|
}
|
|
|
|
|
2015-02-24 11:50:17 +01:00
|
|
|
if (Request::hasFile('file'))
|
|
|
|
{
|
2015-03-14 14:36:03 +01:00
|
|
|
$extension = Input::file('file')->getClientOriginalExtension();
|
|
|
|
$allowed = ['jpg', 'png', 'jpeg'];
|
|
|
|
if(in_array(strtolower($extension), $allowed)) {
|
|
|
|
|
|
|
|
Request::file('file')->move("imgs/avatar/", $idUser . "." . $extension);
|
|
|
|
$user->image = "imgs/avatar/" . $idUser . "." . $extension;
|
|
|
|
$user->save();
|
|
|
|
|
2015-03-23 15:04:19 +01:00
|
|
|
return redirect('/referent')->with('message', 'Votre compte a été mit à jour avec succès.');
|
2015-03-14 14:36:03 +01:00
|
|
|
} else
|
|
|
|
$user->save();
|
2015-03-23 15:04:19 +01:00
|
|
|
return redirect('/referent')->with('erreur', 'Votre image n\'est pas valide.');
|
2015-03-14 14:36:03 +01:00
|
|
|
} else {
|
|
|
|
$user->save();
|
2015-03-23 15:04:19 +01:00
|
|
|
return redirect('/referent')->with('message', 'Votre compte a été mit à jour avec succès.');
|
2015-03-14 14:36:03 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-24 11:50:17 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-03-14 14:36:03 +01:00
|
|
|
|
|
|
|
public function ajouterListeOeuvre()
|
2015-02-24 11:50:17 +01:00
|
|
|
{
|
2015-03-14 14:36:03 +01:00
|
|
|
$newConfig = new ConfigJeu();
|
|
|
|
$newConfig->referent_id = Auth::user()->id;
|
|
|
|
$newConfig->nom = Input::get('nomListe');
|
2015-03-14 16:11:11 +01:00
|
|
|
$newConfig->parametres = json_encode(['p1' => 2, 'p2' => 3, 'p3' => 4, 'pt' => '3',
|
|
|
|
'm1' => 2, 'm2' => 3, 'm3' => 4, 'mt' => '3']);
|
2015-03-14 14:36:03 +01:00
|
|
|
$newConfig->save();
|
2015-02-24 11:50:17 +01:00
|
|
|
|
|
|
|
return redirect('/referent');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-03-14 14:36:03 +01:00
|
|
|
public function supprimerListeOeuvre($idListe)
|
2015-02-24 11:50:17 +01:00
|
|
|
{
|
2015-03-14 14:36:03 +01:00
|
|
|
$ListeOeuvre = Auth::user()->configjeu->find($idListe)->delete();
|
2015-02-24 11:50:17 +01:00
|
|
|
return redirect('/referent');
|
|
|
|
}
|
2015-03-14 14:36:03 +01:00
|
|
|
|
|
|
|
public function modifierListeOeuvre($idListe)
|
2015-02-24 11:50:17 +01:00
|
|
|
{
|
2015-03-14 14:36:03 +01:00
|
|
|
$me = Auth::user();
|
|
|
|
$listeoeuvres = Oeuvre::simplePaginate(1);
|
|
|
|
$meslistes = $me->configjeu;
|
|
|
|
$mesoeuvres = $me->configjeu->find($idListe);
|
|
|
|
|
2015-03-15 02:23:26 +01:00
|
|
|
return view('backend/ref_home',['meslistes' => $meslistes, 'mesoeuvres' => $mesoeuvres, 'me' => $me, 'listeoeuvres' => $listeoeuvres,
|
2015-03-15 19:38:11 +01:00
|
|
|
'auteurs' => Auteur::all(), 'domaines' => Domaine::all(), 'matieres' => Matiere::all(), 'techniques' => Technique::all(), 'paramjeu' => json_decode($mesoeuvres->parametres)
|
2015-03-15 02:23:26 +01:00
|
|
|
]);
|
2015-03-04 19:36:23 +01:00
|
|
|
}
|
|
|
|
|
2015-03-14 14:36:03 +01:00
|
|
|
public function changerParamListe() {
|
|
|
|
|
|
|
|
Auth::user()->configjeu()->update(array('actifMemo' => 0));
|
|
|
|
Auth::user()->configjeu()->update(array('actifPuzzle' => 0));
|
|
|
|
|
2015-03-17 19:24:29 +01:00
|
|
|
if(Input::get('memo') != 0)
|
2015-03-14 14:36:03 +01:00
|
|
|
ConfigJeu::where('referent_id', '=', Auth::user()->id)->find(Input::get('memo'))->update(array('actifMemo' => 1));
|
2015-03-17 19:24:29 +01:00
|
|
|
if(Input::get('puzzle') != 0)
|
2015-03-14 14:36:03 +01:00
|
|
|
ConfigJeu::where('referent_id', '=', Auth::user()->id)->find(Input::get('puzzle'))->update(array('actifPuzzle' => 1));
|
2015-03-17 19:24:29 +01:00
|
|
|
|
2015-03-24 11:27:48 +01:00
|
|
|
return ;
|
2015-03-14 14:36:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function ajouterOeuvresDansListe($id) {
|
|
|
|
//todo verifier user
|
|
|
|
$cj = ConfigJeu::find($id);
|
|
|
|
$cj->oeuvres()->attach(Input::get('toadd'));
|
2015-03-17 19:24:29 +01:00
|
|
|
|
|
|
|
Session::flash('message', 'Vous avez ajouter des oeuvres dans votre liste.');
|
2015-03-14 14:36:03 +01:00
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function supprimerOeuvresDansListe($id) {
|
|
|
|
//todo verifier user
|
|
|
|
|
|
|
|
$cj = ConfigJeu::find($id);
|
|
|
|
if(count(Input::get('todel')) >= 1)
|
|
|
|
$cj->oeuvres()->detach(Input::get('todel'));
|
|
|
|
|
2015-03-17 19:24:29 +01:00
|
|
|
Session::flash('erreur', 'Vous avez supprimer des oeuvres de votre liste.');
|
2015-03-14 14:36:03 +01:00
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function changeParamListe($id) {
|
|
|
|
$me = Auth::user();
|
|
|
|
$configjeu = $me->configjeu->find($id);
|
|
|
|
$paramsToSave = Input::all();
|
|
|
|
unset($paramsToSave['_token']);
|
2015-03-14 16:11:11 +01:00
|
|
|
$valid = true;
|
|
|
|
foreach($paramsToSave as $p) {
|
|
|
|
if(!(is_numeric($p) && $p > 0 && $p<= 10)) $valid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(!$valid)
|
|
|
|
Session::flash('erreur', 'Les paramètres du jeu sont incorrect. Rééessayez.');
|
|
|
|
else {
|
2015-03-15 19:38:11 +01:00
|
|
|
Session::flash('message', 'Vos modifications ont été prise en compte.');
|
2015-03-14 16:11:11 +01:00
|
|
|
$configjeu->parametres = json_encode($paramsToSave);
|
|
|
|
$configjeu->save();
|
|
|
|
}
|
|
|
|
return redirect()->back();
|
2015-03-14 14:36:03 +01:00
|
|
|
}
|
|
|
|
|
2015-02-24 11:50:17 +01:00
|
|
|
}
|