Skip to content
Snippets Groups Projects
Commit 971e67e4 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

rel #30143: fix tests

parent d150be4f
Branches
Tags
2 merge requests!1148Dev#30143 create album record thumbnail from first image,!1137Dev#30143 create album record thumbnail from first image
......@@ -16,16 +16,19 @@
*
* 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
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
abstract class ZendAfi_View_Helper_PremierChapitre_Abstract extends ZendAfi_View_Helper_BaseHelper {
public function loadScript(){}
protected function _tag($name, $content=null, $attribs=[]) {
$html = '<' . $name . $this->_htmlAttribs($attribs);
if (null === $content)
return $html . $this->getClosingBracket();
return $html . '>' . $content . '</' . $name . '>';
}
}
?>
\ No newline at end of file
abstract class ZendAfi_View_Helper_PremierChapitre_Abstract
extends ZendAfi_View_Helper_BaseHelper {
protected function _detectPremierChapitre($data) {
if ($data instanceOf Class_PremierChapitre)
return $data;
if ($data instanceOf Class_Notice)
return Class_PremierChapitre::getByNotice($data);
}
}
\ No newline at end of file
......@@ -20,26 +20,31 @@
*/
class ZendAfi_View_Helper_PremierChapitre_Frame extends ZendAfi_View_Helper_PremierChapitre_Abstract {
class ZendAfi_View_Helper_PremierChapitre_Frame
extends ZendAfi_View_Helper_PremierChapitre_Abstract {
public function premierChapitre_Frame($data, $preferences=[]) {
$this->loadScript();
$html = '';
$pc_active = new Class_WebService_PremierChapitre();
if (!$pc_active->isEnabled()) return $html;
if ($data instanceOf Class_PremierChapitre) $pc = $data;
else if ($data instanceOf Class_Notice) {
$ntc = $data;
$pc = Class_PremierChapitre::getByNotice($ntc);
if (!$pc) return $html;
}
else return $html;
$h = 700;
if (!empty($preferences['maxHeight']) && $preferences['maxHeight'] < $h) $h = $preferences['maxHeight'];
$frm_attribs = ['id' => 'pc_frame',
'class' => 'iframe_premierchapitre',
'style' => 'width:100%; height:'.$h.'px; border:none;',
'src' => $pc->getUrl()];
return $this->_tag('iframe','',$frm_attribs);
if (!(new Class_WebService_PremierChapitre())->isEnabled())
return '';
if (!$model = $this->_detectPremierChapitre($data))
return '';
return $this
->_tag('iframe',
'',
['id' => 'pc_frame',
'class' => 'iframe_premierchapitre',
'style' => 'width:100%; height:' . $this->_detectHeight($preferences) . 'px; border:none;',
'src' => $model->getUrl()]);
}
}
?>
\ No newline at end of file
protected function _detectHeight($preferences) {
$default = 700;
return (!empty($preferences['maxHeight']) && $preferences['maxHeight'] < $default)
? $preferences['maxHeight']
: $default;
}
}
\ No newline at end of file
<?php
/**
* Copyright (c) 2015, Gal VINOT (Ville de Montrouge). All rights reserved.
* Copyright (c) 2015, Gaël VINOT (Ville de Montrouge). 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
......@@ -20,34 +20,51 @@
*/
class ZendAfi_View_Helper_PremierChapitre_Lien extends ZendAfi_View_Helper_PremierChapitre_Abstract {
private $_img = '/public/opac/images/lireavecpremierchapitre.png';
class ZendAfi_View_Helper_PremierChapitre_Lien
extends ZendAfi_View_Helper_PremierChapitre_Abstract {
public function premierChapitre_Lien($data, $preferences=[]) {
$this->loadScript();
$html = '';
$pc_active = new Class_WebService_PremierChapitre();
if (!$pc_active->isEnabled()) return $html;
if ($data instanceOf Class_PremierChapitre) $pc = $data;
else if ($data instanceOf Class_Notice) {
$ntc = $data;
$pc = Class_PremierChapitre::getByNotice($ntc);
if (!$pc) return $html;
}
else return $html;
$lnk_attribs = [ 'id' => 'pc_lienNotice',
'href' => $pc->getUrl()];
$contenu = $this->_tag('img',null,['src' => $this->_img,
'style' => 'height: 30px; margin-left: 30px;']);
if (!empty($preferences['linkNotice']) && $preferences['linkNotice']) {
$lnk_attribs['href'] = '/premier-chapitre/notice/ean/'.$pc->getId();
$contenu = 'Voir le document';
}
else if (!empty($preferences['targetLink']) && $preferences['targetLink'] == 'ancre' ) {
$lnk_attribs['href'] = '#pc_ancre';
}
return $this->_tag('a',$contenu,$lnk_attribs);
if (!(new Class_WebService_PremierChapitre())->isEnabled())
return '';
if (!$model = $this->_detectPremierChapitre($data))
return '';
return $this->_tag('a',
$this->_getContent(),
['id' => 'pc_lienNotice',
'href' => $this->_getHref($model, $preferences)]);
}
}
?>
\ No newline at end of file
protected function _getHref($model, $preferences) {
if ($this->_isLinkToRecord($preferences))
return '/premier-chapitre/notice/ean/' . $model->getId();
return ($this->_isLinkToTarget($preferences))
? '#pc_ancre' : $model->getUrl();
}
protected function _getContent($preferences) {
return $this->_isLinkToRecord($preferences)
? $this->_('Voir le document') : $this->_getImage();
}
protected function _isLinkToRecord($preferences) {
return !empty($preferences['linkNotice']) && $preferences['linkNotice'];
}
protected function _isLinkToTarget($preferences) {
return !empty($preferences['targetLink']) && $preferences['targetLink'] == 'ancre';
}
protected function _getImage() {
$this->_tag('img', null,
['src' => '/public/opac/images/lireavecpremierchapitre.png',
'style' => 'height: 30px; margin-left: 30px;']);
}
}
\ No newline at end of file
......@@ -20,53 +20,86 @@
*/
class ZendAfi_View_Helper_PremierChapitre_Vignettes extends ZendAfi_View_Helper_PremierChapitre_Abstract {
class ZendAfi_View_Helper_PremierChapitre_Vignettes
extends ZendAfi_View_Helper_PremierChapitre_Abstract {
private $_imgCss = 'margin: 5px;box-sizing: border-box;box-shadow: 0 1px 2px rgba(0,0,0,.075);padding: 4px;max-height: 122px; max-width: 200px;';
public function premierChapitre_Vignettes($data, $preferences=[]) {
$this->loadScript();
$html = '';
$pc_active = new Class_WebService_PremierChapitre();
if (!$pc_active->isEnabled()) return $html;
$bloc_vignettes = '';
foreach($data as $pc) {
if (!empty($preferences['target']) && $preferences['target'] == 'frame')
$bloc_vignettes .= $this->_vignetteFrame($pc,$preferences);
else
$bloc_vignettes .= $this->_vignetteNotice($pc,$preferences);
}
$html .= $this->_tag('div',$bloc_vignettes);
if (!empty($preferences['linkNotice']) && $preferences['linkNotice']) {
$html .= $this->_tag('div','<p></p><p>'.$this->view->premierChapitre_Lien($data[0],$preferences).'</p>');
}
if (!empty($preferences['target']) && $preferences['target'] == 'frame') {
$html .= $this->view->premierChapitre_Frame($data[0],$preferences);
}
return $this->_tag('div', $html);
return ((new Class_WebService_PremierChapitre())->isEnabled())
? $this->_tag('div',
$this->_tag('div', $this->_renderThumbnails($data, $preferences))
. $this->_renderFirstLink($data[0], $preferences)
. $this->_renderFirstFrame($data[0], $preferences))
: '';
}
protected function _vignetteFrame($pc, $preferences){
$onclick = "\$('#pc_frame')[0].src='".$pc->getUrl()."';";
if(!empty($preferences['linkNotice']) && $preferences['linkNotice'])
$onclick .= "\$('#pc_lienNotice')[0].href='/premier-chapitre/notice/ean/".$pc->getId()."';";
$lnk_attribs = ['onclick' => $onclick,'style'=>'cursor:pointer;'];
return $this->_tag('a',$this->_vignetteImg($pc),$lnk_attribs);
protected function _renderThumbnails($data, $preferences) {
$html = '';
foreach($data as $model)
$html .= $this->_renderThumbnail($model, $preferences);
return $html;
}
protected function _renderThumbnail($model, $preferences) {
return (!empty($preferences['target']) && $preferences['target'] == 'frame')
? $this->_vignetteFrame($model, $preferences)
: $this->_vignetteNotice($model, $preferences);
}
protected function _renderFirstLink($first, $preferences) {
return $this->_isLinkToRecord($preferences)
? $this->_tag('div',
$this->_tag('p', '')
. $this->_tag('p',
$this->view->premierChapitre_Lien($first, $preferences)
))
: '';
}
protected function _renderFirstFrame($first, $preferences) {
return (!empty($preferences['target']) && $preferences['target'] == 'frame')
? $this->view->premierChapitre_Frame($first, $preferences)
: '';
}
protected function _vignetteFrame($model, $preferences){
$onclick = "\$('#pc_frame')[0].src='".$model->getUrl()."';";
if ($this->_isLinkToRecord($preferences))
$onclick .= "\$('#pc_lienNotice')[0].href='/premier-chapitre/notice/ean/" . $model->getId()."';";
return $this->_tag('a', $this->_vignetteImg($model),
['onclick' => $onclick,
'style'=>'cursor:pointer;']);
}
protected function _vignetteNotice($pc, $preferences){
$lnk_attribs = ['href' => '/premier-chapitre/notice/ean/"'.$pc->getId()];
return $this->_tag('a',$this->_vignetteImg($pc),$lnk_attribs);
protected function _isLinkToRecord($preferences) {
return !empty($preferences['linkNotice']) && $preferences['linkNotice'];
}
protected function _vignetteNotice($model, $preferences){
$lnk_attribs = ['href' => '/premier-chapitre/notice/ean/' . $model->getId()];
return $this->_tag('a', $this->_vignetteImg($model),
$lnk_attribs);
}
protected function _vignetteImg($pc){
$img_attribs = ['src' => $pc->getMiniature(),
'alt' => $pc->getTitre().' - '.$pc->getAuteur(),
'title' => $pc->getTitre().' - '.$pc->getAuteur(),
'style' => $this->_imgCss,
'data-toggwle'=>"tooltip"];
return $this->_tag('img',null,$img_attribs);
protected function _vignetteImg($model) {
return $this->_tag('img', null,
['src' => $model->getMiniature(),
'alt' => $model->getTitre().' - '.$model->getAuteur(),
'title' => $model->getTitre().' - '.$model->getAuteur(),
'style' => $this->_imgCss,
'data-toggwle'=>"tooltip"]);
}
}
?>
\ No newline at end of file
}
\ No newline at end of file
......@@ -1644,11 +1644,10 @@ class NoticeAjaxControllerCvsWithRecordsSearchTest extends NoticeAjaxControllerC
'titre_principal' => 'Le photographe',
'auteur_principal' => 'Guibert']);
$this->_cvs = Class_CVSLink::forUser($record);
$this->_http_client = Storm_Test_ObjectWrapper::mock();
$this->_http_client = $this->mock();
Class_CVSLink::setTimeSource((new TimeSourceForTest)->setTime(1369640315));
Class_CVSLink::setDefaultHttpClient($this->_http_client);
Class_Xml::setDefaultHttpClient($this->_http_client);
Class_WebService_Abstract::setDefaultHttpClient($this->_http_client);
RessourcesNumeriquesFixtures::activateCVS();
$this->_http_client
......
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