SAE_2.02/CodeIgniter-3.1.13/application/controllers/Musiques.php

65 lines
2.3 KiB
PHP
Raw Normal View History

2024-05-20 21:59:37 +02:00
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Musiques extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->model('Model_music');
2024-05-31 11:35:07 +02:00
$this->load->model('Model_playlist');
2024-05-20 21:59:37 +02:00
$this->load->library('pagination');
$this->load->helper('url');
$this->load->helper('html');
2024-05-31 11:35:07 +02:00
$this->load->library('session');
2024-05-20 21:59:37 +02:00
}
public function index($page = 1){
2024-05-30 14:38:38 +02:00
$limit = 30;
2024-05-20 21:59:37 +02:00
$offset = ($page - 1) * $limit;
2024-05-22 22:05:48 +02:00
$sort = $this->input->get('sort');
2024-05-30 14:38:38 +02:00
$genre_id = $this->input->get('genre_id');
$artist_id = $this->input->get('artist_id');
2024-05-22 22:05:48 +02:00
$total_musiques = $this->Model_music->get_total_musiques_filtered($genre_id, $artist_id);
$total_pages = ceil($total_musiques / $limit);
2024-05-22 22:05:48 +02:00
$current_page = $page;
$musiques = $this->Model_music->getMusiques($limit, $offset, $sort, 'ASC', $genre_id, $artist_id);
2024-05-30 14:38:38 +02:00
$genres = $this->Model_music->getGenres();
$artists = $this->Model_music->getArtists();
2024-05-31 11:35:07 +02:00
if ($this->session->userdata('user_id')) {
$user_id = $this->session->userdata('user_id');
$data['user_playlists'] = $this->Model_playlist->get_user_playlists($user_id);
}
2024-05-20 21:59:37 +02:00
$data['musiques'] = $musiques;
2024-05-22 22:05:48 +02:00
$data['total_pages'] = $total_pages;
$data['current_page'] = $current_page;
2024-05-30 14:38:38 +02:00
$data['sort'] = $sort;
$data['genres'] = $genres;
$data['artists'] = $artists;
$data['genre_id'] = $genre_id;
$data['artist_id'] = $artist_id;
$data['title'] = "Musiques - Onzeur";
$data['css'] = "assets/css/musiques_list";
// Vérifier si la page demandée est valide
if ($page > $total_pages || $page < 1) {
// Définir le message d'erreur
$data['error_message'] = "Aucun résultat n'a été trouvé...";
// Charger la vue des musiques avec le message d'erreur
$this->load->view('layout/header_dark', $data);
$this->load->view('musiques_list', $data);
$this->load->view('layout/footer_dark');
return;
}
2024-05-20 22:42:38 +02:00
2024-05-30 13:49:35 +02:00
$this->load->view('layout/header_dark', $data);
2024-05-30 14:38:38 +02:00
$this->load->view('musiques_list', $data);
$this->load->view('layout/footer_dark');
}
2024-05-20 22:42:38 +02:00
2024-05-20 21:59:37 +02:00
}