-
Notifications
You must be signed in to change notification settings - Fork 0
Schema
Adrian Teh edited this page May 22, 2013
·
5 revisions
- activity_type_id:integer
- title:string
CiviCrm::CustomGroup.where(:extends => “Activity”, :extends_entity_column_value => 32).first.title - custom_group_id:integer
CiviCrm::CustomGroup.where(:extends => “Activity”, :extends_entity_column_value => 32).first.id
`CiviCrm::CustomField.where(:custom_group_id => survey.custom_group_id)`
- custom_field_id:integer
- survey_id:integer
- label:string
class Survey < ActiveRecord::Base
has_many :custom_fields
attr_accessible :activity_type_id
def responses
params = {
activity_type_id: self.activity_type_id,
'return.target_contact_id': 1
}
self.custom_fields.each do |f|
params["return.custom_#{custom_field_id}"] = 1
end
CiviCrm::Activity.where(params).map do |response|
Response.new(self, response)
end
end
end
class CustomField < ActiveRecord::Base
belongs_to :survey
end
class Response
attr_accessor :survey, :response
def initialize(survey, response)
@survey = survey
@response = response
end
def answers
@answers ||= begin
survey.custom_fields.map do |field|
OpenStruct.new(:label => field.label,
:answer => response.send("custom_#{ field.custom_field_id }"))
end
end
end
def contact
@contact ||= CiviCrm::Contact.where(id: response.target_contact_id)
end
end