Move today variable
This commit is contained in:
parent
314e25ac11
commit
4aee2735ac
|
@ -8,11 +8,18 @@ use Twig_SimpleFilter;
|
||||||
|
|
||||||
class FormatTalksExtension extends Twig_Extension
|
class FormatTalksExtension extends Twig_Extension
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var string The current date.
|
||||||
|
*/
|
||||||
|
private $today;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getFilters()
|
public function getFilters()
|
||||||
{
|
{
|
||||||
|
$this->today = (new \DateTime())->format('Y-m-d');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
new Twig_SimpleFilter('all_talks', [$this, 'getAll']),
|
new Twig_SimpleFilter('all_talks', [$this, 'getAll']),
|
||||||
new Twig_SimpleFilter('upcoming_talks', [$this, 'getUpcoming']),
|
new Twig_SimpleFilter('upcoming_talks', [$this, 'getUpcoming']),
|
||||||
|
@ -43,10 +50,8 @@ class FormatTalksExtension extends Twig_Extension
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getUpcoming(array $data) {
|
public function getUpcoming(array $data) {
|
||||||
$today = (new \DateTime())->format('Y-m-d');
|
$talks = $this->format($data)->filter(function ($talk) {
|
||||||
|
return $talk['event']['date'] >= $this->today;
|
||||||
$talks = $this->format($data)->filter(function ($talk) use ($today) {
|
|
||||||
return $talk['event']['date'] >= $today;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->sort($talks);
|
return $this->sort($talks);
|
||||||
|
@ -62,10 +67,8 @@ class FormatTalksExtension extends Twig_Extension
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getPast(array $data) {
|
public function getPast(array $data) {
|
||||||
$today = (new \DateTime())->format('Y-m-d');
|
$talks = $this->format($data)->filter(function ($talk) {
|
||||||
|
return $talk['event']['date'] < $this->today;
|
||||||
$talks = $this->format($data)->filter(function ($talk) use ($today) {
|
|
||||||
return $talk['event']['date'] < $today;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this->sort($talks);
|
return $this->sort($talks);
|
||||||
|
|
Loading…
Reference in a new issue