-
Notifications
You must be signed in to change notification settings - Fork 20
Imobiliaria2.0 #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: imobiliaria2.0
Are you sure you want to change the base?
Imobiliaria2.0 #54
Changes from all commits
80ac9da
7a60737
33d3421
6246d13
c26ffcb
d851492
29f665a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,12 +6,19 @@ | |
|
|
||
| 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; | ||
|
|
||
| class ImovelController extends AbstractController | ||
| { | ||
|
|
||
| private $imovelService; | ||
|
|
||
| public function __construct(ImovelService $imovelService){ | ||
| $this->imovelService = $imovelService; | ||
| } | ||
|
|
||
| /** | ||
| * @Route("/imovel/cadastro", name="cadasto_imovel") | ||
|
|
@@ -28,9 +35,10 @@ public function cadastroImovel(Request $request) | |
|
|
||
| if ($form->isSubmitted()) { | ||
| $imovel = $form->getData(); | ||
| $em = $this->getDoctrine()->getManager(); | ||
| $em->persist($imovel); | ||
| $em->flush(); | ||
| $this->imovelService->salvar($imovel); | ||
| //$em = $this->getDoctrine()->getManager(); | ||
| //$em->persist($imovel); | ||
| //$em->flush(); | ||
|
|
||
| return $this->redirectToRoute('index'); | ||
| } | ||
|
|
@@ -80,6 +88,43 @@ public function imovelVisualizar(Request $request) | |
| 'imovel' => $imovel | ||
| ]); | ||
| } | ||
| /** | ||
| * @Route("/editar/{id}", name="editar_imovel") | ||
| */ | ||
| public function editarImovel(int $id, Request $request) | ||
| { | ||
|
|
||
| $imovelParaEditar = $this->imovelService->getById($id); | ||
|
|
||
| if (!$imovelParaEditar) { | ||
| throw new \Exception('Imovel não encontrado'); | ||
| } | ||
|
|
||
| $form = $this->createForm(ImovelType::class, $imovelParaEditar); | ||
|
|
||
| $form->handleRequest($request); | ||
|
|
||
| if ($form->isSubmitted()) { | ||
| $imovelParaEditar = $form->getData(); | ||
| $this->imovelService->editar($imovelParaEditar); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bacana. |
||
| return $this->redirectToRoute('listar_imoveis'); | ||
| } | ||
|
|
||
| return $this->render('imovel_cadastro.html.twig', [ | ||
| 'form' => $form->createView() | ||
| ]); | ||
| } | ||
|
|
||
| /** | ||
| * @Route("/deletar/{id}", name="deletar_imovel") | ||
| */ | ||
| public function deletarImovel(int $id, Request $request) | ||
| { | ||
| $this->imovelService->deletar($id); | ||
| $this->addFlash('success', 'Imovel de id:'.$id.' deletado com sucesso!!!'); | ||
| return $this->redirectToRoute('listar_imoveis'); | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| <?php | ||
|
|
||
| namespace App\Entity; | ||
|
|
||
| use Doctrine\ORM\Mapping as ORM; | ||
|
|
||
| /** | ||
| * @ORM\Entity | ||
| */ | ||
| class ContratoLocacao | ||
| { | ||
| /** | ||
| * @ORM\Id | ||
| * @ORM\Column(type="integer") | ||
| * @ORM\GeneratedValue(strategy="AUTO") | ||
| */ | ||
| private $id; | ||
| /** | ||
| * @ORM\Column(type="integer") | ||
| */ | ||
| private $ativo; | ||
|
|
||
| public function setAtivo($status){ | ||
| $this->ativo = $status; | ||
| } | ||
| public function isAtivo(){ | ||
| return $this->ativo; | ||
| } | ||
|
|
||
| /** | ||
| * @ORM\Column(type="string", length=15, nullable=true) | ||
| */ | ||
| private $status; | ||
|
|
||
| /** | ||
| * @ORM\Column(type="datetime",name="dt_locacao", nullable=true) | ||
| */ | ||
| private $dtLocacao; | ||
| /** | ||
| * @ORM\Column(type="integer") | ||
| */ | ||
| private $duracaoEmMeses; | ||
|
|
||
| /** | ||
| * @return mixed | ||
| */ | ||
| public function getId() | ||
| { | ||
| return $this->id; | ||
| } | ||
|
|
||
| /** | ||
| * @param mixed $id | ||
| */ | ||
| public function setId($id): void | ||
| { | ||
| $this->id = $id; | ||
| } | ||
|
|
||
| /** | ||
| * @return mixed | ||
| */ | ||
| public function getDtLocacao() | ||
| { | ||
| return $this->dtLocacao; | ||
| } | ||
| /** | ||
| * @param mixed $dtLocacao | ||
| */ | ||
| public function setDtLocacao($dtLocacao): void | ||
| { | ||
| $this->dtLocacao = $dtLocacao; | ||
| } | ||
|
|
||
| /** | ||
| * @return mixed | ||
| */ | ||
| public function getDuracaoEmMeses() | ||
| { | ||
| return $this->duracaoEmMeses; | ||
| } | ||
|
|
||
| /** | ||
| * @param mixed $duracaoEmMeses | ||
| */ | ||
| public function setDuracaoEmMeses($duracaoEmMeses): void | ||
| { | ||
| $this->duracaoEmMeses = $duracaoEmMeses; | ||
| } | ||
|
|
||
| /** | ||
| * @ORM\ManyToOne(targetEntity="App\Entity\Imovel", inversedBy="contratoLocacao") | ||
| */ | ||
| private $imovel; | ||
|
|
||
| public function setImovel($imovel){ | ||
| $this->imovel = $imovel; | ||
| } | ||
|
|
||
| public function getImovel(){ | ||
| return $this->imovel; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| <?php | ||
|
|
||
| namespace App\Repository; | ||
|
|
||
| use Doctrine\ORM\Mapping as ORM; | ||
| use App\Entity\Imovel; | ||
| use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||
| use Symfony\Bridge\Doctrine\RegistryInterface; | ||
|
|
||
|
|
||
|
|
||
| class ImovelRepository extends ServiceEntityRepository | ||
| { | ||
|
|
||
| public function __construct(RegistryInterface $registry) | ||
| { | ||
| parent::__construct($registry, Imovel::class); | ||
| } | ||
|
|
||
| public function salvar(Imovel $imovel){ | ||
| $em = $this->getEntityManager(); | ||
| $em->persist($imovel); | ||
| $em->flush(); | ||
| } | ||
|
|
||
| public function editar(Imovel $imovel){ | ||
| $em = $this->getEntityManager(); | ||
| $em->merge($imovel); | ||
| $em->flush(); | ||
| } | ||
|
|
||
| public function deletar(int $id){ | ||
| $em = $this->getEntityManager(); | ||
| $imovelParaDeletar = $em->getRepository(Imovel::class)->find($id); | ||
| $em->remove($imovelParaDeletar); | ||
| $em->flush(); | ||
| } | ||
|
|
||
| public function getById(int $id){ | ||
| $em = $this->getEntityManager(); | ||
| return $em->getRepository(Imovel::class)->find($id); | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lembrar sempre das psrs e deixar uma linha embranco no fim do arquivo. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?php | ||
|
|
||
| namespace App\Service; | ||
|
|
||
| use Doctrine\ORM\Mapping as ORM; | ||
| use App\Entity\Imovel; | ||
| use App\Repository\ImovelRepository; | ||
| use Symfony\Bridge\Doctrine\RegistryInterface; | ||
|
|
||
|
|
||
|
|
||
| class ImovelService | ||
| { | ||
|
|
||
| private $imovelRepository; | ||
|
|
||
| public function __construct(ImovelRepository $imovelRepository){ | ||
| $this->imovelRepository = $imovelRepository; | ||
| } | ||
|
|
||
| public function salvar(Imovel $imovel){ | ||
| $this->imovelRepository->salvar($imovel); | ||
| } | ||
|
|
||
| public function editar(Imovel $imovel){ | ||
| $this->imovelRepository->editar($imovel); | ||
| } | ||
|
|
||
| public function deletar(int $id){ | ||
| $this->imovelRepository->deletar($id); | ||
| } | ||
| public function getById(int $id){ | ||
| return $this->imovelRepository->getById($id); | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. faltou uma linha em branco |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,80 @@ | ||
| {% include "base.html.twig" %} | ||
|
|
||
| <!-- Begin Page Content --> | ||
| <div class="container-fluid"> | ||
|
|
||
| <!-- Page Heading --> | ||
| <h1 class="h3 mb-4 text-gray-800">Cadastro de Imóveis</h1> | ||
| <div | ||
| class="container-fluid"> | ||
|
|
||
| <!-- Page Heading --> | ||
| <h1 class="h3 mb-4 text-gray-800">Cadastro de Imóveis</h1> | ||
| {{ form_start(form) }} | ||
| <div class="row"> | ||
| <div class="col-4"> | ||
| {{form_row(form.status)}} | ||
| </div> | ||
| <div class="col-4"> | ||
| {{form_row(form.caracteristicas)}} | ||
| </div> | ||
| <div class="col-4"> | ||
| {{form_row(form.observacao)}} | ||
| </div> | ||
| <div class="col-4"> | ||
| {{form_row(form.tipoImovel)}} | ||
| </div> | ||
| <div class="col-4"> | ||
| {{form_row(form.dtCadastro)}} | ||
| </div> | ||
| </div> | ||
| <div class="row"> | ||
| <div class="col-12"> | ||
| {{form_label(form.endereco)}} | ||
| </div> | ||
| </div> | ||
| <div class="row"> | ||
| <div class="col-4"> | ||
| {{form_row(form.endereco.logradouro)}} | ||
| </div> | ||
| <div class="col-4"> | ||
| {{form_row(form.endereco.bairro)}} | ||
| </div> | ||
| <div class="col-4"> | ||
| {{form_row(form.endereco.numero)}} | ||
| </div> | ||
| <div class="col-4"> | ||
| {{form_row(form.endereco.cep)}} | ||
| </div> | ||
| <div class="col-4"> | ||
| {{form_row(form.endereco.complemento)}} | ||
| </div> | ||
| <div class="col-4"> | ||
| {{form_row(form.endereco.uf)}} | ||
| </div> | ||
| <div class="col-4"> | ||
| {{form_row(form.endereco.cidade)}} | ||
| </div> | ||
| <div class="col-4"> | ||
| {{form_row(form.endereco.dddTelefone)}} | ||
| </div> | ||
| <div class="col-4"> | ||
| {{form_row(form.endereco.telefone)}} | ||
| </div> | ||
| <div class="col-4"> | ||
| {{form_row(form.endereco.dddCelular)}} | ||
| </div> | ||
| <div class="col-4"> | ||
| {{form_row(form.endereco.celular)}} | ||
| </div> | ||
| </div> | ||
| <div class="d-sm-flex align-items-center justify-content-between mb-4"> | ||
|
|
||
| <div class="d-sm-flex align-items-center justify-content-between mb-4"> | ||
| {{ form_start(form) }} | ||
| {{ form_widget(form) }} | ||
| {{ form_widget(form) }} | ||
|
|
||
| <input class="btn btn-success btn-icon-split" type="submit"/> | ||
| <input class="btn btn-success btn-icon-split" type="submit"/> | ||
|
|
||
| {{ form_end(form) }} | ||
| {{ form_end(form) }} | ||
|
|
||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <!-- End of Main Content --> | ||
|
|
||
| {% include "footer.html.twig" %}s | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ótimo, mas sempre é uma boa pratica não deixar código comentado, já que temos o git para vermos os historicos...