confLabinvent; * $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; * $action = $this->request->getAttribute('params')['action']; S/ $action = $this->getActionPassed(); $role = $this->getUserRole($user); // Super-Admin peut accéder à chaque action // if($role == 'Super Administrateur') return true; // Administration peut ajouter, supprimer ou modifier un site // if($role == 'Administration' && in_array($action,['add','delete','edit'])) return true; /* * if (in_array($action, ['view', 'index'])) { * return true; * } * * if($this->userHasRoleAtLeast('Administration Plus')) { * if($action != 'delete') return true; * } S/ // return false; return $this->isAuthorizedCommons($user); } */ /** * Index method * * @return \Cake\Network\Response|null */ public function index() { $this->index_generic( 'sites', ['nom'=>[]] ); /* $sites = $this->paginate($this->Sites); $this->set(compact('sites')); $this->set('_serialize', [ 'sites' ]); */ } /** * View method * * @param string|null $id * Site id. * @return \Cake\Network\Response|null * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ public function view($id = null) { return $this->view_generic($id, ['Emprunts', 'Materiels', 'Users']); /* $site = $this->Sites->get($id, [ 'contain' => [ 'Materiels' ] ]); $materiels = TableRegistry::get('Materiels')->find('all')->where([ 'site_id =' => $id ]); $this->set('materiels', $materiels); $emprunts = TableRegistry::get('Emprunts')->find('all')->where([ 'site_id =' => $id ]); $this->set('emprunts', $emprunts); $this->set('site', $site); $this->set('_serialize', [ 'site' ]); */ } /** * Add method * * @return \Cake\Network\Response|void Redirects on successful add, renders view otherwise. */ public function add() { $site = $this->Sites->newEntity(); if ($this->request->is('post')) { $site = $this->Sites->patchEntity($site, $this->request->getData()); if ($this->Sites->save($site)) { $this->Flash->success(__('Le site a bien été ajouté.')); return $this->redirect([ 'action' => 'view', $site->id ]); } else { $this->Flash->error(__('Le site n\'a pas pu être ajouté.')); } } $this->set(compact('site')); $this->set('_serialize', [ 'site' ]); } /** * Edit method * * @param string|null $id * Site id. * @return \Cake\Network\Response|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Network\Exception\NotFoundException When record not found. */ public function edit($id = null) { $site = $this->Sites->get($id, [ 'contain' => [] ]); if ($this->request->is([ 'patch', 'post', 'put' ])) { $site = $this->Sites->patchEntity($site, $this->request->getData()); if ($this->Sites->save($site)) { $this->Flash->success(__('Le site a bien été édité.')); return $this->redirect([ 'action' => 'view', $id ]); } else { $this->Flash->error(__('Le site n\a pas pu être édité.')); } } $this->set(compact('site')); $this->set('_serialize', [ 'site' ]); } /** * Delete method * * @param string|null $id * Site id. * @return \Cake\Network\Response|null Redirects to index. * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. */ public function delete($id = null) { $this->delete_generic($id); /* $this->request->allowMethod([ 'post', 'delete' ]); $site = $this->Sites->get($id); if ($this->Sites->delete($site)) { $this->Flash->success(__('Le site a bien été supprimé.')); } else { $this->Flash->error(__('Le site n\a pas pu être supprimé.')); } return $this->redirect([ 'action' => 'index' ]); */ } }