Skip to content

Commit

Permalink
PHP code fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Github Actions Workflow committed Aug 19, 2020
1 parent 4109986 commit 863e5ac
Showing 1 changed file with 46 additions and 45 deletions.
91 changes: 46 additions & 45 deletions src/TwigExtension/ArcheTwigDateExtension.php
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
<?php

namespace Drupal\acdh_repo_gui\TwigExtension;

class ArcheTwigDateExtension extends \Twig_Extension {

public function getFilters() {
return [ new \Twig_SimpleFilter('archeTranslateDateFilter', function($value, $dateformat){
(isset($_SESSION['language'])) ? $lang = strtolower($_SESSION['language']) : $lang = "en";

$dateformat = $this->extendDateFormat($dateformat);

if($lang == 'de') {
setlocale( LC_TIME , 'de_DE.utf8');
return strftime($dateformat, strtotime($value));
} else {
setlocale( LC_TIME , 'en_US.utf8');
return strftime($dateformat, strtotime($value));
}
})
];

}

/**
* Gets a unique identifier for this Twig extension.
*/
public function getName() {
return 'acdh_repo_gui.twig_extension';
}

/**
* change the datefomat to work with strftime
*
* @param string $dateformat
* @return string
*/
private function extendDateFormat(string $dateFormat): string {
$search = array('Y', 'y', 'M', 'm', 'D', 'd');
$replace = array('%Y', '%y', '%b', '%m', '%d', '%d');

return str_replace($search, $replace, $dateFormat);
}

}
<?php

namespace Drupal\acdh_repo_gui\TwigExtension;

class ArcheTwigDateExtension extends \Twig_Extension
{
public function getFilters()
{
return [ new \Twig_SimpleFilter('archeTranslateDateFilter', function ($value, $dateformat) {
(isset($_SESSION['language'])) ? $lang = strtolower($_SESSION['language']) : $lang = "en";

$dateformat = $this->extendDateFormat($dateformat);

if ($lang == 'de') {
setlocale(LC_TIME, 'de_DE.utf8');
return strftime($dateformat, strtotime($value));
} else {
setlocale(LC_TIME, 'en_US.utf8');
return strftime($dateformat, strtotime($value));
}
})
];
}

/**
* Gets a unique identifier for this Twig extension.
*/
public function getName()
{
return 'acdh_repo_gui.twig_extension';
}

/**
* change the datefomat to work with strftime
*
* @param string $dateformat
* @return string
*/
private function extendDateFormat(string $dateFormat): string
{
$search = array('Y', 'y', 'M', 'm', 'D', 'd');
$replace = array('%Y', '%y', '%b', '%m', '%d', '%d');

return str_replace($search, $replace, $dateFormat);
}
}

0 comments on commit 863e5ac

Please sign in to comment.