limesurvey_rails 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +23 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +42 -0
- data/app/assets/images/limesurvey_rails/.gitkeep +0 -0
- data/app/assets/javascripts/limesurvey_rails/application.js +15 -0
- data/app/assets/javascripts/limesurvey_rails/surveys.js +2 -0
- data/app/assets/stylesheets/limesurvey_rails/application.css +13 -0
- data/app/assets/stylesheets/limesurvey_rails/surveys.css +4 -0
- data/app/assets/stylesheets/scaffold.css +56 -0
- data/app/controllers/limesurvey_rails/application_controller.rb +3 -0
- data/app/controllers/limesurvey_rails/surveys_controller.rb +51 -0
- data/app/helpers/limesurvey_rails/application_helper.rb +4 -0
- data/app/helpers/limesurvey_rails/surveys_helper.rb +4 -0
- data/app/models/limesurvey_rails/no_persistence_active_model.rb +33 -0
- data/app/models/limesurvey_rails/survey.rb +151 -0
- data/app/models/limesurvey_rails/survey_participation.rb +78 -0
- data/app/views/limesurvey_rails/surveys/_form.html.haml +16 -0
- data/app/views/limesurvey_rails/surveys/edit.html.haml +7 -0
- data/app/views/limesurvey_rails/surveys/index.html.haml +21 -0
- data/app/views/limesurvey_rails/surveys/new.html.haml +5 -0
- data/app/views/limesurvey_rails/surveys/show.html.haml +12 -0
- data/config/locales/en.yml +2 -0
- data/config/locales/it.yml +15 -0
- data/config/routes.rb +7 -0
- data/db/migrate/20140130110450_create_limesurvey_rails_survey_participations.rb +11 -0
- data/lib/limesurvey_rails.rb +10 -0
- data/lib/limesurvey_rails/configuration.rb +31 -0
- data/lib/limesurvey_rails/engine.rb +21 -0
- data/lib/limesurvey_rails/exceptions.rb +7 -0
- data/lib/limesurvey_rails/limesurvey_rails.rb +86 -0
- data/lib/limesurvey_rails/participant.rb +86 -0
- data/lib/limesurvey_rails/version.rb +3 -0
- data/limesurvey_rails.gemspec +30 -0
- data/script/rails +8 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/test_model.rb +7 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +65 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +7 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +38 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20140130103310_create_test_models.rb +12 -0
- data/spec/dummy/db/schema.rb +34 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/spec/factories/test_models.rb +10 -0
- data/spec/factories/limesurvey_rails_survey_participations.rb +9 -0
- data/spec/factories/limesurvey_rails_surveys.rb +8 -0
- data/spec/limesurvey_rails_spec.rb +97 -0
- data/spec/models/limesurvey_rails/participant_spec.rb +174 -0
- data/spec/models/limesurvey_rails/survey_participations_spec.rb +113 -0
- data/spec/models/limesurvey_rails/survey_spec.rb +222 -0
- data/spec/spec_helper.rb +77 -0
- data/spec/support/shared_examples.rb +56 -0
- data/spec/support/test_limesurvey_constants.rb +26 -0
- data/spec/support/utils.rb +47 -0
- metadata +286 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OWUwNmEyNGI1YWJhNTU5MDNlMTc5NzFhNDhlMDdkMjE3MTM1YmIyNQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NTc5Y2I1NmM3NzUyZTU0NTdiODA4MWFmZTAwYzZkZTk2OWNjN2Y5YQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MTVhZmQxZGY4ZmJmODY3MGM4NjgyOWYzNTdmZTEwZWQ1NzgyMGZjYjk2ZDM1
|
10
|
+
NDI0MjU1NDQ2MWJiM2JiYmE1YWQ5ZDA0NDRjYmNiNmJiYjViMTYzMjBmZWRh
|
11
|
+
ZTQ3OWVmOWFiM2UzMTJhYmI5NTFmYWMzYzE1ZGM3YzJkNDFhMGU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NWNjMzBmMTEyY2M1NzkyMDg2OTVlMDcyNWI2YTI0OGYwZmQ1NjhkZTRkZGE5
|
14
|
+
NmZmNDhjOWQ1YzlkMmI3ZDMzNGExMjNhODkzMzI3NDg1Mzk3ZTdlZTA4OWRl
|
15
|
+
ZDMwMWE2MjUwM2RlOGQ5M2VkYTg4ZTVlODhlMzAxYjBjODU4MWY=
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
.ruby-version
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 masciugo
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# LimesurveyRails
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'limesurvey_rails'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install limesurvey_rails
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/limesurvey_rails/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# tasks for gem managment by bundler:
|
2
|
+
# rake build # Build limesurvey_rails-1.1.0.gem into the pkg directory
|
3
|
+
# rake install # Build and install limesurvey_rails-1.1.0.gem into system gems
|
4
|
+
# rake release # Create tag v1.1.0 and build and push limesurvey_rails-1.1.0.gem to Rubygems
|
5
|
+
require "bundler/gem_tasks"
|
6
|
+
|
7
|
+
# check for missing gems
|
8
|
+
begin
|
9
|
+
Bundler.setup(:default, :development)
|
10
|
+
rescue Bundler::BundlerError => e
|
11
|
+
$stderr.puts e.message
|
12
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
13
|
+
exit e.status_code
|
14
|
+
end
|
15
|
+
|
16
|
+
# load tasks from dummy application
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
###### RSpec stuff
|
21
|
+
require 'rspec/core'
|
22
|
+
require 'rspec/core/rake_task'
|
23
|
+
|
24
|
+
desc "Run all specs in spec directory (excluding plugin specs) or the ones tagged by provided tag"
|
25
|
+
RSpec::Core::RakeTask.new(:spec, :tag, :seed) do |t, task_args|
|
26
|
+
Rake::Task['app:db:test:prepare'].invoke
|
27
|
+
t.rspec_opts = ''
|
28
|
+
t.rspec_opts += " --tag #{task_args[:tag]}" unless task_args[:tag].blank?
|
29
|
+
t.rspec_opts += " --seed #{task_args[:seed]}" unless task_args[:seed].blank?
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "Run specfiles specified by pattern with optional seed"
|
33
|
+
RSpec::Core::RakeTask.new(:specfile, :pattern, :seed) do |t, task_args|
|
34
|
+
Rake::Task['app:db:test:prepare'].invoke
|
35
|
+
t.pattern = task_args[:pattern] unless task_args[:pattern].nil?
|
36
|
+
t.rspec_opts = ''
|
37
|
+
t.rspec_opts += " --seed #{task_args[:seed]}" unless task_args[:seed].blank?
|
38
|
+
# t.rspec_opts += " --fail-fast" # Making RSpec stop operation immediately after failing
|
39
|
+
end
|
40
|
+
###### end of RSpec stuff
|
41
|
+
|
42
|
+
task :default => :spec
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,56 @@
|
|
1
|
+
body { background-color: #fff; color: #333; }
|
2
|
+
|
3
|
+
body, p, ol, ul, td {
|
4
|
+
font-family: verdana, arial, helvetica, sans-serif;
|
5
|
+
font-size: 13px;
|
6
|
+
line-height: 18px;
|
7
|
+
}
|
8
|
+
|
9
|
+
pre {
|
10
|
+
background-color: #eee;
|
11
|
+
padding: 10px;
|
12
|
+
font-size: 11px;
|
13
|
+
}
|
14
|
+
|
15
|
+
a { color: #000; }
|
16
|
+
a:visited { color: #666; }
|
17
|
+
a:hover { color: #fff; background-color:#000; }
|
18
|
+
|
19
|
+
div.field, div.actions {
|
20
|
+
margin-bottom: 10px;
|
21
|
+
}
|
22
|
+
|
23
|
+
#notice {
|
24
|
+
color: green;
|
25
|
+
}
|
26
|
+
|
27
|
+
.field_with_errors {
|
28
|
+
padding: 2px;
|
29
|
+
background-color: red;
|
30
|
+
display: table;
|
31
|
+
}
|
32
|
+
|
33
|
+
#error_explanation {
|
34
|
+
width: 450px;
|
35
|
+
border: 2px solid red;
|
36
|
+
padding: 7px;
|
37
|
+
padding-bottom: 0;
|
38
|
+
margin-bottom: 20px;
|
39
|
+
background-color: #f0f0f0;
|
40
|
+
}
|
41
|
+
|
42
|
+
#error_explanation h2 {
|
43
|
+
text-align: left;
|
44
|
+
font-weight: bold;
|
45
|
+
padding: 5px 5px 5px 15px;
|
46
|
+
font-size: 12px;
|
47
|
+
margin: -7px;
|
48
|
+
margin-bottom: 0px;
|
49
|
+
background-color: #c00;
|
50
|
+
color: #fff;
|
51
|
+
}
|
52
|
+
|
53
|
+
#error_explanation ul li {
|
54
|
+
font-size: 12px;
|
55
|
+
list-style: square;
|
56
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require_dependency "limesurvey_rails/application_controller"
|
2
|
+
|
3
|
+
module LimesurveyRails
|
4
|
+
class SurveysController < ApplicationController
|
5
|
+
# GET /surveys
|
6
|
+
def index
|
7
|
+
@surveys = Survey.all
|
8
|
+
end
|
9
|
+
|
10
|
+
# PUT /surveys/1/invite
|
11
|
+
def invite_participants
|
12
|
+
@survey = Survey.find(params[:id])
|
13
|
+
@survey.invite_participants!
|
14
|
+
redirect_to surveys_url
|
15
|
+
end
|
16
|
+
|
17
|
+
# GET /surveys/1
|
18
|
+
def show
|
19
|
+
redirect_to Survey.url_for(params[:id])
|
20
|
+
end
|
21
|
+
|
22
|
+
# GET /surveys/new
|
23
|
+
def new
|
24
|
+
@survey = Survey.new
|
25
|
+
end
|
26
|
+
|
27
|
+
# GET /surveys/1/edit
|
28
|
+
def edit
|
29
|
+
redirect_to Survey.url_for(params[:id])
|
30
|
+
end
|
31
|
+
|
32
|
+
# POST /surveys
|
33
|
+
def create
|
34
|
+
@survey = Survey.new(params[:survey])
|
35
|
+
respond_to do |format|
|
36
|
+
if @survey.valid? and Survey.add(@survey.title,@survey.language)
|
37
|
+
format.html { redirect_to surveys_url, notice: 'Survey was successfully created.' }
|
38
|
+
else
|
39
|
+
format.html { render action: "new" }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# DELETE /surveys/1
|
45
|
+
def destroy
|
46
|
+
@survey = Survey.find(params[:id])
|
47
|
+
@survey.destroy
|
48
|
+
redirect_to surveys_url
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module LimesurveyRails
|
2
|
+
class NoPersistenceActiveModel
|
3
|
+
include ActiveModel::MassAssignmentSecurity
|
4
|
+
include ActiveModel::Validations
|
5
|
+
include ActiveModel::Conversion
|
6
|
+
include ActiveModel::AttributeMethods
|
7
|
+
extend ActiveModel::Naming
|
8
|
+
|
9
|
+
# http://stackoverflow.com/questions/8835215/how-to-handle-translations-for-an-activemodel
|
10
|
+
class << self
|
11
|
+
def i18n_scope
|
12
|
+
:activerecord
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(params = {})
|
17
|
+
params.each do |name, value|
|
18
|
+
send("#{name}=", value)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def persisted?
|
23
|
+
false
|
24
|
+
end
|
25
|
+
|
26
|
+
# http://api.rubyonrails.org/classes/ActiveModel/AttributeMethods.html
|
27
|
+
def attributes
|
28
|
+
if defined?(self.class::ALL_ATTRIBUTES)
|
29
|
+
self.class::ALL_ATTRIBUTES.inject({}){|memo,a| memo.merge( a => send(a) )}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
module LimesurveyRails
|
2
|
+
|
3
|
+
class Survey < NoPersistenceActiveModel
|
4
|
+
|
5
|
+
LIST_SURVEYS_ATTRIBUTES = %w{ sid surveyls_title startdate expires active }
|
6
|
+
|
7
|
+
GET_SUMMARY_RESPONSES_ATTRIBUTES = %w{ completed_responses incomplete_responses full_responses }
|
8
|
+
GET_SUMMARY_TOKENS_ATTRIBUTES = %w{ token_count token_invalid token_sent token_opted_out token_completed }
|
9
|
+
GET_SUMMARY_ATTRIBUTES = GET_SUMMARY_RESPONSES_ATTRIBUTES + GET_SUMMARY_TOKENS_ATTRIBUTES
|
10
|
+
GET_SURVEY_PROPERTY_ATTRIBUTES = %w{ attributedescriptions savetimings allowprev tokenanswerspersistence showgroupinfo showwelcome owner_id template printanswers assessments shownoanswer showprogress admin language ipaddr usecaptcha showqnumcode allowjumps active additional_languages refurl usetokens bouncetime navigationdelay expires datestamp datecreated bounce_email bounceprocessing nokeyboard startdate usecookie publicstatistics bounceaccounttype alloweditaftercompletion adminemail allowregister publicgraphs emailresponseto bounceaccounthost googleanalyticsstyle anonymized allowsave listpublic emailnotificationto bounceaccountpass googleanalyticsapikey faxto autonumber_start htmlemail tokenlength bounceaccountencryption format autoredirect sendconfirmation showxquestions bounceaccountuser }
|
11
|
+
GET_LANGUAGE_PROPERTIES_ATTRIBUTES = %w{ surveyls_survey_id surveyls_url surveyls_email_register_subj email_admin_notification_subj surveyls_language surveyls_urldescription surveyls_email_register email_admin_notification surveyls_title surveyls_email_invite_subj surveyls_email_confirm_subj email_admin_responses_subj surveyls_description surveyls_email_invite surveyls_email_confirm email_admin_responses surveyls_welcometext surveyls_email_remind_subj surveyls_dateformat surveyls_numberformat surveyls_endtext surveyls_email_remind surveyls_attributecaptions }
|
12
|
+
|
13
|
+
ALL_ATTRIBUTES = (GET_SUMMARY_ATTRIBUTES | GET_SURVEY_PROPERTY_ATTRIBUTES | GET_LANGUAGE_PROPERTIES_ATTRIBUTES ).sort.unshift('id')
|
14
|
+
|
15
|
+
attr_accessor *ALL_ATTRIBUTES
|
16
|
+
|
17
|
+
alias_attribute :title, :surveyls_title
|
18
|
+
alias_attribute :created_at, :datecreated
|
19
|
+
|
20
|
+
validates_presence_of :surveyls_title
|
21
|
+
validates_presence_of :language
|
22
|
+
|
23
|
+
def self.all(lang = nil)
|
24
|
+
LimesurveyRails.list_surveys(LimesurveyRails.configuration.username).map{|s| build(s['sid'],lang) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.find(survey_id,lang = nil)
|
28
|
+
build(survey_id,lang)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.add(title,lang)
|
32
|
+
id = LimesurveyRails.add_survey(nil,title,lang)
|
33
|
+
LimesurveyRails.activate_tokens(id,[1])
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.new_survey_url
|
37
|
+
LimesurveyRails.configuration.base_url + '/admin/survey/sa/newsurvey'
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.url_for(survey_id)
|
41
|
+
LimesurveyRails.configuration.base_url + "/admin/survey/sa/view/surveyid/#{survey_id}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def destroy
|
45
|
+
num_rows_to_delete = SurveyParticipation.for_survey(id).size
|
46
|
+
LimesurveyRails.delete_survey(id) and num_rows_to_delete == SurveyParticipation.for_survey(id).delete_all
|
47
|
+
end
|
48
|
+
|
49
|
+
def active?
|
50
|
+
case active
|
51
|
+
when 'Y'
|
52
|
+
true
|
53
|
+
when 'N'
|
54
|
+
false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def status
|
59
|
+
active? ? 'active' : 'not active'
|
60
|
+
end
|
61
|
+
|
62
|
+
def description
|
63
|
+
"#{id} - #{title} [#{status}]"
|
64
|
+
end
|
65
|
+
|
66
|
+
# def ==(comparison_object)
|
67
|
+
# comparison_object.equal?(self) ||
|
68
|
+
# (comparison_object.instance_of?(self.class) &&
|
69
|
+
# comparison_object.id == id &&
|
70
|
+
# !comparison_object.new_record?)
|
71
|
+
# end
|
72
|
+
|
73
|
+
def url
|
74
|
+
Survey.url_for(id)
|
75
|
+
end
|
76
|
+
|
77
|
+
def inspect
|
78
|
+
"#< #{self.class} id=#{id} title='#{title}' >"
|
79
|
+
end
|
80
|
+
|
81
|
+
def to_s
|
82
|
+
"#{title} [#{id}]"
|
83
|
+
end
|
84
|
+
|
85
|
+
def participants
|
86
|
+
participations = SurveyParticipation.for_survey(id)
|
87
|
+
raise InconsistentParticipantsError if participations.map(&:token_id).sort != LimesurveyRails.list_participants(id).map{|p| p['tid']}.sort
|
88
|
+
participations.map(&:participant)
|
89
|
+
end
|
90
|
+
|
91
|
+
def add_participant!(participant)
|
92
|
+
if participant.class.is_a_limesurvey_participant_class?
|
93
|
+
SurveyParticipation.create!(:participant_id => participant.id, :survey_id => id)
|
94
|
+
return true
|
95
|
+
else
|
96
|
+
raise WrongArgumentError, "expexted limesurvey participant enabled object, got #{participant.class}"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def add_participant(participant)
|
101
|
+
add_participant!(participant) rescue false
|
102
|
+
end
|
103
|
+
|
104
|
+
def remove_participant!(participant)
|
105
|
+
if participant.class.is_a_limesurvey_participant_class?
|
106
|
+
ss = SurveyParticipation.find_by_participant_id_and_survey_id(participant.id,id)
|
107
|
+
ss.destroy
|
108
|
+
return true
|
109
|
+
else
|
110
|
+
raise WrongArgumentError, "expected limesurvey participant enabled object, got #{participant.class}"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def remove_participant(participant)
|
115
|
+
remove_participant!(participant) rescue false
|
116
|
+
end
|
117
|
+
|
118
|
+
def invite_participants!
|
119
|
+
res = LimesurveyRails.invite_participants(id)
|
120
|
+
status = res.delete('status')
|
121
|
+
if status.end_with?('No candidate tokens')
|
122
|
+
[0,token_count]
|
123
|
+
elsif status.end_with?('left to send')
|
124
|
+
[res.size, status.split(' ').first.to_i]
|
125
|
+
else
|
126
|
+
raise
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def reload
|
131
|
+
Survey.build(id)
|
132
|
+
end
|
133
|
+
|
134
|
+
private
|
135
|
+
|
136
|
+
def self.build(survey_id, lang = nil)
|
137
|
+
all_attributes = {id: survey_id}
|
138
|
+
all_attributes.merge!(LimesurveyRails.get_survey_properties(survey_id,GET_SURVEY_PROPERTY_ATTRIBUTES))
|
139
|
+
|
140
|
+
# if all_attributes['active'] == 'Y'
|
141
|
+
all_attributes.merge!(LimesurveyRails.get_summary(survey_id,'all'))
|
142
|
+
# else
|
143
|
+
# GET_SUMMARY_TOKENS_ATTRIBUTES.each{|a| all_attributes[a] = LimesurveyRails.get_summary(survey_id,a) rescue nil }
|
144
|
+
# end
|
145
|
+
all_attributes.merge!(LimesurveyRails.get_language_properties(survey_id,GET_LANGUAGE_PROPERTIES_ATTRIBUTES,lang || all_attributes['language']))
|
146
|
+
new(all_attributes)
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|