Class: City

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
app/models/city.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clearObject



72
73
74
75
76
# File 'app/models/city.rb', line 72

def self.clear
  if Rails.env.test?
    City.all.each { |r| r.remove }
  end
end

.featureObject



53
54
55
# File 'app/models/city.rb', line 53

def self.feature
  where( :is_feature => true )
end

.for_homepageObject



97
98
99
100
101
102
103
# File 'app/models/city.rb', line 97

def self.for_homepage
  cities = City.all.order_by( :name => :asc )
  cities = cities.delete_if do |c|
    ( false == c.is_feature ) && ( 0 == c.galleries.length ) && ( 0 == c.reports.length )
  end
  return cities
end

.listObject



61
62
63
64
65
# File 'app/models/city.rb', line 61

def self.list
  out = self.order_by( :name => :asc )
  # no_city = City.where( :cityname => 'no_city' ).first || City.create( :cityname => 'no_city', :name => 'No City' )
  [['', nil]] + out.map { |item| [ item.name, item.id ] }
end

.list_citynames(lang = 'en') ⇒ Object



67
68
69
70
# File 'app/models/city.rb', line 67

def self.list_citynames lang = 'en'
  out = self.order_by( :name => :asc )
  [['', nil]] + out.map { |item| [ item['name_'+lang], item.cityname ] }
end

.n_featuresObject



78
79
80
# File 'app/models/city.rb', line 78

def self.n_features
  4
end

.non_featureObject



57
58
59
# File 'app/models/city.rb', line 57

def self.non_feature
  where( :is_feature => false )
end

Instance Method Details

#add_newsitem(doc) ⇒ Object



109
110
111
112
113
114
# File 'app/models/city.rb', line 109

def add_newsitem doc
  # puts! self.newsitems, "city newsitems are"
  if 'Video' == doc.class.name
    self.newsitems << Newsitem.new({ :descr => '', :username => '', :video => doc })
  end
end

#j_reports(args = {}) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/models/city.rb', line 82

def j_reports args = {}
  out =  []
  self.reports.each do |r| # .page( params[:reports_page] 
    rr = r.clone
    # rr[:photo_url] = r.photo.photo.url( :mini ) unless r.photo.blank?
    # rr[:photo_url] ||= '/assets/missing.png'
    rr[:username] = r.user.username
    rr.created_at = r.created_at # pretty_date( r.created_at )
    rr[:tag_name] = r.tag.name unless r.tag.blank?
    rr[:tag_name] ||= ''
    out << rr
  end
  return out
end