From 17f9b325b105ba9a292d6dda10f9331f2f17d34e Mon Sep 17 00:00:00 2001 From: silvestrejp Date: Sat, 22 Jun 2019 23:19:51 -0300 Subject: [PATCH] Envio do projeto imobiliario 2.0. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Itens que foram implementados: ok 1 - Criar ação do botão editar imovel. ok 2 - Criar ação do botão deletar imovel. ok 3 - Formatar o type de cadastro de imoveis ok 4 - Criar serviços e Ações nos respositores para o Controller Usuario. ok Editar ok Deletar ok 5 - Criar serviços e Ações nos respositores para o Controller Imovel. ok Salvar ok Editar ok Deletar ok 6 - Criar os repositores para a Entidade Imovel. ok 7 - Mapear Entidade ContratoAdm. ok 8 - Mapear Entidade ContratoLocacao. --- data/database.sqlite | Bin 20480 -> 28672 bytes src/Controller/ImovelController.php | 44 ++++++- src/Controller/UsuarioController.php | 21 ++-- src/Entity/ContratoAdm.php | 121 ++++++++++++++++++ src/Entity/ContratoLocacao.php | 181 +++++++++++++++++++++++++++ src/Entity/Usuario.php | 5 - src/Forms/ImovelType.php | 10 +- src/Forms/UsuarioType.php | 2 +- src/Repository/ImovelRepository.php | 55 ++++++++ src/Repository/UsuarioRepository.php | 55 ++++++++ src/Service/ImovelService.php | 34 +++++ src/Service/UsuarioService.php | 34 +++++ templates/imovel_cadastro.html.twig | 77 +++++++++++- templates/listar_imoveis.html.twig | 36 +++--- templates/usuario_cadastro.html.twig | 2 +- 15 files changed, 626 insertions(+), 51 deletions(-) create mode 100644 src/Entity/ContratoAdm.php create mode 100644 src/Entity/ContratoLocacao.php create mode 100644 src/Repository/ImovelRepository.php create mode 100644 src/Repository/UsuarioRepository.php create mode 100644 src/Service/ImovelService.php create mode 100644 src/Service/UsuarioService.php diff --git a/data/database.sqlite b/data/database.sqlite index 6804099194477c98dfb0bd95dbcdc352559b3065..23bf42ab044491eb4675cb26734cdfaa7f78b710 100755 GIT binary patch delta 2783 zcmb`JZ)h839LFzBnoBOZyPj#5W^I}$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%`Etq-{f|sj`kH+7C3$4%h;5{3kh08BMFkDq!oybBv0%^(j zGw=O4F%Q!%5S*+U^vOB6(0qjP;p8k#pE#oUXL9Z=r`DXUx{We3i#Ex+`{ko;D5{Df zs-{A-j7@c~d|27fyeeR&5^G%@r!v26um8kwNtUvEVzK@x08QSt%Oj^{nZ3e5AW$Qw z#t1V>R(3ygY{F04#YH2o9kcI4A*+G-eGTfU?WVg6JO{i z2!9h^2|W$nEH_ORLPM**2GEg{dlC$BN?DR|U(fN&^r)@4aXv-t{Gw$ST)yb0ZQ{iF zQjYL9NS5%l!Lp=4vR2OfB+=bIOB}brXI#DlDOnCb-76y$M=0PuJ$FBpU>ZPVP>wV+ zvoz73b*}$(niL6^WO~j4;Mm6?{6#n!`YW^%61e+Z68;T0;Y-0g!Heu;daFEOjcc9k fL2pKx|J#{NWBKCPRiA&3VQE#ojZ1C*=lTB^vYlFh diff --git a/src/Controller/ImovelController.php b/src/Controller/ImovelController.php index 5cbf296..3c775b5 100644 --- a/src/Controller/ImovelController.php +++ b/src/Controller/ImovelController.php @@ -6,6 +6,7 @@ use App\Entity\Imovel; use App\Forms\ImovelType; +use App\Service\ImovelService; use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Routing\Annotation\Route; @@ -19,7 +20,7 @@ class ImovelController extends AbstractController * @param Request $request * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ - public function cadastroImovel(Request $request) + public function cadastroImovel(Request $request, ImovelService $imovelservice) { $imovel = new Imovel(); @@ -28,9 +29,7 @@ public function cadastroImovel(Request $request) if ($form->isSubmitted()) { $imovel = $form->getData(); - $em = $this->getDoctrine()->getManager(); - $em->persist($imovel); - $em->flush(); + $imovelservice->salvar($imovel); return $this->redirectToRoute('index'); } @@ -81,6 +80,43 @@ public function imovelVisualizar(Request $request) ]); } + /** + * @Route("/editar_imovel/{id}", name="editar_imovel") + */ + public function editarImovel(int $id, Request $request, ImovelService $imovelservice) + { + $em = $this->getDoctrine()->getManager(); + $imovel = $em->getRepository(Imovel::class)->find($id); + + if (!$imovel) { + throw new \Exception('Imóvel não encontrado'); + } + + $form = $this->createForm(ImovelType::class, $imovel); + + $form->handleRequest($request); + + if ($form->isSubmitted()) { + $imovel = $form->getData(); + $imovelservice->atualizar($imovel); + + return $this->redirectToRoute('listar_imoveis'); + } + return $this->render('imovel_cadastro.html.twig', [ + 'form' => $form->createView() + ]); + } + + /** + * @Route("/deletar_imovel/{id}", name="deletar_imovel") + */ + public function deletarImovel(int $id, Request $request, ImovelService $imovelservice) + { + $imovelservice->remover($id); + $this->addFlash('success', 'Imóvel de id:' . $id . ' deletado com sucesso!!!'); + + return $this->redirectToRoute('listar_imoveis'); + } } \ No newline at end of file diff --git a/src/Controller/UsuarioController.php b/src/Controller/UsuarioController.php index f1facd9..93ce8e7 100644 --- a/src/Controller/UsuarioController.php +++ b/src/Controller/UsuarioController.php @@ -6,6 +6,7 @@ use App\Entity\Corretor; use App\Forms\UsuarioType; use App\Entity\Usuario; +use App\Service\UsuarioService; use phpDocumentor\Reflection\DocBlock\Tags\Throws; use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; @@ -21,10 +22,9 @@ class UsuarioController extends AbstractController { /** - *@IsGranted("ROLE_ADMIN") * @Route("/usuario", name="usuario_novo") */ - public function cadastroUsuario(Request $request) + public function cadastroUsuario(Request $request, UsuarioService $usuarioservice) { $usuario = new Usuario(); $form = $this->createForm(UsuarioType::class, $usuario); @@ -32,9 +32,7 @@ public function cadastroUsuario(Request $request) if ($form->isSubmitted()) { $usuario = $form->getData(); - $em = $this->getDoctrine()->getManager(); - $em->persist($usuario); - $em->flush(); + $usuarioservice->salvar($usuario); return $this->redirectToRoute('index'); } @@ -71,7 +69,7 @@ public function listarUsuarios(Request $request) /** * @Route("/editar/{id}", name="editar_usuario") */ - public function editarUsuario(int $id, Request $request) + public function editarUsuario(int $id, Request $request, UsuarioService $usuarioservice) { $em = $this->getDoctrine()->getManager(); $usuario = $em->getRepository(Usuario::class)->find($id); @@ -86,9 +84,7 @@ public function editarUsuario(int $id, Request $request) if ($form->isSubmitted()) { $usuario = $form->getData(); - $em = $this->getDoctrine()->getManager(); - $em->merge($usuario); - $em->flush(); + $usuarioservice->atualizar($usuario); return $this->redirectToRoute('listar_usuarios'); } @@ -101,12 +97,9 @@ public function editarUsuario(int $id, Request $request) /** * @Route("/deletar/{id}", name="deletar_usuario") */ - public function deletarUsuario(int $id, Request $request) + public function deletarUsuario(int $id, Request $request, UsuarioService $usuarioService) { - $em = $this->getDoctrine()->getManager(); - $usuario = $em->getRepository(Usuario::class)->find($id); - $em->remove($usuario); - $em->flush(); + $usuarioService->remover($id); $this->addFlash('success', 'Usuario de id:'.$id.' deletado com sucesso!!!'); return $this->redirectToRoute('listar_usuarios'); diff --git a/src/Entity/ContratoAdm.php b/src/Entity/ContratoAdm.php new file mode 100644 index 0000000..d641947 --- /dev/null +++ b/src/Entity/ContratoAdm.php @@ -0,0 +1,121 @@ +id; + } + + /** + * @param mixed $id + */ + public function setId($id): void + { + $this->id = $id; + } + + /** + * @return mixed + */ + public function getDtCadastro() + { + return $this->dt_cadastro; + } + + /** + * @param mixed $dt_cadastro + */ + public function setDtCadastro($dt_cadastro): void + { + $this->dt_cadastro = $dt_cadastro; + } + + /** + * @return mixed + */ + public function getUsusarioId() + { + return $this->ususario_id; + } + + /** + * @param mixed $ususario_id + */ + public function setUsusarioId($ususario_id): void + { + $this->ususario_id = $ususario_id; + } + + /** + * @return mixed + */ + public function getImovelId() + { + return $this->imovel_id; + } + + /** + * @param mixed $imovel_id + */ + public function setImovelId($imovel_id): void + { + $this->imovel_id = $imovel_id; + } + + /** + * @return mixed + */ + public function getClausulaContratual() + { + return $this->clausula_contratual; + } + + /** + * @param mixed $clausula_contratual + */ + public function setClausulaContratual($clausula_contratual): void + { + $this->clausula_contratual = $clausula_contratual; + } + +} \ No newline at end of file diff --git a/src/Entity/ContratoLocacao.php b/src/Entity/ContratoLocacao.php new file mode 100644 index 0000000..9bc07a7 --- /dev/null +++ b/src/Entity/ContratoLocacao.php @@ -0,0 +1,181 @@ +id; + } + + /** + * @param mixed $id + */ + public function setId($id): void + { + $this->id = $id; + } + + /** + * @return mixed + */ + public function getDtCadastro() + { + return $this->dt_cadastro; + } + + /** + * @param mixed $dt_cadastro + */ + public function setDtCadastro($dt_cadastro): void + { + $this->dt_cadastro = $dt_cadastro; + } + + /** + * @return mixed + */ + public function getDtValidade() + { + return $this->dt_validade; + } + + /** + * @param mixed $dt_validade + */ + public function setDtValidade($dt_validade): void + { + $this->dt_validade = $dt_validade; + } + + /** + * @return mixed + */ + public function getFormaPagamento() + { + return $this->forma_pagamento; + } + + /** + * @param mixed $forma_pagamento + */ + public function setFormaPagamento($forma_pagamento): void + { + $this->forma_pagamento = $forma_pagamento; + } + + /** + * @return mixed + */ + public function getDtVencimento() + { + return $this->dt_vencimento; + } + + /** + * @param mixed $dt_vencimento + */ + public function setDtVencimento($dt_vencimento): void + { + $this->dt_vencimento = $dt_vencimento; + } + + /** + * @return mixed + */ + public function getUsusarioId() + { + return $this->ususario_id; + } + + /** + * @param mixed $ususario_id + */ + public function setUsusarioId($ususario_id): void + { + $this->ususario_id = $ususario_id; + } + + /** + * @return mixed + */ + public function getImovelId() + { + return $this->imovel_id; + } + + /** + * @param mixed $imovel_id + */ + public function setImovelId($imovel_id): void + { + $this->imovel_id = $imovel_id; + } + + /** + * @return mixed + */ + public function getClausulaContratual() + { + return $this->clausula_contratual; + } + + /** + * @param mixed $clausula_contratual + */ + public function setClausulaContratual($clausula_contratual): void + { + $this->clausula_contratual = $clausula_contratual; + } + + +} \ No newline at end of file diff --git a/src/Entity/Usuario.php b/src/Entity/Usuario.php index 692db37..e532e0d 100644 --- a/src/Entity/Usuario.php +++ b/src/Entity/Usuario.php @@ -52,11 +52,6 @@ class Usuario */ private $endereco; - /** -// * @ORM\OneToMany(targetEntity="Entity\contratoLocacao", mappedBy="usuario") -// */ -// private $contratoLocacao; - // /** // * @ORM\OneToMany(targetEntity="Entity\ContratoAdm", mappedBy="usuario") // */ diff --git a/src/Forms/ImovelType.php b/src/Forms/ImovelType.php index 14fb62a..fa2b1d0 100755 --- a/src/Forms/ImovelType.php +++ b/src/Forms/ImovelType.php @@ -26,25 +26,25 @@ class ImovelType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options): void { $builder -// ->setAction('../usuario') +// ->setAction('../imovel') // ->setMethod('POST') ->add('status', ChoiceType::class, [ 'label' => 'Status', 'choices' => [ - 'Disponivel' => 'disponivel', + 'Disponível' => 'disponivel', 'Alugado' => 'alugado', 'Em Manutenção' => 'Em Manutenção', - 'Vistoria' => 'Vistoria', + 'Vistória' => 'Vistoria', 'Sem Cotrato Adm' => 'Sem Cotrato Adm', 'Sem Contrato de Locação' => 'Sem Contrato de Locação' ] ]) ->add('caracteristicas', TextType::class, [ - 'label' => 'Caracterisiticas do Imovel', + 'label' => 'Características do Imóvel' ]) ->add('observacao', TextType::class, [ - 'label' => 'Observações Geral', + 'label' => 'Observações Gerais', ]) ->add('tipoImovel', ChoiceType::class, [ 'empty_data' => 'Casa', diff --git a/src/Forms/UsuarioType.php b/src/Forms/UsuarioType.php index 486f2bf..198f781 100755 --- a/src/Forms/UsuarioType.php +++ b/src/Forms/UsuarioType.php @@ -38,7 +38,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ] ]) ->add('sexo', TextType::class, [ - 'label' => 'Sexto', + 'label' => 'Sexo', ]) ->add('email', EmailType::class, [ 'label' => 'Email', diff --git a/src/Repository/ImovelRepository.php b/src/Repository/ImovelRepository.php new file mode 100644 index 0000000..a5f526a --- /dev/null +++ b/src/Repository/ImovelRepository.php @@ -0,0 +1,55 @@ +getEntityManager(); + $em->persist($imovel); + $em->flush(); + } + + /** + * @param Imovel $imovel + * @throws \Doctrine\ORM\ORMException + * @throws \Doctrine\ORM\OptimisticLockException + */ + public function atualizar(Imovel $imovel) + { + $em = $this->getEntityManager(); + $em->merge($imovel); + $em->flush(); + } + + /** + * @param int $id + * @throws \Doctrine\ORM\ORMException + * @throws \Doctrine\ORM\OptimisticLockException + */ + public function remover(int $id) + { + $em = $this->getEntityManager(); + $imovel = $em->getRepository(Imovel::class)->find($id); + $em->remove($imovel); + $em->flush(); + } + +} \ No newline at end of file diff --git a/src/Repository/UsuarioRepository.php b/src/Repository/UsuarioRepository.php new file mode 100644 index 0000000..600454b --- /dev/null +++ b/src/Repository/UsuarioRepository.php @@ -0,0 +1,55 @@ +getEntityManager(); + $em->persist($usuario); + $em->flush(); + } + + /** + * @param Usuario $usuario + * @throws \Doctrine\ORM\ORMException + * @throws \Doctrine\ORM\OptimisticLockException + */ + public function atualizar(Usuario $usuario) + { + $em = $this->getEntityManager(); + $em->merge($usuario); + $em->flush(); + } + + /** + * @param int $id + * @throws \Doctrine\ORM\ORMException + * @throws \Doctrine\ORM\OptimisticLockException + */ + public function remover(int $id) + { + $em = $this->getEntityManager(); + $usuario = $em->getRepository(Usuario::class)->find($id); + $em->remove($usuario); + $em->flush(); + } + +} \ No newline at end of file diff --git a/src/Service/ImovelService.php b/src/Service/ImovelService.php new file mode 100644 index 0000000..feb075e --- /dev/null +++ b/src/Service/ImovelService.php @@ -0,0 +1,34 @@ +imovelrepository = $imovelrepository; + } + + public function salvar(Imovel $imovel) + { + $this->imovelrepository->salvar($imovel); + } + + public function atualizar(Imovel $imovel) + { + $this->imovelrepository->atualizar($imovel); + } + + public function remover(int $id) + { + $this->imovelrepository->remover($id); + } + +} \ No newline at end of file diff --git a/src/Service/UsuarioService.php b/src/Service/UsuarioService.php new file mode 100644 index 0000000..0254bd3 --- /dev/null +++ b/src/Service/UsuarioService.php @@ -0,0 +1,34 @@ +usuarioRepository = $usuarioRepository; + } + + public function salvar(Usuario $usuario) + { + $this->usuarioRepository->salvar($usuario); + } + + public function atualizar(Usuario $usuario) + { + $this->usuarioRepository->atualizar($usuario); + } + + public function remover(int $id) + { + $this->usuarioRepository->remover($id); + } + +} \ No newline at end of file diff --git a/templates/imovel_cadastro.html.twig b/templates/imovel_cadastro.html.twig index 9e378da..2508484 100644 --- a/templates/imovel_cadastro.html.twig +++ b/templates/imovel_cadastro.html.twig @@ -5,16 +5,81 @@

Cadastro de Imóveis

+ {{ form_start(form) }} +
+
+ {{ form_row(form.status) }} +
+
+ {{ form_row(form.tipoImovel) }} +
-
- {{ form_start(form) }} - {{ form_widget(form) }} +
+
+
+ {{ form_row(form.observacao) }} +
+
+ {{ form_row(form.caracteristicas) }} +
- +
+
+
+ {{ form_row(form.dtCadastro) }} +
+
+

Endereço

+
+
+ {{ form_row(form.endereco.logradouro) }} +
+
+ {{ form_row(form.endereco.numero) }} +
+
+
+
+ {{ form_row(form.endereco.bairro) }} +
+
+ {{ form_row(form.endereco.cep) }} +
+
+
+
+ {{ form_row(form.endereco.cidade) }} +
+
+ {{ form_row(form.endereco.uf) }} +
+
+
+
+ {{ form_row(form.endereco.complemento) }} +
+
+
+
+ {{ form_row(form.endereco.dddTelefone) }} +
+
+ {{ form_row(form.endereco.telefone) }} +
+
+
+
+ {{ form_row(form.endereco.dddCelular) }} +
+
+ {{ form_row(form.endereco.celular) }} +
+
+ + + {{ form_end(form) }} - {{ form_end(form) }} -
diff --git a/templates/listar_imoveis.html.twig b/templates/listar_imoveis.html.twig index 6af1973..f37f68f 100644 --- a/templates/listar_imoveis.html.twig +++ b/templates/listar_imoveis.html.twig @@ -14,23 +14,25 @@ Status - Caracterisitcas - Observacao - Tipo do Imovel + Características + Observação + Tipo do Imóvel Data Cadastro Bairro Rua + Editar/Deletar Status - Caracterisitcas - Observacao - Tipo do Imovel + Características + Observação + Tipo do Imóvel Data Cadastro Bairro Rua + Editar/Deletar @@ -45,9 +47,13 @@ {{ imovel.dtCadastro|date("m/d/Y") }} {{ imovel.endereco.bairro }} {{ imovel.endereco.logradouro }} - + - + + + + + {% endfor %} @@ -62,21 +68,21 @@ - - + + - + - + - - + + - + diff --git a/templates/usuario_cadastro.html.twig b/templates/usuario_cadastro.html.twig index b994c77..c635c6d 100644 --- a/templates/usuario_cadastro.html.twig +++ b/templates/usuario_cadastro.html.twig @@ -83,7 +83,7 @@ -{% include "footer.html.twig" %}s +{% include "footer.html.twig" %}