From 6e9d62d5027a3ac5eeb4258897c87c0e13343f52 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tondon=20C=C3=A9sar?= <pilou.tondon@hotmail.fr>
Date: Wed, 25 Mar 2020 09:35:54 +0100
Subject: [PATCH] partie2

---
 Seance5-6/seance/index.php                    |  4 ++
 .../seance/src/controller/IndexController.php | 28 ++++++++++++-
 Seance5-6/seance/src/view/VuePartie2.php      | 41 +++++++++++++++++++
 3 files changed, 72 insertions(+), 1 deletion(-)
 create mode 100644 Seance5-6/seance/src/view/VuePartie2.php

diff --git a/Seance5-6/seance/index.php b/Seance5-6/seance/index.php
index ad19e22..a035d74 100644
--- a/Seance5-6/seance/index.php
+++ b/Seance5-6/seance/index.php
@@ -21,6 +21,10 @@ $app->get('/api/games/:id', function($id){
     IndexController::jeuParId($id);
 })->name('partie1');
 
+$app->get('/api/games/',function() {
+    IndexController::partie2();
+})->name('partie2');
+
 
 
 $app->run();
diff --git a/Seance5-6/seance/src/controller/IndexController.php b/Seance5-6/seance/src/controller/IndexController.php
index 18a4db0..88db463 100644
--- a/Seance5-6/seance/src/controller/IndexController.php
+++ b/Seance5-6/seance/src/controller/IndexController.php
@@ -3,8 +3,8 @@
 namespace seance\controller;
 
 use seance\modele\Game;
-use seance\reponse\CQuestion1;
 use seance\view\VuePartie1;
+use seance\view\VuePartie2;
 
 class IndexController
 {
@@ -16,4 +16,30 @@ class IndexController
         $vue->render();
     }
 
+    public static function partie2() {
+        $game = Game::where('id','<=','200')->get();
+       // $game = Game::where('id','=',1)->get();
+        // $json = json_encode($game,JSON_FORCE_OBJECT);
+        $json = '{ "games" : [ ';
+        foreach($game as $key => $value) {
+            $json = $json .  '{
+                "id": ' . $value->id . ',
+                "name":' . $value->name . ',
+                "deck":' . $value->deck . ',
+            },
+            ';
+            if ($value->id == 200) {
+                $json = $json .  '{
+                    "id": ' . $value->id . ',
+                    "name":' . $value->name . ',
+                    "deck":' . $value->deck . ',
+                }
+                ';
+            }
+        }
+        $json = $json . ']}';
+        $cq2 = new VuePartie2($json);
+        $cq2->render();
+    }
+
 }
\ No newline at end of file
diff --git a/Seance5-6/seance/src/view/VuePartie2.php b/Seance5-6/seance/src/view/VuePartie2.php
new file mode 100644
index 0000000..a7c83ed
--- /dev/null
+++ b/Seance5-6/seance/src/view/VuePartie2.php
@@ -0,0 +1,41 @@
+<?php
+
+namespace seance\view;
+
+use Illuminate\Database\Eloquent\ModelNotFoundException;
+use seance\modele\Character;
+use seance\modele\Game;
+
+
+class VuePartie2
+{
+    private $content;
+
+    public function __construct($json)
+    {
+        $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>
+            <h1>Titre</h1>
+            <p>$json</p>
+        </body>
+
+END;
+
+    }
+
+    public function render()
+    {
+        echo $this->content;
+    }
+
+}
-- 
GitLab