SAE_2.02/CodeIgniter-3.1.13/application/controllers/Search.php

59 lines
1.9 KiB
PHP
Raw Normal View History

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Search extends CI_Controller {
public function __construct(){
parent::__construct();
2024-05-30 14:11:04 +02:00
$this->load->model('Search_model');
2024-06-01 17:49:36 +02:00
$this->load->model('Model_playlist');
2024-05-30 14:11:04 +02:00
$this->load->helper(['url', 'html']);
2024-06-01 17:49:36 +02:00
$this->load->library('session');
}
public function index(){
$query = $this->input->get('query');
if (empty($query)) {
$data['query'] = $query;
$data['musiques'] = [];
$data['albums'] = [];
$data['genres'] = [];
$data['artistes'] = [];
$data['error'] = "La requête de recherche ne peut pas être vide.";
2024-05-30 14:11:04 +02:00
$data['title'] = "Résultats de la recherche";
$data['css'] = "assets/css/search_results";
2024-05-30 13:49:35 +02:00
$this->load->view('layout/header_dark', $data);
2024-05-30 14:11:04 +02:00
$this->load->view('search_results', $data);
$this->load->view('layout/footer_dark');
2024-05-27 13:39:48 +02:00
return;
}
$musiques = $this->Search_model->searchMusiques($query);
$albums = $this->Search_model->searchAlbums($query);
$genres = $this->Search_model->searchGenres($query);
$artistes = $this->Search_model->searchArtistes($query);
$data['query'] = $query;
$data['musiques'] = $musiques;
$data['albums'] = $albums;
$data['genres'] = $genres;
$data['artistes'] = $artistes;
2024-06-01 17:49:36 +02:00
if ($this->session->userdata('user_id')) {
$user_id = $this->session->userdata('user_id');
$data['user_playlists'] = $this->Model_playlist->get_user_playlists($user_id);
}
2024-05-30 13:49:35 +02:00
2024-05-30 14:11:04 +02:00
$data['title'] = "Résultats de la recherche";
$data['css'] = "assets/css/search_results";
2024-05-30 13:49:35 +02:00
$this->load->view('layout/header_dark', $data);
2024-05-30 14:11:04 +02:00
$this->load->view('search_results', $data);
$this->load->view('layout/footer_dark');
}
}
2024-05-30 14:11:04 +02:00
?>