170 lines
4.0 KiB
PHP
170 lines
4.0 KiB
PHP
<?php
|
|
namespace OCA\Gestion\Controller;
|
|
|
|
use Exception;
|
|
use OCA\Gestion\Service\NavigationService;
|
|
use OCA\Gestion\Service\Order\OrderService;
|
|
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 OrderController extends Controller {
|
|
private $idNextcloud;
|
|
private $myDb;
|
|
// private $src_path = "/var/www/html/apps/gestion/img/";
|
|
private $src_path = "/var/www/html/custom_apps/gestion/img/";
|
|
private const H2F_DEFAULT_ADMIN = "Emmanuelle";
|
|
private const DEFAULT_ADMIN = "admin";
|
|
private $urlGenerator;
|
|
private $mailer;
|
|
private $config;
|
|
|
|
/** @var IRootStorage */
|
|
private $storage;
|
|
|
|
private $user;
|
|
private $groups = [];
|
|
|
|
/** @var OrderService */
|
|
private $orderService;
|
|
|
|
/** @var \OCA\Gestion\Service\NavigationService */
|
|
private $navigationService;
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
public function __construct($AppName,
|
|
IRequest $request,
|
|
$UserId,
|
|
Bdd $myDb,
|
|
IRootFolder $rootFolder,
|
|
IURLGenerator $urlGenerator,
|
|
IMailer $mailer,
|
|
Iconfig $config,
|
|
IUserSession $userSession,
|
|
IGroupManager $groupManager,
|
|
OrderService $orderService,
|
|
NavigationService $navigationService
|
|
){
|
|
|
|
parent::__construct($AppName, $request);
|
|
|
|
$this->idNextcloud = $UserId;
|
|
$this->myDb = $myDb;
|
|
$this->urlGenerator = $urlGenerator;
|
|
$this->mailer = $mailer;
|
|
$this->config = $config;
|
|
$this->orderService = $orderService;
|
|
$this->navigationService = $navigationService;
|
|
//$this->fpdf = $fpdf;
|
|
|
|
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 order() {
|
|
return new TemplateResponse('gestion', 'order', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->navigationService->getNavigationLink()));
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function getOrdersWithDetails() {
|
|
$orders = $this->orderService->getOrdersWithDetailsAsArray();
|
|
return json_encode($orders);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function createDefaultOrder() {
|
|
try{
|
|
$this->orderService->createDefaultOrder($this->idNextcloud);
|
|
return true;
|
|
}
|
|
catch(Exception $e){
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function updateOrderDate($orderId,$orderDate) {
|
|
try{
|
|
$this->orderService->updateOrderDate($orderId,$orderDate);
|
|
return true;
|
|
}
|
|
catch(Exception $e){
|
|
var_dump($e->getMessage());
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function thanatoProductFee() {
|
|
return new TemplateResponse('gestion', 'thanatoProductFee', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud, 'url' => $this->navigationService->getNavigationLink()));
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function getThanatoProductsFees() {
|
|
$thanatoProductsFees = $this->orderService->getThanatoProductsFees();
|
|
return json_encode($thanatoProductsFees);
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function createDefaultThanatoProductFee() {
|
|
try{
|
|
$this->orderService->createDefaultThanatoProductFee();
|
|
return true;
|
|
}
|
|
catch(Exception $e){
|
|
return null;
|
|
}
|
|
}
|
|
}
|