diff --git a/data/ddl/table/TAG.php b/data/ddl/table/TAG.php index 75860272c58bb358db7421be029992a7dfc7b26b..9a5f43d3de5e542b6b478dfd8cc39bb7e6697655 100644 --- a/data/ddl/table/TAG.php +++ b/data/ddl/table/TAG.php @@ -129,6 +129,30 @@ return [ 'position' => 4, 'commentaire' => NULL, ], + 'DATE_DEBUT' => [ + 'name' => 'DATE_DEBUT', + 'type' => 'date', + 'bdd-type' => 'DATE', + 'length' => 0, + 'scale' => NULL, + 'precision' => NULL, + 'nullable' => TRUE, + 'default' => NULL, + 'position' => 11, + 'commentaire' => NULL, + ], + 'DATE_FIN' => [ + 'name' => 'DATE_FIN', + 'type' => 'date', + 'bdd-type' => 'DATE', + 'length' => 0, + 'scale' => NULL, + 'precision' => NULL, + 'nullable' => TRUE, + 'default' => NULL, + 'position' => 12, + 'commentaire' => NULL, + ], ], ]; diff --git a/module/Application/config/tag.config.php b/module/Application/config/tag.config.php index ff64c29cca234f6e7050f5018f9ddf4205dea0e8..bca191af1452eec61f5e8bcc61d14a3b608cbea8 100644 --- a/module/Application/config/tag.config.php +++ b/module/Application/config/tag.config.php @@ -2,6 +2,8 @@ namespace Application; +use Application\Form\Tag\TagSaisieForm; +use Application\Form\Tag\TagSaisieFormFactory; use Application\Provider\Privilege\Privileges; use UnicaenPrivilege\Guard\PrivilegeController; @@ -100,9 +102,10 @@ return [ ], 'view_helpers' => [ ], - 'form_elements' => [ - 'invokables' => [ - Form\Tag\TagSaisieForm::class => Form\Tag\TagSaisieForm::class, - ], + + + 'forms' => [ + TagSaisieForm::class => TagSaisieFormFactory::class, ], + ]; diff --git a/module/Application/src/Controller/TagController.php b/module/Application/src/Controller/TagController.php index 9fad948bd8c3c54b4769c757735b8145a14fc781..218dc65ccccb9fff3dd49d519fdeb4b17fa5f8bb 100644 --- a/module/Application/src/Controller/TagController.php +++ b/module/Application/src/Controller/TagController.php @@ -3,7 +3,7 @@ namespace Application\Controller; use Application\Entity\Db\Tag; -use Application\Form\Tag\Traits\TagSaisieFormAwareTrait; +use Application\Form\Tag\TagSaisieFormAwareTrait; use Application\Service\Traits\TagServiceAwareTrait; use UnicaenApp\View\Model\MessengerViewModel; @@ -13,7 +13,7 @@ class TagController extends AbstractController use TagSaisieFormAwareTrait; - public function indexAction() + public function indexAction () { $this->em()->getFilters()->enable('historique')->init([ Tag::class, @@ -25,19 +25,21 @@ class TagController extends AbstractController } - public function saisirAction() + + public function saisirAction () { /* @var $tag Tag */ - $tag = $this->getEvent()->getParam('tag'); + $tag = $this->getEvent()->getParam('tag'); + $form = $this->getFormTag(); - $form = $this->getFormTagSaisie(); if (empty($tag)) { $title = 'Création d\'un nouveau tag'; - $tag = $this->getServiceTag()->newEntity(); + $tag = $this->getServiceTag()->newEntity(); } else { $title = 'Édition d\'un tag'; } + $form->bindRequestSave($tag, $this->getRequest(), function (Tag $tag) { try { $this->getServiceTag()->save($tag); @@ -51,7 +53,8 @@ class TagController extends AbstractController } - public function supprimerAction() + + public function supprimerAction () { $tag = $this->getEvent()->getParam('tag'); diff --git a/module/Application/src/Entity/Db/Mapping/Application.Entity.Db.Tag.dcm.xml b/module/Application/src/Entity/Db/Mapping/Application.Entity.Db.Tag.dcm.xml index 690e2b4f1ec06e036cc41e324d50082bb2a08056..1ab73fc243a921f1a93339f6687d60f690ccd0ae 100755 --- a/module/Application/src/Entity/Db/Mapping/Application.Entity.Db.Tag.dcm.xml +++ b/module/Application/src/Entity/Db/Mapping/Application.Entity.Db.Tag.dcm.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> -<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +<doctrine-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity name="Application\Entity\Db\Tag" table="TAG"> <indexes> @@ -17,6 +17,9 @@ <field name="histoModification" type="datetime" column="HISTO_MODIFICATION" nullable="false"/> <field name="libelleCourt" type="string" column="LIBELLE_COURT" length="50" nullable="false"/> <field name="libelleLong" type="string" column="LIBELLE_LONG" length="200" nullable="false"/> + <field name="dateDebut" type="datetime" column="DATE_DEBUT" nullable="false"/> + <field name="dateFin" type="datetime" column="DATE_FIN" nullable="false"/> + <many-to-one field="histoModificateur" target-entity="Application\Entity\Db\Utilisateur"> <join-columns> <join-column name="HISTO_MODIFICATEUR_ID" referenced-column-name="ID"/> diff --git a/module/Application/src/Entity/Db/Tag.php b/module/Application/src/Entity/Db/Tag.php index b13abc133646d1e414297ebb4cc037c11437767f..abdfb9f4689876d7341e69eafa858b3106ff3838 100755 --- a/module/Application/src/Entity/Db/Tag.php +++ b/module/Application/src/Entity/Db/Tag.php @@ -2,6 +2,7 @@ namespace Application\Entity\Db; +use Laminas\Validator\Date; use UnicaenApp\Entity\HistoriqueAwareInterface; use UnicaenApp\Entity\HistoriqueAwareTrait; @@ -9,28 +10,35 @@ class Tag implements HistoriqueAwareInterface { use HistoriqueAwareTrait; - protected ?int $id = null; + protected ?int $id = null; - protected ?string $code = null; + protected ?string $code = null; - protected ?string $libelleCourt = null; + protected ?string $libelleCourt = null; - protected ?string $libelleLong = null; + protected ?string $libelleLong = null; + private ?\DateTime $dateDebut = null; - public function getId(): ?int + private ?\DateTime $dateFin = null; + + + + public function getId (): ?int { return $this->id; } - public function getCode(): ?string + + public function getCode (): ?string { return $this->code; } - public function setCode(?string $code): Tag + + public function setCode (?string $code): Tag { $this->code = $code; @@ -38,13 +46,38 @@ class Tag implements HistoriqueAwareInterface } - public function getLibelleCourt(): ?string + + public function __toString (): string + { + return $this->getLibelleLong() ? : $this->getLibelleCourt(); + } + + + + public function getLibelleLong (): ?string + { + return $this->libelleLong; + } + + + + public function setLibelleLong (?string $libelleLong): Tag + { + $this->libelleLong = $libelleLong; + + return $this; + } + + + + public function getLibelleCourt (): ?string { return $this->libelleCourt; } - public function setLibelleCourt(?string $libelleCourt): Tag + + public function setLibelleCourt (?string $libelleCourt): Tag { $this->libelleCourt = $libelleCourt; @@ -52,22 +85,35 @@ class Tag implements HistoriqueAwareInterface } - public function getLibelleLong(): ?string + + public function getDateDebut (): ?\DateTime { - return $this->libelleLong; + return $this->dateDebut; } - public function setLibelleLong(?string $libelleLong): Tag + + public function setDateDebut (?\DateTime $dateDebut): Tag { - $this->libelleLong = $libelleLong; + $this->dateDebut = $dateDebut; return $this; } - public function __toString(): string + + public function getDateFin (): ?\DateTime { - return $this->getLibelleLong() ?: $this->getLibelleCourt(); + return $this->dateFin; } + + + + public function setDateFin (?\DateTime $dateFin): Tag + { + $this->dateFin = $dateFin; + + return $this; + } + } diff --git a/module/Application/src/Form/Tag/TagSaisieForm.php b/module/Application/src/Form/Tag/TagSaisieForm.php index 64d6e8c934a35e9d38babf2a0b629fbb4ac18d36..980ec182d710094c15109372c6ac931716f9f7e6 100644 --- a/module/Application/src/Form/Tag/TagSaisieForm.php +++ b/module/Application/src/Form/Tag/TagSaisieForm.php @@ -4,6 +4,7 @@ namespace Application\Form\Tag; use Application\Entity\Db\Tag; use Application\Form\AbstractForm; +use Application\Service\Traits\AnneeServiceAwareTrait; /** * Description of TagSaisieForm @@ -12,14 +13,22 @@ use Application\Form\AbstractForm; */ class TagSaisieForm extends AbstractForm { + use AnneeServiceAwareTrait; - public function init() + public function init () { $this->spec(Tag::class); + + $this->build(); - $this->get('libelleCourt')->setLabel('Libellé court'); - $this->get('libelleLong')->setLabel('Libellé long'); + $this->setLabels([ + 'libelleCourt' => 'Libellé court', + 'libelleLong' => 'Libellé long', + 'dateDebut' => 'A partir de', + 'dateFin' => 'jusqu\'à', + + ]); $this->addSecurity(); $this->addSubmit(); diff --git a/module/Application/src/Form/Tag/TagSaisieFormAwareTrait.php b/module/Application/src/Form/Tag/TagSaisieFormAwareTrait.php new file mode 100644 index 0000000000000000000000000000000000000000..bd93527b61048f98898de6a249be0f8befaf6a96 --- /dev/null +++ b/module/Application/src/Form/Tag/TagSaisieFormAwareTrait.php @@ -0,0 +1,38 @@ +<?php + +namespace Application\Form\Tag; + + +/** + * Description of TagSaisieFormAwareTrait + * + */ +trait TagSaisieFormAwareTrait +{ + protected ?TagSaisieForm $formTag = null; + + + + public function getFormTag (): ?TagSaisieForm + { + if (!empty($this->formTag)) { + return $this->formTag; + } + + return \Application::$container->get('FormElementManager')->get(TagSaisieForm::class); + } + + + + /** + * @param TagSaisieForm $formTag + * + * @return self + */ + public function setFormTag (?TagSaisieForm $formTag) + { + $this->formTag = $formTag; + + return $this; + } +} \ No newline at end of file diff --git a/module/Application/src/Form/Tag/TagSaisieFormFactory.php b/module/Application/src/Form/Tag/TagSaisieFormFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..fa9d89edc3cc3aa929505a0c887533e4ddc2511d --- /dev/null +++ b/module/Application/src/Form/Tag/TagSaisieFormFactory.php @@ -0,0 +1,31 @@ +<?php + +namespace Application\Form\Tag; + +use Psr\Container\ContainerInterface; + + +/** + * Description of TagSaisieFormFactory + * + * @author Antony Le Courtes <antony.lecourtes at unicaen.fr> + */ +class TagSaisieFormFactory +{ + + /** + * @param ContainerInterface $container + * @param string $requestedName + * @param array|null $options + * + * @return TagSaisieForm + */ + public function __invoke (ContainerInterface $container, $requestedName, $options = null): TagSaisieForm + { + $form = new TagSaisieForm(); + + /* Injectez vos dépendances ICI */ + + return $form; + } +} \ No newline at end of file diff --git a/module/Application/src/Form/Tag/Traits/TagSaisieFormAwareTrait.php b/module/Application/src/Form/Tag/Traits/TagSaisieFormAwareTrait.php deleted file mode 100755 index a4b18d993f8d46b239f785bfb72d9e1dc186bebc..0000000000000000000000000000000000000000 --- a/module/Application/src/Form/Tag/Traits/TagSaisieFormAwareTrait.php +++ /dev/null @@ -1,39 +0,0 @@ -<?php - -namespace Application\Form\Tag\Traits; - -use Application\Entity\Db\Tag; -use Application\Form\Tag\TagSaisieForm; - -/** - * Description of TagSaisieFormAwareTrait - * - * @author Antony Le Courtes <antony.lecourtes at unicaen.fr> - */ -trait TagSaisieFormAwareTrait -{ - protected ?TagSaisieForm $formTagSaisie = null; - - - /** - * @param TagSaisieForm $formTagSaisie - * - * @return self - */ - public function setFormTagSaisie(?TagSaisieForm $formTagSaisie) - { - $this->formTagSaisie = $formTagSaisie; - - return $this; - } - - - public function getFormTagSaisie(): ?TagSaisieForm - { - if (!empty($this->formTagSaisie)) { - return $this->formTagSaisie; - } - - return \Application::$container->get('FormElementManager')->get(TagSaisieForm::class); - } -} \ No newline at end of file diff --git a/module/Application/src/Service/TagService.php b/module/Application/src/Service/TagService.php index 1510a41b5aea7f60911b95657f406a244230dd3f..814bd09b55f83fae1cd588affc04fcf2a2088fb9 100755 --- a/module/Application/src/Service/TagService.php +++ b/module/Application/src/Service/TagService.php @@ -4,6 +4,7 @@ namespace Application\Service; use Application\Entity\Db\Tag; use Doctrine\ORM\QueryBuilder; +use Laminas\Validator\Date; /** * Description of TagService @@ -19,32 +20,50 @@ class TagService extends AbstractEntityService * @return string * @throws RuntimeException */ - public function getEntityClass() + public function getEntityClass () { return Tag::class; } + + /** * Retourne l'alias d'entité courante * * @return string */ - public function getAlias() + public function getAlias () { return 'tag'; } + + + public function getListByDate (QueryBuilder $qb = null, $alias = null) + { + [$qb, $alias] = $this->initQuery($qb, $alias); + $qb->andWhere("$alias.histoDestruction is Null"); + $qb->andWhere("CURRENT_TIMESTAMP() BETWEEN $alias.dateDebut AND $alias.dateFin"); + $qb->addOrderBy("$alias.libelleLong"); + + return parent::getList($qb, $alias); + } + + + /** * Retourne la liste des tags * * @param QueryBuilder|null $queryBuilder + * * @return Tag[] */ - public function getList(QueryBuilder $qb = null, $alias = null) + public function getList (QueryBuilder $qb = null, $alias = null) { - list($qb, $alias) = $this->initQuery($qb, $alias); + [$qb, $alias] = $this->initQuery($qb, $alias); $qb->andWhere("$alias.histoDestruction is Null"); $qb->addOrderBy("$alias.libelleLong"); + return parent::getList($qb, $alias); } } \ No newline at end of file diff --git a/module/Application/view/application/tag/index.phtml b/module/Application/view/application/tag/index.phtml index 5444d28f1c1961393f09d80e0e7a546ffd6732c3..04d3e2e9c8af2949b88a4ce54d899111926a2aed 100644 --- a/module/Application/view/application/tag/index.phtml +++ b/module/Application/view/application/tag/index.phtml @@ -2,6 +2,7 @@ /** * @var $this \Application\View\Renderer\PhpRenderer * @var $motifNonPaiements \Paiement\Entity\Db\MotifNonPaiement[] + * @var $fr \Application\Entity\Db\Tag */ use Application\Provider\Privilege\Privileges; @@ -20,6 +21,8 @@ $canEdit = $this->isAllowed(Privileges::getResourceId(Privileges::MOTIF_NON_PAIE <th style="word-wrap: break-word ; ">Code</th> <th style="word-wrap: break-word ; ">Libelle Court</th> <th style="word-wrap: break-word ; ">Libelle Long</th> + <th style="word-wrap: break-word ; ">A partir de</th> + <th style="word-wrap: break-word ; ">Jusqu'à</th> <?php if ($canEdit) echo '<th>Actions</th>' ?> </thead> <tbody> @@ -28,6 +31,8 @@ $canEdit = $this->isAllowed(Privileges::getResourceId(Privileges::MOTIF_NON_PAIE <td style="word-wrap: break-word ; "><?= $fr->getCode() ?></td> <td style="word-wrap: break-word ; "><?= $fr->getLibelleCourt() ?></td> <td style="word-wrap: break-word ; "><?= $fr->getLibelleLong() ?></td> + <td style="word-wrap: break-word ; "><?= ($fr->getDateDebut() instanceof DateTime) ? $fr->getDateDebut()->format('d-m-Y') : '' ?></td> + <td style="word-wrap: break-word ; "><?= ($fr->getDateFin() instanceof DateTime) ? $fr->getDateFin()->format('d-m-Y') : '' ?></td> <?php if ($canEdit) { ?> <td style="text-align:center;width:1px;white-space: nowrap"> <a class="mod-ajax" data-submit-reload="true" diff --git a/module/Enseignement/src/Form/VolumeHoraireSaisieCalendaireForm.php b/module/Enseignement/src/Form/VolumeHoraireSaisieCalendaireForm.php index 580e83782ad23113703bac09a272214f7f0cc77f..85fdc2567b1b54bfa4e08ac1926dcdb983a8e1b6 100644 --- a/module/Enseignement/src/Form/VolumeHoraireSaisieCalendaireForm.php +++ b/module/Enseignement/src/Form/VolumeHoraireSaisieCalendaireForm.php @@ -49,42 +49,8 @@ class VolumeHoraireSaisieCalendaireForm extends AbstractForm protected $editTag = false; - /** - * @return MotifNonPaiement[] - */ - protected function getMotifsNonPaiement() - { - $qb = $this->getServiceMotifNonPaiement()->finderByHistorique(); - - return $this->getServiceMotifNonPaiement()->getList($qb); - } - - /** - * @return TypeIntervention[] - */ - protected function getTypesIntervention() - { - $qb = $this->getServiceTypeIntervention()->finderByContext(); - $this->getServiceTypeIntervention()->finderByHistorique($qb); - - return $this->getServiceTypeIntervention()->getList($qb); - } - - - /** - * @return Periode[] - */ - protected function getPeriodes() - { - $qb = $this->getServicePeriode()->finderByHistorique(); - $this->getServicePeriode()->finderByEnseignement($qb); - - return $this->getServicePeriode()->getList($qb); - } - - - public function build() + public function build () { $this->setAttributes([ 'action' => $this->getCurrentUrl(), @@ -180,7 +146,7 @@ class VolumeHoraireSaisieCalendaireForm extends AbstractForm 'options' => [ 'label' => "Tag :", 'empty_option' => "Aucun tag", - 'value_options' => Util::collectionAsOptions($this->getServiceTag()->getList()), + 'value_options' => Util::collectionAsOptions($this->getServiceTag()->getListByDate()), 'disable_inarray_validator' => true, ], @@ -228,74 +194,119 @@ class VolumeHoraireSaisieCalendaireForm extends AbstractForm } + /** - * @return bool + * @return Periode[] */ - public function canViewMNP(): bool + protected function getPeriodes () { - return $this->viewMNP; + $qb = $this->getServicePeriode()->finderByHistorique(); + $this->getServicePeriode()->finderByEnseignement($qb); + + return $this->getServicePeriode()->getList($qb); } + /** - * @param bool $viewMNP - * - * @return SaisieCalendaire + * @return TypeIntervention[] */ - public function setViewMNP(bool $viewMNP): self + protected function getTypesIntervention () { - $this->viewMNP = $viewMNP; + $qb = $this->getServiceTypeIntervention()->finderByContext(); + $this->getServiceTypeIntervention()->finderByHistorique($qb); - return $this; + return $this->getServiceTypeIntervention()->getList($qb); } + /** * @return bool */ - public function canEditMNP(): bool + public function canEditMNP (): bool { return $this->editMNP; } + + /** + * @return MotifNonPaiement[] + */ + protected function getMotifsNonPaiement () + { + $qb = $this->getServiceMotifNonPaiement()->finderByHistorique(); + + return $this->getServiceMotifNonPaiement()->getList($qb); + } + + + /** * @return bool */ - public function canViewTag(): bool + public function canEditTag (): bool { - return $this->viewTag; + return $this->editTag; } + /** - * @param bool $viewTag + * @return bool + */ + public function canViewMNP (): bool + { + return $this->viewMNP; + } + + + + /** + * @param bool $viewMNP * - * @return Saisie + * @return SaisieCalendaire */ - public function setViewTag(bool $viewTag): self + public function setViewMNP (bool $viewMNP): self { - $this->viewTag = $viewTag; + $this->viewMNP = $viewMNP; return $this; } + /** * @return bool */ - public function canEditTag(): bool + public function canViewTag (): bool { - return $this->editTag; + return $this->viewTag; } + + /** + * @param bool $viewTag + * + * @return Saisie + */ + public function setViewTag (bool $viewTag): self + { + $this->viewTag = $viewTag; + + return $this; + } + + + /** * @param bool $editTag * * @return Saisie */ - public function setEditTag(bool $editTag): self + public function setEditTag (bool $editTag): self { $this->editTag = $editTag; @@ -303,12 +314,13 @@ class VolumeHoraireSaisieCalendaireForm extends AbstractForm } + /** * @param bool $editMNP * * @return SaisieCalendaire */ - public function setEditMNP(bool $editMNP): self + public function setEditMNP (bool $editMNP): self { $this->editMNP = $editMNP; @@ -316,13 +328,14 @@ class VolumeHoraireSaisieCalendaireForm extends AbstractForm } + /** * Should return an array specification compatible with * {@link Laminas\InputFilter\Factory::createInputFilter()}. * * @return array */ - public function getInputFilterSpecification() + public function getInputFilterSpecification () { return [ 'horaire-debut' => [ @@ -331,24 +344,24 @@ class VolumeHoraireSaisieCalendaireForm extends AbstractForm 'horaire-fin' => [ 'required' => true, 'validators' => [[ - 'name' => 'Callback', - 'options' => [ - 'messages' => [ - \Laminas\Validator\Callback::INVALID_VALUE => 'L\'horaire de fin doit être ultérieur à l\'horaire de début', - ], - 'callback' => function ($value, $context = []) { - if (!$context['horaire-debut'] && $context['horaire-fin']) return true; // pas d'horaires de saisis - - $horaireDebut = DateTimeFromString::run($context['horaire-debut']); - $horaireFin = DateTimeFromString::run($context['horaire-fin']); - $deb = $horaireDebut->getTimestamp(); - $fin = $horaireFin->getTimestamp(); - $diff = $fin - $deb; - - return $diff >= 0; - }, - ], - ]], + 'name' => 'Callback', + 'options' => [ + 'messages' => [ + \Laminas\Validator\Callback::INVALID_VALUE => 'L\'horaire de fin doit être ultérieur à l\'horaire de début', + ], + 'callback' => function ($value, $context = []) { + if (!$context['horaire-debut'] && $context['horaire-fin']) return true; // pas d'horaires de saisis + + $horaireDebut = DateTimeFromString::run($context['horaire-debut']); + $horaireFin = DateTimeFromString::run($context['horaire-fin']); + $deb = $horaireDebut->getTimestamp(); + $fin = $horaireFin->getTimestamp(); + $diff = $fin - $deb; + + return $diff >= 0; + }, + ], + ]], ], 'motif-non-paiement' => [ 'required' => false, @@ -391,6 +404,9 @@ class VolumeHoraireSaisieCalendaireForm extends AbstractForm } + + + /** * * @@ -406,31 +422,16 @@ class SaisieCalendaireHydrator implements HydratorInterface private $data; - private function getVal($key) - { - if (isset($this->data[$key])) { - switch ($key) { - case 'horaire-debut': - case 'horaire-fin': - return DateTimeFromString::run($this->data[$key]); - default: - return $this->data[$key]; - } - } else { - return null; - } - } - /** * Hydrate $object with the provided $data. * - * @param array $data + * @param array $data * @param VolumeHoraireListe $object * * @return object */ - public function hydrate(array $data, $object) + public function hydrate (array $data, $object) { @@ -441,28 +442,28 @@ class SaisieCalendaireHydrator implements HydratorInterface $ancienHoraireDebut = $lfh->allToData(VolumeHoraireListe::FILTRE_HORAIRE_DEBUT, $this->getVal('ancien-horaire-debut')); - $horaireDebut = $lfh->allToData(VolumeHoraireListe::FILTRE_HORAIRE_DEBUT, $this->getVal('horaire-debut')); + $horaireDebut = $lfh->allToData(VolumeHoraireListe::FILTRE_HORAIRE_DEBUT, $this->getVal('horaire-debut')); $object->setHoraireDebut($ancienHoraireDebut != $horaireDebut ? $ancienHoraireDebut : $horaireDebut); $ancienHoraireFin = $lfh->allToData(VolumeHoraireListe::FILTRE_HORAIRE_FIN, $this->getVal('ancien-horaire-fin')); - $horaireFin = $lfh->allToData(VolumeHoraireListe::FILTRE_HORAIRE_FIN, $this->getVal('horaire-fin')); + $horaireFin = $lfh->allToData(VolumeHoraireListe::FILTRE_HORAIRE_FIN, $this->getVal('horaire-fin')); $object->setHoraireFin($ancienHoraireFin != $horaireFin ? $ancienHoraireFin : $horaireFin); $ancienTypeIntervention = $lfh->allToData(VolumeHoraireListe::FILTRE_TYPE_INTERVENTION, $this->getVal('ancien-type-intervention')); - $typeIntervention = $lfh->allToData(VolumeHoraireListe::FILTRE_TYPE_INTERVENTION, $this->getVal('type-intervention')); + $typeIntervention = $lfh->allToData(VolumeHoraireListe::FILTRE_TYPE_INTERVENTION, $this->getVal('type-intervention')); $object->setTypeIntervention($ancienTypeIntervention != $typeIntervention && $ancienTypeIntervention ? $ancienTypeIntervention : $typeIntervention); $ancienPeriode = $lfh->allToData(VolumeHoraireListe::FILTRE_PERIODE, $this->getVal('ancien-periode')); - $periode = $lfh->allToData(VolumeHoraireListe::FILTRE_PERIODE, $this->getVal('periode')); + $periode = $lfh->allToData(VolumeHoraireListe::FILTRE_PERIODE, $this->getVal('periode')); $object->setPeriode($ancienPeriode != $periode && $ancienPeriode ? $ancienPeriode : $periode); $ancienMotifNonPaiement = $lfh->allToData(VolumeHoraireListe::FILTRE_MOTIF_NON_PAIEMENT, $this->getVal('ancien-motif-non-paiement')); - $motifNonPaiement = $lfh->allToData(VolumeHoraireListe::FILTRE_MOTIF_NON_PAIEMENT, $this->getVal('motif-non-paiement')); + $motifNonPaiement = $lfh->allToData(VolumeHoraireListe::FILTRE_MOTIF_NON_PAIEMENT, $this->getVal('motif-non-paiement')); $object->setMotifNonPaiement($ancienMotifNonPaiement != $motifNonPaiement && $ancienMotifNonPaiement ? $ancienMotifNonPaiement : $motifNonPaiement); $ancienTag = $lfh->allToData(VolumeHoraireListe::FILTRE_TAG, $this->getVal('ancien-tag')); - $tag = $lfh->allToData(VolumeHoraireListe::FILTRE_TAG, $this->getVal('tag')); + $tag = $lfh->allToData(VolumeHoraireListe::FILTRE_TAG, $this->getVal('tag')); $object->setTag($ancienTag != $tag && $ancienTag ? $ancienTag : $tag); $heures = (float)$this->getVal('heures'); @@ -474,6 +475,24 @@ class SaisieCalendaireHydrator implements HydratorInterface } + + private function getVal ($key) + { + if (isset($this->data[$key])) { + switch ($key) { + case 'horaire-debut': + case 'horaire-fin': + return DateTimeFromString::run($this->data[$key]); + default: + return $this->data[$key]; + } + } else { + return null; + } + } + + + /** * Extract values from an object * @@ -481,7 +500,7 @@ class SaisieCalendaireHydrator implements HydratorInterface * * @return array */ - public function extract($object): array + public function extract ($object): array { $lfh = new ListeFilterHydrator(); $lfh->setEntityManager($this->getEntityManager()); @@ -509,23 +528,19 @@ class SaisieCalendaireHydrator implements HydratorInterface /* Conversion des dates en objets */ if (isset($data['horaire-debut']) && $data['horaire-debut'] > 0) { $data['horaire-debut'] = (new \DateTime)->setTimestamp($data['horaire-debut']); - } - else{ + } else { //Pour une meilleure gestion du datetime local, si pas d'horaire de début on set à la date du jour 00:00 $now = new \DateTime(); - $now->setTime(0,0); + $now->setTime(0, 0); $data['horaire-debut'] = $now; - } if (isset($data['horaire-fin']) && $data['horaire-fin'] > 0) { $data['horaire-fin'] = (new \DateTime)->setTimestamp($data['horaire-fin']); - } - else{ + } else { //Pour une meilleure gestion du datetime local, si pas d'horaire de début on set à la date du jour 00:00 $now = new \DateTime(); - $now->setTime(0,0); + $now->setTime(0, 0); $data['horaire-fin'] = $now; - } return $data; diff --git a/module/Enseignement/src/Form/VolumeHoraireSaisieForm.php b/module/Enseignement/src/Form/VolumeHoraireSaisieForm.php index d61fa963d1a652c97da452b40c7568d055727857..a77d2e3193024e863ac8533d2a8516fb03fbea77 100755 --- a/module/Enseignement/src/Form/VolumeHoraireSaisieForm.php +++ b/module/Enseignement/src/Form/VolumeHoraireSaisieForm.php @@ -46,42 +46,8 @@ class VolumeHoraireSaisieForm extends AbstractForm protected $editTag = false; - /** - * @return MotifNonPaiement[] - */ - protected function getMotifsNonPaiement() - { - $qb = $this->getServiceMotifNonPaiement()->finderByHistorique(); - - return $this->getServiceMotifNonPaiement()->getList($qb); - } - - - /** - * @return TypeIntervention[] - */ - protected function getTypesIntervention() - { - $qb = $this->getServiceTypeIntervention()->finderByContext(); - $this->getServiceTypeIntervention()->finderByHistorique($qb); - return $this->getServiceTypeIntervention()->getList($qb); - } - - - /** - * @return Periode[] - */ - protected function getPeriodes() - { - $qb = $this->getServicePeriode()->finderByHistorique(); - $this->getServicePeriode()->finderByEnseignement($qb); - - return $this->getServicePeriode()->getList($qb); - } - - - public function build() + public function build () { $this->setAttributes([ 'action' => $this->getCurrentUrl(), @@ -133,7 +99,7 @@ class VolumeHoraireSaisieForm extends AbstractForm 'options' => [ 'label' => "Tag :", 'empty_option' => "Aucun tag", - 'value_options' => Util::collectionAsOptions($this->getServiceTag()->getList()), + 'value_options' => Util::collectionAsOptions($this->getServiceTag()->getListByDate()), ], 'attributes' => [ 'value' => "", @@ -178,64 +144,93 @@ class VolumeHoraireSaisieForm extends AbstractForm } + /** * @return bool */ - public function canViewMNP(): bool + public function canEditMNP (): bool { - return $this->viewMNP; + return $this->editMNP; } + /** - * @param bool $viewMNP - * - * @return Saisie + * @return MotifNonPaiement[] */ - public function setViewMNP(bool $viewMNP): self + protected function getMotifsNonPaiement () { - $this->viewMNP = $viewMNP; + $qb = $this->getServiceMotifNonPaiement()->finderByHistorique(); - return $this; + return $this->getServiceMotifNonPaiement()->getList($qb); } + /** * @return bool */ - public function canEditMNP(): bool + public function canEditTag (): bool { - return $this->editMNP; + return $this->editTag; + } + + + + /** + * @return bool + */ + public function canViewMNP (): bool + { + return $this->viewMNP; } + + /** + * @param bool $viewMNP + * + * @return Saisie + */ + public function setViewMNP (bool $viewMNP): self + { + $this->viewMNP = $viewMNP; + + return $this; + } + + + /** * @param bool $editMNP * * @return Saisie */ - public function setEditMNP(bool $editMNP): self + public function setEditMNP (bool $editMNP): self { $this->editMNP = $editMNP; return $this; } + + /** * @return bool */ - public function canViewTag(): bool + public function canViewTag (): bool { return $this->viewTag; } + /** * @param bool $viewTag * * @return Saisie */ - public function setViewTag(bool $viewTag): self + public function setViewTag (bool $viewTag): self { $this->viewTag = $viewTag; @@ -243,21 +238,13 @@ class VolumeHoraireSaisieForm extends AbstractForm } - /** - * @return bool - */ - public function canEditTag(): bool - { - return $this->editTag; - } - /** * @param bool $editTag * * @return Saisie */ - public function setEditTag(bool $editTag): self + public function setEditTag (bool $editTag): self { $this->editTag = $editTag; @@ -265,13 +252,14 @@ class VolumeHoraireSaisieForm extends AbstractForm } + /** * Should return an array specification compatible with * {@link Laminas\InputFilter\Factory::createInputFilter()}. * * @return array */ - public function getInputFilterSpecification() + public function getInputFilterSpecification () { return [ 'motif-non-paiement' => [ @@ -297,9 +285,38 @@ class VolumeHoraireSaisieForm extends AbstractForm ], ]; } + + + + /** + * @return TypeIntervention[] + */ + protected function getTypesIntervention () + { + $qb = $this->getServiceTypeIntervention()->finderByContext(); + $this->getServiceTypeIntervention()->finderByHistorique($qb); + + return $this->getServiceTypeIntervention()->getList($qb); + } + + + + /** + * @return Periode[] + */ + protected function getPeriodes () + { + $qb = $this->getServicePeriode()->finderByHistorique(); + $this->getServicePeriode()->finderByEnseignement($qb); + + return $this->getServicePeriode()->getList($qb); + } } + + + /** * * @@ -315,25 +332,16 @@ class SaisieHydrator implements HydratorInterface private $data; - private function getVal($key) - { - if (isset($this->data[$key])) { - return $this->data[$key]; - } else { - return null; - } - } - /** * Hydrate $object with the provided $data. * - * @param array $data + * @param array $data * @param VolumeHoraireListe $object * * @return object */ - public function hydrate(array $data, $object) + public function hydrate (array $data, $object) { @@ -349,11 +357,11 @@ class SaisieHydrator implements HydratorInterface $object->setPeriode($periode); $ancienMotifNonPaiement = $lfh->allToData(VolumeHoraireListe::FILTRE_MOTIF_NON_PAIEMENT, $this->getVal('ancien-motif-non-paiement')); - $motifNonPaiement = $lfh->allToData(VolumeHoraireListe::FILTRE_MOTIF_NON_PAIEMENT, $this->getVal('motif-non-paiement')); + $motifNonPaiement = $lfh->allToData(VolumeHoraireListe::FILTRE_MOTIF_NON_PAIEMENT, $this->getVal('motif-non-paiement')); $ancienTag = $lfh->allToData(VolumeHoraireListe::FILTRE_TAG, $this->getVal('ancien-tag')); - $tag = $lfh->allToData(VolumeHoraireListe::FILTRE_TAG, $this->getVal('tag')); - + $tag = $lfh->allToData(VolumeHoraireListe::FILTRE_TAG, $this->getVal('tag')); + $heures = (float)$this->getVal('heures'); $object->setMotifNonPaiement($motifNonPaiement); @@ -365,6 +373,18 @@ class SaisieHydrator implements HydratorInterface } + + private function getVal ($key) + { + if (isset($this->data[$key])) { + return $this->data[$key]; + } else { + return null; + } + } + + + /** * Extract values from an object * @@ -372,7 +392,7 @@ class SaisieHydrator implements HydratorInterface * * @return array */ - public function extract($object): array + public function extract ($object): array { $lfh = new ListeFilterHydrator(); $lfh->setEntityManager($this->getEntityManager());