From 72302beb921318d74ef9822ff197accfd06727e1 Mon Sep 17 00:00:00 2001
From: PaulKelbert <paul.kelbert3@etu.univ-lorraine.fr>
Date: Mon, 23 Mar 2020 11:50:07 +0100
Subject: [PATCH] =?UTF-8?q?d=C3=A9but=20partie=201?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Seance5-6/seance/.htaccess                    | 19 ++++++++
 Seance5-6/seance/index.php                    |  8 +++-
 .../seance/src/controller/IndexController.php | 11 +++--
 Seance5-6/seance/src/reponse/CQuestion1.php   | 29 ------------
 Seance5-6/seance/src/view/VuePartie1.php      | 44 +++++++++++++++++++
 5 files changed, 77 insertions(+), 34 deletions(-)
 create mode 100644 Seance5-6/seance/.htaccess
 delete mode 100644 Seance5-6/seance/src/reponse/CQuestion1.php
 create mode 100644 Seance5-6/seance/src/view/VuePartie1.php

diff --git a/Seance5-6/seance/.htaccess b/Seance5-6/seance/.htaccess
new file mode 100644
index 0000000..a6ca267
--- /dev/null
+++ b/Seance5-6/seance/.htaccess
@@ -0,0 +1,19 @@
+RewriteEngine On
+#
+# RewriteBase indispensable sur webetu :
+
+# RewriteBase /www/username0/mywishlist
+
+
+#
+# Pour interdire l'accès aux répertoires contenant du code
+RewriteRule ^sql(/.*|)$ - [NC,F]
+RewriteRule ^src(/.*|)$ - [NC,F]
+RewriteRule ^vendor(/.*|)$ - [NC,F]
+
+#
+# réécriture pour slim
+
+RewriteCond %{REQUEST_FILENAME} !-d
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteRule ^ index.php [QSA,L]
diff --git a/Seance5-6/seance/index.php b/Seance5-6/seance/index.php
index b644a50..ad19e22 100644
--- a/Seance5-6/seance/index.php
+++ b/Seance5-6/seance/index.php
@@ -2,7 +2,7 @@
 
 require 'vendor/autoload.php';
 use seance\modele\Game;
-use seace\controller\IndexController;
+use seance\controller\IndexController;
 
 use Illuminate\Database\Capsule\Manager as DB;
 $file = parse_ini_file('conf.ini');
@@ -14,9 +14,13 @@ $app = new \Slim\Slim();
 
 
 $app->get('/', function(){
-    IndexController::test();
+    echo "page index";
 })->name('testIndex');
 
+$app->get('/api/games/:id', function($id){
+    IndexController::jeuParId($id);
+})->name('partie1');
+
 
 
 $app->run();
diff --git a/Seance5-6/seance/src/controller/IndexController.php b/Seance5-6/seance/src/controller/IndexController.php
index 46f06dd..18a4db0 100644
--- a/Seance5-6/seance/src/controller/IndexController.php
+++ b/Seance5-6/seance/src/controller/IndexController.php
@@ -1,14 +1,19 @@
 <?php
 
-namespace seace\controller;
+namespace seance\controller;
 
+use seance\modele\Game;
 use seance\reponse\CQuestion1;
+use seance\view\VuePartie1;
 
 class IndexController
 {
 
-    public static function test(){
-        new CQuestion1();
+    public static function jeuParId($id){
+        $game = Game::find($id);
+
+        $vue = new VuePartie1($game);
+        $vue->render();
     }
 
 }
\ No newline at end of file
diff --git a/Seance5-6/seance/src/reponse/CQuestion1.php b/Seance5-6/seance/src/reponse/CQuestion1.php
deleted file mode 100644
index 320ac55..0000000
--- a/Seance5-6/seance/src/reponse/CQuestion1.php
+++ /dev/null
@@ -1,29 +0,0 @@
-<?php
-
-namespace seance\reponse;
-
-use Illuminate\Database\Eloquent\ModelNotFoundException;
-use seance\modele\Character;
-use seance\modele\Game;
-
-
-class CQuestion1
-{
-
-    public function __construct()
-    {
-        echo "<a href='index.php'>Retour au menu</a><br><br>";
-
-
-
-        $game = Game::find(12342);
-
-        $p = $game->appears_in;
-
-        foreach ($p as $pers) {
-            echo $pers->name . "  --  " . $pers->deck . "<br>";
-        }
-
-    }
-
-}
\ No newline at end of file
diff --git a/Seance5-6/seance/src/view/VuePartie1.php b/Seance5-6/seance/src/view/VuePartie1.php
new file mode 100644
index 0000000..101ea1e
--- /dev/null
+++ b/Seance5-6/seance/src/view/VuePartie1.php
@@ -0,0 +1,44 @@
+<?php
+
+namespace seance\view;
+class VuePartie1
+{
+
+    private $content;
+
+    public function __construct($game)
+    {
+        $this->content = <<< END
+<!DOCTYPE html>
+<html lang="fr">
+<head>
+    <meta charset="UTF-8" content="application/json">
+    
+    <link rel="stylesheet" href="css/main.css">
+   
+    <title>photobox</title>
+</head>
+
+<body>
+{
+ "id": $game->id,
+ "name": "$game->name",
+ "alias": "$game->alias",
+ "deck": "$game->deck",
+ "description": ...",
+ "original_release_date": "$game->original_release_date"
+}
+
+
+</body>
+
+END;
+
+    }
+
+    public function render()
+    {
+        echo $this->content;
+    }
+
+}
\ No newline at end of file
-- 
GitLab