ajout recherche album
This commit is contained in:
parent
b73c4e4526
commit
1bd8d93ce5
codeigniter
@ -14,13 +14,12 @@ class Albums extends CI_Controller {
|
||||
$this->load->helper('form');
|
||||
}
|
||||
public function index(){
|
||||
|
||||
|
||||
$albums = $this->model_music->getAlbums();
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('albums_list',['albums'=>$albums,'sort'=>$this->sort]);
|
||||
$this->load->view('layout/footer');
|
||||
}
|
||||
$albums = $this->model_music->getAlbums();
|
||||
$num_results = count($albums);
|
||||
$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('layout/footer');
|
||||
}
|
||||
|
||||
public function view($id){
|
||||
$tracks = $this->model_music->getTracksByAlbumId($id);
|
||||
@ -32,9 +31,20 @@ class Albums extends CI_Controller {
|
||||
public function tri(){
|
||||
$Ctri = $this->input->get('Ctri');
|
||||
$trie = $this->model_music->get_tri_Albums($Ctri);
|
||||
$num_results = count($trie);
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('albums_list',['albums'=>$trie, 'sort'=>$this->sort]);
|
||||
$this->load->view('layout/footer');
|
||||
$this->load->view('albums_list', ['albums' => $trie, 'sort' => $this->sort, 'num_results' => $num_results, 'is_search' => false]);
|
||||
$this->load->view('layout/footer');
|
||||
}
|
||||
|
||||
public function search(){
|
||||
$query = $this->input->get('query');
|
||||
$albums = $this->model_music->searchAlbums($query);
|
||||
$num_results = count($albums);
|
||||
$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('layout/footer');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -57,4 +57,17 @@ class Model_music extends CI_Model {
|
||||
);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function searchAlbums($query){
|
||||
$this->db->select('album.name, album.id, year, artist.name as artistName, genre.name as genreName, jpeg');
|
||||
$this->db->from('album');
|
||||
$this->db->join('artist', 'album.artistid = artist.id');
|
||||
$this->db->join('genre', 'genre.id = album.genreid');
|
||||
$this->db->join('cover', 'cover.id = album.coverid');
|
||||
$this->db->like('album.name', $query);
|
||||
$this->db->or_like('artist.name', $query);
|
||||
$this->db->order_by('album.id', 'ASC');
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,26 @@
|
||||
|
||||
<h5>Albums list</h5>
|
||||
<ul class="tri"><h6 id ="tri"> <?php echo "$sort" ?> </h6>
|
||||
<li class="sous_tri">
|
||||
<ul><?=anchor('Albums/tri/?Ctri=ASC', 'Tri A-Z');?></ul>
|
||||
<ul><?=anchor('Albums/tri/?Ctri=DESC', 'Tri Z-A');?></ul>
|
||||
</li>
|
||||
<div class="sorting-search">
|
||||
<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>
|
||||
<button type="submit" name="Ctri" value="DESC" class="tri-button">Tri Z-A</button>
|
||||
</form>
|
||||
</ul>
|
||||
|
||||
<form action="<?= site_url('Albums/search'); ?>" method="get" class="search-form">
|
||||
<input type="text" name="query" placeholder="Chercher des albums" class="search-input">
|
||||
<button type="submit" class="search-button">Rechercher</button>
|
||||
</form>
|
||||
|
||||
<?php if(isset($is_search) && $is_search): ?>
|
||||
<form action="<?= site_url('Albums'); ?>" method="get" class="back-form">
|
||||
<button type="submit" class="back-button">Retour à la liste complète</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
|
||||
<?php if(isset($is_search) && $is_search): ?>
|
||||
<p>Nombre de résultats : <?php echo $num_results; ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<section class="list">
|
||||
<?php
|
||||
|
@ -144,3 +144,31 @@ div.new {
|
||||
.sous_tri a:hover{
|
||||
color: #1399fc;
|
||||
}*/
|
||||
|
||||
.sorting-search {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.tri-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.search-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
width: 200px;
|
||||
padding: 5px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.back-form {
|
||||
display: inline-block;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user