OSDN Git Service

separate manifest
[pettanr/pettanr.git] / lib / locmare / list_group / list / filter.rb
1 module Locmare
2   module ListGroupModule
3     class FilterList < Base
4       attr :filter_key, :filter_item_name
5       
6       def init
7         super
8         @filter_key = @list_manifest.filter_key
9         @filter_item_name = @list_manifest.filter_item_name
10       end
11       
12       def where_condition filter_item_id
13         w = self.base_where_condition
14         w += ' and ' unless w.blank?
15         [w + @table_name + '.' + @filter_key + ' = ?', filter_item_id] 
16       end
17       
18       def include_hash
19         w = super
20         w.merge!({@filter_item_name => {} }) unless w[@filter_item_name]
21         w
22       end
23       
24       def items operators, options, offset, page_size
25         filter_item_id = options[:id]
26         @model.where(self.where_condition(filter_item_id)).includes(self.include_hash).order(self.order).offset(offset).limit(page_size)
27       end
28       
29       def count operators, options
30         filter_item_id = options[:id]
31         @model.where(self.where_condition(filter_item_id)).includes(self.include_hash).count
32       end
33       
34     end
35     
36   end
37 end