Example #1
0
            $productData = findAllProducts($query, '');
        }
        $query2 = $db->suppliers->where('supplierID', $supplierId);
        $supplierData = findSupplierDetails($query2);
        $data = array_merge($supplierData, $productData);
        $app->response()->header('content-type', 'application/json');
        echo json_encode(array('supplier_details' => $supplierData, 'supplier_products' => $productData));
        // echo json_encode(array('supplier_details'=>$supplierData));
        // echo json_encode($data);
    } else {
        if (isset($_GET['products_details']) and $_GET['products_details'] == 'true') {
            $query = $db->products();
            $productData = findAllProducts($query, '');
        }
        $supplierData = array();
        $query2 = $db->suppliers();
        foreach ($query2 as $p) {
            $supplierData[] = findSupplierDetails($query2);
        }
        $data = array_merge($supplierData, $productData);
        $app->response()->header('content-type', 'application/json');
        echo json_encode(array('supplier_details' => $supplierData, 'supplier_products' => $productData));
    }
});
// For finding usages of given type say tiles or marbles
$app->get('/shiningfloor/products(/:type)/usages', function ($type) use($app, $db) {
    $usages_area;
    $type_id = $db->types()->where('type_name', $type)->select('id')->fetch();
    // $query = $db->products->where('type_id',$type_id);
    $query = $db->products_usages()->where('type_id', $type_id);
    foreach ($query as $p) {