Commit pour Louay Dardouri (problème de PC)

This commit is contained in:
stiti 2024-05-20 18:18:00 +02:00
parent 85553ae9cb
commit dc14c38fb1
5 changed files with 167 additions and 44 deletions

View File

@ -8,18 +8,29 @@ class Albums extends CI_Controller {
$this->load->model('model_music');
$this->load->helper('url');
}
public function index($page = 1){
$limit = 21;
$offset = ($page - 1) * $limit;
$albums = $this->model_music->getAlbums($limit, $offset);
$total_albums = $this->model_music->get_total_albums();
$data['total_pages'] = ceil($total_albums / $limit);
$data['current_page'] = $page;
$data['albums'] = $albums;
$this->load->view('layout/header_not_logged_dark');
$this->load->view('albums_list', $data);
$this->load->view('layout/footer_dark');
}
public function view($id){
$album = $this->model_music->get_album_by_id($id);
$data['album'] = $album;
$this->load->view('layout/header_not_logged_dark');
$this->load->view('album_view', $data);
$this->load->view('layout/footer_dark');
}
}
?>

View File

@ -1,22 +1,22 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Model_music extends CI_Model {
public function __construct(){
$this->load->database();
}
public function __construct(){
$this->load->database();
}
public function getAlbums($limit, $offset){
$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
LIMIT $limit OFFSET $offset"
public function getAlbums($limit, $offset){
$query = $this->db->query(
"SELECT album.id, album.name, album.year, artist.name as artistName, genre.name as genreName, cover.jpeg
FROM album
JOIN artist ON album.artistid = artist.id
JOIN genre ON album.genreid = genre.id
JOIN cover ON album.coverid = cover.id
ORDER BY album.year
LIMIT $limit OFFSET $offset"
);
return $query->result();
}
return $query->result();
}
public function get_total_albums(){
$query = $this->db->query("SELECT COUNT(*) as total_albums FROM album");
@ -24,4 +24,31 @@ class Model_music extends CI_Model {
return $result->total_albums;
}
public function get_album_by_id($id){
// Fetch album details
$query = $this->db->query(
"SELECT album.id, album.name, album.year, artist.name as artistName, genre.name as genreName, cover.jpeg
FROM album
JOIN artist ON album.artistid = artist.id
JOIN genre ON album.genreid = genre.id
JOIN cover ON album.coverid = cover.id
WHERE album.id = ?", array($id)
);
$album = $query->row();
if ($album) {
// Fetch album tracks
$query = $this->db->query(
"SELECT track.id, track.diskNumber, track.number, track.duration, song.name as songName
FROM track
JOIN song ON track.songid = song.id
WHERE track.albumid = ?
ORDER BY track.diskNumber, track.number", array($id)
);
$album->tracks = $query->result();
}
return $album;
}
}
?>

View File

@ -0,0 +1,32 @@
<!-- application/views/album_view.php -->
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="<?php echo base_url('assets/css/album_view.css'); ?>">
<title><?php echo $album->name; ?> - Details</title>
</head>
<body>
<div class="album-details">
<h1><?php echo $album->name; ?></h1>
<p><strong>Artiste :</strong> <?php echo $album->artistName; ?></p>
<p><strong>Année :</strong> <?php echo $album->year; ?></p>
<p><strong>Genre :</strong> <?php echo $album->genreName; ?></p>
<img src="data:image/jpeg;base64,<?php echo base64_encode($album->jpeg); ?>" alt="Image d'album">
<?php if (!empty($album->tracks)): ?>
<h2>Musiques</h2>
<ul>
<?php foreach ($album->tracks as $track): ?>
<li>
<strong><?php echo $track->diskNumber . '.' . $track->number; ?>:</strong> <?php echo $track->songName; ?> (<?php echo gmdate("i:s", $track->duration); ?>)
</li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p>Aucune musique n'est disponible dans cette album...</p>
<?php endif; ?>
</div>
</body>
</html>

View File

@ -1,34 +1,41 @@
<!-- application/views/albums_list.php -->
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="<?php echo base_url('assets/css/style.css'); ?>">
<link rel="icon" type="image/x-icon" href="<?php echo base_url('assets/img/Logo_ONZEUR.png'); ?>">
<title>Page d'accueil</title>
</head>
<body>
<h1 class="title">Listes des albums</h1>
<section class="list">
<?php foreach($albums as $album): ?>
<div>
<article>
<header class="short-text">
<?php echo anchor("albums/view/{$album->id}", $album->name); ?>
</header>
<img src="data:image/jpeg;base64,<?php echo base64_encode($album->jpeg); ?>" alt="<?php echo $album->name; ?>">
<footer class="short-text"><?php echo $album->year; ?> - <?php echo $album->artistName; ?></footer>
</article>
</div>
<?php endforeach; ?>
</section>
<h1 class="title">Listes des albums</h1>
<section class="list">
<?php
foreach($albums as $album){
echo "<div><article>";
echo "<header class='short-text'>";
echo anchor("albums/view/{$album->id}","{$album->name}");
echo "</header>";
echo '<img src="data:image/jpeg;base64,'.base64_encode($album->jpeg).'" />';
echo "<footer class='short-text'>{$album->year} - {$album->artistName}</footer>
</article></div>";
}
?>
</section>
<div class="pagination">
<?php if ($current_page > 1): ?>
<a href="<?php echo base_url('index.php/albums/index/'.($current_page-1)); ?>">Précédent</a>
<?php endif; ?>
<div class="pagination">
<?php if ($current_page > 1): ?>
<a href="<?php echo base_url('index.php/albums/index/'.($current_page-1)); ?>">Précédent</a>
<?php endif; ?>
<?php for ($i = 1; $i <= $total_pages; $i++): ?>
<a href="<?php echo base_url('index.php/albums/index/'.$i); ?>" <?php echo ($i == $current_page) ? 'class="active"' : ''; ?>><?php echo $i; ?></a>
<?php endfor; ?>
<?php if ($current_page < $total_pages): ?>
<a href="<?php echo base_url('index.php/albums/index/'.($current_page+1)); ?>">Suivant</a>
<?php endif; ?>
</div>
<?php for ($i = 1; $i <= $total_pages; $i++): ?>
<a href="<?php echo base_url('index.php/albums/index/'.$i); ?>" <?php echo ($i == $current_page) ? 'class="active"' : ''; ?>><?php echo $i; ?></a>
<?php endfor; ?>
<?php if ($current_page < $total_pages): ?>
<a href="<?php echo base_url('index.php/albums/index/'.($current_page+1)); ?>">Suivant</a>
<?php endif; ?>
</div>
</body>
</html>

View File

@ -0,0 +1,46 @@
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 0;
}
.album-details {
max-width: 800px;
margin: 20px auto;
padding: 20px;
background-color: #ffffff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.album-details h1 {
font-size: 2em;
margin-bottom: 10px;
}
.album-details p {
font-size: 1.2em;
margin: 5px 0;
}
.album-details img {
max-width: 100%;
height: auto;
margin: 20px 0;
}
.album-details h2 {
font-size: 1.5em;
margin-top: 20px;
}
.album-details ul {
list-style-type: none;
padding: 0;
}
.album-details ul li {
padding: 10px 0;
border-bottom: 1px solid #ddd;
}