Commit 70d6a38a authored by Ghislain Loas's avatar Ghislain Loas
Browse files

dev #72825 change export json to csv

parent 42c7c08f
Pipeline #4460 failed with stage
in 33 minutes and 43 seconds
......@@ -400,7 +400,7 @@ class AbonneController extends ZendAfi_Controller_Action {
$id_pret = $this->_getParam('id_pret');
$ids = array_filter(explode(';', $id_pret));
if (!count($ids)) {
$this->_renderExtendPopup([$this->_('Aucune prolongation éffectué.')]);
$this->_renderExtendPopup([$this->_('Aucune prolongation éffectuée.')]);
return;
}
......@@ -1021,22 +1021,24 @@ class AbonneController extends ZendAfi_Controller_Action {
public function barcodesExportAction() {
$this->_helper->viewRenderer->setNoRender();
$datas = [];
$emprunts = $this->_user->getLoansWithoutPNB($this->_request->getParams());
foreach($emprunts as $emprunt) {
if (!$exemplaire = $emprunt->getExemplaireOPAC())
continue;
$datas[] = (string) $exemplaire->getCodeBarres();
}
$filename = $this->_('prets_codes_barres_%s_%s%s',
$this->_user->getId(),
uniqid(),
'.json');
$this->_helper->binaryDownload(json_encode(array_filter($datas)), $filename);
'.csv');
$description = (new Class_TableDescription('loans-barcodes'))
->addColumn('', function($loan)
{
return $loan->getCodeBarre();
});
$datas = array_filter($this->_user
->getLoansWithoutPNB($this->_request->getParams())
->getArrayCopy());
$this->_helper->csv($filename,
$this->view->renderCsv($description,
$datas));
}
......
......@@ -1104,16 +1104,10 @@ class AbonneControllerPretsListMoreThanUndredHoldsTest extends AbonneControllerP
class AbonneControllerBarcodesExportThreePretsTest extends AbonneControllerPretsListThreePretsTestCase {
protected
$_dl_file,
$_json = ['124', '123'];
public function setUp() {
parent::setUp();
$this->dispatch('abonne/barcodes-export', true);
$this->_dl_file = tempnam('/tmp', 'JSON');
file_put_contents($this->_dl_file, $this->_response->getBody());
$this->_json = json_encode($this->_json);
}
......@@ -1131,14 +1125,9 @@ class AbonneControllerBarcodesExportThreePretsTest extends AbonneControllerPrets
/** @test */
public function bodyShouldContainsJsons() {
$this->assertSame($this->_json, $this->_response->getBody());
}
/** @test */
public function dlFileShouldContainsJson() {
$this->assertEquals($this->_json, file_get_contents($this->_dl_file));
public function bodyShouldContainsBarCodes() {
$this->assertContains('124', $this->_response->getBody());
$this->assertContains('123', $this->_response->getBody());
}
}
......
......@@ -206,7 +206,7 @@ abstract class HandleOnholdDispatchTestCase extends HandleOnholdTestCase {
/** @test */
public function exportJsonShouldBeDisplay() {
public function exportBarcodesShouldBeDisplay() {
$this->dispatch('/opac/abonne/prets/onhold/yes', true);
$this->assertXPathContentContains('//a[contains(@href, "abonne/barcodes-export/onhold/yes")]', 'Export codes barres');
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment