Commit b3c0012e authored by Ghislain Loas's avatar Ghislain Loas

Merge branch 'hotline#108948_pb_affichage_heures_sur_les_articles' into 'hotline'

hotline #108948 : fix time display on articles in templates

See merge request !3498
parents dd1e8f8c c8b6dd38
Pipeline #10036 canceled with stage
in 6 minutes and 12 seconds
- ticket #108948 : Article : correction de l'affichage des horaires dans les thèmes du magasin de thèmes
\ No newline at end of file
......@@ -110,13 +110,14 @@ class Intonation_Library_View_Wrapper_Article extends Intonation_Library_View_Wr
public function getBadges() {
$badges = [];
$title = $this->_model->getTitre();
if ($this->_model->isStatusDraft())
$badges [] = ((new Intonation_Library_Badge)
->setTag('span')
->setClass('danger')
->setText($this->_('Brouillon'))
->setTitle($this->_('Cet article "%s" est un brouillon.', $this->_model->getTitre())));
->setTitle($this->_('Cet article "%s" est un brouillon.', $title)));
if (($library = $this->_model->getBib()) && !$library->isPortail())
$badges [] = ((new Intonation_Library_Badge)
......@@ -130,44 +131,24 @@ class Intonation_Library_View_Wrapper_Article extends Intonation_Library_View_Wr
'library',
'library'))
->setText($library->getLibelle())
->setTitle($this->_('Bibliothèque de l\'article "%s"', $this->_model->getTitre())));
->setTitle($this->_('Bibliothèque de l\'article "%s"', $title)));
$badges [] = ((new Intonation_Library_Badge)
->setTag('span')
->setClass('info')
->setText($this->_model->getCategorieLibelle())
->setTitle($this->_('Catégorie de l\'article "%s"', $this->_model->getTitre())));
->setTitle($this->_('Catégorie de l\'article "%s"', $title)));
if ($location = $this->_model->getLieuLibelle())
$badges [] = ((new Intonation_Library_Badge)
->setTag('span')
->setClass('secondary')
->setText($location)
->setTitle($this->_('Lieu relié à l\'article "%s"', $this->_model->getTitre())));
->setTitle($this->_('Lieu relié à l\'article "%s"', $title)));
if ($event_start = $this->_model->getEventsDebut())
$badges [] = (new Intonation_Library_Badge)
->setTag('span')
->setClass('success')
->setText($this->_('%s à %s',
strftime($this->_('%d/%m/%Y'), strtotime($event_start)),
strftime($this->_('%H:%M'), strtotime($event_start))))
->setTitle($this->_('"%s" commence le %s à %s',
$this->_model->getTitre(),
strftime($this->_('%d %B %Y'), strtotime($event_start)),
strftime($this->_('%Hh%Mm'), strtotime($event_start))));
if ($event_end = $this->_model->getEventsFin())
$badges [] = (new Intonation_Library_Badge)
->setTag('span')
->setClass('warning')
->setText($this->_('%s à %s',
strftime($this->_('%d/%m/%Y'), strtotime($event_end)),
strftime($this->_('%H:%M'), strtotime($event_end))))
->setTitle($this->_('"%s" finit le %s à %s',
$this->_model->getTitre(),
strftime($this->_('%d %B %Y'), strtotime($event_end)),
strftime($this->_('%Hh%Mm'), strtotime($event_end))));
$badges = (new Intonation_Library_View_Wrapper_ArticleDateTimeBadges($this->_view, $this->_model))
->injectInto($badges);
if ($tags = $this->_model->getTags()) {
foreach(array_filter(explode(';', $tags)) as $tag) {
......@@ -178,7 +159,7 @@ class Intonation_Library_View_Wrapper_Article extends Intonation_Library_View_Wr
->setText($tag)
->setTitle($this->_('L\'étiquette "%s" de l\'article "%s".',
$tag,
$this->_model->getTitre())));
$title)));
}
}
......@@ -277,4 +258,142 @@ class Intonation_Library_View_Wrapper_Article extends Intonation_Library_View_Wr
public function getOsmData() {
return null;
}
}
class Intonation_Library_View_Wrapper_ArticleDateTimeBadges {
use Trait_Translator;
protected $_view, $_model;
public function __construct($view, $model) {
$this->_view = $view;
$this->_model = $model;
}
public function injectInto($badges) {
return $this->_injectEventEnd($this->_injectEventStart($badges));
}
protected function _injectEventStart($badges) {
return (new Intonation_Library_View_Wrapper_ArticleDateTimeBadges_EventStart($this->_view, $this->_model))
->injectInto($badges);
}
protected function _injectEventEnd($badges) {
return (new Intonation_Library_View_Wrapper_ArticleDateTimeBadges_EventEnd($this->_view, $this->_model))
->injectInto($badges);
}
protected function _badge($time) {
return (new Intonation_Library_Badge)
->setTag('span')
->setClass('success')
->setText($this->_text($time))
->setTitle($this->_title($time));
}
protected function _text($time) {
return $this->_model->getAllDay()
? $this->_shortDate($time)
: $this->_('%s à %s', $this->_shortDate($time), $this->_shortTime($time));
}
protected function _title($time) {
return $this->_model->getAllDay()
? sprintf($this->_dateTitle(),
$this->_model->getTitre(), $this->_longDate($time))
: sprintf($this->_dateTimeTitle(),
$this->_model->getTitre(), $this->_longDate($time), $this->_longTime($time));
}
protected function _shortDate($time) {
return strftime($this->_('%d/%m/%Y'), $time);
}
protected function _shortTime($time) {
return strftime($this->_('%H:%M'), $time);
}
protected function _longDate($time) {
return strftime($this->_('%d %B %Y'), $time);
}
protected function _longTime($time) {
return strftime($this->_('%Hh%Mm'), $time);
}
protected function _dateTitle() {
return '';
}
protected function _dateTimeTitle() {
return '';
}
}
class Intonation_Library_View_Wrapper_ArticleDateTimeBadges_EventStart
extends Intonation_Library_View_Wrapper_ArticleDateTimeBadges {
public function injectInto($badges) {
if (!$datetime = $this->_model->getEventsDebut())
return $badges;
$badges [] = $this->_badge(strtotime($datetime));
return $badges;
}
protected function _dateTitle() {
return $this->_('"%s" commence le %s');
}
protected function _dateTimeTitle() {
return $this->_('"%s" commence le %s à %s');
}
}
class Intonation_Library_View_Wrapper_ArticleDateTimeBadges_EventEnd
extends Intonation_Library_View_Wrapper_ArticleDateTimeBadges {
public function injectInto($badges) {
if (!$datetime = $this->_model->getEventsFin())
return $badges;
$badges [] = $this->_badge(strtotime($datetime));
return $badges;
}
protected function _dateTitle() {
return $this->_('"%s" finit le %s');
}
protected function _dateTimeTitle() {
return $this->_('"%s" finit le %s à %s');
}
}
\ No newline at end of file
......@@ -1964,21 +1964,47 @@ class TemplatesCmsListActionTest extends TemplatesIntonationTestCase {
class TemplatesCmsArticleViewTest extends TemplatesIntonationTestCase {
/** @test */
public function dispatchShouldRenderParlerVousFrançais() {
public function setUp() {
parent::setUp();
$this->fixture('Class_Article',
['id' => 7,
'titre' => 'Parlez-vous français ?',
'contenu' => '<p>Une b...</p>']);
'contenu' => '<p>Une b...</p>',
'events_debut' => '2020-03-13 00:00:00',
'events_fin' => '2020-07-31 00:00:00',
'all_day' => 1]);
$this->dispatch('/opac/cms/articleview/id/7/id_profil/72', true);
$this->dispatch('/opac/cms/articleview/id/7/id_profil/72');
}
/** @test */
public function parlerVousFrançaisShouldBePresent() {
$this->assertXPathContentContains('//main//div', 'Parlez-vous français ?');
}
/** @test */
public function timeOfEventShouldNotBePresent() {
$this->assertNotXPathContentContains('//span', '00:00');
}
/** @test */
public function eventStartShouldNotBePresent() {
$this->assertXPathContentContains('//span', '13/03/2020');
}
/** @test */
public function eventEndShouldNotBePresent() {
$this->assertXPathContentContains('//span', '31/07/2020');
}
}
class TemplatesViewRecordTest extends TemplatesIntonationTestCase {
public function setUp() {
parent::setUp();
......
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