Exemple #1
0
    //If Title is set then return this version
    if (isset($requestPayload['title'])) {
        $params['newTitle'] = $requestPayload['title'];
    }
    if (isset($params['newTitle'])) {
        $jsonResponse = $Preferences->fetchByUserAndTableAndTitle($currentUser['id'], $table, $params['newTitle']);
        // $Preferences->updateDefaultByName($currentUser['id'], $table, $jsonResponse);
    } else {
        $jsonResponse = $Preferences->fetchByUserAndTableAndTitle($currentUser['id'], $table);
    }
    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":
Exemple #2
0
 public static function getAllSchemas($userGroupId, $versionHash)
 {
     $cacheKey = MemcacheProvider::getKeyDirectusGroupSchema($userGroupId, $versionHash);
     $acl = Bootstrap::get('acl');
     $ZendDb = Bootstrap::get('ZendDb');
     $directusPreferencesTableGateway = new DirectusPreferencesTableGateway($acl, $ZendDb);
     $getPreferencesFn = function () use($directusPreferencesTableGateway) {
         $currentUser = Auth::getUserInfo();
         $preferences = $directusPreferencesTableGateway->fetchAllByUser($currentUser['id']);
         return $preferences;
     };
     $getSchemasFn = function () {
         $tableSchemas = TableSchema::getTableSchemas();
         $columnSchemas = TableSchema::getColumnSchemas();
         // Nest column schemas in table schemas
         foreach ($tableSchemas as &$table) {
             $tableName = $table['id'];
             $table['columns'] = array_values($columnSchemas[$tableName]);
             foreach ($columnSchemas[$tableName] as $column) {
                 if ($column['column_key'] == 'PRI') {
                     $table['primary_column'] = $column['column_name'];
                     break;
                 }
             }
             $table = array('schema' => $table);
         }
         return $tableSchemas;
     };
     // 3 hr cache
     $schemas = $directusPreferencesTableGateway->memcache->getOrCache($cacheKey, $getSchemasFn, 10800);
     // Append preferences post cache
     $preferences = $getPreferencesFn();
     foreach ($schemas as &$table) {
         $table['preferences'] = $preferences[$table['schema']['id']];
     }
     return $schemas;
 }