liquid_feedback_frontend
annotate model/survey.lua @ 1847:bcfa66dd8980
Added version numbers
| author | bsw | 
|---|---|
| date | Thu Feb 03 16:07:59 2022 +0100 (2022-02-03) | 
| parents | 5a8a09119865 | 
| children | 
| rev | line source | 
|---|---|
| bsw@1735 | 1 Survey = mondelefant.new_class() | 
| bsw@1735 | 2 Survey.table = 'survey' | 
| bsw@1735 | 3 | 
| bsw@1735 | 4 Survey:add_reference{ | 
| bsw@1735 | 5 mode = '1m', | 
| bsw@1735 | 6 to = "SurveyQuestion", | 
| bsw@1735 | 7 this_key = 'id', | 
| bsw@1735 | 8 that_key = 'survey_id', | 
| bsw@1735 | 9 ref = 'questions', | 
| bsw@1735 | 10 back_ref = 'survey', | 
| bsw@1735 | 11 default_order = 'position' | 
| bsw@1735 | 12 } | 
| bsw@1735 | 13 | 
| bsw@1735 | 14 | 
| bsw@1735 | 15 local new_selector = Survey.new_selector | 
| bsw@1735 | 16 | 
| bsw@1735 | 17 function Survey:new_selector() | 
| bsw@1735 | 18 local selector = new_selector(self) | 
| bsw@1735 | 19 selector:add_field("CASE WHEN (open_until NOTNULL AND open_until > now()) THEN open_until - now() ELSE NULL END", "time_left") | 
| bsw@1735 | 20 return selector | 
| bsw@1735 | 21 end | 
| bsw@1735 | 22 | 
| bsw@1735 | 23 function Survey:get_open() | 
| bsw@1735 | 24 return self:new_selector() | 
| bsw@1735 | 25 :add_where("open_from < now() and open_until > now()") | 
| bsw@1735 | 26 :optional_object_mode() | 
| bsw@1735 | 27 :exec() | 
| bsw@1735 | 28 end | 
| bsw@1735 | 29 | 
| bsw@1735 | 30 function Survey.object_get:open() | 
| bsw@1735 | 31 if self.open_from < atom.timestamp:get_current() and self.open_until > atom.timestamp:get_current() then | 
| bsw@1735 | 32 return true | 
| bsw@1735 | 33 end | 
| bsw@1735 | 34 return false | 
| bsw@1735 | 35 end |