liquid_feedback_frontend

changeset 287:ee477a136fd4

Moved notification functions to model
author bsw
date Sat Feb 25 12:04:36 2012 +0100 (2012-02-25)
parents c587d8762e62
children ad5d7a4eb13d
files app/main/member/settings_notification.lua model/event.lua
line diff
     1.1 --- a/app/main/member/settings_notification.lua	Sat Feb 25 11:51:37 2012 +0100
     1.2 +++ b/app/main/member/settings_notification.lua	Sat Feb 25 12:04:36 2012 +0100
     1.3 @@ -1,58 +1,3 @@
     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 @@ -155,31 +100,5 @@
    1.63      ui.submit{ value = _"Change display settings" }
    1.64    end
    1.65  }
    1.66 -
    1.67 -local last_id = 6000;
    1.68 -
    1.69 -while last_id < 6050 do
    1.70 -
    1.71 -  local event = Event:new_selector()
    1.72 -    :add_where{ "event.id > ?", last_id }
    1.73 -    :add_order_by("event.id")
    1.74 -    :limit(1)
    1.75 -    :optional_object_mode()
    1.76 -    :exec()
    1.77 -
    1.78 -  last_id = nil
    1.79 -  if event then
    1.80 -    last_id = event.id
    1.81 -    local members_to_notify = Member:new_selector()
    1.82 -      :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.83 -      :add_where("member.activated NOTNULL AND member.notify_email NOTNULL")
    1.84 -      :exec()
    1.85 -    ui.container{ content = _("Event #{id} -> #{num} members", { id = event.id, num = #members_to_notify }) }
    1.86 -    
    1.87 -    send_notification(event)
    1.88 -
    1.89 -  end
    1.90 -end
    1.91 -
    1.92 -  
    1.93 + 
    1.94  -- 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.95 \ No newline at end of file
     2.1 --- a/model/event.lua	Sat Feb 25 11:51:37 2012 +0100
     2.2 +++ b/model/event.lua	Sat Feb 25 12:04:36 2012 +0100
     2.3 @@ -7,4 +7,87 @@
     2.4    this_key      = 'issue_id',
     2.5    that_key      = 'id',
     2.6    ref           = 'issue',
     2.7 -}
     2.8 \ No newline at end of file
     2.9 +}
    2.10 +
    2.11 +function Event.object:send_notification() 
    2.12 +
    2.13 +  local url
    2.14 +
    2.15 +  local body = ""
    2.16 +  
    2.17 +  body = body .. _("      Unit: #{name}\n", { name = self.issue.area.unit.name })
    2.18 +  body = body .. _("      Area: #{name}\n", { name = self.issue.area.name })
    2.19 +  body = body .. _("     Issue: ##{id}\n", { id = self.issue_id })
    2.20 +  body = body .. _("    Policy: #{phase}\n", { phase = self.issue.policy.name })
    2.21 +  body = body .. _("     Phase: #{phase}\n\n", { phase = self.state })
    2.22 +  body = body .. _("     Event: #{event}\n\n", { event = self.event })
    2.23 +
    2.24 +  if self.initiative_id then
    2.25 +    url = request.get_absolute_baseurl() .. "initiative/show/" .. self.initiative_id .. ".html"
    2.26 +  elseif self.suggestion_id then
    2.27 +    url = request.get_absolute_baseurl() .. "suggestion/show/" .. self.suggestion_id .. ".html"
    2.28 +  else
    2.29 +    url = request.get_absolute_baseurl() .. "issue/show/" .. self.issue_id .. ".html"
    2.30 +  end
    2.31 +  
    2.32 +  body = body .. _("       URL: #{url}\n\n", { url = url })
    2.33 +  
    2.34 +  if self.initiative_id then
    2.35 +    local initiative = Initiative:by_id(self.initiative_id)
    2.36 +    body = body .. _("i#{id}: #{name}\n\n", { id = initiative.id, name = initiative.name })
    2.37 +  else
    2.38 +    local initiative_count = Initiative:new_selector()
    2.39 +      :add_where{ "initiative.issue_id = ?", self.issue_id }
    2.40 +      :count()
    2.41 +    local initiatives = Initiative:new_selector()
    2.42 +      :add_where{ "initiative.issue_id = ?", self.issue_id }
    2.43 +      :add_order_by("initiative.supporter_count DESC")
    2.44 +      :limit(3)
    2.45 +      :exec()
    2.46 +    for i, initiative in ipairs(initiatives) do
    2.47 +      body = body .. _("i#{id}: #{name}\n", { id = initiative.id, name = initiative.name })
    2.48 +    end
    2.49 +    if initiative_count - 3 > 0 then
    2.50 +      body = body .. _("and #{count} more initiatives\n", { count = initiative_count })
    2.51 +    end
    2.52 +    body = body .. "\n"
    2.53 +  end
    2.54 +  
    2.55 +  if self.suggestion_id then
    2.56 +    local suggestion = Suggestion:by_id(self.suggestion_id)
    2.57 +    body = body .. _("#{name}\n\n", { name = suggestion.name })
    2.58 +  end
    2.59 +  
    2.60 +  slot.put("<pre>", encode.html_newlines(body), "</pre>")
    2.61 +  slot.put("<hr />")
    2.62 +end
    2.63 +
    2.64 +function Event:send_next_notification(last_event_id)
    2.65 +
    2.66 +  local event = Event:new_selector()
    2.67 +    :add_where{ "event.id > ?", last_id }
    2.68 +    :add_order_by("event.id")
    2.69 +    :limit(1)
    2.70 +    :optional_object_mode()
    2.71 +    :exec()
    2.72 +
    2.73 +  last_id = nil
    2.74 +  if event then
    2.75 +    last_id = event.id
    2.76 +    local members_to_notify = Member:new_selector()
    2.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 } )
    2.78 +      :add_where("member.activated NOTNULL AND member.notify_email NOTNULL")
    2.79 +      :exec()
    2.80 +      
    2.81 +    ui.container{ content = _("Event #{id} -> #{num} members", { id = event.id, num = #members_to_notify }) }
    2.82 +    
    2.83 +    event:send_notification()
    2.84 +    
    2.85 +    return event.id
    2.86 +
    2.87 +  else
    2.88 +    return last_event_id
    2.89 +
    2.90 +  end
    2.91 +
    2.92 +end
    2.93 \ No newline at end of file

Impressum / About Us