liquid_feedback_frontend

annotate app/main/api/initiative.lua @ 124:f740026b1518

add initiator support in delegation

if a delegation is issued from the initiative view, the initiators
from that one are added to the delegation target list. this makes it easier to delegate to the author without the need to add him to the contact list.
author Daniel Poelzleithner <poelzi@poelzi.org>
date Mon Sep 20 20:32:04 2010 +0200 (2010-09-20)
parents ae5fbdbc1758
children
rev   line source
bsw@75 1 local id = param.get("id")
bsw@51 2 local min_id = param.get("min_id")
bsw@51 3 local max_id = param.get("max_id")
bsw@51 4 local area_id = param.get("area_id", atom.integer)
bsw@51 5 local issue_id = param.get("issue_id", atom.integer)
bsw@51 6 local policy_id = param.get("policy_id", atom.integer)
bsw@51 7 local state = param.get("state")
bsw@51 8 local agreed = param.get("agreed")
bsw@51 9 local rank = param.get("rank")
bsw@95 10 --local search = param.get("search")
bsw@95 11 --local search_context = param.get("search_context") or "full"
bsw@51 12 local limit = param.get("limit", atom.integer)
bsw@51 13 local order = param.get("order")
bsw@95 14 local render_draft = param.get("render_draft")
bsw@95 15
bsw@95 16 if render_draft and render_draft ~= "html" then
bsw@95 17 error("unsupported render target, only 'html' is supported right now")
bsw@95 18 end
bsw@51 19
bsw@51 20 local initiatives_selector = Initiative:new_selector()
bsw@75 21 :join("issue", nil, "issue.id = initiative.issue_id")
bsw@51 22 :join("area", nil, "area.id = issue.area_id")
bsw@51 23 :join("policy", nil, "policy.id = issue.policy_id")
bsw@51 24
bsw@51 25 if id then
bsw@51 26 initiatives_selector:add_where{"initiative.id = ?", id}
bsw@51 27 end
bsw@51 28
bsw@51 29 if min_id then
bsw@51 30 initiatives_selector:add_where{"initiative.id >= ?", min_id}
bsw@51 31 end
bsw@51 32
bsw@51 33 if max_id then
bsw@51 34 initiatives_selector:add_where{"initiative.id <= ?", max_id}
bsw@51 35 end
bsw@51 36
bsw@51 37 if area_id then
bsw@51 38 initiatives_selector:add_where{"area.id = ?", area_id}
bsw@51 39 end
bsw@51 40
bsw@51 41 if issue_id then
bsw@51 42 initiatives_selector:add_where{"issue.id = ?", issue_id}
bsw@51 43 end
bsw@51 44
bsw@51 45 if policy_id then
bsw@51 46 initiatives_selector:add_where{"policy.id = ?", policy_id}
bsw@51 47 end
bsw@51 48
bsw@51 49 if state then
bsw@75 50 Issue:modify_selector_for_state(initiatives_selector, state)
bsw@51 51 end
bsw@51 52
bsw@51 53 if agreed then
bsw@51 54 initiatives_selector:add_where("initiative.agreed")
bsw@51 55 end
bsw@51 56
bsw@51 57 if rank then
bsw@51 58 initiatives_selector:add_where{ "initiative.rank = ?", rank }
bsw@51 59 end
bsw@51 60
bsw@95 61 --[[
bsw@51 62 if search then
bsw@51 63 if search_context == "full" then
bsw@51 64 elseif search_context == "title" then
bsw@51 65 end
bsw@51 66 end
bsw@95 67 --]]
bsw@51 68
bsw@51 69 if order == "supporter_count" then
bsw@51 70 initiatives_selector:add_order_by("initiative.supporter_count")
bsw@51 71 end
bsw@51 72
bsw@81 73 if order == "id_desc" then
bsw@81 74 initiatives_selector:add_order_by("initiative.id DESC")
bsw@81 75 else
bsw@81 76 initiatives_selector:add_order_by("initiative.id")
bsw@81 77 end
bsw@51 78
bsw@51 79 if limit then
bsw@51 80 initiatives_selector:limit(limit)
bsw@51 81 end
bsw@51 82
bsw@51 83 local api_engine = param.get("api_engine") or "xml"
bsw@51 84
bsw@51 85 local function format_timestamp(timestamp)
bsw@51 86 if timestamp then
bsw@51 87 return format.timestamp(timestamp)
bsw@51 88 else
bsw@51 89 return ""
bsw@51 90 end
bsw@51 91 end
bsw@51 92
bsw@51 93 local fields = {
bsw@51 94
bsw@51 95 { name = "area_id", field = "area.id" },
bsw@51 96 { name = "area_name", field = "area.name" },
bsw@51 97 { name = "issue_id", field = "issue.id" },
bsw@51 98 {
bsw@51 99 name = "issue_state",
bsw@51 100 func = function(record)
bsw@51 101 return record.issue.state
bsw@51 102 end
bsw@51 103 },
bsw@51 104 {
bsw@51 105 name = "issue_created",
bsw@51 106 field = "issue.created",
bsw@51 107 func = function(record)
bsw@51 108 return format_timestamp(record.issue_created)
bsw@51 109 end
bsw@51 110 },
bsw@51 111 {
bsw@51 112 name = "issue_accepted",
bsw@51 113 field = "issue.accepted",
bsw@51 114 func = function(record)
bsw@51 115 return format_timestamp(record.issue_accepted)
bsw@51 116 end
bsw@51 117 },
bsw@51 118 {
bsw@51 119 name = "issue_half_frozen",
bsw@51 120 field = "issue.half_frozen",
bsw@51 121 func = function(record)
bsw@51 122 return format_timestamp(record.issue_half_frozen)
bsw@51 123 end
bsw@51 124 },
bsw@51 125 {
bsw@51 126 name = "issue_fully_frozen",
bsw@51 127 field = "issue.fully_frozen",
bsw@51 128 func = function(record)
bsw@51 129 return format_timestamp(record.issue_fully_frozen)
bsw@51 130 end
bsw@51 131 },
bsw@51 132 {
bsw@51 133 name = "issue_closed",
bsw@51 134 field = "issue.closed",
bsw@51 135 func = function(record)
bsw@51 136 return format_timestamp(record.issue_closed)
bsw@51 137 end
bsw@51 138 },
bsw@51 139 { name = "issue_admission_time", field = "issue.admission_time" },
bsw@51 140 { name = "issue_discussion_time", field = "issue.discussion_time" },
bsw@51 141 { name = "issue_verification_time", field = "issue.verification_time" },
bsw@51 142 { name = "issue_voting_time", field = "issue.voting_time" },
bsw@51 143 { name = "issue_ranks_available", field = "issue.ranks_available" },
bsw@51 144
bsw@51 145 { name = "policy_issue_quorum_num", field = "policy.issue_quorum_num" },
bsw@51 146 { name = "policy_issue_quorum_den", field = "policy.issue_quorum_den" },
bsw@51 147 { name = "policy_initiative_quorum_num",
bsw@51 148 field = "policy.initiative_quorum_num" },
bsw@51 149 { name = "policy_initiative_quorum_den",
bsw@51 150 field = "policy.initiative_quorum_den" },
bsw@51 151 { name = "policy_majority_num", field = "policy.majority_num" },
bsw@51 152 { name = "policy_majority_den", field = "policy.majority_den" },
bsw@51 153 { name = "policy_majority_strict", field = "policy.majority_strict" },
bsw@51 154 { name = "id", field = "initiative.id" },
bsw@51 155 { name = "name", field = "initiative.name" },
bsw@51 156 { name = "discussion_url", field = "initiative.discussion_url" },
bsw@51 157 {
bsw@51 158 name = "created",
bsw@51 159 field = "initiative.created",
bsw@51 160 func = function(record)
bsw@99 161 return format_timestamp(record.created)
bsw@51 162 end
bsw@51 163 },
bsw@95 164 {
bsw@95 165 name = "revoked",
bsw@95 166 field = "initiative.revoked",
bsw@95 167 func = function(record)
bsw@99 168 return format_timestamp(record.revoked)
bsw@95 169 end
bsw@95 170 },
bsw@51 171 { name = "suggested_initiative_id", field = "initiative.suggested_initiative_id" },
bsw@51 172 { name = "admitted", field = "initiative.admitted" },
bsw@51 173 { name = "issue_population", field = "issue.population" },
bsw@51 174 { name = "supporter_count", field = "initiative.supporter_count" },
bsw@51 175 { name = "informed_supporter_count", field = "initiative.informed_supporter_count" },
bsw@51 176 { name = "satisfied_supporter_count", field = "initiative.satisfied_supporter_count" },
bsw@51 177 { name = "satisfied_informed_supporter_count",
bsw@51 178 field = "initiative.satisfied_informed_supporter_count" },
bsw@51 179 { name = "issue_vote_now", field = "issue.vote_now" },
bsw@51 180 { name = "issue_vote_later", field = "issue.vote_later" },
bsw@51 181 { name = "issue_voter_count", field = "issue.voter_count" },
bsw@51 182 { name = "positive_votes", field = "initiative.positive_votes" },
bsw@51 183 { name = "negative_votes", field = "initiative.negative_votes" },
bsw@51 184 { name = "agreed", field = "initiative.agreed" },
bsw@51 185 { name = "rank", field = "initiative.rank" },
bsw@51 186 {
bsw@51 187 name = "current_draft_created",
bsw@51 188 func = function(record)
bsw@99 189 return format_timestamp(record.current_draft.created)
bsw@51 190 end
bsw@51 191 },
bsw@51 192 {
bsw@51 193 name = "current_draft_formatting_engine",
bsw@51 194 func = function(record)
bsw@51 195 return record.current_draft.formatting_engine
bsw@51 196 end
bsw@51 197 },
bsw@51 198 {
bsw@51 199 name = "current_draft_content",
bsw@51 200 func = function(record)
bsw@95 201 if render_draft then
bsw@95 202 return record.current_draft:get_content(render_draft)
bsw@95 203 else
bsw@95 204 return record.current_draft.content
bsw@95 205 end
bsw@51 206 end
bsw@51 207 }
bsw@51 208 }
bsw@51 209
bsw@51 210 util.autoapi{
bsw@75 211 relation_name = "initiative",
bsw@95 212 selector = initiatives_selector,
bsw@95 213 fields = fields,
bsw@95 214 api_engine = api_engine
bsw@51 215 }

Impressum / About Us