Add a basic display of the tactics in the home page
continuous-integration/drone/push Build is failing Details

pull/18/head
DahmaneYanis 1 year ago
parent 913fb432c8
commit 55c67cc484

@ -2,12 +2,28 @@
namespace App\Controller; namespace App\Controller;
use App\Connexion;
use App\Gateway\AuthGateway;
use App\Gateway\TacticInfoGateway;
use App\Http\HttpResponse; use App\Http\HttpResponse;
use App\Http\ViewHttpResponse; use App\Http\ViewHttpResponse;
use App\Model\AuthModel;
use App\Model\TacticModel;
class UserController { 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 { 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 { public function default(): HttpResponse {

@ -31,6 +31,23 @@ class TacticInfoGateway {
return new TacticInfo($id, $row["name"], strtotime($row["creation_date"])); 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 { public function insert(string $name): TacticInfo {
$this->con->exec( $this->con->exec(
"INSERT INTO TacticInfo(name) VALUES(:name)", "INSERT INTO TacticInfo(name) VALUES(:name)",

@ -35,6 +35,10 @@ class TacticModel {
return $this->tactics->get($id); return $this->tactics->get($id);
} }
public function getLast(int $nb) : ?array {
return $this->tactics->getLast($nb);
}
/** /**
* Update the name of a tactic * Update the name of a tactic
* @param int $id the tactic identifier * @param int $id the tactic identifier

@ -0,0 +1,6 @@
.bandeau {
background-color: red;
}
body {
background-color: blue;
}

@ -5,30 +5,49 @@
<meta name="viewport" <meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge"> <meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title> <title>Page d'accueil</title>
<style>
#bandeau {
display : flex;
flex-direction : row;
}
#bandeau:h1 {
self-align : center;
}
</style>
</head> </head>
<body> <body>
<h1>Page Home à faire</h1> <div id="bandeau">
<h1>IQ Ball</h1>
<p>Profil</p>
</div>
<h2> Mes équipes </h2>
<h2> Mes équipes </h2>
{% for team in recentTeam %} {% for team in recentTeam %}
<div> <div>
<p> {{team.name}} </p> <p> {{team.name}} </p>
</div> </div>
{% endfor %} {% endfor %}
<h2> Mes strategies </h2> <h2> Mes strategies </h2>
<button onclick="location.pathname = "/tactic/create"> Créer une nouvelle équipe </button> <button onclick="location.pathname='/tactic/create'"> Créer une nouvelle tactique </button>
{% for tactic in recentTactic %} {% if recentTactic != null %}
<div onclick="location.pathname = /tactic/edit/{{ strategie.id }}"> {% for tactic in recentTactic %}
<div onclick="location.pathname=/tactic/edit/{{ strategie.id }}">
<p> {{tactic.id}} - {{tactic.name}} - {{tactic.creation_date}} </p> <p> {{tactic.id}} - {{tactic.name}} - {{tactic.creation_date}} </p>
<button onclick="location.pathname='/tactic/edit/{{ tactic.id }}'"> Editer la stratégie {{tactic.id}} </button>
</div> </div>
{% endfor %} {% endfor %}
{% else %}
<p> Aucune tactique créé !</p>
{% endif %}
<h2> <h2>

Loading…
Cancel
Save