liquid_feedback_frontend
view model/event.lua @ 356:7ee7ec1b10fc
Fix link to area list in navigation (single unit mode)
| author | bsw | 
|---|---|
| date | Wed Feb 29 20:31:21 2012 +0100 (2012-02-29) | 
| parents | ee477a136fd4 | 
| children | a80e74881caf | 
 line source
     1 Event = mondelefant.new_class()
     2 Event.table = 'event'
     4 Event:add_reference{
     5   mode          = 'm1',
     6   to            = "Issue",
     7   this_key      = 'issue_id',
     8   that_key      = 'id',
     9   ref           = 'issue',
    10 }
    12 function Event.object:send_notification() 
    14   local url
    16   local body = ""
    18   body = body .. _("      Unit: #{name}\n", { name = self.issue.area.unit.name })
    19   body = body .. _("      Area: #{name}\n", { name = self.issue.area.name })
    20   body = body .. _("     Issue: ##{id}\n", { id = self.issue_id })
    21   body = body .. _("    Policy: #{phase}\n", { phase = self.issue.policy.name })
    22   body = body .. _("     Phase: #{phase}\n\n", { phase = self.state })
    23   body = body .. _("     Event: #{event}\n\n", { event = self.event })
    25   if self.initiative_id then
    26     url = request.get_absolute_baseurl() .. "initiative/show/" .. self.initiative_id .. ".html"
    27   elseif self.suggestion_id then
    28     url = request.get_absolute_baseurl() .. "suggestion/show/" .. self.suggestion_id .. ".html"
    29   else
    30     url = request.get_absolute_baseurl() .. "issue/show/" .. self.issue_id .. ".html"
    31   end
    33   body = body .. _("       URL: #{url}\n\n", { url = url })
    35   if self.initiative_id then
    36     local initiative = Initiative:by_id(self.initiative_id)
    37     body = body .. _("i#{id}: #{name}\n\n", { id = initiative.id, name = initiative.name })
    38   else
    39     local initiative_count = Initiative:new_selector()
    40       :add_where{ "initiative.issue_id = ?", self.issue_id }
    41       :count()
    42     local initiatives = Initiative:new_selector()
    43       :add_where{ "initiative.issue_id = ?", self.issue_id }
    44       :add_order_by("initiative.supporter_count DESC")
    45       :limit(3)
    46       :exec()
    47     for i, initiative in ipairs(initiatives) do
    48       body = body .. _("i#{id}: #{name}\n", { id = initiative.id, name = initiative.name })
    49     end
    50     if initiative_count - 3 > 0 then
    51       body = body .. _("and #{count} more initiatives\n", { count = initiative_count })
    52     end
    53     body = body .. "\n"
    54   end
    56   if self.suggestion_id then
    57     local suggestion = Suggestion:by_id(self.suggestion_id)
    58     body = body .. _("#{name}\n\n", { name = suggestion.name })
    59   end
    61   slot.put("<pre>", encode.html_newlines(body), "</pre>")
    62   slot.put("<hr />")
    63 end
    65 function Event:send_next_notification(last_event_id)
    67   local event = Event:new_selector()
    68     :add_where{ "event.id > ?", last_id }
    69     :add_order_by("event.id")
    70     :limit(1)
    71     :optional_object_mode()
    72     :exec()
    74   last_id = nil
    75   if event then
    76     last_id = event.id
    77     local members_to_notify = Member:new_selector()
    78       :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 } )
    79       :add_where("member.activated NOTNULL AND member.notify_email NOTNULL")
    80       :exec()
    82     ui.container{ content = _("Event #{id} -> #{num} members", { id = event.id, num = #members_to_notify }) }
    84     event:send_notification()
    86     return event.id
    88   else
    89     return last_event_id
    91   end
    93 end
