mirror of
https://github.com/nextcloud/integration_moodle.git
synced 2025-12-17 21:02:05 +01:00
72 lines
1.7 KiB
PHP
72 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* Nextcloud - moodle
|
|
*
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
* later. See the COPYING file.
|
|
*
|
|
* @author Julien Veyssier <eneiluj@posteo.net>
|
|
* @copyright Julien Veyssier 2020
|
|
*/
|
|
|
|
namespace OCA\Moodle\Controller;
|
|
|
|
use OCP\IConfig;
|
|
use OCP\IRequest;
|
|
use OCP\AppFramework\Http\DataResponse;
|
|
use OCP\AppFramework\Controller;
|
|
|
|
use OCA\Moodle\AppInfo\Application;
|
|
|
|
class ConfigController extends Controller {
|
|
|
|
/**
|
|
* @var IConfig
|
|
*/
|
|
private $config;
|
|
/**
|
|
* @var string|null
|
|
*/
|
|
private $userId;
|
|
|
|
public function __construct(string $appName,
|
|
IRequest $request,
|
|
IConfig $config,
|
|
?string $userId) {
|
|
parent::__construct($appName, $request);
|
|
$this->config = $config;
|
|
$this->userId = $userId;
|
|
}
|
|
|
|
/**
|
|
* set config values
|
|
* @NoAdminRequired
|
|
*
|
|
* @param array $values
|
|
* @return DataResponse
|
|
*/
|
|
public function setConfig(array $values): DataResponse {
|
|
foreach ($values as $key => $value) {
|
|
$this->config->setUserValue($this->userId, Application::APP_ID, $key, $value);
|
|
}
|
|
if (isset($values['token']) && $values['token'] === '') {
|
|
$this->config->deleteUserValue($this->userId, Application::APP_ID, 'token');
|
|
$this->config->deleteUserValue($this->userId, Application::APP_ID, 'user_name');
|
|
$this->config->deleteUserValue($this->userId, Application::APP_ID, 'privatetoken');
|
|
}
|
|
return new DataResponse(1);
|
|
}
|
|
|
|
/**
|
|
* set admin config values
|
|
*
|
|
* @param array $values
|
|
* @return DataResponse
|
|
*/
|
|
public function setAdminConfig(array $values): DataResponse {
|
|
foreach ($values as $key => $value) {
|
|
$this->config->setAppValue(Application::APP_ID, $key, $value);
|
|
}
|
|
return new DataResponse(1);
|
|
}
|
|
}
|