diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php index f9601bd..6102e0d 100644 --- a/src/Controllers/UserController.php +++ b/src/Controllers/UserController.php @@ -1,10 +1,12 @@ $user->email, 'user' => $user, 'userFullName' => $user->name . ' ' . $user->surname, + 'orders' => $orders, ]; + return $this->render('account', $params); } header('Location: /login/'); } + public function updateInfoAction(): void { session_start(); $request = Request::getBody(); $arrayKey = array_key_first($request); - $updateField = mb_substr($arrayKey,3); + $updateField = mb_substr($arrayKey, 3); $funcName = 'updateUser' . $updateField; UserService::$funcName(); header('Location: /account/'); diff --git a/src/Services/Repository/OrderService.php b/src/Services/Repository/OrderService.php index 0910fb4..f8c5a86 100644 --- a/src/Services/Repository/OrderService.php +++ b/src/Services/Repository/OrderService.php @@ -55,6 +55,7 @@ public static function addOrder(): ?array { $errors[] = 'Error adding a product/order link: ' . DbConnection::get()->error; } + return !empty($errors) ? $errors : null; } catch (Exception $e) @@ -66,7 +67,7 @@ public static function addOrder(): ?array /** * @throws Exception */ - public static function getOrderList(): array + public static function getOrderList($userEmail = null): array { $query = "SELECT O.`ID`, O.`DATE_CREATE`, O.`PRICE`," . " U.`NAME`, U.`SURNAME`, U.`EMAIL`, U.`ADDRESS`, P.`TITLE` " @@ -74,17 +75,33 @@ public static function getOrderList(): array . " INNER JOIN `PRODUCT_ORDER` PR ON O.`ID` = PR.`ORDER_ID`" . "INNER JOIN `PRODUCT` P ON PR.PRODUCT_ID = P.ID"; - $result = SecurityService::safeSelectQuery($query); - + if ($userEmail !== null) + { + $query .= " WHERE U.EMAIL=?"; + $params = [$userEmail]; + $result = SecurityService::safeSelectQuery($query, $params); + } + else + { + $result = SecurityService::safeSelectQuery($query); + } + $orders = []; while ($row = mysqli_fetch_assoc($result)) { - $orders[] = new Order((int)$row['ID'], $row['DATE_CREATE'], - (float)$row['PRICE'], $row['NAME'], - $row['SURNAME'], $row['EMAIL'], - $row['ADDRESS'], $row['TITLE']); + $orders[] = new Order( + (int)$row['ID'], + $row['DATE_CREATE'], + (float)$row['PRICE'], + $row['NAME'], + $row['SURNAME'], + $row['EMAIL'], + $row['ADDRESS'], + $row['TITLE'] + ); } + return $orders; } @@ -110,7 +127,6 @@ public static function addOrderUnauthorised(): ?array 'DATE_CREATE' => date('Y-m-d H:i:s'), ]; - if (!SecurityService::safeInsertQuery('`ORDER`', $orderData)) { $errors[] = 'Error adding an order: ' . DbConnection::get()->error; @@ -127,6 +143,7 @@ public static function addOrderUnauthorised(): ?array { $errors[] = 'Error adding a product/order link: ' . DbConnection::get()->error; } + return !empty($errors) ? $errors : null; } catch (Exception $e) diff --git a/src/Views/default/components/account-orders.php b/src/Views/default/components/account-orders.php index afb6c0f..fa18cff 100644 --- a/src/Views/default/components/account-orders.php +++ b/src/Views/default/components/account-orders.php @@ -1,91 +1,37 @@

Order History

+
- -
-
- -
+
\ No newline at end of file diff --git a/src/Views/default/pages/account.php b/src/Views/default/pages/account.php index 0621499..823f5e7 100644 --- a/src/Views/default/pages/account.php +++ b/src/Views/default/pages/account.php @@ -2,7 +2,8 @@ /** * @var $userFullName * @var $userEmail - * @var \Up\Models\Product $user + * @var \Up\Models\User $user + * @var \Up\Models\Order $orders */ ?>
@@ -33,7 +34,7 @@ class="account__img"> renderComponent('account-profile', ['user' => $user, 'userEmail' => $userEmail]) ?>
- renderComponent('account-orders', []) ?> + renderComponent('account-orders', ['orders' => $orders]) ?>
renderComponent('account-modals', ['user' => $user]) ?>