This repository has been archived on 2024-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
epubreader/lib/Controller/PreferenceController.php

114 lines
2.7 KiB
PHP
Raw Normal View History

2020-04-21 20:37:42 +00:00
<?php
/**
* @author Frank de Lange
* @copyright 2017 Frank de Lange
*
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OCA\Epubreader\Controller;
2020-04-21 20:37:42 +00:00
2023-06-16 14:58:23 +00:00
use OCA\Epubreader\Service\PreferenceService;
2020-04-21 20:37:42 +00:00
use OCP\AppFramework\Controller;
2023-06-16 19:20:03 +00:00
use OCP\AppFramework\Http\JSONResponse;
2023-06-16 14:58:23 +00:00
use OCP\IRequest;
2020-04-21 20:37:42 +00:00
class PreferenceController extends Controller {
2023-06-16 19:20:03 +00:00
private PreferenceService $preferenceService;
2020-04-21 20:37:42 +00:00
2023-06-16 14:58:23 +00:00
/**
* @param string $AppName
* @param IRequest $request
* @param PreferenceService $preferenceService
*/
2023-06-16 19:20:03 +00:00
public function __construct(
string $AppName,
2023-06-16 14:58:23 +00:00
IRequest $request,
2023-06-16 19:20:03 +00:00
PreferenceService $preferenceService
) {
2020-04-21 20:37:42 +00:00
parent::__construct($AppName, $request);
2023-06-16 14:58:23 +00:00
$this->preferenceService = $preferenceService;
}
2020-04-21 20:37:42 +00:00
/**
2023-06-16 14:58:23 +00:00
* @brief return preference for $fileId
*
* @NoAdminRequired
* @NoCSRFRequired
*
* @param string $scope
* @param int $fileId
2023-06-16 19:20:03 +00:00
* @param ?string $name if null, return all preferences for $scope + $fileId
2020-04-21 20:37:42 +00:00
*/
2023-06-16 19:20:03 +00:00
public function get(string $scope, int $fileId, ?string $name = null): JSONResponse {
return new JSONResponse($this->preferenceService->get($scope, $fileId, $name));
2023-06-16 14:58:23 +00:00
}
2020-04-21 20:37:42 +00:00
/**
2023-06-16 14:58:23 +00:00
* @brief write preference for $fileId
*
* @NoAdminRequired
* @NoCSRFRequired
*
* @param string $scope
* @param int $fileId
* @param string $name
* @param string $value
2020-04-21 20:37:42 +00:00
*/
2023-06-16 19:31:46 +00:00
public function set(string $scope, int $fileId, string $name, string $value): JSONResponse {
2023-06-16 19:20:03 +00:00
return new JSONResponse($this->preferenceService->set($scope, $fileId, $name, $value));
2020-04-21 20:37:42 +00:00
}
/**
2023-06-16 14:58:23 +00:00
* @brief return default preference
*
* @NoAdminRequired
* @NoCSRFRequired
*
* @param string $scope
* @param string $name if null, return all default preferences for scope
2020-04-21 20:37:42 +00:00
*/
2023-06-16 19:20:03 +00:00
public function getDefault(string $scope, string $name): JSONResponse {
return new JSONResponse($this->preferenceService->getDefault($scope, $name));
2023-06-16 14:58:23 +00:00
}
2020-04-21 20:37:42 +00:00
/**
2023-06-16 14:58:23 +00:00
* @brief write default preference
*
* @NoAdminRequired
* @NoCSRFRequired
*
* @param string $scope
* @param string $name
* @param string $value
2020-04-21 20:37:42 +00:00
*/
2023-06-16 19:20:03 +00:00
public function setDefault(string $scope, string $name, string $value): JSONResponse {
return new JSONResponse($this->preferenceService->setDefault($scope, $name, $value));
2023-06-16 14:58:23 +00:00
}
2020-04-21 20:37:42 +00:00
2023-06-16 14:58:23 +00:00
/**
* @brief delete preference
*
* @param string $scope
* @param int $fileId
* @param string $name
*/
2023-06-16 19:20:03 +00:00
public function delete(string $scope, int $fileId, string $name): void {
$this->preferenceService->delete($scope, $fileId, $name);
2023-06-16 14:58:23 +00:00
}
2020-04-21 20:37:42 +00:00
2023-06-16 14:58:23 +00:00
/**
* @brief delete default preference
*
2023-06-16 19:20:03 +00:00
* @param string $scope
* @param string $name
2023-06-16 14:58:23 +00:00
*/
2023-06-16 19:20:03 +00:00
public function deleteDefault(string $scope, string $name): void {
$this->preferenceService->deleteDefault($scope, $name);
2023-06-16 14:58:23 +00:00
}
2020-04-21 20:37:42 +00:00
}