150 lines
3.4 KiB
PHP
150 lines
3.4 KiB
PHP
<?php
|
|
namespace OCA\Gestion\Controller;
|
|
|
|
use Exception;
|
|
use OCA\Gestion\Service\ConfigurationService;
|
|
use OCA\Gestion\Service\NavigationService;
|
|
use OCA\Gestion\Service\Vehicle\VehicleService;
|
|
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 OCP\IURLGenerator;
|
|
use OCP\IConfig;
|
|
|
|
date_default_timezone_set('Europe/Paris');
|
|
|
|
class VehicleController 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 $vehicleService;
|
|
|
|
private $logger;
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
public function __construct($AppName,
|
|
IRequest $request,
|
|
$UserId,
|
|
IRootFolder $rootFolder,
|
|
IURLGenerator $urlGenerator,
|
|
IMailer $mailer,
|
|
Iconfig $config,
|
|
IUserSession $userSession,
|
|
IGroupManager $groupManager,
|
|
NavigationService $navigationService,
|
|
ConfigurationService $configurationService,
|
|
LoggerInterface $logger,
|
|
VehicleService $vehicleService
|
|
){
|
|
|
|
parent::__construct($AppName, $request);
|
|
|
|
$this->idNextcloud = $UserId;
|
|
$this->urlGenerator = $urlGenerator;
|
|
$this->mailer = $mailer;
|
|
$this->config = $config;
|
|
$this->navigationService = $navigationService;
|
|
$this->configurationService = $configurationService;
|
|
$this->logger = $logger;
|
|
$this->vehicleService = $vehicleService;
|
|
|
|
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 vehicle() {
|
|
return new TemplateResponse('gestion', 'vehicle', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->navigationService->getNavigationLink()));
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function getVehicles() {
|
|
$vehicles = $this->vehicleService->getVehicles();
|
|
return $vehicles;
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function createDefaultVehicle() {
|
|
try{
|
|
$this->vehicleService->createDefaultVehicle();
|
|
return true;
|
|
}
|
|
catch(Exception $e){
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function getVehiclePurchaseTypes() {
|
|
try{
|
|
$types = $this->vehicleService->getVehiclePurchaseTypes();
|
|
return $types;
|
|
}
|
|
catch(Exception $e){
|
|
return json_encode([]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function getAvailableVehicles() {
|
|
try{
|
|
$vehicles = $this->vehicleService->getAvailableVehicles();
|
|
return $vehicles;
|
|
}
|
|
catch(Exception $e){
|
|
return json_encode([]);
|
|
}
|
|
}
|
|
}
|