Views music

This commit is contained in:
Vincent TEISSIER 2024-06-05 08:08:12 +02:00
parent db5398a1d9
commit b2a2c3ce4a
4 changed files with 30 additions and 54 deletions

@ -6,7 +6,7 @@ class Music extends CI_Controller {
public function __construct(){ public function __construct(){
parent::__construct(); parent::__construct();
$this->load->model('model_music'); $this->load->model('model_music');
$this->load->library('session'); // La session est déjà chargée via autoload.php, mais par précaution. $this->load->library('session');
} }
public function index(){ public function index(){
@ -33,14 +33,12 @@ class Music extends CI_Controller {
$this->load->view('layout/footer'); $this->load->view('layout/footer');
} }
public function view($songId) { public function view($trackId) {
$songData = $this->model_music->getSongDetails($songId); $songData = $this->model_music->getSongDetails($trackId);
$is_logged_in = $this->session->userdata('logged_in'); $is_logged_in = $this->session->userdata('logged_in');
$data = array( $data = array(
'song' => $songData['song'], 'song' => $songData,
'album' => $songData['album'],
'artist' => $songData['artist'],
'is_logged_in' => $is_logged_in 'is_logged_in' => $is_logged_in
); );
@ -48,6 +46,4 @@ class Music extends CI_Controller {
$this->load->view('song_details', $data); $this->load->view('song_details', $data);
$this->load->view('layout/footer'); $this->load->view('layout/footer');
} }
} }

@ -153,37 +153,18 @@ class Model_music extends CI_Model {
public function getSongDetails($songId) { public function getSongDetails($songId) {
// Get song details $this->db->select('song.name as songName, song.id as songId, album.name as albumName, album.id as albumId, album.year, artist.name as artistName, artist.id as artistId, cover.jpeg');
$this->db->select('song.name as songName, song.id'); $this->db->from('track');
$this->db->from('song'); $this->db->join('album', 'track.albumId = album.id');
$this->db->where('song.id', $songId); $this->db->join('song', 'song.id = track.songId');
$songQuery = $this->db->get(); $this->db->join('artist', 'album.artistid = artist.id');
$songDetails = $songQuery->row(); $this->db->join('cover', 'cover.id = album.coverid');
$this->db->where('track.id', $songId);
// Get album details for the song $result = $this->db->get();
$this->db->select('album.id as albumId, album.name as albumName, album.year'); return $result->row_array();
$this->db->from('album');
$this->db->join('track', 'track.albumId = album.id');
$this->db->where('track.songId', $songId);
$albumQuery = $this->db->get();
$albumDetails = $albumQuery->row();
// Get artist details for the album
$this->db->select('artist.id as artistId, artist.name as artistName');
$this->db->from('artist');
$this->db->join('album', 'album.artistId = artist.id');
$this->db->where('album.id', $albumDetails->albumId);
$artistQuery = $this->db->get();
$artistDetails = $artistQuery->row();
return array('song' => $songDetails, 'album' => $albumDetails, 'artist' => $artistDetails);
} }
// Suppression de la deuxième méthode researchtype // Suppression de la deuxième méthode researchtype
public function research(){ public function research(){

@ -4,12 +4,12 @@
foreach($musics as $music){ foreach($musics as $music){
echo "<div><article>"; echo "<div><article>";
echo "<header class='short-text'>"; echo "<header class='short-text'>";
if(isset($music->albumName)) { if(isset($music->trackName)) {
echo anchor("music/view/{$music->trackId}", $music->albumName); echo anchor("music/view/{$music->trackId}", $music->trackName);
} }
echo "</header>"; echo "</header>";
echo '<img src="data:image/jpeg;base64,'.base64_encode($music->jpeg).'" />'; echo '<img src="data:image/jpeg;base64,'.base64_encode($music->jpeg).'" />';
echo "<footer class='short-text'>{$music->year} - {$music->artistName}</footer> echo "<footer class='short-text'>{$music->year} - {$music->artistName} - {$music->albumName}</footer>
</article></div>"; </article></div>";
} }
?> ?>

@ -5,11 +5,10 @@
</head> </head>
<body> <body>
<h1><?= $song['songName'] ?></h1> <h1><?= $song['songName'] ?></h1>
<p><strong>Album:</strong> <?= anchor("music/view/{$song['albumId']}", $song['albumName']) ?> (<?= $song['album']['year'] ?>)</p> <p><strong>Album:</strong> <?= anchor("music/view/{$song['albumId']}", $song['albumName']) ?> (<?= $song['year'] ?>)</p>
<p><strong>Artist:</strong> <?= $song['artist']['artistName'] ?></p> <p><strong>Artist:</strong> <?= $song['artistName'] ?></p>
<!-- Ajoutez ici d'autres détails de la chanson si nécessaire -->
<?php if(isset($song['jpeg']) && $song['jpeg'] != ''): ?> <?php if(isset($song['jpeg']) && $song['jpeg'] != ''): ?>
<img src="data:image/jpeg;base64,<?= base64_encode($song['jpeg']) ?>" alt="<?= $song['album']['albumName'] ?> Cover"> <img src="data:image/jpeg;base64,<?= base64_encode($song['jpeg']) ?>" alt="<?= $song['albumName'] ?> Cover">
<?php endif; ?> <?php endif; ?>
</body> </body>
</html> </html>