Commit 33c230f8 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Correction de bugs multiples sur l'interface de gestion des statuts des intervenants

parent 03e3c7df
Loading
Loading
Loading
Loading
+8 −9
Changes for code/test6.php: 8 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -7,14 +7,13 @@
 * @var $sl         \Zend\ServiceManager\ServiceLocatorInterface
 */

use Application\Processus\PlafondProcessus;
use Application\Service\ElementPedagogiqueService;
use Application\Service\IntervenantService;
use Application\Service\PlafondService;
use Application\Service\TypeVolumeHoraireService;
use Application\Service\StatutIntervenantService;

/** @var PlafondProcessus $pp */
$pp = $sl->get(PlafondProcessus::class);
echo 'test2';
$si = $sl->get(StatutIntervenantService::class);

var_dump($pp );
 No newline at end of file
$s = $si->get(19);


$ns = $s->dupliquer();

var_dump($ns);
 No newline at end of file
+0 −1
Changes for module/Application/autoload_classmap.php: 0 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -238,7 +238,6 @@ return [
    'Application\Entity\Db\Traits\VServiceValideAwareTrait'                                              => __DIR__ . '/src/Application/Entity/Db/Traits/VServiceValideAwareTrait.php',
    'Application\Entity\Db\Traits\FormuleResultatServiceReferentielAwareTrait'                           => __DIR__ . '/src/Application/Entity/Db/Traits/FormuleResultatServiceReferentielAwareTrait.php',
    'Application\Entity\Db\Traits\CiviliteAwareTrait'                                                    => __DIR__ . '/src/Application/Entity/Db/Traits/CiviliteAwareTrait.php',
    'Application\Entity\Db\Traits\StatutIntervenantAwareTrait'                                           => __DIR__ . '/src/Application/Entity/Db/Traits/StatutIntervenantAwareTrait.php',
    'Application\Entity\Db\Traits\VIndicAttenteDemandeMepAwareTrait'                                     => __DIR__ . '/src/Application/Entity/Db/Traits/VIndicAttenteDemandeMepAwareTrait.php',
    'Application\Entity\Db\Traits\AdresseIntervenantAwareTrait'                                          => __DIR__ . '/src/Application/Entity/Db/Traits/AdresseIntervenantAwareTrait.php',
    'Application\Entity\Db\Traits\CentreCoutEpAwareTrait'                                                => __DIR__ . '/src/Application/Entity/Db/Traits/CentreCoutEpAwareTrait.php',
+38 −31
Changes for module/Application/src/Application/Controller/StatutIntervenantController.php: 38 added lines, 31 removed lines.
Original line number Diff line number Diff line
@@ -4,18 +4,20 @@ namespace Application\Controller;

use Application\Entity\Db\StatutIntervenant;
use Application\Provider\Privilege\Privileges;
use Application\Service\Traits\StatutIntervenantAwareTrait;
use Application\Exception\DbException;
use Application\Form\StatutIntervenant\Traits\StatutIntervenantSaisieFormAwareTrait;
use Application\Service\Traits\StatutIntervenantServiceAwareTrait;
use UnicaenApp\View\Model\MessengerViewModel;
use Application\Service\Traits\TypeIntervenantServiceAwareTrait;

class StatutIntervenantController extends AbstractController
{
    use StatutIntervenantAwareTrait;
    use StatutIntervenantServiceAwareTrait;
    use StatutIntervenantSaisieFormAwareTrait;
    use TypeIntervenantServiceAwareTrait;



    public function indexAction()
    {
        $this->em()->getFilters()->enable('historique')->init([
@@ -28,6 +30,7 @@ class StatutIntervenantController extends AbstractController
    }



    public function saisieAction()
    {
        /* @var $statutIntervenant StatutIntervenant */
@@ -35,20 +38,19 @@ class StatutIntervenantController extends AbstractController
        $statutIntervenant = $this->getEvent()->getParam('statutIntervenant');
        $form              = $this->getFormStatutIntervenantSaisie();
        if (empty($statutIntervenant)) {
            //$title = 'Création d\'un nouveau statut d\'intervenant';
            $tblSi=$this->getServiceStatutIntervenant()->getList();
            $ordre=0;
            foreach($tblSi as $eltSi){
                if ($eltSi->getOrdre() > $ordre) $ordre=$eltSi->getOrdre();
            }
            $ordre++;
            $title             = 'Création d\'un nouveau statut d\'intervenant';
            $statutIntervenant = $this->getServiceStatutIntervenant()->newEntity();
            $statutIntervenant->setOrdre($this->getServiceStatutIntervenant()->fetchMaxOrdre() + 1);
        } else {
            $title = 'Édition d\'un statut d\'intervenant';
        }

        if ($this->isAllowed(Privileges::getResourceId(Privileges::INTERVENANT_STATUT_EDITION))) {
        $canEdit = $this->isAllowed(Privileges::getResourceId(Privileges::INTERVENANT_STATUT_EDITION));
        if ($statutIntervenant->getSource()->getImportable()) {
            $canEdit = false; // Si la source est synchronisable alors pas d'édition possible
        }

        if ($canEdit) {
            $form->bindRequestSave($statutIntervenant, $this->getRequest(), function (StatutIntervenant $si) {
                try {
                    $this->getServiceStatutIntervenant()->save($si);
@@ -67,68 +69,73 @@ class StatutIntervenantController extends AbstractController
        return compact('form', 'title');
    }



    public function deleteAction()
    {
        $statutIntervenant = $this->getEvent()->getParam('statutIntervenant');

        $canEdit = $this->isAllowed(Privileges::getResourceId(Privileges::INTERVENANT_STATUT_EDITION));
        if ($statutIntervenant->getSource()->getImportable()) {
            $canEdit = false; // Si la source est synchronisable alors pas d'édition possible
        }

        if (!$canEdit) {
            $this->flashMessenger()->addErrorMessage('Statut non modifiable : droit non accordé, car vous n\'avez pas le privilège pour cela ou bien le statut est synchronisé depuis un autre logiciel');
        } else {
            try {
                $this->getServiceStatutIntervenant()->delete($statutIntervenant);
                $this->flashMessenger()->addSuccessMessage("Statut d'Intervenant supprimé avec succès.");
            } catch (\Exception $e) {
                $this->flashMessenger()->addErrorMessage(DbException::translate($e)->getMessage());
            }
        }

        return new MessengerViewModel(compact('statutIntervenant'));
    }



    public function statutIntervenantTrierAction()
    {
        /* @var $si StatutIntervenant */
        $txt='result=';
        $champsIds = explode(',', $this->params()->fromPost('champsIds', ''));
        $this->flashMessenger(var_dump($champsIds));
        $ordre = 1;
        $ordre     = $this->getServiceStatutIntervenant()->fetchMaxOrdre() + 1; // Pour éviter tout doublon!!
        foreach ($champsIds as $champId) {
            $txt.=$champId.'=>';
            $si = $this->getServiceStatutIntervenant()->get($champId);
            if ($si) {
                $txt .= ';' . $si->getOrdre();
                $si->setOrdre($ordre);
                $ordre++;
                try {
                    $this->getServiceStatutIntervenant()->save($si);
                } catch (\Exception $e) {
                    $e = DbException::translate($e);
                    $txt .= ':' . $e->getMessage();
                    $this->flashMessenger()->addErrorMessage(DbException::translate($e)->getMessage());
                }
            }
        }

        return new JsonModel(['msg' => 'Tri des champs effectué']);
    }



    public function cloneAction()
    {
        /* @var $statutIntervenant StatutIntervenant */
        /* @var $statutIntervenantNew StatutIntervenant */

        $statutIntervenant = $this->getEvent()->getParam('statutIntervenant');
        $form              = $this->getFormStatutIntervenantSaisie();
        if (empty($statutIntervenant)) {
            $this->flashMessenger()->addErrorMessage($e->getMessage() . ':' . $statutIntervenant->getId());
            return;
        }
        $title = 'Dupplication d\'un statut d\'intervenant';
        $statutIntervenantNew = clone $statutIntervenant;
        $i=$this->getServiceStatutIntervenant()->fetchMaxOrdre()+1;
        $statutIntervenantNew->setOrdre($i+1);

        $title                = 'Duplication d\'un statut d\'intervenant';
        $newStatutIntervenant = $statutIntervenant->dupliquer();
        $newStatutIntervenant->setOrdre($this->getServiceStatutIntervenant()->fetchMaxOrdre() + 1);
        //$statutIntervenantNew->setOrdre($this->getServiceStatutIntervenant()->fetchMaxOrdre()+1);
        $form->bind($statutIntervenantNew);
        $form->bind($newStatutIntervenant);
        $request = $this->getRequest();
        if ($request->isPost()) {
            $form->setData($request->getPost());
            if ($form->isValid()) {
                try {
                    $this->getServiceStatutIntervenant()->save($statutIntervenantNew);
                    $form->get('id')->setValue($statutIntervenantNew->getId()); // transmet le nouvel ID
                    $this->getServiceStatutIntervenant()->save($newStatutIntervenant);
                    $form->get('id')->setValue($newStatutIntervenant->getId()); // transmet le nouvel ID
                    $this->flashMessenger()->addSuccessMessage('Enregistrement effectué');
                } catch (\Exception $e) {
                    $e        = DbException::translate($e);
+35 −16
Changes for module/Application/src/Application/Entity/Db/StatutIntervenant.php: 35 added lines, 16 removed lines.
Original line number Diff line number Diff line
@@ -206,6 +206,8 @@ class StatutIntervenant implements HistoriqueAwareInterface, RoleInterface, Impo
        return $this;
    }



    /**
     * @return boolean
     */
@@ -642,6 +644,20 @@ class StatutIntervenant implements HistoriqueAwareInterface, RoleInterface, Impo



    /**
     * @param int $id
     *
     * @return StatutIntervenant
     */
    public function setId($id): StatutIntervenant
    {
        $this->id = $id;

        return $this;
    }



    /**
     * Set typeIntervenant
     *
@@ -790,9 +806,11 @@ class StatutIntervenant implements HistoriqueAwareInterface, RoleInterface, Impo
            $privilege = $privilege->getFullCode();
        }
        $privileges = $this->getPrivilege();
        if ($privileges) foreach ($privileges as $priv) {
        if ($privileges) {
            foreach ($privileges as $priv) {
                if ($priv->getFullCode() === $privilege) return true;
            }
        }

        return false;
    }
@@ -853,6 +871,7 @@ class StatutIntervenant implements HistoriqueAwareInterface, RoleInterface, Impo
    }



    /**
     * @return boolean
     */
@@ -876,22 +895,22 @@ class StatutIntervenant implements HistoriqueAwareInterface, RoleInterface, Impo
    }


    /**
     * @since PHP 5.6.0
     * This method is called by var_dump() when dumping an object to get the properties that should be shown.
     * If the method isn't defined on an object, then all public, protected and private properties will be shown.
     *
     * @return array
     * @link  http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.debuginfo
     */
    function __debugInfo()

    public function dupliquer()
    {
        return [
            'id'         => $this->id,
            'sourceCode' => $this->sourceCode,
            'libelle'    => $this->libelle,
            'type'       => $this->typeIntervenant ? $this->typeIntervenant->getLibelle() : null,
        ];
        $new = new StatutIntervenant();
        $methods = get_class_methods($this);
        foreach( $methods as $method ){
            $setMethod = 'set'.substr($method, 3);
            if (0 === strpos($method, 'get') && in_array($setMethod, $methods)){
                $new->$setMethod($this->$method());
            }
        }
        $new->setId(null);
        $uid = uniqid();
        $new->setSourceCode( $this->getSourceCode().'_'.$uid);
        $new->setLibelle($this->getLibelle().' (Copie '.$uid.')');

        return $new;
    }
}
+19 −11
Changes for module/Application/src/Application/Service/StatutIntervenantService.php: 19 added lines, 11 removed lines.
Original line number Diff line number Diff line
@@ -14,6 +14,9 @@ use Doctrine\ORM\QueryBuilder;
class StatutIntervenantService extends AbstractEntityService
{
    use SourceServiceAwareTrait;



    /**
     * retourne la classe des entités
     *
@@ -25,27 +28,32 @@ class StatutIntervenantService extends AbstractEntityService
        return StatutIntervenant::class;
    }



    /**
     * Retourne l'alias d'entité courante
     *
     * @return string
     */
    public function getAlias(){
    public function getAlias()
    {
        return 'si';
    }



    /**
     * Retourne la liste des étapes
     * @param QueryBuilder|null $qb
     * @param null              $alias
     *
     * @param QueryBuilder|null $queryBuilder
     * @param string|null $alias
     * @return StatutIntervenant[]
     * @return QueryBuilder
     */
    public function getList( QueryBuilder $qb=null, $alias=null )
    public function orderBy( QueryBuilder $qb=null, $alias=null )
    {
        list($qb,$alias) = $this->initQuery($qb, $alias);
        $qb->orderBy("$alias.ordre");
        return parent::getList($qb, $alias);
        $qb->addOrderBy("$alias.ordre");

        return $qb;
    }


@@ -53,17 +61,17 @@ class StatutIntervenantService extends AbstractEntityService
    /**
     * @return int
     */
    public function fetchMaxOrdre(): integer
    public function fetchMaxOrdre(): int
    {
        $sql = 'SELECT MAX(ordre) max_ordre FROM statut_intervenant WHERE histo_destruction IS NULL';

        $res = $this->getEntityManager()->getConnection()->fetchColumn($sql, [0]);
        var_dump($res);
        $res = $this->getEntityManager()->getConnection()->fetchColumn($sql, [], 0);

        return (int)$res;
    }



    /**
     * Retourne une nouvelle entité, initialisée avec les bons paramètres
     *
Loading