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

55 lines
1.8 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Artistes 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');
$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){
$artistes = $this->model_music->get_filtered_artistes($genre, $sort, $order);
$data['artistes'] = $artistes;
}else{
$recherche=filter_input(INPUT_GET,'recherche');
$artistes = $this->model_music->getSearchArtistes($recherche);
$data['artistes'] = $artistes;
}
$this->load->view('layout/header');
if ($artistes == false){
$page = preg_split('/[\/]/',$_SERVER['REQUEST_URI']);
$this->load->view('error',['page'=>$page[count($page)-1]]);
$artistes = $this->model_music->get_filtered_artistes($genre, $sort, $order);
$data['artistes'] = $artistes;
}
$data['genres'] = $this->model_music->get_all_genres_artistes();
$this->load->view('artistes_list',$data);
$this->load->view('layout/footer');
}
public function addArtistestoPlaylist($id) {
$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');
$this->load->view('addArtistestoplaylist', ["playlists" => $playlists]);
$this->load->view('layout/footer');
}else{
$playlistId = $this->input->post('playlist_id');
$this->model_music->AddArtistestoPlaylist($playlistId,$id);
redirect('artistes');
}
}
}