@homeworks=@course.homework_commons.where("name like '%#{@search}%'").order("created_at desc").limit(10).offset(@page*10)
else
@homeworks=@course.homework_commons.where("name like '%#{@search}%' and publish_time <= '#{Date.today}'").order("created_at desc").limit(10).offset(@page*10)
end
end
private
private
defupdate_quotesattachment
defupdate_quotesattachment
@ -960,7 +979,7 @@ class CoursesController < ApplicationController
@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,final_score - absence_penalty - late_penalty) as score").where(:id=>pro.student_work_id)
end
else
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,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,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,final_score - absence_penalty - late_penalty) as score").where(:id=>pro.student_work_id)
end
else
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,final_score - absence_penalty - late_penalty) as score").where(:user_id=>User.current.id)
end
end
@ -134,14 +146,22 @@ class StudentWorkController < ApplicationController
@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,final_score - absence_penalty - late_penalty) as score").where(:id=>pro.student_work_id)
end
else
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,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,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,final_score - absence_penalty - late_penalty) as score").where(:id=>pro.student_work_id)
end
else
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,final_score - absence_penalty - late_penalty) as score").where(:user_id=>User.current.id)
@homeworks=HomeworkCommon.where("course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and (name like '%#{search}%')").order("created_at desc")
elsifparams[:type]=="2"#课程资源
@homeworks=HomeworkCommon.where("user_id = #{@user.id} and publish_time <= '#{Date.today}' and (name like '%#{search}%')").order("created_at desc")
@attachments=Attachment.where("(author_id = #{params[:id]} and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
@attachments=Attachment.where("(author_id = #{params[:id]} and is_publish = 1 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(',')}))").order("created_on desc")
"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")
"or (container_type = 'Course' and is_public = 1 and container_id in (#{user_course_ids.empty??'0':user_course_ids.join(',')}))").order("created_on desc")
"or (container_type = 'Course' and is_public = 1 and container_id in (#{user_course_ids.empty??'0':user_course_ids.join(',')}) and is_publish = 1)").order("created_on desc")
end
end
elsifparams[:type]=="2"#课程资源
elsifparams[:type]=="2"#课程资源
ifUser.current.id.to_i==params[:id].to_i
ifUser.current.id.to_i==params[:id].to_i
user_course_ids=User.current.courses.map{|c|c.id}
user_course_ids=User.current.courses.map{|c|c.id}
@attachments=Attachment.where("(author_id = #{params[:id]} and container_type = 'Course') or (container_type = 'Course' and container_id in (#{user_course_ids.empty??'0':user_course_ids.join(',')})) ").order("created_on desc")
@attachments=Attachment.where("(author_id = #{params[:id]} and 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")
@attachments=Attachment.where("(author_id = #{params[:id]} and is_public = 1 and container_type = 'Course')"+
@attachments=Attachment.where("(author_id = #{params[:id]} and is_public = 1 and container_type = 'Course' and is_publish = 1)"+
"or (container_type = 'Course' and is_public = 1 and container_id in (#{user_course_ids.empty??'0':user_course_ids.join(',')}))").order("created_on desc")
"or (container_type = 'Course' and is_public = 1 and is_publish = 1 and container_id in (#{user_course_ids.empty??'0':user_course_ids.join(',')}))").order("created_on desc")
end
end
elsifparams[:type]=="3"#项目资源
elsifparams[:type]=="3"#项目资源
ifUser.current.id.to_i==params[:id].to_i
ifUser.current.id.to_i==params[:id].to_i
@ -1994,9 +2169,9 @@ class UsersController < ApplicationController
end
end
elsifparams[:type]=="4"#附件
elsifparams[:type]=="4"#附件
ifUser.current.id.to_i==params[:id].to_i
ifUser.current.id.to_i==params[:id].to_i
@attachments=Attachment.where("author_id = #{params[:id]} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon')").order("created_on desc")
@attachments=Attachment.where("author_id = #{params[:id]} and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc")
else
else
@attachments=Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon')").order("created_on desc")
@attachments=Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal')").order("created_on desc")
end
end
elsifparams[:type]=="5"#用户资源
elsifparams[:type]=="5"#用户资源
ifUser.current.id.to_i==params[:id].to_i
ifUser.current.id.to_i==params[:id].to_i
@ -2102,10 +2277,18 @@ class UsersController < ApplicationController
sort_projects=ForgeActivity.find_by_sql("SELECT MAX(updated_at) AS updated_at,user_id, project_id FROM forge_activities WHERE project_id IN #{project_ids} GROUP BY project_id ORDER BY MAX(updated_at) DESC")
# sql = "SELECT distinct c.* FROM `courses` c, tags t, taggings ts where t.id = ts.tag_id and ts.taggable_id = c.id and c.is_excellent = 1 and is_delete = 0 and
# ts.taggable_type = 'Course' and t.name like '%#{keywords}%'"
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)
end
end
defstudent_work_score_avg
defstudent_work_score_avg
@ -158,7 +158,12 @@ class Member < ActiveRecord::Base
end
end
defstudent_work_score_sum
defstudent_work_score_sum
StudentWork.joins(:homework_common).where("student_works.user_id = #{self.user_id} and homework_commons.course_id = #{self.course_id}").sum(:final_score).try(:round,2).to_f
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