From be4bd7aa8933e7d9e16a9973ce5949219f7e272a Mon Sep 17 00:00:00 2001 From: Etienne Pallier Date: Fri, 7 Jun 2019 16:43:46 +0200 Subject: [PATCH] Export materiels CSV trié par numéro labo (décroissant) --- README.md | 2 +- src/Controller/MaterielsController.php | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 79 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 211eb1b..7f7ea71 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Logiciel testé et validé sur les configurations suivantes : VERSION ACTUELLE Date: 07/06/2019 -Version: 2.13.1 +Version: 2.13.2 Author: EP Commentaire: LDAP CACHED cleanup diff --git a/src/Controller/MaterielsController.php b/src/Controller/MaterielsController.php index 7731e98..9fc747d 100755 --- a/src/Controller/MaterielsController.php +++ b/src/Controller/MaterielsController.php @@ -2257,7 +2257,9 @@ class MaterielsController extends AppController return $ISOK ? $listName[$materiel->$fkName] : ""; } - $materiels = NULL; + //$materiels = NULL; + $materiels = []; + $surCategories = $this->Materiels->SurCategories->find('list', [ 'keyField' => 'id', 'valueField' => 'nom' @@ -2288,10 +2290,12 @@ class MaterielsController extends AppController ])->toArray(); $what = ''; $this->myDebug($this->request->getData()); - + + // Critères pour requete sql sur materiels $contain = ['Fournisseurs']; + $order = ['numero_laboratoire' => 'DESC']; - // EXPORT SELECTED materiels only + // CAS 1 - EXPORT SELECTED materiels only if ($this->request->getData('export') !== null) { $this->myDebug("IN EXPORT"); $what = $this->request->getData('what'); @@ -2309,52 +2313,90 @@ class MaterielsController extends AppController } $this->myDebug($selectedMateriels); + /* // Si la liste de materiels cochés est vide, ne rien faire if (empty($selectedMateriels)) { if ($what != '' && $what != 'search') return $this->redirect(['action' => 'index', $what]); else if ($what == 'search') return $this->redirect('javascript:window.history.go(-3)'); else return $this->redirect(['action' => 'index']); } + */ //if (sizeof($selectedMateriels) > 0) { - $materiels = $this->Materiels->find('all') - ->where(['Materiels.id' => $selectedMateriels[0]]) - ->contain($contain); - - for ($j = 0; $j < sizeof($selectedMateriels); $j ++) { - $materiels->orWhere([ - 'Materiels.id' => $selectedMateriels[$j] - ]); + if (! empty($selectedMateriels)) { + /* + $materiels = $this->Materiels->find('all') + ->where(['Materiels.id' => $selectedMateriels[0]]) + ->contain($contain); + for ($j = 0; $j < sizeof($selectedMateriels); $j ++) { + $materiels->orWhere([ + 'Materiels.id' => $selectedMateriels[$j] + ]); + } + */ + //$materielsTable = TableRegistry::getTableLocator()->get('Materiels'); + //$materiels = $materielsTable->find() + $materiels = $this->Materiels->find() + ->contain($contain) + ->where(['Materiels.id' => $selectedMateriels[0]]); + for ($j = 0; $j < sizeof($selectedMateriels); $j ++) + $materiels->orWhere( ['Materiels.id' => $selectedMateriels[$j]] ); + $materiels->order($order); + /* + $materiels = $this->Materiels->find() + ->contain($contain) + ->where([ + //'OR' => [['id' => 2], ['id' => 10]], + 'OR' => [$selectedMateriels], + ]); + */ } //$this->myDebug($materiels); //} - // EXPORT ALL materiels + // CAS 2 - EXPORT ALL materiels } else if ($this->request->getData('exportAll') !== null) { - $this->myDebug("IN EXPORTALL"); + $this->myDebug("IN EXPORT ALL"); + // Exporte seulement les materiels du statut coché if ($this->request->getData('what') !== null) { $what = $this->request->getData('what'); $status = $what; + /* $materiels = $this->Materiels->find('all', [ 'conditions' => [ 'Materiels.status =' => $status ], 'contain' => $contain ]); + */ + $materiels = $this->Materiels + ->find() + ->where(['Materiels.status =' => $status]) + ->contain($contain) + ->order($order); + + // Exporte seulement TOUS les materiels (sauf ARCHIVED) } else { $status = 'ARCHIVED'; + /* $materiels = $this->Materiels->find('all', [ 'conditions' => [ 'Materiels.status !=' => $status ], 'contain' => $contain ]); + */ + $materiels = $this->Materiels + ->find() + ->where(['Materiels.status !=' => $status]) + ->contain($contain) + ->order($order); } $this->myDebug("what is " . $what); $this->myDebug("statut is " . $status); - // OTHER CASE 3 + // CAS 3 (search) } else if (isset($this->request->getAttribute('params')['pass'][0])) { $this->myDebug("OTHER CASE 3"); $what = $this->request->getAttribute('params')['pass'][0]; @@ -2363,17 +2405,37 @@ class MaterielsController extends AppController $materiels = $this->request->getSession()->read("result"); } - // OTHER CASE 4 + // CAS 4 (???) - Tous les matériels (sauf ARCHIVED) } else { $this->myDebug("OTHER CASE 4"); + /* $materiels = $this->Materiels->find('all', [ 'conditions' => [ 'Materiels.status !=' => 'ARCHIVED' ], 'contain' => $contain ]); + */ + $materiels = $this->Materiels + ->find() + ->where(['Materiels.status !=' => 'ARCHIVED']) + ->contain($contain) + ->order($order); + } + + // (EP) Si aucun materiel retourné par la sélection => terminé, ne rien faire, basta + if (empty($materiels)) { + if ($what != '' && $what != 'search') return $this->redirect(['action' => 'index', $what]); + else if ($what == 'search') return $this->redirect('javascript:window.history.go(-3)'); + else return $this->redirect(['action' => 'index']); } + /* + // (EP ) Tri des materiels par numéro inventaire + $num_labos = array_column($materiels->toArray(), 'numero_laboratoire'); + // Ajoute $materiels en tant que dernier paramètre, pour trier par la clé commune + array_multisort($num_labos, SORT_DESC, $materiels->toArray()); + */ // NOW, CREATE THE CSV file from $materiels @@ -2381,7 +2443,7 @@ class MaterielsController extends AppController //$this->myDebug("Nb matos = " . count($materiels)); //$this->myDebug($materiels, true); - $this->myDebug($materiels); + //$this->myDebug($materiels); ini_set('max_execution_time', 600); -- libgit2 0.21.2