Skip to content

Commit

Permalink
fix played search for album and artist
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlan-00 committed Oct 20, 2021
1 parent b2e5a58 commit 359dc7c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Repository/Model/Search.php
Expand Up @@ -1489,6 +1489,19 @@ private function album_to_sql()
: "";
$where[] = "`myplayed_" . $my_type . "_" . $user_id . "`.`object_id` $operator_sql";
break;
case 'played':
$column = 'id';
$my_type = 'album';
$operator_sql = ((int)$sql_match_operator == 0) ? 'IS NULL' : 'IS NOT NULL';
// played once per user
if (!array_key_exists('played', $table)) {
$table['played'] = '';
}
$table['played'] .= (!strpos((string) $table['played'], "played_" . $my_type . "_" . $user_id))
? "LEFT JOIN (SELECT `object_id`, `object_type`, `user` FROM `object_count` WHERE `object_count`.`object_type` = '$my_type' AND `object_count`.`count_type` = 'stream' AND `object_count`.`user`=$user_id GROUP BY `object_id`, `object_type`, `user`) AS `played_" . $my_type . "_" . $user_id . "` ON `album`.`$column`=`played_" . $my_type . "_" . $user_id . "`.`object_id` AND `played_" . $my_type . "_" . $user_id . "`.`object_type` = '$my_type'"
: "";
$where[] = "`played_" . $my_type . "_" . $user_id . "`.`object_id` $operator_sql";
break;
case 'last_play':
$my_type = 'album';
if (!array_key_exists('last_play', $table)) {
Expand Down Expand Up @@ -1767,6 +1780,19 @@ private function artist_to_sql()
: "";
$where[] = "`myplayed_" . $my_type . "_" . $user_id . "`.`object_id` $operator_sql";
break;
case 'played':
$column = 'id';
$my_type = 'artist';
$operator_sql = ((int)$sql_match_operator == 0) ? 'IS NULL' : 'IS NOT NULL';
// played once per user
if (!array_key_exists('played', $table)) {
$table['played'] = '';
}
$table['played'] .= (!strpos((string) $table['played'], "played_" . $my_type . "_" . $user_id))
? "LEFT JOIN (SELECT `object_id`, `object_type`, `user` FROM `object_count` WHERE `object_count`.`object_type` = '$my_type' AND `object_count`.`count_type` = 'stream' AND `object_count`.`user`=$user_id GROUP BY `object_id`, `object_type`, `user`) AS `played_" . $my_type . "_" . $user_id . "` ON `album`.`$column`=`played_" . $my_type . "_" . $user_id . "`.`object_id` AND `played_" . $my_type . "_" . $user_id . "`.`object_type` = '$my_type'"
: "";
$where[] = "`played_" . $my_type . "_" . $user_id . "`.`object_id` $operator_sql";
break;
case 'last_play':
$my_type = 'artist';
if (!array_key_exists('last_play', $table)) {
Expand Down

0 comments on commit 359dc7c

Please sign in to comment.