WIP did a few little changes, add colorpicker for the creation of the team, still have to make changes in regard to it
continuous-integration/drone/push Build is passing Details

pull/16/head
Maël DAIM 1 year ago
parent 1acede4169
commit 9bc03c099b

@ -1,6 +1,9 @@
-- drop tables here
DROP TABLE IF EXISTS FormEntries;
DROP TABLE IF EXISTS TacticInfo;
DROP TABLE IF EXISTS Team;
DROP TABLE IF EXISTS Member;
DROP TABLE IF EXISTS Participate;
CREATE TABLE FormEntries(name varchar, description varchar);
@ -12,15 +15,14 @@ CREATE TABLE Team(
secondColor numeric
);
CREATE TABLE Participate(
idTeam numeric FOREIGN KEY REFERENCES Team(id),
idMember numeric FOREIGN KEY REFERENCES Member(id),
role char CHECK (role IN ('C','P'))
CREATE TABLE Member(
id integer PRIMARY KEY AUTOINCREMENT
);
CREATE TABLE Member(
id integer PRIMARY KEY AUTOINCREMENT,
email varchar,
CREATE TABLE Participate(
idTeam integer FOREIGN KEY REFERENCES Team(id),
idMember integer FOREIGN KEY REFERENCES Member(id),
role char CHECK (role IN ('C','P'))
);
CREATE TABLE TacticInfo(

@ -9,9 +9,6 @@ use App\Model\TeamModel;
use App\Validation\FieldValidationFail;
use App\Validation\Validators;
use \Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
class TeamController /* verif si les camp sont assignés, sinon erreur 400*/
{
@ -32,7 +29,9 @@ class TeamController /* verif si les camp sont assignés, sinon erreur 400*/
}
public function submitTeam(array $request): HttpResponse {
$request['mainColor'] = intval($request['mainColor']);
$request['secondColor'] = intval($request['secondColor']);
var_dump($request['secondColor']);
$errors = [];
$request = HttpRequest::from($request, $errors, [
"name" => [Validators::lenBetween(1, 32), Validators::nameWithSpaces()],
@ -49,8 +48,8 @@ class TeamController /* verif si les camp sont assignés, sinon erreur 400*/
}
return ViewHttpResponse::twig('insert_team.html.twig', ['bad_fields' => $badFields]);
}
$this->model->createTeam($request['name'], $request['picture'], intval($request['mainColor']), intval($request['secondColor']));
return ViewHttpResponse::twig('sample_form.html.twig', []); /*todo appeler une vue qui display la team au lieu de ça*/
$id = $this->model->createTeam($request['name'], $request['picture'], $request['mainColor'], $request['secondColor']);
return $this->displayTeam($id);
}
public function displayListTeamByName(): HttpResponse {
@ -62,14 +61,18 @@ class TeamController /* verif si les camp sont assignés, sinon erreur 400*/
$request = HttpRequest::from($request, $errors, [
"name" => [Validators::lenBetween(1, 32), Validators::nameWithSpaces()]
]);
if (!empty($errors) && $errors[0] instanceof FieldValidationFail) {
$badField = $errors[0]->getFieldName();
return ViewHttpResponse::twig('list_team_by_name.html.twig', ['bad_field' => $badField]);
}
$results = $this->model->listByName($request['name']);
if (empty($results)) {
return ViewHttpResponse::twig('display_teams.html.twig', []);
}
return ViewHttpResponse::twig('display_teams.html.twig', ['teams' => $results]);
}

@ -11,7 +11,6 @@ class Member {
*/
private int $userId;
private string $email;
/**
* @var MemberRole the member's role
*/
@ -19,12 +18,10 @@ class Member {
/**
* @param int $userId
* @param string $email
* @param MemberRole $role
*/
public function __construct(int $userId, string $email, MemberRole $role) {
public function __construct(int $userId, MemberRole $role) {
$this->userId = $userId;
$this->email = $email;
$this->role = $role;
}
@ -42,12 +39,4 @@ class Member {
public function getRole(): MemberRole {
return $this->role;
}
/**
* @return string
*/
public function getEmail(): string {
return $this->email;
}
}

@ -24,6 +24,13 @@ class TeamGateway {
);
}
public function getIdOfLastInsertion(): array{
return $this->con->fetch(
"SELECT last_insert_rowid() as id",
[]
);
}
public function listByName(string $name): array {
return $this->con->fetch(
"SELECT id,name,picture,mainColor,secondColor FROM Team WHERE name LIKE '%' || :name || '%'",

@ -6,6 +6,7 @@ use App\Gateway\TeamGateway;
use App\Data\Team;
use App\Data\Member;
use App\Data\MemberRole;
use http\Url;
/**
*
@ -21,15 +22,17 @@ class TeamModel /* throw des exceptions(ex validation des champs, filtre etc) po
$this->gateway = $gateway;
}
public function createTeam(string $name, string $picture, int $mainColor, int $secondColor) {
public function createTeam(string $name, string $picture, int $mainColor, int $secondColor): int{
$this->gateway->insert($name, $picture, $mainColor, $secondColor);
return (int) $this->gateway->getIdOfLastInsertion()['id'];
}
public function listByName(string $name): array {
$teams = [];
$results = $this->gateway->listByName($name);
foreach ($results as $row) {
$teams[] = new Team($row['id'], $row['name'], $row['picture'], $row['mainColor'], $row['secondColor']);
$url = new Url($row['picture']);
$teams[] = new Team($row['id'], $row['name'], $url, $row['mainColor'], $row['secondColor']);
}
return $teams;
}
@ -44,10 +47,9 @@ class TeamModel /* throw des exceptions(ex validation des champs, filtre etc) po
} else {
$role = 2;
}
$members[] = new Member($row['id'], $row['email'], $role);
$members[] = new Member($row['id'], $role);
}
$team = new Team($result['id'], $result['name'], $result['picture'], $result['mainColor'], $result['secondColor'], $members);
return $team;
return new Team($result['id'], $result['name'], $result['picture'], $result['mainColor'], $result['secondColor'], $members);
}
}

@ -22,7 +22,7 @@
</div>
{% else %}
{% for t in teams %}
<div onclick="window.location.href = '/team/{{ t.id }}'">
<div class="team" onclick="window.location.href = '/team/{{ t.id }}'">
<p>Nom de l'équipe : {{ t.name }}</p>
<p>picture : {{ t.picture }}</p>
</div>

@ -71,9 +71,9 @@
<label for= "picture">Logo:</label>
<input type="text" id="picture" name="picture" required >
<label for="mainColor">Couleur principale</label>
<input type="text" id="mainColor" name="mainColor" required>
<input type="color" id="mainColor" name="mainColor" required>
<label for="secondColor">Couleur secondaire</label>
<input type="text" id="secondColor" name="secondColor" required>
<input type="color" id="secondColor" name="secondColor" required>
</div>
<div class="form-group">
<input type="submit" value="Confirmer">

Loading…
Cancel
Save