Ajout trie croissant decroissanant, recherche de genre
This commit is contained in:
parent
af51088be9
commit
08fdeb6dd0
codeigniter
application
assets
@ -5,23 +5,30 @@ class Albums extends CI_Controller {
|
|||||||
|
|
||||||
private $sort = 'Tri';
|
private $sort = 'Tri';
|
||||||
|
|
||||||
|
public function __construct(){
|
||||||
|
parent::__construct();
|
||||||
|
$this->load->model('model_music');
|
||||||
|
$this->load->helper('html');
|
||||||
|
$this->load->helper('url');
|
||||||
|
$this->load->helper('form');
|
||||||
|
}
|
||||||
|
|
||||||
public function __construct(){
|
public function index(){
|
||||||
parent::__construct();
|
|
||||||
$this->load->model('model_music');
|
|
||||||
$this->load->helper('html');
|
|
||||||
$this->load->helper('url');
|
|
||||||
$this->load->helper('form');
|
|
||||||
}
|
|
||||||
public function index(){
|
|
||||||
$albums = $this->model_music->getAlbums();
|
$albums = $this->model_music->getAlbums();
|
||||||
|
$genres = $this->model_music->getGenres();
|
||||||
$num_results = count($albums);
|
$num_results = count($albums);
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
$this->load->view('albums_list', ['albums' => $albums, 'sort' => $this->sort, 'num_results' => $num_results, 'is_search' => false]);
|
$this->load->view('albums_list', [
|
||||||
|
'albums' => $albums,
|
||||||
|
'sort' => $this->sort,
|
||||||
|
'num_results' => $num_results,
|
||||||
|
'is_search' => false,
|
||||||
|
'genres' => $genres
|
||||||
|
]);
|
||||||
$this->load->view('layout/footer');
|
$this->load->view('layout/footer');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function view($id){
|
public function view($id){
|
||||||
$tracks = $this->model_music->getTracksByAlbumId($id);
|
$tracks = $this->model_music->getTracksByAlbumId($id);
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
$this->load->view('album_info', ['tracks' => $tracks]);
|
$this->load->view('album_info', ['tracks' => $tracks]);
|
||||||
@ -31,20 +38,35 @@ class Albums extends CI_Controller {
|
|||||||
public function tri(){
|
public function tri(){
|
||||||
$Ctri = $this->input->get('Ctri');
|
$Ctri = $this->input->get('Ctri');
|
||||||
$trie = $this->model_music->get_tri_Albums($Ctri);
|
$trie = $this->model_music->get_tri_Albums($Ctri);
|
||||||
|
$genres = $this->model_music->getGenres();
|
||||||
$num_results = count($trie);
|
$num_results = count($trie);
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
$this->load->view('albums_list', ['albums' => $trie, 'sort' => $this->sort, 'num_results' => $num_results, 'is_search' => false]);
|
$this->load->view('albums_list', [
|
||||||
|
'albums' => $trie,
|
||||||
|
'sort' => $this->sort,
|
||||||
|
'num_results' => $num_results,
|
||||||
|
'is_search' => false,
|
||||||
|
'genres' => $genres
|
||||||
|
]);
|
||||||
$this->load->view('layout/footer');
|
$this->load->view('layout/footer');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function search(){
|
public function search(){
|
||||||
$query = $this->input->get('query');
|
$query = $this->input->get('query');
|
||||||
$albums = $this->model_music->searchAlbums($query);
|
$genre = $this->input->get('genre');
|
||||||
|
$albums = $this->model_music->searchAlbums($query, $genre);
|
||||||
|
$genres = $this->model_music->getGenres();
|
||||||
$num_results = count($albums);
|
$num_results = count($albums);
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
$this->load->view('albums_list', ['albums' => $albums, 'sort' => $this->sort, 'num_results' => $num_results, 'is_search' => true]);
|
$this->load->view('albums_list', [
|
||||||
|
'albums' => $albums,
|
||||||
|
'sort' => $this->sort,
|
||||||
|
'num_results' => $num_results,
|
||||||
|
'is_search' => true,
|
||||||
|
'genres' => $genres
|
||||||
|
]);
|
||||||
$this->load->view('layout/footer');
|
$this->load->view('layout/footer');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,29 +76,60 @@ class Model_music extends CI_Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function get_tri_Albums($Ctri){
|
public function get_tri_Albums($Ctri){
|
||||||
$query = $this->db->query(
|
$orderBy = '';
|
||||||
"SELECT album.name,album.id,year,artist.name as artistName, genre.name as genreName,jpeg
|
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
|
FROM album
|
||||||
JOIN artist ON album.artistid = artist.id
|
JOIN artist ON album.artistid = artist.id
|
||||||
JOIN genre ON genre.id = album.genreid
|
JOIN genre ON genre.id = album.genreid
|
||||||
JOIN cover ON cover.id = album.coverid
|
JOIN cover ON cover.id = album.coverid
|
||||||
ORDER BY album.name $Ctri
|
$orderBy"
|
||||||
"
|
|
||||||
);
|
);
|
||||||
return $query->result();
|
return $query->result();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function searchAlbums($query){
|
public function getGenres(){
|
||||||
$this->db->select('album.name, album.id, year, artist.name as artistName, genre.name as genreName, jpeg');
|
$query = $this->db->query("SELECT * FROM genre");
|
||||||
$this->db->from('album');
|
return $query->result();
|
||||||
$this->db->join('artist', 'album.artistid = artist.id');
|
}
|
||||||
$this->db->join('genre', 'genre.id = album.genreid');
|
|
||||||
$this->db->join('cover', 'cover.id = album.coverid');
|
public function searchAlbums($query, $genre){
|
||||||
$this->db->like('album.name', $query);
|
$sql = "SELECT album.name, album.id, year, artist.name as artistName, genre.name as genreName, jpeg
|
||||||
$this->db->or_like('artist.name', $query);
|
FROM album
|
||||||
$this->db->order_by('album.id', 'ASC');
|
JOIN artist ON album.artistid = artist.id
|
||||||
$query = $this->db->get();
|
JOIN genre ON genre.id = album.genreid
|
||||||
return $query->result();
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql .= " ORDER BY album.id ASC";
|
||||||
|
|
||||||
|
$query = $this->db->query($sql, $params);
|
||||||
|
return $query->result();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,11 +1,23 @@
|
|||||||
<h5>Albums list</h5>
|
<h5>Albums list</h5>
|
||||||
<div class="sorting-search">
|
<div class="sorting-search">
|
||||||
<form action="<?= site_url('Albums/tri'); ?>" method="get" class="tri-form">
|
<form action="<?= site_url('Albums/tri'); ?>" method="get" class="tri-form">
|
||||||
<button type="submit" name="Ctri" value="ASC" class="tri-button">Tri A-Z</button>
|
<select name="Ctri" class="tri-select">
|
||||||
<button type="submit" name="Ctri" value="DESC" class="tri-button">Tri Z-A</button>
|
<option value="">Trier</option>
|
||||||
</form>
|
<option value="ASC"<?php echo isset($_GET['Ctri']) && $_GET['Ctri'] == 'ASC' ? ' selected' : ''; ?>>Trie A-Z</option>
|
||||||
|
<option value="DESC"<?php echo isset($_GET['Ctri']) && $_GET['Ctri'] == 'DESC' ? ' selected' : ''; ?>>Trie Z-A</option>
|
||||||
|
<option value="year ASC"<?php echo isset($_GET['Ctri']) && $_GET['Ctri'] == 'year ASC' ? ' selected' : ''; ?>>Trie par année (croissant)</option>
|
||||||
|
<option value="year DESC"<?php echo isset($_GET['Ctri']) && $_GET['Ctri'] == 'year DESC' ? ' selected' : ''; ?>>Trie par année (décroissant)</option>
|
||||||
|
</select>
|
||||||
|
<button type="submit" class="tri-button">Appliquer le tri</button>
|
||||||
|
</form>
|
||||||
</ul>
|
</ul>
|
||||||
<form action="<?= site_url('Albums/search'); ?>" method="get" class="search-form">
|
<form action="<?= site_url('Albums/search'); ?>" method="get" class="search-form">
|
||||||
|
<select name="genre" class="search-genre">
|
||||||
|
<option value="">Tous les genres</option>
|
||||||
|
<?php foreach($genres as $genre): ?>
|
||||||
|
<option value="<?= $genre->id ?>"><?= $genre->name ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
<input type="text" name="query" placeholder="Chercher des albums" class="search-input">
|
<input type="text" name="query" placeholder="Chercher des albums" class="search-input">
|
||||||
<button type="submit" class="search-button">Rechercher</button>
|
<button type="submit" class="search-button">Rechercher</button>
|
||||||
</form>
|
</form>
|
||||||
@ -17,7 +29,6 @@
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<?php if(isset($is_search) && $is_search): ?>
|
<?php if(isset($is_search) && $is_search): ?>
|
||||||
<p>Nombre de résultats : <?php echo $num_results; ?></p>
|
<p>Nombre de résultats : <?php echo $num_results; ?></p>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
@ -21,11 +21,12 @@
|
|||||||
<ul class="option">
|
<ul class="option">
|
||||||
<li><?=anchor('albums','Albums');?></li>
|
<li><?=anchor('albums','Albums');?></li>
|
||||||
<li><?=anchor('artistes','Artistes');?></li>
|
<li><?=anchor('artistes','Artistes');?></li>
|
||||||
<li><?=anchor('playlist','Playlist');?></li>
|
<?php if ($this->session->userdata('pseudo')) : /* Vérifier si l'utilisateur est connecté */ ?>
|
||||||
<?php if ($this->session->userdata('pseudo')) : /* Vérifier si l'utilisateur est connecté */ ?>
|
<li><?=anchor('playlist','Playlist');?></li>
|
||||||
|
<?php endif; ?>
|
||||||
<li class="deroulant"><a><?= $this->session->userdata('pseudo'); ?></a>
|
<?php if ($this->session->userdata('pseudo')) : /* Vérifier si l'utilisateur est connecté */ ?>
|
||||||
<ul class="sous">
|
<li class="deroulant"><a><?= $this->session->userdata('pseudo'); ?></a>
|
||||||
|
<ul class="sous">
|
||||||
|
|
||||||
<li><?= anchor('profil', 'Profil'); ?></li>
|
<li><?= anchor('profil', 'Profil'); ?></li>
|
||||||
<li><?=anchor('deconnexion', 'Se déconnecter'); ?></li>
|
<li><?=anchor('deconnexion', 'Se déconnecter'); ?></li>
|
||||||
|
@ -18,6 +18,15 @@ section.list img {
|
|||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
strong {
|
||||||
|
margin-left: 233px;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul.option li {
|
||||||
|
margin-right: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* modification par Yann */
|
/* modification par Yann */
|
||||||
@ -35,8 +44,8 @@ main.container {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.options {
|
ul.options {
|
||||||
margin-right : 20px!important;
|
margin-right : 50px;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,3 +181,17 @@ div.new {
|
|||||||
.back-form {
|
.back-form {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.search-genre {
|
||||||
|
margin-right: 10px;
|
||||||
|
padding: 5px;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tri-select {
|
||||||
|
width: 55%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tri-button {
|
||||||
|
width: 55%!important;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user