Skip to content
Snippets Groups Projects
Commit 5ea3ce00 authored by SASSU Thomas's avatar SASSU Thomas
Browse files

ajout characters platforms et erreur slim $_GET[page] inexistant et ajoiut des...

ajout characters platforms et erreur slim $_GET[page] inexistant et ajoiut des differents controleurs et vues
parent 89f0c9b5
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,8 @@ 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;
use \gp\controleurs\ControleurPlatform as ControleurPlatform;
use \gp\controleurs\ControleurCharacter as ControleurCharacter;
$db = new DB();
$db->addConnection(parse_ini_file('./conf/conf.ini'));
......@@ -14,7 +15,6 @@ $db->setAsGlobal();
$db->bootEloquent();
$app = new \Slim\Slim();
$app->response->headers->set('Content-Type', 'application/json');
$app->get('/',function () use ($app) {
$c = new ControleurPrincipal();
......@@ -22,27 +22,67 @@ $app->get('/',function () use ($app) {
$app->response->headers->set('Content-Type', 'text/html');
});
/* ------------------------------------------------------------
* GAMES
* ------------------------------------------------------------
*/
// Affiche un jeu au fromat JSON
$app->get('/api/games/:id',function ($id) {
$app->get('/api/games/:id',function ($id) use ($app){
$app->response->headers->set('Content-Type', 'application/json');
$c = new ControleurGame();
$c->getGame($id);
})->name('getGame');
// Affiche tous les jeu paginé au format JSON
$app->get('/api/games/',function () {
$app->get('/api/games/',function () use ($app){
$app->response->headers->set('Content-Type', 'application/json');
$c = new ControleurGame();
$c->getGames();
})->name('getGames');
// Affiche les commentaires d'un jeu
$app->get('/api/games/:id/comments',function ($id) {
$app->get('/api/games/:id/comments',function ($id) use ($app){
$app->response->headers->set('Content-Type', 'application/json');
$c = new ControleurGame();
$c->getGameComments($id);
});
$app->get('/api/games/:id/characters',function ($id) {
$app->get('/api/games/:id/characters',function ($id) use ($app){
$app->response->headers->set('Content-Type', 'application/json');
$c = new ControleurGame();
$c->getGameCharacters($id);
});
$app->get('/api/games/:id/platforms',function ($id) {
$app->get('/api/games/:id/platforms',function ($id) use ($app){
$app->response->headers->set('Content-Type', 'application/json');
$c = new ControleurGame();
$c->getGamePlatforms($id);
});
/* ------------------------------------------------------------
* PLATFORMS
* ------------------------------------------------------------
*/
$app->get('/api/platforms/:id',function ($id) use ($app){
$app->response->headers->set('Content-Type', 'application/json');
$c = new ControleurPlatform();
$c->getPlatform($id);
})->name('getPlatform');
$app->get('/api/platforms/',function () use ($app){
$app->response->headers->set('Content-Type', 'application/json');
$c = new ControleurPlatform();
$c->getPlatforms();
})->name('getPlatforms');
/* ------------------------------------------------------------
* CHARACTERS
* ------------------------------------------------------------
*/
$app->get('/api/characters/:id',function ($id) use ($app){
$app->response->headers->set('Content-Type', 'application/json');
$c = new ControleurCharacter();
$c->getCharacter($id);
})->name('getCharacter');
$app->get('/api/characters/',function () use ($app){
$app->response->headers->set('Content-Type', 'application/json');
$c = new ControleurCharacter();
$c->getCharacters();
})->name('getCharacters');
$app->run();
\ No newline at end of file
<?php
namespace gp\controleurs;
use gp\modeles\Character;
use gp\vues\VueCharacter;
use Slim\Slim;
class ControleurCharacter
{
public function getCharacter($id){
$character = Character::where('id', '=', $id)->first();
$v = new VueCharacter(json_encode($character));
$v->render();
}
public function getcharacters() {
$results = null;
if(isset($_GET['page'])) {
$page = filter_var($_GET['page'], FILTER_SANITIZE_NUMBER_INT);
ini_set('memory_limit', '512M');
$response = Character::paginate(200, ['*'], 'page', $page);
$json = (json_decode(json_encode($response), true));
$route = explode('bdappli_laurent_vonderscher_sassu_percin/GamePedia', Slim::getInstance()->urlFor('getCharacters'));
foreach ($json['data'] as $character) {
$url = $route[1] . "{$character['id']}";
$results['characters'][] = ["character" => $character, "links" => ["self" => ["href" => $url]]];
}
$prev = $json['prev_page_url'];
$next = $json['next_page_url'];
if ($next == '') $next = $json['first_page_url'];
if ($prev == '') $prev = $json['last_page_url'];
$links = ["prev" => ["href" => "/api/platforms{$prev}"], "next" => ["href" => "/api/platforms{$next}"]];
$results['links'] = $links;
}
$v = new VueCharacter(json_encode($results));
$v->render();
}
}
\ No newline at end of file
......@@ -14,24 +14,32 @@ class ControleurGame
$results['game'] = $game;
$results['links'] = [
"comments" =>["href" => $route."/comments"] ,
"characters" =>["href" => $route."/characters"]
"characters" =>["href" => $route."/characters"],
"platforms" =>["href" => $route."/platforms"]
];
$v = new VueGame(json_encode($results));
$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) {
$route = explode('bdappli_laurent_vonderscher_sassu_percin/GamePedia',Slim::getInstance()->urlFor('getGames'));
$url = $route[1]."{$game['id']}";
$results['games'][] = ["game" => $game, "links" => ["self" => ["href" => $url]]];
$results = null;
if(isset($_GET['page'])) {
$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));
$route = explode('bdappli_laurent_vonderscher_sassu_percin/GamePedia', Slim::getInstance()->urlFor('getGames'));
foreach ($json['data'] as $game) {
$url = $route[1] . "{$game['id']}";
$results['games'][] = ["game" => $game, "links" => ["self" => ["href" => $url]]];
}
$prev = $json['prev_page_url'];
$next = $json['next_page_url'];
if ($next == '') $next = $json['first_page_url'];
if ($prev == '') $prev = $json['last_page_url'];
$links = ["prev" => ["href" => "/api/games{$prev}"], "next" => ["href" => "/api/games{$next}"]];
$results['links'] = $links;
}
$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');
}
......@@ -46,7 +54,12 @@ class ControleurGame
public function getGamePlatforms($id){
$game = Game::where('id', '=', $id)->first();
$platforms = $game->platforms()->get();
$v = new VueGame(json_encode($platforms));
$route = explode('bdappli_laurent_vonderscher_sassu_percin/GamePedia',Slim::getInstance()->urlFor('getPlatforms'));
foreach ($platforms as $platform) {
$url = $route[1]."{$platform['id']}";
$results['platforms'][] = ["platform" => $platform, "links" => ["self" => ["href" => $url]]];
}
$v = new VueGame(json_encode($results));
$v->render('getPlatforms');
}
}
\ No newline at end of file
<?php
namespace gp\controleurs;
use gp\modeles\Platform;
use gp\vues\VuePlatform;
use Slim\Slim;
class ControleurPlatform
{
public function getPlatform($id){
$platform = Platform::where('id', '=', $id)->first();
$v = new VuePlatform(json_encode($platform));
$v->render();
}
public function getPlatforms() {
$results = null;
if(isset($_GET['page'])) {
$page = filter_var($_GET['page'], FILTER_SANITIZE_NUMBER_INT);
ini_set('memory_limit', '512M');
$response = Platform::paginate(20, ['*'], 'page', $page);
$json = (json_decode(json_encode($response), true));
$route = explode('bdappli_laurent_vonderscher_sassu_percin/GamePedia', Slim::getInstance()->urlFor('getPlatforms'));
foreach ($json['data'] as $platform) {
$url = $route[1] . "{$platform['id']}";
$results['platforms'][] = ["platform" => $platform, "links" => ["self" => ["href" => $url]]];
}
$prev = $json['prev_page_url'];
$next = $json['next_page_url'];
if ($next == '') $next = $json['first_page_url'];
if ($prev == '') $prev = $json['last_page_url'];
$links = ["prev" => ["href" => "/api/platforms{$prev}"], "next" => ["href" => "/api/platforms{$next}"]];
$results['links'] = $links;
}
$v = new VuePlatform(json_encode($results));
$v->render();
}
}
\ No newline at end of file
<?php
namespace gp\vues;
class VueCharacter
{
public $tab;
public function __construct($tableau) {
$this->tab = $tableau;
}
public function render() {
echo $this->tab;
}
}
\ No newline at end of file
<?php
namespace gp\vues;
class VuePlatform
{
public $tab;
public function __construct($tableau) {
$this->tab = $tableau;
}
public function render() {
echo $this->tab;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment