Ticket #5452: mythweb_music_artist_sort_ignoring_prefixes.patch

File mythweb_music_artist_sort_ignoring_prefixes.patch, 2.1 KB (added by jonathan@…, 13 years ago)

It can even be done without defining the view using the following querie, artist name will not have the prefix in between brackets like the other, but if that is desired it is an easy fix.

  • mp3act_functions.php

    old new  
    251251      break;
    252252
    253253    case 'letter':
     254      // Define the list of prefixes we wish to ignore (perhaps define them as database item(s) somewhere so users can extend them)
     255      $prefixes = array ('a', 'an', 'the');
     256
    254257      if($itemid == "#")
    255258      {
    256         $query = 'SELECT * FROM music_artists '.
    257           "WHERE artist_name REGEXP '^[0-9].*' ".
    258           'ORDER BY artist_name';
     259          $query = "SELECT artist_id, artist_name, " .
     260                   "LOWER(CASE WHEN SUBSTRING_INDEX(artist_name, ' ', 1) IN ('" . implode("', '", $prefixes) . "') " .
     261                   "THEN " .
     262                   "CONCAT( SUBSTRING(artist_name, INSTR(artist_name , ' ') + 1), ' (', SUBSTRING_INDEX(artist_name, ' ', 1), ')' ) " .
     263                   "ELSE artist_name END) " .
     264                   "AS artist_name_sort " .
     265                   "FROM music_artists " .
     266                   "GROUP BY artist_name_sort " .
     267                   "HAVING artist_name REGEXP '^[0-9].*' " .
     268                   "ORDER BY artist_name_sort";
    259269      }
    260270      else
    261271      {
    262         $query = 'SELECT * FROM music_artists '.
    263           'WHERE artist_name LIKE \''.mysql_real_escape_string($itemid.'%').'\' '.
    264           'ORDER BY artist_name';
     272          $query = "SELECT artist_id, artist_name, " .
     273                   "LOWER(CASE WHEN SUBSTRING_INDEX(artist_name, ' ', 1) IN ('" . implode("', '", $prefixes) . "') " .
     274                   "THEN " .
     275                   "CONCAT( SUBSTRING(artist_name, INSTR(artist_name , ' ') + 1), ' (', SUBSTRING_INDEX(artist_name, ' ', 1), ')' ) " .
     276                   "ELSE artist_name END) " .
     277                   "AS artist_name_sort " .
     278                   "FROM music_artists " .
     279                   "GROUP BY artist_name_sort " .
     280                   "HAVING artist_name_sort " .
     281                   "LIKE '" . mysql_real_escape_string($itemid.'%') . "' " .
     282                   "ORDER BY artist_name_sort";
    265283      }
    266284      $result = mysql_query($query);
    267285      if (!$result)