예제 #1
0
        $response = array_key_exists($id, $response) ? $response[$id] : null;
    }
    if (!$response) {
        $response = ['message' => __t('unable_to_find_setting_collection_x', ['collection' => $id]), 'success' => false];
    }
    JsonView::render($response);
})->via('GET', 'POST', 'PUT');
/**
 * /tables
 * List of viewable tables for the authenticated user group
 *
 * return list of objects with the name of the table
 * Ex. [{name: 'articles'}, {name: 'projects'}]
 */
$app->get("/{$v}/tables/?", function () use($ZendDb, $acl, $app) {
    $tablesNames = TableSchema::getTablenames(false);
    $tables = array_map(function ($table) {
        return ['table_name' => $table];
    }, $tablesNames);
    JsonView::render($tables);
});
// GET and PUT table details
$app->map("/{$v}/tables/:table/?", function ($table) use($ZendDb, $acl, $params, $requestPayload, $app) {
    if ($app->request()->isDelete()) {
        $tableGateway = new TableGateway($acl, $table, $ZendDb);
        $success = $tableGateway->drop();
        $response = ['message' => __t('unable_to_remove_table_x', ['table_name' => $table]), 'success' => false];
        if ($success) {
            $response['success'] = true;
            $response['message'] = __t('table_x_was_removed');
        }
 public function fetchPerTable($groupId)
 {
     // Don't include tables that can't have privileges changed
     /*$blacklist = array(
           'directus_columns',
           'directus_ip_whitelist',
           'directus_messages_recipients',
           'directus_preferences',
           'directus_privileges',
           'directus_settings',
           'directus_social_feeds',
           'directus_social_posts',
           'directus_storage_adapters',
           'directus_tab_privileges',
           'directus_tables',
           'directus_ui',
           'directus_users_copy'
       );*/
     $blacklist = array();
     $select = new Select($this->table);
     $select->where->equalTo('group_id', $groupId);
     $select->group(array('group_id', 'table_name', 'status_id'));
     $rowset = $this->selectWith($select);
     $rowset = $rowset->toArray();
     $tableSchema = new TableSchema();
     $tables = $tableSchema->getTablenames();
     $privileges = array();
     $privilegesHash = array();
     foreach ($rowset as $item) {
         if (in_array($item['table_name'], $blacklist)) {
             continue;
         }
         $privilegesHash[$item['table_name']] = $item;
         $privileges[] = $item;
     }
     foreach ($tables as $table) {
         if (in_array($table, $blacklist)) {
             continue;
         }
         if (array_key_exists($table, $privilegesHash)) {
             continue;
         }
         $item = array('table_name' => $table, 'group_id' => $groupId, 'status_id' => null);
         $privileges[] = $item;
     }
     // sort ascending
     usort($privileges, function ($a, $b) {
         return strcmp($a['table_name'], $b['table_name']);
     });
     return $privileges;
 }