allow filtering events by month

master
Tezza 2015-02-27 01:24:08 +01:00
parent 4b26828d26
commit 74ff436b80
2 changed files with 38 additions and 4 deletions

View File

@ -160,4 +160,20 @@
} }
static public function getEventsByMonth( $events, $year, $month ) {
foreach( $events as $event ) {
if ( ( date( 'Y', $event[ 'start' ] ) == $year ) && ( date( 'm', $event[ 'start' ] ) == $month ) ) {
$eventsInMonth[] = $event;
}
}
return $eventsInMonth;
}
} }

View File

@ -4,6 +4,7 @@
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request;
class WebControllerProvider implements ControllerProviderInterface { class WebControllerProvider implements ControllerProviderInterface {
@ -28,17 +29,34 @@
}); });
$ctr->get('/events', function() use ( $app ) { $ctr->get('/events/', function() use ( $app ) {
return $app['twig']->render( return $app['twig']->render(
'events.twig', 'events.twig',
array( array(
'page' => 'events', 'page' => 'events',
'level2' => Level2::getStatus( $app ), 'level2' => Level2::getStatus( $app ),
'events' => array_slice( 'events' => Level2::getEventsByMonth(
Level2::getEvents( $app ), Level2::getEvents( $app ),
0, date( 'Y' ),
100 date( 'm' )
)
)
);
});
$ctr->get('/events/{year}/{month}', function( $year, $month ) use ( $app ) {
return $app['twig']->render(
'events.twig',
array(
'page' => 'events',
'level2' => Level2::getStatus( $app ),
'events' => Level2::getEventsByMonth(
Level2::getEvents( $app ),
$year,
$month
) )
) )
); );