Newer
Older
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* 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).
*
* 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
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
class BibNumeriqueController extends ZendAfi_Controller_Action {
protected $_user;
public function init() {
parent::init();
$this->_user = $this->view->user = Class_Users::getIdentity();
}
public function viewAlbumAction() {
if (null === ($album = Class_Album::getLoader()->find((int)$this->_getParam('id')))) {
$this->_redirect('opac/');
return;
}
public function albumAction() {
$album = Class_Album::getLoader()->find((int)$this->_getParam('id'));
$this->getHelper('ViewRenderer')->setNoRender();
$this->_response->setBody($this->view->album_JsonVisitor($album));
}
public function albumXspfPlaylistAction() {
$album = Class_Album::getLoader()->find((int)$this->_getParam('id'));
$playlist = $this->view->album_XspfPlaylistVisitor($album);
$this->getHelper('ViewRenderer')->setNoRender();
$response = $this->_response;
$response->clearAllHeaders();
$response->setHeader('Content-Type', 'application/xspf+xml; name="' . $album->getId(). '.xspf"', true);
$response->setHeader('Content-Disposition', 'attachment; filename="' . $album->getId(). '.xspf"', true);
$response->setHeader('Content-Transfer-Encoding', 'base64', true);
$response->setHeader('Expires', '0');
$response->setHeader('Cache-Control', 'no-cache, must-revalidate');
$response->setHeader('Pragma', 'no-cache');
$response->setHeader('Access-Control-Allow-Origin', '*');
$response->setBody($playlist);
}
public function albumRssFeedAction() {
$this->getHelper('ViewRenderer')->setNoRender();
$album = Class_Album::getLoader()->find((int)$this->_getParam('id'));
$rss = $this->view->album_RssFeedVisitor($album);
$this->_response->setBody($rss);
$this->_response->setHeader('Content-Type', 'application/rss+xml', true);
}
public function downloadalbumAction() {
$album = Class_Album::getLoader()->find((int)$this->_getParam('id'));
echo $this->_renderFile($album->getBasePath().$album->getPdf(), true);
}
public function bookletAction() {
$id = $this->_getParam('id');
$container_id = sprintf('booklet_%d', $id);
Class_ScriptLoader::getInstance()
->addAmberPackage('AFI')
->addAmberReady(sprintf("smalltalk.BibNumAlbum._load_in_scriptsRoot_('%s.json', '%s', '%s')",
$this->view->url(array('action' => 'album', 'id' => $id)),
'#'.$container_id,
AMBERURL."afi/souvigny/"))
->loadAmber();
$this->view->container_id = $container_id;
}
public function viewCategorieAction() {
if (null === ($categorie = Class_AlbumCategorie::getLoader()->find((int)$this->_getParam('id')))) {
$this->_redirect('opac/');
return;
}
$this->view->categorie = $categorie;
$this->view->albums = $categorie->getAlbums();
$this->view->subCategories = $categorie->getSousCategories();
}
public function getResourceAction() {
echo $this->_getResource();
}
public function downloadResourceAction() {
echo $this->_getResource(true);
}
public function playRessourceAction() {
if (null === ($ressource = Class_AlbumRessource::find((int)$this->_getParam('id'))))
exit;
$event_data = ['titre' => $ressource->getTitre(),
'album' => $ressource->getTitreAlbum(),
'auteur' => $ressource->getAuteur(),
'editeur' => $ressource->getEditeur(),
'publication' => $ressource->getAnnee(),
'piste' => $ressource->getOrdre(),
'droits' => $ressource->getDroits(),
'source' => $this->view->absoluteUrl($ressource->getPermalink())];
$this->_helper->trackEvent('bib-numerique', 'lecture', $event_data, $ressource->getId());
$this->_redirect($this->view->absoluteUrl($ressource->getOriginalUrl()));
}
public function thumbnailAction() {
if (null === ($ressource = Class_AlbumRessource::find((int)$this->_getParam('id'))))
exit;
// renvoi direct du contenu du fichier
$this->_helper->getHelper('ViewRenderer')->setNoRender(true);
$keys = array('width', 'crop_top', 'crop_right', 'crop_bottom', 'crop_left', 'id');
$params = $this->_request->getParams();
$thumbnail_params = array();
foreach ($keys as $key) {
if (array_key_exists($key, $params))
$thumbnail_params[$key] = (int)$params[$key];
}
echo $this->_renderFile($ressource->getThumbnailFilePath($thumbnail_params),
$this->_getParam('attachment', false));
/**
* Interpretation des permaliens type http://localhost/afi-opac3/bib-numerique/notice/ido/D09030001/folio/1R4
* sur les Albums + folios
*/
public function noticeAction() {
if (!$album = $this->findAlbumByIdOrIdOrigine()) {
$this->_redirect('opac/index');
return;
}
if (!$notice = $album->getNotice()) {
$this->_redirect('opac/index');
return;
}
$url_notice = 'opac/recherche/viewnotice/id/' . $notice->getId();
if ($folio = $this->_getParam('folio'))
$url_notice .= '#/page/'.$album->indexOfRessourceByFolio($folio);
$this->_redirect($url_notice);
}
public function noticeThumbnailAction() {
$this->_helper->getHelper('ViewRenderer')->setNoRender(true);
if (!$album = $this->findAlbumByIdOrIdOrigine())
return;
echo $this->_renderFile($album->getThumbnailPath() ,false);
}
protected function findAlbumByIdOrIdOrigine() {
if ($id_origine = $this->_getParam('ido'))
return Class_Album::getLoader()->findFirstBy(array('id_origine' => $this->_getParam('ido')));
return Class_Album::getLoader()->find((int)$this->_getParam('id'));
}

efalcy
committed
protected function _getResource($as_attachment = false) {
if (null === ($resource = Class_AlbumRessource::getLoader()->find((int)$this->_getParam('id')))) {
// ressource inexistante, on ne fait rien
exit;
}
if ('' == $resource->getFichier()) {
exit;
}
if ($datas=$this->_renderFile($resource->getOriginalPath(), $as_attachment))
echo $datas;
else
die('404 File not found');
}
protected function _renderFile($filepath, $as_attachment = false) {
// renvoi direct du contenu du fichier
$this->_helper->getHelper('ViewRenderer')->setNoRender(true);
$response = Zend_Controller_Front::getInstance()->getResponse();
$response->canSendHeaders(true);
$mimeType = Class_File_Mime::getTypeFromPath($filepath);
$fileInfos = stat($filepath);
$parts = pathinfo($filepath);
if (!$fileInfos['size'])
return false;
$response->clearAllHeaders();
$response->setHeader('Content-Type', $mimeType . '; name="' . $parts['basename'] . '"', true);
$response->setHeader('Content-Transfer-Encoding', 'binary', true);
$response->setHeader('Content-Length', $fileInfos['size'], true);
$response->setHeader('Expires', '0');
$response->setHeader('Cache-Control', 'no-cache, must-revalidate');
$response->setHeader('Pragma', 'no-cache');
if ($as_attachment)
$response->setHeader('Content-Disposition', 'attachment; filename="' . $parts['basename'] . '"', true);
$file = fopen($filepath, 'rb');
$file_data = fread($file, $fileInfos['size']);
fclose($file);
return $file_data;
}

efalcy
committed
public function fullScreenAction() {
$viewRenderer = $this->getHelper('ViewRenderer');
$viewRenderer->setNoRender();

efalcy
committed
$html = 'Aucun document';
if ($id = $this->_getParam('id'))
$html = $this->view->monocleReaderServerSideFullScreen($id);
$this->getResponse()->setHeader('Content-Type', 'text/html;charset=utf-8');
$this->getResponse()->setBody('<!DOCTYPE html><html><body>'.$html.Class_ScriptLoader::getInstance()->html().'</body></html>');

efalcy
committed
if (!$this->_user){
$this->_forwardToLogin('', $this->view->url());
if (!$this->_user->hasRightAccessDilicom())
return $this->_ajaxRedirectToNotice();
if (!$this->view->album = Class_Album::find($this->_getParam('id')))
return $this->_ajaxRedirectToNotice();
public function loanBookAjaxAction() {
if($this->_userShouldBeRedirect())
$this->view->form = $this->view
->newForm(['id' => 'pnb_devices'])
->setMethod('get')
->setAction($this->view->url(['action' => 'download-loan-book-ajax']));
if ($user_agents = (new Class_AdminVar_Dilicom())->getUserAgents())
$this->view->form->addElement('select', 'devices', ['label' => $this->_('Type de liseuse'),
'multiOptions' => $user_agents,
'value'=> (new Class_AdminVar_Dilicom())->defaultDevice()])
->addDisplayGroup(['devices'], 'devices-group',[]);
$this->view->form
->addElement('Submit', 'yes-button', ['label' => $this->_('Oui')])
->addElement('Button', 'no-button',
['label' => $this->_('Non'),
'onclick' => 'opacDialogClose();return false;'])
->addDisplayGroup(['yes-button', 'no-button'],
'question',
['legend' => $this->_('Êtes vous sûr de vouloir emprunter ce document ?')]);
$this->view->titre = $this->_('Emprunter le livre au format EPUB');
$this->renderScript('bib-numerique/loan-book.phtml');
public function loanBookAction() {
if (!$this->_user)
return $this->_forwardToLogin('', $this->view->absoluteUrl());

Ghislain Loas
committed
if (!$this->_user->hasRightAccessDilicom())
return $this->_redirectToReferer();
if (!$album = Class_Album::find($this->_getParam('id')))
return $this->_redirectToReferer();
$content = (new Class_WebService_BibNumerique_Dilicom_Hub())->loanBook($album, $this->_user , $this->_getParam('devices'));
if ($content->returnMessage) {
$this->_helper->notify(implode(',', $content->returnMessage));
return $this->_redirectToNotice($album->getNoticeId());
$this->_redirect($content->link->url);
public function holdBookAction(){
$album = Class_Album::find($this->_getParam('id'));
$status= (new Class_WebService_BibNumerique_Dilicom_Hub())
->isAlbumHoldableBy($album, $this->_user);
if ($status->returnMessage) {
$this->_helper->notify($status->returnMessage[0]);
return $this->_redirectToReferer();
}
$hold = new Class_Hold_Pnb();
$hold->setRecordOriginId($album->getIdOrigine())
->setUser($this->_user)
->save();
$this->_helper->notify($this->_('Réservation enregistrée : %s', $hold->getTitle()));
$this->_redirectToReferer();
}
if (!$ids = $this->_getParam('loan_id'))
return;
$user_loan_id = explode('_',$ids);
if ( !$loan = Class_Loan_Pnb::findFirstBy(['id' => $user_loan_id[1],
'user_id' => $user_loan_id[0]])) {
$this->_helper->notify([$this->_('Pas de pret')]);
return $loan;
}
public function extendsPnbLoanAction() {
if (!$loan = $this->getLoan())
return $this->_redirectToIndex();
$content = (new Class_WebService_BibNumerique_Dilicom_Hub())->extendLoan($loan);
if (!empty($content->returnMessage)) {
$this->_helper->notify(implode($content->returnMessage));
return $this->_redirectToReferer();
}
$this->_helper->notify($this->_('Votre prêt a été prolongé jusqu\'au %s', $loan->getExpectedReturnDate()));
return $this->_redirectToReferer();
}
public function returnPnbLoanAction() {
if (!$loan = $this->getLoan())
return $this->_redirectToIndex();
$content = (new Class_WebService_BibNumerique_Dilicom_Hub())->returnLoan($loan);
if (!empty($content->returnMessage)) {
$this->_helper->notify(implode($content->returnMessage));
return $this->_redirectToReferer();
}
$this->_helper->notify($this->_('Votre document a été retourné'));
return $this->_redirectToReferer();
}
public function downloadLoanBookAjaxAction() {
if ($this->_userShouldBeRedirect())
$content = (new Class_WebService_BibNumerique_Dilicom_Hub())->loanBook(Class_Album::find($this->_getParam('id')), $this->_user, $this->_getParam('devices'));
$this->_withContentDo($content,
function($url)
{
$this->view->download_url = $url;
$this->renderPopupResult($this->_('Téléchargement'),
$this->view->render('bib-numerique/download-book.phtml'));
protected function _ajaxRedirectToNotice() {
$this->view->redirect_url = $this->view->url(['controller' => 'recherche',
'action' => 'viewnotice',
'render' => 'false']);
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
$this->renderPopupResult('', $this->view->render('bib-numerique/redirect.phtml'));
return true;
}
public function consultBookAjaxAction() {
if($this->_userShouldBeRedirect())
return;
$this->view->titre = $this->_('Consulter le livre en ligne');
$this->renderScript('bib-numerique/consult-book.phtml');
}
public function consultBookOpenAjaxAction() {
if ($this->_userShouldBeRedirect())
return;
$client_ip = (new Class_RemoteClient($this->_request))->getIpAddress();
$response = (new Class_WebService_BibNumerique_Dilicom_Hub())
->consultBook($this->view->album, $client_ip, $this->_user);
return $this->_withContentDo($response,
function($url)
{
$this->view->open_url = $url;
$this->renderPopupResult($this->_('Consultation'),
$this->view->render('bib-numerique/consult-book-open.phtml'));
});
if (!$this->_user)
return $this->_forwardToLogin('', $this->view->url());
if (!$this->_user->hasRightAccessDilicom())
return $this->_redirectToReferer();
$client_ip = (new Class_RemoteClient($this->_request))->getIpAddress();
$response = (new Class_WebService_BibNumerique_Dilicom_Hub())
->consultBook($album, $client_ip, $this->_user);
if ($content->returnMessage) {
$this->_helper->notify(implode(',', $content->returnMessage));
return $this->_redirectToNotice($album->getNoticeId());
protected function _redirectToNotice($id = null) {
$this->_redirect($this->view->url(['controller' => 'recherche',
'action' => 'viewnotice',
'id' => $id]),
['prependBase' => false]);
protected function _withContentDo($content, $closure) {
if (!$content)
return $this->_ajaxRedirectToNotice();
if ($content->returnMessage) {
$this->_helper->notify(implode(',', $content->returnMessage));
return $this->_ajaxRedirectToNotice();
$closure($content->link->url);
public function widgetPageAction() {
$id_module = (int)$this->_getParam('id_module');
$id_division = (int)$this->_getParam('id_division');
$page = (int)$this->_getParam('page');
$module_params = Class_Profil::getCurrentProfil()
->getBoitesDivision($id_division)[$id_module];
$helper = new ZendAfi_View_Helper_Accueil_BibNumerique($id_module, $module_params);
$helper->setPage($page);
$helper->setView($this->view);
$this->view->sito_helper = $helper;
$viewRenderer = $this->getHelper('ViewRenderer');
$viewRenderer->setLayoutScript('empty.phtml');
}