ajout filtre et tri pour artiste
This commit is contained in:
@@ -8,19 +8,30 @@ class Artistes extends CI_Controller {
|
|||||||
$this->load->model('model_music');
|
$this->load->model('model_music');
|
||||||
}
|
}
|
||||||
public function index(){
|
public function index(){
|
||||||
|
$genre = $this->input->get('genre');
|
||||||
|
$sort = $this->input->get('sort');
|
||||||
|
$order = $this->input->get('order');
|
||||||
|
|
||||||
if ($recherche=filter_input(INPUT_GET,'recherche') == false or $recherche=filter_input(INPUT_GET,'recherche') == null){
|
if ($recherche=filter_input(INPUT_GET,'recherche') == false or $recherche=filter_input(INPUT_GET,'recherche') == null){
|
||||||
$artistes = $this->model_music->getArtistes();
|
$artistes = $this->model_music->getArtistes();
|
||||||
|
$artistes = $this->model_music->get_filtered_artistes($genre, $sort, $order);
|
||||||
|
$data['artistes'] = $artistes;
|
||||||
}else{
|
}else{
|
||||||
$recherche=filter_input(INPUT_GET,'recherche');
|
$recherche=filter_input(INPUT_GET,'recherche');
|
||||||
$artistes = $this->model_music->getSearchArtistes($recherche);
|
$artistes = $this->model_music->getSearchArtistes($recherche);
|
||||||
|
$data['artistes'] = $artistes;
|
||||||
}
|
}
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
if ($artistes == false){
|
if ($artistes == false){
|
||||||
$page = preg_split('/[\/]/',$_SERVER['REQUEST_URI']);
|
$page = preg_split('/[\/]/',$_SERVER['REQUEST_URI']);
|
||||||
$this->load->view('error',['page'=>$page[count($page)-1]]);
|
$this->load->view('error',['page'=>$page[count($page)-1]]);
|
||||||
$artistes = $this->model_music->getArtistes();
|
$artistes = $this->model_music->getArtistes();
|
||||||
|
$artistes = $this->model_music->get_filtered_artistes($genre, $sort, $order);
|
||||||
|
$data['artistes'] = $artistes;
|
||||||
}
|
}
|
||||||
$this->load->view('artistes_list',['artistes'=>$artistes]);
|
$data['genres'] = $this->model_music->get_all_genres_artistes();
|
||||||
|
|
||||||
|
$this->load->view('artistes_list',$data);
|
||||||
$this->load->view('layout/footer');
|
$this->load->view('layout/footer');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,33 @@ class Model_music extends CI_Model {
|
|||||||
return $query->result();
|
return $query->result();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function get_filtered_artistes($genre = [], $sort = null, $order = null) {
|
||||||
|
$this->db->distinct();
|
||||||
|
$this->db->select('artist.Id,artist.name, genre.name as genreName');
|
||||||
|
$this->db->from('artist');
|
||||||
|
$this->db->join('album', 'album.artistId = artist.Id');
|
||||||
|
$this->db->join('genre', 'album.genreId = genre.Id');
|
||||||
|
|
||||||
|
if (!empty($genre)) {
|
||||||
|
$this->db->where_in('genre.name', $genre);
|
||||||
|
}
|
||||||
|
if ($sort && in_array($sort, ['name'])) {
|
||||||
|
$this->db->order_by($sort, $order);
|
||||||
|
}
|
||||||
|
$query = $this->db->get();
|
||||||
|
return $query->result();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_all_genres_artistes() {
|
||||||
|
$this->db->distinct();
|
||||||
|
$this->db->select('genreId,genre.name as genreName');
|
||||||
|
$this->db->from('artist');
|
||||||
|
$this->db->join('album', 'album.artistId = artist.Id');
|
||||||
|
$this->db->join('genre', 'album.genreId = genre.Id');
|
||||||
|
$query = $this->db->get();
|
||||||
|
return $query->result();
|
||||||
|
}
|
||||||
|
|
||||||
public function get_filtered_chansons($genre = [], $artist = [], $year = [], $album = [], $sort = null, $order = null) {
|
public function get_filtered_chansons($genre = [], $artist = [], $year = [], $album = [], $sort = null, $order = null) {
|
||||||
$this->db->select('track.id as trackId, song.name,song.id,album.year,album.name as albumName, artist.name as artistName, genre.name as genreName');
|
$this->db->select('track.id as trackId, song.name,song.id,album.year,album.name as albumName, artist.name as artistName, genre.name as genreName');
|
||||||
$this->db->from('song');
|
$this->db->from('song');
|
||||||
|
|||||||
@@ -72,7 +72,8 @@
|
|||||||
window.location.href = url;
|
window.location.href = url;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
<?php $page = preg_split('/[\/]/',$_SERVER['REQUEST_URI']);
|
||||||
|
if($page[count($page)-2] != 'viewAlbum'){ ?>
|
||||||
<h5>Filter Albums</h5>
|
<h5>Filter Albums</h5>
|
||||||
<button type="button" onclick="toggleFilterOptions()">Filter</button>
|
<button type="button" onclick="toggleFilterOptions()">Filter</button>
|
||||||
|
|
||||||
@@ -127,7 +128,7 @@
|
|||||||
<button onclick="sortAlbums('genreName', 'asc')">Sort by Genre Asc</button>
|
<button onclick="sortAlbums('genreName', 'asc')">Sort by Genre Asc</button>
|
||||||
<button onclick="sortAlbums('genreName', 'desc')">Sort by Genre Desc</button>
|
<button onclick="sortAlbums('genreName', 'desc')">Sort by Genre Desc</button>
|
||||||
</div>
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
<h5>Albums list</h5>
|
<h5>Albums list</h5>
|
||||||
<section class="list">
|
<section class="list">
|
||||||
|
|||||||
@@ -1,10 +1,114 @@
|
|||||||
|
<style>
|
||||||
|
.filter-options {
|
||||||
|
display: none;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
.filter-buttons {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.filter-buttons.show {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
.filter-checkboxes {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.filter-checkboxes.show {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.sort-buttons {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.show-buttons .sort-buttons {
|
||||||
|
display: block; / Afficher les boutons de tri lorsque la classe show-buttons est appliquée */
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<script>
|
||||||
|
var filterOptionsVisible = false;
|
||||||
|
|
||||||
|
function toggleFilterOptions() {
|
||||||
|
var filterOptions = document.getElementById('filter-options');
|
||||||
|
var filterButtons = document.getElementById('filter-buttons');
|
||||||
|
|
||||||
|
if (!filterOptionsVisible) {
|
||||||
|
filterOptions.style.display = 'block';
|
||||||
|
filterButtons.classList.add('show');
|
||||||
|
filterOptionsVisible = true;
|
||||||
|
} else {
|
||||||
|
filterOptions.style.display = 'none';
|
||||||
|
filterButtons.classList.remove('show');
|
||||||
|
hideCheckboxes();
|
||||||
|
filterOptionsVisible = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleCheckboxes(filterType) {
|
||||||
|
var checkboxes = document.getElementById(filterType + '-checkboxes');
|
||||||
|
if (checkboxes.style.display === 'none' || checkboxes.style.display === '') {
|
||||||
|
checkboxes.style.display = 'block';
|
||||||
|
} else {
|
||||||
|
checkboxes.style.display = 'none';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideCheckboxes() {
|
||||||
|
var checkboxes = document.querySelectorAll('.filter-checkboxes');
|
||||||
|
checkboxes.forEach(function(checkbox) {
|
||||||
|
checkbox.classList.remove('show');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleSortButtons() {
|
||||||
|
var sortButtons = document.getElementById('sort-buttons');
|
||||||
|
if (sortButtons.style.display === 'none' || sortButtons.style.display === '') {
|
||||||
|
sortButtons.style.display = 'block';
|
||||||
|
} else {
|
||||||
|
sortButtons.style.display = 'none';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function sortAlbums(column, order) {
|
||||||
|
var url = "<?= site_url('artistes/index'); ?>";
|
||||||
|
url += "?sort=" + column + "&order=" + order;
|
||||||
|
window.location.href = url;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<h5>Filter Artiste</h5>
|
||||||
|
<button type="button" onclick="toggleFilterOptions()">Filter</button>
|
||||||
|
|
||||||
|
<div id="filter-options" class="filter-options">
|
||||||
|
<form method="get">
|
||||||
|
<div id="filter-buttons" class="filter-buttons">
|
||||||
|
<button type="button" onclick="toggleCheckboxes('genre')">Genres</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="genre-checkboxes" style="display:none;">
|
||||||
|
<?php foreach ($genres as $genre): ?>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="genre[]" value="<?= $genre->genreName; ?>">
|
||||||
|
<?= $genre->genreName; ?>
|
||||||
|
</label><br>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit">Apply Filters</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h5>Sort Artiste</h5>
|
||||||
|
<button type="button" onclick="toggleSortButtons()">Sort</button>
|
||||||
|
<div id="sort-buttons" class="sort-buttons">
|
||||||
|
<button onclick="sortAlbums('name', 'asc')">Sort by Artist Asc</button>
|
||||||
|
<button onclick="sortAlbums('name', 'desc')">Sort by Artist Desc</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<h5>Artiste list</h5>
|
<h5>Artiste list</h5>
|
||||||
<section class="list">
|
<section class="list">
|
||||||
<?php
|
<?php
|
||||||
foreach($artistes as $artistes){
|
foreach($artistes as $artistes){
|
||||||
echo "<div><article>";
|
echo "<div><article>";
|
||||||
echo "<header class='short-text'>";
|
echo "<header class='short-text'>";
|
||||||
echo anchor("albums/viewAlbum/{$artistes->id}","{$artistes->name}");
|
echo anchor("albums/viewAlbum/{$artistes->Id}","{$artistes->name}");
|
||||||
echo "</header>";
|
echo "</header>";
|
||||||
echo "</article></div>";
|
echo "</article></div>";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -147,8 +147,10 @@ foreach($chansons as $chanson){
|
|||||||
echo "<div><article>";
|
echo "<div><article>";
|
||||||
echo "<header class='short-text'>";
|
echo "<header class='short-text'>";
|
||||||
echo anchor("chansons/view/{$chanson->id}","{$chanson->name}");
|
echo anchor("chansons/view/{$chanson->id}","{$chanson->name}");
|
||||||
echo anchor("chansons/addSongtoPlaylist/{$chanson->trackId}","<i class='fa fa-plus'></i>");
|
if($this->session->userdata('logged_in')){
|
||||||
echo "</header>";
|
echo anchor("chansons/addSongtoPlaylist/{$chanson->trackId}","<i class='fa fa-plus'></i>");
|
||||||
|
}
|
||||||
|
echo "</header>";
|
||||||
echo "<nav class='short-text'>Nom album: {$chanson->albumName}</nav>";
|
echo "<nav class='short-text'>Nom album: {$chanson->albumName}</nav>";
|
||||||
echo "<nav class='short-text'>Genre: {$chanson->genreName}</nav>";
|
echo "<nav class='short-text'>Genre: {$chanson->genreName}</nav>";
|
||||||
echo "<footer class='short-text'>{$chanson->year} - {$chanson->artistName}</footer>
|
echo "<footer class='short-text'>{$chanson->year} - {$chanson->artistName}</footer>
|
||||||
|
|||||||
Reference in New Issue
Block a user