diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 930cd67..d93a49b 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -2,12 +2,28 @@ namespace App\Controller; +use App\Connexion; +use App\Gateway\AuthGateway; +use App\Gateway\TacticInfoGateway; use App\Http\HttpResponse; use App\Http\ViewHttpResponse; +use App\Model\AuthModel; +use App\Model\TacticModel; class UserController { + private TacticModel $tacticMdl; + private AuthModel $accountMdl; + + public function __construct() + { + $con = new Connexion(get_database()); + $this->tacticMdl = new TacticModel(new TacticInfoGateway($con)); + $this->accountMdl = new AuthModel(new AuthGateway($con)); + } + public function home(): HttpResponse { - return ViewHttpResponse::twig("home.twig", []); + $listTactic = $this->tacticMdl->getLast(5); + return ViewHttpResponse::twig("home.twig", ["recentTactic" => $listTactic]); } public function default(): HttpResponse { diff --git a/src/Gateway/TacticInfoGateway.php b/src/Gateway/TacticInfoGateway.php index 3441c9a..4806a04 100644 --- a/src/Gateway/TacticInfoGateway.php +++ b/src/Gateway/TacticInfoGateway.php @@ -31,6 +31,23 @@ class TacticInfoGateway { return new TacticInfo($id, $row["name"], strtotime($row["creation_date"])); } + /** + * Return the nb last tactics created + * + * @param integer $nb + * @return array|null + */ + public function getLast(int $nb) : ?array { + $res = $this->con->fetch( + "SELECT * FROM TacticInfo ORDER BY creation_date DESC LIMIT :nb ", + [":nb" => [$nb, PDO::PARAM_INT]] + ); + if (count($res) == 0) { + return null; + } + return $res; + } + public function insert(string $name): TacticInfo { $this->con->exec( "INSERT INTO TacticInfo(name) VALUES(:name)", diff --git a/src/Model/TacticModel.php b/src/Model/TacticModel.php index cabcdec..d696b11 100644 --- a/src/Model/TacticModel.php +++ b/src/Model/TacticModel.php @@ -35,6 +35,10 @@ class TacticModel { return $this->tactics->get($id); } + public function getLast(int $nb) : ?array { + return $this->tactics->getLast($nb); + } + /** * Update the name of a tactic * @param int $id the tactic identifier diff --git a/src/Views/home.css b/src/Views/home.css new file mode 100644 index 0000000..c642b09 --- /dev/null +++ b/src/Views/home.css @@ -0,0 +1,6 @@ +.bandeau { + background-color: red; +} +body { + background-color: blue; +} \ No newline at end of file diff --git a/src/Views/home.twig b/src/Views/home.twig index 600ed1d..b7cc7d3 100644 --- a/src/Views/home.twig +++ b/src/Views/home.twig @@ -5,30 +5,49 @@ - Document + Page d'accueil + -

Page Home à faire

+
+

IQ Ball

+

Profil

+
-

Mes équipes

+

Mes équipes

-{% for team in recentTeam %} -
-

{{team.name}}

-
-{% endfor %} -

Mes strategies

+ {% for team in recentTeam %} +
+

{{team.name}}

+
+ {% endfor %} - +

Mes strategies

+ + + + {% if recentTactic != null %} + {% for tactic in recentTactic %} +
+

{{tactic.id}} - {{tactic.name}} - {{tactic.creation_date}}

+ +
+ {% endfor %} + {% else %} +

Aucune tactique créé !

+ {% endif %} -{% for tactic in recentTactic %} -
-

{{tactic.id}} - {{tactic.name}} - {{tactic.creation_date}}

-
-{% endfor %} -

+