Loading module/Application/config/offre-formation.config.php +35 −0 Original line number Diff line number Diff line Loading @@ -144,6 +144,31 @@ return [ ], ], ], 'modulateurs-centres-couts' => [ 'type' => 'Segment', 'options' => [ 'route' => '/modulateurs-centres-couts/:elementPedagogique', 'constraints' => [ 'elementPedagogique' => '[0-9]*', ], 'defaults' => [ 'action' => 'modulateurs-centres-couts', ], ], ], 'modifier-modulateurs' => [ 'type' => 'Segment', 'options' => [ 'route' => '/modulateurs/modifier/:elementPedagogique', 'constraints' => [ 'elementPedagogique' => '[0-9]*', ], 'defaults' => [ 'action' => 'modifier-modulateur', ], ], ], ], ], 'etape' => [ Loading Loading @@ -341,6 +366,15 @@ return [ Privileges::ODF_ELEMENT_VH_EDITION, ], ], [ 'controller' => 'Application\Controller\OffreFormation\ElementPedagogique', 'action' => ['modulateurs-centres-couts'], 'privileges' => [ Privileges::ODF_CENTRES_COUT_EDITION, Privileges::ODF_MODULATEURS_EDITION, ], ], [ 'controller' => 'Application\Controller\OffreFormation\ElementPedagogique', Loading Loading @@ -451,6 +485,7 @@ return [ Form\OffreFormation\EtapeSaisie::class => Form\OffreFormation\EtapeSaisie::class, Form\OffreFormation\ElementPedagogiqueSaisie::class => Form\OffreFormation\ElementPedagogiqueSaisie::class, Form\OffreFormation\EtapeModulateursSaisie::class => Form\OffreFormation\EtapeModulateursSaisie::class, Form\OffreFormation\ElementModulateurCCSaisie::class => Form\OffreFormation\ElementModulateurCCSaisie::class, Form\OffreFormation\ElementModulateursFieldset::class => Form\OffreFormation\ElementModulateursFieldset::class, Form\OffreFormation\EtapeCentreCout\EtapeCentreCoutForm::class => Form\OffreFormation\EtapeCentreCout\EtapeCentreCoutForm::class, Form\OffreFormation\EtapeCentreCout\ElementCentreCoutFieldset::class => Form\OffreFormation\EtapeCentreCout\ElementCentreCoutFieldset::class, Loading module/Application/src/Application/Controller/OffreFormation/ElementPedagogiqueController.php +52 −4 Original line number Diff line number Diff line Loading @@ -5,9 +5,12 @@ namespace Application\Controller\OffreFormation; use Application\Controller\AbstractController; use Application\Entity\Db\ElementPedagogique; use Application\Filter\FloatFromString; use Application\Form\OffreFormation\Traits\ElementModulateurCentreCoutFormAwareTrait; use Application\Form\OffreFormation\Traits\ElementPedagogiqueSaisieAwareTrait; use Application\Form\OffreFormation\Traits\VolumeHoraireEnsFormAwareTrait; use Application\Provider\Privilege\Privileges; use Application\Service\Traits\CentreCoutEpServiceAwareTrait; use Application\Service\Traits\ElementModulateurServiceAwareTrait; use Application\Service\Traits\ElementPedagogiqueServiceAwareTrait; use Application\Service\Traits\ContextServiceAwareTrait; use Application\Service\Traits\VolumeHoraireEnsServiceAwareTrait; Loading @@ -24,6 +27,9 @@ class ElementPedagogiqueController extends AbstractController use ElementPedagogiqueSaisieAwareTrait; use VolumeHoraireEnsFormAwareTrait; use VolumeHoraireEnsServiceAwareTrait; use ElementModulateurCentreCoutFormAwareTrait; use ElementModulateurServiceAwareTrait; use CentreCoutEpServiceAwareTrait; Loading Loading @@ -255,4 +261,46 @@ class ElementPedagogiqueController extends AbstractController return compact('title', 'vhes', 'form'); } public function modulateursCentresCoutsAction() { $this->em()->getFilters()->enable('historique')->init([ \Application\Entity\Db\ElementModulateur::class, \Application\Entity\Db\CentreCout::class, \Application\Entity\Db\CentreCoutEp::class, ]); $element = $this->getEvent()->getParam('elementPedagogique'); $form = $this->getElementModulateurCentreCoutForm(); //Traitement retour formulaire $request = $this->getRequest(); if ($request->isPost()) { $datasPost = $request->getPost(); //Modulateur foreach($datasPost as $name => $value) { if(strstr($name, 'modulateur')) { $element = $this->getServiceElementModulateur()->addElementModulateur($element, $datasPost[$name]); } } //Centres de coûts $centreCouts = [ 'fi' => $datasPost['fi'], 'fa' => $datasPost['fa'], 'fc' => $datasPost['fc'], ]; $element = $this->getServiceCentreCoutEp()->addElementCentreCout($element, $centreCouts); } $form->setElementPedagogique($element); $form->setAttribute('action', $this->url()->fromRoute('of/element/modulateurs-centres-couts', ['elementPedagogique' => $element->getId()])); $form->build(); return [ 'form' => $form, ]; } } module/Application/src/Application/Form/OffreFormation/ElementModulateurCentreCoutForm.php 0 → 100755 +175 −0 Original line number Diff line number Diff line <?php namespace Application\Form\OffreFormation; use Application\Entity\Db\ElementPedagogique; use Application\Form\AbstractForm; use Application\Form\OffreFormation\Traits\ElementModulateursFieldsetAwareTrait; use Application\Service\Traits\CentreCoutServiceAwareTrait; use Application\Service\Traits\TypeModulateurServiceAwareTrait; use Application\Service\Traits\ElementPedagogiqueServiceAwareTrait; use Zend\Form\Element\Select; /** * Description of ElementModulateurSaisie * * @author Antony Le Courtes <antony.lecourtes@unicaen.fr> */ class ElementModulateurCentreCoutForm extends AbstractForm { use TypeModulateurServiceAwareTrait; use ElementPedagogiqueServiceAwareTrait; use TypeModulateurServiceAwareTrait; use ElementModulateursFieldsetAwareTrait; use CentreCoutServiceAwareTrait; /** * Element * * @var Element */ protected $elementPedagogiquePedagogique; public function __construct($name = null, $options = []) { if (!$name) $name = "element-modulateur-cc-saisie"; parent::__construct($name, $options); } public function init() { $this->setAttribute('class', 'element-modulateur-cc'); $this->setAttribute('action', $this->getCurrentUrl()); $this->add([ 'name' => 'submit', 'type' => 'Submit', 'attributes' => [ 'value' => 'Enregistrer', 'class' => 'btn btn-primary', ], ]); } public function build() { $elementPedagogique = $this->getElementPedagogique(); if (!$elementPedagogique) { throw new \RuntimeException('Element non spécifiée : construction du formulaire impossible'); } //Formulaire partie Modulateur de l'élément pédagogique en cours $typeModulateurs = $this->getServiceTypeModulateur()->finderByElementPedagogique($elementPedagogique)->getQuery()->getResult(); if (!empty($typeModulateurs)) { foreach($typeModulateurs as $typeModulateur) { $values = $typeModulateur->getModulateur(); foreach ($values as $value) { $modulateursValues[$typeModulateur->getCode()][$value->getCode()] = $value->getLibelle(); } $selectName = 'modulateur-' . $typeModulateur->getCode(); $selectModulateur = new Select($selectName); $selectModulateur->setLabel($typeModulateur->getLibelle() . " : "); $selectModulateur->setValueOptions(['' => '(Aucun)'] + $modulateursValues[$typeModulateur->getCode()]); $elementsModulateurs = $elementPedagogique->getElementModulateur(); foreach ($elementsModulateurs as $elementModulateur) { $typeModulateur = $elementModulateur->getModulateur()->getTypeModulateur(); $modulateur = $elementModulateur->getModulateur(); $selectModulateur->setValue($modulateur->getCode()); } $this->add($selectModulateur); } } //Formulaire partie Centres de coût de l'élément pédagogique en cours $centresCoutsEp = $elementPedagogique->getCentreCoutEp(); $centresCoutsValues = []; foreach ($centresCoutsEp as $centreCoutEp) { $codeTypeHeures = $centreCoutEp->getTypeHeures()->getCode(); $centreCout = $centreCoutEp->getCentreCout(); $centresCoutsValues[$codeTypeHeures] = $centreCout->getCode(); } $typeHeuresEp = $elementPedagogique->getTypeHeures()->getValues(); foreach ($typeHeuresEp as $typeHeures) { $selectCentreCout = $this->createSelectElementCentreCout($typeHeures); if (array_key_exists($typeHeures->getCode(), $centresCoutsValues)) { $selectCentreCout->setValue($centresCoutsValues[$typeHeures->getCode()]); } $this->add($selectCentreCout); } $this->add([ 'name' => 'id', 'type' => 'Hidden', ]); } private function createSelectElementCentreCout(\Application\Entity\Db\TypeHeures $th) { //retrieve centre cout by types heures $qb = $this->getServiceCentreCout()->finderByTypeHeures($th); $centresCouts = $qb->getQuery()->execute(); $valueOptions = []; foreach ($centresCouts as $centreCout) { $valueOptions[$centreCout->getCode()] = $centreCout->getCode() . ' - ' . $centreCout->getLibelle(); } $element = new Select($th->getCode()); $element ->setLabel($th->getLibelleCourt()) ->setValueOptions(['' => '(Aucun)'] + $valueOptions) ->setAttribute('class', 'type-heures selectpicker') ->setAttribute('data-live-search', 'true'); return $element; } /** * Retourne la liste des types de modulateurs de l'element * * @return \Application\Entity\Db\Modulateur[] */ public function getTypesModulateurs() { if (!$this->elementPedagogique) { throw new \RuntimeException('Element non spécifié'); } return $this->getServiceTypeModulateur()->getList($this->getServiceTypeModulateur()->finderByElementPedagogique($this->elementPedagogique)); } public function getElementPedagogique() { return $this->elementPedagogique; } public function setElementPedagogique(ElementPedagogique $elementPedagogique) { $this->elementPedagogique = $elementPedagogique; return $this; } public function getInputFilterSpecification() { } } No newline at end of file module/Application/src/Application/Form/OffreFormation/Traits/ElementModulateurCentreCoutFormAwareTrait.php 0 → 100755 +49 −0 Original line number Diff line number Diff line <?php namespace Application\Form\OffreFormation\Traits; use Application\Form\OffreFormation\ElementModulateurCentreCoutForm; /** * Description of ElementModulateurCentreCoutAwareTrait * * @author UnicaenCode */ trait ElementModulateurCentreCoutFormAwareTrait { /** * @var ElementModulateurCentreCoutForm */ private $elementModulateurCentreCoutForm; /** * @param ElementModulateurCentreCoutForm $elementModulateurCentreCoutForm * * @return self */ public function setElementModulateurCentreCoutForm(ElementModulateurCentreCoutForm $elementModulateurCentreCoutForm) { $this->elementModulateurCentreCoutForm = $elementModulateurCentreCoutForm; return $this; } /** * Retourne un nouveau formulaire * * @return ElementModulateurCentreCoutForm */ public function getElementModulateurCentreCoutForm() { if (!empty($this->elementModulateurCentreCoutForm)) { return $this->elementModulateurCentreCoutForm; } return \Application::$container->get('FormElementManager')->get(ElementModulateurCentreCoutForm::class); } } No newline at end of file module/Application/src/Application/Service/CentreCoutEpService.php +73 −6 Original line number Diff line number Diff line Loading @@ -3,8 +3,11 @@ namespace Application\Service; use Application\Entity\Db\CentreCoutEp; use Application\Entity\Db\ElementPedagogique; use Application\Provider\Privilege\Privileges; use Application\Service\Traits\CentreCoutServiceAwareTrait; use Application\Service\Traits\SourceServiceAwareTrait; use Application\Service\Traits\TypeHeuresServiceAwareTrait; use BjyAuthorize\Exception\UnAuthorizedException; /** Loading @@ -15,6 +18,10 @@ use BjyAuthorize\Exception\UnAuthorizedException; class CentreCoutEpService extends AbstractEntityService { use SourceServiceAwareTrait; use CentreCoutServiceAwareTrait; use TypeHeuresServiceAwareTrait; /** * retourne la classe des entités Loading @@ -26,6 +33,8 @@ class CentreCoutEpService extends AbstractEntityService return CentreCoutEp::class; } /** * Retourne l'alias d'entité courante * Loading @@ -47,6 +56,7 @@ class CentreCoutEpService extends AbstractEntityService { $entity = parent::newEntity(); $entity->setSource($this->getServiceSource()->getOse()); return $entity; } Loading @@ -56,8 +66,9 @@ class CentreCoutEpService extends AbstractEntityService * Sauvegarde un centre de coûts * * @param CentreCoutEp $entity * @throws \RuntimeException * * @return CentreCoutEp * @throws \RuntimeException */ public function save($entity) { Loading @@ -72,6 +83,62 @@ class CentreCoutEpService extends AbstractEntityService ) { $entity->setSourceCode(uniqid($cc->getId() . '_' . $th->getId() . '_' . $ep->getId())); } return parent::save($entity); } /** * Ajoute des centres de coût par types d'heures sur élement pédagogique * * @param ElementPedagogique $element * @param Array $centreCouts tableau type heures => centre de coût * * @return ElementPedagogique */ public function addElementCentreCout(ElementPedagogique $element, $centreCouts) { $centreCoutEpCollection = $element->getCentreCoutEp()->toArray(); $mergeCentreCoutEp = []; foreach ($centreCoutEpCollection as $centreCoutEp) { $mergeCentreCoutEp[$centreCoutEp->getTypeHeures()->getCode()] = $centreCoutEp; } foreach ($centreCouts as $th => $cc) { //Mise à jour ou delete if (array_key_exists($th, $mergeCentreCoutEp)) { $centreCoutEp = $mergeCentreCoutEp[$th]; if (empty($cc)) { $this->delete($centreCoutEp); } else { $centreCoutEntity = $this->getServiceCentreCout()->getRepo()->findOneByCode($cc); $centreCoutEp->setCentreCout($centreCoutEntity); $this->save($centreCoutEp); } } else { if (!empty($cc)) { //Creation $centreCoutEntity = $this->getServiceCentreCout()->getRepo()->findOneByCode($cc); $typeHeuresEntity = $this->getServiceTypeHeures()->getRepo()->findOneByCode($th); try { $centreCoutEntity = $this->getServiceCentreCout()->getRepo()->findOneByCode($cc); $typeHeuresEntity = $this->getServiceTypeHeures()->getRepo()->findOneByCode($th); } catch (\Exception $e) { $this->flashMessenger()->addErrorMessage("Centre de coût ou Modulateur inexistant"); } $newCentreCoutEp = $this->newEntity(); $newCentreCoutEp->setCentreCout($centreCoutEntity); $newCentreCoutEp->setElementPedagogique($element); $newCentreCoutEp->setTypeHeures($typeHeuresEntity); $this->save($newCentreCoutEp); } } } //refresh l'entité pour l'affichage utilisateur post traitement $this->entityManager->refresh($element); return $element; } } No newline at end of file Loading
module/Application/config/offre-formation.config.php +35 −0 Original line number Diff line number Diff line Loading @@ -144,6 +144,31 @@ return [ ], ], ], 'modulateurs-centres-couts' => [ 'type' => 'Segment', 'options' => [ 'route' => '/modulateurs-centres-couts/:elementPedagogique', 'constraints' => [ 'elementPedagogique' => '[0-9]*', ], 'defaults' => [ 'action' => 'modulateurs-centres-couts', ], ], ], 'modifier-modulateurs' => [ 'type' => 'Segment', 'options' => [ 'route' => '/modulateurs/modifier/:elementPedagogique', 'constraints' => [ 'elementPedagogique' => '[0-9]*', ], 'defaults' => [ 'action' => 'modifier-modulateur', ], ], ], ], ], 'etape' => [ Loading Loading @@ -341,6 +366,15 @@ return [ Privileges::ODF_ELEMENT_VH_EDITION, ], ], [ 'controller' => 'Application\Controller\OffreFormation\ElementPedagogique', 'action' => ['modulateurs-centres-couts'], 'privileges' => [ Privileges::ODF_CENTRES_COUT_EDITION, Privileges::ODF_MODULATEURS_EDITION, ], ], [ 'controller' => 'Application\Controller\OffreFormation\ElementPedagogique', Loading Loading @@ -451,6 +485,7 @@ return [ Form\OffreFormation\EtapeSaisie::class => Form\OffreFormation\EtapeSaisie::class, Form\OffreFormation\ElementPedagogiqueSaisie::class => Form\OffreFormation\ElementPedagogiqueSaisie::class, Form\OffreFormation\EtapeModulateursSaisie::class => Form\OffreFormation\EtapeModulateursSaisie::class, Form\OffreFormation\ElementModulateurCCSaisie::class => Form\OffreFormation\ElementModulateurCCSaisie::class, Form\OffreFormation\ElementModulateursFieldset::class => Form\OffreFormation\ElementModulateursFieldset::class, Form\OffreFormation\EtapeCentreCout\EtapeCentreCoutForm::class => Form\OffreFormation\EtapeCentreCout\EtapeCentreCoutForm::class, Form\OffreFormation\EtapeCentreCout\ElementCentreCoutFieldset::class => Form\OffreFormation\EtapeCentreCout\ElementCentreCoutFieldset::class, Loading
module/Application/src/Application/Controller/OffreFormation/ElementPedagogiqueController.php +52 −4 Original line number Diff line number Diff line Loading @@ -5,9 +5,12 @@ namespace Application\Controller\OffreFormation; use Application\Controller\AbstractController; use Application\Entity\Db\ElementPedagogique; use Application\Filter\FloatFromString; use Application\Form\OffreFormation\Traits\ElementModulateurCentreCoutFormAwareTrait; use Application\Form\OffreFormation\Traits\ElementPedagogiqueSaisieAwareTrait; use Application\Form\OffreFormation\Traits\VolumeHoraireEnsFormAwareTrait; use Application\Provider\Privilege\Privileges; use Application\Service\Traits\CentreCoutEpServiceAwareTrait; use Application\Service\Traits\ElementModulateurServiceAwareTrait; use Application\Service\Traits\ElementPedagogiqueServiceAwareTrait; use Application\Service\Traits\ContextServiceAwareTrait; use Application\Service\Traits\VolumeHoraireEnsServiceAwareTrait; Loading @@ -24,6 +27,9 @@ class ElementPedagogiqueController extends AbstractController use ElementPedagogiqueSaisieAwareTrait; use VolumeHoraireEnsFormAwareTrait; use VolumeHoraireEnsServiceAwareTrait; use ElementModulateurCentreCoutFormAwareTrait; use ElementModulateurServiceAwareTrait; use CentreCoutEpServiceAwareTrait; Loading Loading @@ -255,4 +261,46 @@ class ElementPedagogiqueController extends AbstractController return compact('title', 'vhes', 'form'); } public function modulateursCentresCoutsAction() { $this->em()->getFilters()->enable('historique')->init([ \Application\Entity\Db\ElementModulateur::class, \Application\Entity\Db\CentreCout::class, \Application\Entity\Db\CentreCoutEp::class, ]); $element = $this->getEvent()->getParam('elementPedagogique'); $form = $this->getElementModulateurCentreCoutForm(); //Traitement retour formulaire $request = $this->getRequest(); if ($request->isPost()) { $datasPost = $request->getPost(); //Modulateur foreach($datasPost as $name => $value) { if(strstr($name, 'modulateur')) { $element = $this->getServiceElementModulateur()->addElementModulateur($element, $datasPost[$name]); } } //Centres de coûts $centreCouts = [ 'fi' => $datasPost['fi'], 'fa' => $datasPost['fa'], 'fc' => $datasPost['fc'], ]; $element = $this->getServiceCentreCoutEp()->addElementCentreCout($element, $centreCouts); } $form->setElementPedagogique($element); $form->setAttribute('action', $this->url()->fromRoute('of/element/modulateurs-centres-couts', ['elementPedagogique' => $element->getId()])); $form->build(); return [ 'form' => $form, ]; } }
module/Application/src/Application/Form/OffreFormation/ElementModulateurCentreCoutForm.php 0 → 100755 +175 −0 Original line number Diff line number Diff line <?php namespace Application\Form\OffreFormation; use Application\Entity\Db\ElementPedagogique; use Application\Form\AbstractForm; use Application\Form\OffreFormation\Traits\ElementModulateursFieldsetAwareTrait; use Application\Service\Traits\CentreCoutServiceAwareTrait; use Application\Service\Traits\TypeModulateurServiceAwareTrait; use Application\Service\Traits\ElementPedagogiqueServiceAwareTrait; use Zend\Form\Element\Select; /** * Description of ElementModulateurSaisie * * @author Antony Le Courtes <antony.lecourtes@unicaen.fr> */ class ElementModulateurCentreCoutForm extends AbstractForm { use TypeModulateurServiceAwareTrait; use ElementPedagogiqueServiceAwareTrait; use TypeModulateurServiceAwareTrait; use ElementModulateursFieldsetAwareTrait; use CentreCoutServiceAwareTrait; /** * Element * * @var Element */ protected $elementPedagogiquePedagogique; public function __construct($name = null, $options = []) { if (!$name) $name = "element-modulateur-cc-saisie"; parent::__construct($name, $options); } public function init() { $this->setAttribute('class', 'element-modulateur-cc'); $this->setAttribute('action', $this->getCurrentUrl()); $this->add([ 'name' => 'submit', 'type' => 'Submit', 'attributes' => [ 'value' => 'Enregistrer', 'class' => 'btn btn-primary', ], ]); } public function build() { $elementPedagogique = $this->getElementPedagogique(); if (!$elementPedagogique) { throw new \RuntimeException('Element non spécifiée : construction du formulaire impossible'); } //Formulaire partie Modulateur de l'élément pédagogique en cours $typeModulateurs = $this->getServiceTypeModulateur()->finderByElementPedagogique($elementPedagogique)->getQuery()->getResult(); if (!empty($typeModulateurs)) { foreach($typeModulateurs as $typeModulateur) { $values = $typeModulateur->getModulateur(); foreach ($values as $value) { $modulateursValues[$typeModulateur->getCode()][$value->getCode()] = $value->getLibelle(); } $selectName = 'modulateur-' . $typeModulateur->getCode(); $selectModulateur = new Select($selectName); $selectModulateur->setLabel($typeModulateur->getLibelle() . " : "); $selectModulateur->setValueOptions(['' => '(Aucun)'] + $modulateursValues[$typeModulateur->getCode()]); $elementsModulateurs = $elementPedagogique->getElementModulateur(); foreach ($elementsModulateurs as $elementModulateur) { $typeModulateur = $elementModulateur->getModulateur()->getTypeModulateur(); $modulateur = $elementModulateur->getModulateur(); $selectModulateur->setValue($modulateur->getCode()); } $this->add($selectModulateur); } } //Formulaire partie Centres de coût de l'élément pédagogique en cours $centresCoutsEp = $elementPedagogique->getCentreCoutEp(); $centresCoutsValues = []; foreach ($centresCoutsEp as $centreCoutEp) { $codeTypeHeures = $centreCoutEp->getTypeHeures()->getCode(); $centreCout = $centreCoutEp->getCentreCout(); $centresCoutsValues[$codeTypeHeures] = $centreCout->getCode(); } $typeHeuresEp = $elementPedagogique->getTypeHeures()->getValues(); foreach ($typeHeuresEp as $typeHeures) { $selectCentreCout = $this->createSelectElementCentreCout($typeHeures); if (array_key_exists($typeHeures->getCode(), $centresCoutsValues)) { $selectCentreCout->setValue($centresCoutsValues[$typeHeures->getCode()]); } $this->add($selectCentreCout); } $this->add([ 'name' => 'id', 'type' => 'Hidden', ]); } private function createSelectElementCentreCout(\Application\Entity\Db\TypeHeures $th) { //retrieve centre cout by types heures $qb = $this->getServiceCentreCout()->finderByTypeHeures($th); $centresCouts = $qb->getQuery()->execute(); $valueOptions = []; foreach ($centresCouts as $centreCout) { $valueOptions[$centreCout->getCode()] = $centreCout->getCode() . ' - ' . $centreCout->getLibelle(); } $element = new Select($th->getCode()); $element ->setLabel($th->getLibelleCourt()) ->setValueOptions(['' => '(Aucun)'] + $valueOptions) ->setAttribute('class', 'type-heures selectpicker') ->setAttribute('data-live-search', 'true'); return $element; } /** * Retourne la liste des types de modulateurs de l'element * * @return \Application\Entity\Db\Modulateur[] */ public function getTypesModulateurs() { if (!$this->elementPedagogique) { throw new \RuntimeException('Element non spécifié'); } return $this->getServiceTypeModulateur()->getList($this->getServiceTypeModulateur()->finderByElementPedagogique($this->elementPedagogique)); } public function getElementPedagogique() { return $this->elementPedagogique; } public function setElementPedagogique(ElementPedagogique $elementPedagogique) { $this->elementPedagogique = $elementPedagogique; return $this; } public function getInputFilterSpecification() { } } No newline at end of file
module/Application/src/Application/Form/OffreFormation/Traits/ElementModulateurCentreCoutFormAwareTrait.php 0 → 100755 +49 −0 Original line number Diff line number Diff line <?php namespace Application\Form\OffreFormation\Traits; use Application\Form\OffreFormation\ElementModulateurCentreCoutForm; /** * Description of ElementModulateurCentreCoutAwareTrait * * @author UnicaenCode */ trait ElementModulateurCentreCoutFormAwareTrait { /** * @var ElementModulateurCentreCoutForm */ private $elementModulateurCentreCoutForm; /** * @param ElementModulateurCentreCoutForm $elementModulateurCentreCoutForm * * @return self */ public function setElementModulateurCentreCoutForm(ElementModulateurCentreCoutForm $elementModulateurCentreCoutForm) { $this->elementModulateurCentreCoutForm = $elementModulateurCentreCoutForm; return $this; } /** * Retourne un nouveau formulaire * * @return ElementModulateurCentreCoutForm */ public function getElementModulateurCentreCoutForm() { if (!empty($this->elementModulateurCentreCoutForm)) { return $this->elementModulateurCentreCoutForm; } return \Application::$container->get('FormElementManager')->get(ElementModulateurCentreCoutForm::class); } } No newline at end of file
module/Application/src/Application/Service/CentreCoutEpService.php +73 −6 Original line number Diff line number Diff line Loading @@ -3,8 +3,11 @@ namespace Application\Service; use Application\Entity\Db\CentreCoutEp; use Application\Entity\Db\ElementPedagogique; use Application\Provider\Privilege\Privileges; use Application\Service\Traits\CentreCoutServiceAwareTrait; use Application\Service\Traits\SourceServiceAwareTrait; use Application\Service\Traits\TypeHeuresServiceAwareTrait; use BjyAuthorize\Exception\UnAuthorizedException; /** Loading @@ -15,6 +18,10 @@ use BjyAuthorize\Exception\UnAuthorizedException; class CentreCoutEpService extends AbstractEntityService { use SourceServiceAwareTrait; use CentreCoutServiceAwareTrait; use TypeHeuresServiceAwareTrait; /** * retourne la classe des entités Loading @@ -26,6 +33,8 @@ class CentreCoutEpService extends AbstractEntityService return CentreCoutEp::class; } /** * Retourne l'alias d'entité courante * Loading @@ -47,6 +56,7 @@ class CentreCoutEpService extends AbstractEntityService { $entity = parent::newEntity(); $entity->setSource($this->getServiceSource()->getOse()); return $entity; } Loading @@ -56,8 +66,9 @@ class CentreCoutEpService extends AbstractEntityService * Sauvegarde un centre de coûts * * @param CentreCoutEp $entity * @throws \RuntimeException * * @return CentreCoutEp * @throws \RuntimeException */ public function save($entity) { Loading @@ -72,6 +83,62 @@ class CentreCoutEpService extends AbstractEntityService ) { $entity->setSourceCode(uniqid($cc->getId() . '_' . $th->getId() . '_' . $ep->getId())); } return parent::save($entity); } /** * Ajoute des centres de coût par types d'heures sur élement pédagogique * * @param ElementPedagogique $element * @param Array $centreCouts tableau type heures => centre de coût * * @return ElementPedagogique */ public function addElementCentreCout(ElementPedagogique $element, $centreCouts) { $centreCoutEpCollection = $element->getCentreCoutEp()->toArray(); $mergeCentreCoutEp = []; foreach ($centreCoutEpCollection as $centreCoutEp) { $mergeCentreCoutEp[$centreCoutEp->getTypeHeures()->getCode()] = $centreCoutEp; } foreach ($centreCouts as $th => $cc) { //Mise à jour ou delete if (array_key_exists($th, $mergeCentreCoutEp)) { $centreCoutEp = $mergeCentreCoutEp[$th]; if (empty($cc)) { $this->delete($centreCoutEp); } else { $centreCoutEntity = $this->getServiceCentreCout()->getRepo()->findOneByCode($cc); $centreCoutEp->setCentreCout($centreCoutEntity); $this->save($centreCoutEp); } } else { if (!empty($cc)) { //Creation $centreCoutEntity = $this->getServiceCentreCout()->getRepo()->findOneByCode($cc); $typeHeuresEntity = $this->getServiceTypeHeures()->getRepo()->findOneByCode($th); try { $centreCoutEntity = $this->getServiceCentreCout()->getRepo()->findOneByCode($cc); $typeHeuresEntity = $this->getServiceTypeHeures()->getRepo()->findOneByCode($th); } catch (\Exception $e) { $this->flashMessenger()->addErrorMessage("Centre de coût ou Modulateur inexistant"); } $newCentreCoutEp = $this->newEntity(); $newCentreCoutEp->setCentreCout($centreCoutEntity); $newCentreCoutEp->setElementPedagogique($element); $newCentreCoutEp->setTypeHeures($typeHeuresEntity); $this->save($newCentreCoutEp); } } } //refresh l'entité pour l'affichage utilisateur post traitement $this->entityManager->refresh($element); return $element; } } No newline at end of file