function delete($id = null) { App::Import('Model', 'Planoestudo'); $planoestudos = new Planoestudo(); if (!$id) { $this->Session->setFlash('Invalido codigo para %s', 'flasherror'); $this->redirect(array('action' => 'index')); } $dados = $planoestudos->getAllMatriculasByPlanoEstudo($id); //var_dump($dados); if (empty($dados)) { //////$logmv->logDelete(5,$this->Session->read('Auth.User.id'),$id,$this->data["Planoestudo"]["name"]); $planoestudoano = $planoestudos->deleteAllDisciplinasByPlanoEstudo($id); $planoestudogruposdisc = $planoestudos->deleteAllGrupoDiscByPlanoEstudo($id); if ($this->Planoestudo->delete($id)) { $this->Session->setFlash('Dados deletados com sucesso ', 'flashok'); $this->redirect(array('action' => 'index')); } } $this->Session->setFlash('Nao e possivel apagar. Matriculas Associadas', 'flasherror'); $this->redirect(array('action' => 'index')); }