resultSet=Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' AND filename LIKE :like ",like:"%#{keywords}%").reorder(sort)
resultSet=Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' AND filename LIKE :like ",like:"%#{keywords}%").reorder(sort)
else
resultSet=Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' ").reorder(sort)
end
@ -250,7 +252,7 @@ class FilesController < ApplicationController
else
resultSet=Attachment.where("attachments.container_type = 'Project' And attachments.container_id = '#{project.id}' ").reorder(sort)
@user_activities=UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'HomeworkCommon'").order('updated_at desc').limit(10).offset(@page*10)
container_type='Course'
act_type='HomeworkCommon'
when"course_news"
@user_activities=UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'News'").order('updated_at desc').limit(10).offset(@page*10)
container_type='Course'
act_type='News'
when"course_message"
@user_activities=UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Message'").order('updated_at desc').limit(10).offset(@page*10)
container_type='Course'
act_type='Message'
when"course_poll"
@user_activities=UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Poll'").order('updated_at desc').limit(10).offset(@page*10)
container_type='Course'
act_type='Poll'
when"course_journals"
@user_activities=UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'JournalsForMessage'").order('updated_at desc').limit(10).offset(@page*10)
container_type='Course'
act_type='JournalsForMessage'
when"project_issue"
@user_activities=UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Issue'").order('updated_at desc').limit(10).offset(@page*10)
container_type='Project'
act_type='Issue'
when"project_message"
@user_activities=UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Message'").order('updated_at desc').limit(10).offset(@page*10)
container_type='Course'
act_type='Message'
when"user_journals"
@user_activities=UserActivity.where("container_type = 'Principal' and act_type= 'JournalsForMessage' and container_id = #{@user.id}").order('updated_at desc').limit(10).offset(@page*10)
container_type='Principal'
act_type='JournalsForMessage'
when"current_user"
@user_activities=UserActivity.where("user_id = #{@user.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('updated_at desc').limit(10).offset(@page*10)
sql="user_id = #{@user.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}))"
end
ifUser.current!=@user
sql+="and user_id = #{@user.id}"
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})or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10)
# @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'HomeworkCommon'").order('updated_at desc').limit(10).offset(@page * 10)
# when "course_news"
# @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'News'").order('updated_at desc').limit(10).offset(@page * 10)
# when "course_message"
# @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Message'").order('updated_at desc').limit(10).offset(@page * 10)
# when "course_poll"
# @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'Poll'").order('updated_at desc').limit(10).offset(@page * 10)
# when "course_journals"
# @user_activities = UserActivity.where("container_type = 'Course' and container_id in #{user_course_ids} and act_type = 'JournalsForMessage'").order('updated_at desc').limit(10).offset(@page * 10)
# when "project_issue"
# @user_activities = UserActivity.where("container_type = 'Project' and container_id in #{user_project_ids} and act_type = 'Issue'").order('updated_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('updated_at desc').limit(10).offset(@page * 10)
# when "user_journals"
# @user_activities = UserActivity.where("container_type = 'Principal' and act_type= 'JournalsForMessage' and container_id = #{@user.id}").order('updated_at desc').limit(10).offset(@page * 10)
# when "current_user"
# @user_activities = UserActivity.where("user_id = #{@user.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('updated_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}) "+
# "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " +
# "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_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})or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10)
sql_select="SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches
WHEREmembers.course_id=#{course_id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{course_id}) AND members.user_id = homework_attaches.user_id
ANDhomework_attaches.bid_idin(SELECTbid_idFROMhomework_for_coursesWHEREcourse_id=#{course_id}) GROUP BY members.user_id
UNIONall
SELECTmembers.*,0asscoreFROMmembers,homework_attaches,students_for_coursesWHEREmembers.course_id=#{course_id} AND
students_for_courses.course_id=#{course_id} and members.user_id = students_for_courses.student_id AND
sql_select="SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches
WHEREmembers.course_id=#{course_id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{course_id}) AND members.user_id = homework_attaches.user_id
ANDhomework_attaches.bid_idin(SELECTbid_idFROMhomework_for_coursesWHEREcourse_id=#{course_id}) GROUP BY members.user_id
UNIONall
SELECTmembers.*,0asscoreFROMmembers,homework_attaches,students_for_coursesWHEREmembers.course_id=#{course_id} AND
students_for_courses.course_id=#{course_id} and members.user_id = students_for_courses.student_id AND
resource_num*5+journal_num*1+homework_journal_num*1)FROM`course_contributor_scores`ASccsWHEREccs.course_id=#{course_id} AND ccs.user_id = members.user_id
WHEREmembers.course_id=#{course_id} ORDER BY #{sort_type} #{score_sort_by}"
else
sql_select="SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches
WHEREmembers.course_id=#{course_id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{course_id}) AND members.user_id = homework_attaches.user_id
andmembers.course_group_id=#{groupid} AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id})
resource_num*5+journal_num*1+homework_journal_num*1)FROM`course_contributor_scores`ASccsWHEREccs.course_id=#{course_id} AND ccs.user_id = members.user_id