find()->where(['id =' => 1])->first(); $role = TableRegistry::get('Users')->find()->where(['username' => $user[$configuration->authentificationType_ldap][0]])->first()['role']; $action = $this->request->params['action']; // Super-Admin peut accéder à chaque action if($role == 'Super Administrateur') return true; if (in_array($action, ['view', 'index'])) { return true; } if($this->userHasRole('Administration Plus')) { if($action != 'delete') return true; } return false; } /** * Index method * * @return \Cake\Network\Response|null */ public function index() { $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) { $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->data); 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->data); 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->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']); } }