diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index b35d7f3db..8c8d8bae4 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -56,10 +56,14 @@ class OrganizationsController < ApplicationController if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization) @organization = Organization.find(params[:id]) project_ids = @organization.projects.map(&:id) << 0 + course_ids = @organization.courses.map(&:id) << 0 + course_types = "('Message','News','HomeworkCommon','Poll','Course')" case params[:type] when nil - @org_activities = OrgActivity.where("(container_id =? and container_type =?) or (container_type ='Project' and org_act_type in ('Issue','Message','ProjectCreateInfo') and container_id in (#{project_ids.join(',')}))", - @organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10) + @org_activities = OrgActivity.where("(container_id =? and container_type =?) " + + "or (container_type ='Project' and org_act_type in ('Issue','Message','ProjectCreateInfo') and container_id in (#{project_ids.join(',')})) "+ + "or (container_type ='Course' and org_act_type in #{course_types} and container_id in (#{course_ids.join(',')}))", + @organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10) when 'project_issue' @org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Issue' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) when 'project_message' @@ -145,7 +149,16 @@ class OrganizationsController < ApplicationController def more_org_projects @organization = Organization.find params[:id] @page = params[:page] - @org_projects = @organization.org_projects.reorder('created_at').page((params[:page].to_i || 1) +1).per(5) + @org_projects = @organization.projects.reorder('created_at').page((params[:page].to_i || 1) +1).per(5) + respond_to do |format| + format.js + end + end + + def more_org_courses + @organization = Organization.find(params[:id]) + @page = params[:page] + @org_courses = @organization.courses.reorder('created_at').page((params[:page].to_i || 1) + 1 ).per(5) respond_to do |format| format.js end diff --git a/app/models/course_activity.rb b/app/models/course_activity.rb index 4e74142ad..cd3234196 100644 --- a/app/models/course_activity.rb +++ b/app/models/course_activity.rb @@ -5,7 +5,7 @@ class CourseActivity < ActiveRecord::Base belongs_to :course belongs_to :user has_many :user_acts, :class_name => 'UserAcivity',:as =>:act - after_save :add_user_activity + after_save :add_user_activity, :add_course_activity before_destroy :destroy_user_activity #在个人动态里面增加当前动态 @@ -30,6 +30,27 @@ class CourseActivity < ActiveRecord::Base end end + def add_course_activity + org_activity = OrgActivity.where("org_act_type = '#{self.course_act_type.to_s}' and org_act_id = '#{self.course_act_id}'").first + if org_activity + org_activity.save + else + if self.course_act_type == 'Message' && !self.course_act.parent_id.nil? + org_activity = OrgActivity.where("org_act_type = 'Message' and org_act_id = #{self.course_act.parent.id}").first + org_activity.created_at = self.created_at + org_activity.save + else + OrgActivity.create(:user_id => self.user_id, + :org_act_id => self.course_act_id, + :org_act_type => self.course_act_type, + :container_id => self.course_id, + :container_type => 'Course', + :created_at => self.created_at, + :updated_at => self.updated_at) + end + end + end + def destroy_user_activity user_activity = UserActivity.where("act_type = '#{self.course_act_type.to_s}' and act_id = '#{self.course_act_id}'") user_activity.destroy_all diff --git a/app/views/layouts/_org_courses.html.erb b/app/views/layouts/_org_courses.html.erb new file mode 100644 index 000000000..2837ef71f --- /dev/null +++ b/app/views/layouts/_org_courses.html.erb @@ -0,0 +1,12 @@ +<% courses.each do |course|%> + <%# pro = Project.find course.course_id %> +