Class: DcPoll

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
app/models/dc_poll.rb

Overview

Schema information

Collection name: dc_poll : Polls

_id                  BSON::ObjectId       _id
created_at           Time                 created_at
updated_at           Time                 updated_at
name                 String               Unique poll name
title                String               Title for the poll
sub_text             String               Short description of the poll
pre_display          String               pre_display
operation            String               Operation performed on submit
parameters           String               Aditional parameters for operation
display              String               Select how fields are positioned on form
css                  String               CSS specific to this poll
form                 String               You can specified input items by providing form acording to rules of drgCMS form.
valid_from           DateTime             Pole is valid from
valid_to             DateTime             Pole is valid to
captcha_type         String               Catpcha type name if captcha is used
active               Mongoid::Boolean     active
created_by           BSON::ObjectId       created_by
updated_by           BSON::ObjectId       updated_by
dc_poll_items        Embedded:DcPollItem  Items for this poll

DcPoll documents are used for different questionaries and formulars which can be accessed independent or connected with DcPage documents. Entry fields can be defined as DcSimpleItem embedded structure or as DRG CMS form YAML style entered into form field.

Instance Method Summary collapse

Instance Method Details

#save_results(data) ⇒ Object

Save poll results to DcPollResults collection

Params: data : Hash : Records hash (params)



85
86
87
88
89
90
91
92
93
94
# File 'app/models/dc_poll.rb', line 85

def save_results(data)
  h = {}
  items = self.form.blank? ? self.dc_poll_items : YAML.load(self.form.gsub(' ',' '))
  items.each do |item|
    next if %w(hidden_field submit_tag link_to comment).include?(item.type)
    next if item.try(:options).match('hidden')
    h[ item['name'] ] = data[ item['name'] ]
  end
  DcPollResult.create(dc_poll_id: self.id, data: h.to_yaml)
end