liquid_feedback_frontend
view model/issue.lua @ 0:3bfb2fcf7ab9
Version alpha1
author | bsw/jbe |
---|---|
date | Wed Nov 18 12:00:00 2009 +0100 (2009-11-18) |
parents | |
children | 5c601807d397 |
line source
1 Issue = mondelefant.new_class()
2 Issue.table = 'issue'
4 Issue:add_reference{
5 mode = 'm1',
6 to = "Area",
7 this_key = 'area_id',
8 that_key = 'id',
9 ref = 'area',
10 }
12 Issue:add_reference{
13 mode = 'm1',
14 to = "Policy",
15 this_key = 'policy_id',
16 that_key = 'id',
17 ref = 'policy',
18 }
20 Issue:add_reference{
21 mode = '1m',
22 to = "Initiative",
23 this_key = 'id',
24 that_key = 'issue_id',
25 ref = 'initiatives',
26 back_ref = 'issue'
27 }
29 Issue:add_reference{
30 mode = '1m',
31 to = "Interest",
32 this_key = 'id',
33 that_key = 'issue_id',
34 ref = 'interests',
35 back_ref = 'issue',
36 default_order = '"id"'
37 }
39 Issue:add_reference{
40 mode = '1m',
41 to = "Supporter",
42 this_key = 'id',
43 that_key = 'issue_id',
44 ref = 'supporters',
45 back_ref = 'issue',
46 default_order = '"id"'
47 }
49 Issue:add_reference{
50 mode = '1m',
51 to = "DirectVoter",
52 this_key = 'id',
53 that_key = 'issue_id',
54 ref = 'direct_voters',
55 back_ref = 'issue',
56 default_order = '"member_id"'
57 }
59 Issue:add_reference{
60 mode = '1m',
61 to = "Vote",
62 this_key = 'id',
63 that_key = 'issue_id',
64 ref = 'votes',
65 back_ref = 'issue',
66 default_order = '"member_id", "initiative_id"'
67 }
69 Issue:add_reference{
70 mode = 'mm',
71 to = "Member",
72 this_key = 'id',
73 that_key = 'id',
74 connected_by_table = 'interest',
75 connected_by_this_key = 'issue_id',
76 connected_by_that_key = 'member_id',
77 ref = 'members'
78 }
80 function Issue:get_state_name_for_state(value)
81 local state_name_table = {}
82 return state_name_table[value] or value
83 end
85 function Issue:search(search_string)
86 return self:new_selector()
87 :join('"initiative"', nil, '"initiative"."issue_id" = "issue"."id"')
88 :add_where{ '"initiative"."name" ILIKE ?', "%" .. search_string:gsub("%%", "") .. "%" }
89 :set_distinct()
90 :exec()
91 end
93 function Issue.object_get:state()
94 if self.accepted then
95 if self.frozen then
96 return "frozen"
97 elseif self.closed then
98 return "closed"
99 else
100 return "accepted"
101 end
102 else
103 if self.closed then
104 return "closed"
105 else
106 return "new"
107 end
108 end
109 end