diff --git a/app/Fieldprotocol/Music/Album.php b/app/Fieldprotocol/Music/Album.php index 1290f1c..12f5bd8 100644 --- a/app/Fieldprotocol/Music/Album.php +++ b/app/Fieldprotocol/Music/Album.php @@ -19,4 +19,16 @@ class Album extends Eloquent { return $this->hasMany('Fieldprotocol\Music\Song'); } + public function links() { + return $this->hasMany('Fieldprotocol\Music\StoreLink', 'album_id'); + } + + public function releaseDate() { + return date('F j, Y', strtotime($this->release_date)); + } + + public function releaseYear() { + return date('Y', strtotime($this->release_date)); + } + } diff --git a/app/Fieldprotocol/Music/StoreLink.php b/app/Fieldprotocol/Music/StoreLink.php new file mode 100644 index 0000000..fcce421 --- /dev/null +++ b/app/Fieldprotocol/Music/StoreLink.php @@ -0,0 +1,20 @@ +belongsTo('Fieldprotocol\Music\Album', 'album_id'); + } + +} diff --git a/app/routes.php b/app/routes.php index 8cb4c0b..73398c5 100755 --- a/app/routes.php +++ b/app/routes.php @@ -1,9 +1,15 @@ get('/apiv1/music/album-info/:albumid', function($albumid) use($app) { + + if (!ctype_digit($albumid)) { + echo 'Don\'t do that'; + return; + } + + $album = $app->album->where('id', $albumid)->first(); + + if ($album) { + echo json_encode($album); + } else { + $app->notFound(); + } + +})->name('apiv1.music.album-info'); + +// retrieve an album's songs +$app->get('/apiv1/music/album-songs/:albumid', function($albumid) use($app) { + + if (!ctype_digit($albumid)) { + echo 'Don\'t do that'; + return; + } + + $album = $app->album->where('id', $albumid)->first(); + + if ($album) { + $json = ['songs' => $album->songs]; + echo json_encode($json); + } else { + $app->notFound(); + } + +})->name('apiv1.music.album-songs'); diff --git a/app/routes/errors/404.php b/app/routes/errors/404.php new file mode 100644 index 0000000..de40286 --- /dev/null +++ b/app/routes/errors/404.php @@ -0,0 +1,5 @@ +notFound(function() use ($app) { + $app->render('errors/404.twig'); +}); diff --git a/app/routes/music.php b/app/routes/music.php deleted file mode 100755 index 2e1ea9e..0000000 --- a/app/routes/music.php +++ /dev/null @@ -1,13 +0,0 @@ -get('/music', function() use($app) { - - $albums = $app->album->all()->sortByDesc('release_date')->values()->all(); - $songs = $albums[0]->songs; - - $app->render('music.twig', [ - 'albums' => $albums, - 'songs' => $songs, - ]); - -})->name('music'); diff --git a/app/routes/about.php b/app/routes/pages/about.php similarity index 66% rename from app/routes/about.php rename to app/routes/pages/about.php index 5857481..fdad5dc 100755 --- a/app/routes/about.php +++ b/app/routes/pages/about.php @@ -2,6 +2,6 @@ $app->get('/about', function() use($app) { - $app->render('about.twig'); + $app->render('pages/about.twig'); })->name('about'); diff --git a/app/routes/contact.php b/app/routes/pages/contact.php similarity index 66% rename from app/routes/contact.php rename to app/routes/pages/contact.php index e125bd9..931f4a6 100755 --- a/app/routes/contact.php +++ b/app/routes/pages/contact.php @@ -2,6 +2,6 @@ $app->get('/contact', function() use($app) { - $app->render('contact.twig'); + $app->render('pages/contact.twig'); })->name('contact'); diff --git a/app/routes/home.php b/app/routes/pages/home.php similarity index 66% rename from app/routes/home.php rename to app/routes/pages/home.php index be6b6c8..d55a9e0 100755 --- a/app/routes/home.php +++ b/app/routes/pages/home.php @@ -2,6 +2,6 @@ $app->get('/home', function() use($app) { - $app->render('home.twig'); + $app->render('pages/home.twig'); })->name('home'); diff --git a/app/routes/index.php b/app/routes/pages/index.php similarity index 100% rename from app/routes/index.php rename to app/routes/pages/index.php diff --git a/app/routes/pages/music.php b/app/routes/pages/music.php new file mode 100755 index 0000000..f64ba0d --- /dev/null +++ b/app/routes/pages/music.php @@ -0,0 +1,16 @@ +get('/music', function() use($app) { + + $albums = $app->album->all()->sortByDesc('release_date')->values()->all(); + $songs = $albums[0]->songs; + $links = $albums[0]->links; + + $app->render('pages/music.twig', [ + 'albums' => $albums, + 'songs' => $songs, + 'links' => $links, + ]); + +})->name('music'); diff --git a/app/routes/shows.php b/app/routes/pages/shows.php similarity index 96% rename from app/routes/shows.php rename to app/routes/pages/shows.php index df150e7..32863e3 100755 --- a/app/routes/shows.php +++ b/app/routes/pages/shows.php @@ -10,7 +10,7 @@ $app->get('/shows', function() use($app) { $show->time = date('H:i', strtotime($show->datetime)); } - $app->render('shows.twig', [ + $app->render('pages/shows.twig', [ 'shows' => $shows, ]); diff --git a/app/views/errors/404.twig b/app/views/errors/404.twig new file mode 100644 index 0000000..d63907a --- /dev/null +++ b/app/views/errors/404.twig @@ -0,0 +1,13 @@ +{% extends 'templates/default.twig' %} + +{% block title %}404 Error{% endblock %} + +{% block content %} + +
+
+

404 Error

+

The URL you were looking for doesn't exist. Perhaps you'd like to start over at the home page?

+
+
+{% endblock %} diff --git a/app/views/about.twig b/app/views/pages/about.twig similarity index 100% rename from app/views/about.twig rename to app/views/pages/about.twig diff --git a/app/views/contact.twig b/app/views/pages/contact.twig similarity index 100% rename from app/views/contact.twig rename to app/views/pages/contact.twig diff --git a/app/views/home.twig b/app/views/pages/home.twig similarity index 100% rename from app/views/home.twig rename to app/views/pages/home.twig diff --git a/app/views/music.twig b/app/views/pages/music.twig similarity index 53% rename from app/views/music.twig rename to app/views/pages/music.twig index c5784b7..64a9018 100644 --- a/app/views/music.twig +++ b/app/views/pages/music.twig @@ -1,7 +1,6 @@ {% extends 'templates/default.twig' %} {% block javascripts %} - {% endblock %} @@ -21,12 +20,21 @@
- {{ albums[0].title }} + {{ albums[0].title }}
-

{{ albums[0].title }}

+

{{ albums[0].title }}

+
Released on {{ albums[0].releaseDate }}
{% if albums[0].description %}
-

{{ albums[0].description }}

+

{{ albums[0].description }}

+ {% endif %} + {% if links %} +
+ {% endif %}
@@ -35,6 +43,7 @@
+

{{ songs[0].title }}