diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 859f19f19..d7cf29387 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -800,11 +800,13 @@ class UsersController < ApplicationController
@user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Issue'").order('created_at desc').limit(10).offset(@page * 10)
when "project_message"
@user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Message'").order('created_at desc').limit(10).offset(@page * 10)
+ when "current_user"
+ @user_activities = UserActivity.where("user_id = #{User.current.id} and ((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}))").order('created_at desc').limit(10).offset(@page * 10)
else
- @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids}) and act_type in #{course_types}").order('created_at desc').limit(10).offset(@page * 10)
+ @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})").order('created_at desc').limit(10).offset(@page * 10)
end
else
- @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids}) and act_type in #{course_types}").order('created_at desc').limit(10).offset(@page * 10)
+ @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})").order('created_at desc').limit(10).offset(@page * 10)
end
# @user_activities = paginateHelper @user_activities,500
@type = params[:type]
diff --git a/app/models/course_activity.rb b/app/models/course_activity.rb
index 284687870..103796a72 100644
--- a/app/models/course_activity.rb
+++ b/app/models/course_activity.rb
@@ -19,6 +19,7 @@ class CourseActivity < ActiveRecord::Base
user_activity.act_type = self.course_act_type
user_activity.container_type = "Course"
user_activity.container_id = self.course_id
+ user_activity.user_id = self.user_id
user_activity.save
end
end
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb
index 92f3f4a1a..13f2518e1 100644
--- a/app/views/users/show.html.erb
+++ b/app/views/users/show.html.erb
@@ -29,6 +29,7 @@
- 更多
+ - <%= link_to "我的动态", {:controller => "users", :action => "show", :type => "current_user"}, :class =>"homepagePostTypeAll postTypeGrey"%>
- <%= link_to "全部动态", {:controller => "users", :action => "show", :type => nil}, :class =>"homepagePostTypeAll postTypeGrey"%>
diff --git a/db/migrate/20150907064144_add_user_id_to_user_activities.rb b/db/migrate/20150907064144_add_user_id_to_user_activities.rb
new file mode 100644
index 000000000..a038f4dab
--- /dev/null
+++ b/db/migrate/20150907064144_add_user_id_to_user_activities.rb
@@ -0,0 +1,5 @@
+class AddUserIdToUserActivities < ActiveRecord::Migration
+ def change
+ add_column :user_activities, :user_id, :int
+ end
+end
diff --git a/db/migrate/20150907064547_update_user_activities.rb b/db/migrate/20150907064547_update_user_activities.rb
new file mode 100644
index 000000000..b4c56c009
--- /dev/null
+++ b/db/migrate/20150907064547_update_user_activities.rb
@@ -0,0 +1,40 @@
+class UpdateUserActivities < ActiveRecord::Migration
+ def up
+ count = UserActivity.all.count / 30 + 2
+ transaction do
+ for i in 1 ... count do i
+ UserActivity.page(i).per(30).each do |activity|
+ if activity.container_type.to_s == 'Project'
+ forge_activity = ForgeActivity.where("forge_act_type = '#{activity.act_type.to_s}' and forge_act_id = #{activity.act_id}").first
+ if forge_activity
+ activity.user_id = forge_activity.user_id
+ else
+ activity.user_id = 0
+ end
+
+ elsif activity.container_type.to_s == 'Course'
+ course_activity = CourseActivity.where("course_act_type = '#{activity.act_type.to_s}' and course_act_id = #{activity.act_id}").first
+ if course_activity
+ activity.user_id = course_activity.user_id
+ else
+ activity.user_id = 0
+ end
+ end
+ activity.save
+ end
+ end
+ end
+ end
+
+ def down
+ count = UserActivity.all.count / 30 + 2
+ transaction do
+ for i in 1 ... count do i
+ UserActivity.page(i).per(30).each do |activity|
+ activity.user_id = nil
+ activity.save
+ end
+ end
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index ec38d5c1d..db0b57ae8 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20150906083453) do
+ActiveRecord::Schema.define(:version => 20150907064547) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@@ -476,13 +476,6 @@ ActiveRecord::Schema.define(:version => 20150906083453) do
add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority"
- create_table "discuss_demos", :force => true do |t|
- t.string "title"
- t.text "body"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
- end
-
create_table "documents", :force => true do |t|
t.integer "project_id", :default => 0, :null => false
t.integer "category_id", :default => 0, :null => false
@@ -913,6 +906,7 @@ ActiveRecord::Schema.define(:version => 20150906083453) do
t.datetime "created_on"
t.integer "comments_count", :default => 0, :null => false
t.integer "course_id"
+ t.datetime "updated_on"
end
add_index "news", ["author_id"], :name => "index_news_on_author_id"
@@ -1421,6 +1415,7 @@ ActiveRecord::Schema.define(:version => 20150906083453) do
t.integer "container_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
+ t.integer "user_id"
end
create_table "user_extensions", :force => true do |t|