} JsonView::render($jsonResponse); })->via('GET', 'POST', 'PUT', 'DELETE'); $app->get("/{$v}/preferences/:table", function ($table) use($app, $ZendDb, $acl) { $currentUser = Auth::getUserInfo(); $params['table_name'] = $table; $Preferences = new DirectusPreferencesTableGateway($acl, $ZendDb); $jsonResponse = $Preferences->fetchSavedPreferencesByUserAndTable($currentUser['id'], $table); JsonView::render($jsonResponse); }); /** * BOOKMARKS COLLECTION */ $app->map("/{$v}/bookmarks(/:id)/?", function ($id = null) use($params, $app, $ZendDb, $acl, $requestPayload) { $currentUser = Auth::getUserInfo(); $bookmarks = new DirectusBookmarksTableGateway($acl, $ZendDb); switch ($app->request()->getMethod()) { case "PUT": $bookmarks->updateBookmark($requestPayload); $id = $requestPayload['id']; break; case "POST": $requestPayload['user'] = $currentUser['id']; $id = $bookmarks->insertBookmark($requestPayload); break; case "DELETE": $bookmark = $bookmarks->fetchByUserAndId($currentUser['id'], $id); if ($bookmark) { echo $bookmarks->delete(array('id' => $id)); } return;
function getBookmarks() { global $ZendDb, $acl, $authenticatedUser; $bookmarks = new DirectusBookmarksTableGateway($acl, $ZendDb); return $bookmarks->fetchAllByUser($authenticatedUser['id']); }