diff --git a/README-LABINVENT.md b/README-LABINVENT.md index 002ea19..29d09a7 100755 --- a/README-LABINVENT.md +++ b/README-LABINVENT.md @@ -51,13 +51,12 @@ Logiciel testé et validé sur les configurations suivantes : VERSION ACTUELLE Date: 29/06/2016 -Version: 2.5.2.0 +Version: 2.5.3.0 -envoi mail ajout document + bugfixes + edition details doc + acl documents + pb saut de ligne champ "text +ajout "administrer" form materiels + index "mes materiels" -Demande (terminé) : https://projects.irap.omp.eu/issues/3913 - https://projects.irap.omp.eu/issues/3716 - https://projects.irap.omp.eu/issues/3912 +Demande (terminé) : https://projects.irap.omp.eu/issues/3906 + https://projects.irap.omp.eu/issues/3916 Version majeure en cours (2.5): https://projects.irap.omp.eu/versions/99 diff --git a/src/Controller/MaterielsController.php b/src/Controller/MaterielsController.php index ef1d046..7c886a3 100755 --- a/src/Controller/MaterielsController.php +++ b/src/Controller/MaterielsController.php @@ -179,9 +179,19 @@ class MaterielsController extends AppController if(isset($GMV)) { $condition = ['Materiels.groupes_metier_id =' => $this->request->query('GMV'), 'Materiels.status =' => 'CREATED', 'Materiels.status !=' => 'ARCHIVED']; } + + $MY = $this->request->query('MY'); + if(isset($MY)) { + if(in_array($this->role, ['Utilisateur', 'Responsable'])) { + $condition = ['Materiels.nom_responsable =' => $this->request->query('MY'), 'Materiels.status !=' => 'ARCHIVED']; + } else { + $condition = ['Materiels.nom_responsable =' => $this->request->query('MY')]; + } + + } - if($this->role == 'Utilisateur') { + if(in_array($this->role, ['Utilisateur', 'Responsable']) && $condition != '') { $condition = ['Materiels.status !=' => 'ARCHIVED']; } @@ -344,6 +354,61 @@ class MaterielsController extends AppController $this->set(compact('materiel', 'surCategories', 'categories', 'sousCategories', 'groupesThematiques', 'groupesMetiers', 'organismes', 'sites', 'utilisateurs', 'mail_responsable')); $this->set('_serialize', ['materiel']); } + + + /** + * Administrer method + * + * @param string|null $id Materiel id. + * @return \Cake\Network\Response|void Redirects on successful edit, renders view otherwise. + * @throws \Cake\Network\Exception\NotFoundException When record not found. + */ + public function administrer($id = null) + { + $materiel = $this->Materiels->get($id, [ + 'contain' => [] + ]); + if ($this->request->is(['patch', 'post', 'put'])) { + $materiel = $this->Materiels->patchEntity($materiel, $this->request->data); + if ($this->Materiels->save($materiel, ['checkRules' => false])) { + $this->Flash->success(__('Le matériel a bien été édité.')); + return $this->redirect(['action' => 'view', $id]); + } else { + $this->Flash->error(__('Le matériel n\'a pas pu être édité.')); + } + } + $surCategories = $this->Materiels->SurCategories->find('list', [ 'keyField' => 'id', 'valueField' => 'nom', 'order' => 'SurCategories.nom']); + $categories = $this->Materiels->Categories->find('list', [ 'keyField' => 'id', 'valueField' => 'nom', 'order' => 'Categories.nom']); + $sousCategories = $this->Materiels->SousCategories->find('list', [ 'keyField' => 'id', 'valueField' => 'nom', 'order' => 'SousCategories.nom']); + $groupesThematiques = $this->Materiels->GroupesThematiques->find('list', [ 'keyField' => 'id', 'valueField' => 'nom', 'order' => 'GroupesThematiques.nom']); + $groupesMetiers = $this->Materiels->GroupesMetiers->find('list', [ 'keyField' => 'id', 'valueField' => 'nom', 'order' => 'GroupesMetiers.nom']); + $organismes = $this->Materiels->Organismes->find('list', [ 'keyField' => 'id', 'valueField' => 'nom', 'order' => 'Organismes.nom']); + $sites = $this->Materiels->Sites->find('list', [ 'keyField' => 'id', 'valueField' => 'nom', 'order' => 'Sites.nom']); + + $users = TableRegistry::get('LdapConnections')->getListUsers(); + //tri des utilisateurs par nom + sort($users); + $utilisateurs = []; + for($i = 0; $i < sizeof($users); $i++) { + $utilisateurs[$users[$i]] = $users[$i]; + } + + if(!empty($materiel->get('nom_responsable'))){ + if(!in_array($materiel->get('nom_responsable'), $utilisateurs)){ + $nom_ancien_responsable = $materiel->get('nom_responsable'); + $this->set(compact('nom_ancien_responsable')); + } + } + $mail_responsable = TableRegistry::get('Users')->find()->select('email')->where(['username =' => $this->LdapAuth->user($this->request->session()->read('authType'))[0]])->first()['email']; + + $this->set('IS_CREATED', $materiel->status == 'CREATED'); + $this->set('IS_VALIDATED', $materiel->status == 'VALIDATED'); + $this->set('IS_ARCHIVED_OR_TOBE', in_array ( $materiel->status, ['TOBEARCHIVED','ARCHIVED'])); + + $this->set(compact('materiel', 'surCategories', 'categories', 'sousCategories', 'groupesThematiques', 'groupesMetiers', 'organismes', 'sites', 'utilisateurs', 'mail_responsable')); + $this->set('_serialize', ['materiel']); + } + /** * Delete method diff --git a/src/Model/Table/MaterielsTable.php b/src/Model/Table/MaterielsTable.php index 0bbcc35..772a455 100755 --- a/src/Model/Table/MaterielsTable.php +++ b/src/Model/Table/MaterielsTable.php @@ -278,6 +278,9 @@ class MaterielsTable extends AppTable public function beforeSave($event, $entity, $options) { + if(!$entity->get('administrer')) { + + if(!empty($entity->get('nom_responsable')) && empty($entity->get('nom_responsable'))){ $entity->set('nom_responsable', $entity->get('nom_ancien_responsable')); } @@ -328,7 +331,8 @@ class MaterielsTable extends AppTable } } - + } + if(empty($entity->get('date_acquisition'))){ $entity->set('date_acquisition', null); } diff --git a/src/Template/Layout/default.ctp b/src/Template/Layout/default.ctp index dfeba1d..a61ffcd 100755 --- a/src/Template/Layout/default.ctp +++ b/src/Template/Layout/default.ctp @@ -94,7 +94,7 @@ $cakeDescription = 'Labinvent 2';