require 'uns_core/has_permissions'

module UnsPhoto
  class Album < ActiveRecord::Base
    include UnsCore::HasPermissions
    include UnsCore::IsSearchable
    include UnsCore::HasCases

    searchable_terms(:name)
    searchable_date(:updated_at)

    has_and_belongs_to_many :photos
    validates_presence_of :name

    def photos_for_user(a_usr)
      self.photos.select do |p|
        ((a_usr != nil) && (p.user_id == a_usr.id)) || 
        p.all_access? ||
        (p.vip_only? && a_usr.vip?)
      end
    end
  end
end
