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/gateway/ExperienceGateway.php

78 lines
2.4 KiB

<?php
namespace App\gateway;
use App\metier\Profil;
use App\metier\Experience;
class ExperienceGateway
{
private \App\gateway\Connection $con;
/**
* @param $con
*/
public function __construct(\App\gateway\Connection $con){
$this->con = $con;
}
public function getNewId() : int
{
$query='SELECT MAX(id) FROM Experience';
$this->con->executeQuery($query);
$res=$this->con->getResults();
return $res[0]['MAX(id)']+1;
}
public function getNbExperience(): int
{
$query = 'SELECT COUNT(*) FROM Experience';
$this->con->executeQuery($query, array());
$res = $this->con->getResults();
return intval($res[0]['COUNT(*)']);
}
public function getExperienceFromId(int $id) : array
{
$query = "SELECT * FROM experience WHERE id=:id";
$this->con->executeQuery($query, array(
':id' => array($id, \PDO::PARAM_INT)
));
return $this->con->getResults();
}
public function getExperienceFromProfil(int $profil) : array
{
$query = "SELECT * FROM experience WHERE profil=:profil" ;
$this->con->executeQuery($query, array(
':profil' => array($profil, \PDO::PARAM_INT)
));
// var_dump($profil);
// var_dump($this->con->getResults());
return $this->con->getResults();
}
public function addExperience(Experience $exp)
{
$query = 'INSERT INTO experience VALUES (:id, :profil, :intitule, :dateBegin, :dateEnd, :nameIndustry, :currentJobb)';
$this->con->executeQuery($query, array(
':id' => array($exp->getId(), \PDO::PARAM_INT),
//':profil' => array($exp->getProfil(), \PDO::PARAM_INT),
':profil' => array(33,\PDO::PARAM_INT),
':intitule' => array($exp->getIntitule(), \PDO::PARAM_STR),
':dateBegin' => array($exp->getDateDebut(), \PDO::PARAM_STR),
':dateEnd' => array($exp->getDateFin(), \PDO::PARAM_STR),
':nameIndustry' => array($exp->getNomEntreprise(), \PDO::PARAM_STR),
':currentJobb' => array($exp->isTravailActuel(), \PDO::PARAM_BOOL),
));
}
public function deleteExperience(int $id)
{
$query = 'DELETE FROM experience WHERE id=:id';
$this->con->executeQuery($query, array(
':id' => array($id, \PDO::PARAM_INT)
));
}
}