Commit 94c06f93 authored by lecluse's avatar lecluse
Browse files

Refactoring : limitation au maximum de l'usage explicite du serviceLocator

Poursuite de l'implémentation des charges d'enseignement
parent 9bb2c29f
<?php
/**
* @var $this \Application\View\Renderer\PhpRenderer
* @var $controller \Zend\Mvc\Controller\AbstractController
* @var $viewName string
* @var $sl \Zend\ServiceManager\ServiceLocatorInterface
*/
/** @var \Application\Processus\IndicateurProcessus $p */
$p = $sl->get('processusIndicateur');
var_dump($p->getServiceContext());
\ No newline at end of file
<?php
/**
* @var $this \Application\View\Renderer\PhpRenderer
* @var $controller \Zend\Mvc\Controller\AbstractController
* @var $viewName string
* @var $sl \Zend\ServiceManager\ServiceLocatorInterface
*/
<?php
namespace Application;
use Application\Provider\Privilege\Privileges;
use UnicaenAuth\Guard\PrivilegeController;
use UnicaenAuth\Provider\Rule\PrivilegeRuleProvider;
return [
/* 'router' => [
'routes' => [
'charges' => [
'child_routes' => [
],
],
],
],
'bjyauthorize' => [
'guards' => [
PrivilegeController::class => [
[
'controller' => 'Application\Controller\Charge',
'action' => ['voir'],
'privileges' => [
],
],
],
],
],*/
'controllers' => [
'invokables' => [
],
],
'service_manager' => [
'invokables' => [
'applicationScenario' => Service\ScenarioService::class,
],
'factories' => [
'ApplicationChargeProvider' => Provider\Charge\ChargeProviderFactory::class,
],
],
'view_helpers' => [
'invokables' => [
'diagramme' => View\Helper\Charge\DiagrammeViewHelper::class,
],
],
'form_elements' => [
'invokables' => [
],
],
];
<?php
namespace Application;
use UnicaenAuth\Guard\PrivilegeController;
return [
/* Routes (à personnaliser) */
'router' => [
'routes' => [
'chargens' => [
'type' => 'Segment',
'options' => [
'route' => '/chargens[/:etape][/:scenario]',
'constraints' => [
'structure' => '[0-9]*',
'etape' => '[0-9]*',
'scenario' => '[0-9]*',
],
'defaults' => [
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Chargens',
'action' => 'index',
],
],
'may_terminate' => true,
'child_routes' => [
/* Placez ici vos routes filles */
],
],
],
],
/* Exemple de menu */
'navigation' => [
'default' => [
'home' => [
'pages' => [
'chargens' => [
'label' => "Charges",
'title' => "Charges d'enseignement",
'route' => 'chargens',
'resource' => PrivilegeController::getResourceId('Application\Controller\Chargens', 'index'),
],
],
],
],
],
/* Droits d'accès */
'bjyauthorize' => [
'guards' => [
PrivilegeController::class => [
[
'controller' => 'Application\Controller\Chargens',
'action' => ['index'],
'privileges' => [
Provider\Privilege\Privileges::CHARGENS_VISUALISATION,
],
],
],
],
],
/* Déclaration du contrôleur */
'controllers' => [
'factories' => [
'Application\Controller\Chargens' => Controller\Factory\ChargensControllerFactory::class,
],
],
'service_manager' => [
'invokables' => [
'applicationScenario' => Service\ScenarioService::class,
],
'factories' => [
'chargens' => Provider\Chargens\ChargensProviderFactory::class,
],
],
'view_helpers' => [
'invokables' => [
'chargens' => View\Helper\Chargens\ChargensViewHelper::class,
],
],
'form_elements' => [
'invokables' => [
'chargensFiltre' => Form\Chargens\FiltreForm::class,
],
],
];
\ No newline at end of file
......@@ -105,7 +105,7 @@ return [
],
],
],
'bjyauthorize' => [
'guards' => [
PrivilegeController::class => [
......@@ -127,18 +127,20 @@ return [
],
],
],
'controllers' => [
'invokables' => [
'Application\Controller\Indicateur' => Controller\IndicateurController::class,
'factories' => [
'Application\Controller\Indicateur' => Controller\Factory\IndicateurControllerFactory::class,
],
],
'service_manager' => [
'invokables' => [
'processusIndicateur' => Processus\IndicateurProcessus::class,
'applicationIndicateur' => Service\IndicateurService::class,
'NotificationIndicateurService' => Service\NotificationIndicateur::class,
],
'factories' => [
'processusIndicateur' => Processus\Factory\IndicateurProcessusFactory::class,
],
],
];
\ No newline at end of file
......@@ -207,9 +207,8 @@ $main = [
],
],
'controller_plugins' => [
'invokables' => [
'em' => Controller\Plugin\Em::class,
'context' => Controller\Plugin\Context::class,
'factories' => [
'context' => Controller\Plugin\ContextFactory::class,
],
],
'view_manager' => [
......@@ -271,7 +270,6 @@ return array_merge_recursive(
include 'offre-formation.config.php',
include 'contrat.config.php',
include 'validation.config.php',
include 'droits.config.php',
include 'agrement.config.php',
include 'formule.config.php',
......@@ -282,5 +280,5 @@ return array_merge_recursive(
include 'pilotage.config.php',
include 'budget.config.php',
include 'parametre.config.php',
include 'charge.config.php'
include 'chargens.config.php'
);
......@@ -296,9 +296,6 @@ return [
'ApplicationElementModulateur' => Service\ElementModulateur::class,
'ApplicationTypeModulateur' => Service\TypeModulateur::class,
'ApplicationDomaineFonctionnel' => Service\DomaineFonctionnel::class,
'FormElementPedagogiqueRechercheHydrator' => Form\OffreFormation\ElementPedagogiqueRechercheHydrator::class,
'ElementModulateursFormHydrator' => Form\OffreFormation\ElementModulateursHydrator::class,
'EtapeModulateursFormHydrator' => Form\OffreFormation\EtapeModulateursHydrator::class,
'AssertionOffreDeFormation' => Assertion\OffreDeFormationAssertion::class,
],
],
......
......@@ -453,9 +453,6 @@ return [
'ApplicationMotifNonPaiement' => Service\MotifNonPaiement::class,
'ApplicationModificationServiceDu' => Service\ModificationServiceDu::class,
'ApplicationCampagneSaisie' => Service\CampagneSaisieService::class,
'ServiceRechercheFormHydrator' => Form\Service\RechercheFormHydrator::class,
'FormServiceReferentielSaisieFieldsetHydrator' => Form\ServiceReferentiel\SaisieFieldsetHydrator::class,
'FormServiceReferentielSaisieHydrator' => Form\ServiceReferentiel\SaisieHydrator::class,
'assertionService' => Assertion\ServiceAssertion::class,
'processusService' => Processus\ServiceProcessus::class,
'processusServiceReferentiel' => Processus\ServiceReferentielProcessus::class,
......
......@@ -77,7 +77,6 @@ return [
'ApplicationVolumeHoraireReferentiel' => Service\VolumeHoraireReferentiel::class,
'ApplicationTypeVolumeHoraire' => Service\TypeVolumeHoraire::class,
'ApplicationEtatVolumeHoraire' => Service\EtatVolumeHoraire::class,
'FormVolumeHoraireSaisieMultipleHydrator' => Form\VolumeHoraire\SaisieMultipleHydrator::class,
],
],
'view_helpers' => [
......
......@@ -13,9 +13,18 @@ class BddConnecteur{
*
* @return array
*/
public function fetch($sql, $params = [])
public function fetch($sql, $params = [], $key=null)
{
return $this->getEntityManager()->getConnection()->fetchAll($sql, $this->prepareParams($params));
$result = $this->getEntityManager()->getConnection()->fetchAll($sql, $this->prepareParams($params));
if (null === $key){
return $result;
}else{
$res = [];
foreach( $result as $d ){
$res[$d[$key]] = $d;
}
return $res;
}
}
......
......@@ -4,12 +4,13 @@ namespace Application\Controller;
use Application\Exception\DbException;
use Application\Form\Supprimer;
use Doctrine\ORM\EntityManager;
use UnicaenApp\Exporter\Pdf;
use Zend\Mvc\Controller\AbstractActionController;
/**
* Description of AbstractController
*
* @method \Doctrine\ORM\EntityManager em()
* @method \Application\Controller\Plugin\Context context()
*
*/
......@@ -40,4 +41,23 @@ abstract class AbstractController extends AbstractActionController
return $form;
}
/**
* @return EntityManager
*/
protected function em()
{
return $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
}
/**
* @return Pdf
*/
protected function pdf()
{
return new Pdf($this->getServiceLocator()->get('view_manager')->getRenderer());
}
}
\ No newline at end of file
<?php
namespace Application\Controller;
use Application\Entity\Db\Etape;
use Application\Entity\Db\Scenario;
use Application\Entity\Db\Structure;
use Application\Form\Chargens\Traits\FiltreFormAwareTrait;
use Application\Provider\Chargens\ChargensProviderAwareTrait;
use Application\Service\Traits\ContextAwareTrait;
use Application\Service\Traits\EtapeAwareTrait;
use Application\Service\Traits\ScenarioServiceAwareTrait;
use Application\Service\Traits\StructureAwareTrait;
/**
* Description of ChargensController
*
* @author LECLUSE Laurent <laurent.lecluse at unicaen.fr>
*/
class ChargensController extends AbstractController
{
use ChargensProviderAwareTrait;
use ContextAwareTrait;
use StructureAwareTrait;
use EtapeAwareTrait;
use ScenarioServiceAwareTrait;
use FiltreFormAwareTrait;
public function indexAction()
{
/** @var Etape $etape */
$etape = $this->getEvent()->getParam('etape');
/** @var Scenario $scenario */
$scenario = $this->getEvent()->getParam('scenario');
if ($etape){
$structure = $etape->getStructure();
}else{
/** @var Structure $structure */
$structure = $this->getEvent()->getParam('structure');
}
$provider = $this->getProviderChargens();
$filtre = $this->getFormChargensFiltre();
if ($etape){
$provider->loadEtape($etape);
$filtre->get('etape')->setValue($etape->getId());
}
if ($scenario){
$provider->loadScenario( $scenario );
$filtre->get('scenario')->setValue($scenario->getId());
}
if ($structure){
$filtre->get('structure')->setValue($structure->getId());
}
return compact('structure', 'etape', 'scenario', 'provider', 'filtre');
}
public function scenarioAction()
{
$noeuds = $this->params()->fromPost('noeuds');
/** @var Scenario $scenario */
$scenario = $this->getEvent()->getParam('scenario');
}
}
\ No newline at end of file
......@@ -366,8 +366,8 @@ class ContratController extends AbstractController
];
// Création du pdf, complétion et envoi au navigateur
$exp = new Pdf($this->getServiceLocator()->get('view_manager')->getRenderer());
$exp->setHeaderSubtitle($contratToString)
$exp = $this->pdf()
->setHeaderSubtitle($contratToString)
->setMarginBottom(25)
->setMarginTop(25);
$exp->setFooterTitle($contratToString . ' - ' . $intervenant->getAnnee());
......
......@@ -18,7 +18,7 @@ use RuntimeException;
use NumberFormatter;
use UnicaenApp\Util;
use UnicaenApp\View\Model\MessengerViewModel;
use UnicaenAuth\Service\UserContext;
use UnicaenAuth\Service\Traits\UserContextServiceAwareTrait;
use Zend\View\Model\ViewModel;
......@@ -30,6 +30,7 @@ class DossierController extends AbstractController
use WorkflowServiceAwareTrait;
use ValidationAwareTrait;
use \Application\Form\Intervenant\Traits\DossierAwareTrait;
use UserContextServiceAwareTrait;
......@@ -277,14 +278,4 @@ class DossierController extends AbstractController
}
}
/**
* @return UserContext
*/
private function getServiceUserContext()
{
return $this->getServiceLocator()->get('authUserContext');
}
}
\ No newline at end of file
<?php
namespace Application\Controller\Factory;
use Application\Controller\ChargensController;
use Zend\Mvc\Controller\ControllerManager;
class ChargensControllerFactory
{
/**
* Create controller
*
* @param ControllerManager $controllerManager
*
* @return ChargensController
*/
public function __invoke(ControllerManager $controllerManager)
{
$sl = $controllerManager->getServiceLocator();
$controller = new ChargensController();
$controller->setProviderChargens($sl->get('chargens'));
//$controller->setServiceContext($sl->get('ApplicationContext'));
//$controller->setServiceStructure($sl->get('ApplicationStructure'));
//$controller->setServiceEtape($sl->get('ApplicationEtape'));
return $controller;
}
}
\ No newline at end of file
<?php
namespace Application\Controller\Factory;
use Application\Controller\IndicateurController;
use Zend\Mvc\Controller\ControllerManager;
use Zend\ServiceManager\ServiceLocatorInterface;
class IndicateurControllerFactory
{
/**
* Create controller
*
* @param ControllerManager $controllerManager
*
* @return IndicateurController
*/
public function __invoke(ControllerManager $controllerManager)
{
$sl = $controllerManager->getServiceLocator();
$httpRouter = $sl->get('HttpRouter');
$renderer = $sl->get('view_manager')->getRenderer();
$cliConfig = $this->getCliConfig($sl);
$controller = new IndicateurController( $httpRouter, $renderer, $cliConfig);
return $controller;
}
/**
* @param ServiceLocatorInterface $serviceLocator
*
* @return array
*/
private function getCliConfig(ServiceLocatorInterface $serviceLocator)
{
$config = $serviceLocator->get('Config');
return [
'domain' => isset($config['cli_config']['domain']) ? $config['cli_config']['domain'] : null,
'scheme' => isset($config['cli_config']['scheme']) ? $config['cli_config']['scheme'] : null,
];
}
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ namespace Application\Controller;
use Application\Acl\Role;
use Application\Provider\Privilege\Privileges;
use Application\Service\Traits\IntervenantAwareTrait;
use UnicaenAuth\Service\Traits\UserContextServiceAwareTrait;
use Zend\View\Model\ViewModel;
/**
......@@ -12,9 +13,10 @@ use Zend\View\Model\ViewModel;
*/
class IndexController extends AbstractController
{
use \Application\Service\Traits\ContextAwareTrait,
\Application\Service\Traits\AnneeAwareTrait,
IntervenantAwareTrait;
use \Application\Service\Traits\ContextAwareTrait;
use \Application\Service\Traits\AnneeAwareTrait;
use IntervenantAwareTrait;
use UserContextServiceAwareTrait;
......@@ -59,13 +61,4 @@ class IndexController extends AbstractController
return [];
}
/**
* @return UserContext
*/
private function getServiceUserContext()
{
return $this->getServiceLocator()->get('authUserContext');
}
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ use Application\Service\Traits\IndicateurServiceAwareTrait;
use Application\Service\Traits\IntervenantAwareTrait;
use Application\Service\Traits\NotificationIndicateurAwareTrait;
use Application\Filter\IntervenantEmailFormatter;
use Zend\View\Renderer\PhpRenderer;
use Exception;
use Zend\Form\Element\Hidden;
use Zend\Form\Element\Text;
......@@ -34,6 +35,43 @@ class IndicateurController extends AbstractController
use AffectationAwareTrait;
use IndicateurProcessusAwareTrait;
/**
* @var TreeRouteStack
*/
private $httpRouter;
/**
* @var PhpRenderer
*/
private $renderer;
/**
* @var array
*/
private $cliConfig;
/**
* PHP 5 allows developers to declare constructor methods for classes.
* Classes which have a constructor method call this method on each newly-created object,
* so it is suitable for any initialization that the object may need before it is used.
*