liquid_feedback_frontend
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/app/main/initiative/_action/add_support.lua Wed Nov 18 12:00:00 2009 +0100 1.3 @@ -0,0 +1,27 @@ 1.4 +local initiative = Initiative:new_selector():add_where{ "id = ?", param.get_id()}:single_object_mode():exec() 1.5 + 1.6 +local member = app.session.member 1.7 + 1.8 +local supporter = Supporter:by_pk(initiative.id, member.id) 1.9 + 1.10 +local last_draft = Draft:new_selector() 1.11 + :add_where{ "initiative_id = ?", initiative.id } 1.12 + :add_order_by("id DESC") 1.13 + :limit(1) 1.14 + :single_object_mode() 1.15 + :exec() 1.16 + 1.17 +if not supporter then 1.18 + supporter = Supporter:new() 1.19 + supporter.member_id = member.id 1.20 + supporter.initiative_id = initiative.id 1.21 + supporter.draft_id = last_draft.id 1.22 + supporter:save() 1.23 + slot.put_into("notice", _"Your support has been added to this initiative") 1.24 +elseif supporter.draft_id ~= last_draft.id then 1.25 + supporter.draft_id = last_draft.id 1.26 + supporter:save() 1.27 + slot.put_into("notice", _"Your support has been updated to the latest draft") 1.28 +else 1.29 + slot.put_into("notice", _"You are already supporting the latest draft") 1.30 +end 1.31 \ No newline at end of file