$get_new = is_null($id) ? $settings_new : $settings_new[$id]; JsonView::render($get_new); })->via('GET', 'POST', 'PUT'); // GET and PUT table details $app->map("/{$v}/tables/:table/?", function ($table) use($ZendDb, $acl, $params, $requestPayload, $app) { $TableGateway = new TableGateway($acl, 'directus_tables', $ZendDb, null, null, null, 'table_name'); $ColumnsTableGateway = new TableGateway($acl, 'directus_columns', $ZendDb); /* PUT updates the table */ if ($app->request()->isPut()) { $data = $requestPayload; $table_settings = array('table_name' => $data['table_name'], 'hidden' => (int) $data['hidden'], 'single' => (int) $data['single'], 'is_junction_table' => (int) $data['is_junction_table'], 'footer' => (int) $data['footer'], 'primary_column' => array_key_exists('primary_column', $data) ? $data['primary_column'] : ''); //@TODO: Possibly pretty this up so not doing direct inserts/updates $set = $TableGateway->select(array('table_name' => $table))->toArray(); //If item exists, update, else insert if (count($set) > 0) { $TableGateway->update($table_settings, array('table_name' => $table)); } else { $TableGateway->insert($table_settings); } $column_settings = array(); foreach ($data['columns'] as $col) { $columnData = array('table_name' => $table, 'column_name' => $col['column_name'], 'ui' => $col['ui'], 'hidden_input' => $col['hidden_input'], 'required' => $col['required'], 'master' => $col['master'], 'sort' => array_key_exists('sort', $col) ? $col['sort'] : 99999, 'comment' => array_key_exists('comment', $col) ? $col['comment'] : ''); $existing = $ColumnsTableGateway->select(array('table_name' => $table, 'column_name' => $col['column_name']))->toArray(); if (count($existing) > 0) { $columnData['id'] = $existing[0]['id']; } array_push($column_settings, $columnData); } $ColumnsTableGateway->updateCollection($column_settings); } $response = TableSchema::getTable($table);
$response['success'] = true; $response['message'] = __t('table_x_was_removed'); } return JsonView::render($response); } $TableGateway = new TableGateway($acl, 'directus_tables', $ZendDb, null, null, null, 'table_name'); $ColumnsTableGateway = new TableGateway($acl, 'directus_columns', $ZendDb); /* PUT updates the table */ if ($app->request()->isPut()) { $data = $requestPayload; $table_settings = ['table_name' => $data['table_name'], 'hidden' => (int) $data['hidden'], 'single' => (int) $data['single'], 'footer' => (int) $data['footer'], 'primary_column' => array_key_exists('primary_column', $data) ? $data['primary_column'] : '']; //@TODO: Possibly pretty this up so not doing direct inserts/updates $set = $TableGateway->select(['table_name' => $table])->toArray(); //If item exists, update, else insert if (count($set) > 0) { $TableGateway->update($table_settings, ['table_name' => $table]); } else { $TableGateway->insert($table_settings); } $column_settings = []; foreach ($data['columns'] as $col) { $columnData = ['table_name' => $table, 'column_name' => $col['column_name'], 'ui' => $col['ui'], 'hidden_input' => $col['hidden_input'] ? 1 : 0, 'hidden_list' => $col['hidden_list'] ? 1 : 0, 'required' => $col['required'] ? 1 : 0, 'sort' => array_key_exists('sort', $col) ? $col['sort'] : 99999, 'comment' => array_key_exists('comment', $col) ? $col['comment'] : '']; // hotfix #1069 single_file UI not saving relational settings $extraFields = ['data_type', 'relationship_type', 'related_table', 'junction_key_right']; foreach ($extraFields as $field) { if (array_key_exists($field, $col)) { $columnData[$field] = $col[$field]; } } $existing = $ColumnsTableGateway->select(['table_name' => $table, 'column_name' => $col['column_name']])->toArray(); if (count($existing) > 0) {