private function initRoute() { $this->app->group('/ch/rammler/agenda', function () { $this->get('/', function ($request, $response, $args) { $res = DB::instance()->fetchRowMany('SELECT id, name, ort, start, ende, auftritt, highlight FROM agenda where start > SUBDATE(NOW(), 1) AND (ende > SUBDATE(NOW(), 1) OR ende IS NULL) order by start, ende, ordnung'); for ($i = 0; $i < count($res); $i++) { $res[$i]['datum'] = DateHelper::getAgendaDate($res[$i]['start'], $res[$i]['ende']); $res[$i]['link'] = $this->router->pathFor('agenda.entry', ['id' => $res[$i]['id']]); } $response = $response->withHeader('Content-Type', 'application/json'); return $response->write(json_encode($res, JSON_UNESCAPED_SLASHES)); })->setName('ist'); $this->get('/{id}', function ($request, $response, $args) { $res = DB::instance()->fetchRow('SELECT id, name, ort FROM agenda where id=:id', ['id' => $args['id']]); $res['_href'] = $this->router->pathFor('agenda.entry', ['id' => $res['id']]); $response = $response->withHeader('Content-Type', 'application/json'); return $response->write(json_encode($res, JSON_UNESCAPED_SLASHES)); })->setName('agenda.entry'); $this->delete('/{id}', function ($request, $response, $args) { $res = DB::instance()->delete('agenda', ['id' => $args['id']]); $response = $response->withHeader('Content-Type', 'application/json'); return $response->write(json_encode($res, JSON_UNESCAPED_SLASHES)); }); }); }
private function initRoute() { $this->app->group('/ch/rammler/vorstand', function () { $this->get('/', function ($request, $response, $args) { $res = DB::instance()->fetchRowMany("SELECT m.id, v.funktion, v.adresse, v.telefon, v.email, CONCAT(m.vorname, ' ', m.nachname) AS name FROM vorstand AS v INNER JOIN mitglied AS m ON v.fk_mitglied=m.id ORDER BY v.reihenfolge"); for ($i = 0; $i < count($res); $i++) { $res[$i]['url'] = $this->router->pathFor('register.bild', ['id' => $res[$i]['id']]); $res[$i]['thumbUrl'] = $this->router->pathFor('register.thumb', ['id' => $res[$i]['id']]); $type = $i % 2 == 0 ? "r" : "l"; $res[$i]['thumb'] = $this->router->pathFor('mitglied.bild.small', ['id' => $res[$i]['id'], 'type' => $type]); } $response = $response->withHeader('Content-Type', 'application/json'); return $response->write(json_encode($res, JSON_UNESCAPED_SLASHES)); }); }); }
private function initRoute() { $this->app->group('/ch/rammler/galerie', function () { $this->get('/', function ($request, $response, $args) { $res = DB::instance()->fetchRowMany('SELECT g.id, g.name, g.ort, count(b.id) AS bilder FROM galerie AS g LEFT JOIN bild AS b ON g.id=b.fk_galerie GROUP BY g.id ORDER BY g.datum DESC'); $response = $response->withHeader('Content-Type', 'application/json'); return $response->write(json_encode($res, JSON_UNESCAPED_SLASHES)); }); $this->get('/aktiv', function ($request, $response, $args) { $res = DB::instance()->fetchRowMany('SELECT g.id, g.name, g.ort, b.name AS bild_name FROM galerie AS g LEFT JOIN bild AS b ON g.id=b.fk_galerie WHERE b.id > 0 GROUP BY g.id ORDER BY g.datum DESC'); $response = $response->withHeader('Content-Type', 'application/json'); for ($i = 0; $i < count($res); $i++) { $res[$i]['thumbUrl'] = $this->router->pathFor('galerie.thumb', ['galerie' => $res[$i]['id'], 'name' => $res[$i]['bild_name']]); } return $response->write(json_encode($res, JSON_UNESCAPED_SLASHES)); }); $this->get('/{id}', function ($request, $response, $args) { $response = $response->withHeader('Content-Type', 'application/json'); $res = DB::instance()->fetchRow('SELECT id, name FROM galerie WHERE id=:id', ['id' => $args['id']]); $res_bilder = DB::instance()->fetchRowMany('SELECT id, name FROM bild WHERE fk_galerie=:id ORDER BY datum ASC', ['id' => $res['id']]); for ($i = 0; $i < count($res_bilder); $i++) { $res_bilder[$i]['url'] = $this->router->pathFor('galerie.bild', ['galerie' => $res['id'], 'name' => $res_bilder[$i]['name']]); $res_bilder[$i]['thumbUrl'] = $this->router->pathFor('galerie.thumb', ['galerie' => $res['id'], 'name' => $res_bilder[$i]['name']]); } $res['bilder'] = $res_bilder; return $response->write(json_encode($res, JSON_UNESCAPED_SLASHES)); })->setName('galerie'); $this->get('/{galerie}/bild/{name}', function ($request, $response, $args) { $image = '../galerie/' . $args['galerie'] . '/' . $args['name'] . '.jpg'; $response = $response->withHeader('Content-Type', 'image/jpg'); return $response->write(file_get_contents($image)); })->setName('galerie.bild'); $this->get('/{galerie}/thumb/{name}', function ($request, $response, $args) { $image = '../galerie/' . $args['galerie'] . '/thumbs/' . $args['name'] . '.jpg'; $response = $response->withHeader('Content-Type', 'image/jpg'); return $response->write(file_get_contents($image)); })->setName('galerie.thumb'); }); }
private function initRoute() { $this->app->group('/ch/rammler/register', function () { $this->get('/', function ($request, $response, $args) { $res = DB::instance()->fetchRowMany('SELECT id, name FROM instrument order by id'); $response = $response->withHeader('Content-Type', 'application/json'); return $response->write(json_encode($res, JSON_UNESCAPED_SLASHES)); }); $this->get('/{id:[0-9]+}/mitglied', function ($request, $response, $args) { $res = DB::instance()->fetchRowMany('SELECT id, vorname, nachname, spitzname, eintritt FROM mitglied WHERE fk_instrument=:id AND fk_status IN (1,2) ORDER BY vorname, nachname', ['id' => $args['id']]); for ($i = 0; $i < count($res); $i++) { $res[$i]['name'] = $res[$i]['vorname'] . " " . $res[$i]['nachname']; $res[$i]['url'] = $this->router->pathFor('register.bild', ['id' => $res[$i]['id']]); $res[$i]['thumbUrl'] = $this->router->pathFor('register.thumb', ['id' => $res[$i]['id']]); $type = $i % 2 == 0 ? "r" : "l"; $res[$i]['thumb'] = $this->router->pathFor('mitglied.bild.small', ['id' => $res[$i]['id'], 'type' => $type]); $res[$i]['type'] = $type; } $response = $response->withHeader('Content-Type', 'application/json'); return $response->write(json_encode($res, JSON_UNESCAPED_SLASHES)); }); $this->get('/{name:[a-z]+}/mitglied', function ($request, $response, $args) { $res = DB::instance()->fetchRowMany('SELECT m.id, m.vorname, m.nachname, m.spitzname, m.eintritt FROM mitglied as m inner join instrument as i on m.fk_instrument=i.id WHERE lower(i.name)=lower(:name) AND m.fk_status IN (1,2) ORDER BY m.vorname, m.nachname', ['name' => $args['name']]); for ($i = 0; $i < count($res); $i++) { $res[$i]['name'] = $res[$i]['vorname'] . " " . $res[$i]['nachname']; $res[$i]['url'] = $this->router->pathFor('register.bild', ['id' => $res[$i]['id']]); $res[$i]['thumbUrl'] = $this->router->pathFor('register.thumb', ['id' => $res[$i]['id']]); $type = $i % 2 == 0 ? "r" : "l"; $res[$i]['thumb'] = $this->router->pathFor('mitglied.bild.small', ['id' => $res[$i]['id'], 'type' => $type]); $res[$i]['type'] = $type; } $response = $response->withHeader('Content-Type', 'application/json'); return $response->write(json_encode($res, JSON_UNESCAPED_SLASHES)); }); $this->get('/bild/{id}', function ($request, $response, $args) { $response = $response->withHeader('Content-Type', 'image/png'); if (file_exists('./images/mitglied/' . $args['id'] . '.png')) { return $response->write(file_get_contents('./images/mitglied/' . $args['id'] . '.png')); } return $response->write(file_get_contents('./images/mitglied/default.png')); })->setName('register.bild'); $this->get('/thumb/{id}', function ($request, $response, $args) { $response = $response->withHeader('Content-Type', 'image/png'); if (file_exists('./images/mitglied/small/' . $args['id'] . '.png')) { return $response->write(file_get_contents('./images/mitglied/small/' . $args['id'] . '.png')); } return $response->write(file_get_contents('./images/mitglied/small/default.png')); })->setName('register.thumb'); }); $this->app->group('/ch/rammler/mitglied', function () { $this->get('/', function ($request, $response, $args) { // TODO: $res = DB::instance()->fetchRowMany('SELECT m.id, m.vorname, m.nachname FROM mitglied as m ORDER BY m.nachname, m.vorname'); $res = DB::instance()->fetchRowMany('SELECT m.id, m.vorname, m.nachname FROM mitglied as m ORDER BY m.vorname, m.nachname'); $response = $response->withHeader('Content-Type', 'application/json'); return $response->write(json_encode($res, JSON_UNESCAPED_SLASHES)); }); $this->get('/bild/{id}/{type}', function ($request, $response, $args) { $img = $args['id'] . $args['type'] . '.jpg'; if (file_exists('./images/mitglied/1617/' . $img)) { $response = $response->withHeader('Content-Type', 'image/jpeg'); return $response->write(file_get_contents('./images/mitglied/1617/' . $img)); } $response = $response->withHeader('Content-Type', 'image/png'); return $response->write(file_get_contents('./images/mitglied/1617/default.png')); })->setName('mitglied.bild'); $this->get('/bild/{id}/{type}/small', function ($request, $response, $args) { $img = $args['id'] . $args['type'] . '.jpg'; if (file_exists('./images/mitglied/1617/small/' . $img)) { $response = $response->withHeader('Content-Type', 'image/jpeg'); return $response->write(file_get_contents('./images/mitglied/1617/small/' . $img)); } $response = $response->withHeader('Content-Type', 'image/png'); return $response->write(file_get_contents('./images/mitglied/1617/small/default.png')); })->setName('mitglied.bild.small'); }); }
private function initRoute() { $this->app->group('/ch/rammler/mitgliederportrait', function () { $this->get('/', function ($request, $response, $args) { $res = DB::instance()->fetchRowMany(Mitgliederportrait::$mitgliederportrait_sql . ' WHERE m.id NOT IN (6, 19, 20, 26, 32)'); for ($i = 0; $i < count($res); $i++) { $type = $i % 2 == 0 ? "r" : "l"; $res[$i]['thumb'] = $this->router->pathFor('mitglied.bild.small', ['id' => $res[$i]['id'], 'type' => $type]); $res[$i]['type'] = $type; } $response = $response->withHeader('Content-Type', 'application/json'); return $response->write(json_encode($res, JSON_UNESCAPED_SLASHES)); }); $this->get('/{id:[0-9]+}/{type:[lr]}', function ($request, $response, $args) { $res = DB::instance()->fetchRow(Mitgliederportrait::$mitgliederportrait_sql . ' WHERE m.id=:id', ['id' => $args['id']]); $res['fragebogen'] = DB::instance()->fetchRowMany('SELECT f.frage, a.antwort FROM mitgliederportrait_frage AS f INNER JOIN mitgliederportrait_antwort AS a ON f.id=a.fk_frage WHERE fk_saison=1 AND fk_mitglied=:id ORDER BY f.id;', ['id' => $args['id']]); $res['image'] = $this->router->pathFor('mitglied.bild', ['id' => $res['id'], 'type' => $args['type']]); $response = $response->withHeader('Content-Type', 'application/json'); return $response->write(json_encode($res, JSON_UNESCAPED_SLASHES)); })->setName('mitgliederportrait'); $this->get('/fragen', function ($request, $response, $args) { $res = DB::instance()->fetchRowMany('SELECT * FROM mitgliederportrait_frage'); $response = $response->withHeader('Content-Type', 'application/json'); return $response->write(json_encode($res, JSON_UNESCAPED_SLASHES)); }); $this->get('/{id:[0-9]+}/antworten', function ($request, $response, $args) { $res = DB::instance()->fetchRowMany('SELECT * FROM mitgliederportrait_antwort WHERE fk_mitglied=' . $args['id']); $response = $response->withHeader('Content-Type', 'application/json'); return $response->write(json_encode($res, JSON_UNESCAPED_SLASHES)); }); $this->put('/{id:[0-9]+}/antworten', function ($request, $response, $args) { $fehler = false; $antworten = $request->getParsedBody(); foreach ($antworten as $antwort) { if (!DB::instance()->ExecuteSQL('INSERT INTO mitgliederportrait_antwort (antwort, fk_frage, fk_mitglied) VALUES ("' . $antwort['antwort'] . '",' . $antwort['frage'] . ',' . $args['id'] . ')')) { $fehler = true; } } if ($fehler) { $response = $response->withStatus(500); } else { $response = $response->withStatus(201); } $response = $response->withHeader('Content-Type', 'application/json'); return $response->write(json_encode("", JSON_UNESCAPED_SLASHES)); }); $this->get('/fototermin', function ($request, $response, $args) { $res = DB::instance()->fetchRowMany('SELECT * FROM fototermin'); $response = $response->withHeader('Content-Type', 'application/json'); return $response->write(json_encode($res, JSON_UNESCAPED_SLASHES)); }); $this->put('/{id:[0-9]+}/fototermin/{terminid:[0-9]+}', function ($request, $response, $args) { if (DB::instance()->ExecuteSQL('INSERT INTO fototermin_mitglied (fk_mitglied, fk_termin) VALUES (' . $args['id'] . ',' . $args['terminid'] . ')')) { $response = $response->withStatus(201); } else { $response = $response->withStatus(500); } return $response->write(json_encode("", JSON_UNESCAPED_SLASHES)); }); }); }