function changePromo($newPromo)
 {
     $bdd = new Connector();
     // Check if promo exists
     $promo = $bdd->Select("*", "promo", array("where" => array(array("id_promo", "=", $newPromo))));
     if (!$promo) {
         throw new LengthException("La promo n'existe pas");
     }
     // Change promo in both object and BDD
     $this->promo = $newPromo;
     $this->libelle_promo = $promo[0]["libelle"];
     $bdd->Update("document", array("where" => array(array("id", "=", $this->id)), "set" => array("promo" => $this->promo)));
 }
 function write()
 {
     $bdd = new Connector();
     $promo = $bdd->Select("*", "promo", array("where" => array(array("id_promo", "=", $this->id_promo))));
     if (!$promo) {
         throw new UnexpectedValueException("La promo n'existe plus en base de données");
     }
     $promo = $promo[0];
     $attrs = get_object_vars($this);
     $toUpdate = array();
     foreach ($attrs as $key => $value) {
         if ($value != $promo[$key]) {
             $toUpdate[$key] = $value;
         }
     }
     $bdd->Update("promo", array("set" => $toUpdate, "where" => array(array("id_promo", "=", $this->id_promo))));
 }
Beispiel #3
0
 public static function getAll()
 {
     $bdd = new Connector();
     $datas = $bdd->Select("*", "data");
     $toReturn = array();
     foreach ($datas as $data) {
         $doc = new Data($data["id"]);
         array_push($toReturn, self::toArray($doc));
     }
     return $toReturn;
 }