liquid_feedback_frontend

annotate app/main/member/settings_notification.lua @ 286:c587d8762e62

Registration process updated for Core 2.0, lockable member fields, notification settings
author bsw
date Sat Feb 25 11:51:37 2012 +0100 (2012-02-25)
parents
children ee477a136fd4
rev   line source
bsw@286 1 function send_notification(event)
bsw@286 2
bsw@286 3 local url
bsw@286 4
bsw@286 5 local body = ""
bsw@286 6
bsw@286 7 body = body .. _(" Unit: #{name}\n", { name = event.issue.area.unit.name })
bsw@286 8 body = body .. _(" Area: #{name}\n", { name = event.issue.area.name })
bsw@286 9 body = body .. _(" Issue: ##{id}\n", { id = event.issue_id })
bsw@286 10 body = body .. _(" Policy: #{phase}\n", { phase = event.issue.policy.name })
bsw@286 11 body = body .. _(" Phase: #{phase}\n\n", { phase = event.state })
bsw@286 12 body = body .. _(" Event: #{event}\n\n", { event = event.event })
bsw@286 13
bsw@286 14 if event.initiative_id then
bsw@286 15 url = request.get_absolute_baseurl() .. "initiative/show/" .. event.initiative_id .. ".html"
bsw@286 16 elseif event.suggestion_id then
bsw@286 17 url = request.get_absolute_baseurl() .. "suggestion/show/" .. event.suggestion_id .. ".html"
bsw@286 18 else
bsw@286 19 url = request.get_absolute_baseurl() .. "issue/show/" .. event.issue_id .. ".html"
bsw@286 20 end
bsw@286 21
bsw@286 22 body = body .. _(" URL: #{url}\n\n", { url = url })
bsw@286 23
bsw@286 24 if event.initiative_id then
bsw@286 25 local initiative = Initiative:by_id(event.initiative_id)
bsw@286 26 body = body .. _("i#{id}: #{name}\n\n", { id = initiative.id, name = initiative.name })
bsw@286 27 else
bsw@286 28 local initiative_count = Initiative:new_selector()
bsw@286 29 :add_where{ "initiative.issue_id = ?", event.issue_id }
bsw@286 30 :count()
bsw@286 31 local initiatives = Initiative:new_selector()
bsw@286 32 :add_where{ "initiative.issue_id = ?", event.issue_id }
bsw@286 33 :add_order_by("initiative.supporter_count DESC")
bsw@286 34 :limit(3)
bsw@286 35 :exec()
bsw@286 36 for i, initiative in ipairs(initiatives) do
bsw@286 37 body = body .. _("i#{id}: #{name}\n", { id = initiative.id, name = initiative.name })
bsw@286 38 end
bsw@286 39 if initiative_count - 3 > 0 then
bsw@286 40 body = body .. _("and #{count} more initiatives\n", { count = initiative_count })
bsw@286 41 end
bsw@286 42 body = body .. "\n"
bsw@286 43 end
bsw@286 44
bsw@286 45 if event.suggestion_id then
bsw@286 46 local suggestion = Suggestion:by_id(event.suggestion_id)
bsw@286 47 body = body .. _("#{name}\n\n", { name = suggestion.name })
bsw@286 48 end
bsw@286 49
bsw@286 50 slot.put("<pre>", encode.html_newlines(body), "</pre>")
bsw@286 51 slot.put("<hr />")
bsw@286 52 end
bsw@286 53
bsw@286 54
bsw@286 55
bsw@286 56 slot.put_into("title", _"Notification settings")
bsw@286 57
bsw@286 58 slot.select("actions", function()
bsw@286 59 ui.link{
bsw@286 60 content = function()
bsw@286 61 ui.image{ static = "icons/16/cancel.png" }
bsw@286 62 slot.put(_"Cancel")
bsw@286 63 end,
bsw@286 64 module = "member",
bsw@286 65 view = "settings"
bsw@286 66 }
bsw@286 67 end)
bsw@286 68
bsw@286 69
bsw@286 70 util.help("member.settings.notification", _"Notification settings")
bsw@286 71
bsw@286 72 ui.form{
bsw@286 73 attr = { class = "vertical" },
bsw@286 74 module = "member",
bsw@286 75 action = "update_notification",
bsw@286 76 routing = {
bsw@286 77 ok = {
bsw@286 78 mode = "redirect",
bsw@286 79 module = "index",
bsw@286 80 view = "index"
bsw@286 81 }
bsw@286 82 },
bsw@286 83 content = function()
bsw@286 84 ui.tag{ tag = "p", _"Send me notifications about issues in following phases:" }
bsw@286 85
bsw@286 86 ui.container{ content = function()
bsw@286 87 ui.tag{
bsw@286 88 tag = "input",
bsw@286 89 attr = { type = "radio", name = "notification_level", value = "voting" }
bsw@286 90 }
bsw@286 91 ui.tag{ content = _"Voting phase" }
bsw@286 92 ui.tag{ tag = "ul", content = function()
bsw@286 93 ui.tag{ tag = "li", content = _"Voting of an issue in one of my areas or I'm interested in starts" }
bsw@286 94 end }
bsw@286 95 end }
bsw@286 96
bsw@286 97 ui.container{ content = function()
bsw@286 98 ui.tag{
bsw@286 99 tag = "input",
bsw@286 100 attr = { type = "radio", name = "notification_level", value = "frozen" }
bsw@286 101 }
bsw@286 102 ui.tag{ content = _"Frozen and voting phase" }
bsw@286 103 ui.tag{ tag = "ul", content = function()
bsw@286 104 ui.tag{ tag = "li", content = _"An issue in one of my areas or I'm interested in enters phase 'frozen'" }
bsw@286 105 ui.tag{ tag = "li", content = _"A new initiative is created in an issue I'm interested in" }
bsw@286 106 ui.tag{ tag = "li", content = _"Voting of an issue in one of my areas or I'm interested in starts" }
bsw@286 107 end }
bsw@286 108 end }
bsw@286 109
bsw@286 110 ui.container{ content = function()
bsw@286 111 ui.tag{
bsw@286 112 tag = "input",
bsw@286 113 attr = { type = "radio", name = "notification_level", value = "discussion" }
bsw@286 114 }
bsw@286 115 ui.tag{ content = _"Discussion, frozen and voting phase" }
bsw@286 116 ui.tag{ tag = "ul", content = function()
bsw@286 117 ui.tag{ tag = "li", content = _"An issue in one of my areas or I'm interested in enters phase 'discussion'" }
bsw@286 118 ui.tag{ tag = "li", content = _"A new initiative is created in an issue I'm interested in" }
bsw@286 119 ui.tag{ tag = "li", content = _"The draft of an initiative I'm supporting is updated" }
bsw@286 120 ui.tag{ tag = "li", content = _"An initiative I was supporting is revoked" }
bsw@286 121 ui.tag{ tag = "li", content = _"A new suggestion is created in an initiative I'm supporting" }
bsw@286 122 ui.tag{ tag = "li", content = _"An issue in one of my areas or I'm interested in enters phase 'frozen'" }
bsw@286 123 ui.tag{ tag = "li", content = _"Voting of an issue in one of my areas or I'm interested in starts" }
bsw@286 124 end }
bsw@286 125 end }
bsw@286 126
bsw@286 127 ui.container{ content = function()
bsw@286 128 ui.tag{
bsw@286 129 tag = "input",
bsw@286 130 attr = { type = "radio", name = "notification_level", value = "any" }
bsw@286 131 }
bsw@286 132 ui.tag{ content = _"Any phase" }
bsw@286 133 ui.tag{ tag = "ul", content = function()
bsw@286 134 ui.tag{ tag = "li", content = _"A new issue is created in one of my areas" }
bsw@286 135 ui.tag{ tag = "li", content = _"An issue in one of my areas or i'm interested in enters phase 'discussion'" }
bsw@286 136 ui.tag{ tag = "li", content = _"A new initiative is created in an issue I'm interested in" }
bsw@286 137 ui.tag{ tag = "li", content = _"The draft of an initiative I'm supporting is updated" }
bsw@286 138 ui.tag{ tag = "li", content = _"An initiative I was supporting is revoked" }
bsw@286 139 ui.tag{ tag = "li", content = _"A new suggestion is created in an initiative I'm supporting" }
bsw@286 140 ui.tag{ tag = "li", content = _"An issue in one of my areas or I'm interested in enters phase 'frozen'" }
bsw@286 141 ui.tag{ tag = "li", content = _"Voting of an issue in one of my areas or I'm interested in starts" }
bsw@286 142 end }
bsw@286 143 end }
bsw@286 144
bsw@286 145 ui.container{ content = function()
bsw@286 146 ui.tag{
bsw@286 147 tag = "input",
bsw@286 148 attr = { type = "radio", name = "notification_level", value = "none" }
bsw@286 149 }
bsw@286 150 ui.tag{ content = _"No notifications at all" }
bsw@286 151 end }
bsw@286 152
bsw@286 153
bsw@286 154
bsw@286 155 ui.submit{ value = _"Change display settings" }
bsw@286 156 end
bsw@286 157 }
bsw@286 158
bsw@286 159 local last_id = 6000;
bsw@286 160
bsw@286 161 while last_id < 6050 do
bsw@286 162
bsw@286 163 local event = Event:new_selector()
bsw@286 164 :add_where{ "event.id > ?", last_id }
bsw@286 165 :add_order_by("event.id")
bsw@286 166 :limit(1)
bsw@286 167 :optional_object_mode()
bsw@286 168 :exec()
bsw@286 169
bsw@286 170 last_id = nil
bsw@286 171 if event then
bsw@286 172 last_id = event.id
bsw@286 173 local members_to_notify = Member:new_selector()
bsw@286 174 :join("event_seen_by_member", nil, { "event_seen_by_member.seen_by_member_id = member.id AND event_seen_by_member.notify_level <= member.notify_level AND event_seen_by_member.id = ?", event.id } )
bsw@286 175 :add_where("member.activated NOTNULL AND member.notify_email NOTNULL")
bsw@286 176 :exec()
bsw@286 177 ui.container{ content = _("Event #{id} -> #{num} members", { id = event.id, num = #members_to_notify }) }
bsw@286 178
bsw@286 179 send_notification(event)
bsw@286 180
bsw@286 181 end
bsw@286 182 end
bsw@286 183
bsw@286 184
bsw@286 185 -- select event.id, event.occurrence, membership.member_id NOTNULL as membership, interest.member_id NOTNULL as interest, supporter.member_id NOTNULL as supporter, event.event, event.state, issue.id, initiative.name FROM event JOIN issue ON issue.id = event.issue_id LEFT JOIN membership ON membership.area_id = issue.area_id AND membership.member_id = 41 LEFT JOIN interest ON interest.issue_id = issue.id AND interest.member_id = 41 LEFT JOIN initiative ON initiative.id = event.initiative_id LEFT JOIN supporter ON supporter.initiative_id = initiative.id AND supporter.member_id = 41 WHERE (((event.event = 'issue_state_changed' OR event.event = 'initiative_created_in_new_issue') AND membership.member_id NOTNULL OR interest.member_id NOTNULL) OR (event.event = 'initiative_created_in_existing_issue' AND interest.member_id NOTNULL) OR ((event.event = 'initiative_revoked' OR event.event = 'new_draft_created' OR event.event = 'suggestion_created') AND supporter.member_id NOTNULL)) AND event.id > 7000 ORDER by event.id ASC LIMIT 1;

Impressum / About Us