From 00c50d8114f5b57c704abec875bb1fc7dd0914ee Mon Sep 17 00:00:00 2001 From: yutao <283765470@qq.com> Date: Tue, 14 Jul 2015 15:16:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=B8=BB=E9=A1=B5->=E8=AE=BF?= =?UTF-8?q?=E5=AE=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 150 +++++++++++-------- app/helpers/users_helper.rb | 9 ++ app/models/visitor.rb | 3 + app/views/layouts/base_users_new.html.erb | 29 ++-- app/views/users/user_fanslist.html.erb | 7 +- config/routes.rb | 1 + db/migrate/20150714161100_create_visitors.rb | 14 ++ 7 files changed, 134 insertions(+), 79 deletions(-) create mode 100644 app/models/visitor.rb create mode 100644 db/migrate/20150714161100_create_visitors.rb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d89dc35a3..79c498dbf 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -26,10 +26,10 @@ class UsersController < ApplicationController menu_item :user_homework, :only => :user_homeworks menu_item :user_project, :only => [:user_projects, :watch_projects] # menu_item :requirement_focus, :only => :watch_bids - menu_item :requirement_focus, :only => :watch_contests + menu_item :requirement_focus, :only => :watch_contests menu_item :user_newfeedback, :only => :user_newfeedback - - + + #Ended by young # edit @@ -40,24 +40,27 @@ class UsersController < ApplicationController :user_watchlist, :user_fanslist,:update, :user_courses, :user_homeworks, :watch_projects, :show_score, :topic_score_index, :project_score_index, :activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index, :activity_new_score_index, :influence_new_score_index, :score_new_index,:update_score,:user_activities,:user_projects_index, - :user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show] + :user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist] #edit has been deleted by huang, 2013-9-23 - before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses, - :user_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments, + before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses, + :user_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index, :activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index, :activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index, - :user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show] + :user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist] before_filter :auth_user_extension, only: :show #before_filter :rest_user_score, only: :show #before_filter :select_entry, only: :user_projects accept_api_auth :index, :show, :create, :update, :destroy,:tag_save , :tag_saveEx - + #william before_filter :require_login, :only => [:tag_save,:tag_saveEx] #before_filter :refresh_changests, :only =>[:user_activities,:user_courses,:user_projects,:user_newfeedback] + #visitor + before_filter :recorded_visitor, :only => [:show,:user_fanslist,:user_watchlist,:user_visitorlist] + helper :sort include SortHelper helper :custom_fields @@ -179,21 +182,21 @@ class UsersController < ApplicationController # format.api # end end - + #new add by linchun - def watch_contests - @bids = Contest.watched_by(@user) + def watch_contests + @bids = Contest.watched_by(@user) @offset, @limit = api_offset_and_limit({:limit => 10}) @contest_count = @contests.count @contest_pages = Paginator.new @contest_count, @limit, params['page'] - @offset ||= @contest_pages.reverse_offset + @offset ||= @contest_pages.reverse_offset unless @offset == 0 @contest = @contests.offset(@offset).limit(@limit).all.reverse else limit = @bid_count % @limit @contest = @contests.offset(@offset).limit(limit).all.reverse end - + respond_to do |format| format.html { render :layout => 'base_users' @@ -230,9 +233,9 @@ class UsersController < ApplicationController end end # end - + # added by huang - def user_homeworks + def user_homeworks # @membership = @user.memberships.all(:conditions => Project.visible_condition(User.current)) # @memberships = [] # @membership.each do |membership| @@ -251,9 +254,9 @@ class UsersController < ApplicationController # return # end # end - end - - + end + + include CoursesHelper def user_courses @@ -334,7 +337,7 @@ class UsersController < ApplicationController #end def index - + @status = params[:status] || 1 sort_init 'login', 'asc' sort_update %w(login firstname lastname mail admin created_on last_login_on) @@ -350,7 +353,7 @@ class UsersController < ApplicationController # 先内连一下statuses 保证排序之后数量一致 scope = User.visible. joins("INNER JOIN user_statuses ON users.id = user_statuses.user_id") - + # unknow scope = scope.in_group(params[:group_id]) if params[:group_id].present? @@ -387,7 +390,7 @@ class UsersController < ApplicationController # limit and offset @users = @users.limit(@user_pages.per_page).offset(@user_pages.offset) - + @user_base_tag = params[:id] ? 'base_users':'users_base' respond_to do |format| format.html { @@ -397,7 +400,7 @@ class UsersController < ApplicationController format.api end end - + def search sort_init 'login', 'asc' sort_update %w(login firstname lastname mail admin created_on last_login_on) @@ -601,9 +604,9 @@ class UsersController < ApplicationController end when "2" message = [] - if @user == User.current + if @user == User.current message = JournalsForMessage.reference_message(@user.id) - message += Journal.reference_message(@user.id) + message += Journal.reference_message(@user.id) end @activity_count = message.size @info_pages = Paginator.new @activity_count, pre_count, params['page'] @@ -634,7 +637,7 @@ class UsersController < ApplicationController p_ids = [] Project.where(id: project_ids).each do |x| p_ids << x.id unless x.visible?(User.current) - end + end ids = [] ids << Issue.where(id: act_ids, project_id: p_ids).map{|x| x.id} @@ -653,7 +656,7 @@ class UsersController < ApplicationController p_ids = [] Project.where(id: project_ids).each do |x| p_ids << x.id unless x.visible?(User.current) - end + end ids << Journal.where(id: act_ids, journalized_id: p_ids, journalized_type: 'Project').map{|x| x.id} #News @@ -662,16 +665,16 @@ class UsersController < ApplicationController p_ids = [] Project.where(id: project_ids).each do |x| p_ids << x.id unless x.visible?(User.current) - end + end ids << News.where(id: act_ids, project_id: p_ids).map{|x| x.id} project_ids = News.where(id: act_ids).select('distinct course_id').map{|x| x.course_id} c_ids = [] Course.where(id: project_ids).each do |x| c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x) - end + end ids << News.where(id: act_ids, course_id: p_ids).map{|x| x.id} - + #Message act_ids = activity.where(act_type: 'Message').select('act_id').map{|x| x.act_id} board_ids = Message.where(id: act_ids).select('distinct board_id').map{|x| x.board_id} @@ -679,14 +682,14 @@ class UsersController < ApplicationController p_ids = [] Project.where(id: project_ids).each do |x| p_ids << x.id unless x.visible?(User.current) - end + end ids << Message.where(id: act_ids, board_id: p_ids).map{|x| x.id} - + project_ids = Board.where(id: board_ids).select('distinct course_id').map{|x| x.course_id} c_ids = [] Course.where(id: project_ids).each do |x| c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x) - end + end ids << Message.where(id: act_ids, board_id: c_ids).map{|x| x.id} logger.debug "filter ids #{ids}" @@ -704,33 +707,33 @@ class UsersController < ApplicationController # (e.act_type == "Message" && !e.act.board.nil? && ((!e.act.board.project.nil? && !e.act.board.project.visible?(User.current)) || (!e.act.board.course.nil? && e.act.board.course.is_public == 0 && !User.current.member_of_course?(e.act.board.course)))))) # } # - + @activity_count = activity.count @activity_pages = Paginator.new @activity_count, pre_count, params['page'] @activity = activity.slice(@activity_pages.offset,@activity_pages.per_page) @state = 0 end - + if params[:user].present? - + user_temp = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{params[:user]}%' or lastname like '%#{params[:user]}%'") - + if user_temp.size > 1 - activity = Activity.where('user_id in (?)', user_temp).where('user_id in (?)', watcher).order('id desc') + activity = Activity.where('user_id in (?)', user_temp).where('user_id in (?)', watcher).order('id desc') elsif user_temp.size == 1 - activity = Activity.where('user_id = ?', user_temp).where('user_id in (?)', watcher).order('id desc') + activity = Activity.where('user_id = ?', user_temp).where('user_id in (?)', watcher).order('id desc') else activity = Activity.where("1 = 0") end @offset, @limit = api_offset_and_limit({:limit => 10}) - @activity_count = activity.count + @activity_count = activity.count @activity_pages = Paginator.new @activity_count, @limit, params['page'] @offset ||= @activity_pages.offset - @activity = activity.offset(@offset).limit(@limit) + @activity = activity.offset(@offset).limit(@limit) @state = 0 end - - + + #Modified by nie unless User.current.admin? if !@user.active? #|| (@user != User.current && @memberships.empty? && events.empty?) @@ -752,17 +755,17 @@ class UsersController < ApplicationController def info message = [] - if @user == User.current + if @user == User.current message = JournalsForMessage.reference_message(@user.id) - message += Journal.reference_message(@user.id) + message += Journal.reference_message(@user.id) end @offset, @limit = api_offset_and_limit({:limit => 10}) @info_count = message.size @info_pages = Paginator.new @info_count, @limit, params['page'] @offset ||= @info_pages.offset - + messages = message.sort {|x,y| y.created_on <=> x.created_on } - + @message = messages[@offset, @limit] unless User.current.admin? @@ -778,7 +781,7 @@ class UsersController < ApplicationController end end #### end - + def new @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option) @@ -836,7 +839,7 @@ class UsersController < ApplicationController @auth_sources = AuthSource.all @membership ||= Member.new end - + def watch_projects @watch_projects = Project.joins(:watchers).where("project_type <>? and watchable_type = ? and `watchers`.user_id = ?", '1','Project', @user.id) @state = 1 @@ -1025,36 +1028,47 @@ class UsersController < ApplicationController @action = 'fans' render :layout=>'base_users_new' end - + def user_visitorlist + limit = 10; + #query = @user.watcher_users; + query = User.joins("join visitors v on #{User.table_name}.id=v.user_id") + query = query.where("v.master_id=?",@user.id) + @obj_count = query.count(); + @obj_pages = Paginator.new @obj_count,limit,params['page'] + @list = query.order("v.updated_on desc").limit(limit).offset(@obj_pages.offset).all(); + @action = 'visitor' + render :template=>'users/user_fanslist',:layout=>'base_users_new' + end + #william def update_extensions(user_extensions) user_extensions = params[:user_extensions] unless user_extensions.nil? user_extensions = UserExtensions.find_by_id(user_extensions.user_id) - + # user_extensions. end end # added by bai def topic_score_index - + end - + def project_score_index - + end - + def activity_score_index - + end - + def influence_score_index - + end - + def score_index - + end # end def topic_new_score_index @@ -1100,7 +1114,7 @@ class UsersController < ApplicationController # 必填自己的工作单位,其实就是学校 def auth_user_extension - if @user == User.current && @user.user_extensions.nil? + if @user == User.current && @user.user_extensions.nil? flash[:error] = l(:error_complete_occupation) redirect_to my_account_url end @@ -1128,4 +1142,20 @@ class UsersController < ApplicationController render_404 end end + + def recorded_visitor + if(User.current.logged? && User.current != @user) + #impl = Visitor.where('user_id=? and master_id=?',User.current.id,@user.id).find; + # impl = Visitor.find_by_sql('user_id=? and master_id=?',[User.current.id,@user.id]); + impl = Visitor.find_by_user_id_and_master_id(User.current.id,@user.id); + if(impl.nil?) + impl = Visitor.new + impl.user_id = User.current.id + impl.master_id = @user.id + else + impl.updated_on = Time.now + end + impl.save + end + end end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 8f8f38878..2a1852807 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -321,6 +321,15 @@ module UsersHelper list = obj.watcher_users.order("#{Watcher.table_name}.id desc").limit(10).all return [count,list]; end + def get_visitor_users(obj) + query = Visitor.where("master_id=?",obj.id) + count = query.count + if count == 0 + return [0,[]] + end + list = query.order("updated_on desc").limit(10).all + return [count,list]; + end def get_create_course_count(user) return Course.where("tea_id = ?",user.id).count() diff --git a/app/models/visitor.rb b/app/models/visitor.rb new file mode 100644 index 000000000..6563fde16 --- /dev/null +++ b/app/models/visitor.rb @@ -0,0 +1,3 @@ +class Visitor < ActiveRecord::Base + belongs_to :user +end \ No newline at end of file diff --git a/app/views/layouts/base_users_new.html.erb b/app/views/layouts/base_users_new.html.erb index 7277761ce..c0fe7421a 100644 --- a/app/views/layouts/base_users_new.html.erb +++ b/app/views/layouts/base_users_new.html.erb @@ -253,23 +253,18 @@ $(".subNav").click(function(){ <%= render :partial => 'layouts/user_watch_list', :locals => {:user => @user} %> <%= render :partial => 'layouts/user_fans_list', :locals => {:user => @user} %> - - - - - - - - - - - - - - - - - + <% visitor_count,visitor_list = get_visitor_users(@user) %> +