/** * Delete method * * @param string|null $id Projeto id. * @return void Redirects to index. * @throws \Cake\Network\Exception\NotFoundException When record not found. */ public function delete($id = null) { $this->request->allowMethod(['post', 'delete', 'get']); $projeto = $this->Projeto->get($id); $projeto->historico = true; $temAluno = $this->Projeto->Usuario->find('all', ['conditions' => ['usuario.idProjeto' => $id, 'usuario.historico' => 0]])->count() > 0; if (!$temAluno) { if ($this->Projeto->save($projeto)) { $ldap = new LDAP(3); if (!$ldap->disponivel($projeto->user)) { $ldap->removeUser($projeto->user); } $ldap->removeGroup($projeto->grupo); $this->Flash->success(__('Projeto Excluido.')); return $this->redirect(['action' => 'index']); } else { $this->Flash->error(__('Projeto não pode ser excluído.')); return $this->redirect(['action' => 'index']); } } else { $this->Flash->error(__('Projeto não pode ser excluído pois contém alunos vinculados.')); return $this->redirect(['action' => 'index']); } }