liquid_feedback_frontend
diff 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 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/app/main/member/settings_notification.lua Sat Feb 25 11:51:37 2012 +0100 1.3 @@ -0,0 +1,185 @@ 1.4 +function send_notification(event) 1.5 + 1.6 + local url 1.7 + 1.8 + local body = "" 1.9 + 1.10 + body = body .. _(" Unit: #{name}\n", { name = event.issue.area.unit.name }) 1.11 + body = body .. _(" Area: #{name}\n", { name = event.issue.area.name }) 1.12 + body = body .. _(" Issue: ##{id}\n", { id = event.issue_id }) 1.13 + body = body .. _(" Policy: #{phase}\n", { phase = event.issue.policy.name }) 1.14 + body = body .. _(" Phase: #{phase}\n\n", { phase = event.state }) 1.15 + body = body .. _(" Event: #{event}\n\n", { event = event.event }) 1.16 + 1.17 + if event.initiative_id then 1.18 + url = request.get_absolute_baseurl() .. "initiative/show/" .. event.initiative_id .. ".html" 1.19 + elseif event.suggestion_id then 1.20 + url = request.get_absolute_baseurl() .. "suggestion/show/" .. event.suggestion_id .. ".html" 1.21 + else 1.22 + url = request.get_absolute_baseurl() .. "issue/show/" .. event.issue_id .. ".html" 1.23 + end 1.24 + 1.25 + body = body .. _(" URL: #{url}\n\n", { url = url }) 1.26 + 1.27 + if event.initiative_id then 1.28 + local initiative = Initiative:by_id(event.initiative_id) 1.29 + body = body .. _("i#{id}: #{name}\n\n", { id = initiative.id, name = initiative.name }) 1.30 + else 1.31 + local initiative_count = Initiative:new_selector() 1.32 + :add_where{ "initiative.issue_id = ?", event.issue_id } 1.33 + :count() 1.34 + local initiatives = Initiative:new_selector() 1.35 + :add_where{ "initiative.issue_id = ?", event.issue_id } 1.36 + :add_order_by("initiative.supporter_count DESC") 1.37 + :limit(3) 1.38 + :exec() 1.39 + for i, initiative in ipairs(initiatives) do 1.40 + body = body .. _("i#{id}: #{name}\n", { id = initiative.id, name = initiative.name }) 1.41 + end 1.42 + if initiative_count - 3 > 0 then 1.43 + body = body .. _("and #{count} more initiatives\n", { count = initiative_count }) 1.44 + end 1.45 + body = body .. "\n" 1.46 + end 1.47 + 1.48 + if event.suggestion_id then 1.49 + local suggestion = Suggestion:by_id(event.suggestion_id) 1.50 + body = body .. _("#{name}\n\n", { name = suggestion.name }) 1.51 + end 1.52 + 1.53 + slot.put("<pre>", encode.html_newlines(body), "</pre>") 1.54 + slot.put("<hr />") 1.55 +end 1.56 + 1.57 + 1.58 + 1.59 +slot.put_into("title", _"Notification settings") 1.60 + 1.61 +slot.select("actions", function() 1.62 + ui.link{ 1.63 + content = function() 1.64 + ui.image{ static = "icons/16/cancel.png" } 1.65 + slot.put(_"Cancel") 1.66 + end, 1.67 + module = "member", 1.68 + view = "settings" 1.69 + } 1.70 +end) 1.71 + 1.72 + 1.73 +util.help("member.settings.notification", _"Notification settings") 1.74 + 1.75 +ui.form{ 1.76 + attr = { class = "vertical" }, 1.77 + module = "member", 1.78 + action = "update_notification", 1.79 + routing = { 1.80 + ok = { 1.81 + mode = "redirect", 1.82 + module = "index", 1.83 + view = "index" 1.84 + } 1.85 + }, 1.86 + content = function() 1.87 + ui.tag{ tag = "p", _"Send me notifications about issues in following phases:" } 1.88 + 1.89 + ui.container{ content = function() 1.90 + ui.tag{ 1.91 + tag = "input", 1.92 + attr = { type = "radio", name = "notification_level", value = "voting" } 1.93 + } 1.94 + ui.tag{ content = _"Voting phase" } 1.95 + ui.tag{ tag = "ul", content = function() 1.96 + ui.tag{ tag = "li", content = _"Voting of an issue in one of my areas or I'm interested in starts" } 1.97 + end } 1.98 + end } 1.99 + 1.100 + ui.container{ content = function() 1.101 + ui.tag{ 1.102 + tag = "input", 1.103 + attr = { type = "radio", name = "notification_level", value = "frozen" } 1.104 + } 1.105 + ui.tag{ content = _"Frozen and voting phase" } 1.106 + ui.tag{ tag = "ul", content = function() 1.107 + ui.tag{ tag = "li", content = _"An issue in one of my areas or I'm interested in enters phase 'frozen'" } 1.108 + ui.tag{ tag = "li", content = _"A new initiative is created in an issue I'm interested in" } 1.109 + ui.tag{ tag = "li", content = _"Voting of an issue in one of my areas or I'm interested in starts" } 1.110 + end } 1.111 + end } 1.112 + 1.113 + ui.container{ content = function() 1.114 + ui.tag{ 1.115 + tag = "input", 1.116 + attr = { type = "radio", name = "notification_level", value = "discussion" } 1.117 + } 1.118 + ui.tag{ content = _"Discussion, frozen and voting phase" } 1.119 + ui.tag{ tag = "ul", content = function() 1.120 + ui.tag{ tag = "li", content = _"An issue in one of my areas or I'm interested in enters phase 'discussion'" } 1.121 + ui.tag{ tag = "li", content = _"A new initiative is created in an issue I'm interested in" } 1.122 + ui.tag{ tag = "li", content = _"The draft of an initiative I'm supporting is updated" } 1.123 + ui.tag{ tag = "li", content = _"An initiative I was supporting is revoked" } 1.124 + ui.tag{ tag = "li", content = _"A new suggestion is created in an initiative I'm supporting" } 1.125 + ui.tag{ tag = "li", content = _"An issue in one of my areas or I'm interested in enters phase 'frozen'" } 1.126 + ui.tag{ tag = "li", content = _"Voting of an issue in one of my areas or I'm interested in starts" } 1.127 + end } 1.128 + end } 1.129 + 1.130 + ui.container{ content = function() 1.131 + ui.tag{ 1.132 + tag = "input", 1.133 + attr = { type = "radio", name = "notification_level", value = "any" } 1.134 + } 1.135 + ui.tag{ content = _"Any phase" } 1.136 + ui.tag{ tag = "ul", content = function() 1.137 + ui.tag{ tag = "li", content = _"A new issue is created in one of my areas" } 1.138 + ui.tag{ tag = "li", content = _"An issue in one of my areas or i'm interested in enters phase 'discussion'" } 1.139 + ui.tag{ tag = "li", content = _"A new initiative is created in an issue I'm interested in" } 1.140 + ui.tag{ tag = "li", content = _"The draft of an initiative I'm supporting is updated" } 1.141 + ui.tag{ tag = "li", content = _"An initiative I was supporting is revoked" } 1.142 + ui.tag{ tag = "li", content = _"A new suggestion is created in an initiative I'm supporting" } 1.143 + ui.tag{ tag = "li", content = _"An issue in one of my areas or I'm interested in enters phase 'frozen'" } 1.144 + ui.tag{ tag = "li", content = _"Voting of an issue in one of my areas or I'm interested in starts" } 1.145 + end } 1.146 + end } 1.147 + 1.148 + ui.container{ content = function() 1.149 + ui.tag{ 1.150 + tag = "input", 1.151 + attr = { type = "radio", name = "notification_level", value = "none" } 1.152 + } 1.153 + ui.tag{ content = _"No notifications at all" } 1.154 + end } 1.155 + 1.156 + 1.157 + 1.158 + ui.submit{ value = _"Change display settings" } 1.159 + end 1.160 +} 1.161 + 1.162 +local last_id = 6000; 1.163 + 1.164 +while last_id < 6050 do 1.165 + 1.166 + local event = Event:new_selector() 1.167 + :add_where{ "event.id > ?", last_id } 1.168 + :add_order_by("event.id") 1.169 + :limit(1) 1.170 + :optional_object_mode() 1.171 + :exec() 1.172 + 1.173 + last_id = nil 1.174 + if event then 1.175 + last_id = event.id 1.176 + local members_to_notify = Member:new_selector() 1.177 + :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 } ) 1.178 + :add_where("member.activated NOTNULL AND member.notify_email NOTNULL") 1.179 + :exec() 1.180 + ui.container{ content = _("Event #{id} -> #{num} members", { id = event.id, num = #members_to_notify }) } 1.181 + 1.182 + send_notification(event) 1.183 + 1.184 + end 1.185 +end 1.186 + 1.187 + 1.188 +-- 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; 1.189 \ No newline at end of file