Example #1
0
 /**
  * Edita uma reunião já existente
  * 
  * @return type
  */
 public function editarAction()
 {
     $form = new Editar();
     if ($this->isPost()) {
         // Id deve vir por parametro
         $idReuniao = $this->getParam('id', false);
         if ($form->isValid()) {
             $data = $form->getData();
             Database::beginTransaction();
             try {
                 // Deleta todos os adeptos desta reuniao para adicionar tudo novamente
                 $reuniaoAdeptoBo = new ReuniaoAdeptoBusiness();
                 $reuniaoAdeptoBo->deleteAdeptosDaReuniao($idReuniao);
                 // Cadastra adeptos na reuniao
                 foreach ($data['adeptos'] as $idAdepto) {
                     $reuniaoAdeptoBo->insert(array('fk_reuniao' => $idReuniao, 'fk_adepto' => $idAdepto));
                 }
                 Database::commit();
                 // Add mensagem e redireciona
                 $this->addMsg("Reunião cadastrada com sucesso", MsgType::SUCCESS, true);
             } catch (Exception $ex) {
                 Database::rollBack();
                 $this->addMsg("Erro inesperado, tente novamente", MsgType::DANGER, true);
                 $this->addMsg($ex->getMessage(), MsgType::DANGER, true);
             }
         } else {
             $this->addMsg("Seu formulário não foi preenchido corretamente, tente novamente", MsgType::DANGER, true);
             return $this->redirect("/reuniao/adicionar");
         }
     } else {
         $this->addMsg("Nada foi alterado, tente novamente", MsgType::DANGER, true);
         return $this->redirect("/reuniao/adicionar");
     }
     // Redireciona para o relatorio
     $dataTratada = implode('-', array_reverse(explode('/', $_POST['data'])));
     return $this->redirect("/relatorio/anual?al=" . $_POST['al'] . "&ano=" . date('Y', strtotime($dataTratada)));
 }