Exemplo n.º 1
0
$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;
    }
    $jsonResponse = $bookmarks->fetchByUserAndId($currentUser['id'], $id);
    JsonView::render($jsonResponse);
})->via('GET', 'POST', 'PUT', 'DELETE');
/**
 * REVISIONS COLLECTION
 */
$app->get("/{$v}/tables/:table/rows/:id/revisions/?", function ($table, $id) use($acl, $ZendDb, $params) {
    $params['table_name'] = $table;
    $params['id'] = $id;
    $Activity = new DirectusActivityTableGateway($acl, $ZendDb);
    $revisions = $Activity->fetchRevisions($id, $table);
    JsonView::render($revisions);
Exemplo n.º 2
0
$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(['id' => $id]);
            }
            return;
    }
    $jsonResponse = $bookmarks->fetchByUserAndId($currentUser['id'], $id);
    JsonView::render($jsonResponse);
})->via('GET', 'POST', 'PUT', 'DELETE');
/**
 * REVISIONS COLLECTION
 */
$app->get("/{$v}/tables/:table/rows/:id/revisions/?", function ($table, $id) use($acl, $ZendDb, $params) {
    $params['table_name'] = $table;
    $params['id'] = $id;
    $Activity = new DirectusActivityTableGateway($acl, $ZendDb);
    $revisions = $Activity->fetchRevisions($id, $table);
    JsonView::render($revisions);