Commit 47c7a110 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Ajout de l'ordre et de la visibilite

parent db82b59a
Loading
Loading
Loading
Loading
+44
Changes for module/Application/src/Application/Entity/Db/Information.php: 44 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ use UnicaenApp\Entity\HistoriqueAwareTrait;
class Information implements HistoriqueAwareInterface
{
    use HistoriqueAwareTrait;
    const DEFAULT_PRIORITE = 0;

    /** @var integer */
    private $id;
@@ -23,6 +24,11 @@ class Information implements HistoriqueAwareInterface
    /** @var string */
    private $contenu;

    /** @var  integer*/
    private $priorite;
    /** @var boolean */
    private $visible;

    /**
     * @return int
     */
@@ -67,4 +73,42 @@ class Information implements HistoriqueAwareInterface
        $this->contenu = $contenu;
        return $this;
    }

    /**
     * @return int
     */
    public function getPriorite()
    {
        return $this->priorite;
    }

    /**
     * @param int $priorite
     * @return Information
     */
    public function setPriorite($priorite)
    {
        $this->priorite = $priorite;
        return $this;
    }

    /**
     * @return bool
     */
    public function isVisible()
    {
        return $this->visible;
    }

    /**
     * @param bool $visible
     * @return Information
     */
    public function setVisible($visible)
    {
        $this->visible = $visible;
        return $this;
    }


}
 No newline at end of file
+2
Changes for module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.Information.dcm.xml: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -9,6 +9,8 @@

        <field name="titre"     column="TITRE"          type="string"   length="256"    nullable="false"/>
        <field name="contenu"   column="CONTENU"        type="string"   length="10000"  nullable="false"/>
        <field name="priorite"  column="PRIORITE"       type="integer"                  nullable="false"/>
        <field name="visible"   column="EST_VISIBLE"    type="boolean"                  nullable="false"/>

        <field name="histoCreation" type="datetime" column="HISTO_CREATION" nullable="false"/>
        <field name="histoDestruction" type="datetime" column="HISTO_DESTRUCTION" nullable="true"/>
+4
Changes for module/Application/src/Application/Form/Hydrator/InformationHydrator.php: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@ class InformationHydrator implements HydratorInterface
        return [
            'titre' => $object->getTitre(),
            'contenu' => $object->getContenu(),
            'priorite' => $object->getPriorite(),
            'visible' => $object->isVisible(),
        ];
    }

@@ -29,6 +31,8 @@ class InformationHydrator implements HydratorInterface
    {
        $object->setTitre($data['titre']);
        $object->setContenu($data['contenu']);
        $object->setPriorite($data['priorite']);
        $object->setVisible( ($data['visible'] == 1)?true:false);
        return $object;
    }

+27
Changes for module/Application/src/Application/Form/InformationForm.php: 27 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
namespace Application\Form;

use Zend\Form\Element\Button;
use Zend\Form\Element\Radio;
use Zend\Form\Element\Text;
use Zend\Form\Form;

@@ -21,6 +22,31 @@ class InformationForm extends Form {
                'id' => 'titre',
            ],
        ]);
        $this->add([
            'type' => Radio::class,
            'name' => 'visible',
            'options' => [
                'label' => 'Visibilité de la page :',
                'value_options' => [
                    '1' => 'Visible',
                    '0' => 'Cachée',
                ],
                'attributes' => [
                    'class' => 'radio-inline',
                ],
            ],
        ]);
        // priorite
        $this->add([
            'type' => Text::class,
            'name' => 'priorite',
            'options' => [
                'label' => "Priorite (valeur numérique) :",
            ],
            'attributes' => [
                'id' => 'priorite',
            ],
        ]);
        // contenu
        $this->add([
            'name' => 'contenu',
@@ -36,6 +62,7 @@ class InformationForm extends Form {
                'class' => 'form-control',
            ]
        ]);

        // button
        $this->add([
            'type' => Button::class,
+11
Changes for module/Application/src/Application/Service/Information/InformationService.php: 11 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ class InformationService {
    public function getInformations()
    {
        $qb = $this->getEntityManager()->getRepository(Information::class)->createQueryBuilder('information')
            ->orderBy('information.priorite', 'DESC')
        ;

        $result = $qb->getQuery()->getResult();
@@ -50,12 +51,18 @@ class InformationService {
     */
    public function create($information)
    {
        try {
            $date = new \DateTime();
        } catch (\Exception $e) {
            throw new RuntimeException("Problème de récupération de la date lors de la création en base d'une Information", $e);
        }
        $user = $this->userContextService->getIdentityDb();
        $information->setHistoCreation($date);
        $information->setHistoCreateur($user);
        $information->setHistoModification($date);
        $information->setHistoModificateur($user);
        if ($information->getPriorite() === null) $information->setPriorite(Information::DEFAULT_PRIORITE);
        if ($information->isVisible() === null) $information->setVisible(true);
        $this->getEntityManager()->persist($information);
        try {
            $this->getEntityManager()->flush($information);
@@ -71,7 +78,11 @@ class InformationService {
     */
    public function update($information)
    {
        try {
            $date = new \DateTime();
        } catch (\Exception $e) {
            throw new RuntimeException("Problème de récupération de la date lors de la mise à jour en base d'une Information", $e);
        }
        $user = $this->userContextService->getIdentityDb();
        $information->setHistoModification($date);
        $information->setHistoModificateur($user);
Loading