1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-05 19:42:38 +02:00

Option to clone playlist

This commit is contained in:
Daniel Neto 2024-05-16 14:39:01 -03:00
parent 7a431e1ac6
commit 53f58c358b
5 changed files with 139 additions and 40 deletions

View file

@ -84,6 +84,7 @@ function _error_log_debug($message, $show_args = false)
function _error_log($message, $type = 0, $doNotRepeat = false)
{
if(isSchedulerRun()){
echo $message.PHP_EOL;
return false;
}
if (empty($doNotRepeat)) {

View file

@ -162,7 +162,7 @@ class PlayList extends ObjectYPT
if (!empty($_REQUEST['searchPlaylist'])) {
$sql .= " AND pl.name LIKE CONCAT('%', ?, '%') ";
$formats .= "s";
$values[] = $_REQUEST['searchPlaylist'];
$values[] = trim($_REQUEST['searchPlaylist']);
}
$sql .= self::getSqlFromPost("pl.");
@ -295,7 +295,7 @@ class PlayList extends ObjectYPT
if (!empty($_REQUEST['searchPlaylist'])) {
$sql .= " AND pl.name LIKE CONCAT('%', ?, '%') ";
$formats .= "s";
$values[] = $_REQUEST['searchPlaylist'];
$values[] = trim($_REQUEST['searchPlaylist']);
}
$res = sqlDAL::readSql($sql, $formats, $values, $refreshCacheFromPlaylist);
$row = sqlDAL::fetchAssoc($res);
@ -930,7 +930,8 @@ class PlayList extends ObjectYPT
return sqlDAL::writeSql($sql);
}
static function getNextOrder($playlists_id){
static function getNextOrder($playlists_id)
{
$sql = 'SELECT MAX(`order`) AS max_order
FROM playlists_has_videos
WHERE playlists_id = ? ';
@ -1242,4 +1243,39 @@ class PlayList extends ObjectYPT
}
return $rows;
}
public static function clone($playlists_id)
{
// Modify the name to include " (Clone)"
$sql = "INSERT INTO playlists (name, created, modified, users_id, status, showOnTV, showOnFirstPage)
SELECT
CONCAT(name, ' (Clone)') AS name,
NOW() AS created,
NOW() AS modified,
users_id,
status,
showOnTV,
showOnFirstPage
FROM
playlists
WHERE
id = ?";
$new_playlist_id = sqlDAL::writeSql($sql, 'i', [$playlists_id]);
// Clone the videos associated with the playlist
$sql = "INSERT INTO playlists_has_videos (playlists_id, videos_id, `order`)
SELECT
? AS playlists_id,
videos_id,
`order`
FROM
playlists_has_videos
WHERE
playlists_id = ?";
sqlDAL::writeSql($sql, 'ii', [$new_playlist_id, $playlists_id]);
return $new_playlist_id;
}
}

View file

@ -0,0 +1,41 @@
<?php
global $global, $config;
if (!isset($global['systemRootPath'])) {
require_once '../../videos/configuration.php';
}
require_once $global['systemRootPath'] . 'objects/playlist.php';
require_once $global['systemRootPath'] . 'objects/configuration.php';
header('Content-Type: application/json');
$obj = new stdClass();
$obj->error = true;
$obj->msg = "";
if(!User::isLogged()){
forbiddenPage('Must login');
}
$users_id = User::getId();
$playlistPlugin = AVideoPlugin::getObjectDataIfEnabled('PlayLists');
if (empty($playlistPlugin)) {
forbiddenPage('Programs plugin not enabled');
}
$playlists_id = intval($_REQUEST['playlists_id']);
if (empty($playlists_id)) {
forbiddenPage('Programs id error');
}
$pl = new PlayList($playlists_id);
if (User::getId() != $pl->getUsers_id() && !User::isAdmin()) {
forbiddenPage('Programs does not belong to you');
}
$obj->new_playlist_id = PlayList::clone($playlists_id);
$obj->error = empty($obj->new_playlist_id);
die(json_encode($obj));

View file

@ -153,7 +153,7 @@ $_page = new Page(array('Manage playlist'));
?>
<div class="col-sm-6 col-md-4 col-lg-3 pl pl<?php echo $value["id"]; ?> <?php echo implode(' ', $classes) ?>">
<div class="panel panel-<?php echo $totalSubPlaylists ? 'primary' : 'default'; ?>">
<div class="panel-heading">
<div class="panel-heading clearfix">
<?php
echo "[{$value["id"]}] ";
if (!empty($totalSubPlaylists)) {
@ -174,6 +174,9 @@ $_page = new Page(array('Manage playlist'));
<button type="button" class="btn btn-default btn-xs editBtn " onclick="editPlayList(<?php echo $value['id']; ?>);" data-toggle="tooltip" title="<?php echo __('Edit'); ?>">
<i class="fas fa-edit"></i>
</button>
<button type="button" class="btn btn-default btn-xs cloneBtn " onclick="clonePlayList(<?php echo $value['id']; ?>);" data-toggle="tooltip" title="<?php echo __('Clone'); ?>">
<i class="fa-regular fa-clone"></i>
</button>
<?php
echo PlayLists::scheduleLiveButton($value['id'], false);
?>
@ -422,6 +425,22 @@ $_page = new Page(array('Manage playlist'));
avideoModalIframe(webSiteRootURL + 'viewProgram/' + playlists_id);
}
function clonePlayList(playlists_id) {
var url = 'plugin/PlayLists/clone.json.php';
var data = {
"playlists_id": playlists_id
};
var pleaseWait = true;
var returnFunction = function(response) {
console.log('returnFunction', response);
if (!response.error) {
avideoToastSuccess(__('Playlist cloned') + ' #' + response.new_playlist_id);
editPlayList(response.new_playlist_id);
}
};
avideoAjaxWithResponse(url, data, pleaseWait, returnFunction);
}
function removeFromSerie(playlists_id, videos_id) {
swal({
title: "<?php echo __('Are you sure?'); ?>",

View file

@ -1763,6 +1763,9 @@ function avideoResponse(response) {
avideoToastInfo(response.msg);
} else {
avideoToastSuccess(response.msg);
if (typeof response.eval !== 'undefined') {
eval(response.eval);
}
}
}
}
@ -2358,42 +2361,41 @@ function changeVideoStatus(videos_id, status) {
}
function avideoAjax(url, data) {
if (!url.startsWith('http')) {
url = webSiteRootURL + url;
}
avideoAjax2(url, data, true);
avideoAjaxWithResponse(url, data, true, ()=>{});
}
function avideoAjax2(url, data, pleaseWait) {
function avideoAjaxWithResponse(url, data, pleaseWait, returnFunction) {
if (pleaseWait) {
modal.showPleaseWait();
}
if (!url.startsWith('http')) {
url = webSiteRootURL + url;
}
$.ajax({
url: url,
data: data,
type: 'post',
success: function (response) {
if (response.error) {
avideoAlertError(response.msg);
} else {
avideoToastSuccess(response.msg);
if (typeof response.eval !== 'undefined') {
eval(response.eval);
}
}
},
error: function (response) {
//console.error('avideoAjax2', url, data, pleaseWait, response.responseJSON);
if (response.responseJSON.error) {
avideoAlertError(response.responseJSON.msg);
} else {
avideoToastError(response.responseJSON.msg);
}
},
complete: function (response) {
complete: function (jqXHR, textStatus) {
if (pleaseWait) {
modal.hidePleaseWait();
}
if (jqXHR.status >= 200 && jqXHR.status < 300) {
// Successful response
if (jqXHR.responseJSON) {
avideoResponse(jqXHR.responseJSON);
returnFunction(jqXHR.responseJSON);
} else {
returnFunction(jqXHR.responseText);
}
} else {
// Error response
console.error('Error:', textStatus, jqXHR.statusText);
if (jqXHR.responseJSON) {
avideoResponse(jqXHR.responseJSON);
} else {
avideoAlertError(textStatus + ': ' + jqXHR.statusText);
}
}
}
});
}