diff options
author | Julius Härtl <jus@bitgrid.net> | 2020-08-14 16:22:22 +0200 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2020-08-19 17:07:27 +0200 |
commit | b49f814faa08be51d4008f4b367a797cf95002a7 (patch) | |
tree | ebf517d9ca3e2688f80e1175ac3bbbaadd43e94d /apps/dashboard/lib/Service/BackgroundService.php | |
parent | 2535e0ec044b0500edf9b00afb544da5c69bf8eb (diff) | |
download | nextcloud-server-b49f814faa08be51d4008f4b367a797cf95002a7.tar.gz nextcloud-server-b49f814faa08be51d4008f4b367a797cf95002a7.zip |
Implement background reset and proper shipped setting
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/dashboard/lib/Service/BackgroundService.php')
-rw-r--r-- | apps/dashboard/lib/Service/BackgroundService.php | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/apps/dashboard/lib/Service/BackgroundService.php b/apps/dashboard/lib/Service/BackgroundService.php index 2046513851f..06e0a451b88 100644 --- a/apps/dashboard/lib/Service/BackgroundService.php +++ b/apps/dashboard/lib/Service/BackgroundService.php @@ -32,6 +32,7 @@ use OCP\Files\IAppData; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\Files\SimpleFS\ISimpleFile; +use OCP\IConfig; class BackgroundService { @@ -64,7 +65,7 @@ class BackgroundService { 'yana-sichikova-sergey-ovachev-stone-flower-2k.jpg', ]; - public function __construct(IRootFolder $rootFolder, IAppData $appData, $userId) { + public function __construct(IRootFolder $rootFolder, IAppData $appData, IConfig $config, $userId) { if ($userId === null) { return; } @@ -74,14 +75,26 @@ class BackgroundService { } catch (NotFoundException $e) { $this->dashboardUserFolder = $appData->newFolder($userId); } + $this->config = $config; + $this->userId = $userId; + } + + public function setDefaultBackground() { + $this->config->deleteUserValue($this->userId, 'dashboard', 'background'); } public function setFileBackground($path) { + $this->config->setUserValue($this->userId, 'dashboard', 'background', 'custom'); $file = $this->userFolder->get($path); $newFile = $this->dashboardUserFolder->newFile('background.jpg', $file->fopen('r')); } + public function setShippedBackground($fileName) { + $this->config->setUserValue($this->userId, 'dashboard', 'background', $fileName); + } + public function setUrlBackground($url) { + $this->config->setUserValue($this->userId, 'dashboard', 'background', 'custom'); if (substr($url, 0, 1) === '/') { $url = \OC::$server->getURLGenerator()->getAbsoluteURL($url); } @@ -92,11 +105,15 @@ class BackgroundService { $newFile = $this->dashboardUserFolder->newFile('background.jpg', $content); } - /** - * @throws NotFoundException - */ - public function getBackground(): ISimpleFile { - return $this->dashboardUserFolder->getFile('background.jpg'); + public function getBackground() { + $background = $this->config->getUserValue($this->userId, 'dashboard', 'background', 'default'); + if ($background === 'custom') { + try { + return $this->dashboardUserFolder->getFile('background.jpg'); + } catch (NotFoundException $e) { + } + } + return null; } } |