mirror of
https://github.com/nextcloud/integration_moodle.git
synced 2025-12-17 21:02:05 +01:00
101 lines
2.6 KiB
PHP
101 lines
2.6 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\App\IAppManager;
|
|
use OCP\Files\IAppData;
|
|
use OCP\AppFramework\Http\DataDisplayResponse;
|
|
|
|
use OCP\IURLGenerator;
|
|
use OCP\IConfig;
|
|
use OCP\IServerContainer;
|
|
use OCP\IL10N;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
use OCP\AppFramework\Http;
|
|
use OCP\AppFramework\Http\RedirectResponse;
|
|
|
|
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
|
|
|
use OCP\IRequest;
|
|
use OCP\IDBConnection;
|
|
use OCP\AppFramework\Http\DataResponse;
|
|
use OCP\AppFramework\Controller;
|
|
|
|
use OCA\Moodle\Service\MoodleAPIService;
|
|
use OCA\Moodle\AppInfo\Application;
|
|
|
|
class ConfigController extends Controller {
|
|
|
|
private $userId;
|
|
private $config;
|
|
private $dbconnection;
|
|
private $dbtype;
|
|
|
|
public function __construct($AppName,
|
|
IRequest $request,
|
|
IServerContainer $serverContainer,
|
|
IConfig $config,
|
|
IAppManager $appManager,
|
|
IAppData $appData,
|
|
IDBConnection $dbconnection,
|
|
IURLGenerator $urlGenerator,
|
|
IL10N $l,
|
|
LoggerInterface $logger,
|
|
MoodleAPIService $moodleAPIService,
|
|
$userId) {
|
|
parent::__construct($AppName, $request);
|
|
$this->l = $l;
|
|
$this->userId = $userId;
|
|
$this->appData = $appData;
|
|
$this->serverContainer = $serverContainer;
|
|
$this->config = $config;
|
|
$this->dbconnection = $dbconnection;
|
|
$this->urlGenerator = $urlGenerator;
|
|
$this->logger = $logger;
|
|
$this->moodleAPIService = $moodleAPIService;
|
|
}
|
|
|
|
/**
|
|
* 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');
|
|
}
|
|
$response = new DataResponse(1);
|
|
return $response;
|
|
}
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
$response = new DataResponse(1);
|
|
return $response;
|
|
}
|
|
}
|