Add new views and styles for music application
- Created new CSS files for styling the application, including home.css and style.css. - Implemented 403 and 404 error views with appropriate messages and navigation. - Developed a dump view to display deleted elements with restoration options. - Enhanced home view to include music search functionality and display results. - Added listplay view for managing music playlists, including creation and deletion options. - Implemented loadmusic view for uploading new music with necessary fields. - Created login and register views for user authentication. - Developed sound view to display individual music tracks with playback controls and options for liking and deleting. - Updated menu view to include navigation links based on user authentication status.
This commit is contained in:
65
controller/connection/Connection.controller.php
Normal file
65
controller/connection/Connection.controller.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
class Connection{
|
||||
protected $lastID;
|
||||
|
||||
function __construct(){
|
||||
$this->param = include 'param.php';
|
||||
}
|
||||
|
||||
private function getConnection(){
|
||||
$param = include 'param.php';
|
||||
return mysqli_connect($param['host'], $param['username'], $param['password'], $param['dbname']);
|
||||
}
|
||||
|
||||
protected function tableExists(string $table){
|
||||
$tables = $this->getData("SHOW TABLES");
|
||||
foreach($tables as $tableName){
|
||||
if(strtolower($tableName[0]) == strtolower($table)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function execNoQuery($sql){
|
||||
$link = $this->getConnection();
|
||||
if(mysqli_query($link, $sql)){
|
||||
$this->lastID = mysqli_insert_id($link);
|
||||
mysqli_close($link);
|
||||
}else{
|
||||
echo mysqli_error($link) . '<br><br>';
|
||||
}
|
||||
}
|
||||
|
||||
private function execQuery($sql){
|
||||
$link = $this->getConnection();
|
||||
$query = mysqli_query($link, $sql);
|
||||
if(mysqli_close($link)){
|
||||
return $query;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected function getValue($tableName, $nameParam1, $nameParam2, $valueSearh){
|
||||
$sql = "SELECT $nameParam1 FROM $tableName WHERE $nameParam2='$valueSearh'";
|
||||
$result = $this->execQuery($sql);
|
||||
return mysqli_fetch_array($result)[$nameParam1];
|
||||
}
|
||||
|
||||
protected function getData($sql, $idColumn=null){
|
||||
$result = $this->execQuery($sql);
|
||||
$data = [];
|
||||
$cont = 0;
|
||||
while($row = mysqli_fetch_array($result)){
|
||||
if($idColumn == null){
|
||||
$data[$cont] = $row;
|
||||
$cont++;
|
||||
}else{
|
||||
$data[$row[$idColumn]] = $row;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
9
controller/connection/param.php
Normal file
9
controller/connection/param.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
"dbname" => "musicdb",
|
||||
"username" => "root",
|
||||
"password" => "",
|
||||
"host" => "localhost"
|
||||
];
|
||||
|
||||
120
controller/html/Html.controller.php
Normal file
120
controller/html/Html.controller.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
class Html
|
||||
{
|
||||
private $title;
|
||||
private $icon;
|
||||
private $html;
|
||||
private $head;
|
||||
private $body;
|
||||
private $style;
|
||||
private $script;
|
||||
private $meta;
|
||||
private $content;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->title = [];
|
||||
$this->icon = [];
|
||||
$this->html = [];
|
||||
$this->head = [];
|
||||
$this->body = [];
|
||||
$this->style = [];
|
||||
$this->script = [];
|
||||
$this->meta = [];
|
||||
$this->content = '';
|
||||
|
||||
// Cargando meta
|
||||
$this->loadMeta(['http-equiv' => 'Content-Type', 'content' => 'text/html;charset=UTF-8']);
|
||||
$this->loadMeta(['name' => 'viewport', 'content' => 'width=device-width, initial-scale=1, shrink-to-fit=no']);
|
||||
$this->loadMeta(['name' => 'description', 'content' => 'Escucha tu musica favorita donde y cuando quieras.']);
|
||||
$this->loadMeta(['name' => 'author', 'content' => 'Creado por RMB']);
|
||||
}
|
||||
|
||||
public function setTitle(string $title)
|
||||
{
|
||||
$this->title = [
|
||||
'start' => '<title>',
|
||||
'text' => $title,
|
||||
'end' => '</title>'
|
||||
];
|
||||
}
|
||||
|
||||
public function setIconPage(string $url)
|
||||
{
|
||||
$this->icon = [
|
||||
'start' => '<link',
|
||||
0 => ' ',
|
||||
1 => "rel='",
|
||||
'rel' => 'icon',
|
||||
2 => "' ",
|
||||
3 => "href='",
|
||||
'href' => $url,
|
||||
4 => "' ",
|
||||
5 => "type='",
|
||||
'type' => 'image/png',
|
||||
'end' => "'>"
|
||||
];
|
||||
}
|
||||
|
||||
public function loadMeta(array $meta)
|
||||
{
|
||||
$acum = '<meta ';
|
||||
foreach ($meta as $index => $value) {
|
||||
$acum .= "$index='$value' ";
|
||||
}
|
||||
$acum = trim($acum) . '>';
|
||||
array_push($this->meta, $acum);
|
||||
}
|
||||
|
||||
public function loadScripts(array $urls)
|
||||
{
|
||||
foreach ($urls as $url) {
|
||||
array_push($this->script, "<script src='$url'></script>");
|
||||
}
|
||||
}
|
||||
|
||||
public function loadStyles(array $urls)
|
||||
{
|
||||
foreach ($urls as $url) {
|
||||
array_push($this->style, "<link rel='stylesheet' href='$url' type='text/css'>");
|
||||
}
|
||||
}
|
||||
|
||||
public function loadHTML(string $html)
|
||||
{
|
||||
$this->content = $html;
|
||||
}
|
||||
|
||||
public function output()
|
||||
{
|
||||
$this->head = [
|
||||
'meta' => implode($this->meta),
|
||||
'title' => implode($this->title),
|
||||
'icon' => implode($this->icon),
|
||||
'style' => implode($this->style)
|
||||
];
|
||||
|
||||
$this->body = [
|
||||
'content' => $this->content,
|
||||
'script' => implode($this->script)
|
||||
];
|
||||
|
||||
$this->html = [
|
||||
'head' => implode($this->head),
|
||||
'body' => implode($this->body)
|
||||
];
|
||||
|
||||
echo implode($this->html);
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return isset($this->title['text']) ? $this->title['text'] : '';
|
||||
}
|
||||
|
||||
public function getIconPage(string $atribute = 'href')
|
||||
{
|
||||
return isset($this->icon[$atribute]) ? $this->icon[$atribute] : '';
|
||||
}
|
||||
}
|
||||
36
controller/listplayer/ListMusic.controller.php
Normal file
36
controller/listplayer/ListMusic.controller.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
class ListMusic extends Connection{
|
||||
private $table = 'listmusic';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if(!parent::tableExists($this->table)){
|
||||
parent::execNoQuery("CREATE TABLE $this->table(
|
||||
idListMusic INTEGER(10) PRIMARY KEY AUTO_INCREMENT,
|
||||
idMusic INTEGER(10) NOT NULL,
|
||||
idList INTEGER(10) NOT NULL,
|
||||
dateListMusic TIMESTAMP DEFAULT NOW(),
|
||||
deleteListMusic BOOLEAN DEFAULT FALSE
|
||||
)");
|
||||
}
|
||||
}
|
||||
|
||||
protected function newMusicToList(array $data){
|
||||
parent::execNoQuery("INSERT INTO $this->table(idMusic,idList) VALUES({$data['idMusic']}, {$data['idList']})");
|
||||
}
|
||||
|
||||
protected function existsMusicInList(int $idMusic, int $idList){
|
||||
$result = parent::getData("SELECT * FROM $this->table WHERE idMusic=$idMusic AND idList=$idList");
|
||||
return !empty($result);
|
||||
}
|
||||
|
||||
protected function getList(int $idList){
|
||||
$Music = new Music();
|
||||
$musics = parent::getData("SELECT * FROM $this->table WHERE idList=$idList AND NOT deleteListMusic");
|
||||
foreach($musics as $index => $music){
|
||||
$musics[$index]['music'] = $Music->getMusic($music['idMusic']);
|
||||
}
|
||||
return $musics;
|
||||
}
|
||||
}
|
||||
51
controller/listplayer/ListPlayer.controller.php
Normal file
51
controller/listplayer/ListPlayer.controller.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
class ListPlayer extends ListMusic{
|
||||
private $table = 'listplayer';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if(!parent::tableExists($this->table)){
|
||||
parent::execNoQuery("CREATE TABLE $this->table(
|
||||
idList INTEGER(10) PRIMARY KEY AUTO_INCREMENT,
|
||||
listName VARCHAR(200) NOT NULL,
|
||||
dateList TIMESTAMP DEFAULT NOW(),
|
||||
dateListDelete TIMESTAMP DEFAULT NOW(),
|
||||
idUser INTEGER(10) NOT NULL,
|
||||
deleteList BOOLEAN DEFAULT FALSE
|
||||
)");
|
||||
}
|
||||
}
|
||||
|
||||
public function newList(string $namelist){
|
||||
parent::execNoQuery("INSERT INTO $this->table(listname,idUser) VALUES('$namelist', " . Session::getUserID() .")");
|
||||
}
|
||||
|
||||
public function getListMusic(string $listMusic){
|
||||
$lists = parent::getData("SELECT * FROM $this->table WHERE NOT deleteList AND MD5(idList)='$listMusic'");
|
||||
|
||||
if(!empty($lists)){
|
||||
$lists[0]['musics'] = parent::getList($lists[0]['idList'], new Music());
|
||||
}
|
||||
|
||||
return !empty($lists) ? $lists[0] : [];
|
||||
}
|
||||
|
||||
public function addMusicToList(int $idList, int $idMusic){
|
||||
if(!parent::existsMusicInList($idMusic, $idList)){
|
||||
parent::newMusicToList(['idList' => $idList, 'idMusic' => $idMusic]);
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteList(int $idList){
|
||||
parent::execNoQuery("UPDATE $this->table SET deleteList=NOT deleteList, dateListDelete=NOW() WHERE idList=$idList AND idUser=" . Session::getUserID());
|
||||
}
|
||||
|
||||
public function getDelete(){
|
||||
return parent::getData("SELECT idList as id, listName as name, dateListDelete AS date, '$this->table' as 'origin' FROM $this->table WHERE deleteList AND idUser=" . Session::getUserID());
|
||||
}
|
||||
|
||||
public function getListName(){
|
||||
return parent::getData("SELECT * FROM $this->table WHERE NOT deleteList AND idUser=" . Session::getUserID());
|
||||
}
|
||||
}
|
||||
113
controller/music/Music.controller.php
Normal file
113
controller/music/Music.controller.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
class Music extends Connection{
|
||||
private $table = 'music';
|
||||
private $tableLike = 'likeMusic';
|
||||
private $tableGenner = 'genner';
|
||||
private $user;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if(!parent::tableExists($this->table)){
|
||||
parent::execNoQuery("CREATE TABLE $this->table(
|
||||
idMusic INTEGER(10) PRIMARY KEY AUTO_INCREMENT,
|
||||
nameMusic VARCHAR(200) NOT NULL,
|
||||
formatMusic VARCHAR(50) NOT NULL,
|
||||
fileNameMusic VARCHAR(50) NOT NULL,
|
||||
fileSizeMusic INTEGER(10) NOT NULL,
|
||||
descriptionMusic VARCHAR(500),
|
||||
authorMusic VARCHAR(200),
|
||||
idGenner INTEGER(10) NOT NULL,
|
||||
idUser INTEGER(10) NOT NULL,
|
||||
dateMusic TIMESTAMP DEFAULT NOW(),
|
||||
dateMusicDelete TIMESTAMP DEFAULT NOW(),
|
||||
deleteMusic BOOLEAN DEFAULT FALSE
|
||||
)");
|
||||
}
|
||||
|
||||
if(!parent::tableExists($this->tableLike)){
|
||||
parent::execNoQuery("CREATE TABLE $this->tableLike(
|
||||
idLike INTEGER(10) PRIMARY KEY AUTO_INCREMENT,
|
||||
idMusic INTEGER(10) NOT NULL,
|
||||
idUser INTEGER(10) NOT NULL,
|
||||
deleteLike BOOLEAN DEFAULT FALSE
|
||||
)");
|
||||
}
|
||||
|
||||
if(!parent::tableExists($this->tableGenner)){
|
||||
parent::execNoQuery("CREATE TABLE $this->tableGenner(
|
||||
idGenner INTEGER(10) PRIMARY KEY AUTO_INCREMENT,
|
||||
gennerName VARCHAR(100) NOT NULL,
|
||||
dateGenner TIMESTAMP DEFAULT NOW(),
|
||||
deleteGenner BOOLEAN DEFAULT FALSE
|
||||
)");
|
||||
}
|
||||
|
||||
$this->user = new User();
|
||||
}
|
||||
|
||||
private function __getMusic(array $musics){
|
||||
foreach($musics as $index => $music){
|
||||
$musics[$index]['user'] = $this->user->getUser($music['idUser']);
|
||||
$musics[$index]['genner'] = parent::getData("SELECT * FROM $this->tableGenner WHERE idGenner={$music['idGenner']}")[0];
|
||||
$musics[$index]['like'] = count(parent::getData("SELECT * FROM $this->tableLike WHERE idMusic={$music['idMusic']} AND idUser=" . Session::getUserID() . " AND NOT deleteLike")) == 1;
|
||||
$musics[$index]['likes'] = count(parent::getData("SELECT * FROM $this->tableLike WHERE idMusic={$music['idMusic']} AND NOT deleteLike"));
|
||||
}
|
||||
|
||||
return $musics;
|
||||
}
|
||||
|
||||
public function getMusics(string $search=null){
|
||||
$musics = parent::getData(
|
||||
"SELECT * FROM $this->table WHERE NOT deleteMusic"
|
||||
. (($search != null) ? " AND descriptionMusic LIKE '%$search%' OR nameMusic LIKE '%$search%' OR authorMusic LIKE '%$search%'" : ' LIMIT 10')
|
||||
);
|
||||
|
||||
return $this->__getMusic($musics);
|
||||
}
|
||||
|
||||
public function getMusic(int $idMusic){
|
||||
return $this->__getMusic(parent::getData("SELECT * FROM $this->table WHERE idMusic=$idMusic AND NOT deleteMusic"))[0];
|
||||
}
|
||||
|
||||
public function newMusic(array $music){
|
||||
parent::execNoQuery("INSERT INTO $this->table(
|
||||
nameMusic, formatMusic, fileNameMusic,
|
||||
fileSizeMusic, descriptionMusic, authorMusic,
|
||||
idGenner, idUser
|
||||
) VALUES(
|
||||
'{$music['nameMusic']}', '{$music['formatMusic']}', '{$music['fileNameMusic']}',
|
||||
'{$music['fileSizeMusic']}', '{$music['descriptionMusic']}', '{$music['authorMusic']}',
|
||||
{$music['idGenner']}, {$music['idUser']}
|
||||
)");
|
||||
}
|
||||
|
||||
public function getDelete(){
|
||||
return parent::getData("SELECT idMusic as id, CONCAT(nameMusic, ' - ', authorMusic) as name, dateMusicDelete as date, '$this->table' as 'origin' FROM $this->table WHERE deleteMusic AND idUser=" . Session::getUserID());
|
||||
}
|
||||
|
||||
public function deleteMusic(int $music){
|
||||
parent::execNoQuery("UPDATE $this->table SET deleteMusic=NOT deleteMusic, dateMusicDelete=NOW() WHERE idMusic=$music");
|
||||
}
|
||||
|
||||
public function like(array $like){
|
||||
$data = parent::getData("SELECT * FROM $this->tableLike WHERE idMusic={$like['idMusic']} AND idUser={$like['idUser']}");
|
||||
if(count($data) > 0){
|
||||
parent::execNoQuery("UPDATE $this->tableLike SET deleteLike=(NOT deleteLike) WHERE idLike={$data[0]['idLike']}");
|
||||
}else{
|
||||
parent::execNoQuery("INSERT INTO $this->tableLike(idMusic, idUser) VALUES({$like['idMusic']}, " . Session::getUserID() . ")");
|
||||
}
|
||||
}
|
||||
|
||||
public function newGennerMusic(string $name){
|
||||
parent::execNoQuery("INSERT INTO $this->tableGenner(gennerName) VALUES('$name')");
|
||||
}
|
||||
|
||||
public function updateGenner(int $idGenner, string $name){
|
||||
parent::execNoQuery("UPDATE $this->tableGenner SET gennerName='$name' WHERE idGenner=$idGenner");
|
||||
}
|
||||
|
||||
public function getGennersMusical(){
|
||||
return parent::getData("SELECT * FROM $this->tableGenner WHERE NOT deleteGenner order by gennerName", "idGenner");
|
||||
}
|
||||
}
|
||||
26
controller/user/Session.controller.php
Normal file
26
controller/user/Session.controller.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
|
||||
class Session{
|
||||
public static function Auth(){
|
||||
return isset($_SESSION['LOGIN'])?$_SESSION['LOGIN']:false;
|
||||
}
|
||||
|
||||
public static function Admin(){
|
||||
return isset($_SESSION['privileges'])?$_SESSION['privileges']:false;
|
||||
}
|
||||
|
||||
public static function getUsername(){
|
||||
return isset($_SESSION['username'])?$_SESSION['username']:null;
|
||||
}
|
||||
|
||||
public static function getUserID(){
|
||||
return isset($_SESSION['idUser'])?$_SESSION['idUser']:0;
|
||||
}
|
||||
|
||||
public static function logout(){
|
||||
unset($_SESSION);
|
||||
session_destroy();
|
||||
}
|
||||
}
|
||||
47
controller/user/User.controller.php
Normal file
47
controller/user/User.controller.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
class User extends Connection{
|
||||
private $table = 'user';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if(!parent::tableExists($this->table)){
|
||||
parent::execNoQuery("CREATE TABLE $this->table(
|
||||
idUser INTEGER(10) PRIMARY KEY AUTO_INCREMENT,
|
||||
username VARCHAR(50) NOT NULL, userpassword VARCHAR(50) NOT NULL,
|
||||
privileges BOOLEAN DEFAULT FALSE, date TIMESTAMP DEFAULT NOW(),
|
||||
deleteUser BOOLEAN DEFAULT FALSE
|
||||
)");
|
||||
}
|
||||
}
|
||||
|
||||
public function isAccess(array $login){
|
||||
$data = parent::getData("SELECT * FROM $this->table
|
||||
WHERE username='{$login['username']}'
|
||||
AND userpassword=MD5('{$login['password']}')
|
||||
AND NOT deleteUser"
|
||||
);
|
||||
|
||||
if(count($data) == 1){
|
||||
$_SESSION = $data[0];
|
||||
$_SESSION['LOGIN'] = true;
|
||||
}
|
||||
return count($data) == 1;
|
||||
}
|
||||
|
||||
public function newUser(array $register){
|
||||
parent::execNoQuery("INSERT INTO $this->table(username,userpassword) VALUE('{$register['username']}', MD5('{$register['password']}'))");
|
||||
}
|
||||
|
||||
public function exists(string $username){
|
||||
return count(parent::getData("SELECT * FROM $this->table WHERE username='$username'")) > 0;
|
||||
}
|
||||
|
||||
public function getUsers(){
|
||||
return parent::getData("SELECT * FROM $this->table WHERE NOT deleteUser");
|
||||
}
|
||||
|
||||
public function getUser(int $idUser){
|
||||
return parent::getData("SELECT * FROM $this->table WHERE NOT deleteUser AND idUser = $idUser")[0];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user