You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Web/Sources/src/data/core/database/CoachMapper.php

100 lines
2.5 KiB

<?php
namespace Database;
use Model\CoachAthlete;
use Model\User;
use \PDO;
use \DateTime;
use Model\Role;
use Model\Coach;
use Shared\Log;
class CoachMapper {
public function coachSqlToEntity(array $data): array {
$coachEntities = [];
foreach ($data as $coachData) {
$coach = new CoachEntity();
if (isset($coachData['idAthlete'])) {
$coach->setIdCoach($coachData['idAthlete']);
}
if (isset($coachData['nom'])) {
$coach->setNom($coachData['nom']);
}
if (isset($coachData['prenom'])) {
$coach->setPrenom($coachData['prenom']);
}
if (isset($coachData['username'])) {
$coach->setUsername($coachData['username']);
}
if (isset($coachData['email'])) {
$coach->setEmail($coachData['email']);
}
if (isset($coachData['sexe'])) {
$coach->setSexe($coachData['sexe']);
}
if (isset($coachData['taille'])) {
$coach->setTaille($coachData['taille']);
}
if (isset($coachData['poids'])) {
$coach->setPoids($coachData['poids']);
}
if (isset($coachData['motDePasse'])) {
$coach->setMotDePasse($coachData['motDePasse']);
}
if (isset($coachData['dateNaissance'])) {
$coach->setDateNaissance($coachData['dateNaissance']);
}
if (isset($coachData['isCoach'])) {
$coach->setIsCoach($coachData['isCoach']);
}
$coachEntities[] = $coach;
}
return $coachEntities;
}
public function CoachEntityToModel(CoachEntity $coachEntity):User{
$role = new CoachAthlete();
$date = new DateTime($coachEntity->getDateNaissance());
$user = new User(
$coachEntity->getNom(),
$coachEntity->getPrenom(),
$coachEntity->getUsername(),
$coachEntity->getEmail(),
$coachEntity->getMotDePasse(),
$coachEntity->getSexe(),
$coachEntity->getTaille(),
$coachEntity->getPoids(),
$date,
$role
);
return $user;
}
public function CoachToEntity(User $user):CoachEntity{
$coach = new CoachEntity();
$coach->setIdCoach($user->getId());
$coach->setAthleteId($user->getId());
return $coach;
}
}
?>