function GetOrder($conn, $order_id) { $order_result = GetFullOrder($order_id, $conn); $orderList = array(); // lista wszystkich zamówień foreach ($order_result as $order) { $order_products_result = GetProductList($order['order_id'], $conn); $products = array(); foreach ($order_products_result as $product) { $photo = $conn->GetPhotosForProductId($product['product_id'])->fetch(); array_push($products, array('product_id' => $product['product_id'], 'amount' => $product['amount'], 'photo' => new Photo($photo['photo_id'], $photo['extension']))); } $order_tmp = new Order($order['order_id'], $order['status_name'], $order['status_id'], $order['date'], $order['message'], $order['delivery'], $order['amount'], new Client($order['client_name'], $order['address'], $order['city'], $order['postal_code'], $order['email'], $order['nick'])); $order_tmp->addProduct($products); array_push($orderList, $order_tmp); } return $orderList[0]; }
function GetOrderList($config, $jsonResult) { $conn = new connection($config); $order_result = GetOrdersList($conn); $orderList = array(); // lista wszystkich zamówień foreach ($order_result as $order) { $order_products_result = GetProductList($order['order_id'], $conn); $products = array(); foreach ($order_products_result as $product) { $photo = $conn->GetPhotosForProductId($product['product_id'])->fetch(); array_push($products, array('product_id' => $product['product_id'], 'amount' => $product['amount'], 'photo' => new Photo($photo['photo_id'], $photo['extension']))); } $order_tmp = new Order($order['order_id'], $order['status_name'], $order['status_id'], $order['date'], $order['message'], $order['delivery'], $order['amount'], new Client($order['client_name'], $order['address'], $order['city'], $order['postal_code'], $order['email'], $order['nick'])); $order_tmp->addProduct($products); array_push($orderList, $order_tmp); } if ($order_result->rowCount() === 0) { $jsonResult->json_data['result_code'] = JSON::$resultCodes['no_orders']; } else { $jsonResult->json_data['result_code'] = JSON::$resultCodes['ok']; $jsonResult->json_data['result_data'] = $orderList; } }
<?php /** * Created by PhpStorm. * User: Hoan * Date: 10/29/2015 * Time: 1:17 PM */ //Khởi động session session_start(); //Kiểm tra nếu chưa đăng nhập thì quay về trang đăng nhập if (!isset($_SESSION['user'])) { header('location:../user/login.php'); } //Require các file cần thiết require '../../configs/config.php'; require '../../libraries/connect.php'; require '../../models/product.php'; $product_list = GetProductList(); //Giao diện require '../../views/product/v_list.php';
<?php session_start(); ?> <?php header('Content-Type: application/json'); include 'classes.php'; $jsonResult = new JSON(array(), null, array()); $config = $jsonResult->GetAccesToken(); if ($config !== null) { GetProductList($config, $jsonResult); } else { $jsonResult->json_data['result_code'] = JSON::$resultCodes['token_error']; } print $jsonResult->PrepareJSON(); function GetProductList($config, $jsonResult) { $cargo_id = $_GET['cargo_id']; $conn = new connection($config); $result = $conn->query("SELECT kind.name as kind_name , amount , product_id\n from product\n inner join kind on product.kind_id = kind.kind_id\n inner join cargo on product.cargo_id = cargo.cargo_id\n where cargo.cargo_id = '" . $cargo_id . "'\n ORDER BY kind.name;"); $kinds = array(); foreach ($result as $row) { $tmp_photos = array(); $result2 = $conn->query("SELECT photo.photo_id , photo.extension\n from product inner join photo on product.product_id = photo.product_id\n where product.product_id = '" . $row['product_id'] . "';"); foreach ($result2 as $row2) { array_push($tmp_photos, new Photo($row2['photo_id'], $row2['extension'])); } array_push($kinds, new Product($row['product_id'], $row['kind_name'], $row['amount'], $tmp_photos)); } $jsonResult->json_data['result_data'] = $kinds;