@ -35,17 +37,20 @@ 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)
@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)
@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
#@orgs_not_in_course = User.current.organizations.where("organizations.id not in (#{course_org_ids.join(',')}) and organizations.name like ?", condition).page(params[:page].to_i || 1).per(limit)
#@org_count = User.current.organizations.where("organizations.id not in (#{course_org_ids.join(',')}) and organizations.name like ?", condition).count
ifcourse_org_ids.empty?
@orgs_not_in_course=User.current.organizations.where("name like ?",condition).page((params[:page].to_i||1)).per(limit)
@org_count=@orgs_not_in_course.count
else
course_org_ids="("+course_org_ids.join(',')+")"
@orgs_not_in_course=User.current.organizations.where("organizations.id not in #{course_org_ids} and organizations.name like ?",condition).page((params[:page].to_i||1)).per(limit)
@ -580,6 +685,13 @@ class CoursesController < ApplicationController
end
end
defis_deleted
if@course.is_delete==1and!User.current.admin?
render_404
return
end
end
defget_courses
@user=User.current
membership=@user.coursememberships.all
@ -633,6 +745,11 @@ class CoursesController < ApplicationController
end
defshow
# 被删除的课程只有超级管理员才能看到,is_delete为1的时候,标记课程被删除
# if @course.is_delete == 1 && !User.current.admin?
# render_403
# return
# end
#更新创建课程消息状态
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)
@ -683,10 +800,10 @@ class CoursesController < ApplicationController
@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
defupdate_quotesattachment
ifattachment.copy_from
attachments=Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.copy_from} or id = #{attachment.copy_from}")
else
attachments=Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.id} or id = #{attachment.copy_from}")
end
attachment.quotes=get_qute_numberattachment
attachment.save
attachments.eachdo|att|
att.quotes=attachment.quotes
att.save
end
end
defget_qute_numberattachment
ifattachment.copy_from
result=Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.copy_from}")
else
result=Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.id}")
end
ifresult.nil?||result.count<=0
return0
else
returnresult[0].number
end
end
defallow_joincourse
ifcourse_endTime_timeout?course
respond_todo|format|
@ -796,7 +970,7 @@ class CoursesController < ApplicationController
@ -144,27 +188,27 @@ 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
ifids.blank?
resultSet=Attachment.where("attachments.container_type = 'Project' And attachments.container_id = '#{project.id}' AND filename LIKE :like ",like:"%#{keywords}%").
reorder(sort)
#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"
end
ifkeywords!="%%"
resultSet=Attachment.where("attachments.container_type = 'Project' And attachments.container_id = '#{project.id}' AND filename LIKE :like ",like:"%#{keywords}%").reorder(sort)
else
resultSet=Attachment.where("((attachments.container_type = 'Project' And attachments.container_id = '#{project.id}') OR (container_type = 'Version' AND container_id IN (#{ids}))) AND filename LIKE :like ",like:"%#{keywords}%").
reorder(sort)
resultSet=Attachment.where("attachments.container_type = 'Project' And attachments.container_id = '#{project.id}' ").reorder(sort)
end
end
@ -186,12 +230,11 @@ class FilesController < ApplicationController
@order=""
@is_remote=false
ifparams[:project_id]
@isproject =true
@page =params[:page]?params[:page].to_i+1:2
@container_type=0
ifparams[:sort]
params[:sort].split(",").eachdo|sort_type|
order_by=sort_type.split(":")
caseorder_by[0]
when"filename"
attribute="filename"
@ -229,25 +272,19 @@ class FilesController < ApplicationController
# org_acts = OrgActivity.where("container_type='OrgSubfield' and container_id=? and org_act_type='Message' and org_act_id=?", field_id.to_i, @message.id)
@org_activities=OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{@org_subfield.id})").order('updated_at desc').page(params[:page]||1).per(10)
@org_activities=OrgActivity.where("container_type = 'Project' and org_act_type = 'Issue' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page]||1).per(10)
when'project_message'
@org_activities=OrgActivity.where("container_type = 'Project' and org_act_type = 'Message' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page]||1).per(10)
when'org'
@org_activities=OrgActivity.where("container_id =? and container_type =?",@organization.id,'Organization').order('updated_at desc').page(params[:page]||1).per(10)
when'course_homework'
@org_activities=OrgActivity.where("container_type = 'Course' and org_act_type = 'HomeworkCommon' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page]||1).per(10)
when'course_news'
@org_activities=OrgActivity.where("container_type = 'Course' and org_act_type = 'News' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page]||1).per(10)
when'course_message'
@org_activities=OrgActivity.where("container_type = 'Course' and org_act_type = 'Message' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page]||1).per(10)
when'course_poll'
@org_activities=OrgActivity.where("container_type = 'Course' and org_act_type = 'Poll' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page]||1).per(10)
sameName=@config_page?Organization.where('name = ? and id != ?',params[:org_name],params[:org_id].to_i).count==0:Organization.where('name = ?',params[:org_name]).count==0
@org_activities=OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{@org_subfield.id})").order('updated_at desc').page(params[:page]||1).per(10)
else
shield_project_ids=ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Project'").map(&:shield_id)
shield_course_ids=ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Course'").map(&:shield_id)
@org_activities=OrgActivity.where("container_type = 'Project' and org_act_type = 'Issue' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page]||1).per(10)
when'project_message'
@org_activities=OrgActivity.where("container_type = 'Project' and org_act_type = 'Message' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page]||1).per(10)
when'org'
@org_activities=OrgActivity.where("container_id =? and container_type =?",@organization.id,'Organization').order('updated_at desc').page(params[:page]||1).per(10)
when'course_homework'
@org_activities=OrgActivity.where("container_type = 'Course' and org_act_type = 'HomeworkCommon' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page]||1).per(10)
when'course_news'
@org_activities=OrgActivity.where("container_type = 'Course' and org_act_type = 'News' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page]||1).per(10)
when'course_message'
@org_activities=OrgActivity.where("container_type = 'Course' and org_act_type = 'Message' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page]||1).per(10)
when'course_poll'
@org_activities=OrgActivity.where("container_type = 'Course' and org_act_type = 'Poll' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page]||1).per(10)
sameName=@config_page?Organization.where('name = ? and id != ?',params[:org_name],params[:org_id].to_i).count==0:Organization.where('name = ?',params[:org_name]).count==0
sql="select courses.* from courses inner join members on courses.id = members.course_id where members.user_id = #{User.current.id} and courses.name like '#{condition}'"+
"and courses.id not in (select distinct org_courses.course_id from org_courses where org_courses.organization_id = #{@organization.id})"
sql="select projects.* from projects inner join members on projects.id = members.project_id where members.user_id = #{User.current.id} and projects.status != 9 and projects.name like '#{condition}'"+
" and projects.id not in (select org_projects.project_id from org_projects where organization_id = #{@organization.id})"
@ -75,17 +75,19 @@ class ProjectsController < ApplicationController
if!params[:name].nil?
condition="%#{params[:name].strip}%".gsub("","")
end
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)
@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)
@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
project_org_ids=OrgProject.find_by_sql("select distinct organization_id from org_projects where project_id = #{params[:id]}").map(&:organization_id)<<0
@orgs_not_in_project=User.current.organizations.where("organizations.id not in (#{project_org_ids.join(',')}) and organizations.name like ?",condition).page(params[:page].to_i||1).per(limit)
@org_count=User.current.organizations.where("organizations.id not in (#{project_org_ids.join(',')}) and organizations.name like '#{condition}'").count
# if project_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(limit)
# @org_count = Organization.where("is_public = 1 or creator_id =?", User.current.id).where("name like ?", condition).count
# @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
@events_pages=ForgeActivity.where("project_id = ? and forge_act_type != ?",@project,"Document").order("created_at desc").page(params['page'||1]).per(20);
caseparams[:type]
whennil
@events_pages=ForgeActivity.where("project_id = ? and forge_act_type in ('Issue', 'Message','News', 'ProjectCreateInfo')",@project).order("updated_at desc").limit(10).offset(@page*10)
when'issue'
@events_pages=ForgeActivity.where("project_id = ? and forge_act_type = 'Issue'",@project).order("updated_at desc").limit(10).offset(@page*10)
when'news'
@events_pages=ForgeActivity.where("project_id = ? and forge_act_type = 'News'",@project).order("updated_at desc").limit(10).offset(@page*10)
when'message'
@events_pages=ForgeActivity.where("project_id = ? and forge_act_type = 'Message'",@project).order("updated_at desc").limit(10).offset(@page*10)
end
#events = @activity.events(@date_from, @date_to)
else
@events_pages=ForgeActivity.includes(:project).where("forge_activities.project_id = ? and projects.is_public
@ -499,6 +518,14 @@ class ProjectsController < ApplicationController
defedit
end
defset_public_or_private
@project=Project.find(params[:id])
if@project.is_public?
@project.update_attribute(:is_public,0)
else
@project.update_attribute(:is_public,1)
end
end
# by young
# include CoursesHelper
defmember
@ -686,7 +713,11 @@ class ProjectsController < ApplicationController
@school=School.where("name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'").page((params[:page].to_i||1)-1).per(100)
@school=School.where("name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'").reorder('pinyin').page((params[:page].to_i||1)-1).per(100)
@school_count=School.where("name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'").count
ShieldActivity.where("container_type='Organization' and container_id=#{params[:org_id].to_i} and shield_type='Project' and shield_id=#{params[:project_id]}").eachdo|act|
ShieldActivity.where("container_type='Organization' and container_id=#{params[:org_id].to_i} and shield_type='Course' and shield_id=#{params[:course_id]}").eachdo|act|
act.destroy
end
end
elsifparams[:user_id]
ifparams[:project_id]
ShieldActivity.where("container_type='User' and container_id=#{params[:user_id].to_i} and shield_type='Project' and shield_id=#{params[:project_id]}").eachdo|act|
ShieldActivity.where("container_type='User' and container_id=#{params[:user_id].to_i} and shield_type='Course' and shield_id=#{params[:course_id]}").eachdo|act|
@ -95,12 +96,27 @@ class StudentWorkController < ApplicationController
@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=@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(:id=>pro.student_work_id)
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)
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(:id=>pro.student_work_id)
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)
end
ifmy_work.empty?
@stundet_works=[]
else
@ -116,12 +132,27 @@ class StudentWorkController < ApplicationController
@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(: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(:id=>pro.student_work_id)
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)
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(:id=>pro.student_work_id)
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)
end
ifmy_work.empty?
@stundet_works=[]
else
@ -168,9 +199,15 @@ class StudentWorkController < ApplicationController
@ -128,7 +135,7 @@ class UsersController < ApplicationController
#课程相关消息
when'homework'
@message_alls=CourseMessage.where("course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage','StudentWork') and user_id =?",@user).order("created_at desc")
@message_alls=CourseMessage.where("course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage','StudentWork','Exercise') and user_id =?",@user).order("created_at desc")
when'course_message'
@message_alls=CourseMessage.where("course_message_type =? and user_id =?","Message",@user).order("created_at desc")
when'course_news'
@ -185,11 +192,13 @@ class UsersController < ApplicationController
forge_querys=ForgeMessage.where("user_id =? and viewed =?",user,0)
user_querys=UserFeedbackMessage.where("user_id =? and viewed =?",user,0)
forum_querys=MemoMessage.where("user_id =? and viewed =?",user,0)
org_querys=OrgMessage.where("user_id=? and viewed=0",user)
ifUser.current.id==@user.id
course_querys.update_all(:viewed=>true)
forge_querys.update_all(:viewed=>true)
user_querys.update_all(:viewed=>true)
forum_querys.update_all(:viewed=>true)
org_querys.update_all(:viewed=>true)
end
end
@ -396,8 +405,47 @@ class UsersController < ApplicationController
@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")
@ -856,7 +955,7 @@ class UsersController < ApplicationController
#显示更多用户课程
defuser_courses4show
@page=params[:page].to_i+1
@courses=@user.courses.visible.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(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5).offset(@page*5)
end
#显示更多用户项目
@ -946,9 +1045,11 @@ class UsersController < ApplicationController
"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")
end
elsifparams[:type]=="2"#课程资源
@ -1367,15 +1468,15 @@ class UsersController < ApplicationController
"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")
end
elsifparams[:type]=="2"#课程资源
@ -1423,12 +1524,14 @@ class UsersController < ApplicationController
defsearch_user_course
@user=User.current
if!params[:search].nil?
@course=@user.courses.where("#{Course.table_name}.id = #{params[:search].to_i} or #{Course.table_name}.name like '%#{params[:search.to_s]}%'")
search="%#{params[:search].to_s.strip.downcase}%"
@course=@user.courses.where("#{Course.table_name}.id = #{params[:search].to_i} or #{Course.table_name}.name like :p",:p=>search)
"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")
end
elsifparams[:type]=="2"#课程资源
@ -1828,9 +2169,9 @@ class UsersController < ApplicationController
end
elsifparams[:type]=="4"#附件
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
@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
elsifparams[:type]=="5"#用户资源
ifUser.current.id.to_i==params[:id].to_i
@ -1855,46 +2196,46 @@ class UsersController < ApplicationController
@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")
@attachments=Attachment.where("((author_id = #{params[:id]} 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 (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")
end
end
@type=params[:type]
@ -1932,6 +2273,31 @@ 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}%'"
user.courses.visible.select("courses.*,(SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").select{|c|user.allowed_to?(:as_teacher,c)}.eachdo|course|
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").select{|c|user.allowed_to?(:as_teacher,c)}.eachdo|course|
@ -92,7 +106,35 @@ class Attachment < ActiveRecord::Base
" LEFT JOIN #{News.table_name} ON #{Attachment.table_name}.container_type='News' AND (#{News.table_name}.project_id in "+self.public_project_id+" OR #{News.table_name}.course_id in "+self.public_course_id+")"+
" LEFT JOIN #{HomeworkAttach.table_name} ON #{Attachment.table_name}.container_type='HomeworkAttach' AND #{HomeworkAttach.table_name}.bid_id in "+self.public_bid_id)
}
scope:indexable,lambda{where('is_public = 1 and ((container_type in ("Principal")) '+
'or (container_type = "Course" and container_id in( SELECT `courses`.id FROM `courses` WHERE (courses.status <> 9 AND courses.is_public = 1)) )'+
'or (container_type = "Project" and container_id in(SELECT `projects`.id FROM `projects` WHERE (projects.status <> 9 AND projects.is_public = 1) ))'+')')}#用于elastic建索引的scope
defself.search(query)
__elasticsearch__.search(
{
query:{
multi_match:{
query:query,
type:"most_fields",
operator:"or",
fields:['filename']
}
},
sort:{
_score:{order:"desc"},
downloads:{order:"desc"}
},
highlight:{
pre_tags:['<span class="c_red">'],
post_tags:['</span>'],
fields:{
filename:{}
}
}
}
)
end
# add by nwb
# 公开的项目id列表
defself.public_project_id
@ -307,11 +349,18 @@ class Attachment < ActiveRecord::Base
# Deletes the file from the file system if it's not referenced by other attachments
defdelete_from_disk
ifAttachment.where("disk_filename = ? AND id <> ?",disk_filename,id).empty?
#资源存在,且历史记录为0 且 该资源没有存在任何拷贝才能删除资源
ifAttachment.where("disk_filename = ? AND id <> ?",disk_filename,id).empty?&&self.attachment_histories.count==0&&Attachment.where('copy_from = ?',self.id).count==0
@ -18,7 +32,7 @@ class Course < ActiveRecord::Base
:conditions=>"#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE})"
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
defstudent_work_score_avg
@ -158,7 +158,12 @@ class Member < ActiveRecord::Base
end
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
has_many:members,:include=>[:principal,:roles],:conditions=>"#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}"
@ -73,6 +87,7 @@ class Project < ActiveRecord::Base