Thanasoft-H2F/gestion/lib/Controller/ProviderController.php

144 lines
3.5 KiB
PHP

<?php
namespace OCA\Gestion\Controller;
use Exception;
use OCA\Gestion\Service\ConfigurationService;
use OCA\Gestion\Service\NavigationService;
use OCA\Gestion\Service\Provider\ProviderService;
use OCA\Gestion\Service\Provider\Statistic\ProviderStatisticService;
use Psr\Log\LoggerInterface;
defined("TAB1") or define("TAB1", "\t");
use OCP\IGroupManager;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\Mail\IMailer;
use OCP\Files\IRootFolder;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Controller;
use OCA\Gestion\Db\Bdd;
use OCP\IURLGenerator;
use OCP\IConfig;
date_default_timezone_set('Europe/Paris');
class ProviderController extends Controller {
private $idNextcloud;
private $urlGenerator;
private $mailer;
private $config;
/** @var IRootStorage */
private $storage;
private $user;
private $groups = [];
/** @var \OCA\Gestion\Service\NavigationService */
private $navigationService;
private $providerService;
private $providerStatisticService;
private $logger;
/**
* Constructor
*/
public function __construct($AppName,
IRequest $request,
$UserId,
Bdd $myDb,
IRootFolder $rootFolder,
IURLGenerator $urlGenerator,
IMailer $mailer,
Iconfig $config,
IUserSession $userSession,
IGroupManager $groupManager,
NavigationService $navigationService,
ConfigurationService $configurationService,
LoggerInterface $logger,
ProviderService $providerService,
ProviderStatisticService $providerStatisticService
){
parent::__construct($AppName, $request);
$this->idNextcloud = $UserId;
$this->myDb = $myDb;
$this->urlGenerator = $urlGenerator;
$this->mailer = $mailer;
$this->config = $config;
$this->navigationService = $navigationService;
$this->configurationService = $configurationService;
$this->logger = $logger;
$this->providerService = $providerService;
$this->providerStatisticService = $providerStatisticService;
if ($userSession->isLoggedIn()) {
$this->user = $userSession->getUser();
}
if ($this->user != null) {
$groups = $groupManager->getUserGroups($this->user);
$this->groups = [];
foreach ($groups as $group) {
$this->groups[] = $group->getGID();
}
}
try{
$this->storage = $rootFolder->getUserFolder($this->idNextcloud);
}catch(\OC\User\NoUserException $e){
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function provider() {
return new TemplateResponse('gestion', 'provider', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->navigationService->getNavigationLink()));
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getProviders() {
$providers = $this->providerService->getProvidersAsArray();
return json_encode($providers);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function createDefaultProvider() {
try{
$this->providerService->createDefaultProvider($this->idNextcloud);
return true;
}
catch(Exception $e){
return null;
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function exportProvidersStatistic(array $providerIds,$year){
try{
$filenames = $this->providerStatisticService->exportProvidersStatisticByYear($providerIds,$year,$this->idNextcloud);
return $filenames;
}
catch(Exception $e){
return [];
}
}
}