Last active
December 15, 2015 08:28
-
-
Save dextervip/5230565 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Ideiah\GestaoQuadra\ClienteBundle\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
use Gedmo\Mapping\Annotation as Gedmo; | |
use Ideiah\GestaoQuadra\AgendaBundle\Entity\Solicitacao; | |
use Ideiah\GestaoQuadra\AgendaBundle\Entity\Horario; | |
use Symfony\Component\Validator\Constraints as Assert; | |
/** | |
* Cliente | |
* | |
* @ORM\Table() | |
* @ORM\Entity(repositoryClass="Ideiah\GestaoQuadra\ClienteBundle\Entity\ClienteRepository") | |
*/ | |
class Cliente | |
{ | |
/** | |
* @var integer | |
* | |
* @ORM\Column(name="id", type="integer") | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="AUTO") | |
*/ | |
private $id; | |
/** | |
* @var string | |
* | |
* @Assert\NotBlank() | |
* @Assert\Length(min = "3", max = "60") | |
* @ORM\Column(name="nome", type="string", length=255) | |
*/ | |
private $nome; | |
/** | |
* @var integer | |
* | |
* @Assert\Type(type="numeric") | |
* @ORM\Column(type="decimal", precision=20) | |
*/ | |
private $rg; | |
/** | |
* @var string | |
* | |
* @Assert\NotBlank() | |
* @Assert\Type(type="numeric") | |
* @Assert\Length(min = "11", max = "11") | |
* @ORM\Column(name="cpf", type="string", length=11) | |
*/ | |
private $cpf; | |
/** | |
* @var string | |
* | |
* @Assert\NotBlank() | |
* @Assert\Email() | |
* @ORM\Column(name="email", type="string", length=255) | |
*/ | |
private $email; | |
/** | |
* @var \DateTime | |
* | |
* @Assert\NotBlank() | |
* @Assert\Date() | |
* @ORM\Column(name="data_nascimento", type="date") | |
*/ | |
private $dataNascimento; | |
/** | |
* @var integer | |
* | |
* @Assert\NotBlank() | |
* @Assert\Length(min = "8", max = "14") | |
* @ORM\Column(name="telefone", type="integer") | |
*/ | |
private $telefone; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="obs", type="text", nullable=true) | |
*/ | |
private $obs; | |
/** | |
* @var Pontuacao | |
* | |
* @ORM\OneToOne(targetEntity="Pontuacao", cascade={"persist"}) | |
* @ORM\JoinColumn(name="id_pontuacao", referencedColumnName="id", nullable=false) | |
*/ | |
private $pontuacao; | |
/** | |
* @ORM\OneToMany(targetEntity="Ideiah\GestaoQuadra\AgendaBundle\Entity\Solicitacao", mappedBy="cliente", cascade={"persist", "remove"}) | |
*/ | |
private $solicitacoes; | |
/** | |
* @ORM\OneToMany(targetEntity="Ideiah\GestaoQuadra\AgendaBundle\Entity\Horario", mappedBy="cliente", cascade={"persist", "remove"}) | |
*/ | |
private $horarios; | |
/** | |
* @var \DateTime | |
* @Gedmo\Timestampable(on="create") | |
* @ORM\Column(name="data_criacao", type="datetime") | |
*/ | |
private $data_criacao; | |
/** | |
* @var \DateTime | |
* @Gedmo\Timestampable(on="update") | |
* @ORM\Column(name="data_modificacao", type="datetime") | |
*/ | |
private $data_modificacao; | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Ideiah\GestaoQuadra\AgendaBundle\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
use Gedmo\Mapping\Annotation as Gedmo; | |
use Ideiah\GestaoQuadra\ClienteBundle\Entity\Cliente; | |
use Symfony\Component\Validator\Constraints as Assert; | |
use Symfony\Component\Validator\ExecutionContext; | |
/** | |
* Solicitacao | |
* | |
* @Assert\Callback(methods={"validarHora"}) | |
* @ORM\Table() | |
* @ORM\Entity(repositoryClass="Ideiah\GestaoQuadra\AgendaBundle\Entity\SolicitacaoRepository") | |
*/ | |
class Solicitacao { | |
const STATUS_PENDENTE = 'Pendente'; | |
const STATUS_ACEITA = 'Aceita'; | |
const STATUS_REJEITADA = 'Rejeitada'; | |
/** | |
* @var integer | |
* | |
* @ORM\Column(name="id", type="integer") | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="AUTO") | |
*/ | |
private $id; | |
/** | |
* @var \DateTime | |
* | |
* @ORM\Column(name="hora_inicial", type="time") | |
*/ | |
private $hora_inicial; | |
/** | |
* @var \DateTime | |
* | |
* @ORM\Column(name="hora_final", type="time") | |
*/ | |
private $hora_final; | |
/** | |
* @var \DateTime | |
* | |
* @ORM\Column(name="data", type="date") | |
*/ | |
private $data; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="obs", type="text", nullable=true) | |
*/ | |
private $obs; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="status", type="text") | |
*/ | |
private $status; | |
/** | |
* @var boolean | |
* | |
* @ORM\Column(name="luz", type="boolean") | |
*/ | |
private $luz; | |
/** | |
* @ORM\ManyToOne(targetEntity="Ideiah\GestaoQuadra\ClienteBundle\Entity\Cliente", inversedBy="solicitacoes", cascade={"persist"}) | |
* @ORM\JoinColumn(nullable=true) | |
*/ | |
private $cliente; | |
/** | |
* @var \DateTime | |
* @Gedmo\Timestampable(on="create") | |
* @ORM\Column(name="data_criacao", type="datetime") | |
*/ | |
private $data_criacao; | |
/** | |
* @var \DateTime | |
* @Gedmo\Timestampable(on="update") | |
* @ORM\Column(name="data_modificacao", type="datetime") | |
*/ | |
private $data_modificacao; | |
... | |
public function validarHora(ExecutionContextInterface $context) { | |
if ($this->getHoraInicial() == $this->getHoraFinal()) { | |
$context->addViolationAt('hora_inicial', 'A hora inicial não pode ser igual ou maior a hora final!'); | |
} | |
if ($this->getHoraInicial() > $this->getHoraFinal()) { | |
$context->addViolationAt('hora_inicial', 'A hora inicial tem que ser menor que a hora final!'); | |
} | |
if ((new \DateTime($this->getHoraInicial()))->format('i') !== '00') { | |
$context->addViolationAt('hora_inicial', 'A hora é inválida, apenas horas inteiras podem ser inseridas!'); | |
} | |
if ((new \DateTime($this->getHoraFinal()))->format('H:i') !== '23:59') { | |
if ((new \DateTime($this->getHoraFinal()))->format('i') !== '00') { | |
$context->addViolationAt('hora_final', 'A hora é inválida, apenas horas inteiras podem ser inseridas!'); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Ideiah\GestaoQuadra\AgendaBundle\Service; | |
use Symfony\Component\Validator\Constraints as Assert; | |
use Symfony\Component\Validator\ExecutionContextInterface; | |
/** | |
* Solicitacao | |
* @Assert\Callback(methods={"validarHora"}) | |
*/ | |
class Solicitacao { | |
/** | |
* @var integer | |
*/ | |
private $id; | |
/** | |
* @Assert\NotBlank() | |
* @Assert\MaxLength(255) | |
* @Assert\MinLength(2) | |
*/ | |
private $nome; | |
/** | |
* | |
*/ | |
private $rg; | |
/** | |
* @Assert\NotBlank() | |
* @Assert\Type(type="numeric") | |
* @Assert\MaxLength(11) | |
* @Assert\MinLength(11) | |
*/ | |
private $cpf; | |
/** | |
* @Assert\NotBlank() | |
* @Assert\Email() | |
*/ | |
private $email; | |
/** | |
* @Assert\NotBlank() | |
*/ | |
private $telefone; | |
/** | |
* @Assert\NotBlank() | |
* @Assert\Date() | |
*/ | |
private $dataNascimento; | |
/** | |
* @Assert\NotBlank() | |
* @Assert\Time() | |
*/ | |
private $hora_inicial; | |
/** | |
* @Assert\NotBlank() | |
* @Assert\Time() | |
*/ | |
private $hora_final; | |
/** | |
* @Assert\NotBlank() | |
* @Assert\Date() | |
*/ | |
private $data; | |
/** | |
* @Assert\MaxLength(300) | |
*/ | |
private $obs; | |
/** | |
* @var boolean | |
* @Assert\Type(type="bool") | |
*/ | |
private $luz; | |
... | |
public function validarHora(ExecutionContextInterface $context) { | |
if ($this->getHoraInicial() == $this->getHoraFinal()) { | |
$context->addViolationAt('hora_inicial', 'A hora inicial não pode ser igual ou maior a hora final!'); | |
} | |
if ($this->getHoraInicial() > $this->getHoraFinal()) { | |
$context->addViolationAt('hora_inicial', 'A hora inicial tem que ser menor que a hora final!'); | |
} | |
if ((new \DateTime($this->getHoraInicial()))->format('i') !== '00') { | |
$context->addViolationAt('hora_inicial', 'A hora é inválida, apenas horas inteiras podem ser inseridas!'); | |
} | |
if ((new \DateTime($this->getHoraFinal()))->format('H:i') !== '23:59') { | |
if ((new \DateTime($this->getHoraFinal()))->format('i') !== '00') { | |
$context->addViolationAt('hora_final', 'A hora é inválida, apenas horas inteiras podem ser inseridas!'); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Ideiah\GestaoQuadra\AgendaBundle\Entity; | |
use Doctrine\ORM\EntityRepository; | |
use Ideiah\GestaoQuadra\AgendaBundle\Service\Solicitacao as SolicitacaoService; | |
use Ideiah\GestaoQuadra\AgendaBundle\Entity\Solicitacao as Solicitacao; | |
use Ideiah\GestaoQuadra\ClienteBundle\Entity\Cliente; | |
use Ideiah\GestaoQuadra\ClienteBundle\Entity\Pontuacao; | |
/** | |
* SolicitacaoRepository | |
* | |
* This class was generated by the Doctrine ORM. Add your own custom | |
* repository methods below. | |
*/ | |
class SolicitacaoRepository extends EntityRepository { | |
public function cadastrarSolicitacao(SolicitacaoService $solicitacaoService) { | |
$em = $this->getEntityManager(); | |
$clienteRepository = $em->getRepository('Ideiah\GestaoQuadra\ClienteBundle\Entity\Cliente'); | |
$cliente = $clienteRepository->findOneBy(array('cpf' => $solicitacaoService->getCpf())); | |
if (is_null($cliente) == true) { | |
$cliente = new Cliente(); | |
$cliente->setNome($solicitacaoService->getNome()); | |
$cliente->setCpf($solicitacaoService->getCpf()); | |
$cliente->setRg($solicitacaoService->getRg()); | |
$cliente->setEmail($solicitacaoService->getEmail()); | |
$cliente->setTelefone($solicitacaoService->getTelefone()); | |
$cliente->setDataNascimento(new \DateTime($solicitacaoService->getDataNascimento())); | |
$pontuacao = new Pontuacao(); | |
$pontuacao->setPontos(0)->setMes(date('n')); | |
$cliente->setPontuacao($pontuacao); | |
$em->persist($cliente); | |
} | |
$solicitacao = new Solicitacao(); | |
$solicitacao->setLuz($solicitacaoService->getLuz()); | |
$solicitacao->setObs($solicitacaoService->getObs()); | |
$solicitacao->setStatus(Solicitacao::STATUS_PENDENTE); | |
$solicitacao->setData(new \DateTime($solicitacaoService->getData())); | |
$solicitacao->setHoraInicial(new \DateTime($solicitacaoService->getHoraInicial())); | |
$solicitacao->setHoraFinal(new \DateTime($solicitacaoService->getHoraFinal())); | |
$solicitacao->setCliente($cliente); | |
$cliente->adicionarSolicitacao($solicitacao); | |
$em->persist($solicitacao); | |
$em->flush(); | |
return $solicitacao; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Ideiah\GestaoQuadra\AgendaBundle\Form; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormBuilderInterface; | |
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | |
class SolicitacaoType extends AbstractType { | |
public function buildForm(FormBuilderInterface $builder, array $options) { | |
$builder | |
->add('nome') | |
->add('rg') | |
->add('cpf','text') | |
->add('email') | |
->add('telefone') | |
->add('dataNascimento', null, array('widget' => 'single_text', | |
'label' => 'Data de Nascimento')) | |
->add('data', null, array('widget' => 'single_text')) | |
->add('hora_inicial', null, array('widget' => 'single_text')) | |
->add('hora_final', null, array('widget' => 'single_text')) | |
->add('obs', null, array('label' => 'Observação')) | |
->add('luz', null, array('label' => 'Com luz', | |
'required' => false)) | |
; | |
} | |
public function setDefaultOptions(OptionsResolverInterface $resolver) { | |
$resolver->setDefaults(array( | |
'data_class' => 'Ideiah\GestaoQuadra\AgendaBundle\Service\Solicitacao' | |
)); | |
} | |
public function getName() { | |
return 'ideiah_gestaoquadra_agendabundle_solicitacaotype'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment