216 lines
9.6 KiB
PHP
216 lines
9.6 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('/ricette/:catID', function ($categoryID) use ($app) {
|
|
$callbackFn = $app->request()->get('callback');
|
|
$mysqlconnetion = new MysqlClass;
|
|
//$mysqlconnetion->connetti();
|
|
$query = "select * from (select ID as ricetta_id, titolo, autore, valutazione, difficolta, " .
|
|
"(select id from immagini where immagini.id_ricette = ricette.id and published = 1 order by published_date limit 1) as firstImage " .
|
|
"from ricette where ricette.ID_CATEGORIA = " . $categoryID . " order by titolo, autore) as TMP";
|
|
$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/: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('/ricette/: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('/ricette/search/:numItems/:startItem(/:categoryId(/:difficolta(/:titolo)))',
|
|
function ($numItems = 10, $startItem = 0, $categoryId = 0, $difficolta = 0, $titolo = "") use ($app) {
|
|
$callbackFn = $app->request()->get('callback');
|
|
$mysqlconnetion = new MysqlClass;
|
|
$queryBase = " from ricette"
|
|
. " INNER JOIN categorie ON categorie.ID = ricette.id_categoria"
|
|
. " where 1 = 1";
|
|
if ($categoryId > 0) {
|
|
$queryBase = $queryBase . " AND ID_CATEGORIA = " . $categoryId;
|
|
}
|
|
if ($titolo != null && $titolo != "") {
|
|
foreach (explode(" ", htmlentities(urldecode($titolo))) as $ele)
|
|
$queryBase = $queryBase . " AND titolo like '%" . $ele . "%'";
|
|
}
|
|
if ($difficolta > 0) {
|
|
$queryBase = $queryBase . " AND difficolta = " . $difficolta;
|
|
}
|
|
$queryBase = $queryBase . " order by titolo, autore";
|
|
|
|
$query = "select ricette.ID as ricetta_id, categorie.name AS categoria_name, titolo, autore, valutazione, difficolta" . $queryBase . " LIMIT " . $numItems * $startItem . " , " . $numItems;
|
|
$retObj2 = $mysqlconnetion->queryToObject($query);
|
|
|
|
$query = "select COUNT(*) as TotalRecords" . $queryBase;
|
|
$retObj = $mysqlconnetion->queryToObject($query);
|
|
|
|
$mysqlconnetion->disconnetti();
|
|
|
|
foreach ($retObj2 as $ele) {
|
|
$ele["titolo"] = html_entity_decode($ele["titolo"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
}
|
|
|
|
$retObj["records"] = $retObj2;
|
|
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 from immagini WHERE published = 1 AND ID_RICETTE = " . $itemID;
|
|
$photos = $mysqlconnetion->queryToObject($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"];
|
|
$retObj[0]["foto"] = $photos;
|
|
$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);
|
|
});
|
|
?>
|