liquid_feedback_frontend

view model/delegation.lua @ 1800:b87997219042

Updated spanish translation
author bsw
date Thu Oct 21 15:22:29 2021 +0200 (2021-10-21)
parents 81bde33c2256
children
line source
1 Delegation = mondelefant.new_class()
2 Delegation.table = 'delegation'
4 Delegation:add_reference{
5 mode = 'm1',
6 to = "Member",
7 this_key = 'truster_id',
8 that_key = 'id',
9 ref = 'truster',
10 }
12 Delegation:add_reference{
13 mode = 'm1',
14 to = "Member",
15 this_key = 'trustee_id',
16 that_key = 'id',
17 ref = 'trustee',
18 }
20 Delegation:add_reference{
21 mode = 'm1',
22 to = "Unit",
23 this_key = 'unit_id',
24 that_key = 'id',
25 ref = 'unit',
26 }
28 Delegation:add_reference{
29 mode = 'm1',
30 to = "Area",
31 this_key = 'area_id',
32 that_key = 'id',
33 ref = 'area',
34 }
36 Delegation:add_reference{
37 mode = 'm1',
38 to = "Issue",
39 this_key = 'issue_id',
40 that_key = 'id',
41 ref = 'issue',
42 }
44 function Delegation:by_pk(truster_id, unit_id, area_id, issue_id)
45 local selector = self:new_selector():optional_object_mode()
46 selector:add_where{ "truster_id = ?", truster_id }
47 if unit_id then
48 selector:add_where{ "unit_id = ?", unit_id }
49 else
50 selector:add_where("unit_id ISNULL")
51 end
52 if area_id then
53 selector:add_where{ "area_id = ?", area_id }
54 else
55 selector:add_where("area_id ISNULL")
56 end
57 if issue_id then
58 selector:add_where{ "issue_id = ? ", issue_id }
59 else
60 selector:add_where("issue_id ISNULL ")
61 end
62 return selector:exec()
63 end
65 function Delegation:selector_for_broken(member_id)
66 return Delegation:new_selector()
67 :left_join("issue", nil, "issue.id = delegation.issue_id")
68 :add_where("issue.id ISNULL OR issue.closed ISNULL")
69 :join("member", nil, "delegation.trustee_id = member.id")
70 :add_where{"delegation.truster_id = ?", member_id}
71 :add_where{"member.active = 'f' OR (member.last_activity IS NULL OR age(member.last_activity) > ?::interval)", config.delegation_warning_time }
72 end
74 function Delegation:delegations_to_check_for_member_id(member_id, for_update)
76 Member:new_selector():add_where({ "id = ?", member_id }):for_update():exec()
78 local selector = Delegation:new_selector()
79 :add_field("member.name", "member_name")
80 :add_field("unit.name", "unit_name")
81 :add_field("area.name", "area_name")
82 :left_join("area", nil, "area.active AND area.id = delegation.area_id")
83 :join("unit", nil, "unit.active AND (unit.id = delegation.unit_id OR unit.id = area.unit_id)")
84 :left_join("member", nil, "member.id = delegation.trustee_id")
85 :add_where({ "delegation.truster_id = ?", member_id })
86 :add_order_by("unit.name, area.name NULLS FIRST")
88 if for_update then
89 selector:for_update_of("delegation")
90 end
92 return selector:exec()
94 end

Impressum / About Us