create_course_messages=@course.course_messages.where("user_id =? and course_message_type =? and course_id =? and viewed =?",User.current.id,'Course',@course.id,0)
create_course_messages.update_all(:viewed=>true)
@ -1067,7 +1081,7 @@ class CoursesController < ApplicationController
query_message_news=ForgeMessage.where("forge_message_id =? and user_id =? and viewed =?",@news.id,User.current.id,0).first
# 更新新闻的时候一并更新回复
ForgeMessage.where("forge_message_id in (#{ids}) and forge_message_type = 'Comment' and user_id = #{User.current.id}").update_all(:viewed=>true)unlessids.blank?
else
query_message_news=@news.course_messages
query_message_news=CourseMessage.where("course_message_id =? and user_id =? and viewed =?",@news.id,User.current.id,0).first
CourseMessage.where("course_message_id in (#{ids}) and course_message_type = 'Comment' and user_id = #{User.current.id}").update_all(:viewed=>true)unlessids.blank?
@stundet_works=search_homework_member@homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order}#{@b_sort}"),@name
@stundet_works=search_homework_member@homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order}#{@b_sort}"),@name
@stundet_works=search_homework_member@homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins(:user).where("users.id in #{student_in_group}").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name
elsif@order=='student_id'
@stundet_works=search_homework_member@homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins(:user).where("users.id in #{student_in_group}").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order}#{@b_sort}"),@name
else
@stundet_works=search_homework_member@homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order}#{@b_sort}"),@name
@stundet_works=@homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id=>pro.student_work_id)
@stundet_works=@homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").where(:id=>pro.student_work_id)
end
else
@stundet_works=@homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id=>User.current.id)
@stundet_works=@homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").where(:user_id=>User.current.id)
@ -129,15 +139,21 @@ class StudentWorkController < ApplicationController
ifpro.nil?
my_work=[]
else
my_work=@homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id=>pro.student_work_id)
my_work=@homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").where(:id=>pro.student_work_id)
end
else
my_work=@homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id=>User.current.id)
my_work=@homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").where(:user_id=>User.current.id)
end
ifmy_work.empty?
@stundet_works=[]
else
@stundet_works=search_homework_member@homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order}#{@b_sort}"),@name
if@order=='lastname'
@stundet_works=search_homework_member@homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins(:user).where("users.id in #{student_in_group}").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name
elsif@order=='student_id'
@stundet_works=search_homework_member@homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins(:user).where("users.id in #{student_in_group}").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order}#{@b_sort}"),@name
else
@stundet_works=search_homework_member@homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order}#{@b_sort}"),@name
end
@show_all=true
end
else
@ -148,25 +164,28 @@ class StudentWorkController < ApplicationController
return
end
@student_work_count=(search_homework_member@homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order}#{@b_sort}"),@name).count
@student_work_count=(search_homework_member@homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order}#{@b_sort}"),@name).count
else
if@homework.is_open==1
@stundet_works=search_homework_member@homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order}#{@b_sort}"),@name
@stundet_works=search_homework_member@homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order}#{@b_sort}"),@name
@stundet_works=@homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id=>pro.student_work_id)
@stundet_works=@homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").where(:id=>pro.student_work_id)
end
else
@stundet_works=@homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id=>User.current.id)
@stundet_works=@homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").where(:user_id=>User.current.id)
@ -186,15 +205,21 @@ class StudentWorkController < ApplicationController
ifpro.nil?
my_work=[]
else
my_work=@homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:id=>pro.student_work_id)
my_work=@homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").where(:id=>pro.student_work_id)
end
else
my_work=@homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").where(:user_id=>User.current.id)
my_work=@homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").where(:user_id=>User.current.id)
end
ifmy_work.empty?
@stundet_works=[]
else
@stundet_works=search_homework_member@homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order}#{@b_sort}"),@name
if@order=='lastname'
@stundet_works=search_homework_member@homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins(:user).order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name
elsif@order=='student_id'
@stundet_works=search_homework_member@homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order}#{@b_sort}"),@name
else
@stundet_works=search_homework_member@homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").order("#{@order}#{@b_sort}"),@name
end
@show_all=true
end
else
@ -205,7 +230,7 @@ class StudentWorkController < ApplicationController
return
end
@student_work_count=(search_homework_member@homework.student_works.select("student_works.*,IF(final_score is null,null,final_score - absence_penalty - late_penalty) as score").order("#{@order}#{@b_sort}"),@name).count
@student_work_count=(search_homework_member@homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").order("#{@order}#{@b_sort}"),@name).count
end
@score=@b_sort=="desc"?"asc":"desc"
@ -303,6 +328,7 @@ class StudentWorkController < ApplicationController
@course=@user.courses.where("is_delete = 0 and #{Course.table_name}.id != #{homework.course_id} and #{Course.table_name}.id = #{params[:search].to_i} or #{Course.table_name}.name like :p",:p=>search).select{|course|@user.allowed_to?(:as_teacher,course)}
@ -524,20 +527,22 @@ class UsersController < ApplicationController
@homeworks=HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%' or user_id in #{user_ids})").order("created_at desc")
@homeworks=HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%' or user_id in #{user_ids})").order("#{@order}#{@b_sort}")
elsifparams[:type]=="2"#课程资源
@homeworks=HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and (name like '%#{search}%')").order("created_at desc")
@homeworks=HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and (name like '%#{search}%')").order("#{@order}#{@b_sort}")
attachments=Attachment.where("(is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) "+
"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("created_on desc")
attachments=Attachment.where("(is_publish = 1 and is_public =1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) ").order("created_on desc")
end
# 获取我的资源
@ -2341,7 +2357,7 @@ class UsersController < ApplicationController
# 获取公共资源课程
defget_course_resources_publicuser_course_ids
attchments=Attachment.where("(container_type = 'Course' and is_publish = 1) or (container_type = 'Course' and container_id in (#{user_course_ids.empty??'0':user_course_ids.join(',')}) and is_publish = 1) ").order("created_on desc")
attchments=Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1 and is_public =1)").order("created_on desc")
end
# 获取我的项目资源
@ -2351,7 +2367,7 @@ class UsersController < ApplicationController
# 获取公共资源的项目资源
defget_project_resources_publicuser_project_ids
attchments=Attachment.where("(container_type = 'Project') or (container_type = 'Project' and container_id in (#{user_project_ids.empty??'0':user_project_ids.join(',')}) and is_publish = 1) ").order("created_on desc")
attchments=Attachment.where("container_type = 'Project' and container_id is not null and is_public =1").order("created_on desc")
end
# 获取我上传的附件
@ -2361,7 +2377,7 @@ class UsersController < ApplicationController
attchments=Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal') and container_id is not null and is_public =1").order("created_on desc")
end
# 获取我的用户类型资源
@ -2371,7 +2387,7 @@ class UsersController < ApplicationController
attchments=Attachment.where("container_type = 'Principal'and container_id is not null and is_public =1").order("created_on desc")
end
# 资源库 分为全部 课程资源 项目资源 附件
@ -2603,9 +2619,7 @@ class UsersController < ApplicationController
end
elsifparams[:type]=="6"#全部资源
# 公共资源库:所有公开资源或者我上传的私有资源
@attachments=Attachment.where("((is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) "+
"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("created_on desc")
@attachments=Attachment.where("is_publish = 1 and is_public = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course') and (filename like :p)",:p=>search).order("created_on desc")
StudentWork.find_by_sql("SELECT * FROM student_works WHERE homework_common_id IN (SELECT id FROM homework_commons WHERE course_id = '#{course.id}')").count
UserExtensions.find_by_sql("SELECT * FROM user_extensions WHERE occupation = '#{school.name}' AND identity = '1'").count
end
defteacher_numschool
UserExtensions.find_by_sql("SELECT * FROM user_extensions AS ue, schools AS s WHERE ue.school_id = s.id AND s.name = '#{school.name}' AND ue.identity = '0'").count
@ -150,7 +150,7 @@ class Member < ActiveRecord::Base
#当前学生在指定作业内的得分
defhomework_common_scorehomework_common
StudentWork.select("IF(final_score is null,null,final_score - absence_penalty - late_penalty) as final_score").where(:homework_common_id=>homework_common.id,:user_id=>self.user_id)
StudentWork.select("IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as final_score").where(:homework_common_id=>homework_common.id,:user_id=>self.user_id)
end
defstudent_work_score_avg
@ -158,7 +158,7 @@ class Member < ActiveRecord::Base
end
defstudent_work_score_sum
sql_select="SELECT (SUM(IF(student_works.final_score is null,null,student_works.final_score - student_works.absence_penalty - student_works.late_penalty))) as score
sql_select="SELECT (SUM(IF(student_works.final_score IS NULL,NULL,IF(student_works.final_score =0,0,student_works.final_score - student_works.absence_penalty - student_works.late_penalty)))) as score