个人主页

This commit is contained in:
yutao 2015-07-17 15:07:01 +08:00
parent 8d858cccfc
commit 2efb4833f2
3 changed files with 41 additions and 24 deletions

View File

@ -82,6 +82,7 @@ class UsersController < ApplicationController
# fq
helper :words
helper :project_score
helper :issues
include UsersHelper
def refresh_changests
@ -587,11 +588,21 @@ class UsersController < ApplicationController
user_ids << @user.id
end
query = Activity.where(user_id: user_ids)
if(lastid != nil)
query = query.where("id < ?",lastid)
query = Activity.joins("join courses c on c.id=#{Activity.table_name}.activity_container_id and #{Activity.table_name}.activity_container_type='Course'")
query = query.where("#{Activity.table_name}.user_id in (?)", user_ids)
if User.current != @user #看别人
if @user.user_extensions!=nil && @user.user_extensions.identity == 0 #看老师
query = query.joins("join members m on c.id=m.course_id and m.user_id = #{@user.id}")
query = query.joins("join member_roles r on m.id = r.member_id")
query = query.where("r.role_id in(3,7,9)")
end
query = query.where("c.is_public=1")
end
@list = query_activities(query,'Course');
if(lastid != nil)
query = query.where("#{Activity.table_name}.id < ?",lastid)
end
query = query.order("#{Activity.table_name}.id desc")
@list = query_activities(query)
render :layout=>nil
end
@ -611,11 +622,16 @@ class UsersController < ApplicationController
user_ids << @user.id
end
query = Activity.where(user_id: user_ids)
if(lastid != nil)
query = query.where("id < ?",lastid)
query = Activity.joins("join projects c on c.id=#{Activity.table_name}.activity_container_id and #{Activity.table_name}.activity_container_type='Project'")
query = query.where(user_id: user_ids)
if User.current != @user #看别人
query = query.where("c.is_public=1")
end
@list = query_activities(query,'Project');
if(lastid != nil)
query = query.where("#{Activity.table_name}.id < ?",lastid)
end
query = query.order("#{Activity.table_name}.id desc")
@list = query_activities(query);
render :action=>'user_course_activities',:layout=>nil
end

View File

@ -395,27 +395,27 @@ module UsersHelper
#
# return e;
# end
def query_activities(query,type)
query = query.where("activity_container_type = ?",type)
list = query.order("id desc").limit(8).all
def query_activities(query)
list = query.limit(8).all
result = [];
for item in list
container = get_activity_container(item,type)
container = get_activity_container(item)
result << { :item=>item,:e=>container }
end
return result
end
def get_activity_container activity,type
if type == 'Project'
return activity.act.project if activity.act.respond_to?('project')
end
if type == 'Course'
if activity.act_type == 'Poll'
return Course.find_by_id(activity.act.polls_group_id)
end
return activity.act.course if activity.act.respond_to?('course')
end
return nil;
def get_activity_container activity
return activity.activity_container
# if type == 'Project'
# return activity.act.project if activity.act.respond_to?('project')
# end
# if type == 'Course'
# if activity.act_type == 'Poll'
# return Course.find_by_id(activity.act.polls_group_id)
# end
# return activity.act.course if activity.act.respond_to?('course')
# end
# return nil;
end
# def activity_is_show(activity,e)
@ -447,7 +447,7 @@ module UsersHelper
when "Issue"
return activity.act.subject
when "Journal"
return activity.act.notes
return details_to_strings(activity.act.details,true).to_s
when "JournalsForMessage"
return activity.act.notes
when "Message"

View File

@ -2,6 +2,7 @@ class Activity < ActiveRecord::Base
attr_accessible :act_id, :act_type, :user_id
belongs_to :act, :polymorphic => true
belongs_to :user
belongs_to :activity_container, polymorphic: true
validates :act_id, presence: true
validates :act_type, presence: true
validates :user_id, presence: true