From f20eff9b05a5308cf8f768d0586170921e59da75 Mon Sep 17 00:00:00 2001 From: afornerot Date: Tue, 9 Jun 2020 14:18:17 +0200 Subject: [PATCH] gestion du niveau01 autre (ref #141) --- .../CoreBundle/Controller/CoreController.php | 13 ++++++++- .../Controller/RegistrationController.php | 10 ++++++- .../CoreBundle/Controller/UserController.php | 10 ++++++- .../CoreBundle/Entity/Registration.php | 29 +++++++++++++++++++ .../src/Cadoles/CoreBundle/Entity/User.php | 29 +++++++++++++++++++ .../CoreBundle/Form/RegistrationType.php | 13 ++++++++- .../src/Cadoles/CoreBundle/Form/UserType.php | 13 ++++++++- .../views/Registration/edit.html.twig | 14 +++++++++ .../Resources/views/User/edit.html.twig | 20 +++++++++++-- 9 files changed, 143 insertions(+), 8 deletions(-) diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/CoreController.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/CoreController.php index 73e03010..e365fbed 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/CoreController.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/CoreController.php @@ -102,8 +102,19 @@ class CoreController extends Controller } } } + + // Si niveau01 commence par autre = alors niveau01other obligatoire + $message=""; + $niveau01=strtolower($user->getNiveau01()->getLabel()); + if(stripos($niveau01,"autre")===0) { + if(!$user->getNiveau01other()) { + $toprofil=true; + $message="
Merci d'indiquer votre ".$this->getParameter("labelniveau01"); + } + } + if($toprofil) { - return $this->redirect($this->generateUrl('cadoles_core_user',array("info"=>"Merci de compléter votre profil"))); + return $this->redirect($this->generateUrl('cadoles_core_user',array("info"=>"Merci de compléter votre profil".$message))); } } diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/RegistrationController.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/RegistrationController.php index bdbbf465..7e5a3a90 100755 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/RegistrationController.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/RegistrationController.php @@ -159,7 +159,7 @@ class RegistrationController extends Controller $action, $data->getUsername(), $data->getEmail(), - $data->getNiveau01()->getLabel(), + $data->getNiveau01()->getLabel()."
".$data->getNiveau01other(), $data->getStatut()->getLabel(), (is_null($data->getKeyexpire())?"":$data->getKeyexpire()->format('d/m/Y H:i:s')) )); @@ -859,6 +859,14 @@ class RegistrationController extends Controller if($this->getUserBy("username",$data->getUsername())||$this->getUserBy("email",$data->getEmail())) { $form->addError(new FormError('Un utilisateur utilise déjà ce login ou cet email')); } + + // Si niveau01 commence par autre = niveau01other obligatoire + $niveau01=strtolower($data->getNiveau01()->getLabel()); + if(stripos($niveau01,"autre")===0) { + if(!$data->getNiveau01other()) { + $form->addError(new FormError("Merci d'indiquer votre ".$this->getParameter("labelniveau01"))); + } + } } if ($form->get('submit')->isClicked() && !$form->isValid()) { diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/UserController.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/UserController.php index 5f14647d..ceb21eaf 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/UserController.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/UserController.php @@ -303,7 +303,7 @@ class UserController extends Controller array_push($tmp,$data->getFirstname()); array_push($tmp,"".$data->getEmail().""); array_push($tmp,$data->getTelephonenumber()); - array_push($tmp,$data->getNiveau01()->getLabel()); + array_push($tmp,$data->getNiveau01()->getLabel()."
".$data->getNiveau01other()); if($viewniveau02) array_push($tmp,($data->getNiveau02()!==null?$data->getNiveau02()->getLabel():"")); array_push($tmp,$groups); array_push($tmp,$data->getJob()); @@ -1262,6 +1262,14 @@ class UserController extends Controller if($this->getRegistrationBy("username",$data->getUsername())||$this->getRegistrationBy("email",$data->getEmail())) { $form->addError(new FormError('Une inscription utilise déjà ce login ou cet email')); } + + // Si niveau01 commence par autre = niveau01other obligatoire + $niveau01=strtolower($data->getNiveau01()->getLabel()); + if(stripos($niveau01,"autre")===0) { + if(!$data->getNiveau01other()) { + $form->addError(new FormError("Merci d'indiquer votre ".$this->getParameter("labelniveau01"))); + } + } } diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/Registration.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/Registration.php index 585473b2..5fb07eb6 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/Registration.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/Registration.php @@ -123,6 +123,11 @@ class Registration implements UserInterface, \Serializable */ private $position; + /** + * @ORM\Column(type="string", length=150, nullable=true) + */ + private $niveau01other; + /** * @ORM\Column(type="integer", length=60, nullable=true) */ @@ -738,4 +743,28 @@ class Registration implements UserInterface, \Serializable { return $this->groupid; } + + /** + * Set niveau01other + * + * @param string $niveau01other + * + * @return Registration + */ + public function setNiveau01other($niveau01other) + { + $this->niveau01other = $niveau01other; + + return $this; + } + + /** + * Get niveau01other + * + * @return string + */ + public function getNiveau01other() + { + return $this->niveau01other; + } } diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/User.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/User.php index ff193744..2006ebd8 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/User.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Entity/User.php @@ -173,6 +173,11 @@ class User implements UserInterface, \Serializable */ private $visitecpt; + /** + * @ORM\Column(type="string", length=150, nullable=true) + */ + private $niveau01other; + /** * @ORM\ManyToOne(targetEntity="Country", inversedBy="users") * @ORM\JoinColumn(nullable=true) @@ -1854,4 +1859,28 @@ class User implements UserInterface, \Serializable { return $this->visitecpt; } + + /** + * Set niveau01other + * + * @param string $niveau01other + * + * @return User + */ + public function setNiveau01other($niveau01other) + { + $this->niveau01other = $niveau01other; + + return $this; + } + + /** + * Get niveau01other + * + * @return string + */ + public function getNiveau01other() + { + return $this->niveau01other; + } } diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Form/RegistrationType.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Form/RegistrationType.php index 2b3e2a85..18d12520 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Form/RegistrationType.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Form/RegistrationType.php @@ -76,10 +76,21 @@ class RegistrationType extends AbstractType EntityType::class, array("class" => "CadolesCoreBundle:Niveau01", "label" => $session->get('labelniveau01'), + 'placeholder' => '== Choisir '.$session->get('labelniveau01').' ==', "choice_label" => "label", - "disabled" => ($options["mode"]=="delete"?true:false), + "disabled" => ($options["mode"]=="delete"?true:false), "attr" => array("class" => "form-control", "style" => "margin-bottom:15px","readonly" => ($options["mode"]=="delete"?true:false)))); + + $builder->add('niveau01other', + TextType::class, array( + "label" =>"Autre ".$session->get('labelniveau01'), + "disabled" => ($options["mode"]=="delete"?true:false), + "required" => false, + "attr" => array("class" => "form-control", "style" => "margin-bottom:15px") + ) + ); + # Password if($options["mode"]!="delete"&&$options["mode"]!="send") { $builder->add('password', diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Form/UserType.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Form/UserType.php index 6820d2c5..a787af90 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Form/UserType.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Form/UserType.php @@ -84,6 +84,7 @@ class UserType extends AbstractType EntityType::class, array("class" => "CadolesCoreBundle:Niveau01", "label" => $session->get('labelniveau01'), + 'placeholder' => '== Choisir '.$session->get('labelniveau01').' ==', "choice_label" => "label", "query_builder"=> function (EntityRepository $er) use($access,$perm,$userid) { if($access=="config") { @@ -102,7 +103,17 @@ class UserType extends AbstractType }, "disabled" => ($options["mode"]=="delete"||$options["masteridentity"]!="SQL"?true:false), "attr" => array("class" => "form-control", "style" => "margin-bottom:15px","readonly" => ($options["mode"]=="delete"?true:false)))); - + + + $builder->add('niveau01other', + TextType::class, array( + "label" =>"Autre ".$session->get('labelniveau01'), + "disabled" => ($options["mode"]=="delete"?true:false), + "required" => false, + "attr" => array("class" => "form-control", "style" => "margin-bottom:15px") + ) + ); + if($options["mode"]!="delete"&&$options["masteridentity"]=="SQL") { $builder->add('password', RepeatedType::class, array( diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Registration/edit.html.twig b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Registration/edit.html.twig index 53ca6ac7..aec4396a 100755 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Registration/edit.html.twig +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/Registration/edit.html.twig @@ -105,6 +105,7 @@ {% if form.job is defined %} {{ form_row(form.job) }} {% endif %} {% if form.position is defined %} {{ form_row(form.position) }} {% endif %} {{ form_row(form.niveau01) }} +
{{ form_row(form.niveau01other) }}
{% if form.niveau02 is defined %} {{ form_row(form.niveau02) }} {% endif %} @@ -164,6 +165,10 @@ hideshow(); }); + $(document.body).on("change","#registration_niveau01",function(){ + hideshow(); + }); + $(document.body).on("change","#registration_niveau02",function(){ $.ajax({ method: "POST", @@ -188,6 +193,15 @@ $("#blockcity").hide(); $("#registration_birthplace").val([]).trigger('change'); } + + niveau01=$("#registration_niveau01 option:selected").text().toLowerCase(); + if(niveau01.startsWith("autre")) { + $("#niveau01other").show(); + } + else { + $("#registration_niveau01other").val(""); + $("#niveau01other").hide(); + } } $(document).ready(function() { diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/User/edit.html.twig b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/User/edit.html.twig index 8eeb71e6..fdb53bce 100755 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/User/edit.html.twig +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/views/User/edit.html.twig @@ -27,7 +27,7 @@
Erreur
{% for flashMessage in app.session.flashbag.get('error') %} - {{ flashMessage }}
+ {{ flashMessage | raw }}
{% endfor %}

@@ -37,7 +37,7 @@
Information
{% for flashMessage in app.session.flashbag.get('notice') %} - {{ flashMessage }}
+ {{ flashMessage | raw }}
{% endfor %}

@@ -46,7 +46,7 @@ {% if info is defined and info %}
Information
- {{ info }}
+ {{ info | raw }}

{% endif %} @@ -114,6 +114,7 @@ {% if form.job is defined %}{{ form_row(form.job) }}{% endif %} {% if form.position is defined %}{{ form_row(form.position) }}{% endif %} {{ form_row(form.niveau01) }} +
{{ form_row(form.niveau01other) }}
{% if form.niveau02 is defined %}{{ form_row(form.niveau02) }}{% endif %} @@ -418,6 +419,10 @@ hideshow(); }); + $(document.body).on("change","#user_niveau01",function(){ + hideshow(); + }); + $(document.body).on("change","#user_niveau02",function(){ $.ajax({ method: "POST", @@ -449,6 +454,15 @@ else { $("#panelmodos").hide(); } + + niveau01=$("#user_niveau01 option:selected").text().toLowerCase(); + if(niveau01.startsWith("autre")) { + $("#niveau01other").show(); + } + else { + $("#user_niveau01other").val(""); + $("#niveau01other").hide(); + } }