コード例 #1
0
 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');
     }
 }
コード例 #2
0
 public static function getAllOrder()
 {
     $query = "SELECT * FROM commandes";
     $result = DBOperation::getAll($query);
     $orders = [];
     foreach ($result as $order) {
         $orders[] = new Order($order['prix'], $order['id_user'], $order['id'], $order['date']);
     }
     return $orders;
 }
コード例 #3
0
 public static function getOrders()
 {
     $sQuery = " select * from orders ";
     $sQuery .= " ORDER BY date DESC ";
     $aAllOrders = [];
     foreach (DBOperation::getAll($sQuery) as $aOrder) {
         $aAllOrders[] = self::convertToObject($aOrder);
     }
     return $aAllOrders;
 }
コード例 #4
0
 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;
 }
コード例 #5
0
 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);
     }
 }
コード例 #6
0
 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);
     }
 }
コード例 #7
0
 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);
 }
コード例 #8
0
 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);
     }
 }
コード例 #9
0
 public static function getNumberProducts()
 {
     $sQuery = " SELECT category.id, category.name, category.description, COUNT( product_id ) AS numberproducts ";
     $sQuery .= " FROM category INNER JOIN product_category ON category.id = product_category.category_id";
     $sQuery .= " GROUP BY category.id, category.name, category.description";
     $aCategories = array();
     foreach (DBOperation::getAll($sQuery) as $aCategory) {
         $aCategories[] = $aCategory;
     }
     return $aCategories;
 }