Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
afi
opacce
Commits
fcac722b
Commit
fcac722b
authored
Mar 16, 2018
by
Patrick Barroca
😁
Browse files
dev #17352 : download raw record action
parent
bfecd191
Pipeline
#3689
passed with stage
in 30 minutes and 47 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
103 additions
and
28 deletions
+103
-28
application/modules/opac/controllers/AbonneController.php
application/modules/opac/controllers/AbonneController.php
+1
-6
application/modules/opac/controllers/RechercheController.php
application/modules/opac/controllers/RechercheController.php
+10
-21
library/Class/Cosmogramme/Integration/RawRecord.php
library/Class/Cosmogramme/Integration/RawRecord.php
+41
-1
library/ZendAfi/Controller/Action/Helper/BinaryDownload.php
library/ZendAfi/Controller/Action/Helper/BinaryDownload.php
+51
-0
No files found.
application/modules/opac/controllers/AbonneController.php
View file @
fcac722b
...
...
@@ -988,13 +988,8 @@ class AbonneController extends ZendAfi_Controller_Action {
$datas
[]
=
$exemplaire
->
toUnimarcIso2709
();
}
$response
=
$this
->
_response
;
$response
->
clearAllHeaders
();
$filename
=
'prets_'
.
$this
->
_user
->
getId
()
.
'-'
.
uniqid
()
.
'.txt'
;
$response
->
setHeader
(
'Content-Type'
,
'application/octet-stream; name="'
.
$filename
.
'"'
,
true
);
$response
->
setHeader
(
'Content-Disposition'
,
'attachment; filename="'
.
$filename
.
'"'
,
true
);
$response
->
setBody
(
implode
(
''
,
$datas
));
$this
->
_helper
->
binaryDownload
(
implode
(
$datas
),
$filename
);
}
...
...
application/modules/opac/controllers/RechercheController.php
View file @
fcac722b
...
...
@@ -749,32 +749,21 @@ class RechercheController extends ZendAfi_Controller_Action {
public
function
downloadRecordAction
()
{
if
(
!
$record
=
Class_Notice
::
find
(
$this
->
_getParam
(
'id'
,
0
)))
{
$this
->
_redirect
(
'/'
);
return
;
}
if
(
!
$record
=
Class_Notice
::
find
(
$this
->
_getParam
(
'id'
,
0
)))
return
$this
->
_redirect
(
'/'
);
$this
->
_helper
->
getHelper
(
'ViewRenderer'
)
->
setNoRender
(
true
);
if
(
$layout
=
Zend_Layout
::
getMvcInstance
())
$layout
->
disableLayout
();
$response
=
Zend_Controller_Front
::
getInstance
()
->
getResponse
();
$response
->
canSendHeaders
(
true
);
$this
->
_helper
->
binaryDownload
(
$record
->
getUnimarc
(),
$record
->
getId
()
.
'.txt'
);
}
$response
->
clearAllHeaders
();
$response
->
setHeader
(
'Content-Type'
,
'application/octet-stream; name="'
.
$record
->
getId
()
.
'.txt"'
,
true
);
$response
->
setHeader
(
'Content-Transfer-Encoding'
,
'binary'
,
true
);
$unimarc
=
$record
->
getUnimarc
();
$response
->
setHeader
(
'Content-Length'
,
strlen
(
$unimarc
),
true
);
$response
->
setHeader
(
'Expires'
,
'0'
);
$response
->
setHeader
(
'Cache-Control'
,
'no-cache, must-revalidate'
);
$response
->
setHeader
(
'Pragma'
,
'no-cache'
);
$response
->
setHeader
(
'Content-Disposition'
,
'attachment; filename="'
.
$record
->
getId
()
.
'.txt"'
,
true
);
public
function
downloadItemAction
()
{
if
(
!
$item
=
Class_Exemplaire
::
find
(
$this
->
_getParam
(
'id'
,
0
)))
return
$this
->
_redirect
(
'/'
);
$response
->
sendHeaders
();
if
(
!
$raw_record
=
Class_Cosmogramme_Integration_RawRecord
::
findFor
(
$item
))
return
$this
->
_redirect
(
'/'
);
echo
$unimarc
;
$this
->
_helper
->
binaryDownload
(
$raw_record
->
getData
(),
$raw_record
->
getName
())
;
}
...
...
library/Class/Cosmogramme/Integration/RawRecord.php
View file @
fcac722b
...
...
@@ -26,7 +26,8 @@ class Class_Cosmogramme_Integration_RawRecord {
protected
$_library_id
,
$_data
,
$_id
;
$_id
,
$_date
;
public
static
function
hasVersionFor
(
$item
)
{
return
(
new
static
(
''
,
$item
->
getIdOrigine
(),
$item
->
getIdIntBib
()))
...
...
@@ -34,6 +35,14 @@ class Class_Cosmogramme_Integration_RawRecord {
}
public
static
function
findFor
(
$item
)
{
$instance
=
new
static
(
''
,
$item
->
getIdOrigine
(),
$item
->
getIdIntBib
());
return
(
$instance
=
$instance
->
loadLastVersion
())
?
$instance
:
null
;
}
public
function
__construct
(
$data
,
$id
,
$library_id
)
{
$this
->
_library_id
=
$library_id
;
$this
->
_data
=
$data
;
...
...
@@ -51,9 +60,40 @@ class Class_Cosmogramme_Integration_RawRecord {
}
public
function
getData
()
{
return
$this
->
_data
;
}
public
function
getName
()
{
return
'raw_record_'
.
implode
(
'_'
,
[
$this
->
_library_id
,
$this
->
_id
,
$this
->
_humanDate
()]);
}
public
function
save
()
{
$this
->
newVersionWith
([
'id'
=>
$this
->
_id
,
'library_id'
=>
$this
->
_library_id
,
'data'
=>
$this
->
_data
]);
}
public
function
loadLastVersion
()
{
if
(
!
$version
=
$this
->
getLastVersion
())
return
;
$this
->
_data
=
$version
->
getData
()[
'data'
];
$this
->
_date
=
$version
->
getDate
();
return
$this
;
}
protected
function
_humanDate
()
{
return
$this
->
_date
?
date
(
'Y-m-d'
,
$this
->
_date
)
:
''
;
}
}
library/ZendAfi/Controller/Action/Helper/BinaryDownload.php
0 → 100644
View file @
fcac722b
<?php
/**
* Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class
ZendAfi_Controller_Action_Helper_BinaryDownload
extends
Zend_Controller_Action_Helper_Abstract
{
public
function
direct
(
$content
,
$filename
)
{
Zend_Controller_Action_HelperBroker
::
getStaticHelper
(
'viewRenderer'
)
->
setNoRender
(
true
);
if
(
$layout
=
Zend_Layout
::
getMvcInstance
())
$layout
->
disableLayout
();
$response
=
$this
->
getResponse
();
$response
->
canSendHeaders
(
true
);
$response
->
clearAllHeaders
();
$response
->
setHeader
(
'Content-Type'
,
'application/octet-stream; name="'
.
$filename
.
'"'
,
true
);
$response
->
setHeader
(
'Content-Transfer-Encoding'
,
'binary'
,
true
);
$response
->
setHeader
(
'Content-Length'
,
strlen
(
$content
),
true
);
$response
->
setHeader
(
'Expires'
,
'0'
);
$response
->
setHeader
(
'Cache-Control'
,
'no-cache, must-revalidate'
);
$response
->
setHeader
(
'Pragma'
,
'no-cache'
);
$response
->
setHeader
(
'Content-Disposition'
,
'attachment; filename="'
.
$filename
.
'"'
,
true
);
$response
->
sendHeaders
();
echo
$content
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment