SAEWEB2.2/ci/application/controllers/Albums.php

62 lines
2.0 KiB
PHP
Raw Permalink Normal View History

2024-05-21 15:05:29 +02:00
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Albums extends CI_Controller {
2024-05-30 10:05:37 +02:00
public function __construct(){
parent::__construct();
$this->load->model('model_music');
2024-06-12 18:17:31 +02:00
$this->load->library('session');
2024-05-30 10:05:37 +02:00
}
2024-05-28 11:55:36 +02:00
2024-05-30 10:05:37 +02:00
public function index(){
2024-06-10 18:45:37 +02:00
$genre = $this->model_music->getGenre();
$this->load->view('layout/header');
2024-06-10 18:45:37 +02:00
$this->load->view('GenreFilter',['genre'=>$genre]);
2024-06-10 11:16:43 +02:00
$selectedGenre = '0';
$search = '';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
2024-06-10 18:45:37 +02:00
if(isset($_POST['Genre'])){
$selectedGenre = $_POST['Genre'];
}
2024-06-10 11:16:43 +02:00
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if(isset($_POST['recherche'])){
$search = $_POST['recherche'];
}
}
2024-06-12 18:17:31 +02:00
$mail = $this->session->userdata('mail');
$playlists = $this->model_music->getPlaylist($mail);
2024-06-10 18:45:37 +02:00
$albums = $this->model_music->searchAlbums($search, $selectedGenre);
$this->load->view('albums_list', ['albums' => $albums, 'playlists' => $playlists]);
$this->load->view('layout/footer');
2024-05-30 10:05:37 +02:00
}
2024-05-21 15:05:29 +02:00
2024-06-10 18:45:37 +02:00
2024-05-30 10:05:37 +02:00
public function view($album_id){
2024-05-30 10:33:06 +02:00
$songs = $this->model_music->getSongOfAlbum($album_id);
2024-05-30 10:05:37 +02:00
if (empty($songs)) {
2024-05-30 16:14:38 +02:00
$songs = [];
2024-05-30 10:05:37 +02:00
}
2024-06-12 18:17:31 +02:00
$mail = $this->session->userdata('mail');
$playlists = $this->model_music->getPlaylist($mail);
$this->load->view('layout/header');
2024-06-11 15:08:29 +02:00
$this->load->view('song_album_list', ['songs' => $songs, 'playlists' => $playlists]);
$this->load->view('layout/footer');
2024-06-11 15:08:29 +02:00
}
public function addAllSongsToPlaylist(){
$album_id = $this->input->post('album_id');
$playlistId = $this->input->post('playlist');
$songs = $this->model_music->getSongOfAlbum($album_id);
foreach ($songs as $song) {
$this->model_music->addSongToPlaylist($song->name, $playlistId);
}
redirect('playlist');
}
2024-05-30 10:05:37 +02:00
}
?>