Class: Odania::Site

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Taggable::TagCount
Defined in:
app/models/odania/site.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Taggable::TagCount

#tag_counts_on

Instance Attribute Details

Returns the value of attribute menu_cache.



29
30
31
# File 'app/models/odania/site.rb', line 29

def menu_cache
  @menu_cache
end

Class Method Details

.get_site(host) ⇒ Object



25
26
27
# File 'app/models/odania/site.rb', line 25

def self.get_site(host)
	Odania::Site.active.where(host: host).first
end

Instance Method Details

#get_current_menu(locale) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/models/odania/site.rb', line 37

def get_current_menu(locale)
	self.menu_cache = {} if self.menu_cache.nil?
	return self.menu_cache[locale] unless self.menu_cache[locale].nil?

	language = Odania::Language.where(iso_639_1: locale).first

	current_menu = self.menus.where(language_id: language.id).first unless locale.nil? or language.nil?
	return nil if current_menu.nil?

	self.menu_cache[locale] = current_menu
	return current_menu
end

#get_languagesObject



71
72
73
74
75
76
77
# File 'app/models/odania/site.rb', line 71

def get_languages
	langs = []
	self.menus.each do |menu|
		langs << menu.language
	end
	langs
end

#get_template_nameObject



63
64
65
66
67
68
69
# File 'app/models/odania/site.rb', line 63

def get_template_name
	return '-' if self.template.blank?

	template_info = Odania.templates[self.template]
	return 'error' if template_info.nil?
	template_info[:name]
end

#validate_default_widgetObject



31
32
33
34
35
# File 'app/models/odania/site.rb', line 31

def validate_default_widget
	if !self.default_widget_id.nil? and !self.id.eql?(self.default_widget.site_id)
		errors.add(:default_widget_id, 'invalid widget')
	end
end

#validate_language_is_presentObject



57
58
59
60
61
# File 'app/models/odania/site.rb', line 57

def validate_language_is_present
	if self.default_language_id.nil?
		errors.add(:default_language_id, 'has to be set')
	end
end

#validate_template_existsObject



50
51
52
53
54
55
# File 'app/models/odania/site.rb', line 50

def validate_template_exists
	self.template = nil if ''.eql? self.template
	if !self.template.nil? and !Odania.templates.include?(self.template)
		errors.add(:template, 'invalid template')
	end
end