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

rel #12794 : added analytics view helper and use it in record details rendering

parent 03503074
Branches
Tags
4 merge requests!258Dev/13872 Orphee Allow Hold Available Items,!93Master,!88Hotline 6.41,!85Hotline#12794 Display 464 Periodicals Title Authors
......@@ -169,14 +169,18 @@ class NoticeAjaxController extends Zend_Controller_Action {
return;
}
if ('' != ($html = $this->view->Notice_Analytics($notice))) {
$this->_sendResponse($html);
return;
}
if ($notice->isPeriodique()) {
$periodiques = $this->notice->getArticlesPeriodique($this->id_notice);
$html=$this->notice_html->getArticlesPeriodique($periodiques);
$this->_sendResponse($this->notice_html->getArticlesPeriodique($periodiques));
return;
}
else
$html=$this->view->notice_Entete($notice, ['entete' => Class_Codification::CHAMPS]);
$this->_sendResponse($html);
$this->_sendResponse($this->view->notice_Entete($notice, ['entete' => Class_Codification::CHAMPS]));
}
......
<?php
/**
* Copyright (c) 2012-2014, 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_Notice_Analytics extends Zend_View_Helper_HtmlElement {
use Trait_Translator;
const PREF_ANALYTICS = 'analytics';
const PREF_ANALYTICS_TITLE = 'analytics_title';
const PREF_ANALYTICS_AUTHORS = 'analytics_authors';
const FIELD_NAME = 'code';
const FIELD_VALUE= 'valeur';
public function notice_analytics($notice) {
if (!$notice)
return '';
$preferences = Class_Profil::getCurrentProfil()
->getCfgModulesPreferences('recherche', 'viewnotice', $notice->getTypeDoc());
$analytics_field = $preferences[self::PREF_ANALYTICS];
$title_field = $preferences[self::PREF_ANALYTICS_TITLE];
$authors_field = explode(';', $preferences[self::PREF_ANALYTICS_AUTHORS]);
if (!$analytics_field || !is_array($authors_field)
|| empty($analytics = $notice->get_subfield($analytics_field)))
return '';
$items = [];
foreach ($analytics as $analytic) {
$item = new ZendAfi_View_Helper_Notice_AnalyticsItem();
$subfields = $notice->decoupe_bloc_champ($analytic);
foreach ($subfields as $subfield) {
if ($title_field == $subfield[self::FIELD_NAME]) {
$item->setTitle($subfield[self::FIELD_VALUE]);
continue;
}
if (in_array($subfield[self::FIELD_NAME], $authors_field))
$item->addAuthor($subfield[self::FIELD_VALUE]);
}
if ($item->isValid())
$items[] = $item;
}
if (empty($items))
return '';
$html = '<h3 class"notice_info_ligne_titre">' . $this->_('Contient') . '</h3><ul><li>';
$items_html = array_map(function ($item) {return $item->html();},
$items);
$html .= implode('</li><li>', $items_html);
$html .= '</li></ul>';
return $html;
}
}
class ZendAfi_View_Helper_Notice_AnalyticsItem {
protected $_title, $_authors=[];
public function setTitle($title) {
$this->_title = $title;
}
public function addAuthor($author) {
$this->_authors[] = $author;
}
public function isValid() {
return '' != $this->_title;
}
public function html() {
if (!$this->isValid())
return '';
return $this->_title
. ((!empty($this->_authors))
? ' / ' . implode(' / ', $this->_authors)
: '');
}
}
?>
\ No newline at end of file
<?php
/**
* Copyright (c) 2012-2014, 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_Notice_AnalyticsTest extends ViewHelperTestCase {
public function setUp() {
parent::setUp();
$this->_helper = new ZendAfi_View_Helper_Notice_Analytics();
$this->_helper->setView(new ZendAfi_Controller_Action_Helper_View());
$this->_fixture = new ZendAfi_View_Helper_Notice_AnalyticsUnimarcFixture();
$this->_notice = $this->fixture('Class_Notice', ['id' => 12,
'type_doc' => 1]);
}
/** @test */
public function withoutNoticeShouldBeEmpty() {
$this->assertEquals('', $this->_helper->notice_Analytics(null));
}
/** @test */
public function withEmptyNoticeShouldBeEmpty() {
$this->assertEquals('', $this->_helper->notice_Analytics($this->_notice));
}
/** @test */
public function withoutPreferenceShouldBeEmpty() {
$this->_notice->setUnimarc($this->_fixture->unimarcWithAnalyticsIn464());
$this->assertEquals('', $this->_helper->notice_Analytics($this->_notice));
}
/** @test */
public function withPreferenceShouldContainsUneJourneeAvecLesOrques() {
$this->prepareAnalyticsIn('464', 'a', 'f');
$this->_notice->setUnimarc($this->_fixture->unimarcWithAnalyticsIn464());
$html = $this->_helper->notice_Analytics($this->_notice);
$this->assertXPathContentContains($html, '//li', 'avec les orques / Nior, Annabelle');
}
/** @test */
public function withPreferenceAndNoAnalyticsShouldBeEmpty() {
$this->prepareAnalyticsIn('464', 'a', 'f');
$this->_notice->setUnimarc($this->_fixture->unimarcWithoutAnalyticsIn464());
$this->assertEquals('', $this->_helper->notice_Analytics($this->_notice));
}
protected function prepareAnalyticsIn($field, $title, $authors) {
$profil = Class_Profil::getCurrentProfil();
$profil->setModulePreference('recherche', 'viewnotice1', 'analytics', $field);
$profil->setModulePreference('recherche', 'viewnotice1', 'analytics_title', $title);
$profil->setModulePreference('recherche', 'viewnotice1', 'analytics_authors', $authors);
}
}
class ZendAfi_View_Helper_Notice_AnalyticsUnimarcFixture {
public function unimarcWithAnalyticsIn464() {
return '00490nls0 2200193 450 0010003000000050009000030110013000121000041000251010008000661100008000742000026000822070018001082100013001263000041001393260015001804610017001954640050002128010034002629420051221 a12928429 a20051221a20059999m 0fre 0103 0 afre aaga1 aMobiClici21/06/2005 0a74,21/06/2005 d20050621 amagazine de connaissances sur CD-ROM aBimestriel tMobiClicv74 1aUne journée avec les orquesfNior, Annabelle 1aFRbc20051221wBiblixNet 2.0';
}
public function unimarcWithoutAnalyticsIn464() {
return '00433nas0 2200181 450 0010006000000050009000060110013000151000041000281010008000691100008000772000026000852070019001112100013001303000041001433260015001844610018001998010034002171459100000000 a12928429 a19700101a20059999m 0fre 0103 0 afre aaga1 aMobiClici01/11/2012 0a147,01/11/2012 d20121101 amagazine de connaissances sur CD-ROM aBimestriel tMobiClicv147 1aFRbc19700101wBiblixNet 2.0';
}
}
?>
\ 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