1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
| <?php
$racine = substr(DIRNAME(__FILE__),0,strpos(DIRNAME(__FILE__),'DAO'));
require_once ($racine ."configAccueil.php");
require_once (configAccueil::$Chemin["Factory"]);
require_once (configAccueil::$Chemin["DAOWidgetEvol"]);
//require_once (configAccueil::$Chemin["tableWidgets_Evol"]);
require_once (configAccueil::$Chemin["Widget.class"]);
require_once (configAccueil::$Chemin["Evol.class"]);
require_once (configAccueil::$Chemin['MysqliException']);
require_once (configAccueil::$Chemin['Error']);
class DAOWidgetEvolImplMysqli implements DAOWidgetEvol {
private $table, $column_idEvol, $column_idWidget, $column_texte;
private $identft;
public function __construct(){
$this->table = configAccueil::$BDD["tableWidgets_Evol"];
$this->column_idEvol = configAccueil::$BDD["tWidgets_Evol_colIdEvol"];
$this->column_idWidget = configAccueil::$BDD["tWidgets_Evol_colIdWidget"];
$this->column_texte = configAccueil::$BDD["tWidgets_Evol_colContenuEvol"];
$this->identft = $_SESSION['identft'];
}
/** Méthode qui récupère les id (code) des evols pour un widget de type "evol" donné
* @param int $id_widget l'id du widget de type "evol" pour lequel on recherche les evols associées
* @return array un tableau d'objets de type Evol::class
* @throws MysqliException si erreur lors de l'exécution de la requête SQL
*/
public function recupererWidgetEvol(int $id_widget):WidgetEvol
{
$widgeEvol = new WidgetEvol();
$mysql_connect = DAOFactory::connecterBDD();
$start = microtime(true);
$query = "SELECT DISTINCT $this->column_idEvol FROM $this->table WHERE $this->column_idWidget = ?";
$params = array();
$params['query'] = $query;
$params['script'] = "DAO/Implementation/Mysqli/DAOWidgetEvolImplMysqli.recupererEvols()";
$params['start'] = $start;
$params['user'] = $this->identft;
$params['idWidget'] = $id_widget;
if($stmt = $mysql_connect->prepare($query)){
if($stmt->bind_param("i", $id_widget)){
if($stmt->execute()){
if($result = $stmt->get_result()){
while($row = $result->fetch_assoc()) {
$widgeEvol->addCodeEvol($row[$this->column_idEvol]);
//array_push($liste_id_actu, $row[$this->column_idEvol]);
}
$result->close();
$stmt->close();
} else {
$params['erreurSQL'] = $stmt->error;
throw new MysqliException(Erreur::$Mysqli_typeErreur['execution'], EErreur::$Mysqli_getResult['code'], Erreur::$Mysqli_getResult['msg'], $params);
}
} else {
$params['erreurSQL'] = $stmt->error;
throw new MysqliException(Erreur::$Mysqli_typeErreur['execution'], EErreur::$Mysqli_executeQuery['code'], Erreur::$Mysqli_executeQuery['msg'], $params);
}
} else {
$params['erreurSQL'] = $stmt->error;
throw new MysqliException(Erreur::$Mysqli_typeErreur['execution'], EErreur::$Mysqli_bindParams['code'], Erreur::$Mysqli_bindParams['msg'], $params);
}
} else {
$params['erreurSQL'] = $mysql_connect->error;
throw new MysqliException(Erreur::$Mysqli_typeErreur['execution'], EErreur::$Mysqli_prepare['code'], Erreur::$Mysqli_prepare['msg'], $params);
}
return $widgeEvol;
}
/** Méthode qui va enregistrer une ligne dans la table de relation "widgets_Evols"
* @param WidgetEvol $widget le widget principal enregistré dans la table "widgets"
* @throws MysqliException si erreur lors de l'exécution de la requête SQL
*/
public function enregistrerWidgetEvol(WidgetEvol $widget)
{
$mysql_connect = DAOFactory::connecterBDD();
$start = microtime(true);
$query = "INSERT INTO $this->table($this->column_idWidget,$this->column_idEvol) VALUES(?,?)";
$params = array();
$params['query'] = $query;
$params['script'] = "DAO/Implementation/Mysqli/DAOWidgetEvolImplMysqli.enregistrerWidgetEvol()";
$params['start'] = $start;
$params['user'] = $this->identft;
$id = $widget->getId();
$id_evol = "";
if($stmt = $mysql_connect->prepare($query)) {
if($stmt->bind_param("is", $id, $id_evol)){
//on va enregistrer dans la table de relation, autant de paire id_widget/id_evo qu'il y a d'evols
//dans le cas d'un widget de type evols, dans les données on a un tableau d'evol (Evol::class)
foreach ($widget->getCodeEvols() as $id_evo)
{
$params['idEvol'] = $id_evo;
$id_evol = $id_evo;
if(!$stmt->execute()){
$params['erreurSQL'] = $stmt->error;
throw new MysqliException(Erreur::$Mysqli_typeErreur['execution'], Erreur::$Mysqli_executeQuery['code'], Erreur::$Mysqli_executeQuery['msg'], $params);
}
}
} else {
$params['erreurSQL'] = $stmt->error;
throw new MysqliException(Erreur::$Mysqli_typeErreur['execution'], Erreur::$Mysqli_bindParams['code'], Erreur::$Mysqli_bindParams['msg'], $params);
}
} else {
$params['erreurSQL'] = $mysql_connect->error;
throw new MysqliException(Erreur::$Mysqli_typeErreur['execution'], Erreur::$Mysqli_prepare['code'], Erreur::$Mysqli_prepare['msg'], $params);
}
}
/** Méthode qui va supprimer les lignes associées à l'id du widget passé en paramètre
* @param int $idWidget l'id du widget général qui va être supprimé
* @throws MysqliException si erreur lors de l'exécution de la requête SQL
*/
public function supprimerWidgetsEvol(int $idWidget)
{
$mysql_connect = DAOFactory::connecterBDD();
$start = microtime(true);
$query = "DELETE FROM $this->table WHERE $this->column_idWidget = ?";
$params = array();
$params['query'] = $query;
$params['script'] = "DAO/Implementation/Mysqli/DAOWidgetEvolImplMysqli.supprimerWidgetsEvolsAssocies()";
$params['start'] = $start;
$params['user'] = $this->identft;
$params['idWidget'] = $idWidget;
if($stmt = $mysql_connect->prepare($query)) {
if($stmt->bind_param("i", $idWidget)){
if(!$stmt->execute()){
$params['erreurSQL'] = $stmt->error;
throw new MysqliException(Erreur::$Mysqli_typeErreur['execution'], Erreur::$Mysqli_executeQuery['code'], Erreur::$Mysqli_executeQuery['msg'], $params);
}
} else {
$params['erreurSQL'] = $stmt->error;
throw new MysqliException(Erreur::$Mysqli_typeErreur['execution'], Erreur::$Mysqli_bindParams['code'], Erreur::$Mysqli_bindParams['msg'], $params);
}
} else {
$params['erreurSQL'] = $mysql_connect->error;
throw new MysqliException(Erreur::$Mysqli_typeErreur['execution'], Erreur::$Mysqli_prepare['code'], Erreur::$Mysqli_prepare['msg'], $params);
}
}
public function recupererTexteId($id, $id_evol){
$texte_evol = "";
$mysql_connect = DAOFactory::connecterBDD();
$start = microtime(true);
$query = "SELECT DISTINCT $this->column_texte FROM $this->table WHERE $this->column_idWidget = ? AND $this->column_idEvol = ?";
$params = array();
$params['query'] = $query;
$params['script'] = "DAO/Implementation/Mysqli/DAOEvolImplMysqli.recupererNomEvol()";
$params['start'] = $start;
$params['user'] = $this->identft;
$params['id'] = $id;
$params['id_evol'] = $id_evol;
if($stmt = $mysql_connect->prepare($query)){
if($stmt->bind_param("ss", $id, $id_evol)){
if($stmt->execute()){
if($result = $stmt->get_result()){
if($row = $result->fetch_assoc()) {
$texte_evol = $row[$this->column_texte];
}
$result->close();
} else {
$params['erreurSQL'] = $stmt->error;
throw new MysqliException(Erreur::$Mysqli_typeErreur['execution'], Erreur::$Mysqli_getResult['code'], Erreur::$Mysqli_getResult['msg'], $params);
}
} else {
$params['erreurSQL'] = $stmt->error;
throw new MysqliException(Erreur::$Mysqli_typeErreur['execution'], Erreur::$Mysqli_executeQuery['code'], Erreur::$Mysqli_executeQuery['msg'], $params);
}
} else {
$params['erreurSQL'] = $stmt->error;
throw new MysqliException(Erreur::$Mysqli_typeErreur['execution'], Erreur::$Mysqli_bindParams['code'], Erreur::$Mysqli_bindParams['msg'], $params);
}
} else {
$params['erreurSQL'] = $mysql_connect->error;
throw new MysqliException(Erreur::$Mysqli_typeErreur['execution'], Erreur::$Mysqli_prepare['code'], Erreur::$Mysqli_prepare['msg'], $params);
}
return $texte_evol;
}
public function recupererIdWidgetEvol($id_evol){
$IdWidget_evol = "";
$mysql_connect = DAOFactory::connecterBDD();
$start = microtime(true);
$query = "SELECT DISTINCT $this->column_idWidget FROM $this->table WHERE $this->column_idEvol = ?";
$params = array();
$params['query'] = $query;
$params['script'] = "DAO/Implementation/Mysqli/DAOEvolImplMysqli.recupererIdWidgetEvol()";
$params['start'] = $start;
$params['user'] = $this->identft;
$params['id_evol'] = $id_evol;
if($stmt = $mysql_connect->prepare($query)){
if($stmt->bind_param("s", $id_evol)){
if($stmt->execute()){
if($result = $stmt->get_result()){
if($row = $result->fetch_assoc()) {
$IdWidget_evol = $row[$this->column_idWidget];
}
$result->close();
} else {
$params['erreurSQL'] = $stmt->error;
throw new MysqliException(Erreur::$Mysqli_typeErreur['execution'], Erreur::$Mysqli_getResult['code'], Erreur::$Mysqli_getResult['msg'], $params);
}
} else {
$params['erreurSQL'] = $stmt->error;
throw new MysqliException(Erreur::$Mysqli_typeErreur['execution'], Erreur::$Mysqli_executeQuery['code'], Erreur::$Mysqli_executeQuery['msg'], $params);
}
} else {
$params['erreurSQL'] = $stmt->error;
throw new MysqliException(Erreur::$Mysqli_typeErreur['execution'], Erreur::$Mysqli_bindParams['code'], Erreur::$Mysqli_bindParams['msg'], $params);
}
} else {
$params['erreurSQL'] = $mysql_connect->error;
throw new MysqliException(Erreur::$Mysqli_typeErreur['execution'], Erreur::$Mysqli_prepare['code'], Erreur::$Mysqli_prepare['msg'], $params);
}
return $IdWidget_evol;
}
}
?> |
Partager