Skip to content
Snippets Groups Projects
Commit 1faaa8f0 authored by Patrick Barroca's avatar Patrick Barroca 😁
Browse files

rel #44527 : separation betweem visitor and render

parent 6c59318e
Branches
Tags
2 merge requests!1701Dev#44527 recette uniformisation de la saisie des horaires,!1700Dev#44527 recette uniformisation de la saisie des horaires
......@@ -30,12 +30,10 @@ class Class_Ouverture_Visitor {
CLOSURE_KEY = 'C';
protected
$_view,
$_content,
$_openings;
public function __construct($view) {
$this->_view = $view;
public function __construct() {
$this->_openings = [static::DEFAULT_KEY => [],
static::PERIODICAL_KEY => [],
static::EXCEPTIONAL_KEY => [],
......@@ -115,84 +113,36 @@ class Class_Ouverture_Visitor {
protected function _addToTime($time, $days) {
return $time + (60*60*24*$days);
return $time + (60 * 60 * 24 * $days);
}
protected function _periodKeyFor($opening) {
return $this->_view->humanDateRange(strtotime($opening->getValidityStart()),
strtotime($opening->getValidityEnd()));
return md5($opening->getValidityStart() . ':' . $opening->getValidityEnd());
}
public function getContent() {
if ($this->_content)
return $this->_content;
return $this->_view->tag('ul',
$this->_renderDefaults()
. $this->_renderPeriods()
. $this->_renderExceptionals()
. $this->_renderClosures());
return $this->_content;
}
protected function _renderDefaults() {
if (!$default = $this->_getDefault())
return '';
$content = '';
foreach($default as $opening)
$content .= $this->_view->tag('li', $this->_renderOne($opening));
return $this->_view->tag('li',
$this->_view->tag('h3', $this->_view->_('Normaux'))
. $this->_view->tag('ul', $content));
}
protected function _renderPeriods() {
return ($periodical = $this->_getPeriodical())
? $this->_renderPeriod(key($periodical), current($periodical))
: '';
}
protected function _renderClosures() {
if (!$closure = $this->_getClosure())
return '';
$content = '';
foreach($closure as $opening)
$content .= $this->_view->tag('li', $this->_renderOne($opening));
return $this->_view
->tag('li',
$this->_view->tag('h3',
$this->_view->_plural(count($closure),
'',
'Fermeture exceptionnelle',
'Fermetures exceptionnelles'))
. $this->_view->tag('ul', $content));
}
protected function _getPeriodical() {
public function getPeriodical() {
return $this->_getType(static::PERIODICAL_KEY);
}
protected function _getExceptional() {
public function getExceptional() {
return $this->_getType(static::EXCEPTIONAL_KEY);
}
protected function _getDefault() {
public function getDefault() {
return $this->_getType(static::DEFAULT_KEY);
}
protected function _getClosure() {
public function getClosure() {
return $this->_getType(static::CLOSURE_KEY);
}
......@@ -210,47 +160,6 @@ class Class_Ouverture_Visitor {
}
protected function _renderExceptionals() {
if (!$exceptional = $this->_getExceptional())
return '';
$content = '';
foreach($exceptional as $opening)
$content .= $this->_view->tag('li', $this->_renderOne($opening));
return $this->_view
->tag('li',
$this->_view->tag('h3',
$this->_view->_plural(count($exceptional),
'',
'Ouverture exceptionnelle',
'Ouvertures exceptionnelles'))
. $this->_view->tag('ul', $content));
}
protected function _renderPeriod($label, $openings) {
$content = '';
foreach($openings as $opening)
$content .= $this->_view->tag('li', $this->_renderOne($opening));
return $this->_view->tag('li',
$this->_view->tag('h3', $label)
. $this->_view->tag('ul', $content));
}
protected function _renderOne($opening) {
$am = $this->_renderTimeSegment($opening->getDebutMatin(), $opening->getFinMatin());
$pm = $this->_renderTimeSegment($opening->getDebutApresMidi(), $opening->getFinApresMidi());
$hours = $this->_renderTimes($am, $pm);
return $opening->getFormattedJour()
. ($hours ? (' : ' . str_replace('h00', 'h', $hours)) : '');
}
protected function _renderTimeSegment($from, $to) {
if ($from == $to)
return $this->_renderHour($from);
......
......@@ -157,9 +157,7 @@ class ZendAfi_View_Helper_BibView extends ZendAfi_View_Helper_BaseHelper {
protected function _renderBlockHoraire() {
$visitor = new Class_Ouverture_Visitor($this->view);
$this->bib->acceptOpeningsVisitor($visitor);
$content = $visitor->getContent();
$content = $this->view->libraryOpenings($this->bib);
return $this
->_renderBlock($this->_tag('dd', $content),
......
<?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_LibraryOpenings extends ZendAfi_View_Helper_BaseHelper {
public function libraryOpenings($library) {
if (!$library)
return '';
$visitor = new Class_Ouverture_Visitor();
$library->acceptOpeningsVisitor($visitor);
if ($content = $visitor->getContent())
return $content;
return $this->_tag('ul',
$this->_renderDefaults($visitor->getDefault())
. $this->_renderPeriods($visitor->getPeriodical())
. $this->_renderExceptionals($visitor->getExceptional())
. $this->_renderClosures($visitor->getClosure()));
}
protected function _renderDefaults($default) {
if (!$default)
return '';
$content = '';
foreach($default as $opening)
$content .= $this->_tag('li', $this->_renderOne($opening));
return $this->_tag('li',
$this->_tag('h3', $this->_('Normaux'))
. $this->_tag('ul', $content));
}
protected function _renderPeriods($periodical) {
return ($periodical)
? $this->_renderPeriod(current($periodical))
: '';
}
protected function _renderPeriod($openings) {
$content = '';
foreach($openings as $opening)
$content .= $this->_tag('li', $this->_renderOne($opening));
$first = current($openings);
$label = $this->view->humanDateRange(strtotime($first->getValidityStart()),
strtotime($first->getValidityEnd()));
return $this->_tag('li',
$this->_tag('h3', $label) . $this->_tag('ul', $content));
}
protected function _renderClosures($closure) {
if (!$closure)
return '';
$content = '';
foreach($closure as $opening)
$content .= $this->_tag('li', $this->_renderOne($opening));
return $this->_tag('li',
$this->_tag('h3',
$this->view->_plural(count($closure),
'',
'Fermeture exceptionnelle',
'Fermetures exceptionnelles'))
. $this->_tag('ul', $content));
}
protected function _renderExceptionals($exceptional) {
if (!$exceptional)
return '';
$content = '';
foreach($exceptional as $opening)
$content .= $this->_tag('li', $this->_renderOne($opening));
return $this->_tag('li',
$this->_tag('h3',
$this->view->_plural(count($exceptional),
'',
'Ouverture exceptionnelle',
'Ouvertures exceptionnelles'))
. $this->_tag('ul', $content));
}
protected function _renderOne($opening) {
$am = $this->_renderTimeSegment($opening->getDebutMatin(), $opening->getFinMatin());
$pm = $this->_renderTimeSegment($opening->getDebutApresMidi(), $opening->getFinApresMidi());
$hours = $this->_renderTimes($am, $pm);
return $opening->getFormattedJour()
. ($hours ? (' : ' . str_replace('h00', 'h', $hours)) : '');
}
protected function _renderTimeSegment($from, $to) {
if ($from == $to)
return $this->_renderHour($from);
$from = $this->_renderHour($from);
$to = $this->_renderHour($to);
return $from && $to
? $from . ' - ' . $to
: '';
}
protected function _renderHour($hour) {
return '00:00' == $hour ? '' : str_replace(':', 'h', $hour);
}
protected function _renderTimes($am, $pm) {
if ('' != $am && '' != $pm) {
if (substr($am, -5, 5) == substr($pm, 0, 5))
return substr($am, 0, 5) . substr($pm, 5);
return $am . ' / ' . $pm;
}
if ($am)
return $am;
return $pm;
}
}
\ 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