app/models/c80_estate/area.rb in c80_estate-0.1.0 vs app/models/c80_estate/area.rb in c80_estate-0.1.0.1
- old
+ new
@@ -1,10 +1,11 @@
module C80Estate
class Area < ActiveRecord::Base
belongs_to :property
belongs_to :atype
belongs_to :owner, :polymorphic => true
+ belongs_to :assigned_person, :polymorphic => true
has_many :item_props, :dependent => :destroy
accepts_nested_attributes_for :item_props,
:reject_if => lambda { |attributes|
# puts "attributes:: #{attributes}"
# attributes:: {"value"=>"", "prop_name_id"=>""}
@@ -20,7 +21,52 @@
},
:allow_destroy => true
has_many :comments, :dependent => :destroy # площадь можно прокомментировать
has_and_belongs_to_many :astatuses, # единственный статус: либо занята, либо свободна
:join_table => 'c80_estate_areas_astatuses'
+
+ def self.all_areas
+ self.all
+ end
+
+ def self.free_areas
+ self.joins(:astatuses).where(:c80_estate_astatuses => { tag: 'free'})
+ end
+
+ def self.busy_areas
+ self.joins(:astatuses).where(:c80_estate_astatuses => { tag: 'busy'})
+ end
+
+ def atype_title
+ res = "-"
+ if atype.present?
+ res = atype.title
+ end
+ res
+ end
+
+ def property_title
+ res = "-"
+ if property.present?
+ res = property.title
+ end
+ res
+ end
+
+ def astatus_title
+ res = "-"
+ if astatuses.count > 0
+ res = astatuses.first.title
+ end
+ res
+ end
+
+ def assigned_person_title
+ res = "-"
+ if assigned_person.present?
+ res = assigned_person.email
+ end
+ res
+ end
+
end
end
\ No newline at end of file