Class: Asset

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/asset.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.count_for_labels(filter) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/asset.rb', line 30

def self.count_for_labels(filter)
  options = {:include => [:labelings], :group => "label_id"}
  unless filter.empty?
    options[:conditions] = "assets.id IN(
        SELECT DISTINCT assets.id 
          FROM assets 
            LEFT OUTER JOIN classifications ON (assets.id = classifications.asset_id) 
            LEFT OUTER JOIN labelings ON (labelings.classification_id=classifications.id) 
          WHERE (#{filter.to_condition}) 
          GROUP BY assets.id 
        HAVING COUNT(label_id)=#{filter.size})"
        filter.to_condition
  end
  count options
end

.filter(filter) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'app/models/asset.rb', line 20

def self.filter(filter)
  options = {:select => "assets.*", :order => "name"}
  unless filter.empty?
    options[:joins] = "LEFT OUTER JOIN labelings ON labelings.classification_id=classifications.id"
    options[:conditions] = filter.to_condition
    options[:group] = "assets.id HAVING COUNT(label_id)=#{filter.size}"
  end
  all options
end

Instance Method Details

#publish=(test) ⇒ Object



13
14
# File 'app/models/asset.rb', line 13

def publish=(test)
end

#publishedObject



17
18
19
# File 'app/models/asset.rb', line 17

def published
  1
end

#published=(test) ⇒ Object



15
16
# File 'app/models/asset.rb', line 15

def published=(test)
end

#put_on_trayObject



46
47
48
49
50
# File 'app/models/asset.rb', line 46

def put_on_tray
  return if user.nil?

  tray_positions.create(:user_id => user.id, :asset_id => id, :position => user.tray_positions.maximum(:position) ? user.tray_positions.maximum(:position)+1 : 1)
end