liquid_feedback_frontend
annotate model/initiative.lua @ 172:165f4bd02cf3
don't show the first draft of a new initiative as a new draft event in the timeline
new draft should only show changes of drafts drafts of new initiatives as they are handled by the new initiative event
new draft should only show changes of drafts drafts of new initiatives as they are handled by the new initiative event
author | Daniel Poelzleithner <poelzi@poelzi.org> |
---|---|
date | Sun Oct 10 19:40:32 2010 +0200 (2010-10-10) |
parents | 88ac7798b562 |
children | f460555c9896 |
rev | line source |
---|---|
bsw/jbe@0 | 1 Initiative = mondelefant.new_class() |
bsw/jbe@0 | 2 Initiative.table = 'initiative' |
bsw/jbe@0 | 3 |
bsw/jbe@0 | 4 Initiative:add_reference{ |
bsw/jbe@0 | 5 mode = 'm1', |
bsw/jbe@0 | 6 to = "Issue", |
bsw/jbe@0 | 7 this_key = 'issue_id', |
bsw/jbe@0 | 8 that_key = 'id', |
bsw/jbe@0 | 9 ref = 'issue', |
bsw/jbe@0 | 10 } |
bsw/jbe@0 | 11 |
bsw/jbe@0 | 12 Initiative:add_reference{ |
bsw/jbe@0 | 13 mode = '1m', |
bsw/jbe@0 | 14 to = "Draft", |
bsw/jbe@0 | 15 this_key = 'id', |
bsw/jbe@0 | 16 that_key = 'initiative_id', |
bsw/jbe@0 | 17 ref = 'drafts', |
bsw/jbe@0 | 18 back_ref = 'initiative', |
bsw/jbe@19 | 19 default_order = '"id" DESC' |
bsw/jbe@0 | 20 } |
bsw/jbe@0 | 21 |
bsw/jbe@0 | 22 Initiative:add_reference{ |
bsw/jbe@0 | 23 mode = '1m', |
bsw/jbe@0 | 24 to = "Suggestion", |
bsw/jbe@0 | 25 this_key = 'id', |
bsw/jbe@0 | 26 that_key = 'initiative_id', |
bsw/jbe@0 | 27 ref = 'suggestions', |
bsw/jbe@0 | 28 back_ref = 'initiative', |
bsw/jbe@0 | 29 } |
bsw/jbe@0 | 30 |
bsw/jbe@0 | 31 Initiative:add_reference{ |
bsw/jbe@0 | 32 mode = '1m', |
bsw/jbe@0 | 33 to = "Initiator", |
bsw/jbe@0 | 34 this_key = 'id', |
bsw/jbe@0 | 35 that_key = 'initiative_id', |
bsw/jbe@0 | 36 ref = 'initiators', |
bsw@10 | 37 back_ref = 'initiative' |
bsw/jbe@0 | 38 } |
bsw/jbe@0 | 39 |
bsw/jbe@0 | 40 Initiative:add_reference{ |
bsw/jbe@0 | 41 mode = '1m', |
bsw/jbe@0 | 42 to = "Supporter", |
bsw/jbe@0 | 43 this_key = 'id', |
bsw/jbe@0 | 44 that_key = 'initiative_id', |
bsw/jbe@0 | 45 ref = 'supporters', |
bsw/jbe@0 | 46 back_ref = 'initiative', |
bsw/jbe@0 | 47 default_order = '"id"' |
bsw/jbe@0 | 48 } |
bsw/jbe@0 | 49 |
bsw/jbe@0 | 50 Initiative:add_reference{ |
bsw/jbe@0 | 51 mode = '1m', |
bsw/jbe@0 | 52 to = "Opinion", |
bsw/jbe@0 | 53 this_key = 'id', |
bsw/jbe@0 | 54 that_key = 'initiative_id', |
bsw/jbe@0 | 55 ref = 'opinions', |
bsw/jbe@0 | 56 back_ref = 'initiative', |
bsw/jbe@0 | 57 default_order = '"id"' |
bsw/jbe@0 | 58 } |
bsw/jbe@0 | 59 |
bsw/jbe@0 | 60 Initiative:add_reference{ |
bsw/jbe@0 | 61 mode = '1m', |
bsw/jbe@0 | 62 to = "Vote", |
bsw/jbe@0 | 63 this_key = 'id', |
bsw/jbe@0 | 64 that_key = 'initiative_id', |
bsw/jbe@0 | 65 ref = 'votes', |
bsw/jbe@0 | 66 back_ref = 'initiative', |
bsw/jbe@0 | 67 default_order = '"member_id"' |
bsw/jbe@0 | 68 } |
bsw/jbe@0 | 69 |
bsw/jbe@0 | 70 Initiative:add_reference{ |
bsw@10 | 71 mode = 'm1', |
bsw@10 | 72 to = "Initiative", |
bsw@10 | 73 this_key = 'suggested_initiative_id', |
bsw@10 | 74 that_key = 'id', |
bsw@10 | 75 ref = 'suggested_initiative', |
bsw@10 | 76 } |
bsw@10 | 77 |
bsw@10 | 78 Initiative:add_reference{ |
bsw/jbe@0 | 79 mode = 'mm', |
bsw/jbe@0 | 80 to = "Member", |
bsw/jbe@0 | 81 this_key = 'id', |
bsw/jbe@0 | 82 that_key = 'id', |
bsw/jbe@0 | 83 connected_by_table = '"initiator"', |
bsw/jbe@0 | 84 connected_by_this_key = 'initiative_id', |
bsw/jbe@0 | 85 connected_by_that_key = 'member_id', |
bsw/jbe@0 | 86 ref = 'initiating_members' |
bsw/jbe@0 | 87 } |
bsw/jbe@0 | 88 |
bsw/jbe@0 | 89 Initiative:add_reference{ |
bsw/jbe@0 | 90 mode = 'mm', |
bsw/jbe@0 | 91 to = "Member", |
bsw/jbe@0 | 92 this_key = 'id', |
bsw/jbe@0 | 93 that_key = 'id', |
bsw/jbe@0 | 94 connected_by_table = '"supporter"', |
bsw/jbe@0 | 95 connected_by_this_key = 'initiative_id', |
bsw/jbe@0 | 96 connected_by_that_key = 'member_id', |
bsw/jbe@0 | 97 ref = 'supporting_members' |
bsw/jbe@0 | 98 } |
bsw/jbe@0 | 99 |
bsw@3 | 100 Initiative:add_reference{ |
bsw@3 | 101 mode = 'mm', |
bsw@3 | 102 to = "Member", |
bsw@3 | 103 this_key = 'id', |
bsw@3 | 104 that_key = 'id', |
bsw@3 | 105 connected_by_table = 'direct_supporter_snapshot', |
bsw@3 | 106 connected_by_this_key = 'initiative_id', |
bsw@3 | 107 connected_by_that_key = 'member_id', |
bsw@3 | 108 ref = 'supporting_members_snapshot' |
bsw@3 | 109 } |
bsw@3 | 110 |
bsw/jbe@6 | 111 |
bsw@2 | 112 function Initiative:get_search_selector(search_string) |
bsw/jbe@0 | 113 return self:new_selector() |
bsw/jbe@6 | 114 :join("draft", nil, "draft.initiative_id = initiative.id") |
bsw@2 | 115 :add_field( {'"highlight"("initiative"."name", ?)', search_string }, "name_highlighted") |
bsw/jbe@6 | 116 :add_where{ '"initiative"."text_search_data" @@ "text_search_query"(?) OR "draft"."text_search_data" @@ "text_search_query"(?)', search_string, search_string } |
bsw/jbe@6 | 117 :add_group_by('"initiative"."id"') |
bsw/jbe@6 | 118 :add_group_by('"initiative"."issue_id"') |
bsw/jbe@6 | 119 :add_group_by('"initiative"."name"') |
bsw/jbe@6 | 120 :add_group_by('"initiative"."discussion_url"') |
bsw/jbe@6 | 121 :add_group_by('"initiative"."created"') |
bsw/jbe@6 | 122 :add_group_by('"initiative"."revoked"') |
bsw/jbe@6 | 123 :add_group_by('"initiative"."admitted"') |
bsw/jbe@6 | 124 :add_group_by('"initiative"."supporter_count"') |
bsw/jbe@6 | 125 :add_group_by('"initiative"."informed_supporter_count"') |
bsw/jbe@6 | 126 :add_group_by('"initiative"."satisfied_supporter_count"') |
bsw/jbe@6 | 127 :add_group_by('"initiative"."satisfied_informed_supporter_count"') |
bsw/jbe@6 | 128 :add_group_by('"initiative"."positive_votes"') |
bsw/jbe@6 | 129 :add_group_by('"initiative"."negative_votes"') |
bsw/jbe@6 | 130 :add_group_by('"initiative"."agreed"') |
bsw/jbe@6 | 131 :add_group_by('"initiative"."rank"') |
bsw/jbe@19 | 132 :add_group_by('"initiative"."suggested_initiative_id"') |
bsw/jbe@6 | 133 :add_group_by('"initiative"."text_search_data"') |
bsw/jbe@6 | 134 :add_group_by('"issue"."population"') |
bsw/jbe@19 | 135 :add_group_by("_initiator.member_id") |
bsw/jbe@19 | 136 :add_group_by("_supporter.member_id") |
bsw/jbe@0 | 137 end |
bsw/jbe@0 | 138 |
bsw@51 | 139 --function Member:get_search_selector(search_string) |
bsw@51 | 140 -- return self:new_selector() |
bsw@51 | 141 -- :add_where("active") |
bsw@51 | 142 --end |
bsw@2 | 143 |
bsw@2 | 144 |
bsw/jbe@0 | 145 function Initiative.object_get:current_draft() |
bsw/jbe@0 | 146 return Draft:new_selector() |
bsw/jbe@0 | 147 :add_where{ '"initiative_id" = ?', self.id } |
bsw/jbe@0 | 148 :add_order_by('"id" DESC') |
bsw/jbe@0 | 149 :single_object_mode() |
bsw/jbe@0 | 150 :exec() |
bsw/jbe@0 | 151 end |
bsw/jbe@0 | 152 |
bsw/jbe@0 | 153 function Initiative.object_get:shortened_name() |
bsw/jbe@0 | 154 local name = self.name |
bsw/jbe@0 | 155 if #name > 100 then |
bsw/jbe@0 | 156 name = name:sub(1,100) .. "..." |
bsw/jbe@0 | 157 end |
bsw/jbe@0 | 158 return name |
bsw/jbe@0 | 159 end |
bsw/jbe@52 | 160 |
bsw/jbe@52 | 161 function Initiative.object_get:initiator_names() |
bsw/jbe@52 | 162 local members = Member:new_selector() |
bsw/jbe@52 | 163 :join("initiator", nil, "initiator.member_id = member.id") |
bsw/jbe@52 | 164 :add_where{ "initiator.initiative_id = ?", self.id } |
bsw/jbe@52 | 165 :add_where{ "initiator.accepted" } |
bsw/jbe@52 | 166 :exec() |
bsw/jbe@52 | 167 |
bsw/jbe@52 | 168 local member_names = {} |
bsw/jbe@52 | 169 for i, member in ipairs(members) do |
bsw/jbe@52 | 170 member_names[#member_names+1] = member.name |
bsw/jbe@52 | 171 end |
bsw/jbe@52 | 172 return member_names |
bsw/jbe@52 | 173 end |
bsw/jbe@52 | 174 |