test with 5 events from the google calendar

master
Tezza 2015-02-23 15:45:47 +01:00
parent 33acb99851
commit 506ee8898d
5 changed files with 99 additions and 28 deletions

View File

@ -5,6 +5,8 @@
require_once __DIR__.'/bootstrap.php';
date_default_timezone_set ( 'Europe/Luxembourg' );
$app = new Silex\Application();
$app->register(

View File

@ -1,3 +1,7 @@
{
"debug" : false
"debug" : false,
"google" : {
"api_key" : "",
"calendar_id" : ""
}
}

View File

@ -6,7 +6,7 @@
class Level2 {
static public function getStatus () {
static public function getStatus() {
$spaceAPI = json_decode(
file_get_contents( 'https://spaceapi.syn2cat.lu/status/json' ),
@ -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;
}
}

View File

@ -16,7 +16,12 @@
return $app['twig']->render(
'level2.twig',
array(
'level2' => Level2::getStatus()
'level2' => Level2::getStatus(),
'events' => array_slice(
Level2::getEvents( $app ),
0,
5
)
)
);

View File

@ -2,39 +2,41 @@
{% block container %}
<!-- Example row of columns -->
<div class="row">
<div class="col-sm-4">
<h2>Events</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 class="col-sm-8">
<div class="row">
{% for event in events %}
<div class="row 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>
{% if event.url.0 is defined %}
<a href="{{ event.url.0 }}">
{{ event.name }}
</a>
{% endif %}
</h2>
{% if event.location is defined %}
<h4>{{ event.location }}</h4>
{% endif %}
<p>{{ event.description }}</p>
</div>
</div>
{% 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>