Commit 08eae408 authored by llaffont's avatar llaffont
Browse files

Ajout d'un view helper (PageContext) pour injecter des informations contextuelles à l'action

parent 9f294616
......@@ -2707,6 +2707,7 @@ library/ZendAfi/View/Helper/Notice/Onglets.php -text
library/ZendAfi/View/Helper/Notice/Vignette.php -text
library/ZendAfi/View/Helper/NuageTags.php -text
library/ZendAfi/View/Helper/OsmPlayer.php -text
library/ZendAfi/View/Helper/PageContext.php -text
library/ZendAfi/View/Helper/Pager.php -text
library/ZendAfi/View/Helper/PartialCycle.php -text
library/ZendAfi/View/Helper/Permalink.php -text
......@@ -2730,6 +2731,7 @@ library/ZendAfi/View/Helper/TagHistoriqueRecherche.php -text
library/ZendAfi/View/Helper/TagImg.php -text
library/ZendAfi/View/Helper/TagModelTable.php -text
library/ZendAfi/View/Helper/TagObjetsImgProperties.php -text
library/ZendAfi/View/Helper/TagPageTitle.php -text
library/ZendAfi/View/Helper/TagPreview.php -text
library/ZendAfi/View/Helper/TagRating.php -text
library/ZendAfi/View/Helper/TagRss.php -text
......@@ -5253,6 +5255,7 @@ tests/library/ZendAfi/View/Helper/IconeSupportTest.php -text
tests/library/ZendAfi/View/Helper/IframeContainerTest.php -text
tests/library/ZendAfi/View/Helper/Java/MenuImageTest.php -text
tests/library/ZendAfi/View/Helper/Notice/MurTest.php -text
tests/library/ZendAfi/View/Helper/PageContextTest.php -text
tests/library/ZendAfi/View/Helper/RenderAlbumTest.php -text
tests/library/ZendAfi/View/Helper/RenderFormTest.php -text
tests/library/ZendAfi/View/Helper/RenderLieuTest.php -text
......
......@@ -32,6 +32,8 @@ class AbonneController extends ZendAfi_Controller_Action {
$this->_user = Class_Users::getLoader()->getIdentity();
$this->clearEmprunteurCache();
$this->view->getHelper('PageContext')->setContextHelper('Abonne_Resume', [$this->_user]);
}
......@@ -140,7 +142,7 @@ class AbonneController extends ZendAfi_Controller_Action {
public function viewavisAction(){
$this->_redirect('blog/viewauteur/id/'.$this->_user->getId());
$this->_forward('viewauteur', 'blog', ['id' => $this->_user->getId()]);
}
......
......@@ -26,8 +26,8 @@ class ZendAfi_View_Helper_Abonne_Avis extends ZendAfi_View_Helper_Abonne_Abstrac
? 'Vous avez rédigé '.count($avis). ' avis.'
: 'Vous n\'avez rédigé aucun avis.';
$action_url = $this->view->url(['controller' => 'blog',
'action' => 'viewauteur',
$action_url = $this->view->url(['controller' => 'abonne',
'action' => 'viewavis',
'id' => $user->getId()]);
return $this->tagFicheAbonne(sprintf('<a href=\'%s\'>%s</a>',
......
......@@ -70,7 +70,7 @@ class ZendAfi_View_Helper_Abonne_Resume extends Zend_View_Helper_HtmlElement {
public function avis($user) {
$avis = $user->getAvis();
return $this->view->tagAnchor(['controller' => 'blog', 'action' => 'viewauteur', 'id' => $user->getId()],
return $this->view->tagAnchor(['controller' => 'abonne', 'action' => 'viewavis', 'id' => $user->getId()],
(count($avis) ? count($avis) : $this->_('Aucun')).' avis');
}
}
......
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* AFI-OPAC 2.0 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).
*
* AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class ZendAfi_View_Helper_PageContext extends Zend_View_Helper_HtmlElement {
protected
$_context_helper_class,
$_context_helper_params,
$_default_context_helper_class,
$_default_context_helper_params;
public function pageContext() {
$context_helper_class = isset($this->_context_helper_class)
? $this->_context_helper_class
: $this->_default_context_helper_class;
$context_helper_params = isset($this->_context_helper_params)
? $this->_context_helper_params
: $this->_default_context_helper_params;
if (!$context_helper_class)
return '';
return call_user_func_array([$this->view, $context_helper_class], $context_helper_params);
}
public function setContextHelper($helper_class, $params) {
$this->_context_helper_class = $helper_class;
$this->_context_helper_params = $params;
}
public function setDefaultContextHelper($helper_class, $params) {
$this->_default_context_helper_class = $helper_class;
$this->_default_context_helper_params = $params;
}
}
?>
\ No newline at end of file
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* AFI-OPAC 2.0 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).
*
* AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class ZendAfi_View_Helper_TagPageTitle extends Zend_View_Helper_HtmlElement {
public function tagPageTitle($profil) {
$titre_parts = $profil->getTitreSiteParts();
if ($favicon = $profil->getFavicon())
$html = '<img src="'.$favicon.'" alt="'.implode('/', $titre_parts).'"/>';
else
$html = '<span>'.implode('&nbsp;/&nbsp;</span><span>', $titre_parts).'</span>';
return '<h1 class="titre">'.$html.'</h1>';
}
}
?>
\ No newline at end of file
......@@ -61,7 +61,7 @@ class View_Helper_Abonne_ResumeTest extends ViewHelperTestCase {
/** @test */
public function linkAvisShouldContainsDeuxAvis() {
$this->assertXPathContentContains($this->_html,
'//div/a[contains(@href, "blog/viewauteur/id/3")]',
'//div/a[contains(@href, "abonne/viewavis/id/3")]',
'2 avis');
}
}
......
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* AFI-OPAC 2.0 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).
*
* AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
require_once 'library/ZendAfi/View/Helper/ViewHelperTestCase.php';
class View_Helper_PageContextTest extends ViewHelperTestCase {
protected $helper;
public function setUp() {
parent::setUp();
$this->helper = new ZendAfi_View_Helper_PageContext();
$this->helper->setView(new ZendAfi_Controller_Action_Helper_View());
}
/** @test */
public function withDefaultTagPageTitleShouldRender() {
$this->helper->setDefaultContextHelper('TagPageTitle', [Class_Profil::newInstanceWithId(4, ['libelle' => 'jeunes'])]);
$html = $this->helper->pageContext();
$this->assertXPathContentContains($html, '//h1[@class="titre"]', 'jeunes');
}
/** @test */
public function withNoDefaultAndNoContextShouldNotRender() {
$this->assertEmpty($this->helper->pageContext());
}
/** @test */
public function withContextAndDefaultShouldRenderContext() {
$this->helper->setContextHelper('TagPageTitle', [Class_Profil::newInstanceWithId(4, ['libelle' => 'adultes'])]);
$this->helper->setDefaultContextHelper('TagPageTitle', [Class_Profil::newInstanceWithId(4, ['libelle' => 'jeunes'])]);
$html = $this->helper->pageContext();
$this->assertXPathContentContains($html, '//h1[@class="titre"]', 'adultes');
}
}
?>
\ No newline at end of file
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