@ -36,17 +36,18 @@ class CoursesController < ApplicationController
if!params[:name].nil?
condition="%#{params[:name].strip}%".gsub("","")
end
limit=15
course_org_ids=OrgCourse.find_by_sql("select distinct organization_id from org_courses where course_id = #{params[:id]}").map(&:organization_id)
ifcourse_org_ids.empty?
@orgs_not_in_course=Organization.where("(is_public or creator_id =?) and name like ?",User.current.id,condition).page((params[:page].to_i||1)).per(10)
@orgs_not_in_course=Organization.where("(is_public or creator_id =?) and name like ?",User.current.id,condition).page((params[:page].to_i||1)).per(limit)
@org_count=Organization.where("is_public = 1 or creator_id =?",User.current.id).where("name like ?",condition).count
else
course_org_ids="("+course_org_ids.join(',')+")"
@orgs_not_in_course=Organization.where("id not in #{course_org_ids} and (is_public = 1 or creator_id =?) and name like ?",User.current.id,condition).page((params[:page].to_i||1)).per(10)
@orgs_not_in_course=Organization.where("id not in #{course_org_ids} and (is_public = 1 or creator_id =?) and name like ?",User.current.id,condition).page((params[:page].to_i||1)).per(limit)
@org_count=Organization.where("id not in #{course_org_ids} and (is_public = 1 or creator_id =?)",User.current.id).where("name like ?",condition).count
@ -144,6 +183,19 @@ class FilesController < ApplicationController
#resultSet = Attachment.find_by_sql("SELECT `attachments`.* FROM `attachments` LEFT OUTER JOIN `homework_attaches` ON `attachments`.container_type = 'HomeworkAttach' AND `attachments`.container_id = `homework_attaches`.id LEFT OUTER JOIN `homework_for_courses` ON `homework_attaches`.bid_id = `homework_for_courses`.bid_id LEFT OUTER JOIN `homework_for_courses` AS H_C ON `attachments`.container_type = 'Bid' AND `attachments`.container_id = H_C.bid_id WHERE (`homework_for_courses`.course_id = 117 OR H_C.course_id = 117 OR (`attachments`.container_type = 'Course' AND `attachments`.container_id = 117)) AND `attachments`.filename LIKE '%#{keywords}%'").reorder("created_on DESC")
resultSet=Attachment.where("attachments.container_type = 'OrgSubfield' And attachments.container_id = '#{org_subfield.id}' AND filename LIKE :like ",like:"%#{keywords}%").
reorder(sort)
else
resultSet=Attachment.where("attachments.container_type = 'OrgSubfield' And attachments.container_id = '#{org_subfield.id}' ").reorder(sort)
end
#resultSet = Attachment.find_by_sql("SELECT `attachments`.* FROM `attachments` LEFT OUTER JOIN `homework_attaches` ON `attachments`.container_type = 'HomeworkAttach' AND `attachments`.container_id = `homework_attaches`.id LEFT OUTER JOIN `homework_for_courses` ON `homework_attaches`.bid_id = `homework_for_courses`.bid_id LEFT OUTER JOIN `homework_for_courses` AS H_C ON `attachments`.container_type = 'Bid' AND `attachments`.container_id = H_C.bid_id WHERE (`homework_for_courses`.course_id = 117 OR H_C.course_id = 117 OR (`attachments`.container_type = 'Course' AND `attachments`.container_id = 117)) AND `attachments`.filename LIKE '%#{keywords}%'").reorder("created_on DESC")
end
deffind_project_attachekeywords,project,sort=""
ifsort==""
sort="created_on DESC"
@ -298,10 +350,52 @@ class FilesController < ApplicationController
@ -75,17 +75,18 @@ class ProjectsController < ApplicationController
if!params[:name].nil?
condition="%#{params[:name].strip}%".gsub("","")
end
limit=15
project_org_ids=OrgProject.find_by_sql("select distinct organization_id from org_projects where project_id = #{params[:id]}").map(&:organization_id)
ifproject_org_ids.empty?
@orgs_not_in_project=Organization.where("(is_public or creator_id =?) = 1 and name like ?",User.current.id,condition).page((params[:page].to_i||1)).per(10)
@orgs_not_in_project=Organization.where("(is_public or creator_id =?) = 1 and name like ?",User.current.id,condition).page((params[:page].to_i||1)).per(limit)
@org_count=Organization.where("is_public = 1 or creator_id =?",User.current.id).where("name like ?",condition).count
else
project_org_ids="("+project_org_ids.join(',')+")"
@orgs_not_in_project=Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?) and name like ?",User.current.id,condition).page((params[:page].to_i||1)).per(10)
@orgs_not_in_project=Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?) and name like ?",User.current.id,condition).page((params[:page].to_i||1)).per(limit)
@org_count=Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?)",User.current.id).where("name like ?",condition).count
@attachments=Attachment.where("((author_id = #{params[:id]} and container_type in('Project','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 (filename like '%#{search}%') ").order("created_on desc")
" or (container_type = 'Course' and container_id in (#{user_course_ids.empty??'0':user_course_ids.join(',')}))) and (filename like :p) ",:p=>search).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 (filename like '%#{search}%') ").order("created_on desc")
" and (filename like :p) ",:p=>search).order("created_on desc")
end
elsifparams[:type]=="2"#课程资源
ifUser.current.id.to_i==params[:id].to_i
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(',')})) and (filename like '%#{search}%') ").order("created_on desc")
@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(',')})) and (filename like :p) ",:p=>search).order("created_on desc")
@attachments=Attachment.where("((author_id = #{params[:id]} and is_public = 1 and container_type = 'Course') "+
"or (container_type = 'Course' and is_public = 1 and container_id in (#{user_course_ids.empty??'0':user_course_ids.join(',')})) )"+
" and (filename like '%#{search}%') ").order("created_on desc")
" and (filename like :p) ",:p=>search).order("created_on desc")
end
elsifparams[:type]=="3"#项目资源
ifUser.current.id.to_i==params[:id].to_i
@attachments=Attachment.where("author_id = #{params[:id]} and container_type = 'Project' and (filename like '%#{search}%')").order("created_on desc")
@attachments=Attachment.where("author_id = #{params[:id]} and container_type = 'Project' and (filename like :p)",:p=>search).order("created_on desc")
else
@attachments=Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Project' and (filename like '%#{search}%') ").order("created_on desc")
@attachments=Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Project' and (filename like :p) ",:p=>search).order("created_on desc")
end
elsifparams[:type]=="4"#附件
ifUser.current.id.to_i==params[:id].to_i
@attachments=Attachment.where("author_id = #{params[:id]} and container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like '%#{search}%')").order("created_on desc")
@attachments=Attachment.where("author_id = #{params[:id]} and container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like :p)",:p=>search).order("created_on desc")
else
@attachments=Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like '%#{search}%')").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') and (filename like :p)",:p=>search).order("created_on desc")
end
elsifparams[:type]=="5"#用户资源
ifUser.current.id.to_i==params[:id].to_i
@attachments=Attachment.where("author_id = #{params[:id]} and container_type = 'Principal' and (filename like '%#{search}%')").order("created_on desc")
@attachments=Attachment.where("author_id = #{params[:id]} and container_type = 'Principal' and (filename like :p)",:p=>search).order("created_on desc")
else
@attachments=Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Principal' and (filename like '%#{search}%')").order("created_on desc")
@attachments=Attachment.where("author_id = #{params[:id]} and is_public = 1 and container_type = 'Principal' and (filename like :p)",:p=>search).order("created_on desc")
标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) if exercise_question.exercise_standard_answers.first %>
标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) if exercise_question.exercise_standard_answers.first%>