Sha256: 3d5ccf13059fd6f1c947ed760deafc7b24543c1b3abd9ed98f0fda78f26780fe

Contents?: true

Size: 1.87 KB

Versions: 3

Compression:

Stored size: 1.87 KB

Contents

module C80Estate
  class Property < ActiveRecord::Base
    belongs_to :atype
    belongs_to :owner, :polymorphic => true
    belongs_to :assigned_person, :polymorphic => true
    has_many :item_props, :dependent => :destroy
    has_many :pphotos, :dependent => :destroy   # одна или несколько фоток
    accepts_nested_attributes_for :pphotos,
                                  :reject_if => lambda { |attributes|
                                    !attributes.present?
                                  },
                                  :allow_destroy => true
    has_many :plogos, :dependent => :destroy   # одна или несколько фоток
    accepts_nested_attributes_for :plogos,
                                  :reject_if => lambda { |attributes|
                                    !attributes.present?
                                  },
                                  :allow_destroy => true
    has_many :areas, :dependent => :destroy
    has_many :comments, :dependent => :destroy
    has_many :sevents, :dependent => :destroy
    has_many :pstats, :dependent => :destroy

    def assigned_person_title
      res = "-"
      if assigned_person.present?
        res = assigned_person.email
      end
      res
    end

    def logo_path
      url = 'property_default_logo.png'
      if plogos.count > 0
        url = plogos.first.image.thumb256
      end
      url
    end

    def main_image_url
      url = 'no_thumb.png'
      if pphotos.count > 0
        url = pphotos.first.image.thumb512
      end
      url
    end

    def last_updater
      pstats.last.sevent.auser.email
    end

    def square_value
      sum = 0
      areas.all.each do |area|
        sum += area.square_value
      end
      sum
    end

    def power_price_value
      sum = 0
      areas.all.each do |area|
        sum += area.power_price_value
      end
      sum
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
c80_estate-0.1.0.17 app/models/c80_estate/property.rb
c80_estate-0.1.0.16 app/models/c80_estate/property.rb
c80_estate-0.1.0.15 app/models/c80_estate/property.rb