Files
SAE_PHP_2024/CodeIgniter-3.1.13/application/controllers/Chansons.php

59 lines
2.1 KiB
PHP

<?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');
}
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');
if ($recherche=filter_input(INPUT_GET,'recherche') == false or $recherche=filter_input(INPUT_GET,'recherche') == null){
$chansons = $this->model_music->get_filtered_chansons($genre, $artist, $year, $album, $sort, $order);
$data['chansons'] = $chansons;
}else{
$recherche=filter_input(INPUT_GET,'recherche');
$chansons = $this->model_music->getSearchChansons($recherche);
$data['chansons'] = $chansons;
}
$this->load->view('layout/header');
if ($chansons == false){
$page = preg_split('/[\/]/',$_SERVER['REQUEST_URI']);
$this->load->view('error',['page'=>$page[count($page)-1]]);
$chansons = $this->model_music->get_filtered_chansons($genre, $artist, $year, $album, $sort, $order);
$data['chansons'] = $chansons;
}
$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);
$this->load->view('layout/footer');
}
public function addSongtoPlaylist($id){
$playlists = $this->model_music->getPlaylist();
$this->form_validation->set_rules('playlist_id', 'playlist_id', 'required');
if ($this->form_validation->run() == FALSE){
$this->load->view('layout/header');
$this->load->view('addSongtoplaylist', ["playlists" => $playlists]);
$this->load->view('layout/footer');
}else{
$playlistId = $this->input->post('playlist_id');
$this->model_music->AddSongtoPlaylist($playlistId,$id);
}
}
}