202 lines
8.9 KiB
PHP
202 lines
8.9 KiB
PHP
<?php
|
|
|
|
// inclusione del file contenente la classe
|
|
require_once "./include.php";
|
|
|
|
$app->get('/categories', function () use ($app) {
|
|
$callbackFn = $app->request()->get('callback');
|
|
$mysqlconnetion = new MysqlClass;
|
|
//$mysqlconneti on->connetti();
|
|
$retObj = $mysqlconnetion->queryToObject("select ID as category_id, NAME as name from categorie order by name");
|
|
$mysqlconnetion->disconnetti();
|
|
|
|
returnJson($app, $callbackFn, $retObj);
|
|
});
|
|
|
|
$app->get('/typeingredients', function () use ($app) {
|
|
$callbackFn = $app->request()->get('callback');
|
|
$mysqlconnetion = new MysqlClass;
|
|
//$mysqlconnetion->connetti();
|
|
$retObj = $mysqlconnetion->queryToObject("select ID as tipo_ingredienti_id, name from tipo_ingredienti order by name");
|
|
$mysqlconnetion->disconnetti();
|
|
|
|
returnJson($app, $callbackFn, $retObj);
|
|
});
|
|
|
|
$app->get('/typeqtys', function () use ($app) {
|
|
$callbackFn = $app->request()->get('callback');
|
|
$mysqlconnetion = new MysqlClass;
|
|
//$mysqlconnetion->connetti();
|
|
$retObj = $mysqlconnetion->queryToObject("select ID as tipo_quantita_id, name from tipo_quantita");
|
|
$mysqlconnetion->disconnetti();
|
|
|
|
returnJson($app, $callbackFn, $retObj);
|
|
});
|
|
|
|
$app->get('/categoryitems/:catID', function ($categoryID) use ($app) {
|
|
$callbackFn = $app->request()->get('callback');
|
|
$mysqlconnetion = new MysqlClass;
|
|
//$mysqlconnetion->connetti();
|
|
$query = "select ID as ricetta_id, titolo, autore, valutazione, difficolta from ricette where ID_CATEGORIA = " . $categoryID . " order by titolo, autore";
|
|
$retObj = $mysqlconnetion->queryToObject($query);
|
|
$mysqlconnetion->disconnetti();
|
|
|
|
foreach ($retObj as $ele) {
|
|
$ele["titolo"] = html_entity_decode($ele["titolo"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
}
|
|
|
|
returnJson($app, $callbackFn, $retObj);
|
|
});
|
|
|
|
$app->get('/categoryitems/:categoryID/mostvote(/:numItems)', function ($categoryID, $numItems = 10) use ($app) {
|
|
$callbackFn = $app->request()->get('callback');
|
|
$mysqlconnetion = new MysqlClass;
|
|
//$mysqlconnetion->connetti();
|
|
$query = "select ID as ricetta_id, titolo, autore from ricette where ID_CATEGORIA = " . $categoryID . " order by Valutazione desc, titolo, autore LIMIT " . $numItems;
|
|
$retObj = $mysqlconnetion->queryToObject($query);
|
|
$mysqlconnetion->disconnetti();
|
|
|
|
foreach ($retObj as $ele) {
|
|
$ele["titolo"] = html_entity_decode($ele["titolo"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
}
|
|
|
|
returnJson($app, $callbackFn, $retObj);
|
|
});
|
|
|
|
$app->get('/categoryitems/:categoryID/lastinserted(/:numItems)', function ($categoryID, $numItems = 10) use ($app) {
|
|
$callbackFn = $app->request()->get('callback');
|
|
$mysqlconnetion = new MysqlClass;
|
|
//$mysqlconnetion->connetti();
|
|
$query = "select ID as ricetta_id, titolo, autore from ricette where ID_CATEGORIA = " . $categoryID . " order by Data_creazione desc, titolo, autore LIMIT " . $numItems;
|
|
$retObj = $mysqlconnetion->queryToObject($query);
|
|
$mysqlconnetion->disconnetti();
|
|
|
|
foreach ($retObj as $ele) {
|
|
$ele["titolo"] = html_entity_decode($ele["titolo"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
}
|
|
|
|
returnJson($app, $callbackFn, $retObj);
|
|
});
|
|
|
|
$app->get('/categoryitems/search/:numItems(/:categoryId(/:difficolta(/:titolo)))',
|
|
function ($numItems = 10, $categoryId = 0, $difficolta = 0, $titolo = "") use ($app) {
|
|
$callbackFn = $app->request()->get('callback');
|
|
$mysqlconnetion = new MysqlClass;
|
|
$query = "select ricette.ID as ricetta_id, categorie.name AS categoria_name, titolo, autore, valutazione, difficolta from ricette"
|
|
. " INNER JOIN categorie ON categorie.ID = ricette.id_categoria"
|
|
. " where 1 = 1";
|
|
if ($categoryId > 0) {
|
|
$query = $query . " AND ID_CATEGORIA = " . $categoryId;
|
|
}
|
|
if ($titolo != null && $titolo != "") {
|
|
foreach (explode(" ", htmlentities(urldecode($titolo))) as $ele)
|
|
$query = $query . " AND titolo like '%" . $ele . "%'";
|
|
}
|
|
if ($difficolta > 0) {
|
|
$query = $query . " AND difficolta = " . $difficolta;
|
|
}
|
|
$query = $query . " order by titolo, autore LIMIT " . $numItems;
|
|
|
|
$retObj = $mysqlconnetion->queryToObject($query);
|
|
$mysqlconnetion->disconnetti();
|
|
|
|
foreach ($retObj as $ele) {
|
|
$ele["titolo"] = html_entity_decode($ele["titolo"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
}
|
|
returnJson($app, $callbackFn, $retObj);
|
|
});
|
|
|
|
$app->get('/ricette/authors(/:startWith)',
|
|
function ($startWith = "") use ($app) {
|
|
$callbackFn = $app->request()->get('callback');
|
|
$mysqlconnetion = new MysqlClass;
|
|
$query = "select distinct autore from ricette"
|
|
. " where 1 = 1";
|
|
|
|
if ($startWith != null && $startWith != "") {
|
|
$query = $query . " AND autore like '%" . $startWith . "%'";
|
|
}
|
|
|
|
$query = $query . " order by autore";
|
|
|
|
$retObj = $mysqlconnetion->queryToObject($query);
|
|
$mysqlconnetion->disconnetti();
|
|
|
|
returnJson($app, $callbackFn, $retObj);
|
|
});
|
|
|
|
$app->get('/ricetta/body/:itemID', function ($itemID) use ($app) {
|
|
$callbackFn = $app->request()->get('callback');
|
|
$mysqlconnetion = new MysqlClass;
|
|
|
|
$query = "UPDATE ricette Set valutazione = valutazione + 1 WHERE ricette.ID = " . $itemID;
|
|
$mysqlconnetion->executeQuery($query);
|
|
|
|
$query = "SELECT id_categoria, categorie.name AS categoria_name, ricette.ID AS ricetta_id, titolo, procedimento, autore, link_fonte, link_youtube, valutazione FROM ricette INNER JOIN categorie ON categorie.ID = ricette.id_categoria WHERE ricette.ID = " . $itemID;
|
|
$retObj = $mysqlconnetion->queryToObject($query);
|
|
|
|
$query2 = "select ingredienti.id_tipo_ingredienti, tipo_ingredienti.name as nome_ingrediente, quantita, ingredienti.id_tipo_quantita, tipo_quantita.Name as unita, note, posizione from ingredienti " .
|
|
"inner join tipo_ingredienti on ingredienti.ID_TIPO_INGREDIENTI = tipo_ingredienti.ID " .
|
|
"left outer join tipo_quantita on ingredienti.ID_TIPO_QUANTITA = tipo_quantita.ID " .
|
|
"where ingredienti.ID_RICETTE = " . $itemID . " order by ingredienti.posizione";
|
|
|
|
$retObj2 = $mysqlconnetion->queryToObject($query2);
|
|
|
|
foreach ($retObj2 as $ele) {
|
|
$ele["note"] = html_entity_decode($ele["note"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
}
|
|
|
|
$retObj[0]["titolo"] = html_entity_decode($retObj[0]["titolo"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
$retObj[0]["procedimento"] = html_entity_decode($retObj[0]["procedimento"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
$retObj[0]["ingredienti"] = $retObj2;
|
|
|
|
$mysqlconnetion->disconnetti();
|
|
|
|
returnJson($app, $callbackFn, $retObj);
|
|
});
|
|
|
|
$app->get('/ricetta/header/:itemID', function ($itemID) use ($app) {
|
|
$callbackFn = $app->request()->get('callback');
|
|
$mysqlconnetion = new MysqlClass;
|
|
$query = "UPDATE ricette Set valutazione = valutazione + 1 WHERE ricette.ID = " . $itemID;
|
|
$mysqlconnetion->executeQuery($query);
|
|
$query = "SELECT id_categoria, categorie.name AS categoria_name, ricette.ID AS ricetta_id, titolo, procedimento, autore, link_fonte, link_youtube, valutazione FROM ricette INNER JOIN categorie ON categorie.ID = ricette.id_categoria WHERE ricette.ID = " . $itemID;
|
|
$retObj = $mysqlconnetion->queryToObject($query);
|
|
$retObj[0]["titolo"] = html_entity_decode($retObj[0]["titolo"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
$retObj[0]["procedimento"] = html_entity_decode($retObj[0]["procedimento"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
$data = $retObj[0]["link_youtube"];
|
|
$output = array();
|
|
if ($data != "") {
|
|
$d = explode(";", $data);
|
|
$index = 0;
|
|
foreach ($d as $ele) {
|
|
$obj["VideoID"] = $ele;
|
|
$output[$index] = $obj;
|
|
$index++;
|
|
}
|
|
}
|
|
$retObj[0]["link_youtube"] = $output;
|
|
$mysqlconnetion->disconnetti();
|
|
returnJson($app, $callbackFn, $retObj);
|
|
});
|
|
|
|
$app->get('/ricetta/ingredienti/:itemID', function ($itemID) use ($app) {
|
|
$callbackFn = $app->request()->get('callback');
|
|
$mysqlconnetion = new MysqlClass;
|
|
$query2 = "select ingredienti.id_tipo_ingredienti, tipo_ingredienti.name as nome_ingrediente, quantita, ingredienti.id_tipo_quantita, tipo_quantita.Name as unita, note, posizione from ingredienti " .
|
|
"inner join tipo_ingredienti on ingredienti.ID_TIPO_INGREDIENTI = tipo_ingredienti.ID " .
|
|
"left outer join tipo_quantita on ingredienti.ID_TIPO_QUANTITA = tipo_quantita.ID " .
|
|
"where ingredienti.ID_RICETTE = " . $itemID . " order by ingredienti.posizione";
|
|
|
|
$retObj2 = $mysqlconnetion->queryToObject($query2);
|
|
|
|
foreach ($retObj2 as $ele) {
|
|
$ele["note"] = html_entity_decode($ele["note"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
}
|
|
|
|
$mysqlconnetion->disconnetti();
|
|
|
|
returnJson($app, $callbackFn, $retObj2);
|
|
});
|
|
?>
|