Commit a1cdb47c authored by Ghislain Loas's avatar Ghislain Loas
Browse files

dev #72825 add barcodes export

parent 684086bb
Pipeline #4431 failed with stage
in 34 minutes
......@@ -1014,6 +1014,26 @@ 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);
}
public function manageSettingsAction() {
if(!Class_Users::getIdentity())
return $this->_forward('popup-login', 'auth', 'opac', ['redirect' => $this->view->url()]);
......
......@@ -207,6 +207,22 @@ class Class_Profil_Preferences_Loans {
$view = $view_helper->view;
$form = ZendAfi_Form_User_LoanSearch::newWith($view_helper->getRequestParams());
return $view->renderForm($form);
}),
(new Class_Entity(['Id' => 'export_barcodes',
'Label' => $this->_('Export des codes barres')]))
->whenCalledDo('renderWith', function($view_helper)
{
$loans = $view_helper->getLoans();
$view = $view_helper->view;
return ($loans->isEmpty())
? ''
: $view->tagAnchor(
$view->url(['controller' => 'abonne',
'action' => 'barcodes-export']),
$this->_('Export des codes barres'),
['class' => 'loan-export']);
})];
}
......
......@@ -27,8 +27,7 @@ class ZendAfi_View_Helper_Abonne_LoanExport extends ZendAfi_View_Helper_Abonne_A
return $this->view->tagAnchor($this->view->url(['controller' => 'abonne',
'action' => 'loan-export']),
$this->view->_('Export unimarc'),
$this->view->_('Export Unimarc'),
['class' => 'loan-export']);
}
}
?>
\ No newline at end of file
}
\ No newline at end of file
......@@ -1091,4 +1091,46 @@ class AbonneControllerPretsListMoreThanUndredHoldsTest extends AbonneControllerP
public function tooManyHoldsMessageShouldBePresent() {
$this->assertXPathContentContains('//p[@class="error"]', 'L\'enrichissement des documents');
}
}
\ No newline at end of file
}
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);
}
/** @test */
public function responseBodyShouldBeAttachment() {
$this->assertHeaderContains('Content-Disposition', 'attachment');
}
/** @test */
public function responseFileNameShouldContainsPrets() {
$this->assertHeaderContains('Content-Disposition', 'filename="prets_codes_barres_');
$this->assertHeaderContains('Content-Type', 'name="prets_codes_barres_');
}
/** @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));
}
}
......@@ -47,7 +47,7 @@ abstract class HandleOnholdTestCase extends AbstractControllerTestCase {
(new Class_Entity())
->setController('abonne')
->setAction('prets'),
['tools_composition' => 'search_tool;export_unimarc;extend_all',
['tools_composition' => 'search_tool;export_barcodes;export_unimarc;extend_all',
'table_composition' => 'loaned_by;doctype;thumbnail;title;author;library;return_date;onhold']);
$this->_ilsdi = 'http://chamb.com/koha/ilsdi.pl';
......@@ -185,6 +185,27 @@ abstract class HandleOnholdDispatchTestCase extends HandleOnholdTestCase {
$this->dispatch('/opac/abonne/prets/start_issue_date/12%2F06%2F2015/end_issue_date/12%2F06%2F2019/start_date_retour/20%2F06%2F2015/end_date_retour/20%2F06%2F2019/onhold//', true);
$this->assertXPath('//input' . $params);
}
/** @test */
public function extendAllShouldBeDisplay() {
$this->dispatch('/opac/abonne/prets/', true);
$this->assertXPathContentContains('//a', 'Tout prolonger');
}
/** @test */
public function exportUnimarcShouldBeDisplay() {
$this->dispatch('/opac/abonne/prets/onhold/yes', true);
$this->assertXPathContentContains('//a[contains(@href, "abonne/loan-export/onhold/yes")]', 'Export Unimarc');
}
/** @test */
public function exportJsonShouldBeDisplay() {
$this->dispatch('/opac/abonne/prets/onhold/yes', true);
$this->assertXPathContentContains('//a[contains(@href, "abonne/barcodes-export/onhold/yes")]', 'Export des 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