/** * Get the thumbnail relative URI. * * @param Thumbnail $thumb * * @return mixed */ private function getThumbnailUri(Thumbnail $thumb) { if ($thumb->getFileName() == null) { return false; } $app = $this->getContainer(); return $app['url_generator']->generate('thumb', ['width' => $thumb->getWidth(), 'height' => $thumb->getHeight(), 'action' => $thumb->getScale(), 'file' => $thumb->getFileName()]); }
$response['Content-Type'] = 'application/json'; $response->status(200); } catch (PDOException $e) { respondError($e->getMessage()); } }); $app->post('/cat/', function () use($app, $db) { $request = Slim::getInstance()->request(); $data = json_decode($request->getBody()); $thumbnail = new Thumbnail($data->thumbnail); try { $thumbnail->save(); } catch (Exception $e) { respondError($e->getMessage()); } $thumbnailFileName = $thumbnail->getFileName(); $sql = "INSERT INTO cats (name, description, data, author, isPublic, thumbnail, created) VALUES (:name, :description, :data, :author, :isPublic, :thumbnail, NOW())"; $isPublic = $data->isPublic == true ? 1 : 0; try { $stmt = $db->prepare($sql); $stmt->bindParam("name", $data->name); $stmt->bindParam("description", $data->description); $stmt->bindParam("data", json_encode($data->cat)); $stmt->bindParam("author", $data->author); $stmt->bindParam("isPublic", $isPublic); $stmt->bindParam("thumbnail", $thumbnailFileName); $stmt->execute(); $catId = $db->lastInsertId(); $responseData = array("id" => $catId); foreach ($data->tags as $tag) { $sql = "INSERT IGNORE INTO tags (label) VALUES (:label)";