Current path: home/webdevt/cryptoimpot.fr/module/Application/src/Controller/
?? Go up: /home/webdevt/cryptoimpot.fr/module/Application/src
<?php
namespace Application\Controller;
use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\View\Model\ViewModel;
use Laminas\Mail\Message;
use Laminas\Mime;
use Laminas\Mail\Transport\Sendmail as SendmailTransport;
class ApercuController extends AbstractActionController {
const ROUTE_INDEX = 'apercu';
const ROUTE_CORRECTION = 'correction';
/**
* Constructor.
*/
public function __construct($entityManager, $authManager, $userManager, $config)
{
$this->entityManager = $entityManager;
$this->authManager = $authManager;
$this->userManager = $userManager;
$this->config = $config;
}
public function getConfig() {
return $this->config;
}
/**
* @var Doctrine\ORM\EntityManager
*/
protected $em;
// public function setEntityManager(EntityManager $em) {
// $this->em = $em;
// }
//
// public function getEntityManager() {
// if (null === $this->em) {
// $this->em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
// }
// return $this->em;
// }
public function getEntityManager() {
return $this->entityManager;
// if (null === $this->em) {
// $this->em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
// }
// return $this->em;
}
// public function getServiceManager() {
// return $this->serviceManager;
// }
//
// public function setServiceManager(Laminas\ServiceManager\ServiceManager $serviceManager) {
// $this->serviceManager = $serviceManager;
// return $this;
// }
public function indexAction() {
// if ($this->zfcUserAuthentication()->hasIdentity()) {
// $user = $this->zfcUserAuthentication()->getIdentity();
// //var_dump($user);
// } else {
// return $this->redirect()->toRoute('zfcuser', array('action' => 'login'));
// }
if($user = $this->currentUser()) {
} else {
return $this->redirect()->toRoute(\Application\Controller\UserController::ROUTE_LOGIN);
}
/* Array with number item authorize per page */
$config = $this->getConfig();
$configNumber = $config['number_per_page_authorize'];
/* Init query option */
$queryOption = array();
/* Page number default */
$queryOption['page'] = $pageNumber = $this->params()->fromQuery('page', '1');
/* Display Table or List */
$queryOption['display'] = $displayState = $this->params()->fromQuery('display', 'table');
/* Number element display per page */
$nb_element_per_page = $this->params()->fromQuery('nb_element_per_page', '30');
$queryOption['nb_element_per_page'] = $_SESSION['countPerPage'] = in_array($nb_element_per_page, array('30', '60', '90')) ? $nb_element_per_page : '30';
/* List Sort by field */
$sort_by = $this->params()->fromQuery('sort_by', 'datetimeTransaction');
$colTable = array(
//'id' => 'Id',
'datetime' => array(
'label' => 'Date',
'class' => 'col-sm-2',
'allowOrder' => true,
),
'exchange' => array(
'label' => 'Plateforme',
'class' => 'col-sm-1',
'allowOrder' => true,
),
// 'type' => array(
// 'label' => 'Type',
// 'class' => 'col-sm-2',
// 'allowOrder' => true,
// ),
// 'pair' => array(
// 'label' => 'Pair',
// 'class' => 'col-sm-2',
// 'allowOrder' => true,
// ),
'tradedAmount' => array(
'label' => 'Montant tradé',
'class' => 'col-sm-2',
'allowOrder' => true,
),
'tradedCurrency' => array(
'label' => 'Monnaie tradée',
'class' => 'col-sm-1',
'allowOrder' => true,
),
'receivedAmount' => array(
'label' => 'Montant reçu',
'class' => 'col-sm-1',
'allowOrder' => true,
),
'receivedCurrency' => array(
'label' => 'Monnaie reçue',
'class' => 'col-sm-2',
'allowOrder' => true,
),
'cumulTradedCurrency' => array(
'label' => 'Cumul tradé',
'class' => 'col-sm-2',
'allowOrder' => true,
),
'cumulReceivedCurrency' => array(
'label' => 'Cumul recu',
'class' => 'col-sm-2',
'allowOrder' => true,
),
'commentaire' => array(
'label' => 'Warnings',
'class' => 'col-sm-2',
'allowOrder' => true,
),
// 'action' => array(
// 'label' => 'Action',
// 'class' => 'col-sm-1',
// 'allowOrder' => false,
// ),
);
// $queryOption['sort_by'] = in_array($sort_by, array('id', 'titre', 'contenu', 'dateCreation', 'dateModification', 'statut')) ? $sort_by : 'id';
//$queryOption['sort_by'] = in_array($sort_by, array('id', 'code', 'prescripteur', 'coordinateur', 'dateCreation', 'dateDepot', 'dateDelivrance', 'createdBy', 'statut')) ? $sort_by : 'id';
$queryOption['sort_by'] = 'dateTransaction';
/* List order ASC or DESC */
$sort = $this->params()->fromQuery('sort', 'ASC');
$queryOption['sort'] = in_array($sort, array('ASC', 'DESC')) ? $sort : 'ASC';
/* Form search */
$formSearch = new \Application\Form\SearchForm();
$request = $this->getRequest();
/* @var $request \Laminas\Http\Request */
$filterOption = null;
if ($request->isGet() && is_string($request->getQuery('search'))) {
$data = $request->getQuery()->toArray();
$formSearch->setInputFilter(new \Application\InputFilter\SearchInputFilter());
$formSearch->setData($data);
if ($formSearch->isValid()) {
$queryOption['search'] = $data['search'];
}
}
$orderOption = array(
'sort_by' => $queryOption['sort_by'],
'sort' => $queryOption['sort'],
);
/* Création Paginator */
//$criteria = array('statut' => 1);
$search = '';
if (isset($queryOption['search'])) {
//$criteria = array_merge($criteria, array('contenu' => "%{$queryOption['search']}%"));
$search = $queryOption['search'];
}
$orderBy = array($orderOption['sort_by'] => $orderOption['sort']);
$entityManager = $this->getEntityManager();
/* @var $entityManager \Doctrine\ORM\EntityManager */
$ledgioMapper = new \Application\Mapper\LedgioMapper($entityManager);
$parametersManager = array(
'user' => $user,
'sort_by' => $queryOption['sort_by'],
'sort' => $queryOption['sort'],
'search' => isset($queryOption['search']) ? $queryOption['search'] : null
);
$paginator = $ledgioMapper->getListByUser($user, $parametersManager, true);
//$allData = $ledgioMapper->getListByIdUser($user->getId(), $parametersManager, false);
//var_dump($allData);
// var_dump($warningLedgio);
////echo 'toto';
/* Option affichage paginator */
$paginator->setItemCountPerPage((int) $queryOption['nb_element_per_page']);
$paginator->setCurrentPageNumber((int) $queryOption['page']);
/* Verify current page < to number pages */
/* set is not allow after getting pages */
$numberPages = $paginator->getPages()->pageCount;
if ((int) $queryOption['page'] > $numberPages) {
$queryOption['page'] = '1';
}
$this->layout('layout/layout-ledgio');
return new ViewModel(array(
'numberPages' => $numberPages,
'paginator' => $paginator,
//'warningLedgio' => $warningLedgio,
'queryOption' => $queryOption,
'colTable' => $colTable,
'formSearch' => $formSearch,
));
}
/*
* @todo utiliser la fonction update du serviceLedgio pour mettre a jour les cumul et les warnings
*/
public function updateLedgioAction() {
if ($user = $this->currentUser()) {
} else {
return $this->redirect()->toRoute(\Application\Controller\UserController::ROUTE_LOGIN);
}
$ledgioService = new \Application\Service\LedgioService($user, $this->getEntityManager());
try {
$ledgioService->update();
} catch (\Exception $exception){
$responseArray['error']['messages'][] = array(
'header' => 'Impossible de mettre à jour les transactions',
'body' => 'Impossible de mettre à jour les transactions.');
}
$responseArray['success']['messages'][] = array(
'header' => 'Succès',
'body' => 'La mise à jour a été réalisée avec succès.');
$response = $this->getResponse();
$response->getHeaders()->addHeaderLine('Content-Type', 'application/json');
$response->setContent(json_encode($responseArray));
return $response;
}
public function correctionAction() {
if($user = $this->currentUser()) {
} else {
return $this->redirect()->toRoute(\Application\Controller\UserController::ROUTE_LOGIN);
}
$ledgioService = new \Application\Service\LedgioService($user, $this->getEntityManager(),$this->getConfig());
try {
$ledgioService->correctionAutomatique();
} catch (\Exception $exception){
$responseArray['error']['messages'][] = array(
'header' => 'Impossible de corriger les erreurs du portefeuille',
'body' => 'Impossible de corriger les erreurs du portefeuille.');
}
$responseArray['success']['messages'][] = array(
'header' => 'Succès',
'body' => 'Les erreurs du portefeuille ont été corrigées.');
$response = $this->getResponse();
$response->getHeaders()->addHeaderLine('Content-Type', 'application/json');
$response->setContent(json_encode($responseArray));
return $response;
}
}