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