test with 5 events from the google calendar
parent
33acb99851
commit
506ee8898d
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
require_once __DIR__.'/bootstrap.php';
|
require_once __DIR__.'/bootstrap.php';
|
||||||
|
|
||||||
|
date_default_timezone_set ( 'Europe/Luxembourg' );
|
||||||
|
|
||||||
$app = new Silex\Application();
|
$app = new Silex\Application();
|
||||||
|
|
||||||
$app->register(
|
$app->register(
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
{
|
{
|
||||||
"debug" : false
|
"debug" : false,
|
||||||
|
"google" : {
|
||||||
|
"api_key" : "",
|
||||||
|
"calendar_id" : ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,4 +22,62 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public function getEvents( $app ) {
|
||||||
|
|
||||||
|
$googleCalendarJson = 'https://www.googleapis.com/calendar/v3/calendars/'
|
||||||
|
. $app[ 'google' ][ 'calendar_id' ] . '/events'
|
||||||
|
. '?singleEvents=true'
|
||||||
|
. '&orderBy=startTime'
|
||||||
|
. '&timeMin=2015-02-22T00%3A00%3A00%2B01%3A00'
|
||||||
|
. '&fields=description%2Citems(description%2Crecurrence%2Csummary%2Clocation%2Cstart%2Cend)%2Csummary'
|
||||||
|
. '&key=' . $app[ 'google' ][ 'api_key' ];
|
||||||
|
|
||||||
|
$googleCalendar = json_decode(
|
||||||
|
file_get_contents( $googleCalendarJson ),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach( $googleCalendar[ 'items' ] as $googleEvent ) {
|
||||||
|
|
||||||
|
$event[ 'name' ] = $googleEvent[ 'summary' ];
|
||||||
|
|
||||||
|
if ( array_key_exists( 'dateTime' , $googleEvent[ 'start' ] ) ){
|
||||||
|
$event[ 'start' ][ 'datetime' ] = strtotime( $googleEvent[ 'start' ][ 'dateTime' ] );
|
||||||
|
} else {
|
||||||
|
$event[ 'start' ][ 'date' ] = strtotime( $googleEvent[ 'start' ][ 'date' ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( array_key_exists( 'dateTime' , $googleEvent[ 'end' ] ) ){
|
||||||
|
$event[ 'end' ][ 'datetime' ] = strtotime( $googleEvent[ 'end' ][ 'dateTime' ] );
|
||||||
|
} else {
|
||||||
|
$event[ 'end' ][ 'date' ] = strtotime( $googleEvent[ 'end' ][ 'date' ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( array_key_exists( 'location' , $googleEvent ) ){
|
||||||
|
$event[ 'location' ] = $googleEvent[ 'location' ];
|
||||||
|
}
|
||||||
|
|
||||||
|
unset( $url );
|
||||||
|
|
||||||
|
if ( array_key_exists( 'description' , $googleEvent ) ){
|
||||||
|
$event[ 'description' ] = $googleEvent[ 'description' ];
|
||||||
|
}
|
||||||
|
|
||||||
|
$urlMatch = '/\b(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)[-A-Z0-9+&@#\/%=~_|$\(\)?!:,.]*[A-Z0-9+&@#\/%=~_|$]/i';
|
||||||
|
preg_match_all( $urlMatch, $event[ 'description' ], $url, PREG_PATTERN_ORDER );
|
||||||
|
|
||||||
|
$event[ 'description' ] = preg_replace( $urlMatch, '', $event[ 'description' ] );
|
||||||
|
|
||||||
|
if ( is_array( $url ) ) {
|
||||||
|
$event[ 'url' ] = $url[ 0 ];
|
||||||
|
}
|
||||||
|
|
||||||
|
$events[] = $event;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $events;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,12 @@
|
||||||
return $app['twig']->render(
|
return $app['twig']->render(
|
||||||
'level2.twig',
|
'level2.twig',
|
||||||
array(
|
array(
|
||||||
'level2' => Level2::getStatus()
|
'level2' => Level2::getStatus(),
|
||||||
|
'events' => array_slice(
|
||||||
|
Level2::getEvents( $app ),
|
||||||
|
0,
|
||||||
|
5
|
||||||
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -2,39 +2,41 @@
|
||||||
|
|
||||||
{% block container %}
|
{% block container %}
|
||||||
|
|
||||||
<!-- Example row of columns -->
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
||||||
<div class="col-sm-4">
|
<div class="col-sm-4">
|
||||||
|
|
||||||
<h2>Events</h2>
|
<h2>Events</h2>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-8 event well">
|
|
||||||
|
<div class="col-sm-8">
|
||||||
|
|
||||||
|
{% for event in events %}
|
||||||
|
|
||||||
|
<div class="row event well">
|
||||||
|
|
||||||
<div class="col-sm-4">
|
<div class="col-sm-4">
|
||||||
<img src="https://www.hackerspace.lu/wp-content/uploads/2015/01/cfbtncrop.jpg" />
|
<img src="https://www.hackerspace.lu/wp-content/uploads/2015/01/cfbtncrop.jpg" />
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<h2>Hello from Tezza :)</h2>
|
<h2>
|
||||||
<h4>Engineering-desks</h4>
|
{% if event.url.0 is defined %}
|
||||||
<p>We're open every monday ;)</p>
|
<a href="{{ event.url.0 }}">
|
||||||
</div>
|
{{ event.name }}
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</h2>
|
||||||
|
{% if event.location is defined %}
|
||||||
|
<h4>{{ event.location }}</h4>
|
||||||
|
{% endif %}
|
||||||
|
<p>{{ event.description }}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
{% endfor %}
|
||||||
|
|
||||||
<div class="col-sm-4">
|
|
||||||
<h2>Hello from Tezza :)</h2>
|
|
||||||
</div>
|
|
||||||
<div class="col-sm-8 event well">
|
|
||||||
<div class="col-sm-4">
|
|
||||||
<img src="https://www.hackerspace.lu/wp-content/uploads/2015/01/cfbtncrop.jpg" />
|
|
||||||
</div>
|
|
||||||
<div class="col-sm-8">
|
|
||||||
<h2>Hello from Tezza :)</h2>
|
|
||||||
<h4>Engineering-desks</h4>
|
|
||||||
<p>We're open every monday ;)</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue