/** * Get info about all tables */ public static function getTables($userGroupId, $versionHash) { $acl = Bootstrap::get('acl'); $zendDb = Bootstrap::get('ZendDb'); $Preferences = new DirectusPreferencesTableGateway($acl, $zendDb); $getTablesFn = function () use($Preferences, $zendDb) { $return = array(); $name = $zendDb->getCurrentSchema(); $sql = 'SELECT S.TABLE_NAME as id FROM INFORMATION_SCHEMA.TABLES S WHERE S.TABLE_SCHEMA = :schema AND (S.TABLE_NAME NOT LIKE "directus\\_%" OR S.TABLE_NAME = "directus_activity" OR S.TABLE_NAME = "directus_files" OR S.TABLE_NAME = "directus_messages" OR S.TABLE_NAME = "directus_groups" OR S.TABLE_NAME = "directus_users" OR S.TABLE_NAME = "directus_messages_recipients" ) GROUP BY S.TABLE_NAME ORDER BY S.TABLE_NAME'; $sth = $zendDb->query($sql); $parameterContainer = new ParameterContainer(); $parameterContainer->offsetSet(':schema', $name, ParameterContainer::TYPE_STRING); $result = $sth->execute($parameterContainer); $currentUser = Auth::getUserInfo(); foreach ($result as $row) { if (!self::canGroupViewTable($row['id'])) { continue; } $tbl["schema"] = self::getTable($row['id']); //$tbl["columns"] = $this->get_table($row['id']); $tbl["preferences"] = $Preferences->fetchByUserAndTableAndTitle($currentUser['id'], $row['id']); // $tbl["preferences"] = $this->get_table_preferences($currentUser['id'], $row['id']); $return[] = $tbl; } return $return; }; $cacheKey = MemcacheProvider::getKeyDirectusGroupSchema($userGroupId, $versionHash); $tables = $Preferences->memcache->getOrCache($cacheKey, $getTablesFn, 10800); // 3 hr cache return $tables; }
})->via('GET', 'PATCH', 'POST', 'PUT'); /** * PREFERENCES COLLECTION */ $app->map("/{$v}/tables/:table/preferences/?", function ($table) use($ZendDb, $acl, $params, $requestPayload, $app) { $currentUser = Auth::getUserInfo(); $params['table_name'] = $table; $Preferences = new DirectusPreferencesTableGateway($acl, $ZendDb); $TableGateway = new TableGateway($acl, 'directus_preferences', $ZendDb); switch ($app->request()->getMethod()) { case "PUT": $TableGateway->manageRecordUpdate('directus_preferences', $requestPayload, TableGateway::ACTIVITY_ENTRY_MODE_DISABLED); break; case "POST": //If Already exists and not saving with title, then updateit! $existing = $Preferences->fetchByUserAndTableAndTitle($currentUser['id'], $table, isset($requestPayload['title']) ? $requestPayload['title'] : null); if (!empty($existing)) { $requestPayload['id'] = $existing['id']; } $requestPayload['user'] = $currentUser['id']; $id = $TableGateway->manageRecordUpdate('directus_preferences', $requestPayload, TableGateway::ACTIVITY_ENTRY_MODE_DISABLED); break; case "DELETE": if ($requestPayload['user'] != $currentUser['id']) { return; } if (isset($requestPayload['id'])) { echo $TableGateway->delete(array('id' => $requestPayload['id'])); } else { if (isset($requestPayload['title']) && isset($requestPayload['table_name'])) { $jsonResponse = $Preferences->fetchByUserAndTableAndTitle($currentUser['id'], $requestPayload['table_name'], $requestPayload['title']);
/** * Get info about all tables */ public static function getTables($userGroupId, $versionHash) { $acl = Bootstrap::get('acl'); $zendDb = Bootstrap::get('ZendDb'); $Preferences = new DirectusPreferencesTableGateway($acl, $zendDb); $getTablesFn = function () use($Preferences, $zendDb) { $return = []; $schemaName = $zendDb->getCurrentSchema(); $select = new Select(); $select->columns(['id' => 'TABLE_NAME']); $select->from(['S' => new TableIdentifier('TABLES', 'INFORMATION_SCHEMA')]); $select->where(['TABLE_SCHEMA' => $schemaName, new NotIn('TABLE_NAME', Schema::getDirectusTables())]); $sql = new Sql($zendDb); $statement = $sql->prepareStatementForSqlObject($select); $result = $statement->execute(); $currentUser = Auth::getUserInfo(); foreach ($result as $row) { if (!self::canGroupViewTable($row['id'])) { continue; } $tbl['schema'] = self::getTable($row['id']); //$tbl['columns'] = $this->get_table($row['id']); $tbl['preferences'] = $Preferences->fetchByUserAndTableAndTitle($currentUser['id'], $row['id']); // $tbl['preferences'] = $this->get_table_preferences($currentUser['id'], $row['id']); $return[] = $tbl; } return $return; }; $cacheKey = MemcacheProvider::getKeyDirectusGroupSchema($userGroupId, $versionHash); $tables = $Preferences->memcache->getOrCache($cacheKey, $getTablesFn, 10800); // 3 hr cache return $tables; }