Release model in rails
This commit is contained in:
parent
a804d30ce8
commit
a31f5b1221
|
@ -6,6 +6,6 @@ class ArtistController < ApplicationController
|
|||
@albums.each do |a|
|
||||
rg_ids << a.id
|
||||
end
|
||||
|
||||
@releases = Release.getReleases(rg_ids, true, true);
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,19 +1,23 @@
|
|||
class Release < ActiveRecord::Base
|
||||
set_table_name 'musicbrainz.bh_release'
|
||||
def self.getReleases(release_groups, group_by_release = false, only_official = false)
|
||||
Release.all(:conditions => ['release_group IN(?) AND '. (only_official ? 'AND release_tyepe=1' : 'release_type IS NOT NULL'), release_groups], :order => 'date ASC, id ASC')
|
||||
|
||||
if ($group_by_release) {
|
||||
$g_releases = array();
|
||||
foreach ($releases as $release) {
|
||||
if (!isset($g_releases[$release['release_group']])) {
|
||||
$g_releases[$release['release_group']] = array();
|
||||
}
|
||||
$g_releases[$release['release_group']][$release['id']] = $release;
|
||||
}
|
||||
return $g_releases;
|
||||
} else {
|
||||
return $releases;
|
||||
}
|
||||
releases = Release.all(
|
||||
:conditions => [
|
||||
'release_group IN(?) AND '+
|
||||
(only_official ? 'release_type=1' : 'release_type IS NOT NULL'), release_groups
|
||||
],
|
||||
:order => 'date ASC, id ASC'
|
||||
)
|
||||
if group_by_release
|
||||
g_releases = {}
|
||||
releases.each do |release|
|
||||
if g_releases[release.release_group].nil?
|
||||
g_releases[release.release_group] = {}
|
||||
end
|
||||
g_releases[release.release_group][release.id] = release
|
||||
end
|
||||
return g_releases
|
||||
end
|
||||
return releases
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue