This commit is contained in:
Brian Smith 2012-12-17 02:02:20 -05:00
parent 45600115f7
commit db2f16c471
2 changed files with 61 additions and 2 deletions

View File

@ -57,6 +57,27 @@ module JamRuby
def add_member(user_id, admin)
BandMusician.create(:band_id => self.id, :user_id => user_id, :admin => admin)
end
def self.recording_index(current_user, band_id)
hide_private = false
band = Band.find(band_id)
# hide private Recordings from anyone who's not in the Band
unless band.users.exists? current_user
hide_private = true
end
if hide_private
recordings = Recording.joins(:band_recordings)
.where(:bands_recordings => {:band_id => "#{band_id}"}, :public => true)
else
recordings = Recording.joins(:band_recordings)
.where(:bands_recordings => {:band_id => "#{band_id}"})
end
return recordings
end
# helper method for creating / updating a Band
def self.save(id, name, website, biography, city, state, country, genres, user_id, photo_url, logo_url)

View File

@ -119,7 +119,15 @@ module JamRuby
end
def liker_count
return 0
return self.likers.size
end
def like_count
return self.likes.size
end
def band_like_count
return self.band_likes.size
end
def follower_count
@ -127,7 +135,11 @@ module JamRuby
end
def following_count
return self.followings.size + self.band_followings.size
return self.followings.size
end
def band_following_count
return self.band_followings.size
end
def favorite_count
@ -175,6 +187,32 @@ module JamRuby
UserMailer.password_changed(self).deliver
end
def self.band_index(user_id)
bands = Band.joins(:band_musicians)
.where(:bands_musicians => {:user_id => "#{user_id}"})
return bands
end
def self.recording_index(current_user, user_id)
hide_private = false
# hide private recordings from anyone but the current user
if current_user.id != user_id
hide_private = true
end
if hide_private
recordings = Recording.joins(:musician_recordings)
.where(:musicians_recordings => {:user_id => "#{user_id}"}, :public => true)
else
recordings = Recording.joins(:musician_recordings)
.where(:musicians_recordings => {:user_id => "#{user_id}"})
end
return recordings
end
# helper method for creating / updating a User
def self.save(id, updater_id, first_name, last_name, email, password, password_confirmation, musician, gender,