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.
SAE_2A_FA-Reseau_ALICA/php/src/modele/UtilisateurModele.php

130 lines
3.8 KiB

<?php
namespace App\modele;
use App\metier\Alumni;
use App\metier\Evenement;
use App\metier\Image;
use App\config;
class UtilisateurModele
{
/**
* @description Charger le flux d'activiter
* @return array flux
*/
public function LoadFeed() : array
{
// TO DO
return [];
}
/**
* @description se connecter
* @param string email
* @param string hash
* @return \App\metier\Alumni
*/
// public function Login(string $email,string $hash) : \App\metier\Alumni
// {
// // TO DO
// return new \App\metier\Alumni(null,null,null);
// }
/**
* @description s'inscrire
* @param string email
* @param string hash
* @param string $pseudo
* @return \Alumni chargé
*/
// public function inscription(string $email, string $hashpassword): \App\metier\Alumni
// {
// $dsn = "mysql:host=localhost;dbname=dbAlica";
// $username = "test";
// $password = "test";
// $role = "Utilisateur";
// $con = new \App\gateway\Connection($dsn, $username, $password);
// $gate = new \App\gateway\AlumniGateway($con);
// // Insérez le nouvel utilisateur dans la base de données en utilisant AlumniGateway
// if ($gate->insert($email, $hashpassword, $role)) {
// // L'insertion a réussi, retournez le nouvel utilisateur
// $nouvelUtilisateur = new \App\metier\Alumni($email, $hashpassword, $role);
// return $nouvelUtilisateur;
// } else {
// // L'insertion a échoué, renvoyez un utilisateur vide pour indiquer l'échec
// return new \App\metier\Alumni(null, null, null);
// }
// }
public function getEvenement() : array
{
global $dsn, $username, $password;
$con = new \App\gateway\Connection($dsn, $username, $password);
$gate = new \App\gateway\EvenementGateway($con);
$gateImage = new \App\gateway\ImageGateway($con);
$data = $gate->getAllEvenement();
$evenement = array();
foreach($data as $row)
{
$imgRaw = $gateImage->obtenirParId($row['image']);
$img = new Image(
intval($imgRaw[0]["id"]),
$imgRaw[0]['nom'],
$imgRaw[0]['taille'],
$imgRaw[0]['type'],
$imgRaw[0]['blob']
);
$evenement[] = new \App\metier\Evenement(
$row['id'],
$row['organisateur'],
$row['titre'],
$row['description'],
$row['date'],
$row['nbPlaceMax'],
$img
);
}
return $evenement;
}
public function ajouterEvenement(Image $img)
{
global $dsn, $username, $password;
$con = new \App\gateway\Connection($dsn, $username, $password);
$gate = new \App\gateway\EvenementGateway($con);
$titre = $_POST["titre"];
$description = $_POST["description"];
$date = $_POST["date"];
$nbPlaceMax = $_POST["nbPlaceMax"];
$evenement = new Evenement(
$gate->getNewId(),
'1', //TODO : Ajouter l'ID de l'admin connecté
$titre,
$description,
$date,
$nbPlaceMax,
$img
);
$gate->insertEvenement($evenement);
}
public function deleteEvenement(int $id)
{
global $dsn, $username, $password;
$con = new \App\gateway\Connection($dsn, $username, $password);
$gate = new \App\gateway\EvenementGateway($con);
$gate->deleteEvenement($id);
}
}