ajout de fonction de tri dans l'onglet artiste
This commit is contained in:
parent
ba0aa60f67
commit
574dd7bf1d
codeigniter
application
assets
@ -3,19 +3,50 @@ defined('BASEPATH') OR exit('No direct script access allowed');
|
|||||||
|
|
||||||
class Artistes extends CI_Controller {
|
class Artistes extends CI_Controller {
|
||||||
|
|
||||||
|
private $sort = 'Tri';
|
||||||
|
|
||||||
public function __construct(){
|
public function __construct(){
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->load->model('model_music');
|
$this->load->model('model_music_artistes');
|
||||||
$this->load->helper('html');
|
$this->load->helper('html');
|
||||||
$this->load->helper('url');
|
$this->load->helper('url');
|
||||||
$this->load->helper('form');
|
$this->load->helper('form');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index(){
|
public function index(){
|
||||||
$artistes = $this->model_music->getArtistes();
|
$artistes = $this->model_music_artistes->getArtistes();
|
||||||
$this->load->view('layout/header');
|
$this->load->view('layout/header');
|
||||||
$this->load->view('artistes_list', ['artistes'=>$artistes]);
|
$this->load->view('artistes_list', ['artistes'=>$artistes]);
|
||||||
$this->load->view('layout/footer');
|
$this->load->view('layout/footer');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function tri(){
|
||||||
|
$Ctri = $this->input->get('Ctri');
|
||||||
|
$trie = $this->model_music_artistes->get_tri_Artistes($Ctri);
|
||||||
|
$num_results = count($trie);
|
||||||
|
$this->load->view('layout/header');
|
||||||
|
$this->load->view('artistes_list', [
|
||||||
|
'artistes' => $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_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');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
68
codeigniter/application/models/Model_music_artistes.php
Normal file
68
codeigniter/application/models/Model_music_artistes.php
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||||
|
|
||||||
|
class Model_music_artistes extends CI_Model {
|
||||||
|
|
||||||
|
public function __construct(){
|
||||||
|
$this->load->database();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getArtistes(){
|
||||||
|
$query = $this->db->query(
|
||||||
|
"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"
|
||||||
|
);
|
||||||
|
return $query->result();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_tri_Artistes($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 artist.name $Ctri";
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = $this->db->query(
|
||||||
|
"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
|
||||||
|
$orderBy"
|
||||||
|
);
|
||||||
|
return $query->result();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function searchArtistes($query){
|
||||||
|
$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";
|
||||||
|
|
||||||
|
$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);
|
||||||
|
return $query->result();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,34 @@
|
|||||||
<h5>Artistes list</h5>
|
<h5>Artistes list</h5>
|
||||||
|
|
||||||
|
<div class="sorting-search">
|
||||||
|
<form action="<?= site_url('Artistes/tri'); ?>" method="get" class="tri-form">
|
||||||
|
<select name="Ctri" class="tri-select">
|
||||||
|
<option value="">Trier</option>
|
||||||
|
<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>
|
||||||
|
<form action="<?= site_url('Artistes/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">
|
<section class="list">
|
||||||
<?php
|
<?php
|
||||||
$artistAlbums = array();
|
$artistAlbums = array();
|
||||||
|
@ -56,13 +56,14 @@ ul.options {
|
|||||||
background-color: #283d5d;
|
background-color: #283d5d;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 50px;
|
top: 50px;
|
||||||
right: 12px;
|
right: 55px;
|
||||||
text-align: center
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sous li {
|
.sous li {
|
||||||
display: block!important;
|
display: block!important;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
|
margin-right: 5px!important;
|
||||||
}
|
}
|
||||||
|
|
||||||
nav > ul li:hover .sous {
|
nav > ul li:hover .sous {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user