liquid_feedback_frontend
view app/main/initiative/_action/add_support.lua @ 0:3bfb2fcf7ab9
Version alpha1
author | bsw/jbe |
---|---|
date | Wed Nov 18 12:00:00 2009 +0100 (2009-11-18) |
parents | |
children | afd9f769c7ae |
line source
1 local initiative = Initiative:new_selector():add_where{ "id = ?", param.get_id()}:single_object_mode():exec()
3 local member = app.session.member
5 local supporter = Supporter:by_pk(initiative.id, member.id)
7 local last_draft = Draft:new_selector()
8 :add_where{ "initiative_id = ?", initiative.id }
9 :add_order_by("id DESC")
10 :limit(1)
11 :single_object_mode()
12 :exec()
14 if not supporter then
15 supporter = Supporter:new()
16 supporter.member_id = member.id
17 supporter.initiative_id = initiative.id
18 supporter.draft_id = last_draft.id
19 supporter:save()
20 slot.put_into("notice", _"Your support has been added to this initiative")
21 elseif supporter.draft_id ~= last_draft.id then
22 supporter.draft_id = last_draft.id
23 supporter:save()
24 slot.put_into("notice", _"Your support has been updated to the latest draft")
25 else
26 slot.put_into("notice", _"You are already supporting the latest draft")
27 end