push
This commit is contained in:
		
							
								
								
									
										151
									
								
								application/controllers/Playlist.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										151
									
								
								application/controllers/Playlist.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,151 @@
 | 
			
		||||
<?php
 | 
			
		||||
defined('BASEPATH') OR exit('No direct script access allowed');
 | 
			
		||||
 | 
			
		||||
class Playlist extends CI_Controller {
 | 
			
		||||
    public function __construct() {
 | 
			
		||||
        parent::__construct();
 | 
			
		||||
        $this->load->model('Model_playlist');
 | 
			
		||||
        $this->load->model('Model_music'); // Ajouté pour accéder aux musiques
 | 
			
		||||
        $this->load->library('session');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function index() {
 | 
			
		||||
        $is_logged_in = $this->session->userdata('logged_in');
 | 
			
		||||
        $user_email = $this->session->userdata('email');
 | 
			
		||||
 | 
			
		||||
        if (!$is_logged_in) {
 | 
			
		||||
            redirect('connect/login');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $data = array(
 | 
			
		||||
            'is_logged_in' => $is_logged_in,
 | 
			
		||||
            'playlists' => $this->Model_playlist->getPlaylistsByUser($user_email)
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        $this->load->view('layout/header', $data);
 | 
			
		||||
        $this->load->view('playlists_list', $data);
 | 
			
		||||
        $this->load->view('layout/footer');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function add() {
 | 
			
		||||
        $is_logged_in = $this->session->userdata('logged_in');
 | 
			
		||||
        $user_email = $this->session->userdata('email');
 | 
			
		||||
 | 
			
		||||
        if (!$is_logged_in) {
 | 
			
		||||
            redirect('connect/login');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $name = $this->input->post('name');
 | 
			
		||||
        $type = $this->input->post('type');
 | 
			
		||||
 | 
			
		||||
        if ($type == 'random') {
 | 
			
		||||
            $numSongs = $this->input->post('numSongs');
 | 
			
		||||
            $artist = $this->input->post('artist');
 | 
			
		||||
            $genre = $this->input->post('genre');
 | 
			
		||||
            $this->Model_playlist->createRandomPlaylist($user_email, $name, $numSongs, $artist, $genre);
 | 
			
		||||
        } else {
 | 
			
		||||
            $this->Model_playlist->addPlaylist($user_email, $name);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        redirect('playlist');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function selectPlaylist() {
 | 
			
		||||
        $itemId = $this->input->post('itemId');
 | 
			
		||||
        $itemType = $this->input->post('itemType');
 | 
			
		||||
        $playlists = $this->Model_playlist->getPlaylistsByUser($this->session->userdata('email'));
 | 
			
		||||
 | 
			
		||||
        $data = array(
 | 
			
		||||
            'itemId' => $itemId,
 | 
			
		||||
            'itemType' => $itemType,
 | 
			
		||||
            'playlists' => $playlists
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        $this->load->view('layout/header', $data);
 | 
			
		||||
        $this->load->view('select_playlist', $data);
 | 
			
		||||
        $this->load->view('layout/footer');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function addItems() {
 | 
			
		||||
        $playlistId = $this->input->post('playlistId');
 | 
			
		||||
        $itemId = $this->input->post('itemId');
 | 
			
		||||
        $itemType = $this->input->post('itemType');
 | 
			
		||||
 | 
			
		||||
        if ($itemType == 'album') {
 | 
			
		||||
            $songs = $this->Model_music->getSongsByAlbum($itemId);
 | 
			
		||||
            foreach ($songs as $song) {
 | 
			
		||||
                $this->Model_playlist->addItem($playlistId, $song->id, 'song');
 | 
			
		||||
            }
 | 
			
		||||
        } else if ($itemType == 'artist') {
 | 
			
		||||
            $albums = $this->Model_music->getAlbumsByArtist($itemId);
 | 
			
		||||
            foreach ($albums as $album) {
 | 
			
		||||
                $songs = $this->Model_music->getSongsByAlbum($album->albumId);
 | 
			
		||||
                foreach ($songs as $song) {
 | 
			
		||||
                    $this->Model_playlist->addItem($playlistId, $song->id, 'song');
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            $this->Model_playlist->addItem($playlistId, $itemId, 'song');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        redirect('playlist/view/' . $playlistId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function view($playlistId) {
 | 
			
		||||
        $is_logged_in = $this->session->userdata('logged_in');
 | 
			
		||||
        $items = $this->Model_playlist->getPlaylistItems($playlistId);
 | 
			
		||||
        $data = array(
 | 
			
		||||
            'is_logged_in' => $is_logged_in,
 | 
			
		||||
            'items' => $items
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        $this->load->view('layout/header', $data);
 | 
			
		||||
        $this->load->view('playlist_details', $data);
 | 
			
		||||
        $this->load->view('layout/footer');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function deleteItem($playlistId, $itemId) {
 | 
			
		||||
        $this->Model_playlist->deleteItem($playlistId, $itemId);
 | 
			
		||||
        redirect('playlist/view/' . $playlistId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function delete($playlist_id) {
 | 
			
		||||
        $is_logged_in = $this->session->userdata('logged_in');
 | 
			
		||||
        $user_email = $this->session->userdata('email');
 | 
			
		||||
 | 
			
		||||
        if (!$is_logged_in) {
 | 
			
		||||
            redirect('connect/login');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $this->Model_playlist->deletePlaylist($playlist_id);
 | 
			
		||||
        redirect('playlist');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function duplicate($playlist_id) {
 | 
			
		||||
        $is_logged_in = $this->session->userdata('logged_in');
 | 
			
		||||
        $user_email = $this->session->userdata('email');
 | 
			
		||||
 | 
			
		||||
        if (!$is_logged_in) {
 | 
			
		||||
            redirect('connect/login');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $this->Model_playlist->duplicatePlaylist($playlist_id, $user_email);
 | 
			
		||||
        redirect('playlist');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function rename() {
 | 
			
		||||
        $is_logged_in = $this->session->userdata('logged_in');
 | 
			
		||||
        $user_email = $this->session->userdata('email');
 | 
			
		||||
 | 
			
		||||
        if (!$is_logged_in) {
 | 
			
		||||
            redirect('connect/login');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $playlistId = $this->input->post('playlistId');
 | 
			
		||||
        $newName = $this->input->post('newName');
 | 
			
		||||
 | 
			
		||||
        $this->Model_playlist->renamePlaylist($playlistId, $newName);
 | 
			
		||||
        redirect('playlist');
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user