aauth = new Aauth(); $this->request = Services::request(); helper('form'); helper('aauth'); } /** * Index * * @return void */ public function index() { $data = $this->aauth->listGroupsPaginated(); $data['cssFiles'] = [ '/assets/css/admin/groups/index.css' ]; echo view('Templates/HeaderAdmin', $data); echo view('Admin/Groups/Home', $data); echo view('Templates/FooterAdmin'); } /** * New * * @return void */ public function new() { echo view('Templates/HeaderAdmin'); echo view('Admin/Groups/New'); echo view('Templates/FooterAdmin'); } /** * Create * * @return void */ public function create() { $name = $this->request->getPost('name'); $definition = $this->request->getPost('definition'); if (! $this->aauth->createGroup($name, $definition)) { return redirect()->back()->with('errors', $this->aauth->getErrorsArray()); } return redirect()->to('/admin/groups'); } /** * Edit * * @return void */ public function edit($groupId) { $data['group'] = $this->aauth->getGroup($groupId); echo view('Templates/HeaderAdmin'); echo view('Admin/Groups/Edit', $data); echo view('Templates/FooterAdmin'); } /** * Update * * @return void */ public function update($groupId) { $name = $this->request->getPost('name'); $definition = $this->request->getPost('definition'); if (! $this->aauth->updateGroup($groupId, empty($name) ? null : $name, empty($definition) ? null : $definition)) { return redirect()->back()->with('errors', $this->aauth->getErrorsArray()); } return redirect()->to('/admin/groups/edit/' . $groupId); } /** * Show * * @return void */ public function show($groupId) { $data['group'] = $this->aauth->getGroup($groupId); echo view('Templates/HeaderAdmin'); echo view('Admin/Groups/Show', $data); echo view('Templates/FooterAdmin'); } /** * Delete * * @return void */ public function delete($groupId) { if (! $this->aauth->getGroup($groupId)) { return redirect()->to('/admin/groups'); } $id = $this->request->getPost('id'); if ($groupId === $id) { if ($this->aauth->deleteGroup($groupId)) { return redirect()->to('/admin/groups'); } } $data['group'] = $this->aauth->getGroup($groupId); echo view('Templates/HeaderAdmin'); echo view('Admin/Groups/Delete', $data); echo view('Templates/FooterAdmin'); } }