1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-03 09:49:30 +02:00

Implementation for #136 started. Album is now ready to be grouped by disks.

Need to create the new view in the album details. Group only works for album with musicbrainz identifiers.
This commit is contained in:
SUTJael 2014-03-20 21:23:34 +01:00
parent cd2e33cb1f
commit 7d22e8d466
15 changed files with 190 additions and 49 deletions

View file

@ -57,9 +57,16 @@ switch ($_REQUEST['action']) {
$name = $search->name;
break;
case 'album':
$album = new Album($_REQUEST['id']);
$media_ids = $album->get_songs();
foreach ($_REQUEST['id'] as $a) {
$album = new Album($a);
if (empty($name)) {
$name = $album->name;
}
$asongs = $album->get_songs();
foreach ($asongs as $song_id) {
$media_ids[] = $song_id;
}
}
break;
case 'artist':
$artist = new Artist($_REQUEST['id']);

View file

@ -42,6 +42,7 @@ function get_song_files($media_ids)
$total_size += sprintf("%.2f",($media->size/1048576));
$media->format();
$dirname = $media->f_album_full;
//debug_event('batch.lib.php', 'Songs file {'.$media->file.'}...', '5');
if (!array_key_exists($dirname, $media_files)) {
$media_files[$dirname] = array();
}

View file

@ -44,6 +44,9 @@ class Album extends database_object
public $_songs = array();
private static $_mapcache = array();
public $album_suite = array();
public $allow_group_disks = false;
/**
* __construct
* Album constructor it loads everything relating
@ -66,6 +69,11 @@ class Album extends database_object
// Little bit of formatting here
$this->full_name = trim(trim($info['prefix']) . ' ' . trim($info['name']));
// Looking for other albums with same mbid, ordering by disk ascending
if ($this->disk && !empty($this->mbid) && AmpConfig::get('album_group')) {
$this->album_suite = $this->get_album_suite();
}
return true;
} // constructor
@ -177,15 +185,31 @@ class Album extends database_object
"`artist`.`id` AS `artist_id` " .
"FROM `song` INNER JOIN `artist` " .
"ON `artist`.`id`=`song`.`artist` ";
if (AmpConfig::get('catalog_disable')) {
$sql .= "LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog` ";
}
$sql .= "WHERE `song`.`album` = ? ";
$suite_array = $this->album_suite;
if (!count($suite_array)) {
$suite_array[] = $this->id;
}
$idlist = '(' . implode(',', $suite_array) . ')';
$sql .= "WHERE `song`.`album` IN $idlist ";
if (AmpConfig::get('catalog_disable')) {
$sql .= "AND `catalog`.`enabled` = '1' ";
}
if (!count($this->album_suite)) {
$sql .= "GROUP BY `song`.`album`";
$db_results = Dba::read($sql, array($this->id));
} else {
$sql .= "GROUP BY `song`.`artist`";
}
debug_event("Album", "$sql", "6");
$db_results = Dba::read($sql);
$results = Dba::fetch_assoc($db_results);
@ -322,6 +346,54 @@ class Album extends database_object
} // get_songs
/**
* get_http_album_query_ids
* return the html album parameters with all album suite ids
*/
public function get_http_album_query_ids($url_param_name)
{
if ($this->allow_group_disks) {
$suite_array = $this->album_suite;
if (!count($suite_array)) {
$suite_array[] = $this->id;
}
} else {
$suite_array = array ($this->id);
}
return http_build_query(array($url_param_name => $suite_array));
}
/**
* get_album_suite
* gets the album ids with the same musicbrainz identifier
*/
public function get_album_suite()
{
$results = array();
$catalog_where = "";
$catalog_join = "LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog`";
if ($catalog) {
$catalog_where .= " AND `catalog`.`id` = '$catalog'";
}
if (AmpConfig::get('catalog_disable')) {
$catalog_where .= " AND `catalog`.`enabled` = '1'";
}
$sql = "SELECT DISTINCT `album`.`id` FROM album LEFT JOIN `song` ON `song`.`album`=`album`.`id` $catalog_join " .
"WHERE `album`.`mbid`='$this->mbid' $catalog_where ORDER BY `album`.`disk` ASC";
$db_results = Dba::read($sql);
while ($r = Dba::fetch_assoc($db_results)) {
$results[] = $r['id'];
}
return $results;
} // get_album_suite
/**
* has_track
* This checks to see if this album has a track of the specified title
@ -356,10 +428,14 @@ class Album extends database_object
$this->f_link_src = $web_path . '/albums.php?action=show&album=' . scrub_out($this->id);
$this->f_name_link = "<a href=\"" . $this->f_link_src . "\" title=\"" . scrub_out($this->full_name) . "\">" . scrub_out($this->f_name);
// If we've got a disk append it
if ($this->disk) {
$this->f_name_link .= " <span class=\"discnb disc" .$this->disk. "\">[" . T_('Disk') . " " . $this->disk . "]</span>";
// Looking to combine disks
if ($this->disk && (!$this->allow_group_disks || ($this->allow_group_disks && !AmpConfig::get('album_group')))) {
$this->f_name_link .= " <span class=\"discnb\">[" . T_('Disk') . " " . $this->disk . "]</span>";
} elseif ($this->disk && $this->allow_group_disks && AmpConfig::get('album_group') && count($this->album_suite) > 1) {
$this->f_name_link .= " <span class=\"discnb\">[#" . count($this->album_suite) . "]</span>";
}
$this->f_name_link .="</a>";
$this->f_link = $this->f_name_link;

View file

@ -161,13 +161,22 @@ class Artist extends database_object
$results = array();
$sql_sort = 'ORDER BY `album`.`name`,`album`.`disk`,`album`.`year`';
$sort_type = AmpConfig::get('album_sort');
if ($sort_type == 'year_asc') { $sql_sort = 'ORDER BY `album`.`year` ASC'; } elseif ($sort_type == 'year_desc') { $sql_sort = 'ORDER BY `album`.`year` DESC'; } elseif ($sort_type == 'name_asc') { $sql_sort = 'ORDER BY `album`.`name` ASC'; } elseif ($sort_type == 'name_desc') { $sql_sort = 'ORDER BY `album`.`name` DESC'; }
$sql_sort = '`album`.`name`,`album`.`disk`,`album`.`year`';
if ($sort_type == 'year_asc') {
$sql_sort = '`album`.`year` ASC';
} elseif ($sort_type == 'year_desc') {
$sql_sort = '`album`.`year` DESC';
} elseif ($sort_type == 'name_asc') {
$sql_sort = '`album`.`name` ASC';
} elseif ($sort_type == 'name_desc') {
$sql_sort = '`album`.`name` DESC';
}
$sql_group = "COALESCE(`album`.`mbid`, `album`.`id`)";
$sql = "SELECT `album`.`id` FROM album LEFT JOIN `song` ON `song`.`album`=`album`.`id` $catalog_join " .
"WHERE `song`.`artist`='$this->id' $catalog_where GROUP BY `album`.`id` $sql_sort";
"WHERE `song`.`artist`='$this->id' $catalog_where GROUP BY $sql_group ORDER BY $sql_sort";
debug_event("Artist", "$sql", "6");
$db_results = Dba::read($sql);

View file

@ -148,6 +148,7 @@ class Browse extends Query
case 'album':
$box_title = T_('Albums') . $match;
Album::build_cache($object_ids, 'extra');
$allow_group_disks = $argument;
$box_req = AmpConfig::get('prefix') . '/templates/show_albums.inc.php';
break;
case 'user':

View file

@ -391,6 +391,9 @@ class Update
$update_string = '- Add concerts options.<br />';
$version[] = array('version' => '360048','description' => $update_string);
$update_string = '- Add album group multiple disks setting.<br />';
$version[] = array('version' => '360049','description' => $update_string);
return $version;
}
@ -2360,4 +2363,21 @@ class Update
return true;
}
/**
* update_360049
*
* Add album group multiple disks setting
*/
public static function update_360049()
{
$sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
"VALUES ('album_group','0','Album - Group multiple disks',25,'boolean','interface')";
Dba::write($sql);
$id = Dba::insert_id();
$sql = "INSERT INTO `user_preference` VALUES (-1,?,'0')";
Dba::write($sql, array($id));
return true;
}
}

View file

@ -34,13 +34,12 @@ function showFilters(element) {
/************************************************************/
var closeplaylist;
function showPlaylistDialog(e, item_type, item_id) {
function showPlaylistDialog(e, item_type, item_ids) {
$("#playlistdialog").dialog("close");
var parent = this;
parent.itemType = item_type;
parent.itemId = item_id;
parent.contentUrl = jsAjaxServer + '/show_edit_playlist.server.php?action=show_edit_object&item_type=' + item_type + '&item_id=' + item_id;
parent.contentUrl = jsAjaxServer + '/show_edit_playlist.server.php?action=show_edit_object&item_type=' + item_type + '&item_id=' + item_ids;
parent.editDialogId = '<div id="playlistdialog"></div>';
$(parent.editDialogId).dialog({

View file

@ -179,6 +179,7 @@ function create_preference_input($name,$value)
case 'share':
case 'share_social':
case 'broadcast_by_default':
case 'album_group':
if ($value == '1') { $is_true = "selected=\"selected\""; } else { $is_false = "selected=\"selected\""; }
echo "<select name=\"$name\">\n";
echo "\t<option value=\"1\" $is_true>" . T_("Enable") . "</option>\n";

View file

@ -212,13 +212,21 @@ switch ($_REQUEST['action']) {
case 'basket':
switch ($_REQUEST['type']) {
case 'album':
foreach ($_REQUEST['id'] as $i) {
$object = new $_REQUEST['type']($i);
$songs = $object->get_songs();
foreach ($songs as $song_id) {
$GLOBALS['user']->playlist->add_object($song_id, 'song');
}
}
break;
case 'artist':
case 'tag':
$object = new $_REQUEST['type']($_REQUEST['id']);
$songs = $object->get_songs();
foreach ($songs as $song_id) {
$GLOBALS['user']->playlist->add_object($song_id,'song');
} // end foreach
}
break;
case 'browse_set':
$browse = new Browse($_REQUEST['browse_id']);
@ -228,6 +236,16 @@ switch ($_REQUEST['action']) {
}
break;
case 'album_random':
$data = explode('_',$_REQUEST['type']);
$type = $data['0'];
foreach ($_REQUEST['id'] as $i) {
$object = new $type($i);
$songs = $object->get_random_songs();
foreach ($songs as $song_id) {
$GLOBALS['user']->playlist->add_object($song_id, 'song');
}
}
break;
case 'artist_random':
case 'tag_random':
$data = explode('_',$_REQUEST['type']);

View file

@ -90,18 +90,21 @@ switch ($_REQUEST['action']) {
}
break;
case 'album':
debug_event('playlist', 'Adding all songs of album {'.$item_id.'}...', '5');
$album = new Album($item_id);
$songs = $album->get_songs();
foreach ($songs as $song_id) {
debug_event('playlist', 'Adding all songs of album(s) {'.$item_id.'}...', '5');
$albums_array = explode(',', $item_id);
foreach ($albums_array as $a) {
$album = new Album($a);
$asongs = $album->get_songs();
foreach ($asongs as $song_id) {
$songs[] = $song_id;
}
}
break;
case 'artist':
debug_event('playlist', 'Adding all songs of artist {'.$item_id.'}...', '5');
$artist = new Artist($item_id);
$songs = $artist->get_songs();
foreach ($songs as $song_id) {
$asongs = $artist->get_songs();
foreach ($asongs as $song_id) {
$songs[] = $song_id;
}
break;

View file

@ -71,7 +71,7 @@ switch ($_REQUEST['action']) {
case 'directplay':
switch ($_REQUEST['playtype']) {
case 'album':
$_SESSION['iframe']['target'] = AmpConfig::get('web_path') . '/stream.php?action=album&album_id='.$_REQUEST['album_id'];
$_SESSION['iframe']['target'] = AmpConfig::get('web_path') . '/stream.php?action=album&album_id='.implode(',', $_REQUEST['album_id']);
break;
case 'artist':
$_SESSION['iframe']['target'] = AmpConfig::get('web_path') . '/stream.php?action=artist&artist_id='.$_REQUEST['artist_id'];

View file

@ -101,13 +101,18 @@ switch ($_REQUEST['action']) {
$media_ids = $album->get_random_songs();
break;
case 'album':
$album = new Album($_REQUEST['album_id']);
debug_event('stream.php', 'Playing/Adding all songs of album(s) {'.$_REQUEST['album_id'].'}...', '5');
$albums_array = explode(',', $_REQUEST['album_id']);
foreach ($albums_array as $a) {
$album = new Album($a);
$songs = $album->get_songs();
foreach ($songs as $song) {
$media_ids[] = array(
'object_type' => 'song',
'object_id' => $song);
}
}
break;
case 'playlist':
$playlist = new Playlist($_REQUEST['playlist_id']);

View file

@ -24,9 +24,9 @@
<span class="cel_play_content">&nbsp;</span>
<div class="cel_play_hover">
<?php if (AmpConfig::get('directplay')) { ?>
<?php echo Ajax::button('?page=stream&action=directplay&playtype=album&album_id=' . $album->id,'play', T_('Play'),'play_album_' . $album->id); ?>
<?php echo Ajax::button('?page=stream&action=directplay&playtype=album&' . $album->get_http_album_query_ids('album_id'), 'play', T_('Play'), 'play_album_' . $album->id); ?>
<?php if (Stream_Playlist::check_autoplay_append()) { ?>
<?php echo Ajax::button('?page=stream&action=directplay&playtype=album&album_id=' . $album->id . '&append=true','play_add', T_('Play last'),'addplay_album_' . $album->id); ?>
<?php echo Ajax::button('?page=stream&action=directplay&playtype=album&' . $album->get_http_album_query_ids('album_id') . '&append=true', 'play_add', T_('Play last'), 'addplay_album_' . $album->id); ?>
<?php } ?>
<?php } ?>
</div>
@ -44,9 +44,9 @@ if (Art::is_enabled()) {
<td class="cel_album"><?php echo $album->f_name_link; ?></td>
<td class="cel_add">
<span class="cel_item_add">
<?php echo Ajax::button('?action=basket&type=album&id=' . $album->id,'add', T_('Add to temporary playlist'),'add_album_' . $album->id); ?>
<?php echo Ajax::button('?action=basket&type=album_random&id=' . $album->id,'random', T_('Random to temporary playlist'),'random_album_' . $album->id); ?>
<a id="<?php echo 'add_playlist_'.$album->id ?>" onclick="showPlaylistDialog(event, 'album', '<?php echo $album->id ?>')">
<?php echo Ajax::button('?action=basket&type=album&' . $album->get_http_album_query_ids('id'), 'add', T_('Add to temporary playlist'), 'add_album_' . $album->id); ?>
<?php echo Ajax::button('?action=basket&type=album_random&' . $album->get_http_album_query_ids('id'), 'random', T_('Random to temporary playlist'), 'random_album_' . $album->id); ?>
<a id="<?php echo 'add_playlist_'.$album->id ?>" onclick="showPlaylistDialog(event, 'album', '<?php if (!count($album->album_suite)) { echo $album->id; } else { echo implode(',', $album->album_suite); } ?>')">
<?php echo UI::get_icon('playlist_add', T_('Add to existing playlist')); ?>
</a>
</span>
@ -68,14 +68,14 @@ if (Art::is_enabled()) {
</a>
<?php } ?>
<?php if (AmpConfig::get('share')) { ?>
<a href="<?php echo $web_path; ?>/share.php?action=show_create&type=album&id=<?php echo $album->id; ?>"><?php echo UI::get_icon('share', T_('Share')); ?></a>
<a href="<?php echo $web_path; ?>/share.php?action=show_create&type=album&<?php echo $album->get_http_album_query_ids('id'); ?>"><?php echo UI::get_icon('share', T_('Share')); ?></a>
<?php } ?>
<?php if (Access::check_function('batch_download')) { ?>
<a href="<?php echo AmpConfig::get('web_path'); ?>/batch.php?action=album&id=<?php echo $album->id; ?>">
<a href="<?php echo AmpConfig::get('web_path'); ?>/batch.php?action=album&<?php echo $album->get_http_album_query_ids('id'); ?>">
<?php echo UI::get_icon('batch_download', T_('Batch Download')); ?>
</a>
<?php } ?>
<?php if (Access::check('interface','50')) { ?>
<?php if (Access::check('interface','50') && (!$album->allow_group_disks || ($album->allow_group_disks && !count($album->album_suite)))) { ?>
<a id="<?php echo 'edit_album_'.$album->id ?>" onclick="showEditDialog('album_row', '<?php echo $album->id ?>', '<?php echo 'edit_album_'.$album->id ?>', '<?php echo T_('Album edit') ?>', 'album_', 'refresh_album')">
<?php echo UI::get_icon('edit', T_('Edit')); ?>
</a>

View file

@ -57,6 +57,7 @@ $thcount = 8;
/* Foreach through the albums */
foreach ($object_ids as $album_id) {
$album = new Album($album_id);
$album->allow_group_disks = $allow_group_disks;
$album->format();
?>
<tr id="album_<?php echo $album->id; ?>" class="<?php echo UI::flip_class(); ?>">

View file

@ -140,7 +140,7 @@ if (AmpConfig::get('show_played_times')) {
<div id="tabs_content">
<div id="albums" class="tab_content" style="display: block;">
<?php
$browse->show_objects($object_ids);
$browse->show_objects($object_ids, true); // Passing 'true' means that we allow grouping albums by disks depending on the configuration
$browse->store();
?>
</div>