liquid_feedback_frontend
view model/supporter.lua @ 945:b865f87ea810
Work on robustification of JavaScript voting
author | jbe |
---|---|
date | Thu Nov 08 13:17:37 2012 +0100 (2012-11-08) |
parents | afd9f769c7ae |
children |
line source
1 Supporter = mondelefant.new_class()
2 Supporter.table = 'supporter'
3 Supporter.primary_key = { "initiative_id", "member_id" }
5 Supporter:add_reference{
6 mode = 'm1',
7 to = "Initiative",
8 this_key = 'initiative_id',
9 that_key = 'id',
10 ref = 'initiative',
11 }
13 Supporter:add_reference{
14 mode = 'm1',
15 to = "Member",
16 this_key = 'member_id',
17 that_key = 'id',
18 ref = 'member',
19 }
21 function Supporter:by_pk(initiative_id, member_id)
22 return self:new_selector()
23 :add_where{ "initiative_id = ?", initiative_id }
24 :add_where{ "member_id = ?", member_id }
25 :optional_object_mode()
26 :exec()
27 end
29 function Supporter.object:has_critical_opinion()
30 return Opinion:new_selector()
31 :add_where{ "initiative_id = ?", self.initiative_id }
32 :add_where{ "member_id = ?", self.member_id }
33 :add_where("(degree = -2 AND fulfilled) OR (degree = 2 AND NOT fulfilled)")
34 :limit(1)
35 :exec()[1] and true or false
36 end