add controller and service

This commit is contained in:
Jonas Heinrich 2018-08-12 16:22:11 +02:00
parent a35258acfb
commit a22ce04317
3 changed files with 80 additions and 1 deletions

View File

@ -14,7 +14,7 @@
<category>multimedia</category> <category>multimedia</category>
<website>https://git.project-insanity.org/onny/nextcloud-app-radio</website> <website>https://git.project-insanity.org/onny/nextcloud-app-radio</website>
<bugs>https://git.project-insanity.org/onny/nextcloud-app-radio/issues</bugs> <bugs>https://git.project-insanity.org/onny/nextcloud-app-radio/issues</bugs>
<screenshot>https://onny.project-insanity.org/files/radio-app.png</screenshot> <screenshot>https://git.project-insanity.org/onny/nextcloud-app-radio/raw/master/screenshot.png</screenshot>
<dependencies> <dependencies>
<nextcloud min-version="14" max-version="14"/> <nextcloud min-version="14" max-version="14"/>
</dependencies> </dependencies>

View File

@ -0,0 +1,54 @@
<?php
namespace OCA\Radio\Controller;
use \OCP\AppFramework\Controller;
use \OCP\AppFramework\Http\TemplateResponse;
use \OCP\IRequest;
use \OCA\Radio\Service\ConfigService;
class SettingsController extends Controller {
private $userId;
private $appConfig;
public function __construct($appName, IRequest $request, ConfigService $appConfig, $userId) {
parent::__construct($appName, $request);
$this->userId = $userId;
$this->appConfig = $appConfig;
}
/**
* Save order for current user
*
* @NoAdminRequired
* @return array response
*/
public function getMenuState() {
$menu_state = $this->appConfig->getUserValue('menu_state', $this->userId);
$response = array(
'status' => 'success',
'data' => array('message' => 'User order saved successfully.'),
'menu_state' => $menu_state
);
return $response;
}
/**
* Save order for current user
*
* @NoAdminRequired
* @param $menu_state string
* @return array response
*/
public function saveMenuState($menu_state) {
$this->appConfig->setUserValue('menu_state', $this->userId, $menu_state);
$response = array(
'status' => 'success',
'data' => array('message' => 'User order saved successfully.'),
'menu_state' => $menu_state
);
return $response;
}
}

25
service/configservice.php Normal file
View File

@ -0,0 +1,25 @@
<?php
namespace OCA\Radio\Service;
use \OCP\IConfig;
class ConfigService {
private $config;
private $appName;
public function __construct(IConfig $config, $appName) {
$this->config = $config;
$this->appName = $appName;
}
public function getUserValue($key, $userId) {
return $this->config->getUserValue($userId, $this->appName, $key);
}
public function setUserValue($key, $userId, $value) {
$this->config->setUserValue($userId, $this->appName, $key, $value);
}
}