Move custom bundle
This commit is contained in:
parent
ee40679c95
commit
b903baaaf3
8 changed files with 13 additions and 20 deletions
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace FormatTalksBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
|
||||
class SculpinFormatTalksExtension extends Extension
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
|
||||
$loader->load('services.yml');
|
||||
}
|
||||
}
|
5
src/FormatTalksBundle/Resources/config/services.yml
Normal file
5
src/FormatTalksBundle/Resources/config/services.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
services:
|
||||
twig.format_talks:
|
||||
class: 'FormatTalksBundle\Twig\FormatTalksExtension'
|
||||
tags:
|
||||
- { name: twig.extension }
|
7
src/FormatTalksBundle/SculpinFormatTalksBundle.php
Normal file
7
src/FormatTalksBundle/SculpinFormatTalksBundle.php
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace FormatTalksBundle;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
class SculpinFormatTalksBundle extends Bundle {}
|
53
src/FormatTalksBundle/Twig/FormatTalksExtension.php
Normal file
53
src/FormatTalksBundle/Twig/FormatTalksExtension.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace FormatTalksBundle\Twig;
|
||||
|
||||
class FormatTalksExtension extends \Twig_Extension
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return [
|
||||
new \Twig_SimpleFilter('format_talks', [$this, 'formatTalks']),
|
||||
];
|
||||
}
|
||||
|
||||
public function formatTalks($data, $onlyUpcoming = false, $onlyPrevious = false)
|
||||
{
|
||||
$event_data = $data['events'];
|
||||
|
||||
$talks = [];
|
||||
foreach ($data['talks'] as $talk) {
|
||||
foreach ($talk['events'] as $event) {
|
||||
$event = array_merge($event, $event_data[$event['event']]);
|
||||
|
||||
$talks[] = compact('talk', 'event');
|
||||
}
|
||||
}
|
||||
|
||||
$today = (new \DateTime())->format('Y-m-d');
|
||||
|
||||
return collect($talks)
|
||||
->filter(function ($talk) use ($today, $onlyPrevious, $onlyUpcoming) {
|
||||
if ($onlyUpcoming) {
|
||||
return $talk['event']['date'] > $today;
|
||||
}
|
||||
|
||||
if ($onlyPrevious) {
|
||||
return $talk['event']['date'] < $today;
|
||||
}
|
||||
|
||||
return true;
|
||||
})->sortByDesc('event.date')->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'format_talks';
|
||||
}
|
||||
}
|
5
src/FormatTalksBundle/composer.json
Normal file
5
src/FormatTalksBundle/composer.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"require": {
|
||||
"tightenco/collect": "^5.4"
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue