From a4450972b735d391ee5f364503a18a5126482b83 Mon Sep 17 00:00:00 2001 From: Pavel Date: Tue, 16 Mar 2010 09:06:41 +0200 Subject: [PATCH] Extra publishing so far --- online/app/controllers/user_controller.rb | 80 ++++++++++++++++++++----------- online/app/models/user.rb | 4 ++ online/app/views/user/greetings.fbml.erb | 23 ++++++++- 3 files changed, 78 insertions(+), 29 deletions(-) diff --git a/online/app/controllers/user_controller.rb b/online/app/controllers/user_controller.rb index 393c32a..ada0f0b 100644 --- a/online/app/controllers/user_controller.rb +++ b/online/app/controllers/user_controller.rb @@ -2,13 +2,16 @@ class UserController < ApplicationController ensure_application_is_installed_by_facebook_user before_filter :source_statistic - + FB_app_link = "http://apps.facebook.com/friendshipchallenge" + Promotion1 = "Take the Nokia E72 friendship challenge now to know your friends better and win up to 6 Nokia E72 devices." + Pic_link = "http://img.gsmarena.com/vv/bigpic/nokia-e72.jpg" + Feed_action = "Know better your friends" def source_statistic if (params[:f]) && (params[:f].to_i != 0) add_stat(0, VISITED, params[:f] ? params[:f].to_i : 0) end end - + def permission @userF = session[:facebook_session].user if @userF.has_permission?("publish_stream") && session[:facebook_session].user.has_permission?("email") @@ -105,7 +108,6 @@ class UserController < ApplicationController for i in 0...6 if params["friend_sel0#{i}"] != nil && params["friend_sel0#{i}"] != "" # begin - @userFB2 =Facebooker::User.new(params["friend_sel0#{i}"], session_new) users_array << @userFB2 user_has_published_once = true @@ -121,64 +123,86 @@ class UserController < ApplicationController user_names = [] #for third time self_publishing = "" + scenario_themself = "" #preparing all names into array debugger - p "users_array.size = #{users_array.size}" for i in 0..(users_array.size - 1) user_names << users_array[i].first_name end #creating messages for list of friends for i in 0..(users_array.size - 1) - p "user_names: #{user_names}" - p " users_array[i].first_name: #{ users_array[i].first_name}" themessage = "" user_names_new = user_names - [users_array[i].first_name] if user_names_new.size == 0 themessage = "" elsif user_names_new.size == 1 - themessage = "#{user_names_new[0]}." + themessage = "#{user_names_new[0]}" elsif user_names_new.size == 2 - themessage = "#{user_names_new[0]} and #{user_names_new[1]}." + themessage = "#{user_names_new[0]} and #{user_names_new[1]}" elsif user_names_new.size == 3 - themessage = "#{user_names_new[0]},#{user_names_new[1]} and #{user_names_new[2]}." + themessage = "#{user_names_new[0]}, #{user_names_new[1]} and #{user_names_new[2]}" elsif user_names_new.size == 4 - themessage = "#{user_names_new[0]},#{user_names_new[1]},#{user_names_new[2]},#{user_names_new[3]}." + themessage = "#{user_names_new[0]}, #{user_names_new[1]},#{user_names_new[2]} and #{user_names_new[3]}" end #preparing for the third stage if themessage != "" - self_publishing = users_array[i].first_name + ", " + themessage + self_publishing = users_array[i].first_name + ( users_array.size > 2 ? ", ":" and ") + themessage else - self_publishing = users_array[i].first_name + "." + self_publishing = users_array[i].first_name + "" end + if themessage != "" + themessage += "." + end + session[:self_publishing] = self_publishing #publishing - if question_number == 1 - p "Publishing: > > > > >" - p "#{users_array[i].first_name}, I chat with you the most. #{themessage != "" ? "I also picked" : ""} #{themessage} Let's stay in touch" - publishing (@userFB,users_array[i],"#{users_array[i].first_name}, I chat with you the most. #{themessage != "" ? "I also picked" : ""} #{themessage} Let's stay in touch","Take the Nokia E72 challenge","http://foo.com","2Take the Nokia E72 friendship challenge now to win up to 6 Nokia E72 devices","http://foo2.com","3Take the Nokia E72 friendship challenge now to win up to 6 Nokia E72 devices",'image',"http://www.finalsense.com/news/image/mobile/nokia-6124classic.jpg","http://foo3.com") + if question_number == 1 + scenario_friend = "#{users_array[i].first_name}, I chat with you the most. #{themessage != "" ? "I also picked" : ""} #{themessage} Let's stay in touch" + scenario_themself = "selected #{@userFB.sex == "female" ? "her": "his"} top #{user_names.size()} friend#{user_names.size() == 1 ? "" : "s"} #{@userFB.sex == "female" ? "she": "he"} chat the most to win Nokia E72: #{self_publishing}. How well do you know your friends? Answer and win now!" + debug_message scenario_friend + publishing(@userFB,users_array[i],scenario_friend,Feed_action,FB_app_link,Promotion1,FB_app_link,Promotion1,'image',Pic_link,FB_app_link) elsif question_number == 2 - p "Publishing: > > > > >" - p "#{users_array[i].first_name}, you are one of #{user_names.size()} my most sporty friends. #{themessage != "" ? "I also picked" : ""} #{themessage} Let's stay in touch" - publishing (@userFB,users_array[i],"#{users_array[i].first_name}, you are one of my #{user_names.size()} most sporty friends. #{themessage != "" ? "I also picked" : ""} #{themessage} Let's stay in touch","Take the Nokia E72 challenge","http://foo.com","2Take the Nokia E72 friendship challenge now to win up to 6 Nokia E72 devices","http://foo2.com","3Take the Nokia E72 friendship challenge now to win up to 6 Nokia E72 devices",'image',"http://www.finalsense.com/news/image/mobile/nokia-6124classic.jpg","http://foo3.com") + + scenario_friend = "#{users_array[i].first_name}, you are one of my #{user_names.size()} person in the first row whom I would invite to my Birthday. #{themessage != "" ? "I also picked" : ""} #{themessage} Let's stay in touch" + scenario_themself = "selected #{@userFB.sex == "female" ? "her": "his"} top #{user_names.size()} friend#{user_names.size() == 1 ? "" : "s"} whom #{@userFB.sex == "female" ? "she": "he"} would invite to Birthday in the first raw to win Nokia E72: #{self_publishing}. How well do you know your friends? Answer and win now!" + debug_message scenario_friend + publishing(@userFB,users_array[i],scenario_friend,Feed_action,FB_app_link,Promotion1,FB_app_link,Promotion1,'image',Pic_link,FB_app_link) elsif question_number == 3 p "Publishing: > > > > >" - p "#{users_array[i].first_name}, you are of #{user_names.size()} most sporty friends. #{themessage != "" ? "I also picked" : ""} #{themessage} Let's stay in touch" - publishing (@userFB,users_array[i],"#{users_array[i].first_name}, you are of #{user_names.size()} most sporty friends. #{themessage != "" ? "I also picked" : ""} #{themessage} Let's stay in touch","Take the Nokia E72 challenge","http://foo.com","2Take the Nokia E72 friendship challenge now to win up to 6 Nokia E72 devices","http://foo2.com","3Take the Nokia E72 friendship challenge now to win up to 6 Nokia E72 devices",'image',"http://www.finalsense.com/news/image/mobile/nokia-6124classic.jpg","http://foo3.com") + scenario_friend = "#{users_array[i].first_name}, you are one of my #{user_names.size()} most sporty friends. #{themessage != "" ? "I also picked" : ""} #{themessage} Let's stay in touch" + scenario_themself = "selected #{@userFB.sex == "female" ? "her": "his"} top sporty #{user_names.size()} friend#{user_names.size() == 1 ? "" : "s"} to win Nokia E72: #{self_publishing}. How well do you know your friends? Answer and win now!" + debug_message scenario_friend + publishing(@userFB,users_array[i],scenario_friend,Feed_action,FB_app_link,Promotion1,FB_app_link,Promotion1,'image',Pic_link,FB_app_link) #end of if question_number == 1 end - #end of for i in 0..users_array.size + #end of for i in 0..users_array.size end - #selfpublishing - p "Publishing: > > > > >" - debug_message("Message was published into stream") - p "selected #{@userFB.sex == "female" ? "her": "his"} top #{user_names.size()} friend#{user_names.size() == 1 ? "" : "s"} to win Nokia E72: #{self_publishing} How well do you know your friends? Answer and win now!" - publishing (@userFB,@userFB,"selected #{@userFB.sex == "Female" ? "her": "his"} top #{user_names.size()} friend#{user_names.size() == 1 ? "" : "s"} to win Nokia E72: #{self_publishing} How well do you know your friends? Answer and win now!","Take the Nokia E72 challenge","http://foo.com","2Take the Nokia E72 friendship challenge now to win up to 6 Nokia E72 devices","http://foo2.com","3Take the Nokia E72 friendship challenge now to win up to 6 Nokia E72 devices",'image',"http://www.finalsense.com/news/image/mobile/nokia-6124classic.jpg","http://foo3.com") + debug_message scenario_themself + publishing(@userFB,@userFB,scenario_themself,Feed_action,FB_app_link,Promotion1,FB_app_link,Promotion1,'image',Pic_link,FB_app_link) + + @userFB2 =Facebooker::User.new(params["friend_sel0#{i}"], session_new) + debug_message("Messages was published into stream") + # if user_has_published_once == true end return user_has_published_once end def greetings + debug_message "Now session[:self_publishing] = '#{session[:self_publishing]}'" + if params[:mybutton] != nil + if params[:mybutton] == "Publish" + session_new = Facebooker::Session.create + @userFB = Facebooker::User.new(session[:facebook_session].user.uid, session_new) + random_friend_num = rand(@userFB.friends.size) + @userFB2 = Facebooker::User.new(@userFB.friends[random_friend_num].uid, session_new) + + scenario_themself = "#{@userFB2.first_name}, I picked up #{params[:self_publishing]} as my top friends to win Nokia E72. Sorry I didn't pick you, but you can try your luck here." + debug_message scenario_themself + publishing(@userFB,@userFB,scenario_themself,Feed_action,FB_app_link,Promotion1,FB_app_link,Promotion1,'image',Pic_link,FB_app_link) + end + redirect_to "http://facebook.com" + end end def product @@ -187,7 +211,7 @@ class UserController < ApplicationController def fanpage end - def publishing (user_from,user_to,main_message,action_link_text,action_link_href,attachment_name,attachment_href,attachment_caption,media_type,media_src,media_href) + def publishing(user_from,user_to,main_message,action_link_text,action_link_href,attachment_name,attachment_href,attachment_caption,media_type,media_src,media_href) user_from.publish_to(user_to, :message => main_message, :action_links => [ diff --git a/online/app/models/user.rb b/online/app/models/user.rb index 4a57cf0..7c218e6 100644 --- a/online/app/models/user.rb +++ b/online/app/models/user.rb @@ -1,2 +1,6 @@ class User < ActiveRecord::Base + class << self + attr_accessor :self_publishing + end + end diff --git a/online/app/views/user/greetings.fbml.erb b/online/app/views/user/greetings.fbml.erb index e0ea79c..db90603 100644 --- a/online/app/views/user/greetings.fbml.erb +++ b/online/app/views/user/greetings.fbml.erb @@ -1,4 +1,16 @@ - +


@@ -11,6 +23,15 @@ Increase your chances by publishing
this acivitiy to all your friends.
+
+
+
+ <% form_tag({:controller => "user", :action => "greetings"}, :method => "get") do %> + + + + <% end %> +
-- 2.11.4.GIT