Files

86 lines
3.0 KiB
PHP
Raw Permalink Normal View History

2024-05-27 13:32:33 +02:00
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Chansons extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->model('model_music');
$this->load->library('form_validation');
2024-05-27 13:32:33 +02:00
}
public function index(){
$genre = $this->input->get('genre');
$artist = $this->input->get('artist');
$year = $this->input->get('year');
$album = $this->input->get('albums');
$sort = $this->input->get('sort');
$order = $this->input->get('order');
2024-06-16 19:05:37 +02:00
$recherche = $this->input->get('recherche', true);
if (empty($recherche)) {
$data['chansons'] = $this->model_music->get_filtered_chansons($genre, $artist, $year, $album, $sort, $order);
} else {
$data['chansons'] = $this->model_music->getSearchChansons($recherche);
}
2024-05-27 13:32:33 +02:00
$this->load->view('layout/header');
2024-06-16 19:05:37 +02:00
if ($data['chansons'] == false){
$page = preg_split('/[\/]/',$_SERVER['REQUEST_URI']);
2024-05-29 10:50:49 +02:00
$this->load->view('error',['page'=>$page[count($page)-1]]);
2024-06-16 19:05:37 +02:00
$data['chansons'] = $this->model_music->get_filtered_chansons($genre, $artist, $year, $album, $sort, $order);
2024-05-29 10:50:49 +02:00
}
$data['genres'] = $this->model_music->get_all_genres_chansons();
$data['artists'] = $this->model_music->get_all_artists_chansons();
$data['years'] = $this->model_music->get_all_years_chansons();
$data['albums'] = $this->model_music->get_all_albums_chansons();
$this->load->view('chansons_list',$data);
2024-05-27 13:32:33 +02:00
$this->load->view('layout/footer');
}
public function addSongtoPlaylist($id){
2024-06-19 11:58:29 +02:00
$playlists = $this->model_music->getPlaylist($this->session->userdata('userId'));
$this->form_validation->set_rules('playlist_id', 'playlist_id', 'required');
if ($this->form_validation->run() == FALSE){
$this->load->view('layout/header');
2024-06-17 18:43:13 +02:00
$this->load->view('addSongtoplaylist', ["id" => $id, "playlists" => $playlists]);
$this->load->view('layout/footer');
}else{
$playlistId = $this->input->post('playlist_id');
2024-06-17 19:18:08 +02:00
$url = $this->input->get('page');
$this->model_music->AddSongtoPlaylist($playlistId,$id);
2024-06-17 19:18:08 +02:00
redirect($url);
}
}
public function deleteSongtoPlaylist($id){
2024-06-19 12:03:56 +02:00
$playlists = $this->model_music->getPlaylistIdSong($id, $this->session->userdata('userId'));
$this->form_validation->set_rules('playlist_id', 'playlist_id', 'required');
if ($this->form_validation->run() == FALSE){
$this->load->view('layout/header');
2024-06-17 18:43:13 +02:00
$this->load->view('deleteSongtoplaylist', ["id" => $id, "playlists" => $playlists]);
$this->load->view('layout/footer');
}else{
$playlistId = $this->input->post('playlist_id');
2024-06-17 19:18:08 +02:00
$url = $this->input->get('page');
$this->model_music->DeleteSongtoPlaylist($playlistId,$id);
2024-06-17 19:18:08 +02:00
redirect($url);
}
}
public function view($id){
$chansons = $this->model_music->get_song_playlist($id);
$data['chansons'] = $chansons;
$this->load->view('layout/header');
$this->load->view('chansons_list',$data);
$this->load->view('layout/footer');
}
2024-05-27 13:32:33 +02:00
}
2024-05-29 10:50:49 +02:00