Пример #1
0
<?php

include_once '../classes/PDOExt.php';
include_once '../classes/Utilities.php';
$dbConnection = new PDOExt();
$utilities = new Utilities();
$response = array();
$serving_id = $utilities->replaceDefault($_POST['serving_id']);
$date = $utilities->replaceToday($_POST['date']);
$userId = $utilities->replaceZero($_POST['user_id']);
try {
    $query = "SELECT food_item.item_id AS food_id,\n                        food_item.`name` AS food_name,\n                        food_item.description AS food_description,\n                        food_item.ingredients AS food_ingredients,\n                        food_item.preparation_method AS food_preparation_method,\n                        food_item.rating AS food_rating,\n                        food_item.price AS food_price,\n                        COALESCE(food_item.food_image_1, '') AS food_image_1,\n                        COALESCE(food_item.food_image_2, '') AS food_image_2,\n                        COALESCE(food_item.food_image_3, '') AS food_image_3,\n                        COALESCE(food_item.food_image_4, '') AS food_image_4,\n                        food_item.category_id,\n                        currency.currency_symbol AS food_currency_symbol,\n                        food_item.chef_id,\n                        CONCAT(chef.f_name, ' ', chef.l_name) AS chef_name,\n                        chef.image_url AS chef_image_url,\n                        chef.rating AS chef_rating,\n                        serving.serving_name,\n                        item_serving_mapping.available_for AS available_for_count,\n                        item_serving_mapping.order_count,\n                        item_serving_mapping.date AS serving_date,\n                        (SELECT COUNT(*) FROM `likes` WHERE food_item_id = food_id) AS likes_count,\n                        (SELECT COUNT(*) FROM `likes` WHERE food_item_id = food_id AND likes.user_id = '{$userId}' ) AS liked_already,\n                        category.category_id,\n                        category.category_name\n                FROM item_serving_mapping INNER JOIN food_item ON item_serving_mapping.item_id = food_item.item_id\n                         INNER JOIN category ON food_item.category_id = category.category_id\n                         INNER JOIN currency ON food_item.currency_id = currency.currency_id\n                         INNER JOIN chef ON food_item.chef_id = chef.chef_id\n                         INNER JOIN serving ON item_serving_mapping.serving_id = serving.serving_id ";
    $query .= " WHERE (item_serving_mapping.date = '{$date}'  OR item_serving_mapping.date = '1970-01-01') ";
    $query .= $serving_id > 0 ? " AND item_serving_mapping.serving_id = {$serving_id} " : " ";
    $query .= "ORDER BY item_serving_mapping.serving_id ASC, food_rating ASC, food_name ASC";
    $statement = $dbConnection->prepare($query);
    try {
        if ($statement->execute($bindParams)) {
            $data = $statement->fetchAll(PDO::FETCH_ASSOC);
            $statement->closeCursor();
            $response = array('status' => 0, 'data' => $data, 'desc' => 'success');
        } else {
            $errorCode = -99;
            $dbError = $statement->errorInfo();
            $statement->closeCursor();
            $response = array('status' => $errorCode, 'data' => array(), 'desc' => 'DB error occured' . $dbError[2]);
        }
    } catch (PDOExecption $e) {
        $errorCode = -7;
        $statement->closeCursor();
        $error = "Exception: " . $e->getMessage();
include_once '../classes/Utilities.php';
include_once '../classes/Logger.php';
$dbConnection = new PDOExt();
$utilities = new Utilities();
$log = new Logger(basename($_SERVER['PHP_SELF']));
$response = array();
$log->arrayLogger($_POST, "POST Req Data");
$item_per_page = 5;
//item to display per page
if (isset($_POST['page_index'])) {
    $page_start = $_POST['page_index'];
    $page_position = ($page_start - 1) * $item_per_page;
} else {
    $page_position = $utilities->replaceZero($_POST['page_start']);
}
$chef_id = $utilities->replaceDefault($_POST['chef_id']);
$dateTime = $utilities->replaceNow();
//print_r($_POST);
try {
    $query = " SELECT food_item.item_id,\n                        food_item.`name` AS food_name,\n                        food_item.description,\n                        food_item.ingredients,\n                        food_item.preparation_method,\n                        food_item.rating AS food_rating,\n                        category.category_id,\n                        category.category_name,\n                        food_item.price,\n                        currency.currency_id,\n                        currency.currency_name,\n                        currency.currency_symbol,\n                        chef.chef_id,\n                        CONCAT(chef.f_name, ' ', chef.l_name) AS chef_name,\n                        CONCAT(chef.country_code, chef.phone_number) AS chef_phone_number,\n                        chef.image_url AS chef_image,\n                        chef.rating AS chef_rating,\n                        food_item.nutrition,\n                        COALESCE(food_item.food_image_1, '') AS food_image_1,\n                        COALESCE(food_item.food_image_2, '') AS food_image_2,\n                        COALESCE(food_item.food_image_3, '') AS food_image_3,\n                        COALESCE(food_item.food_image_4, '') AS food_image_4,\n                        food_item.log_datetime\n                FROM food_item INNER JOIN category ON food_item.category_id = category.category_id\n                         INNER JOIN currency ON food_item.currency_id = currency.currency_id\n                         INNER JOIN chef ON food_item.chef_id = chef.chef_id ";
    $query .= $chef_id > 0 ? " WHERE food_item.chef_id = {$chef_id} " : " ";
    $query .= " ORDER BY food_name ASC\n                LIMIT {$page_position}, {$item_per_page};";
    //echo $query;
    $log->info("Query:" . $query);
    $statement = $dbConnection->prepare($query);
    $sql = "SELECT * FROM food_item";
    $result = $dbConnection->query($sql);
    $row = $result->fetchAll();
    $numOfRows = count($row);
    try {
        if ($statement->execute($bindParams)) {
<?php

include_once '../classes/PDOExt.php';
include_once '../classes/Utilities.php';
$dbConnection = new PDOExt();
$utilities = new Utilities();
$response = array();
$user_id = $utilities->replaceDefault($_POST['user_id']);
try {
    $query = "SELECT food_item.`name` AS food_name,\n                        food_item.description,\n                        food_item.ingredients,\n                        food_item.nutrition,\n                        food_item.preparation_method,\n                        food_item.food_image_1,\n                        food_item.food_image_2,\n                        food_item.food_image_3,\n                        food_item.food_image_4,\n                        food_item.rating,\n                        food_item.price,\n                        CONCAT(chef.f_name, chef.l_name) AS chef_name,\n                        chef.rating AS chef_rating,\n                        chef.image_url\n                FROM likes INNER JOIN food_item ON likes.food_item_id = food_item.item_id\n                         INNER JOIN chef ON food_item.chef_id = chef.chef_id\n                WHERE likes.user_id = '{$user_id}'";
    $statement = $dbConnection->prepare($query);
    try {
        if ($statement->execute($bindParams)) {
            $data = $statement->fetchAll(PDO::FETCH_ASSOC);
            $statement->closeCursor();
            $response = array('status' => 0, 'data' => $data, 'desc' => 'success');
        } else {
            $errorCode = -99;
            $dbError = $statement->errorInfo();
            $statement->closeCursor();
            $response = array('status' => $errorCode, 'data' => array(), 'desc' => 'DB error occured' . $dbError[2]);
        }
    } catch (PDOExecption $e) {
        $errorCode = -7;
        $statement->closeCursor();
        $error = "Exception: " . $e->getMessage();
        $response = array('status' => $errorCode, 'data' => array(), 'desc' => 'PDO exception occured' . $error);
    }
} catch (PDOExecption $e) {
    $errorCode = -8;
    $error = "Exception: " . $e->getMessage();