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 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; }
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; }
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 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; }