Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- in srcBackendBundleFormEventListenerAddProvinceFieldSubscriber.php (line 56)
- 54) $accessor = PropertyAccess::createPropertyAccessor();
- 55) $municipio = $accessor->getValue($data, $this->propertyPathToMunicipio);
- 56) $provincia = ($municipio) ? $municipio->getIdMunicipio()->getProvincia() : null;
- 57) $this->addProvinceForm($form, $provincia); }
- class InscritosType extends AbstractType {
- /**
- * {@inheritdoc}
- */
- public function buildForm(FormBuilderInterface $builder, array $options) {
- $builder
- ->add('nombreUsuario', TextType::class, array("label" => "Nombre: ",
- "required" => "required",
- "attr" => array("class" => "form-name form-control col-sm-4 col-md-3"))) ;
- $builder->addEventSubscriber(new AddProvinceFieldSubscriber('idMunicipio'));
- $builder->addEventSubscriber(new AddMunicipioFieldSubscriber('idMunicipio'));
- }
- //AddMunicipioFieldSubscriber
- namespace BackendBundleFormEventListener;
- use BackendBundleEntityMunicipios;
- use SymfonyComponentEventDispatcherEventSubscriberInterface;
- use SymfonyComponentFormFormEvents;
- use SymfonyComponentFormFormEvent;
- use SymfonyComponentPropertyAccessPropertyAccess;
- use SymfonyBridgeDoctrineFormTypeEntityType;
- use DoctrineORMEntityRepository;
- class AddMunicipioFieldSubscriber implements EventSubscriberInterface {
- private $propertyPathToMunicipio;
- public function __construct($propertyPathToMunicipio) {
- $this->propertyPathToMunicipio = $propertyPathToMunicipio;
- }
- public static function getSubscribedEvents() {
- return array(
- FormEvents::PRE_SET_DATA => 'preSetData',
- FormEvents::PRE_SUBMIT => 'preSubmit'
- );
- }
- private function addCityForm($form, $province_id) {
- $formOptions = array(
- 'class' => 'BackendBundle:Municipios',
- 'label' => 'Municipio',
- "required" => "required",
- 'attr' => array(
- 'class' => 'form-name form-control class_select_municipio',
- ),
- 'query_builder' => function (EntityRepository $repository) use ($province_id) {
- $qb = $repository->createQueryBuilder('municipios')
- ->innerJoin('municipios.idProvincia', 'provincia')
- ->where('provincia.id = :provincia')
- ->setParameter('provincia', $province_id)
- ;
- return $qb;
- }
- );
- $form->add($this->propertyPathToMunicipio, EntityType::class, $formOptions);
- }
- public function preSetData(FormEvent $event) {
- $data = $event->getData();
- $form = $event->getForm();
- if (null === $data) {
- return;
- }
- $accessor = PropertyAccess::createPropertyAccessor();
- $municipios = $accessor->getValue($data, $this->propertyPathToMunicipio);
- $province_id = ($municipios) ? $municipios->getIdMunicipio()->getProvincia()->getId() : null;
- $this->addCityForm($form, $province_id);
- }
- public function preSubmit(FormEvent $event) {
- $data = $event->getData();
- $form = $event->getForm();
- $province_id = array_key_exists('provincia', $data) ? $data['provincia'] : null;
- $this->addCityForm($form, $province_id);
- }
- }
- //AddProvinceFieldSubscriber
- namespace BackendBundleFormEventListener;
- use SymfonyComponentEventDispatcherEventSubscriberInterface;
- use SymfonyComponentFormFormEvents;
- use SymfonyComponentFormFormEvent;
- use SymfonyComponentPropertyAccessPropertyAccess;
- use SymfonyBridgeDoctrineFormTypeEntityType;
- use BackendBundleEntityProvincia;
- use DoctrineORMEntityRepository;
- class AddProvinceFieldSubscriber implements EventSubscriberInterface {
- private $propertyPathToMunicipio;
- public function __construct($propertyPathToMunicipio) {
- $this->propertyPathToMunicipio = $propertyPathToMunicipio;
- }
- public static function getSubscribedEvents() {
- return array(
- FormEvents::PRE_SET_DATA => 'preSetData',
- FormEvents::PRE_SUBMIT => 'preSubmit'
- );
- }
- private function addProvinceForm($form, $Province = null) {
- $formOptions = array(
- 'class' => 'BackendBundle:Provincia',
- 'mapped' => false,
- "required" => "required",
- 'label' => 'Provincia',
- 'attr' => array(
- 'class' => 'form-name form-control class_select_provincia',
- ),
- );
- if ($Province) {
- $formOptions['data'] = $Province;
- }
- $form->add('provincia', EntityType::class, $formOptions);
- }
- public function preSetData(FormEvent $event) {
- $data = $event->getData();
- $form = $event->getForm();
- if (null === $data) {
- return;
- }
- $accessor = PropertyAccess::createPropertyAccessor();
- $municipio = $accessor->getValue($data, $this->propertyPathToMunicipio);
- $provincia = ($municipio) ? $municipio->getIdMunicipio()->getProvincia() : null;
- $this->addProvinceForm($form, $provincia);
- }
- public function preSubmit(FormEvent $event) {
- $form = $event->getForm();
- $this->addProvinceForm($form);
- }
- }
- namespace BackendBundleEntity;
- /**
- * Municipios
- */
- class Municipios
- {
- /**
- * @var integer
- */
- private $idMunicipio;
- /**
- * @var integer
- */
- private $codMunicipio;
- /**
- * @var integer
- */
- private $dc;
- /**
- * @var string
- */
- private $nombre = '';
- /**
- * @var DoctrineCommonCollectionsCollection
- */
- private $userMunicipio;
- /**
- * @var DoctrineCommonCollectionsCollection
- */
- private $inscritosMunicipio;
- /**
- * @var BackendBundleEntityProvincia
- */
- /**
- * @ORMManyToOne(targetEntity="BackendBundleEntityProvincia", inversedBy="municipio")
- * @ORMJoinColumn(name="municipio_id", referencedColumnName="id")
- * @AssertNotBlank
- */
- private $idProvincia;
- /**
- * Constructor
- */
- public function __construct()
- {
- $this->userMunicipio = new DoctrineCommonCollectionsArrayCollection();
- $this->inscritosMunicipio = new DoctrineCommonCollectionsArrayCollection();
- $this->idMunicipio= new DoctrineCommonCollectionsArrayCollection;
- $this->idProvincia= new DoctrineCommonCollectionsArrayCollection;
- }
- public function __toString() {
- // return strval($this->idCcaa);
- return $this->nombre;
- }
- /**
- * Set idMunicipio
- *
- * @param integer $idMunicipio
- *
- * @return Municipios
- */
- public function setIdMunicipio($idMunicipio)
- {
- $this->idMunicipio = $idMunicipio;
- return $this;
- }
- /**
- * Get idMunicipio
- *
- * @return integer
- */
- public function getIdMunicipio()
- {
- return $this->idMunicipio;
- }
- /**
- * Set codMunicipio
- *
- * @param integer $codMunicipio
- *
- * @return Municipios
- */
- public function setCodMunicipio($codMunicipio)
- {
- $this->codMunicipio = $codMunicipio;
- return $this;
- }
- /**
- * Get codMunicipio
- *
- * @return integer
- */
- public function getCodMunicipio()
- {
- return $this->codMunicipio;
- }
- /**
- * Set dc
- *
- * @param integer $dc
- *
- * @return Municipios
- */
- public function setDc($dc)
- {
- $this->dc = $dc;
- return $this;
- }
- /**
- * Get dc
- *
- * @return integer
- */
- public function getDc()
- {
- return $this->dc;
- }
- /**
- * Set nombre
- *
- * @param string $nombre
- *
- * @return Municipios
- */
- public function setNombre($nombre)
- {
- $this->nombre = $nombre;
- return $this;
- }
- /**
- * Get nombre
- *
- * @return string
- */
- public function getNombre()
- {
- return $this->nombre;
- }
- /**
- * Add userMunicipio
- *
- * @param BackendBundleEntityUsers $userMunicipio
- *
- * @return Municipios
- */
- public function addUserMunicipio(BackendBundleEntityUsers $userMunicipio)
- {
- $this->userMunicipio[] = $userMunicipio;
- return $this;
- }
- /**
- * Remove userMunicipio
- *
- * @param BackendBundleEntityUsers $userMunicipio
- */
- public function removeUserMunicipio(BackendBundleEntityUsers $userMunicipio)
- {
- $this->userMunicipio->removeElement($userMunicipio);
- }
- /**
- * Get userMunicipio
- *
- * @return DoctrineCommonCollectionsCollection
- */
- public function getUserMunicipio()
- {
- return $this->userMunicipio;
- }
- /**
- * Add inscritosMunicipio
- *
- * @param BackendBundleEntityInscritos $inscritosMunicipio
- *
- * @return Municipios
- */
- public function addInscritosMunicipio(BackendBundleEntityInscritos $inscritosMunicipio)
- {
- $this->inscritosMunicipio[] = $inscritosMunicipio;
- return $this;
- }
- /**
- * Remove inscritosMunicipio
- *
- * @param BackendBundleEntityInscritos $inscritosMunicipio
- */
- public function removeInscritosMunicipio(BackendBundleEntityInscritos $inscritosMunicipio)
- {
- $this->inscritosMunicipio->removeElement($inscritosMunicipio);
- }
- /**
- * Get inscritosMunicipio
- *
- * @return DoctrineCommonCollectionsCollection
- */
- public function getInscritosMunicipio()
- {
- return $this->inscritosMunicipio;
- }
- /**
- * Set idProvincia
- *
- * @param BackendBundleEntityProvincia $idProvincia
- *
- * @return Municipios
- */
- public function setIdProvincia(BackendBundleEntityProvincia $idProvincia = null)
- {
- $this->idProvincia = $idProvincia;
- return $this;
- }
- /**
- * Get idProvincia
- *
- * @return BackendBundleEntityProvincia
- */
- public function getIdProvincia()
- {
- return $this->idProvincia;
- }
- }
- namespace BackendBundleEntity;
- /**
- * Provincia
- */
- class Provincia
- {
- /**
- * @var integer
- */
- private $id;
- /**
- * @var string
- */
- private $provincia;
- /**
- * @var integer
- */
- private $especial;
- /**
- * @var string
- */
- private $correoNotificaciones;
- /**
- * @var DoctrineCommonCollectionsCollection
- */
- private $userProvincia;
- /**
- * @var DoctrineCommonCollectionsCollection
- */
- private $municipio;
- /**
- * @var DoctrineCommonCollectionsCollection
- */
- private $inscritosProvincia;
- /**
- * @var BackendBundleEntityCcaa
- */
- private $idCcaa;
- /**
- * Constructor
- */
- public function __construct()
- {
- $this->userProvincia = new DoctrineCommonCollectionsArrayCollection();
- $this->municipio = new DoctrineCommonCollectionsArrayCollection();
- $this->inscritosProvincia = new DoctrineCommonCollectionsArrayCollection();
- $this->idMunicipio= new DoctrineCommonCollectionsArrayCollection;
- $this->idProvincia= new DoctrineCommonCollectionsArrayCollection;
- }
- public function __toString() {
- // return strval($this->idCcaa);
- return $this->provincia;
- }
- /**
- * Set id
- *
- * @param integer $id
- *
- * @return Provincia
- */
- public function setId($id)
- {
- $this->id = $id;
- return $this;
- }
- /**
- * Get id
- *
- * @return integer
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * Set provincia
- *
- * @param string $provincia
- *
- * @return Provincia
- */
- public function setProvincia($provincia)
- {
- $this->provincia = $provincia;
- return $this;
- }
- /**
- * Get provincia
- *
- * @return string
- */
- public function getProvincia()
- {
- return $this->provincia;
- }
- /**
- * Set especial
- *
- * @param integer $especial
- *
- * @return Provincia
- */
- public function setEspecial($especial)
- {
- $this->especial = $especial;
- return $this;
- }
- /**
- * Get especial
- *
- * @return integer
- */
- public function getEspecial()
- {
- return $this->especial;
- }
- /**
- * Set correoNotificaciones
- *
- * @param string $correoNotificaciones
- *
- * @return Provincia
- */
- public function setCorreoNotificaciones($correoNotificaciones)
- {
- $this->correoNotificaciones = $correoNotificaciones;
- return $this;
- }
- /**
- * Get correoNotificaciones
- *
- * @return string
- */
- public function getCorreoNotificaciones()
- {
- return $this->correoNotificaciones;
- }
- /**
- * Add userProvincium
- *
- * @param BackendBundleEntityUsers $userProvincium
- *
- * @return Provincia
- */
- public function addUserProvincium(BackendBundleEntityUsers $userProvincium)
- {
- $this->userProvincia[] = $userProvincium;
- return $this;
- }
- /**
- * Remove userProvincium
- *
- * @param BackendBundleEntityUsers $userProvincium
- */
- public function removeUserProvincium(BackendBundleEntityUsers $userProvincium)
- {
- $this->userProvincia->removeElement($userProvincium);
- }
- /**
- * Get userProvincia
- *
- * @return DoctrineCommonCollectionsCollection
- */
- public function getUserProvincia()
- {
- return $this->userProvincia;
- }
- /**
- * Add municipio
- *
- * @param BackendBundleEntityMunicipios $municipio
- *
- * @return Provincia
- */
- public function addMunicipio(BackendBundleEntityMunicipios $municipio)
- {
- $this->municipio[] = $municipio;
- return $this;
- }
- /**
- * Remove municipio
- *
- * @param BackendBundleEntityMunicipios $municipio
- */
- public function removeMunicipio(BackendBundleEntityMunicipios $municipio)
- {
- $this->municipio->removeElement($municipio);
- }
- /**
- * Get municipio
- *
- * @return DoctrineCommonCollectionsCollection
- */
- public function getMunicipio()
- {
- return $this->municipio;
- }
- /**
- * Add inscritosProvincium
- *
- * @param BackendBundleEntityInscritos $inscritosProvincium
- *
- * @return Provincia
- */
- public function addInscritosProvincium(BackendBundleEntityInscritos $inscritosProvincium)
- {
- $this->inscritosProvincia[] = $inscritosProvincium;
- return $this;
- }
- /**
- * Remove inscritosProvincium
- *
- * @param BackendBundleEntityInscritos $inscritosProvincium
- */
- public function removeInscritosProvincium(BackendBundleEntityInscritos $inscritosProvincium)
- {
- $this->inscritosProvincia->removeElement($inscritosProvincium);
- }
- /**
- * Get inscritosProvincia
- *
- * @return DoctrineCommonCollectionsCollection
- */
- public function getInscritosProvincia()
- {
- return $this->inscritosProvincia;
- }
- /**
- * Set idCcaa
- *
- * @param BackendBundleEntityCcaa $idCcaa
- *
- * @return Provincia
- */
- public function setIdCcaa(BackendBundleEntityCcaa $idCcaa = null)
- {
- $this->idCcaa = $idCcaa;
- return $this;
- }
- /**
- * Get idCcaa
- *
- * @return BackendBundleEntityCcaa
- */
- public function getIdCcaa()
- {
- return $this->idCcaa;
- }
- }
Add Comment
Please, Sign In to add comment