mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-05 10:49:37 +02:00
added the ability to split tags, inverse of the tag merge functionality
This commit is contained in:
parent
a87a343ca0
commit
13736a9bfe
3 changed files with 115 additions and 41 deletions
|
@ -190,9 +190,16 @@ class Tag extends database_object implements library_item
|
||||||
|
|
||||||
$sql = 'UPDATE `tag` SET `name` = ? WHERE `id` = ?';
|
$sql = 'UPDATE `tag` SET `name` = ? WHERE `id` = ?';
|
||||||
Dba::write($sql, array($data[name], $this->id));
|
Dba::write($sql, array($data[name], $this->id));
|
||||||
|
|
||||||
if ($data['select_tags']) {
|
if ($data['split_tag']) {
|
||||||
$merge_to = Tag::construct_from_name($data['select_tags']);
|
$split_to = Tag::construct_from_name($data['split_tag']);
|
||||||
|
if ($split_to->id) {
|
||||||
|
$this->split($split_to->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($data['merge_tag']) {
|
||||||
|
$merge_to = Tag::construct_from_name($data['merge_tag']);
|
||||||
if ($merge_to->id) {
|
if ($merge_to->id) {
|
||||||
$this->merge($merge_to->id, ($data['merge_persist'] == '1'));
|
$this->merge($merge_to->id, ($data['merge_persist'] == '1'));
|
||||||
}
|
}
|
||||||
|
@ -227,6 +234,29 @@ class Tag extends database_object implements library_item
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* split
|
||||||
|
* Splits this tag to two.
|
||||||
|
*/
|
||||||
|
public function split($split_to)
|
||||||
|
{
|
||||||
|
if ($this->id != $split_to) {
|
||||||
|
debug_event('tag', 'Splitting tag ' . $this->id . ' into ' . $split_to . ')...', '5');
|
||||||
|
|
||||||
|
$sql = "INSERT INTO `tag_map` (`tag_id`,`user`,`object_type`,`object_id`) " .
|
||||||
|
"SELECT ?,`user`,`object_type`,`object_id` " .
|
||||||
|
"FROM `tag_map` AS `tm`" .
|
||||||
|
"WHERE `tm`.`tag_id` = ? AND NOT EXISTS ( " .
|
||||||
|
"SELECT 1 FROM `tag_map` ".
|
||||||
|
"WHERE `tag_map`.`tag_id` = ? " .
|
||||||
|
"AND `tag_map`.`object_id` = `tm`.`object_id` " .
|
||||||
|
"AND `tag_map`.`object_type` = `tm`.`object_type` " .
|
||||||
|
"AND `tag_map`.`user` = `tm`.`user`" .
|
||||||
|
")";
|
||||||
|
Dba::write($sql, array($split_to, $this->id, $split_to));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get_merged_tags
|
* get_merged_tags
|
||||||
|
@ -502,11 +532,33 @@ class Tag extends database_object implements library_item
|
||||||
} // get_tags
|
} // get_tags
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get_display
|
* get_display_list
|
||||||
* This returns a human formated version of the tags that we are given
|
* This returns a human formated version of the tags that we are given
|
||||||
* it also takes a type so that it knows how to return it, this is used
|
* it also takes a type so that it knows how to return it, this is used
|
||||||
* by the formating functions of the different objects
|
* by the formating functions of the different objects
|
||||||
*/
|
*/
|
||||||
|
public static function get_display_list($tags)
|
||||||
|
{
|
||||||
|
if (!is_array($tags)) { return ''; }
|
||||||
|
|
||||||
|
$results = '<ul class="tags">';
|
||||||
|
|
||||||
|
// Iterate through the tags, format them according to type and element id
|
||||||
|
foreach ($tags as $tag_id=>$value) {
|
||||||
|
$tag = new Tag($tag_id);
|
||||||
|
$results .= '<li>' . $value['name'] . '</li>';
|
||||||
|
}
|
||||||
|
$results .= '</ul>';
|
||||||
|
return $results;
|
||||||
|
|
||||||
|
} // get_display
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get_display
|
||||||
|
* This returns a csv formated version of the tags that we are given
|
||||||
|
* it also takes a type so that it knows how to return it, this is used
|
||||||
|
* by the formating functions of the different objects
|
||||||
|
*/
|
||||||
public static function get_display($tags, $link=false, $filter_type='')
|
public static function get_display($tags, $link=false, $filter_type='')
|
||||||
{
|
{
|
||||||
//debug_event('tag.class.php', 'Get display tags called...', '5');
|
//debug_event('tag.class.php', 'Get display tags called...', '5');
|
||||||
|
|
|
@ -66,7 +66,7 @@ function showPlaylistDialog(e, item_type, item_ids) {
|
||||||
$(this).dialog("destroy");
|
$(this).dialog("destroy");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#playlistdialog").dialog("option", "position", [e.clientX + 10, e.clientY]);
|
$("#playlistdialog").dialog("option", "position", [e.clientX + 10, e.clientY]);
|
||||||
$("#playlistdialog").dialog("open");
|
$("#playlistdialog").dialog("open");
|
||||||
closeplaylist = 0;
|
closeplaylist = 0;
|
||||||
|
@ -120,7 +120,7 @@ function showBroadcastsDialog(e) {
|
||||||
$(this).dialog("destroy");
|
$(this).dialog("destroy");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#broadcastsdialog").dialog("option", "position", [e.clientX - 180, e.clientY]);
|
$("#broadcastsdialog").dialog("option", "position", [e.clientX - 180, e.clientY]);
|
||||||
$("#broadcastsdialog").dialog("open");
|
$("#broadcastsdialog").dialog("open");
|
||||||
closebroadcasts = 0;
|
closebroadcasts = 0;
|
||||||
|
@ -153,17 +153,19 @@ function showEditDialog(edit_type, edit_id, edit_form_id, edit_title, refresh_ro
|
||||||
parent.refreshRowPrefix = refresh_row_prefix;
|
parent.refreshRowPrefix = refresh_row_prefix;
|
||||||
parent.editType = edit_type;
|
parent.editType = edit_type;
|
||||||
parent.editId = edit_id;
|
parent.editId = edit_id;
|
||||||
|
|
||||||
// Convert choices string ("tag0,tag1,tag2,...") to choices array
|
// Convert choices string ("tag0,tag1,tag2,...") to choices array
|
||||||
parent.editTagChoices = new Array();
|
parent.editTagChoices = new Array();
|
||||||
if (tag_choices == undefined && tag_choices != '') {
|
if (tag_choices == undefined && tag_choices != '') {
|
||||||
// Load tag map
|
// Load tag map
|
||||||
$.ajax(jsAjaxServer + '/ajax.server.php?page=tag&action=get_tag_map', { success: function(data) {
|
$.ajax(jsAjaxServer + '/ajax.server.php?page=tag&action=get_tag_map', {
|
||||||
tag_choices = $(data).find('content').text();
|
success: function(data) {
|
||||||
if (tag_choices != '') {
|
tag_choices = $(data).find('content').text();
|
||||||
showEditDialog(edit_type, edit_id, edit_form_id, edit_title, refresh_row_prefix);
|
if (tag_choices != '') {
|
||||||
}
|
showEditDialog(edit_type, edit_id, edit_form_id, edit_title, refresh_row_prefix);
|
||||||
}, type: 'post', dataType: 'xml' });
|
}
|
||||||
|
}, type: 'post', dataType: 'xml'
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var splitted = tag_choices.split(',');
|
var splitted = tag_choices.split(',');
|
||||||
|
@ -171,16 +173,16 @@ function showEditDialog(edit_type, edit_id, edit_form_id, edit_title, refresh_ro
|
||||||
for (i = 0; i < splitted.length; ++i) {
|
for (i = 0; i < splitted.length; ++i) {
|
||||||
parent.editTagChoices.push($.trim(splitted[i]));
|
parent.editTagChoices.push($.trim(splitted[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
parent.dialog_buttons = {};
|
parent.dialog_buttons = {};
|
||||||
this.dialog_buttons[jsSaveTitle] = function() {
|
this.dialog_buttons[jsSaveTitle] = function () {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url : parent.saveUrl,
|
url: parent.saveUrl,
|
||||||
type : 'POST',
|
type: 'POST',
|
||||||
data : $(parent.editFormId).serializeArray(),
|
data: $(parent.editFormId).serializeArray(),
|
||||||
success : function(resp){
|
success: function (resp) {
|
||||||
$("#editdialog").dialog("close");
|
$("#editdialog").dialog("close");
|
||||||
|
|
||||||
if (parent.refreshRowPrefix != '') {
|
if (parent.refreshRowPrefix != '') {
|
||||||
var new_id = $.trim(resp.lastChild.textContent);
|
var new_id = $.trim(resp.lastChild.textContent);
|
||||||
|
|
||||||
|
@ -188,7 +190,7 @@ function showEditDialog(edit_type, edit_id, edit_form_id, edit_title, refresh_ro
|
||||||
if (new_id == '') {
|
if (new_id == '') {
|
||||||
new_id = parent.editId;
|
new_id = parent.editId;
|
||||||
}
|
}
|
||||||
|
|
||||||
var url = jsAjaxServer + '/edit.server.php?action=refresh_updated&type=' + parent.editType + '&id=' + new_id;
|
var url = jsAjaxServer + '/edit.server.php?action=refresh_updated&type=' + parent.editType + '&id=' + new_id;
|
||||||
// Reload only table
|
// Reload only table
|
||||||
$('#' + parent.refreshRowPrefix + parent.editId).load(url, function() {
|
$('#' + parent.refreshRowPrefix + parent.editId).load(url, function() {
|
||||||
|
@ -204,15 +206,15 @@ function showEditDialog(edit_type, edit_id, edit_form_id, edit_title, refresh_ro
|
||||||
loadContentPage(reloadp);
|
loadContentPage(reloadp);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error : function(resp){
|
error: function(resp) {
|
||||||
$("#editdialog").dialog("close");
|
$("#editdialog").dialog("close");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.dialog_buttons[jsCancelTitle] = function() {
|
this.dialog_buttons[jsCancelTitle] = function() {
|
||||||
$("#editdialog").dialog("close");
|
$("#editdialog").dialog("close");
|
||||||
}
|
}
|
||||||
|
|
||||||
$(parent.editDialogId).dialog({
|
$(parent.editDialogId).dialog({
|
||||||
title: edit_title,
|
title: edit_title,
|
||||||
modal: true,
|
modal: true,
|
||||||
|
@ -224,7 +226,7 @@ function showEditDialog(edit_type, edit_id, edit_form_id, edit_title, refresh_ro
|
||||||
open: function () {
|
open: function () {
|
||||||
$(this).load(parent.contentUrl, function() {
|
$(this).load(parent.contentUrl, function() {
|
||||||
$(this).dialog('option', 'position', 'center');
|
$(this).dialog('option', 'position', 'center');
|
||||||
|
|
||||||
if ($('#edit_tags').length > 0) {
|
if ($('#edit_tags').length > 0) {
|
||||||
$("#edit_tags").tagit({
|
$("#edit_tags").tagit({
|
||||||
allowSpaces: true,
|
allowSpaces: true,
|
||||||
|
@ -233,10 +235,16 @@ function showEditDialog(edit_type, edit_id, edit_form_id, edit_title, refresh_ro
|
||||||
availableTags: parent.editTagChoices
|
availableTags: parent.editTagChoices
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($('#select_tags').length > 0) {
|
if ($('#merge_tag').length > 0) {
|
||||||
$.each(parent.editTagChoices, function(i, tagtext) {
|
$.each(parent.editTagChoices, function (i, tagtext) {
|
||||||
$("#select_tags").append(new Option(tagtext, tagtext));
|
$("#merge_tag").append(new Option(tagtext, tagtext));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($('#split_tag').length > 0) {
|
||||||
|
$.each(parent.editTagChoices, function (i, tagtext) {
|
||||||
|
$("#split_tag").append(new Option(tagtext, tagtext));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -247,7 +255,7 @@ function showEditDialog(edit_type, edit_id, edit_form_id, edit_title, refresh_ro
|
||||||
},
|
},
|
||||||
buttons: dialog_buttons
|
buttons: dialog_buttons
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#editdialog").dialog("open");
|
$("#editdialog").dialog("open");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +275,7 @@ function check_inline_song_edit(type, song) {
|
||||||
/*********************/
|
/*********************/
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
|
|
||||||
var eles = $("tbody[id^='sortableplaylist_']");
|
var eles = $("tbody[id^='sortableplaylist_']");
|
||||||
if (eles != null) {
|
if (eles != null) {
|
||||||
var len = eles.length;
|
var len = eles.length;
|
||||||
|
@ -288,7 +296,7 @@ function submitNewItemsOrder(itemId, tableid, rowPrefix, updateUrl, refreshActio
|
||||||
var table = document.getElementById(tableid);
|
var table = document.getElementById(tableid);
|
||||||
var rowLength = table.rows.length;
|
var rowLength = table.rows.length;
|
||||||
var finalOrder = '';
|
var finalOrder = '';
|
||||||
|
|
||||||
for (var i = 0; i < rowLength; ++i) {
|
for (var i = 0; i < rowLength; ++i) {
|
||||||
var row = table.rows[i];
|
var row = table.rows[i];
|
||||||
if (row.id != '') {
|
if (row.id != '') {
|
||||||
|
@ -296,16 +304,16 @@ function submitNewItemsOrder(itemId, tableid, rowPrefix, updateUrl, refreshActio
|
||||||
finalOrder += songid + ";"
|
finalOrder += songid + ";"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (finalOrder != '') {
|
if (finalOrder != '') {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url : updateUrl,
|
url: updateUrl,
|
||||||
type : 'GET',
|
type: 'GET',
|
||||||
data : 'order=' + finalOrder,
|
data: 'order=' + finalOrder,
|
||||||
success : function(resp){
|
success: function (resp) {
|
||||||
var url = jsAjaxServer + '/refresh_reordered.server.php?action=' + parent.refreshAction + '&id=' + parent.itemId;
|
var url = jsAjaxServer + '/refresh_reordered.server.php?action=' + parent.refreshAction + '&id=' + parent.itemId;
|
||||||
// Reload only table
|
// Reload only table
|
||||||
$('#reordered_list_' + parent.itemId).load(url, function() {
|
$('#reordered_list_' + parent.itemId).load(url, function () {
|
||||||
$('#sortableplaylist_' + parent.itemId).sortable({
|
$('#sortableplaylist_' + parent.itemId).sortable({
|
||||||
axis: 'y',
|
axis: 'y',
|
||||||
delay: 200
|
delay: 200
|
||||||
|
@ -324,6 +332,6 @@ function getPagePlaySettings() {
|
||||||
settings += '&subtitle=' + stg_subtitle.value;
|
settings += '&subtitle=' + stg_subtitle.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td class="edit_dialog_content_header"><?php echo T_('Merge this tag to') ?></td>
|
<td class="edit_dialog_content_header"><?php echo T_('Merge this tag to') ?></td>
|
||||||
<td>
|
<td>
|
||||||
<select name="select_tags" id="select_tags">
|
<select name="merge_tag" id="merge_tag">
|
||||||
<option value=""></option>
|
<option value=""></option>
|
||||||
<?php
|
<?php
|
||||||
if ($libitem->merged_to) {
|
if ($libitem->merged_to) {
|
||||||
|
@ -45,6 +45,20 @@
|
||||||
<td class="edit_dialog_content_header"><?php echo T_('Persistent merge') ?></td>
|
<td class="edit_dialog_content_header"><?php echo T_('Persistent merge') ?></td>
|
||||||
<td><input type="checkbox" name="merge_persist" value="1" /></td>
|
<td><input type="checkbox" name="merge_persist" value="1" /></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr><td> </td></tr>
|
||||||
|
<tr>
|
||||||
|
<td class="edit_dialog_content_header"><?php echo T_('Split this tag into') ?></td>
|
||||||
|
<td>
|
||||||
|
<select name="split_tag" id="split_tag">
|
||||||
|
<option value=""></option>
|
||||||
|
<?php
|
||||||
|
if ($libitem->merged_to) {
|
||||||
|
echo "<option value='" . $libitem->merged_to . "'>" . $libitem->merged_to . "</option>";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<input type="hidden" name="id" value="<?php echo $libitem->id; ?>" />
|
<input type="hidden" name="id" value="<?php echo $libitem->id; ?>" />
|
||||||
<input type="hidden" name="type" value="tag_row" />
|
<input type="hidden" name="type" value="tag_row" />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue