travail sur le vocabulaire et sa gateway

php
Patrick BRUGIERE 2 years ago
parent 254c73148e
commit 4026ea5245

@ -1,7 +1,6 @@
<?php
namespace model;
require_once("User.php");
class Teacher extends User
{

@ -4,49 +4,43 @@ namespace model;
class Vocabulary
{
protected $map = array(
"fr" => "eng"
);
protected String $name;
protected String $image;
/**
* @param string[] $map
* @param String $name
* @param String $image
*/
public function __construct(array $map, $name, $image)
public function __construct( $name, $image)
{
$this->map = $map;
$this->name = $name;
$this->image = $image;
}
/*
public function translateToEnglish($fr) {
return isset($this->map[$fr]) ? $this->map[$fr] : $fr;
public function __toString(): string
{
return "Vocabulaire :" . $this->name . $this->image;
}
public function translateToFrench($eng) {
// Chercher la clé correspondante pour la valeur en anglais
$key = array_search($eng, $this->map);
/*
public function translateToEnglish($fr) {
return isset($this->map[$fr]) ? $this->map[$fr] : $fr;
}
// Si la traduction est trouvée, retourner la clé (en français)
return $key !== false ? $key : $eng;
}
public function translateToFrench($eng) {
// Chercher la clé correspondante pour la valeur en anglais
$key = array_search($eng, $this->map);
// Si la traduction est trouvée, retourner la clé (en français)
return $key !== false ? $key : $eng;
}
public function addTranslation($fr, $eng) {
$this->map[$fr] = $eng;
}
*/
public function addTranslation($fr, $eng) {
$this->map[$fr] = $eng;
}
*/
/**
* @return string[]
*/
public function getMap()
{
return $this->map;
}
/**
* @return String
@ -64,13 +58,6 @@ class Vocabulary
return $this->image;
}
/**
* @param string[] $map
*/
public function setMap($map)
{
$this->map = $map;
}
/**
* @param String $nom

@ -1,8 +1,41 @@
<?php
namespace model;
use model\Vocabulary;
use config\Connection;
use PDO;
class VocabularyGateway
{
private Connection $con;
public function __construct(Connection $con){
$this->con = $con;
}
public function findByName(String $name){
try{
$query = "SELECT * FROM Vocabulary v WHERE v.name=:name";
$args = array(':name'=>array($name,PDO::PARAM_STR));
$this->con->ExecuteQuery($query,$args);
$res = $this->con->getResults();
$tab_vocab=[];
foreach($res as $r){
$tab_vocab[]=new Vocabulary($r['id'],$r['name'],$r['image']);
}
Return $tab_vocab;
}
catch(PDOException $e ){
error_log('PDOException: ' . $e->getMessage(), 3, 'error.log');
}
}
}
}
Loading…
Cancel
Save