bsw@1735: Survey = mondelefant.new_class() bsw@1735: Survey.table = 'survey' bsw@1735: bsw@1735: Survey:add_reference{ bsw@1735: mode = '1m', bsw@1735: to = "SurveyQuestion", bsw@1735: this_key = 'id', bsw@1735: that_key = 'survey_id', bsw@1735: ref = 'questions', bsw@1735: back_ref = 'survey', bsw@1735: default_order = 'position' bsw@1735: } bsw@1735: bsw@1735: bsw@1735: local new_selector = Survey.new_selector bsw@1735: bsw@1735: function Survey:new_selector() bsw@1735: local selector = new_selector(self) bsw@1735: selector:add_field("CASE WHEN (open_until NOTNULL AND open_until > now()) THEN open_until - now() ELSE NULL END", "time_left") bsw@1735: return selector bsw@1735: end bsw@1735: bsw@1735: function Survey:get_open() bsw@1735: return self:new_selector() bsw@1735: :add_where("open_from < now() and open_until > now()") bsw@1735: :optional_object_mode() bsw@1735: :exec() bsw@1735: end bsw@1735: bsw@1735: function Survey.object_get:open() bsw@1735: if self.open_from < atom.timestamp:get_current() and self.open_until > atom.timestamp:get_current() then bsw@1735: return true bsw@1735: end bsw@1735: return false bsw@1735: end