Sha256: 3d8d11744fd28bd11fb290343a8c32f679ecb3365e76620358485f9cbc7e676e

Contents?: true

Size: 909 Bytes

Versions: 1

Compression:

Stored size: 909 Bytes

Contents

# coding: utf-8
class Formily::Submit < ActiveRecord::Base

  self.table_name = 'formily_submits'

  has_paper_trail

  belongs_to :form
  has_many :input_values, foreign_key: :submit_id, class_name: 'Formily::InputValue', dependent: :destroy

  validates :form_id, presence: true
  validates :resource_id, presence: true
  validates :resource_type, presence: true

  STATES = {
    0 => 'Not Started',
    1 => 'In Progress',
    2 => 'Complete'
  }

  def is_complete?
    self.state == 2
  end

  def data
    ids = self.form.inputs.map do |i|
      if i.try(:inputs)
        i.inputs.map(&:id)
      else
        i.id
      end
    end

    values = self.input_values.to_a

    ids.map do |i|

      if i.is_a?(Array)
        values.select{|x| i.include?(x.input_id)}.map(&:get_value).join(', ')
      else
        values.select{|x| x.input_id == i}.first.get_value rescue ''
      end

    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
formily-0.0.5.5.7 app/models/formily/submit.rb