Commit fa835064 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Dérogations

parent 79edaaaf
Loading
Loading
Loading
Loading
+21
Changes for code/template/Controller.php: 21 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace <namespace>;

use Application\Controller\AbstractController;


/**
 * Description of <classname>
 *
 * @author <author>
 */
class <classname> extends AbstractController
{

    public function indexAction()
    {
        return [];
    }

}
 No newline at end of file
+5 −5
Changes for module/Application/src/ConfigFactory.php: 5 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -42,16 +42,16 @@ class ConfigFactory
        ];

        if (isset($config['console'])) {
            $finalConfig['console'] = [];
            $finalConfig['console']['router']['routes'] = [];
            foreach ($config['console'] as $cr => $cc) {
                $finalConfig['console'][$cr] = self::routeSimplified($cc);
                $finalConfig['console']['router']['routes'][$cr] = self::routeSimplified($cc, true);
            }
        }

        if (isset($config['routes'])) {
            $finalConfig['router']['routes'] = [];
            foreach ($config['routes'] as $cr => $cc) {
                $finalConfig['router']['routes'][$cr] = self::routeSimplified($cc);
                $finalConfig['router']['routes'][$cr] = self::routeSimplified($cc, false);
            }
        }

@@ -127,7 +127,7 @@ class ConfigFactory



    public static function routeSimplified(array $config): array
    public static function routeSimplified(array $config, bool $isConsole = false): array
    {
        /* On remonte ces params dans le sous-menu options */
        $optionsParams = ['route', 'defaults', 'constraints'];
@@ -151,7 +151,7 @@ class ConfigFactory
        }

        /* On détecte le type s'il n'eiste pas déjà */
        if (!isset($config['type']) && isset($config['options']['route'])) {
        if (!isset($config['type']) && isset($config['options']['route']) && !$isConsole) {
            if (false !== strpos($config['options']['route'], ':')) {
                $config['type'] = 'Segment';
            } else {
+1
Changes for module/Application/src/Controller/AbstractController.php: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ use Laminas\Mvc\Controller\AbstractActionController;
 * Description of AbstractController
 *
 * @method \Application\Controller\Plugin\Context context()
 * @method \Laminas\Mvc\Plugin\FlashMessenger\FlashMessenger flashMessenger()
 *
 */
abstract class AbstractController extends AbstractActionController
+10
Changes for module/Application/view/application/intervenant/voir.phtml: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -54,4 +54,14 @@ if ($this->isAllowed(Privileges::getResourceId(Privileges::INTERVENANT_SUPPRESSI
    ];
}


if ($this->isAllowed(Privileges::getResourceId(Privileges::PLAFONDS_DEROGATIONS_VISUALISATION))) {
    $tabs[] = [
        'id'            => 'derogations',
        'label'         => '<span class="glyphicon glyphicon-random"></span> Dérogations',
        'url'           => $this->url('derogations', ['intervenant' => $intervenant->getId()]),
        'force-refresh' => true,
    ];
}

echo $this->tabajax($tabs, $tab);
 No newline at end of file
+x+126
Changes for module/Plafond/src/Controller/DerogationController.php: 126 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Plafond\Controller;

use Application\Controller\AbstractController;
use Application\Entity\Db\Intervenant;
use Application\Service\Traits\TypeVolumeHoraireServiceAwareTrait;
use Plafond\Entity\Db\PlafondDerogation;
use Plafond\Entity\Db\PlafondEtat;
use Plafond\Service\PlafondServiceAwareTrait;


/**
 * Description of DerogationController
 *
 * @author UnicaenCode
 */
class DerogationController extends AbstractController
{
    use TypeVolumeHoraireServiceAwareTrait;
    use PlafondServiceAwareTrait;

    public function indexAction()
    {
        $intervenant          = $this->getEvent()->getParam('intervenant');
        $typesVolumesHoraires = $this->getServiceTypeVolumeHoraire()->getList();


        if ($this->params()->fromPost('action') == 'save') {
            $this->saveDerogations($intervenant);
        }

        $data = [];
        foreach ($typesVolumesHoraires as $typeVolumeHoraire) {
            $reponse = $this->getServicePlafond()->derogations($typeVolumeHoraire, $intervenant);
            $tvh     = $typeVolumeHoraire->getCode();

            foreach ($reponse as $pc) {
                if (!isset($data[$pc->getId()])) {
                    $data[$pc->getId()] = [
                        'libelle'    => $pc->getLibelle(),
                        'derogation' => floatToString($pc->getDerogation()),
                    ];
                }
                $data[$pc->getId()][$tvh . '-etat']        = $this->getServicePlafond()->getEtat($pc->getEtat())->getLibelle();
                $data[$pc->getId()][$tvh . '-heures']      = floatToString($pc->getHeures());
                $data[$pc->getId()][$tvh . '-plafond']     = floatToString($pc->getPlafond());
                $data[$pc->getId()][$tvh . '-depassement'] = $pc->isDepassement();
                if ($pc->isDepassement()) {
                    if ($pc->getEtat() == PlafondEtat::INFORMATIF) {
                        $data[$pc->getId()][$tvh . '-class'] = 'bg-warning';
                    } elseif ($pc->getEtat() == PlafondEtat::BLOQUANT) {
                        $data[$pc->getId()][$tvh . '-class'] = 'bg-danger';
                    }
                }
            }
        }

        return compact('intervenant', 'data', 'typesVolumesHoraires');
    }



    protected function saveDerogations(Intervenant $intervenant)
    {
        $this->em()->getFilters()->enable('historique')->init([
            PlafondDerogation::class,
        ]);

        $derogations = [];

        $post = $this->params()->fromPost();
        unset($post['action']);
        foreach ($post as $id => $heures) {
            $id     = (int)substr($id, 8);
            $heures = stringToFloat($heures);
            if ($heures != 0) {
                $derogations[$id]['new'] = $heures;
            }
        }

        /* @var $entities PlafondDerogation[] */
        $dql      = "SELECT pd, p
        FROM   " . PlafondDerogation::class . " pd
        JOIN pd.plafond p
        WHERE pd.intervenant = :intervenant";
        $entities = $this->em()->createQuery($dql)->execute(compact('intervenant'));
        foreach ($entities as $entity) {
            $derogations[$entity->getPlafond()->getId()]['old'] = $entity;
        }

        $changed = false;
        foreach ($derogations as $id => $derogation) {
            if (isset($derogation['old']) && !isset($derogation['new'])) {
                // delete
                $derogation['old']->historiser();
                $this->em()->persist($derogation['old']);
                $this->em()->flush($derogation['old']);
                $changed = true;
            } elseif (!isset($derogation['old']) && isset($derogation['new'])) {
                // insert
                $derog = new PlafondDerogation();
                $derog->setIntervenant($intervenant);
                $derog->setPlafond($this->getServicePlafond()->get($id));
                $derog->setHeures($derogation['new']);
                $this->em()->persist($derog);
                $this->em()->flush($derog);
                $changed = true;
            } elseif (isset($derogation['old']) && isset($derogation['new'])) {
                if ($derogation['old']->getHeures() != $derogation['new']) {
                    // update
                    $derogation['old']->setHeures($derogation['new']);
                    $this->em()->persist($derogation['old']);
                    $this->em()->flush($derogation['old']);
                    $changed = true;
                }
            }
        }

        if ($changed) {
            $this->flashMessenger()->addSuccessMessage('Les modifications ont bien été prises en compte');
        }
        $this->getServicePlafond()->calculerPourIntervenant($intervenant);
    }

}
 No newline at end of file
Loading