mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-06 03:49:56 +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
|
@ -191,8 +191,15 @@ class Tag extends database_object implements library_item
|
|||
$sql = 'UPDATE `tag` SET `name` = ? WHERE `id` = ?';
|
||||
Dba::write($sql, array($data[name], $this->id));
|
||||
|
||||
if ($data['select_tags']) {
|
||||
$merge_to = Tag::construct_from_name($data['select_tags']);
|
||||
if ($data['split_tag']) {
|
||||
$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) {
|
||||
$this->merge($merge_to->id, ($data['merge_persist'] == '1'));
|
||||
}
|
||||
|
@ -228,6 +235,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 to this tag.
|
||||
|
@ -502,11 +532,33 @@ class Tag extends database_object implements library_item
|
|||
} // get_tags
|
||||
|
||||
/**
|
||||
* get_display
|
||||
* get_display_list
|
||||
* 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
|
||||
* 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='')
|
||||
{
|
||||
//debug_event('tag.class.php', 'Get display tags called...', '5');
|
||||
|
|
|
@ -158,12 +158,14 @@ function showEditDialog(edit_type, edit_id, edit_form_id, edit_title, refresh_ro
|
|||
parent.editTagChoices = new Array();
|
||||
if (tag_choices == undefined && tag_choices != '') {
|
||||
// Load tag map
|
||||
$.ajax(jsAjaxServer + '/ajax.server.php?page=tag&action=get_tag_map', { success: function(data) {
|
||||
tag_choices = $(data).find('content').text();
|
||||
if (tag_choices != '') {
|
||||
showEditDialog(edit_type, edit_id, edit_form_id, edit_title, refresh_row_prefix);
|
||||
}
|
||||
}, type: 'post', dataType: 'xml' });
|
||||
$.ajax(jsAjaxServer + '/ajax.server.php?page=tag&action=get_tag_map', {
|
||||
success: function(data) {
|
||||
tag_choices = $(data).find('content').text();
|
||||
if (tag_choices != '') {
|
||||
showEditDialog(edit_type, edit_id, edit_form_id, edit_title, refresh_row_prefix);
|
||||
}
|
||||
}, type: 'post', dataType: 'xml'
|
||||
});
|
||||
return;
|
||||
}
|
||||
var splitted = tag_choices.split(',');
|
||||
|
@ -173,12 +175,12 @@ function showEditDialog(edit_type, edit_id, edit_form_id, edit_title, refresh_ro
|
|||
}
|
||||
|
||||
parent.dialog_buttons = {};
|
||||
this.dialog_buttons[jsSaveTitle] = function() {
|
||||
this.dialog_buttons[jsSaveTitle] = function () {
|
||||
$.ajax({
|
||||
url : parent.saveUrl,
|
||||
type : 'POST',
|
||||
data : $(parent.editFormId).serializeArray(),
|
||||
success : function(resp){
|
||||
url: parent.saveUrl,
|
||||
type: 'POST',
|
||||
data: $(parent.editFormId).serializeArray(),
|
||||
success: function (resp) {
|
||||
$("#editdialog").dialog("close");
|
||||
|
||||
if (parent.refreshRowPrefix != '') {
|
||||
|
@ -204,10 +206,10 @@ function showEditDialog(edit_type, edit_id, edit_form_id, edit_title, refresh_ro
|
|||
loadContentPage(reloadp);
|
||||
}
|
||||
},
|
||||
error : function(resp){
|
||||
error: function(resp) {
|
||||
$("#editdialog").dialog("close");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
this.dialog_buttons[jsCancelTitle] = function() {
|
||||
$("#editdialog").dialog("close");
|
||||
|
@ -234,9 +236,15 @@ function showEditDialog(edit_type, edit_id, edit_form_id, edit_title, refresh_ro
|
|||
});
|
||||
}
|
||||
|
||||
if ($('#select_tags').length > 0) {
|
||||
$.each(parent.editTagChoices, function(i, tagtext) {
|
||||
$("#select_tags").append(new Option(tagtext, tagtext));
|
||||
if ($('#merge_tag').length > 0) {
|
||||
$.each(parent.editTagChoices, function (i, 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));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -299,13 +307,13 @@ function submitNewItemsOrder(itemId, tableid, rowPrefix, updateUrl, refreshActio
|
|||
|
||||
if (finalOrder != '') {
|
||||
$.ajax({
|
||||
url : updateUrl,
|
||||
type : 'GET',
|
||||
data : 'order=' + finalOrder,
|
||||
success : function(resp){
|
||||
url: updateUrl,
|
||||
type: 'GET',
|
||||
data: 'order=' + finalOrder,
|
||||
success: function (resp) {
|
||||
var url = jsAjaxServer + '/refresh_reordered.server.php?action=' + parent.refreshAction + '&id=' + parent.itemId;
|
||||
// Reload only table
|
||||
$('#reordered_list_' + parent.itemId).load(url, function() {
|
||||
$('#reordered_list_' + parent.itemId).load(url, function () {
|
||||
$('#sortableplaylist_' + parent.itemId).sortable({
|
||||
axis: 'y',
|
||||
delay: 200
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
<tr>
|
||||
<td class="edit_dialog_content_header"><?php echo T_('Merge this tag to') ?></td>
|
||||
<td>
|
||||
<select name="select_tags" id="select_tags">
|
||||
<select name="merge_tag" id="merge_tag">
|
||||
<option value=""></option>
|
||||
<?php
|
||||
if ($libitem->merged_to) {
|
||||
|
@ -45,6 +45,20 @@
|
|||
<td class="edit_dialog_content_header"><?php echo T_('Persistent merge') ?></td>
|
||||
<td><input type="checkbox" name="merge_persist" value="1" /></td>
|
||||
</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>
|
||||
<input type="hidden" name="id" value="<?php echo $libitem->id; ?>" />
|
||||
<input type="hidden" name="type" value="tag_row" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue