@ -499,6 +500,7 @@ class StudentWorkController < ApplicationController
render_403
render_403
return
return
end
end
@student_work_count=(search_homework_member@homework.student_works.select("student_works.*,student_works.work_score as score").order("#{@order}#{@b_sort}"),@name).count
end
end
@score=@b_sort=="desc"?"asc":"desc"
@score=@b_sort=="desc"?"asc":"desc"
@ -760,49 +762,64 @@ class StudentWorkController < ApplicationController
ts_score=StudentWorksScore.find_by_sql("SELECT AVG(score) AS score FROM (SELECT * FROM (SELECT * FROM student_works_scores WHERE student_work_id = #{@work.id} AND reviewer_role = 2 AND score IS NOT NULL ORDER BY created_at DESC) AS t GROUP BY user_id) AS a")
stu_score=StudentWorksScore.find_by_sql("SELECT AVG(score) AS score FROM (SELECT * FROM (SELECT * FROM student_works_scores WHERE student_work_id = #{@work.id} AND reviewer_role = 3 ORDER BY created_at DESC) AS t GROUP BY user_id) AS a")
@homeworks=HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and course_id in #{course_ids}").order("#{@order}#{@b_sort}")
@homeworks=HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and course_id not in #{course_ids}").order("#{@order}#{@b_sort}")
#@homeworks = HomeworkCommon.where("id in #{homework_ids}")
#@homeworks = HomeworkCommon.where("id in #{homework_ids} and course_id not in #{none_visible_course_ids}")
sql="SELECT homework_commons.* FROM homework_commons INNER JOIN apply_homeworks as ah ON homework_commons.id = ah.homework_common_id where ah.user_id = #{@user.id} order by ah.created_at desc"
sql="SELECT homework_commons.* FROM homework_commons INNER JOIN apply_homeworks as ah ON homework_commons.id = ah.homework_common_id where ah.user_id = #{@user.id} and homework_commons.course_id not in #{none_visible_course_ids} order by ah.created_at desc"
ah=ApplyHomework.where("user_id = ? and homework_common_id = ?",User.current.id,params[:homework].to_i)
ah=ApplyHomework.where("user_id = ? and homework_common_id = ?",User.current.id,params[:homework].to_i)
ifah.empty?
ifah.empty?
@status=2
@status=2
@ -704,26 +719,28 @@ class UsersController < ApplicationController
@homeworks=HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and homework_type in #{type_ids} and (name like '%#{search}%' or user_id in #{user_ids})").order("#{@order}#{@b_sort}")
@homeworks=HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and homework_type in #{type_ids} and (name like '%#{search}%' or user_id in #{user_ids})").order("#{@order}#{@b_sort}")
sql="SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where homework_commons.course_id in #{course_ids} and homework_commons.user_id = #{@user.id} and homework_type in #{type_ids} and publish_time <= '#{Date.today}' and (homework_commons.name like '%#{search}%') order by CONVERT (courses.name USING gbk) COLLATE gbk_chinese_ci #{@b_sort}"
sql="SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where homework_commons.course_id not in #{course_ids} and homework_commons.user_id = #{@user.id} and homework_type in #{type_ids} and publish_time <= '#{Date.today}' and (homework_commons.name like '%#{search}%') order by CONVERT (courses.name USING gbk) COLLATE gbk_chinese_ci #{@b_sort}"
@homeworks=HomeworkCommon.find_by_sql(sql)
@homeworks=HomeworkCommon.find_by_sql(sql)
elsif@order=="user_name"
elsif@order=="user_name"
@homeworks=HomeworkCommon.where("user_id = #{@user.id} and course_id in #{course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").joins(:user).order("CONVERT (lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, CONVERT (firstname USING gbk) COLLATE gbk_chinese_ci #{@b_sort},login #{@b_sort}")
@homeworks=HomeworkCommon.where("user_id = #{@user.id} and course_id not in #{course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").joins(:user).order("CONVERT (lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, CONVERT (firstname USING gbk) COLLATE gbk_chinese_ci #{@b_sort},login #{@b_sort}")
else
else
@homeworks=HomeworkCommon.where("user_id = #{@user.id} and course_id in #{course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").order("#{@order}#{@b_sort}")
@homeworks=HomeworkCommon.where("user_id = #{@user.id} and course_id not in #{course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%') and homework_type in #{type_ids}").order("#{@order}#{@b_sort}")
sql="SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where homework_commons.id in #{homework_ids} and homework_type in #{type_ids} and publish_time <= '#{Date.today}' and (homework_commons.name like '%#{search}%') order by CONVERT (courses.name USING gbk) COLLATE gbk_chinese_ci #{@b_sort}"
sql="SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where courses.is_delete = 0 and homework_commons.id in #{homework_ids} and homework_type in #{type_ids} and publish_time <= '#{Date.today}' and (homework_commons.name like '%#{search}%') order by CONVERT (courses.name USING gbk) COLLATE gbk_chinese_ci #{@b_sort}"
@homeworks=HomeworkCommon.find_by_sql(sql)
@homeworks=HomeworkCommon.find_by_sql(sql)
elsif@order=="user_name"
elsif@order=="user_name"
@homeworks=HomeworkCommon.where("homework_commons.id in #{homework_ids} and (name like '%#{search}%') and homework_type in #{type_ids}").joins(:user).order("CONVERT (lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, CONVERT (firstname USING gbk) COLLATE gbk_chinese_ci #{@b_sort},login #{@b_sort}")
@homeworks=HomeworkCommon.where("homework_commons.id in #{homework_ids} and course_id not in #{none_visible_course_ids} and (name like '%#{search}%') and homework_type in #{type_ids}").joins(:user).order("CONVERT (lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, CONVERT (firstname USING gbk) COLLATE gbk_chinese_ci #{@b_sort},login #{@b_sort}")
else
else
@homeworks=HomeworkCommon.where("id in #{homework_ids} and (name like '%#{search}%') and homework_type in #{type_ids}").order("#{@order}#{@b_sort}")
@homeworks=HomeworkCommon.where("id in #{homework_ids} and (name like '%#{search}%') and course_id not in #{none_visible_course_ids} and homework_type in #{type_ids}").order("#{@order}#{@b_sort}")
end
end
end
end
=begin
=begin
@ -1260,13 +1277,13 @@ class UsersController < ApplicationController
#显示更多用户课程
#显示更多用户课程
defuser_courses4show
defuser_courses4show
@page=params[:page].to_i+1
@page=params[:page].to_i+1
@courses=@user.courses.visible.where("is_delete =?",0).select("courses.*,(SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5).offset(@page*5)
@courses=@user.courses.visible.where("is_delete =?",0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5).offset(@page*5)
end
end
#显示更多用户项目
#显示更多用户项目
defuser_projects4show
defuser_projects4show
@page=params[:page].to_i+1
@page=params[:page].to_i+1
@projects=@user.projects.visible.select("projects.*,(SELECT MAX(created_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(5).offset(@page*5)
@projects=@user.projects.visible.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(5).offset(@page*5)
end
end
defuser_course_activities
defuser_course_activities
@ -1354,7 +1371,7 @@ class UsersController < ApplicationController
shield_course_ids=ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id)
shield_course_ids=ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id)
attachments=Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('OrgSubfield','Principal','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
attachments=Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('OrgSubfield','Principal','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty??'0':user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)"+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty??'0':user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)"+
"or (container_type = 'Project' and container_id in (#{user_project_ids.empty??'0':user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)").order("#{order.nil??'created_on':order}#{score}")
"or (container_type = 'Project' and container_id in (#{user_project_ids.empty??'0':user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)").order("#{order.nil??'created_on':order}#{score}")
@ -2608,6 +2628,7 @@ class UsersController < ApplicationController
@attachments=Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
@attachments=Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty??'0':user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)"+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty??'0':user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)"+
"or (container_type = 'Project' and container_id in (#{user_project_ids.empty??'0':user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)",:p=>search).order("#{order.nil??'created_on':order}#{score}")
"or (container_type = 'Project' and container_id in (#{user_project_ids.empty??'0':user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)",:p=>search).order("#{order.nil??'created_on':order}#{score}")
@ -2615,6 +2636,7 @@ class UsersController < ApplicationController
@ -2663,12 +2688,14 @@ class UsersController < ApplicationController
# 获取我上传的附件
# 获取我上传的附件
defget_attch_resourcesauthor_id,order,score
defget_attch_resourcesauthor_id,order,score
author_id=User.find_by_login(author_id).id
attchments=Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue',
attchments=Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue',
attchments=Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue',
attchments=Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue',
@ -2687,11 +2714,13 @@ class UsersController < ApplicationController
# 获取我的用户类型资源
# 获取我的用户类型资源
defget_principal_resourcesauthor_id,order,score
defget_principal_resourcesauthor_id,order,score
author_id=User.find_by_login(author_id).id
attchments=Attachment.where("author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Principal'").order("#{order.nil??'created_on':order}#{score}")
attchments=Attachment.where("author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Principal'").order("#{order.nil??'created_on':order}#{score}")
attchments=Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Principal') and (filename like :p)",:p=>search).order("#{order.nil??'created_on':order}#{score}")
attchments=Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Principal') and (filename like :p)",:p=>search).order("#{order.nil??'created_on':order}#{score}")
end
end
@ -2763,13 +2792,13 @@ class UsersController < ApplicationController
@courses=@user.courses.visible.where("is_delete =?",0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS #{sort_name}").order("#{sort_name}#{sort_type}")
#根据 作业+资源数排序
#根据 作业+资源数排序
if@order.to_i==2
if@order.to_i==2
@type=2
@type=2
@ -3040,11 +3071,11 @@ class UsersController < ApplicationController
# @projects = @user.projects.visible.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a #{sort_type}")
@projects=@user.projects.visible.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS #{sort_name}").order("#{sort_name}#{sort_type}")
count=ShieldWechatMessage.where("container_type='User' and container_id=#{self.jour.user_id} and shield_type='Course' and shield_id=#{self.jour.course_id}").count
count=ShieldWechatMessage.where("container_type='User' and container_id=#{self.jour.user_id} and shield_type='Course' and shield_id=#{self.jour.course_id}").count
<div class = "leftCoursesList" id="homepageLeftMenuCourses">
<div class = "leftCoursesList" id="homepageLeftMenuCourses">
@ -258,7 +257,6 @@
end
end
%>
%>
<%# projects = @user.projects.visible.select("projects.*, (SELECT MAX(created_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(5)%>
<% projects = @user.projects.visible.select("projects.*, (SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(5)%>
<% projects = @user.projects.visible.select("projects.*, (SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(5)%>
<% student_work_scores = StudentWorksScore.find_by_sql("select max(created_at) as created_at, student_work_id, user_id from student_works_scores where student_work_id in #{sw_id} group by student_work_id order by max(created_at) desc") %>
<%# student_work_scores = StudentWorksScore.find_by_sql("select max(created_at) as created_at, student_work_id, user_id from student_works_scores where student_work_id in #{sw_id} group by student_work_id order by max(created_at) desc") %>
<%# student_work_scores = StudentWorksScore.where("student_work_id in #{sw_id}").reorder("created_at desc") %>
<% student_work_scores = StudentWorksScore.where("student_work_id in #{sw_id} and score is not null").reorder("created_at desc") %>
<% student_work_scores = StudentWorksScore.find_by_sql("select max(created_at) as created_at, student_work_id, user_id from student_works_scores where student_work_id in #{sw_id} group by student_work_id order by max(created_at) desc") %>
<%# student_work_scores = StudentWorksScore.find_by_sql("select max(created_at) as created_at, student_work_id, user_id from student_works_scores where student_work_id in #{sw_id} group by student_work_id order by max(created_at) desc") %>
<% student_work_scores = StudentWorksScore.where("student_work_id in #{sw_id} and score is not null").reorder("created_at desc") %>
<% student_work_scores = StudentWorksScore.find_by_sql("select max(created_at) as created_at, student_work_id, user_id from student_works_scores where student_work_id in #{sw_id} group by student_work_id order by max(created_at) desc") %>
<%# student_work_scores = StudentWorksScore.find_by_sql("select max(created_at) as created_at, student_work_id, user_id from student_works_scores where student_work_id in #{sw_id} group by student_work_id order by max(created_at) desc") %>
<%# student_work_scores = StudentWorksScore.where("student_work_id in #{sw_id}").reorder("created_at desc") %>
<% student_work_scores = StudentWorksScore.where("student_work_id in #{sw_id} and score is not null").reorder("created_at desc") %>