Class: Banner

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#placementsObject



23
24
25
# File 'app/models/banner.rb', line 23

def placements
  @placements || banner_placements
end

Class Method Details

.find_activeObject



55
56
57
58
59
60
61
# File 'app/models/banner.rb', line 55

def self.find_active
  @banners = []
  self.find(:all, :order => "name asc").each do |banner|
    @banners << banner if banner.active?
  end
  @banners
end

.find_active_by_pagesObject



63
64
65
# File 'app/models/banner.rb', line 63

def self.find_active_by_pages
  self.find_active.sort { |a,b| a.pages[0].breadcrumb <=> b.pages[0].breadcrumb }
end

.find_all_by_pagesObject



51
52
53
# File 'app/models/banner.rb', line 51

def self.find_all_by_pages
  self.find_active_by_pages.concat(self.find_inactive)
end

.find_inactiveObject



67
68
69
70
71
72
73
# File 'app/models/banner.rb', line 67

def self.find_inactive
  @banners = []
  self.find(:all, :order => "name asc").each do |banner|
    @banners << banner if banner.inactive?
  end
  @banners
end

.total_active_countObject



79
80
81
# File 'app/models/banner.rb', line 79

def self.total_active_count
  self.find_active.size
end

.total_countObject



75
76
77
# File 'app/models/banner.rb', line 75

def self.total_count
  self.find(:all).size
end

.total_inactive_countObject



83
84
85
# File 'app/models/banner.rb', line 83

def self.total_inactive_count
  self.find_inactive.size
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'app/models/banner.rb', line 27

def active?
  banner_placements.size > 0
end

#inactive?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'app/models/banner.rb', line 31

def inactive?
  ! active?
end

#protected?Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/banner.rb', line 35

def protected?
  if name.downcase.include?('protected')
    true
  else
    protected_banners = []
    if Radiant::Config['admin.protected_banners']
      protected_banners = Radiant::Config['admin.protected_banners'].split(',').map { |b| b.downcase.strip }
    end
    protected_banners.include?(name.downcase)
  end
end

#remove_all_placements!Object



87
88
89
# File 'app/models/banner.rb', line 87

def remove_all_placements!
  banner_placements.each { |placement| placement.destroy }
end

#unprotected?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'app/models/banner.rb', line 47

def unprotected?
  ! protected?
end