Example #1
0
 /**
  * view the property selected, if tenant ask for more informations, as him to register
  * @return ViewModel
  */
 public function visualizaAction()
 {
     //save new tenant or get the tenant prior registered
     if ($this->getRequest()->isPost()) {
         //getting posible tenant prior registered
         $criterio = new Criteria();
         $criterio->where($criterio->expr()->eq('nome', $this->getRequest()->getPost('nome')))->andWhere($criterio->expr()->eq('email', $this->getRequest()->getPost('email')))->andWhere($criterio->expr()->eq('foneCelular', $this->getRequest()->getPost('telefone')));
         $locatario = $this->getEm()->getRepository('MyClasses\\Entities\\Locatario')->matching($criterio);
         //if quantity of tenants by criteria above is zero...
         if (!$locatario->count()) {
             //...register new tenant...
             $locatario = new Locatario();
             $locatario->setNome($this->getRequest()->getPost('nome'));
             $locatario->setEmail($this->getRequest()->getPost('email'));
             $locatario->setFoneCelular($this->getRequest()->getPost('telefone'));
             $this->getEm()->persist($locatario);
             $this->getEm()->flush();
             //...else, get the tenant prior registered
         } else {
             $locatario = $locatario->first();
         }
         $this->sessao->locatario = $locatario;
     }
     //get the property and send to view
     if ($this->Params('id')) {
         $imovel = $this->getEm()->getRepository("MyClasses\\Entities\\Imovel")->find($this->Params('id'));
         return new ViewModel(array('imovel' => $imovel, 'mais' => $this->Params('mais'), 'locatario' => $this->sessao->locatario));
     }
 }
 /**
  * {@inheritDoc}
  */
 public function sets(array $atributos)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'sets', array($atributos));
     return parent::sets($atributos);
 }