bsw@286: Event = mondelefant.new_class() bsw@286: Event.table = 'event' bsw@286: bsw@286: Event:add_reference{ bsw@286: mode = 'm1', bsw@286: to = "Issue", bsw@286: this_key = 'issue_id', bsw@286: that_key = 'id', bsw@286: ref = 'issue', bsw@287: } bsw@287: bsw@287: function Event.object:send_notification() bsw@287: bsw@287: local url bsw@287: bsw@287: local body = "" bsw@287: bsw@287: body = body .. _(" Unit: #{name}\n", { name = self.issue.area.unit.name }) bsw@287: body = body .. _(" Area: #{name}\n", { name = self.issue.area.name }) bsw@287: body = body .. _(" Issue: ##{id}\n", { id = self.issue_id }) bsw@287: body = body .. _(" Policy: #{phase}\n", { phase = self.issue.policy.name }) bsw@287: body = body .. _(" Phase: #{phase}\n\n", { phase = self.state }) bsw@287: body = body .. _(" Event: #{event}\n\n", { event = self.event }) bsw@287: bsw@287: if self.initiative_id then bsw@287: url = request.get_absolute_baseurl() .. "initiative/show/" .. self.initiative_id .. ".html" bsw@287: elseif self.suggestion_id then bsw@287: url = request.get_absolute_baseurl() .. "suggestion/show/" .. self.suggestion_id .. ".html" bsw@287: else bsw@287: url = request.get_absolute_baseurl() .. "issue/show/" .. self.issue_id .. ".html" bsw@287: end bsw@287: bsw@287: body = body .. _(" URL: #{url}\n\n", { url = url }) bsw@287: bsw@287: if self.initiative_id then bsw@287: local initiative = Initiative:by_id(self.initiative_id) bsw@287: body = body .. _("i#{id}: #{name}\n\n", { id = initiative.id, name = initiative.name }) bsw@287: else bsw@287: local initiative_count = Initiative:new_selector() bsw@287: :add_where{ "initiative.issue_id = ?", self.issue_id } bsw@287: :count() bsw@287: local initiatives = Initiative:new_selector() bsw@287: :add_where{ "initiative.issue_id = ?", self.issue_id } bsw@287: :add_order_by("initiative.supporter_count DESC") bsw@287: :limit(3) bsw@287: :exec() bsw@287: for i, initiative in ipairs(initiatives) do bsw@287: body = body .. _("i#{id}: #{name}\n", { id = initiative.id, name = initiative.name }) bsw@287: end bsw@287: if initiative_count - 3 > 0 then bsw@287: body = body .. _("and #{count} more initiatives\n", { count = initiative_count }) bsw@287: end bsw@287: body = body .. "\n" bsw@287: end bsw@287: bsw@287: if self.suggestion_id then bsw@287: local suggestion = Suggestion:by_id(self.suggestion_id) bsw@287: body = body .. _("#{name}\n\n", { name = suggestion.name }) bsw@287: end bsw@287: bsw@287: slot.put("
", encode.html_newlines(body), "
") bsw@287: slot.put("
") bsw@287: end bsw@287: bsw@287: function Event:send_next_notification(last_event_id) bsw@287: bsw@287: local event = Event:new_selector() bsw@287: :add_where{ "event.id > ?", last_id } bsw@287: :add_order_by("event.id") bsw@287: :limit(1) bsw@287: :optional_object_mode() bsw@287: :exec() bsw@287: bsw@287: last_id = nil bsw@287: if event then bsw@287: last_id = event.id bsw@287: local members_to_notify = Member:new_selector() bsw@287: :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@287: :add_where("member.activated NOTNULL AND member.notify_email NOTNULL") bsw@287: :exec() bsw@287: bsw@287: ui.container{ content = _("Event #{id} -> #{num} members", { id = event.id, num = #members_to_notify }) } bsw@287: bsw@287: event:send_notification() bsw@287: bsw@287: return event.id bsw@287: bsw@287: else bsw@287: return last_event_id bsw@287: bsw@287: end bsw@287: bsw@287: end