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');
     }
 }
 private function connectionAction()
 {
     $oUser = new User();
     $oUser->setEmail($_POST['email']);
     $oUser->setPassword($_POST['password']);
     if (UserManager::connect($oUser)) {
         //header('location: index.php');
         header('location: index.php');
     } else {
         $bConnectError = true;
         require ROOT . 'src/ecommerce/view/login/login.php';
     }
 }
 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 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 getCurrent()
 {
     if (!array_key_exists('email', $_SESSION)) {
         return null;
     }
     $oUser = new User();
     $oUser->setEmail($_SESSION['email']);
     return self::get($oUser);
 }