liquid_feedback_frontend
diff model/survey.lua @ 1735:5a8a09119865
Added survey feature
author | bsw |
---|---|
date | Fri Oct 08 00:09:23 2021 +0200 (2021-10-08) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/model/survey.lua Fri Oct 08 00:09:23 2021 +0200 1.3 @@ -0,0 +1,35 @@ 1.4 +Survey = mondelefant.new_class() 1.5 +Survey.table = 'survey' 1.6 + 1.7 +Survey:add_reference{ 1.8 + mode = '1m', 1.9 + to = "SurveyQuestion", 1.10 + this_key = 'id', 1.11 + that_key = 'survey_id', 1.12 + ref = 'questions', 1.13 + back_ref = 'survey', 1.14 + default_order = 'position' 1.15 +} 1.16 + 1.17 + 1.18 +local new_selector = Survey.new_selector 1.19 + 1.20 +function Survey:new_selector() 1.21 + local selector = new_selector(self) 1.22 + selector:add_field("CASE WHEN (open_until NOTNULL AND open_until > now()) THEN open_until - now() ELSE NULL END", "time_left") 1.23 + return selector 1.24 +end 1.25 + 1.26 +function Survey:get_open() 1.27 + return self:new_selector() 1.28 + :add_where("open_from < now() and open_until > now()") 1.29 + :optional_object_mode() 1.30 + :exec() 1.31 +end 1.32 + 1.33 +function Survey.object_get:open() 1.34 + if self.open_from < atom.timestamp:get_current() and self.open_until > atom.timestamp:get_current() then 1.35 + return true 1.36 + end 1.37 + return false 1.38 +end