Example #1
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;
    }
Example #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;
 }