diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php new file mode 100644 index 0000000..d852879 --- /dev/null +++ b/lib/Controller/SettingsController.php @@ -0,0 +1,170 @@ +config = $config; + $this->userId = $userId; + $this->l = $l; + } + + private function getSetting(string $key, string $name, $default): JSONResponse { + try { + $userValue = $this->config->getUserValue( + $this->userId, + $this->appName, + $key, + $default + ); + } catch (Exception $e) { + Util::writeLog('radio', $e->getMessage(), Util::ERROR); + return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); + } + + return new JSONResponse([$name => $userValue], Http::STATUS_OK); + } + + private function setSetting($key, $value): JSONResponse { + try { + $this->config->setUserValue( + $this->userId, + $this->appName, + $key, + $value + ); + } catch (Exception $e) { + return new JSONResponse(['status' => 'error'], Http::STATUS_INTERNAL_SERVER_ERROR); + } + + return new JSONResponse(['status' => 'success'], Http::STATUS_OK); + } + + /** + * get player volume config value + * + * @return JSONResponse + * + * @NoAdminRequired + */ + public function getVolume(): JSONResponse { + return $this->getSetting('volume', 'volume', 0.5); + } + + /** + * set player volume config value + * + * @param string $sorting + * @return JSONResponse + * + * @NoAdminRequired + */ + public function setSorting($sorting = ""): JSONResponse { + $legalArguments = ['title', 'added', 'clickcount', 'lastmodified', 'index']; + if (!in_array($sorting, $legalArguments)) { + return new JSONResponse(['status' => 'error'], Http::STATUS_BAD_REQUEST); + } + return $this->setSetting( + 'sorting', + $sorting + ); + } + + /** + * get view mode option config value + * + * @return JSONResponse + * + * @NoAdminRequired + */ + public function getViewMode(): JSONResponse { + return $this->getSetting('viewMode', 'viewMode', 'grid'); + } + + /** + * set sorting option config value + * + * @param string $viewMode + * @return JSONResponse + * + * @NoAdminRequired + */ + public function setViewMode($viewMode = ""): JSONResponse { + $legalArguments = ['grid', 'list']; + if (!in_array($viewMode, $legalArguments)) { + return new JSONResponse(['status' => 'error'], Http::STATUS_BAD_REQUEST); + } + return $this->setSetting( + 'viewMode', + $viewMode + ); + } + + /** + * get per-user bookmarks limit + * + * @return JSONResponse + * + * @NoAdminRequired + */ + public function getLimit(): JSONResponse { + $limit = (int)$this->config->getAppValue('bookmarks', 'performance.maxBookmarksperAccount', 0); + return new JSONResponse(['limit' => $limit], Http::STATUS_OK); + } + + /** + * get user-defined archive path + * + * @return JSONResponse + * + * @NoAdminRequired + */ + public function getArchivePath(): JSONResponse { + return $this->getSetting( + 'archive.filePath', + 'archivePath', + $this->l->t('Bookmarks') + ); + } + + /** + * set user-defined archive path + * + * @param string $archivePath + * @return JSONResponse + * + * @NoAdminRequired + */ + public function setArchivePath(string $archivePath): JSONResponse { + return $this->setSetting('archive.filePath', $archivePath); + } +}