bsw/jbe@0: Interest = mondelefant.new_class() bsw/jbe@0: Interest.table = 'interest' bsw/jbe@0: Interest.primary_key = { "issue_id", "member_id" } bsw/jbe@0: Interest:add_reference{ bsw/jbe@0: mode = 'm1', bsw/jbe@0: to = "Member", bsw/jbe@0: this_key = 'member_id', bsw/jbe@0: that_key = 'id', bsw/jbe@0: ref = 'member', bsw/jbe@0: } bsw/jbe@0: bsw/jbe@0: Interest:add_reference{ bsw/jbe@0: mode = 'm1', bsw/jbe@0: to = "Issue", bsw/jbe@0: this_key = 'issue_id', bsw/jbe@0: that_key = 'id', bsw/jbe@0: ref = 'issue', bsw/jbe@0: } bsw/jbe@0: bsw/jbe@0: function Interest:by_pk(issue_id, member_id) bsw/jbe@0: return self:new_selector() bsw/jbe@0: :add_where{ "issue_id = ? AND member_id = ?", issue_id, member_id } bsw/jbe@0: :optional_object_mode() bsw/jbe@0: :exec() bsw@1618: end bsw@1618: bsw@1618: function Interest:update(issue_id, member, interested) bsw@1618: local interest = Interest:by_pk(issue_id, member.id) bsw@1618: bsw@1618: local issue = Issue:new_selector():add_where{ "id = ?", issue_id }:for_share():single_object_mode():exec() bsw@1618: bsw@1618: if not member:has_voting_right_for_unit_id(issue.area.unit_id) then bsw@1618: return execute.view { module = "index", view = "403" } bsw@1618: end bsw@1618: bsw@1618: if issue.closed then bsw@1618: slot.put_into("error", _"This issue is already closed.") bsw@1618: return false bsw@1618: elseif issue.fully_frozen then bsw@1618: slot.put_into("error", _"Voting for this issue has already begun.") bsw@1618: return false bsw@1618: elseif bsw@1618: (issue.half_frozen and issue.phase_finished) or bsw@1618: (not issue.accepted and issue.phase_finished) bsw@1618: then bsw@1618: slot.put_into("error", _"Current phase is already closed.") bsw@1618: return false bsw@1618: end bsw@1618: bsw@1618: if interested == false then bsw@1618: if interest then bsw@1618: interest:destroy() bsw@1618: end bsw@1618: return true bsw@1618: end bsw@1618: bsw@1618: if not interest then bsw@1618: interest = Interest:new() bsw@1618: interest.issue_id = issue_id bsw@1618: interest.member_id = app.session.member_id bsw@1618: interest:save() bsw@1618: end bsw@1618: bsw@1618: return true bsw@1618: bsw@1618: end