Esempio n. 1
0
 /**
  * Remove um registro do banco de dados.
  * 
  * @return type
  */
 public function delete(array $where)
 {
     $this->checkGateway();
     // Monta query
     $sql = "DELETE FROM " . $this->name . " WHERE ";
     foreach ($where as $column => $value) {
         // Parametro na query
         $sql .= $column . " = :" . $column . " AND ";
         // Parametro, query segura
         $this->db->bind($column, $value);
     }
     $sql = preg_replace("/\\sAND\\s\$/", '', $sql);
     // Resultado
     return (bool) $this->db->query($sql);
 }
Esempio n. 2
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)));
 }