liquid_feedback_frontend

view model/opinion.lua @ 1668:6d75df24e66e

Updated German translation
author bsw
date Sun Mar 07 09:52:36 2021 +0100 (2021-03-07)
parents 4188405c2425
children
line source
1 Opinion = mondelefant.new_class()
2 Opinion.table = 'opinion'
3 Opinion.primary_key = { "member_id", "suggestion_id" }
5 Opinion:add_reference{
6 mode = 'm1',
7 to = "Initiative",
8 this_key = 'initiative_id',
9 that_key = 'id',
10 ref = 'initiative',
11 }
13 Opinion:add_reference{
14 mode = 'm1',
15 to = "Suggestion",
16 this_key = 'suggestion_id',
17 that_key = 'id',
18 ref = 'suggestion',
19 }
21 Opinion:add_reference{
22 mode = 'm1',
23 to = "Member",
24 this_key = 'member_id',
25 that_key = 'id',
26 ref = 'member',
27 }
29 function Opinion:by_pk(member_id, suggestion_id)
30 return self:new_selector()
31 :add_where{ "member_id = ?", member_id }
32 :add_where{ "suggestion_id = ?", suggestion_id }
33 :optional_object_mode()
34 :exec()
35 end
38 function Opinion:update(suggestion_id, member_id, degree, fulfilled)
40 local opinion = Opinion:by_pk(member_id, suggestion_id)
41 local suggestion = Suggestion:by_id(suggestion_id)
43 if not suggestion then
44 slot.put_into("error", _"This suggestion has been meanwhile deleted")
45 return false
46 end
48 -- TODO important m1 selectors returning result _SET_!
49 local issue = suggestion.initiative:get_reference_selector("issue"):for_share():single_object_mode():exec()
51 if issue.closed then
52 slot.put_into("error", _"This issue is already closed.")
53 return false
54 elseif issue.fully_frozen then
55 slot.put_into("error", _"Voting for this issue has already begun.")
56 return false
57 elseif
58 (issue.half_frozen and issue.phase_finished) or
59 (not issue.accepted and issue.phase_finished)
60 then
61 slot.put_into("error", _"Current phase is already closed.")
62 return false
63 end
65 if degree == 0 then
66 if opinion then
67 opinion:destroy()
68 end
69 return true
70 end
72 if degree ~= 0 and not app.session.member:has_voting_right_for_unit_id(suggestion.initiative.issue.area.unit_id) then
73 return execute.view { module = "index", view = "403" }
74 end
76 if not opinion then
77 opinion = Opinion:new()
78 opinion.member_id = member_id
79 opinion.suggestion_id = suggestion_id
80 opinion.fulfilled = false
81 end
84 if degree ~= nil then
85 opinion.degree = degree
86 end
88 if fulfilled ~= nil then
89 opinion.fulfilled = fulfilled
90 end
92 opinion:save()
93 return true
95 end

Impressum / About Us