Gestion playlist et css
This commit is contained in:
parent
a47749459f
commit
2daa74732b
codeigniter
application
controllers
models
views
assets
@ -35,18 +35,17 @@ class Artistes extends CI_Controller {
|
||||
}
|
||||
|
||||
public function search(){
|
||||
$query = $this->input->get('query');
|
||||
$albums = $this->model_music_artistes->searchArtistes($query);
|
||||
$num_results = count($albums);
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('artistes_list', [
|
||||
'albums' => $albums,
|
||||
'sort' => $this->sort,
|
||||
'num_results' => $num_results,
|
||||
'is_search' => true
|
||||
]);
|
||||
$this->load->view('layout/footer');
|
||||
}
|
||||
$query = $this->input->get('query');
|
||||
$artistes = $this->model_music_artistes->searchArtistes($query);
|
||||
$num_results = count($artistes);
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('artistes_list', [
|
||||
'artistes' => $artistes,
|
||||
'num_results' => $num_results,
|
||||
'is_search' => true
|
||||
]);
|
||||
$this->load->view('layout/footer');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -122,5 +122,26 @@ public function choix_playlist($albumId) {
|
||||
}
|
||||
redirect('playlist/view/' . $playlistId);
|
||||
}
|
||||
|
||||
public function generate(){
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('playlist_generate');
|
||||
$this->load->view('layout/footer');
|
||||
}
|
||||
|
||||
public function generate_random(){
|
||||
$numSongs = (int)$this->input->post('numSongs');
|
||||
$playlistName = $this->input->post('playlistName');
|
||||
$userId = $this->session->userdata('user_id');
|
||||
|
||||
if ($numSongs > 0 && !empty($playlistName)) {
|
||||
$playlistId = $this->model_music->generate_random_playlist($numSongs, $playlistName, $userId);
|
||||
redirect('playlist/view/' . $playlistId);
|
||||
} else {
|
||||
echo "Erreur : Veuillez entrer un nombre de chansons valide et un nom de playlist.";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
|
@ -17,6 +17,27 @@ class Model_music extends CI_Model {
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function get_tri_Albums($Ctri){
|
||||
$orderBy = '';
|
||||
if ($Ctri == 'year ASC') {
|
||||
$orderBy = 'ORDER BY year ASC';
|
||||
} elseif ($Ctri == 'year DESC') {
|
||||
$orderBy = 'ORDER BY year DESC';
|
||||
} elseif ($Ctri == 'ASC' || $Ctri == 'DESC') {
|
||||
$orderBy = "ORDER BY album.name $Ctri";
|
||||
}
|
||||
|
||||
$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
|
||||
$orderBy"
|
||||
);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
|
||||
public function getArtistes(){
|
||||
$query = $this->db->query(
|
||||
@ -75,61 +96,32 @@ class Model_music extends CI_Model {
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function get_tri_Albums($Ctri){
|
||||
$orderBy = '';
|
||||
if ($Ctri == 'year ASC') {
|
||||
$orderBy = 'ORDER BY year ASC';
|
||||
} elseif ($Ctri == 'year DESC') {
|
||||
$orderBy = 'ORDER BY year DESC';
|
||||
} elseif ($Ctri == 'ASC' || $Ctri == 'DESC') {
|
||||
$orderBy = "ORDER BY album.name $Ctri";
|
||||
}
|
||||
|
||||
$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
|
||||
$orderBy"
|
||||
);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function getGenres(){
|
||||
$query = $this->db->query("SELECT * FROM genre");
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function searchAlbums($query, $genre){
|
||||
$sql = "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";
|
||||
|
||||
$conditions = [];
|
||||
$params = [];
|
||||
|
||||
if (!empty($query)) {
|
||||
$conditions[] = "(album.name LIKE ? OR artist.name LIKE ?)";
|
||||
$params[] = "%{$query}%";
|
||||
$params[] = "%{$query}%";
|
||||
}
|
||||
|
||||
if (!empty($genre)) {
|
||||
$conditions[] = "genre.id = ?";
|
||||
$params[] = $genre;
|
||||
}
|
||||
|
||||
if (count($conditions) > 0) {
|
||||
$sql .= " WHERE " . implode(' AND ', $conditions);
|
||||
}
|
||||
public function searchAlbums($query, $genre){
|
||||
$sql = "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
|
||||
WHERE album.name LIKE ? OR artist.name LIKE ?
|
||||
ORDER BY album.id ASC";
|
||||
|
||||
// Paramètres pour les conditions de recherche
|
||||
$params = ["%{$query}%", "%{$query}%"];
|
||||
|
||||
$sql .= " ORDER BY album.id ASC";
|
||||
$query = $this->db->query($sql, $params);
|
||||
return $query->result();
|
||||
}
|
||||
if (!empty($genre)) {
|
||||
$sql .= " AND genre.id = ?";
|
||||
$params[] = $genre;
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql, $params);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
|
||||
public function createPlaylist($name, $userId) {
|
||||
$data = array(
|
||||
@ -179,5 +171,22 @@ class Model_music extends CI_Model {
|
||||
$query = $this->db->get_where('song', array('name' => $songName));
|
||||
return $query->row();
|
||||
}
|
||||
|
||||
public function generate_random_playlist($numSongs, $playlistName, $userId) {
|
||||
$query = $this->db->query(
|
||||
"SELECT id FROM song ORDER BY RAND() LIMIT ?", array((int)$numSongs)
|
||||
);
|
||||
$songs = $query->result();
|
||||
|
||||
$playlistId = $this->createPlaylist($playlistName, $userId);
|
||||
|
||||
foreach ($songs as $song) {
|
||||
$this->addSongToPlaylist($playlistId, $song->id);
|
||||
}
|
||||
|
||||
return $playlistId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -38,31 +38,17 @@ class Model_music_artistes extends CI_Model {
|
||||
}
|
||||
|
||||
|
||||
public function searchArtistes($query){
|
||||
public function searchArtistes($query){
|
||||
// Requête SQL principale pour la recherche d'artistes par nom
|
||||
$sql = "SELECT artist.id AS artistId, artist.name AS artistName, album.name AS albumName, album.id AS albumId, album.year, cover.jpeg
|
||||
FROM album
|
||||
INNER JOIN artist ON album.artistId = artist.id
|
||||
JOIN cover ON cover.id = album.coverId
|
||||
GROUP BY artist.name, album.year";
|
||||
FROM album
|
||||
JOIN artist ON album.artistId = artist.id
|
||||
JOIN cover ON cover.id = album.coverId
|
||||
WHERE artist.name LIKE ?
|
||||
GROUP BY artist.name, album.year
|
||||
ORDER BY artist.name ASC";
|
||||
|
||||
$conditions = [];
|
||||
$params = [];
|
||||
|
||||
if (!empty($query)) {
|
||||
$conditions[] = "(album.name LIKE ? OR artist.name LIKE ?)";
|
||||
$params[] = "%{$query}%";
|
||||
$params[] = "%{$query}%";
|
||||
}
|
||||
|
||||
|
||||
if (count($conditions) > 0) {
|
||||
$sql .= " WHERE " . implode(' AND ', $conditions);
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY album.id ASC";
|
||||
|
||||
$query = $this->db->query($sql, $params);
|
||||
$query = $this->db->query($sql, ["%{$query}%"]);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
</form>
|
||||
|
||||
<?php if(isset($is_search) && $is_search): ?>
|
||||
<form action="<?= site_url('Albums'); ?>" method="get" class="back-form">
|
||||
<form action="<?= site_url('Artistes'); ?>" method="get" class="back-form">
|
||||
<button type="submit" class="back-button">Retour à la liste complète</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
|
9
codeigniter/application/views/playlist_generate.php
Normal file
9
codeigniter/application/views/playlist_generate.php
Normal file
@ -0,0 +1,9 @@
|
||||
<h5>Générer une Playlist Aléatoire</h5>
|
||||
|
||||
<form action="<?= site_url('playlist/generate_random'); ?>" method="post" class="generate-playlist-form">
|
||||
<input type="text" name="playlistName" placeholder="Nom de la playlist" required>
|
||||
<input type="number" name="numSongs" placeholder="Nombre de chansons" required>
|
||||
<button type="submit">Générer</button>
|
||||
</form>
|
||||
|
||||
<a href="<?= site_url('playlist'); ?>" class="btn btn-secondary">Retour aux playlists</a>
|
@ -6,6 +6,10 @@
|
||||
<button type="submit">Créer</button>
|
||||
</form>
|
||||
|
||||
<form action="<?= site_url('playlist/generate'); ?>" method="get" class="generate-playlist-form">
|
||||
<button type="submit">Générer une Playlist</button>
|
||||
</form>
|
||||
|
||||
<!-- Affichez les playlist que nous avons -->
|
||||
<section class="playlists">
|
||||
<?php foreach($playlists as $playlist): ?>
|
||||
@ -15,7 +19,7 @@
|
||||
<?= anchor("playlist/view/{$playlist->id}", "{$playlist->name}"); ?>
|
||||
</header>
|
||||
<!-- Bouton pour supprimer la playlist -->
|
||||
<form action="<?= site_url('playlist/delete/' . $playlist->id); ?>" method="post" style="display:inline;">
|
||||
<form action="<?= site_url('playlist/delete/' . $playlist->id); ?>" method="post" class="btn-supp" style="display:inline;">
|
||||
<button type="submit">Supprimer</button>
|
||||
</form>
|
||||
</article>
|
||||
|
@ -7,34 +7,13 @@
|
||||
<button type="submit">Rechercher et Ajouter</button>
|
||||
</form>
|
||||
|
||||
<!-- Section pour afficher les résultats de la recherche -->
|
||||
<?php if (!empty($searchResults)): ?>
|
||||
<section class="search-results">
|
||||
<h5>Résultats de la recherche :</h5>
|
||||
<ul>
|
||||
<?php foreach($searchResults as $song): ?>
|
||||
<li>
|
||||
<?= $song->name; ?>
|
||||
<!-- Formulaire pour ajouter la chanson à la playlist -->
|
||||
<form action="<?= site_url('playlist/add_song'); ?>" method="post" style="display:inline;">
|
||||
<input type="hidden" name="playlistId" value="<?= $playlistId; ?>">
|
||||
<input type="hidden" name="songId" value="<?= $song->id; ?>">
|
||||
<button type="submit">Ajouter</button>
|
||||
</form>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</section>
|
||||
<p>Test</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Section pour afficher les chansons de son playlist -->
|
||||
<?php if (!empty($songs)): ?>
|
||||
<section class="current-songs">
|
||||
<h5>Chansons actuelles :</h5>
|
||||
<ul>
|
||||
<?php foreach($songs as $song): ?>
|
||||
<li>
|
||||
<li class="play">
|
||||
<?= $song->name; ?>
|
||||
<!-- Formulaire pour supprimer la chanson de la playlist -->
|
||||
<form action="<?= site_url('playlist/remove_song'); ?>" method="post" style="display:inline;">
|
||||
|
@ -210,6 +210,32 @@ form.search-form {
|
||||
margin-left: -200px;
|
||||
}
|
||||
|
||||
form.create-playlist-form {
|
||||
width: 40%;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
form.add-song-form {
|
||||
width: 40%;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
form.generate-playlist-form {
|
||||
width: 40%;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
section.playlists {
|
||||
display: flex;
|
||||
justify-content: left;
|
||||
flex-wrap: wrap;
|
||||
gap: 100px;
|
||||
margin-top: 50px;
|
||||
}
|
||||
|
||||
.btn-supp {
|
||||
width: 30%;
|
||||
}
|
||||
|
||||
|
||||
/* bouton ajouter sur les albums et musique */
|
||||
|
Loading…
x
Reference in New Issue
Block a user