public static function insert(User $user)
 {
     $query = "INSERT INTO users (mail, password, firstname, lastname, address, cp, city, phone, role)\n\t\t\tVALUES ('" . $user->getMail() . "','" . $user->getPassword() . "','" . $user->getFirstname() . "','" . $user->getLastname() . "','" . $user->getAddress() . "','" . $user->getCp() . "','" . $user->getCity() . "','" . $user->getPhone() . "','" . $user->getRole() . "')";
     if (DBOperation::exec($query)) {
         header('Location: index.php?controller=Front&method=home&success');
     } else {
         header('Location: index.php?controller=Front&method=signin&error');
     }
 }
 public static function setOrder(Order $order)
 {
     $query = "INSERT INTO commandes (prix, id_user)\n\t\t\tVALUES ('" . $order->getPrice() . "','" . $order->getIdUser() . "')";
     DBOperation::exec($query);
     $lastId = DBOperation::getLastId();
     foreach ($_SESSION["cart"] as $product) {
         $query = "INSERT INTO produits_commandes (id_produit, id_commande, quantity)\n\t\t\t\tVALUES ('" . $product->getId() . "','" . $lastId . "','" . $product->getQuantity() . "')";
         DBOperation::exec($query);
     }
 }
 public static function save($aProducts, User $oUser)
 {
     if (count($aProducts) === 0) {
         return false;
     }
     $dDate = date('Y-m-d H:i:s');
     $fTotal = self::getTotal();
     // create order
     $sQuery = "insert into orders(user_email,date,total) values('{$oUser->getEmail()}','{$dDate}',{$fTotal})";
     if (!DBOperation::exec($sQuery)) {
         return false;
     }
     $iOrderId = DBOperation::getLastId();
     foreach ($aProducts as $oCartProduct) {
         $sQuery = "insert into order_product(order_id,product_id,quantity) values({$iOrderId},\n                {$oCartProduct->getId()},{$oCartProduct->getQuantity()})";
         if (!DBOperation::exec($sQuery)) {
             return false;
         }
     }
     return true;
 }
 public static function display($iId)
 {
     $sQuery = " update product ";
     $sQuery .= "set active = 1";
     $sQuery .= " WHERE id = " . $iId;
     $iRetExec = DBOperation::exec($sQuery);
     if (null !== ($sLastSqlError = DBOperation::getLastSqlError())) {
         throw new \Exception($sLastSqlError);
     }
 }
 public static function validate(Product $oProduct, User $oUser)
 {
     $sQuery = " update comment";
     $sQuery .= " SET validated = 1";
     $sQuery .= " WHERE product_id = " . $oProduct->getId();
     $sQuery .= " AND user_email = '" . $oUser->getEmail() . "'";
     $iRetExec = DBOperation::exec($sQuery);
     if (null !== ($sLastSqlError = DBOperation::getLastSqlError())) {
         throw new \Exception($sLastSqlError);
     }
 }
 public static function updateProduct($id, $name, $description, $price)
 {
     $query = "UPDATE produits\n\t\t\tSET nom ='" . $name . "', description='" . $description . "', prix='" . $price . "' WHERE id=" . $id;
     DBOperation::exec($query);
 }
 public static function updatePassword($oUser)
 {
     $sQuery = " update user ";
     $sQuery .= " SET password = '******'";
     $sQuery .= " WHERE email = '" . $oUser->getEmail() . "'";
     $iRetExec = DBOperation::exec($sQuery);
     if (null !== ($sLastSqlError = DBOperation::getLastSqlError())) {
         throw new \Exception($sLastSqlError);
     }
 }
 public static function remove($iId)
 {
     $sQuery = " DELETE FROM category ";
     $sQuery .= " WHERE id = " . $iId;
     $iRetExec = DBOperation::exec($sQuery);
     if (null !== ($sLastSqlError = DBOperation::getLastSqlError())) {
         throw new \Exception($sLastSqlError);
     }
 }