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)
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?
@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)}
@ -1199,6 +1199,10 @@ class UsersController < ApplicationController
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
# 获取我的资源
@ -2372,7 +2374,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
# 获取我的项目资源
@ -2382,7 +2384,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
# 获取我上传的附件
@ -2392,7 +2394,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
# 获取我的用户类型资源
@ -2402,7 +2404,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
# 资源库 分为全部 课程资源 项目资源 附件
@ -2634,9 +2636,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