Skip to content

Commit

Permalink
Fix for date formatter twig extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
dasgarner committed Sep 3, 2020
1 parent cdb4b43 commit 9597ce1
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 74 deletions.
1 change: 0 additions & 1 deletion bin/locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
$twig->addExtension(new \Slim\Views\TwigExtension());
$twig->addExtension(new \Xibo\Twig\TransExtension());
$twig->addExtension(new \Xibo\Twig\ByteFormatterTwigExtension());
$twig->addExtension(new \Xibo\Twig\UrlDecodeTwigExtension());
$twig->addExtension(new \Xibo\Twig\DateFormatTwigExtension());


Expand Down
22 changes: 12 additions & 10 deletions lib/Controller/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -888,18 +888,20 @@ public function preview(Request $request, Response $response, $id)
$duration = 0 ;
$extendedLayouts = [];

foreach($layouts as $layout)
foreach ($layouts as $layout)
{
$duration += $layout->duration;
$extendedLayouts[] = ['layout' => $layout,
'duration' => $layout->duration,
'previewOptions' => [
'getXlfUrl' => $this->urlFor($request,'layout.getXlf', ['id' => $layout->layoutId]),
'getResourceUrl' => $this->urlFor($request,'module.getResource', ['regionId' => ':regionId', 'id' => ':id']),
'libraryDownloadUrl' => $this->urlFor($request,'library.download'),
'layoutBackgroundDownloadUrl' => $this->urlFor($request,'layout.download.background', ['id' => ':id']),
'loaderUrl' => $this->getConfig()->uri('img/loader.gif')]
];
$extendedLayouts[] = [
'layout' => $layout,
'duration' => $layout->duration,
'previewOptions' => [
'getXlfUrl' => $this->urlFor($request,'layout.getXlf', ['id' => $layout->layoutId]),
'getResourceUrl' => $this->urlFor($request,'module.getResource', ['regionId' => ':regionId', 'id' => ':id']),
'libraryDownloadUrl' => $this->urlFor($request,'library.download'),
'layoutBackgroundDownloadUrl' => $this->urlFor($request,'layout.download.background', ['id' => ':id']),
'loaderUrl' => $this->getConfig()->uri('img/loader.gif')
]
];
}
$this->getState()->template = 'campaign-preview';
$this->getState()->setData([
Expand Down
1 change: 0 additions & 1 deletion lib/Factory/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public static function create()
]);
$view->addExtension(new TransExtension());
$view->addExtension(new ByteFormatterTwigExtension());
$view->addExtension(new UrlDecodeTwigExtension());
$view->addExtension(new DateFormatTwigExtension());

return $view;
Expand Down
31 changes: 24 additions & 7 deletions lib/Twig/ByteFormatterTwigExtension.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
<?php
/*
* Spring Signage Ltd - http://www.springsignage.com
* Copyright (C) 2015 Spring Signage Ltd
* (ByteFormatterTwigExtension.php)
* Copyright (C) 2020 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
* This file is part of Xibo.
*
* Xibo 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, either version 3 of the License, or
* any later version.
*
* Xibo 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 Xibo. If not, see <http://www.gnu.org/licenses/>.
*/


namespace Xibo\Twig;


use Xibo\Helper\ByteFormatter;
use Twig\Extension\AbstractExtension;
use Xibo\Helper\ByteFormatter;

/**
* Class ByteFormatterTwigExtension
* @package Xibo\Twig
*/
class ByteFormatterTwigExtension extends AbstractExtension
{
public function getName()
Expand Down
31 changes: 24 additions & 7 deletions lib/Twig/DateFormatTwigExtension.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
<?php
/*
* Spring Signage Ltd - http://www.springsignage.com
* Copyright (C) 2015 Spring Signage Ltd
* (DateFormatTwigExtension.php)
* Copyright (C) 2020 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
* This file is part of Xibo.
*
* Xibo 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, either version 3 of the License, or
* any later version.
*
* Xibo 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 Xibo. If not, see <http://www.gnu.org/licenses/>.
*/


namespace Xibo\Twig;


use Twig\Extension\AbstractExtension;

/**
* Class DateFormatTwigExtension
* @package Xibo\Twig
*/
class DateFormatTwigExtension extends AbstractExtension
{
/**
Expand All @@ -19,7 +36,7 @@ class DateFormatTwigExtension extends AbstractExtension
public function getFilters()
{
return array(
'datehms' => new \Twig\TwigFilter('dateFormat', $this)
new \Twig\TwigFilter('datehms', [$this, 'dateFormat'])
);
}

Expand All @@ -30,7 +47,7 @@ public function getFilters()
*
* @return string formated as HH:mm:ss
*/
public function dateFormat( $date )
public function dateFormat($date)
{
return gmdate('H:i:s', $date);
}
Expand Down
47 changes: 0 additions & 47 deletions lib/Twig/UrlDecodeTwigExtension.php

This file was deleted.

2 changes: 1 addition & 1 deletion views/campaign-preview.twig
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
{% autoescape "js" %}
previewTranslations.actionControllerTitle = "{{ "Action Controller"|trans }}";
previewTranslations.navigateToLayout = "{{ "Navigate to layout with code [layoutTag]?"|trans }}";
previewTranslations.emptyRegionMessage = "{{% "Empty Region"|trans }}";
previewTranslations.emptyRegionMessage = "{{ "Empty Region"|trans }}";
{% endautoescape %}
(function($){
Expand Down

0 comments on commit 9597ce1

Please sign in to comment.