🏡 index : ~doyle/zpan.git

author Jordan Doyle <jordan@doyle.wf> 2016-06-22 3:19:11.0 +01:00:00
committer Jordan Doyle <jordan@doyle.wf> 2016-06-22 3:19:11.0 +01:00:00
commit
d535c174d44653be36640b6f23ddb089b38e2cb3 [patch]
tree
a407c1959a9e154e9a75495430a81d20df9b59c4
parent
b0a1df09d56c70bf394127f92bca8af2034e7707
download
d535c174d44653be36640b6f23ddb089b38e2cb3.tar.gz

Add API method to get the current event



Diff

 app/Http/routes.php                                |  3 ++-
 app/Http/Controllers/Event/TimetableController.php | 28 ++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/app/Http/routes.php b/app/Http/routes.php
index 8f9f0bd..d179310 100644
--- a/app/Http/routes.php
+++ a/app/Http/routes.php
@@ -117,6 +117,7 @@
Route::group(['middleware' => 'api', 'as' => 'api::', 'prefix' => 'api'], function () {
    Route::get('dj-says', ['as' => 'dj-says', 'uses' => 'DJ\DJSaysController@getSays']);
    Route::get('timetable', ['as' => 'timetable', 'uses' => 'DJ\TimetableController@getJSONTimetable']);
    Route::get('events', ['as' => 'events', 'uses' => 'Event\TimetableController@getJSONTimetable']);
    Route::get('event/all', ['as' => 'events', 'uses' => 'Event\TimetableController@getJSONTimetable']);
    Route::get('event/current', ['as' => 'event.current', 'uses' => 'Event\TimetableController@getCurrentEvent']);
    Route::post('request', ['as' => 'request', 'uses' => 'DJ\RequestController@request']);
});
diff --git a/app/Http/Controllers/Event/TimetableController.php b/app/Http/Controllers/Event/TimetableController.php
index 3ee608e..48b265f 100644
--- a/app/Http/Controllers/Event/TimetableController.php
+++ a/app/Http/Controllers/Event/TimetableController.php
@@ -179,6 +179,34 @@
    }

    /**
     * Get the current event.
     *
     * @return array
     */
    public function getCurrentEvent()
    {
        $event = Event::where('week', Carbon::now()->weekOfYear)
            ->where('year', Carbon::now()->year)
            ->where('day', Carbon::now()->format('N'))
            ->where('hour', Carbon::now()->hour)
            ->where('approved', true)
            ->first();

        if ($event) {
            return [
                'id' => $event->user()->first()->userid,
                'name' => $event->user()->first()->getDisplayName()->toHtml(),
                'type' => $event->type->name,
                'booked' => true
            ];
        } else {
            return [
                'booked' => false
            ];
        }
    }

    /**
     * Get the booked slots for this week in JSON format.
     *
     * @param bool $raw should we return the user's name in raw html