liquid_feedback_frontend
diff model/opinion.lua @ 1649:4188405c2425
Rework of suggestion views
| author | bsw |
|---|---|
| date | Thu Feb 11 15:48:02 2021 +0100 (2021-02-11) |
| parents | 3bfb2fcf7ab9 |
| children |
line diff
1.1 --- a/model/opinion.lua Thu Feb 11 15:45:56 2021 +0100 1.2 +++ b/model/opinion.lua Thu Feb 11 15:48:02 2021 +0100 1.3 @@ -33,3 +33,63 @@ 1.4 :optional_object_mode() 1.5 :exec() 1.6 end 1.7 + 1.8 + 1.9 +function Opinion:update(suggestion_id, member_id, degree, fulfilled) 1.10 + 1.11 + local opinion = Opinion:by_pk(member_id, suggestion_id) 1.12 + local suggestion = Suggestion:by_id(suggestion_id) 1.13 + 1.14 + if not suggestion then 1.15 + slot.put_into("error", _"This suggestion has been meanwhile deleted") 1.16 + return false 1.17 + end 1.18 + 1.19 + -- TODO important m1 selectors returning result _SET_! 1.20 + local issue = suggestion.initiative:get_reference_selector("issue"):for_share():single_object_mode():exec() 1.21 + 1.22 + if issue.closed then 1.23 + slot.put_into("error", _"This issue is already closed.") 1.24 + return false 1.25 + elseif issue.fully_frozen then 1.26 + slot.put_into("error", _"Voting for this issue has already begun.") 1.27 + return false 1.28 + elseif 1.29 + (issue.half_frozen and issue.phase_finished) or 1.30 + (not issue.accepted and issue.phase_finished) 1.31 + then 1.32 + slot.put_into("error", _"Current phase is already closed.") 1.33 + return false 1.34 + end 1.35 + 1.36 + if degree == 0 then 1.37 + if opinion then 1.38 + opinion:destroy() 1.39 + end 1.40 + return true 1.41 + end 1.42 + 1.43 + if degree ~= 0 and not app.session.member:has_voting_right_for_unit_id(suggestion.initiative.issue.area.unit_id) then 1.44 + return execute.view { module = "index", view = "403" } 1.45 + end 1.46 + 1.47 + if not opinion then 1.48 + opinion = Opinion:new() 1.49 + opinion.member_id = member_id 1.50 + opinion.suggestion_id = suggestion_id 1.51 + opinion.fulfilled = false 1.52 + end 1.53 + 1.54 + 1.55 + if degree ~= nil then 1.56 + opinion.degree = degree 1.57 + end 1.58 + 1.59 + if fulfilled ~= nil then 1.60 + opinion.fulfilled = fulfilled 1.61 + end 1.62 + 1.63 + opinion:save() 1.64 + return true 1.65 + 1.66 +end