Ejemplo n.º 1
0
 * UI COLLECTION
 */
$app->map("/{$v}/tables/:table/columns/:column/:ui/?", function ($table, $column, $ui) use($acl, $ZendDb, $params, $requestPayload, $app) {
    $TableGateway = new TableGateway($acl, 'directus_ui', $ZendDb);
    switch ($app->request()->getMethod()) {
        case "PUT":
        case "POST":
            $keys = array('table_name' => $table, 'column_name' => $column, 'ui_name' => $ui);
            $uis = to_name_value($requestPayload, $keys);
            $column_settings = array();
            foreach ($uis as $col) {
                $existing = $TableGateway->select(array('table_name' => $table, 'column_name' => $column, 'ui_name' => $ui, 'name' => $col['name']))->toArray();
                if (count($existing) > 0) {
                    $col['id'] = $existing[0]['id'];
                }
                array_push($column_settings, $col);
            }
            $TableGateway->updateCollection($column_settings);
    }
    $UiOptions = new DirectusUiTableGateway($acl, $ZendDb);
    $get_new = $UiOptions->fetchOptions($table, $column, $ui);
    JsonView::render($get_new);
})->via('GET', 'POST', 'PUT');
/**
 * Run the Router
 */
if (isset($_GET['run_api_router']) && $_GET['run_api_router']) {
    // Run Slim
    $app->response()->header('Content-Type', 'application/json; charset=utf-8');
    $app->run();
}
Ejemplo n.º 2
0
 public static function getColumnSchemas()
 {
     $acl = Bootstrap::get('acl');
     $zendDb = Bootstrap::get('ZendDb');
     $result = SchemaManager::getAllColumns();
     // Group columns by table name
     $tables = [];
     $tableName = null;
     foreach ($result as $row) {
         $tableName = $row['table_name'];
         $columnName = $row['column_name'];
         // Create nested array by table name
         if (!array_key_exists($tableName, $tables)) {
             $tables[$tableName] = [];
         }
         // @todo getTablePrivilegeList is called in excess,
         // should just be called when $tableName changes
         $readFieldBlacklist = $acl->getTablePrivilegeList($tableName, $acl::FIELD_READ_BLACKLIST);
         $writeFieldBlacklist = $acl->getTablePrivilegeList($tableName, $acl::FIELD_WRITE_BLACKLIST);
         // Indicate if the column is blacklisted for writing
         $row['is_writable'] = !in_array($columnName, $writeFieldBlacklist);
         // Don't include a column that is blacklisted for reading
         if (in_array($columnName, $readFieldBlacklist)) {
             continue;
         }
         $row = self::formatColumnRow($row);
         $tables[$tableName][$columnName] = $row;
     }
     // UI's
     $directusUiTableGateway = new DirectusUiTableGateway($acl, $zendDb);
     $uis = $directusUiTableGateway->fetchExisting()->toArray();
     foreach ($uis as $ui) {
         $uiTableName = $ui['table_name'];
         $uiColumnName = $ui['column_name'];
         // Does the table for the UI settings still exist?
         if (array_key_exists($uiTableName, $tables)) {
             // Does the column for the UI settings still exist?
             if (array_key_exists($uiColumnName, $tables[$uiTableName])) {
                 $column =& $tables[$uiTableName][$uiColumnName];
                 $column['options']['id'] = $ui['ui_name'];
                 $column['options'][$ui['name']] = $ui['value'];
             }
         }
     }
     return $tables;
 }
Ejemplo n.º 3
0
    public static function getColumnSchemas()
    {
        $acl = Bootstrap::get('acl');
        $zendDb = Bootstrap::get('ZendDb');
        $sql = '(
                SELECT
                    C.table_name,
                    C.column_name AS column_name,
                    ifnull(sort, ORDINAL_POSITION) as sort,
                    UCASE(C.data_type) as type,
                    CHARACTER_MAXIMUM_LENGTH as char_length,
                    IS_NULLABLE as is_nullable,
                    COLUMN_DEFAULT as default_value,
                    ifnull(comment, COLUMN_COMMENT) as comment,
                    ui,
                    ifnull(system,0) as system,
                    ifnull(master,0) as master,
                    ifnull(hidden_list,0) as hidden_list,
                    ifnull(hidden_input,0) as hidden_input,
                    relationship_type,
                    table_related,
                    junction_table,
                    junction_key_left,
                    junction_key_right,
                    ifnull(D.required,0) as required,
                    COLUMN_TYPE as column_type,
                    COLUMN_KEY as column_key
                FROM
                    INFORMATION_SCHEMA.COLUMNS C
                LEFT JOIN
                    INFORMATION_SCHEMA.TABLES T ON C.TABLE_NAME = T.TABLE_NAME
                LEFT JOIN
                    directus_columns AS D ON (C.COLUMN_NAME = D.column_name AND C.TABLE_NAME = D.table_name)
                WHERE
                    C.TABLE_SCHEMA = :schema AND (T.TABLE_SCHEMA = :schema AND T.TABLE_TYPE = "BASE TABLE")

            ) UNION ALL (

                SELECT
                    `table_name`,
                    `column_name` AS column_name,
                    sort,
                    UCASE(data_type) as type,
                    NULL AS char_length,
                    "NO" as is_nullable,
                    NULL AS default_value,
                    comment,
                    ui,
                    system,
                    master,
                    hidden_list,
                    hidden_input,
                    relationship_type,
                    table_related,
                    junction_table,
                    junction_key_left,
                    junction_key_right,
                    DC.required,
                    NULL as column_type,
                    NULL as column_key
                FROM
                    `directus_columns` DC
                WHERE
                    `data_type` IN ("alias", "MANYTOMANY", "ONETOMANY")

            ) ORDER BY `table_name`';
        $sth = $zendDb->query($sql);
        $parameterContainer = new ParameterContainer();
        $parameterContainer->offsetSet(':schema', $zendDb->getCurrentSchema(), ParameterContainer::TYPE_STRING);
        $result = $sth->execute($parameterContainer);
        // Group columns by table name
        $tables = array();
        $tableName = null;
        foreach ($result as $row) {
            $tableName = $row['table_name'];
            $columnName = $row['column_name'];
            // Create nested array by table name
            if (!array_key_exists($tableName, $tables)) {
                $tables[$tableName] = array();
            }
            // @todo getTablePrivilegeList is called in excess,
            // should just be called when $tableName changes
            $readFieldBlacklist = $acl->getTablePrivilegeList($tableName, $acl::FIELD_READ_BLACKLIST);
            $writeFieldBlacklist = $acl->getTablePrivilegeList($tableName, $acl::FIELD_WRITE_BLACKLIST);
            // Indicate if the column is blacklisted for writing
            $row["is_writable"] = !in_array($columnName, $writeFieldBlacklist);
            // Don't include a column that is blacklisted for reading
            if (in_array($columnName, $readFieldBlacklist)) {
                continue;
            }
            $row = self::formatColumnRow($row);
            $tables[$tableName][$columnName] = $row;
        }
        // UI's
        $directusUiTableGateway = new DirectusUiTableGateway($acl, $zendDb);
        $uis = $directusUiTableGateway->fetchExisting()->toArray();
        foreach ($uis as $ui) {
            $uiTableName = $ui['table_name'];
            $uiColumnName = $ui['column_name'];
            // Does the table for the UI settings still exist?
            if (array_key_exists($uiTableName, $tables)) {
                // Does the column for the UI settings still exist?
                if (array_key_exists($uiColumnName, $tables[$uiTableName])) {
                    $column =& $tables[$uiTableName][$uiColumnName];
                    $column['options']['id'] = $ui['ui_name'];
                    $column['options'][$ui['name']] = $ui['value'];
                }
            }
        }
        return $tables;
    }
Ejemplo n.º 4
0
    switch ($app->request()->getMethod()) {
        case 'PUT':
        case 'POST':
            $keys = ['table_name' => $table, 'column_name' => $column, 'ui_name' => $ui];
            $uis = to_name_value($requestPayload, $keys);
            $column_settings = [];
            foreach ($uis as $col) {
                $existing = $TableGateway->select(['table_name' => $table, 'column_name' => $column, 'ui_name' => $ui, 'name' => $col['name']])->toArray();
                if (count($existing) > 0) {
                    $col['id'] = $existing[0]['id'];
                }
                array_push($column_settings, $col);
            }
            $TableGateway->updateCollection($column_settings);
    }
    $UiOptions = new DirectusUiTableGateway($acl, $ZendDb);
    $response = $UiOptions->fetchOptions($table, $column, $ui);
    if (!$response) {
        $app->response()->setStatus(404);
        $response = ['message' => __t('unable_to_find_column_x_options_for_x', ['column' => $column, 'ui' => $ui]), 'success' => false];
    }
    JsonView::render($response);
})->via('GET', 'POST', 'PUT');
$app->notFound(function () use($app, $acl, $ZendDb) {
    $app->response()->header('Content-Type', 'text/html; charset=utf-8');
    $settingsTable = new DirectusSettingsTableGateway($acl, $ZendDb);
    $settings = $settingsTable->fetchCollection('global');
    $projectName = isset($settings['project_name']) ? $settings['project_name'] : 'Directus';
    $projectLogoURL = '/assets/img/directus-logo-flat.svg';
    if (isset($settings['cms_thumbnail_url']) && $settings['cms_thumbnail_url']) {
        $projectLogoURL = $settings['cms_thumbnail_url'];