diff --git a/application/controllers/Albums.php b/application/controllers/Albums.php index e512f08..87476a6 100644 --- a/application/controllers/Albums.php +++ b/application/controllers/Albums.php @@ -9,11 +9,21 @@ class Albums extends CI_Controller { $this->load->library('session'); } public function index(){ - $albums = $this->model_music->getAlbums(); + $genre = $this->input->get('genre'); + $order = $this->input->get('order'); + $artist = $this->input->get('artist'); + + $albums = $this->model_music->getAlbums($genre, $order, $artist); + $genres = $this->model_music->researchtype(); + $artists = $this->model_music->nameArtist(); + $is_logged_in = $this->session->userdata('logged_in'); $data = array( 'albums' => $albums, - 'is_logged_in' => $is_logged_in + 'is_logged_in' => $is_logged_in, + 'genres' => $genre, + 'artistes' => $artist + ); $this->load->view('layout/header',$data); $this->load->view('albums_list', $data); diff --git a/application/controllers/Artist.php b/application/controllers/Artist.php new file mode 100644 index 0000000..39dc217 --- /dev/null +++ b/application/controllers/Artist.php @@ -0,0 +1,21 @@ +<?php +defined('BASEPATH') OR exit('No direct script access allowed'); + +class Artist extends CI_Controller { + + public function __construct(){ + parent::__construct(); + $this->load->model('model_music'); + } + public function index(){ + $genre = $this->input->get('genre'); + $order = $this->input->get('order'); + $artists = $this->model_music->getArtists($genre, $order); + $genres = $this->model_music->researchtype(); + $this->load->view('layout/header',['genres'=>$genres]); + $this->load->view('artists_name',['artists'=>$artists]); + $this->load->view('layout/footer'); + } + +} + diff --git a/application/controllers/Music.php b/application/controllers/Music.php new file mode 100644 index 0000000..76180b6 --- /dev/null +++ b/application/controllers/Music.php @@ -0,0 +1,23 @@ +<?php +defined('BASEPATH') OR exit('No direct script access allowed'); + +class Music extends CI_Controller { + + public function __construct(){ + parent::__construct(); + $this->load->model('model_music'); + } + + + public function index(){ + $genre = $this->input->get('genre'); + $order = $this->input->get('order'); + $musics = $this->model_music->getMusics($genre, $order); + $genres = $this->model_music->researchtype(); + $this->load->view('layout/header',['genres'=>$genres]); + $this->load->view('musiques_name',['musics'=>$musics]); + $this->load->view('layout/footer'); + } + +} + diff --git a/application/models/Model_music.php b/application/models/Model_music.php index ddcbb79..fed9d72 100644 --- a/application/models/Model_music.php +++ b/application/models/Model_music.php @@ -5,16 +5,118 @@ class Model_music extends CI_Model { $this->load->database(); } - public function getAlbums(){ - $query = $this->db->query( - "SELECT album.name,album.id,year,artist.name as artistName, genre.name as genreName,jpeg - FROM album - JOIN artist ON album.artistid = artist.id - JOIN genre ON genre.id = album.genreid - JOIN cover ON cover.id = album.coverid - ORDER BY year - " - ); - return $query->result(); + public function getAlbums($genre = '', $order = '', $artist = '') { + $this->db->select('album.name, album.id, year, artist.name as artistName, genre.name as genreName, jpeg'); + $this->db->from('album'); + $this->db->join('artist', 'album.artistid = artist.id'); + $this->db->join('genre', 'genre.id = album.genreid'); + $this->db->join('cover', 'cover.id = album.coverid'); + + + if(!empty($genre)){ + $this->db->where('genre.name', $genre); + } + + if(!empty($artist)){ + $this->db->where('artist.name', $artist); + } + + + + if($order == 'asc' || $order == 'desc'){ + $this->db->order_by('album.name',$order ); + } + + + $query = $this->db->get(); + return $query->result(); } + + + public function getArtists($genre = '', $order = '') { + $this->db->select('artist.name as artistName, artist.id as artistId'); + $this->db->from('artist'); + $this->db->join('album', 'album.artistid = artist.id'); + $this->db->join('genre', 'genre.id = album.genreid'); + $this->db->join('cover', 'cover.id = album.coverid'); + + $this->db->distinct("artist.name"); + + if(!empty($genre)){ + $this->db->where('genre.name', $genre); + } + + + if($order == 'asc' || $order == 'desc'){ + $this->db->order_by('artist.name',$order ); + } + + + $query = $this->db->get(); + return $query->result(); + } + + + public function getMusics($genre = '', $order = '', $artist = '') { + + $this->db->select('album.name, album.id, year, artist.name as artistName, genre.name as genreName, jpeg, song.name as trackName, track.id as trackId'); + $this->db->from('track'); + $this->db->join('album', 'track.albumId = album.id'); + $this->db->join('song', 'song.id = track.songId'); + $this->db->join('artist', 'album.artistid = artist.id'); + $this->db->join('genre', 'genre.id = album.genreid'); + $this->db->join('cover', 'cover.id = album.coverid'); + $this->db->limit(100); + + + + if(!empty($genre)){ + $this->db->where('genre.name', $genre); + } + + if(!empty($artist)){ + $this->db->where('artist.name', $artist); + } + + + if($order == 'asc' || $order == 'desc'){ + $this->db->order_by('song.name',$order ); + } + + + $query = $this->db->get(); + return $query->result(); + } + + public function research(){ + $query = $this->db->query( + + );} + + public function researchtype(){ + + $this->db->select('name'); + $this->db->from('genre'); + /* + if(!empty($playlist_id)){ + $this->db->where('playlists.playlist_id', $playlist_id); + }*/ + + $query = $this->db->get(); + return $query->result(); + + } + + public function nameArtist(){ + + $this->db->select('name'); + $this->db->from('artist'); + + + $query = $this->db->get(); + return $query->result(); + + } + + } diff --git a/application/views/artists_name.php b/application/views/artists_name.php new file mode 100644 index 0000000..197ed97 --- /dev/null +++ b/application/views/artists_name.php @@ -0,0 +1,12 @@ +<h5>Artists list</h5> +<section class="list"> +<?php +foreach($artists as $artist){ + echo "<div><article>"; + echo "<header class='short-text'>"; + echo anchor("artist/view/{$artist->artistId}","{$artist->artistName}"); + echo "</header></article></div>"; +} +?> +</section> + diff --git a/application/views/layout/header.php b/application/views/layout/header.php index 35809b6..065e381 100644 --- a/application/views/layout/header.php +++ b/application/views/layout/header.php @@ -27,6 +27,31 @@ <?php endif; ?> </ul> </nav> + + <form methode="GET"> + <select name="artist" id="artist"> + <option value=''>Tous</option> + <?php foreach($artistes as $artiste){ + echo "<option value='{$artiste->name}'>{$artiste->name}</option>"; + } + ?> + </select> + + <select name="genre" id="genre"> + <option value=''>Tous</option> + <?php foreach($genres as $genre){ + echo "<option value='{$genre->name}'>{$genre->name}</option>"; + } + ?> + </select> + + <select name="order" id="order"> + <option value="">Ordre :</option> + <option value="asc">Croissant</option> + <option value="desc">Decroissant</option> + </select> + <button type="submit">Envoyer</button> + </form> </main> </body> </html> diff --git a/application/views/musiques_name.php b/application/views/musiques_name.php new file mode 100644 index 0000000..cca404d --- /dev/null +++ b/application/views/musiques_name.php @@ -0,0 +1,16 @@ +<h5>Musiques List</h5> +<section class="list"> +<?php +foreach($musics as $music){ + echo "<div><article>"; + echo "<header class='short-text'>"; + echo anchor("albums/view/{$music->trackId}","{$music->trackName}"); + echo "</header>"; + echo '<img src="data:image/jpeg;base64,'.base64_encode($music->jpeg).'" />'; + + echo "<footer class='short-text'>{$music->year} - {$music->artistName}</footer> + </article></div>"; +} +?> +</section> +