Commit be4bd7aa8933e7d9e16a9973ce5949219f7e272a
1 parent
01c4ee29
Exists in
master
and in
2 other branches
Export materiels CSV trié par numéro labo (décroissant)
https://projects.irap.omp.eu/issues/6982
Showing
2 changed files
with
79 additions
and
17 deletions
Show diff stats
README.md
src/Controller/MaterielsController.php
... | ... | @@ -2257,7 +2257,9 @@ class MaterielsController extends AppController |
2257 | 2257 | return $ISOK ? $listName[$materiel->$fkName] : ""; |
2258 | 2258 | } |
2259 | 2259 | |
2260 | - $materiels = NULL; | |
2260 | + //$materiels = NULL; | |
2261 | + $materiels = []; | |
2262 | + | |
2261 | 2263 | $surCategories = $this->Materiels->SurCategories->find('list', [ |
2262 | 2264 | 'keyField' => 'id', |
2263 | 2265 | 'valueField' => 'nom' |
... | ... | @@ -2288,10 +2290,12 @@ class MaterielsController extends AppController |
2288 | 2290 | ])->toArray(); |
2289 | 2291 | $what = ''; |
2290 | 2292 | $this->myDebug($this->request->getData()); |
2291 | - | |
2293 | + | |
2294 | + // Critères pour requete sql sur materiels | |
2292 | 2295 | $contain = ['Fournisseurs']; |
2296 | + $order = ['numero_laboratoire' => 'DESC']; | |
2293 | 2297 | |
2294 | - // EXPORT SELECTED materiels only | |
2298 | + // CAS 1 - EXPORT SELECTED materiels only | |
2295 | 2299 | if ($this->request->getData('export') !== null) { |
2296 | 2300 | $this->myDebug("IN EXPORT"); |
2297 | 2301 | $what = $this->request->getData('what'); |
... | ... | @@ -2309,52 +2313,90 @@ class MaterielsController extends AppController |
2309 | 2313 | } |
2310 | 2314 | |
2311 | 2315 | $this->myDebug($selectedMateriels); |
2316 | + /* | |
2312 | 2317 | // Si la liste de materiels cochés est vide, ne rien faire |
2313 | 2318 | if (empty($selectedMateriels)) { |
2314 | 2319 | if ($what != '' && $what != 'search') return $this->redirect(['action' => 'index', $what]); |
2315 | 2320 | else if ($what == 'search') return $this->redirect('javascript:window.history.go(-3)'); |
2316 | 2321 | else return $this->redirect(['action' => 'index']); |
2317 | 2322 | } |
2323 | + */ | |
2318 | 2324 | |
2319 | 2325 | //if (sizeof($selectedMateriels) > 0) { |
2320 | - $materiels = $this->Materiels->find('all') | |
2321 | - ->where(['Materiels.id' => $selectedMateriels[0]]) | |
2322 | - ->contain($contain); | |
2323 | - | |
2324 | - for ($j = 0; $j < sizeof($selectedMateriels); $j ++) { | |
2325 | - $materiels->orWhere([ | |
2326 | - 'Materiels.id' => $selectedMateriels[$j] | |
2327 | - ]); | |
2326 | + if (! empty($selectedMateriels)) { | |
2327 | + /* | |
2328 | + $materiels = $this->Materiels->find('all') | |
2329 | + ->where(['Materiels.id' => $selectedMateriels[0]]) | |
2330 | + ->contain($contain); | |
2331 | + for ($j = 0; $j < sizeof($selectedMateriels); $j ++) { | |
2332 | + $materiels->orWhere([ | |
2333 | + 'Materiels.id' => $selectedMateriels[$j] | |
2334 | + ]); | |
2335 | + } | |
2336 | + */ | |
2337 | + //$materielsTable = TableRegistry::getTableLocator()->get('Materiels'); | |
2338 | + //$materiels = $materielsTable->find() | |
2339 | + $materiels = $this->Materiels->find() | |
2340 | + ->contain($contain) | |
2341 | + ->where(['Materiels.id' => $selectedMateriels[0]]); | |
2342 | + for ($j = 0; $j < sizeof($selectedMateriels); $j ++) | |
2343 | + $materiels->orWhere( ['Materiels.id' => $selectedMateriels[$j]] ); | |
2344 | + $materiels->order($order); | |
2345 | + /* | |
2346 | + $materiels = $this->Materiels->find() | |
2347 | + ->contain($contain) | |
2348 | + ->where([ | |
2349 | + //'OR' => [['id' => 2], ['id' => 10]], | |
2350 | + 'OR' => [$selectedMateriels], | |
2351 | + ]); | |
2352 | + */ | |
2328 | 2353 | } |
2329 | 2354 | //$this->myDebug($materiels); |
2330 | 2355 | //} |
2331 | 2356 | |
2332 | - // EXPORT ALL materiels | |
2357 | + // CAS 2 - EXPORT ALL materiels | |
2333 | 2358 | } else if ($this->request->getData('exportAll') !== null) { |
2334 | - $this->myDebug("IN EXPORTALL"); | |
2359 | + $this->myDebug("IN EXPORT ALL"); | |
2335 | 2360 | |
2361 | + // Exporte seulement les materiels du statut coché | |
2336 | 2362 | if ($this->request->getData('what') !== null) { |
2337 | 2363 | $what = $this->request->getData('what'); |
2338 | 2364 | $status = $what; |
2365 | + /* | |
2339 | 2366 | $materiels = $this->Materiels->find('all', [ |
2340 | 2367 | 'conditions' => [ |
2341 | 2368 | 'Materiels.status =' => $status |
2342 | 2369 | ], |
2343 | 2370 | 'contain' => $contain |
2344 | 2371 | ]); |
2372 | + */ | |
2373 | + $materiels = $this->Materiels | |
2374 | + ->find() | |
2375 | + ->where(['Materiels.status =' => $status]) | |
2376 | + ->contain($contain) | |
2377 | + ->order($order); | |
2378 | + | |
2379 | + // Exporte seulement TOUS les materiels (sauf ARCHIVED) | |
2345 | 2380 | } else { |
2346 | 2381 | $status = 'ARCHIVED'; |
2382 | + /* | |
2347 | 2383 | $materiels = $this->Materiels->find('all', [ |
2348 | 2384 | 'conditions' => [ |
2349 | 2385 | 'Materiels.status !=' => $status |
2350 | 2386 | ], |
2351 | 2387 | 'contain' => $contain |
2352 | 2388 | ]); |
2389 | + */ | |
2390 | + $materiels = $this->Materiels | |
2391 | + ->find() | |
2392 | + ->where(['Materiels.status !=' => $status]) | |
2393 | + ->contain($contain) | |
2394 | + ->order($order); | |
2353 | 2395 | } |
2354 | 2396 | $this->myDebug("what is " . $what); |
2355 | 2397 | $this->myDebug("statut is " . $status); |
2356 | 2398 | |
2357 | - // OTHER CASE 3 | |
2399 | + // CAS 3 (search) | |
2358 | 2400 | } else if (isset($this->request->getAttribute('params')['pass'][0])) { |
2359 | 2401 | $this->myDebug("OTHER CASE 3"); |
2360 | 2402 | $what = $this->request->getAttribute('params')['pass'][0]; |
... | ... | @@ -2363,17 +2405,37 @@ class MaterielsController extends AppController |
2363 | 2405 | $materiels = $this->request->getSession()->read("result"); |
2364 | 2406 | } |
2365 | 2407 | |
2366 | - // OTHER CASE 4 | |
2408 | + // CAS 4 (???) - Tous les matériels (sauf ARCHIVED) | |
2367 | 2409 | } else { |
2368 | 2410 | $this->myDebug("OTHER CASE 4"); |
2411 | + /* | |
2369 | 2412 | $materiels = $this->Materiels->find('all', [ |
2370 | 2413 | 'conditions' => [ |
2371 | 2414 | 'Materiels.status !=' => 'ARCHIVED' |
2372 | 2415 | ], |
2373 | 2416 | 'contain' => $contain |
2374 | 2417 | ]); |
2418 | + */ | |
2419 | + $materiels = $this->Materiels | |
2420 | + ->find() | |
2421 | + ->where(['Materiels.status !=' => 'ARCHIVED']) | |
2422 | + ->contain($contain) | |
2423 | + ->order($order); | |
2424 | + } | |
2425 | + | |
2426 | + // (EP) Si aucun materiel retourné par la sélection => terminé, ne rien faire, basta | |
2427 | + if (empty($materiels)) { | |
2428 | + if ($what != '' && $what != 'search') return $this->redirect(['action' => 'index', $what]); | |
2429 | + else if ($what == 'search') return $this->redirect('javascript:window.history.go(-3)'); | |
2430 | + else return $this->redirect(['action' => 'index']); | |
2375 | 2431 | } |
2376 | 2432 | |
2433 | + /* | |
2434 | + // (EP ) Tri des materiels par numéro inventaire | |
2435 | + $num_labos = array_column($materiels->toArray(), 'numero_laboratoire'); | |
2436 | + // Ajoute $materiels en tant que dernier paramètre, pour trier par la clé commune | |
2437 | + array_multisort($num_labos, SORT_DESC, $materiels->toArray()); | |
2438 | + */ | |
2377 | 2439 | |
2378 | 2440 | // NOW, CREATE THE CSV file from $materiels |
2379 | 2441 | |
... | ... | @@ -2381,7 +2443,7 @@ class MaterielsController extends AppController |
2381 | 2443 | //$this->myDebug("Nb matos = " . count($materiels)); |
2382 | 2444 | |
2383 | 2445 | //$this->myDebug($materiels, true); |
2384 | - $this->myDebug($materiels); | |
2446 | + //$this->myDebug($materiels); | |
2385 | 2447 | |
2386 | 2448 | ini_set('max_execution_time', 600); |
2387 | 2449 | ... | ... |