mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-04 10:19:25 +02:00
Add merge on tags (fix #120)
Set classic theme box size to 95% (fix #221)
This commit is contained in:
parent
740427c328
commit
f63768348f
7 changed files with 107 additions and 26 deletions
BIN
images/background.png
Normal file
BIN
images/background.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
|
@ -30,6 +30,7 @@ class Tag extends database_object
|
|||
{
|
||||
public $id;
|
||||
public $name;
|
||||
public $merged_to;
|
||||
|
||||
/**
|
||||
* constructor
|
||||
|
@ -166,10 +167,8 @@ class Tag extends database_object
|
|||
{
|
||||
if (!strlen($value)) { return false; }
|
||||
|
||||
$value = Dba::escape($value);
|
||||
|
||||
$sql = "REPLACE INTO `tag` SET `name`='$value'";
|
||||
Dba::write($sql);
|
||||
$sql = "REPLACE INTO `tag` SET `name` = ?";
|
||||
Dba::write($sql, array($value));
|
||||
$insert_id = Dba::insert_id();
|
||||
|
||||
parent::add_to_cache('tag_name', $value, $insert_id);
|
||||
|
@ -187,13 +186,49 @@ class Tag extends database_object
|
|||
//debug_event('tag.class', 'Updating tag {'.$this->id.'} with name {'.$name.'}...', '5');
|
||||
if (!strlen($name)) { return false; }
|
||||
|
||||
$name = Dba::escape($name);
|
||||
|
||||
$sql = 'UPDATE `tag` SET `name` = ? WHERE `id` = ?';
|
||||
Dba::write($sql, array($name, $this->id));
|
||||
|
||||
} // add_tag
|
||||
|
||||
/**
|
||||
* merge
|
||||
* Merge the tag to another one.
|
||||
*/
|
||||
public function merge($merge_to, $is_persistent)
|
||||
{
|
||||
debug_event('tag', 'Merging tag ' . $this->id . ' to ' . $merge_to . ' (persistent: ' . ($is_persistent ? 'yes' : 'no') . ')...', '5');
|
||||
|
||||
$sql = "UPDATE `tag_map` SET `tag_map`.`tag_id` = ? " .
|
||||
"WHERE `tag_map`.`tag_id` = ?";
|
||||
Dba::write($sql, array($merge_to, $this->id));
|
||||
|
||||
if ($is_persistent) {
|
||||
$sql = 'UPDATE `tag` SET `merged_to` = ? WHERE `id` = ?';
|
||||
Dba::write($sql, array($merge_to, $this->id));
|
||||
} else {
|
||||
$this->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get_merged_tags
|
||||
* Get merged tags to this tag.
|
||||
*/
|
||||
public function get_merged_tags()
|
||||
{
|
||||
$sql = "SELECT `tag`.`id`, `tag`.`name`" .
|
||||
"FROM `tag` " .
|
||||
"WHERE `tag`.`merged_to` = ? " .
|
||||
"ORDER BY `tag`.`name`";
|
||||
|
||||
$db_results = Dba::read($sql, array($this->id));
|
||||
|
||||
while ($row = Dba::fetch_assoc($db_results)) {
|
||||
$results[$row['id']] = array('id'=>$row['id'], 'name'=>$row['name']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add_tag_map
|
||||
* This adds a specific tag to the map for specified object
|
||||
|
@ -207,9 +242,14 @@ class Tag extends database_object
|
|||
|
||||
if (!$tag_id || !$id) { return false; }
|
||||
|
||||
// If tag merged to another one, add reference to the merge destination
|
||||
$tag = new Tag($tag_id);
|
||||
if ($tag->merged_to) {
|
||||
$tag_id = $tag->merged_to;
|
||||
}
|
||||
$sql = "INSERT INTO `tag_map` (`tag_id`,`user`,`object_type`,`object_id`) " .
|
||||
"VALUES ('$tag_id','$uid','$type','$id')";
|
||||
Dba::write($sql);
|
||||
"VALUES (?, ?, ?, ?)";
|
||||
Dba::write($sql, array($tag_id, $uid, $type, $id));
|
||||
$insert_id = Dba::insert_id();
|
||||
|
||||
parent::add_to_cache('tag_map_' . $type,$insert_id,array('tag_id'=>$tag_id,'user'=>$uid,'object_type'=>$type,'object_id'=>$id));
|
||||
|
@ -255,11 +295,11 @@ class Tag extends database_object
|
|||
*/
|
||||
public function delete()
|
||||
{
|
||||
$sql = "DELETE FROM `tag_map` WHERE `tag_map`.`tag_id`='".$this->id."'";
|
||||
Dba::write($sql);
|
||||
$sql = "DELETE FROM `tag_map` WHERE `tag_map`.`tag_id` = ?";
|
||||
Dba::write($sql, array($this->id));
|
||||
|
||||
$sql = "DELETE FROM `tag` WHERE `tag`.`id`='".$this->id."'";
|
||||
Dba::write($sql);
|
||||
$sql = "DELETE FROM `tag` WHERE `tag`.`id` = ? OR `tag`.`merged_to` = ?";
|
||||
Dba::write($sql, array($this->id, $this->id));
|
||||
|
||||
// Call the garbage collector to clean everything
|
||||
Tag::gc();
|
||||
|
@ -277,9 +317,8 @@ class Tag extends database_object
|
|||
return parent::get_from_cache('tag_name',$value);
|
||||
}
|
||||
|
||||
$value = Dba::escape($value);
|
||||
$sql = "SELECT * FROM `tag` WHERE `name`='$value'";
|
||||
$db_results = Dba::read($sql);
|
||||
$sql = "SELECT * FROM `tag` WHERE `name` = ?";
|
||||
$db_results = Dba::read($sql, array($value));
|
||||
|
||||
$results = Dba::fetch_assoc($db_results);
|
||||
|
||||
|
@ -298,13 +337,9 @@ class Tag extends database_object
|
|||
{
|
||||
if (!self::validate_type($type)) { return false; }
|
||||
|
||||
$object_id = Dba::escape($object_id);
|
||||
$tag_id = Dba::escape($tag_id);
|
||||
$user = Dba::escape($user);
|
||||
$type = Dba::escape($type);
|
||||
|
||||
$sql = "SELECT * FROM `tag_map` WHERE `tag_id`='$tag_id' AND `user`='$user' AND `object_id`='$object_id' AND `object_type`='$type'";
|
||||
$db_results = Dba::read($sql);
|
||||
$sql = "SELECT * FROM `tag_map` LEFT JOIN `tag` ON `tag`.`id` = `tag_map`.`tag_id` " .
|
||||
"WHERE (`tag_map`.`tag_id` = ? OR `tag_map`.`tag_id` = `tag`.`merged_to`) AND `tag_map`.`user` = ? AND `tag_map`.`object_id` = ? AND `tag_map`.`object_type` = ?";
|
||||
$db_results = Dba::read($sql, array($tag_id, $user, $object_id, $type));
|
||||
|
||||
$results = Dba::fetch_assoc($db_results);
|
||||
|
||||
|
@ -350,14 +385,12 @@ class Tag extends database_object
|
|||
{
|
||||
if (!self::validate_type($type)) { return array(); }
|
||||
|
||||
$id = Dba::escape($id);
|
||||
|
||||
$sql = "SELECT `tag_map`.`id`, `tag`.`name`, `tag_map`.`user` FROM `tag` " .
|
||||
"LEFT JOIN `tag_map` ON `tag_map`.`tag_id`=`tag`.`id` " .
|
||||
"WHERE `tag_map`.`object_type`='$type' AND `tag_map`.`object_id`='$id'";
|
||||
"WHERE `tag_map`.`object_type` = ? AND `tag_map`.`object_id` = ?";
|
||||
|
||||
$results = array();
|
||||
$db_results = Dba::read($sql);
|
||||
$db_results = Dba::read($sql, array($type, $id));
|
||||
|
||||
while ($row = Dba::fetch_assoc($db_results)) {
|
||||
$results[] = $row;
|
||||
|
@ -415,6 +448,7 @@ class Tag extends database_object
|
|||
$sql = "SELECT `tag_map`.`tag_id`, `tag`.`name`, COUNT(`tag_map`.`object_id`) AS `count` " .
|
||||
"FROM `tag_map` " .
|
||||
"LEFT JOIN `tag` ON `tag`.`id`=`tag_map`.`tag_id` " .
|
||||
"WHERE `tag`.`merged_to` IS NULL " .
|
||||
"GROUP BY `tag`.`name` ORDER BY `count` DESC ";
|
||||
|
||||
if ($limit > 0) {
|
||||
|
|
|
@ -404,6 +404,9 @@ class Update
|
|||
$update_string = '- Drop unused dynamic_playlist tables and add session id to votes.<br />';
|
||||
$version[] = array('version' => '370001','description' => $update_string);
|
||||
|
||||
$update_string = '- Add tag persistent merge reference.<br />';
|
||||
$version[] = array('version' => '370002','description' => $update_string);
|
||||
|
||||
return $version;
|
||||
}
|
||||
|
||||
|
@ -2483,4 +2486,17 @@ class Update
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* update_370002
|
||||
*
|
||||
* Add tag persistent merge reference
|
||||
*/
|
||||
public static function update_370002()
|
||||
{
|
||||
$sql = "ALTER TABLE `tag` ADD `merged_to` int(11) NULL AFTER `name`";
|
||||
Dba::write($sql);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -228,6 +228,12 @@ function showEditDialog(edit_type, edit_id, edit_form_id, edit_title, refresh_ro
|
|||
availableTags: parent.editTagChoices
|
||||
});
|
||||
}
|
||||
|
||||
if ($('#select_tags').length > 0) {
|
||||
$.each(parent.editTagChoices, function(i, tagtext) {
|
||||
$("#select_tags").append(new Option(tagtext, tagtext));
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
close: function (e) {
|
||||
|
|
|
@ -181,6 +181,12 @@ switch ($_REQUEST['action']) {
|
|||
case 'tag_row':
|
||||
$tag = new Tag($_POST['id']);
|
||||
$tag->update($_POST['name']);
|
||||
if ($_POST['select_tags']) {
|
||||
$merge_to = Tag::construct_from_name($_POST['select_tags']);
|
||||
if ($merge_to->id) {
|
||||
$tag->merge($merge_to->id, ($_POST['merge_persist'] == '1'));
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$key = 'rfc3514';
|
||||
|
|
|
@ -27,6 +27,24 @@
|
|||
<td class="edit_dialog_content_header"><?php echo T_('Name') ?></td>
|
||||
<td><input type="text" name="name" value="<?php echo scrub_out($tag->name); ?>" /></td>
|
||||
</tr>
|
||||
<tr><td> </td></tr>
|
||||
<tr>
|
||||
<td class="edit_dialog_content_header"><?php echo T_('Merge this tag to') ?></td>
|
||||
<td>
|
||||
<select name="select_tags" id="select_tags">
|
||||
<option value=""></option>
|
||||
<?php
|
||||
if ($tag->merged_to) {
|
||||
echo "<option value='" . $tag->merged_to . "'>" . $tag->merged_to . "</option>";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="edit_dialog_content_header"><?php echo T_('Persistent merge') ?></td>
|
||||
<td><input type="checkbox" name="merge_persist" value="1" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
<input type="hidden" name="id" value="<?php echo $tag->id; ?>" />
|
||||
<input type="hidden" name="type" value="tag_row" />
|
||||
|
|
|
@ -495,6 +495,7 @@ a.button{padding:1px 3px;}
|
|||
float:left;
|
||||
clear:left;
|
||||
height:1%; /* IE6 : Holly Hack comes to rescue once again */
|
||||
width: 95%;
|
||||
}
|
||||
.box-inside {
|
||||
background: url(../images/right.gif) top right repeat-y;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue