diff --git a/GamePedia/index.php b/GamePedia/index.php index fb872a72c1de7ef2c382fcfd7910c06286d60710..87338b309e2f4a07ac286a9b9626810ea7b7ac0c 100644 --- a/GamePedia/index.php +++ b/GamePedia/index.php @@ -4,6 +4,7 @@ session_start(); use \Slim\Slim as Slim; use Illuminate\Database\Capsule\Manager as DB; use \gp\controleurs\ControleurPrincipal as ControleurPrincipal; +use \gp\controleurs\ControleurGame as ControleurGame; use \gp\controleurs\ControleurScript as ControleurScript; $db = new DB(); @@ -13,17 +14,22 @@ $db->setAsGlobal(); $db->bootEloquent(); $app = new \Slim\Slim(); +$app->response->headers->set('Content-Type', 'application/json'); -$app->get('/',function () { +$app->get('/',function () use ($app) { $c = new ControleurPrincipal(); -// $c->afficherAccueil(); + $c->afficherAccueil(); + $app->response->headers->set('Content-Type', 'text/html'); }); -$app->get('/script_TD1/',function () { - $c = new ControleurScript(); - $c->td1(); +$app->get('/api/games/:id',function ($id) { + $c = new ControleurGame(); + $c->getGame($id); }); - +$app->get('/api/games/',function () { + $c = new ControleurGame(); + $c->getGames(); +}); $app->run(); \ No newline at end of file diff --git a/GamePedia/src/controleurs/ControleurGame.php b/GamePedia/src/controleurs/ControleurGame.php new file mode 100644 index 0000000000000000000000000000000000000000..a42f7ba962355e53d0a5a804fd15dff31b9317cf --- /dev/null +++ b/GamePedia/src/controleurs/ControleurGame.php @@ -0,0 +1,28 @@ +<?php + +namespace gp\controleurs; + +use gp\modeles\Game; +use gp\vues\VueGame; +class ControleurGame +{ + public function getGame($id){ + $game = Game::where('id', '=', $id)->first(); + $v = new VueGame(json_encode($game)); + $v->render('getGame'); + } + + public function getGames(){ + $page = filter_var($_GET['page'], FILTER_SANITIZE_NUMBER_INT); + ini_set('memory_limit', '512M'); + $response = Game::paginate(200, ['*'], 'page', $page); + $json = (json_decode(json_encode($response),true)); + foreach ($json['data'] as $game) { + $results['games'][] = ["game" => $game, "links" => ["self" => ["href" => "/api/games/{$game['id']}"]]]; + } + $links = ["prev" =>["href" => "/api/games{$json['prev_page_url']}"] , "next" =>["href" => "/api/games{$json['next_page_url']}"]]; + $results['links'] = $links; + $v = new VueGame(json_encode($results)); + $v->render('getGames'); + } +} \ No newline at end of file diff --git a/GamePedia/src/controleurs/ControleurPrincipal.php b/GamePedia/src/controleurs/ControleurPrincipal.php index 1f386f36d22b369a0113c446ee492cfb3ee95f85..1ca5775d25f2a559074a16e6089cd7dcbd207093 100644 --- a/GamePedia/src/controleurs/ControleurPrincipal.php +++ b/GamePedia/src/controleurs/ControleurPrincipal.php @@ -1,5 +1,5 @@ <?php -namespace gp\modeles; +namespace gp\controleurs; use \gp\vues\VuePrincipale as VuePrincipale; class ControleurPrincipal { diff --git a/GamePedia/src/vues/VueGame.php b/GamePedia/src/vues/VueGame.php new file mode 100644 index 0000000000000000000000000000000000000000..d8715642b91917da4510e66727e083b83209f372 --- /dev/null +++ b/GamePedia/src/vues/VueGame.php @@ -0,0 +1,32 @@ +<?php + +namespace gp\vues; + +class VueGame +{ + public $tab; + + public function __construct($tableau) { + $this->tab = $tableau; + } + + public function render($selecteur) { +// switch ($selecteur){ +// case 'getGame' : { +// $json = $this->afficher_getGame(); +// $cd = ''; +// break; +// } +// case 'getGames' : { +// $json = $this->afficher_getGame(); +// $cd = ''; +// break; +// } +// } + echo $this->tab; + } +// +// private function afficher_getGame() { +// return $this->tab; +// } +} \ No newline at end of file diff --git a/GamePedia/src/vues/VuePrincipale.php b/GamePedia/src/vues/VuePrincipale.php index 90df31ef62a879404f914adb0f86fe38eea86fa9..b11223670d1d94f577400d7a966a3ea299c935da 100644 --- a/GamePedia/src/vues/VuePrincipale.php +++ b/GamePedia/src/vues/VuePrincipale.php @@ -18,96 +18,38 @@ class VuePrincipale break; } } - if (isset($_SESSION['Connexion']) == false) { - $html = <<<END -<!doctype html> -<html class="no-js" lang="fr" dir="ltr"> - <head> - <meta charset="utf-8"> - <meta http-equiv="x-ua-compatible" content="ie=edge"> - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <title>Fridgie</title> - <link rel="stylesheet" href="{$cd}css/style.css"> - </head> - <header class="menu" role="banner"> - <div id="logo"><a href="{$cd}./"><img src="{$cd}img/logo.png"></a></div> - <div id="menu_button"> - <ul> - <li><a class="bouton" href="{$cd}./">Accueil</a></li> - <li><a class="bouton" href="{$cd}indexevenement">Evenement</a></li> - <li><a class="bouton" href="{$cd}indexrecette">Recette</a></li> - <li><a class="bouton" href="{$cd}connexion">Connexion</a></li> - </ul> - </div> - </header> - <body> - - $content - - </body> -</html> + $html = <<<END + <!doctype html> + <html class="no-js" lang="fr" dir="ltr"> + <head> + <meta charset="utf-8"> + <meta http-equiv="x-ua-compatible" content="ie=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>GamePedia</title> + <link rel="stylesheet" href="css/style.css"> + </head> + <header class="menu" role="banner"> + </header> + <body> + + $content + + </body> + </html> END; - } else { - $html = <<<END -<!doctype html> -<html class="no-js" lang="fr" dir="ltr"> - <head> - <meta charset="utf-8"> - <meta http-equiv="x-ua-compatible" content="ie=edge"> - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <title>Fridgie</title> - <link rel="stylesheet" href="css/style.css"> - </head> - <header class="menu" role="banner"> - <div id="logo"><a href="{$cd}./"><img src="{$cd}img/logo.png"></a></div> - <div id="menu_button"> - <ul> - <li><a class="bouton" href="{$cd}./">Accueil</a></li> - <li><a class="bouton" href="{$cd}indexevenement">Evenement</a></li> - <li><a class="bouton" href="{$cd}indexrecette">Recette</a></li> - <li><a class="bouton" href="{$cd}moncompte">Mon Compte</a></li> - </ul> - </div> - </header> - <body> - - $content - - </body> -</html> -END; - } - echo $html; } private function afficherAccueil() { - if (isset($_SESSION['Connexion']) == false) { - $res=" -<div id=\"first\"> - <p><strong>Bienvenue sur Fridgie !</strong> - <br>Rejoignez-nous en vous inscrivant en appuyant ci-dessous.</p> - <a class=\"bouton\" href=\"inscription\">Inscription</a> -</div>"; - } else { - $res=" -<div id=\"first\"> - <p><strong>Bienvenue sur Fridgie !</strong> - <br>Recherchez une recette en appuyant ci-dessous.</p> - <a class=\"bouton\" href=\"recette\">Recherche</a> -</div>"; - } - return $res."<div id='arrow01'></div><div id=\"second\"> - <p> - Fridgie est une application web développée par quatre étudiants de 2ème de DUT Informatique. - Principe du site-web : - <br>Aujourd'hui, nous avons tellement de produits à consommer dans nos frigos qu'au final, nous ne savons même plus quoi manger. - C'est là que Fridgie intervient. En effet, il vous permet de trouver une liste de recette en fonction des ingrédients que vous avez dans votre frigo. - Mais Fridgie est plus grand que ça ! Vous pouvez aussi par exemple créer un évenement qui tourne autour d'une recette, suivant ce principe, - les membres qui s'inscrivent à l'évenement peuvent vous notifier qu'ils apportent tel ou tel ingrédient, et réalisez, facilement, - un plat collaboratif ! - <br><br> S3C - KRELL SPICK PERCIN SASSU - </p> -</div>"; + $res=" + <div id=\"first\"> + <p><strong>Bienvenue sur GamePedia !</strong> + </div>"; + return $res."<div id='arrow01'></div><div id=\"second\"> + <p> + Gamepedia est un projet du semestre 4. + <br> AI2 - SASSU PERCIN VONDERSCHER LAURENT + </p> + </div>"; } } \ No newline at end of file