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

rel #21425 : new display mode for critic box

parent d9a7116f
Branches
Tags
4 merge requests!896Master,!893Master,!885Dev#21425 user comments by domains,!871Dev#21425 user comments by domains
......@@ -16,50 +16,55 @@
*
* 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
*/
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// OPAC3 - Dernières critiques sur les notices
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class ZendAfi_View_Helper_Accueil_Critiques extends ZendAfi_View_Helper_Accueil_Base {
public function getHtml() {
extract($this->preferences);
if ($this->isHierarchicalDisplay()) {
$this->titre = $this->getPreference('titre');
$this->contenu = $this->view->domainTree($this->getPreference('id_catalogue'));
return $this->getHtmlArray();
}
$this->titre = $this->_getTitle();
if ($rss_avis)
if ($this->getPreference('rss_avis'))
$this->rss_interne = $this->_getRSSurl('rss', 'critiques');
$fetched_avis = Class_AvisNotice::getLoader()->getAvisFromPreferences($this->preferences);
$fetched_avis = Class_AvisNotice::getAvisFromPreferences($this->getPreferences());
if ($display_order == 'Random')
if ($this->getPreferences('display_order') == 'Random')
shuffle($fetched_avis);
$selected_avis = array();
$only_img = ($this->preferences['only_img'] == '1');
$selected_avis = [];
$only_img = $this->getPreference('only_img') == '1';
foreach($fetched_avis as $avis) {
if (count($selected_avis) >= $nb_aff_avis)
if (count($selected_avis) >= $this->getPreference('nb_aff_avis'))
break;
if (null == $notice = $avis->getFirstNotice()) {
if (null == $notice = $avis->getFirstNotice())
continue;
}
if (($only_img===false) || ( $avis->getFirstNotice()->hasVignette() === true))
$selected_avis []= $avis;
if ((!$only_img) || $notice->hasVignette())
$selected_avis[] = $avis;
}
if (count($selected_avis) == 0)
$this->contenu = sprintf('<p>%s</p>', $this->translate()->_('Aucune critique récente'));
else {
$avis_helper = $this->_newHelperAvis();
if (count($selected_avis) == 0) {
$this->contenu = $this
->decorateContenu($this->_tag('p', $this->_('Aucune critique récente')));
foreach ($selected_avis as $avis)
$this->contenu .= $this->decorateAvisHtml($avis_helper->avis($avis));
return $this->getHtmlArray();
}
$avis_helper = $this->_newHelperAvis();
foreach ($selected_avis as $avis)
$this->contenu .= $this->decorateAvisHtml($avis_helper->avis($avis));
$this->contenu = $this->decorateContenu($this->contenu);
return $this->getHtmlArray();
}
......@@ -70,7 +75,7 @@ class ZendAfi_View_Helper_Accueil_Critiques extends ZendAfi_View_Helper_Accueil_
protected function decorateContenu($html) {
return $html . '<div class="clear"></div>';
return $html . $this->_tag('div', '', ['class' => 'clear']);
}
......@@ -80,6 +85,7 @@ class ZendAfi_View_Helper_Accueil_Critiques extends ZendAfi_View_Helper_Accueil_
->setLimitNbWord($this->preferences['nb_words'])
->setVignetteLinkToAvis()
->addUrlContext(['retour_avis' => $this->id_module]);
return $avis_helper;
}
......@@ -93,5 +99,9 @@ class ZendAfi_View_Helper_Accueil_Critiques extends ZendAfi_View_Helper_Accueil_
['id_module' => $this->id_module,
'id_menu' => $this->_id_menu]);
}
}
?>
\ No newline at end of file
protected function isHierarchicalDisplay() {
return '1' == $this->getPreference('hierarchical');
}
}
\ No newline at end of file
<?php
/**
* Copyright (c) 2012-2014, 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_View_Helper_DomainTree extends ZendAfi_View_Helper_BaseHelper {
public function domainTree($id) {
$html = '';
if (!$parent = Class_Catalogue::find((int)$id))
return $html;
foreach ($parent->getSousDomaines() as $domain)
$html .= $this->_renderDomain($domain);
return $this->_tag('ul', $html,
['class' => 'review-domains']);
}
protected function _renderDomain($domain) {
return $this
->_tag('li',
$this->_tag('a', $domain->getLibelle(),
['href' => $this->view->url(['controller' => 'blog',
'action' =>'hierarchical',
'id' => $domain->getId(),
'start_id' => $domain->getId()],
null, true)]));
}
}
\ No newline at end of file
......@@ -57,6 +57,15 @@ abstract class CritiquesAvisTestCase extends ViewHelperTestCase {
public function setUp() {
parent::setUp();
$this->_prepareFixtures();
$helper = new ZendAfi_View_Helper_Accueil_Critiques(2, $this->_prefs);
$helper->setView(new ZendAfi_Controller_Action_Helper_View());
$this->html = $helper->getBoite();
}
protected function _prepareFixtures() {
Class_AdminVar::set('AVIS_MIN_SAISIE', 0);
Class_AdminVar::set('AVIS_MAX_SAISIE', 1000);
......@@ -109,14 +118,11 @@ abstract class CritiquesAvisTestCase extends ViewHelperTestCase {
'notices' => [$potter]]);
Class_Profil::setCurrentProfil($this->fixture('Class_Profil', ['id' => 18]));
$helper = new ZendAfi_View_Helper_Accueil_Critiques(2, $this->_prefs);
$helper->setView(new ZendAfi_Controller_Action_Helper_View());
$this->html = $helper->getBoite();
}
}
class CritiquesWithVignettesTest extends CritiquesAvisTestCase {
protected $_prefs = ['type_module' => 'CRITIQUES',
'division' => 1,
......@@ -216,4 +222,51 @@ class CritiquesWithEmptyVignettesAllowedTest extends CritiquesAvisTestCase {
public function boiteGaucheShouldBePresent() {
$this->assertXPath($this->html, "//div[@class='boiteGauche']");
}
}
class CritiquesHierarchicalByDomainViewTest extends CritiquesAvisTestCase {
protected $_prefs = ['type_module' => 'CRITIQUES',
'division' => 1,
'preferences' => ['rss_avis' => false,
'only_img' => 0,
'display_order' => 'Random',
'titre' => '',
'nb_aff_avis' => '3',
'nb_words' => 20,
'boite' => null,
'hierarchical' => '1',
'id_catalogue' => '180']];
protected function _prepareFixtures() {
parent::_prepareFixtures();
$this->fixture('Class_Catalogue',
['id' => 180,
'libelle' => 'THEME',
'sous_domaines' => [$this->fixture('Class_Catalogue',
['id' => 1234,
'libelle' => 'Art']),
$this->fixture('Class_Catalogue',
['id' => 1235,
'libelle' => 'Littérature'])]]);
}
/** @test */
public function shouldDisplayArtLink() {
$this->assertXPathContentContains($this->html,
'//a[contains(@href, "/blog/hierarchical/id/1234/start_id/1234")]',
'Art');
}
/** @test */
public function shouldDisplayLitteratureLink() {
$this->assertXPathContentContains($this->html,
'//a[contains(@href, "/blog/hierarchical/id/1235/start_id/1235")]',
utf8_encode('Littérature'));
}
}
\ No newline at end of file
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