Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 48 additions & 3 deletions src/Controller/ImovelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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);
Copy link
Copy Markdown
Owner

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...

//$em = $this->getDoctrine()->getManager();
//$em->persist($imovel);
//$em->flush();

return $this->redirectToRoute('index');
}
Expand Down Expand Up @@ -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);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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');
}




Expand Down
106 changes: 106 additions & 0 deletions src/Entity/ContratoLocacao.php
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;
}



}
19 changes: 15 additions & 4 deletions src/Entity/Imovel.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,21 @@ public function setEndereco($endereco): void
$this->endereco = $endereco;
}

// /**
// * @ORM\OneToMany(targetEntity="Entity\contratoLocacao", mappedBy="imovel")
// */
// private $contratoLocacao;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ContratoLocacao", mappedBy="imovel")
*/
//um imovel pode ser alugado várias vezes, logo terá vários contratos. Apenas um estará ativo
private $contratoLocacao;

public function setContratoLocao($contrato){
$this->contratoLocacao = $contrato;
}
public function getContratoLocao(){
return $this->contrato;
}



//
// /**
// * @ORM\OneToMany(targetEntity="Entity\ContratoAdm", mappedBy="imovel")
Expand Down
45 changes: 45 additions & 0 deletions src/Repository/ImovelRepository.php
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);
}


}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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.

37 changes: 37 additions & 0 deletions src/Service/ImovelService.php
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);
}


}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

faltou uma linha em branco

87 changes: 68 additions & 19 deletions templates/imovel_cadastro.html.twig
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









Loading