get('/profile/statusCache', function () use ($app) { $callbackFn = $app->request()->get('callback'); $mysqlconnetion = new MysqlClass; $query = "select 0 as ID_CATEGORIA, MAX(Data_creazione) as LastDateModified from categorie" . " UNION" . " select ID_CATEGORIA, MAX(Data_creazione) as LastDateModified from ricette" . " GROUP BY ID_CATEGORIA"; $retObj = $mysqlconnetion->queryToObject($query); $mysqlconnetion->disconnetti(); returnJson($app, $callbackFn, $retObj); }); $app->get('/profile/:keyStore/ricetta/:ricetta_id', function ($keyStore, $ricetta_id) use ($app) { $callbackFn = $app->request()->get('callback'); $mysqlconnetion = new MysqlClass; $query = "select COUNT(*) as Exist FROM blocco_note where ricetta_id = " . $ricetta_id . " AND ProfiloID = '" . $keyStore . "'"; $retObj = $mysqlconnetion->queryToObject($query); $mysqlconnetion->disconnetti(); returnJson($app, $callbackFn, $retObj[0]["Exist"]); }); $app->post('/profile/ricetta', function () use ($app) { $callbackFn = $app->request()->get('callback'); $json_data_body = json_decode($app->request()->post('dataPair')); $mysqlconnetion = new MysqlClass; $query = "update profilo set BloccoNoteUpdated = CURRENT_TIMESTAMP WHERE ProfiloID = '" . $json_data_body->keyStore . "'"; $retNewID = $mysqlconnetion->insertRecord($query); $query = "insert into blocco_note(ricetta_id, ProfiloID) values (" . $json_data_body->ricetta_id . ", '" . $json_data_body->keyStore . "')"; $retNewID = $mysqlconnetion->insertRecord($query); $mysqlconnetion->disconnetti(); returnJson($app, $callbackFn, $retNewID); }); $app->delete('/profile/:keyStore/ricetta/:ricetta_id', function ($keyStore, $ricetta_id) use ($app) { //$callbackFn = $app->request()->params('callback'); $mysqlconnetion = new MysqlClass; $query = "delete from blocco_note where ricetta_id = " . $ricetta_id . " AND ProfiloID = '" . $keyStore . "'"; $retNewID = $mysqlconnetion->insertRecord($query); $mysqlconnetion->disconnetti(); echo $retNewID; //returnJson($app, $callbackFn, $retNewID); }); $app->delete('/profile/:keyStore/ricette', function ($keyStore) use ($app) { $callbackFn = $app->request()->get('callback'); $mysqlconnetion = new MysqlClass; $query = "delete from blocco_note where ProfiloID = '" . $keyStore . "'"; $retNewID = $mysqlconnetion->insertRecord($query); $mysqlconnetion->disconnetti(); returnJson($app, $callbackFn, $retNewID); }); $app->get('/profile/:keyStore/ricette', function ($keyStore) use ($app) { $callbackFn = $app->request()->get('callback'); $mysqlconnetion = new MysqlClass; $query = "select ID as ricetta_id, titolo, autore, valutazione, difficolta from ricette" . " INNER JOIN blocco_note ON blocco_note.ricetta_id = ricette.id" . " where blocco_note.ProfiloID = '" . $keyStore . "' order by titolo, autore"; $retObj = $mysqlconnetion->queryToObject($query); $mysqlconnetion->disconnetti(); foreach ($retObj as $ele) { $ele["titolo"] = html_entity_decode($ele["titolo"]); } returnJson($app, $callbackFn, $retObj); }); $app->get('/profile/:keyStore', function ($keyStore) use ($app) { $callbackFn = $app->request()->get('callback'); $mysqlconnetion = new MysqlClass; $query = "select ProfiloID, TipoAccesso, RisultatiRicerca, TemaUI, Name, Gender, 0 as NumRicette, BloccoNoteUpdated from profilo" . " where ProfiloID = '" . $keyStore . "'"; $retObj = $mysqlconnetion->queryToObject($query); $query = "update profilo set PenultimoAccesso = UltimoAccesso, UltimoAccesso = NOW() where ProfiloID = '" . $keyStore . "'"; $mysqlconnetion->insertRecord($query); $query = "SELECT COUNT( * ) as NumNotifiche" . " FROM notifiche" . " inner join conferma_lettura_profilo on notifiche.id = conferma_lettura_profilo.id_notifica" . " where conferma_lettura_profilo.id_profilo = '" . $keyStore . "' and notifiche.Type = 1 ". " AND conferma_lettura_profilo.conferma_lettura = 0"; $retObj2 = $mysqlconnetion->queryToObject($query); $retObj[0]["NumNotifiche"] = $retObj2[0]["NumNotifiche"]; $query = "SELECT COUNT( * ) as NumLastRicette ". " FROM notifiche" . " inner join conferma_lettura_profilo on notifiche.id = conferma_lettura_profilo.id_notifica" . " where conferma_lettura_profilo.id_profilo = '" . $keyStore . "' and notifiche.Type = 2" . " AND conferma_lettura_profilo.conferma_lettura = 0" . " ORDER BY CreatoIl desc" . " LIMIT 1"; $retObj3 = $mysqlconnetion->queryToObject($query); $retObj[0]["NumLastRicette"] = $retObj3[0]["NumLastRicette"]; returnJson($app, $callbackFn, $retObj); }); $app->get('/profile/:keyStore/notification/:id', function ($keyStore, $idNotification) use ($app) { $callbackFn = $app->request()->get('callback'); $mysqlconnetion = new MysqlClass; $query = "SELECT id, titolo, descrizione, type" . " FROM notifiche" . " where id = " . $idNotification; $retObj = $mysqlconnetion->queryToObject($query); $query = "UPDATE conferma_lettura_profilo SET conferma_lettura = 1 WHERE id_notifica = " . $idNotification . " AND id_profilo = '" . $keyStore . "'"; $retNewID = $mysqlconnetion->insertRecord($query); returnJson($app, $callbackFn, $retObj); }); $app->get('/profile/:keyStore/notifications', function ($keyStore) use ($app) { $callbackFn = $app->request()->get('callback'); $mysqlconnetion = new MysqlClass; $query = "SELECT id, titolo, type, CreatoIl, conferma_lettura_profilo.conferma_lettura" . " FROM notifiche" . " inner join conferma_lettura_profilo on notifiche.id = conferma_lettura_profilo.id_notifica" . " where conferma_lettura_profilo.id_profilo = '" . $keyStore . "' and notifiche.Type = 1" . " UNION" . " (SELECT id, titolo, type, CreatoIl, conferma_lettura_profilo.conferma_lettura" . " FROM notifiche" . " inner join conferma_lettura_profilo on notifiche.id = conferma_lettura_profilo.id_notifica" . " where conferma_lettura_profilo.id_profilo = '" . $keyStore . "' and notifiche.Type = 2" . " ORDER BY CreatoIl desc" . " LIMIT 1" . " )" . " ORDER BY CreatoIl desc"; $retObj = $mysqlconnetion->queryToObject($query); returnJson($app, $callbackFn, $retObj); }); $app->post('/profile', function () use ($app) { $callbackFn = $app->request()->get('callback'); $json_data_body = json_decode($app->request()->post('dataPair')); $mysqlconnetion = new MysqlClass; $query = "insert into profilo(ProfiloID, Name, Email, Gender, TipoAccesso, RisultatiRicerca, TemaUI, UltimoAccesso, CreatoIl) values ('" . $json_data_body->keyStore . "', '" . $json_data_body->name . "', '" . $json_data_body->email . "', '" . $json_data_body->gender . "', '" . $json_data_body->type . "', '" . $json_data_body->risRic . "', '" . $json_data_body->tema . "', NOW(), NOW())"; $retNewID = $mysqlconnetion->insertRecord($query); $mysqlconnetion->disconnetti(); returnJson($app, $callbackFn, $retNewID); }); $app->put('/profile', function () use ($app) { $callbackFn = $app->request()->get('callback'); $json_data_body = json_decode($app->request()->post('dataPair')); $mysqlconnetion = new MysqlClass; $query = "update profilo set RisultatiRicerca = '" . $json_data_body->risRic . "', TemaUI = '" . $json_data_body->tema . "' where ProfiloID = '" . $json_data_body->keyStore . "'"; $retNewID = $mysqlconnetion->insertRecord($query); $mysqlconnetion->disconnetti(); returnJson($app, $callbackFn, $retNewID); }); ?>