/** * Returns an singleton instance of this class * @return */ public static function getInstance() { if (self::$instance == null) { self::$instance = new OrderMapper(); } return self::$instance; }
public function findById($id) { $row = $this->query('SELECT * FROM orders_tb WHERE id = ' . (int) $id)->fetch(); if (!$row) { return null; } $order = new Order(); OrderMapper::map($order, $row); return $order; }
public function find($status = null) { $result = array(); $sql = 'SELECT id, user_id, business_id, order_date, status, assigned_to,order_details FROM orders_tb WHERE ' . 'status = "' . $status . '";'; foreach ($this->query($sql) as $row) { $order = new Order(); OrderMapper::map($order, $row); $result[$order->getId()] = $order; } return $result; }
<?php $errors = array(); $userObj = new User(); $addressObj = new Address(); $orderObj = new Order(); if (array_key_exists('submit', $_POST)) { $userData = array('id' => (int) $_SESSION['user_id'], 'first_name' => $_POST['user']['first_name'], 'last_name' => $_POST['user']['last_name']); $addressData = array('street_no' => $_POST['address']['street_no'], 'street' => $_POST['address']['street'], 'suburb' => $_POST['address']['suburb'], 'city' => $_POST['address']['city'], 'post_code' => $_POST['address']['post_code']); UserMapper::map($userObj, $userData); AddressMapper::map($addressObj, $addressData); //$errors = Validator::validate($userObj); //if (empty($errors)) { $userDao = new UserDao(); $addressDao = new AddressDao(); // $_SESSION['address_id'] = ($addressDao->create($addressObj)->getId()); $userDao->completeRegistration($userObj, $addressDao->createAddress($addressObj)->getId()); //} } if (array_key_exists('order', $_POST)) { $orderData = array('order_details' => $_POST['orders']['order_details'], 'order_date' => $_POST['orders']['order_date'] . '00:00:00'); OrderMapper::map($orderObj, $orderData); $orderDao = new OrderDao(); $orderDao->createOrder($orderObj); }
/** * Initializes DB mappers * * @param object $config * @param object $args * @return */ function __construct($config, $args) { $this->mapper = OrderMapper::getInstance(); $this->config = $config; $this->args = $args; }
$mapper->delete($item); $response = $response->withRedirect("/index.php/inventory"); return $response; }); /**********************SHIPMENT AKA PAYMENT**********************/ // Shipments AKA Payments $app->get('/payments', function ($request, $response, $args) { $this->logger->info("Payment AKA Shipments page"); $mapper = new PaymentMapper($this->db); $payments = $mapper->getPayments(); return $this->renderer->render($response, 'payment/payments.phtml', [$args, "payments" => $payments]); }); // Add payment GET $app->get('/payment/add', function ($request, $response, $args) { $this->logger->info("adding payment item"); $mapper = new OrderMapper($this->db); $orders = $mapper->getOrders(); return $this->renderer->render($response, 'payment/add.phtml', [$args, "orders" => $orders]); }); // Add payment POST $app->post('/payment/add', function ($request, $response) { $post_data = $request->getParsedBody(); $data = []; $data['OrderId'] = (int) filter_var($post_data['order'], FILTER_SANITIZE_STRING); $data['PaymentDate'] = filter_var($post_data['date'], FILTER_SANITIZE_STRING); $data['Amount'] = filter_var($post_data['amount'], FILTER_SANITIZE_STRING); $payment_mapper = new PaymentMapper($this->db); $payment_item = new PaymentEntity($data); $payment_mapper->save($payment_item); $response = $response->withRedirect("/index.php/payments"); return $response;