Class: Movie
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Movie
- Defined in:
- lib/gimdb/model.rb
Class Method Summary (collapse)
- + (Object) get_code(what)
- + (Object) get_kind(users, kind)
- + (Object) get_list(options)
- + (Object) next
Instance Method Summary (collapse)
- - (Object) get_users(what = :to_see)
- - (Object) remove_user(user, what = :to_see)
- - (Object) set_user(user, what = :to_see)
Class Method Details
+ (Object) get_code(what)
120 121 122 123 124 125 126 127 |
# File 'lib/gimdb/model.rb', line 120 def self.get_code(what) case what.to_sym when :to_see then 0 when :seen then 1 when :favourites then 2 else nil end end |
+ (Object) get_kind(users, kind)
112 113 114 115 116 117 118 |
# File 'lib/gimdb/model.rb', line 112 def self.get_kind(users, kind) c = '' users.each { |u| c += "populars.user_id = #{u.id} OR " } c = '(' + c[0..-5] + ') AND ' unless c.empty? c += "populars.kind = #{Movie.get_code(kind)}" Movie.select('movies.*').where(c).joins(:populars).order('title ASC').group('movies.id') end |
+ (Object) get_list(options)
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/gimdb/model.rb', line 89 def self.get_list() @start = [:start] || 1 c = '' c += " AND title LIKE '%#{[:title]}%'" if [:title] if [:release_data] && [:release_data].include?(',') c += " AND year >= #{[:release_data].split(',')[0]}" c += " AND year <= #{[:release_data].split(',')[1]}" end if [:user_rating] && [:user_rating].include?(',') c += " AND rating >= #{[:user_rating].split(',')[0]}" c += " AND rating <= #{[:user_rating].split(',')[1]}" end c += " AND genre LIKE '%#{[:genre]}%'" if [:genre] c = c[5..-1] @movies = Movie.where(c).order('title ASC')#.limit(50) return @movies[@start-1..@start+48] end |
+ (Object) next
107 108 109 110 |
# File 'lib/gimdb/model.rb', line 107 def self.next @start = @start + 50 return @movies[@start-1..@start+48] || [] end |
Instance Method Details
- (Object) get_users(what = :to_see)
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/gimdb/model.rb', line 62 def get_users(what = :to_see) code = Movie.get_code(what) unless code.nil? pops = Popular.where("movie_id = ? AND kind = ?", self.id, code) return [] if pops.nil? return pops.collect{|pop| pop.user} else return [] end end |
- (Object) remove_user(user, what = :to_see)
81 82 83 84 85 86 87 |
# File 'lib/gimdb/model.rb', line 81 def remove_user(user, what = :to_see) code = Movie.get_code(what) unless code.nil? sql = "delete from populars where movie_id = #{self.id} AND user_id = #{user.id} AND kind = #{code}" ActiveRecord::Base.connection.execute(sql) end end |
- (Object) set_user(user, what = :to_see)
73 74 75 76 77 78 79 |
# File 'lib/gimdb/model.rb', line 73 def set_user(user, what = :to_see) code = Movie.get_code(what) unless code.nil? pop = Popular.new(:movie => self, :user => user, :kind => code) self.populars << pop end end |