liquid_feedback_frontend

diff model/event.lua @ 287:ee477a136fd4

Moved notification functions to model
author bsw
date Sat Feb 25 12:04:36 2012 +0100 (2012-02-25)
parents c587d8762e62
children a80e74881caf
line diff
     1.1 --- a/model/event.lua	Sat Feb 25 11:51:37 2012 +0100
     1.2 +++ b/model/event.lua	Sat Feb 25 12:04:36 2012 +0100
     1.3 @@ -7,4 +7,87 @@
     1.4    this_key      = 'issue_id',
     1.5    that_key      = 'id',
     1.6    ref           = 'issue',
     1.7 -}
     1.8 \ No newline at end of file
     1.9 +}
    1.10 +
    1.11 +function Event.object:send_notification() 
    1.12 +
    1.13 +  local url
    1.14 +
    1.15 +  local body = ""
    1.16 +  
    1.17 +  body = body .. _("      Unit: #{name}\n", { name = self.issue.area.unit.name })
    1.18 +  body = body .. _("      Area: #{name}\n", { name = self.issue.area.name })
    1.19 +  body = body .. _("     Issue: ##{id}\n", { id = self.issue_id })
    1.20 +  body = body .. _("    Policy: #{phase}\n", { phase = self.issue.policy.name })
    1.21 +  body = body .. _("     Phase: #{phase}\n\n", { phase = self.state })
    1.22 +  body = body .. _("     Event: #{event}\n\n", { event = self.event })
    1.23 +
    1.24 +  if self.initiative_id then
    1.25 +    url = request.get_absolute_baseurl() .. "initiative/show/" .. self.initiative_id .. ".html"
    1.26 +  elseif self.suggestion_id then
    1.27 +    url = request.get_absolute_baseurl() .. "suggestion/show/" .. self.suggestion_id .. ".html"
    1.28 +  else
    1.29 +    url = request.get_absolute_baseurl() .. "issue/show/" .. self.issue_id .. ".html"
    1.30 +  end
    1.31 +  
    1.32 +  body = body .. _("       URL: #{url}\n\n", { url = url })
    1.33 +  
    1.34 +  if self.initiative_id then
    1.35 +    local initiative = Initiative:by_id(self.initiative_id)
    1.36 +    body = body .. _("i#{id}: #{name}\n\n", { id = initiative.id, name = initiative.name })
    1.37 +  else
    1.38 +    local initiative_count = Initiative:new_selector()
    1.39 +      :add_where{ "initiative.issue_id = ?", self.issue_id }
    1.40 +      :count()
    1.41 +    local initiatives = Initiative:new_selector()
    1.42 +      :add_where{ "initiative.issue_id = ?", self.issue_id }
    1.43 +      :add_order_by("initiative.supporter_count DESC")
    1.44 +      :limit(3)
    1.45 +      :exec()
    1.46 +    for i, initiative in ipairs(initiatives) do
    1.47 +      body = body .. _("i#{id}: #{name}\n", { id = initiative.id, name = initiative.name })
    1.48 +    end
    1.49 +    if initiative_count - 3 > 0 then
    1.50 +      body = body .. _("and #{count} more initiatives\n", { count = initiative_count })
    1.51 +    end
    1.52 +    body = body .. "\n"
    1.53 +  end
    1.54 +  
    1.55 +  if self.suggestion_id then
    1.56 +    local suggestion = Suggestion:by_id(self.suggestion_id)
    1.57 +    body = body .. _("#{name}\n\n", { name = suggestion.name })
    1.58 +  end
    1.59 +  
    1.60 +  slot.put("<pre>", encode.html_newlines(body), "</pre>")
    1.61 +  slot.put("<hr />")
    1.62 +end
    1.63 +
    1.64 +function Event:send_next_notification(last_event_id)
    1.65 +
    1.66 +  local event = Event:new_selector()
    1.67 +    :add_where{ "event.id > ?", last_id }
    1.68 +    :add_order_by("event.id")
    1.69 +    :limit(1)
    1.70 +    :optional_object_mode()
    1.71 +    :exec()
    1.72 +
    1.73 +  last_id = nil
    1.74 +  if event then
    1.75 +    last_id = event.id
    1.76 +    local members_to_notify = Member:new_selector()
    1.77 +      :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.78 +      :add_where("member.activated NOTNULL AND member.notify_email NOTNULL")
    1.79 +      :exec()
    1.80 +      
    1.81 +    ui.container{ content = _("Event #{id} -> #{num} members", { id = event.id, num = #members_to_notify }) }
    1.82 +    
    1.83 +    event:send_notification()
    1.84 +    
    1.85 +    return event.id
    1.86 +
    1.87 +  else
    1.88 +    return last_event_id
    1.89 +
    1.90 +  end
    1.91 +
    1.92 +end
    1.93 \ No newline at end of file

Impressum / About Us