@ -87,6 +130,30 @@ 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")
end
deffind_project_attachekeywords,project,sort=""
ifsort==""
sort="created_on DESC"
end
ids=""
len=0
count=project.versions.count
project.versions.eachdo|version|
len=len+1
iflen!=count
ids+=version.id.to_s+','
else
ids+=version.id.to_s
end
end
ifids.blank?
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}%").
@ -49,14 +51,16 @@ class HomeworkAttachController < ApplicationController
order_by="created_at #{direction}"
end
all_homework_list=HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*,
(SELECTstarsFROMseems_rateable_ratesWHERErateable_type='HomeworkAttach'ANDrateable_id=homework_attaches.idANDis_teacher_score=1ANDstarsISNOTNULL ORDER BYupdated_atDESClimit0,1)ASt_score,
(SELECTstarsFROMseems_rateable_ratesWHERErateable_type='HomeworkAttach'ANDrateable_id=homework_attaches.idANDis_teacher_score=1ANDstarsISNOTNULL ORDER BYupdated_atDESClimit0,1)ASt_score,
bids=courses[i].homeworks.where("bids.created_on between '#{date_from}' and '#{date_to}'").order("bids.created_on desc")
attachments=courses[i].attachments.where("attachments.created_on between '#{date_from}' and '#{date_to}'").order('attachments.created_on DESC')
@bids+=bidsifbids.count>0
@attachments+=attachmentsifattachments.count>0
end
end
# user 提交的作业
@homeworks=HomeworkAttach.where("user_id=#{user.id} and (created_at between '#{date_from}' and '#{date_to}')").order("created_at desc")
# 查询user在课程。项目中发布的讨论帖子
messages=Message.find_by_sql("select DISTINCT * from messages where author_id = #{user.id} and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc")
@course_messages||=[]
@project_messages||=[]
unlessmessages.first.nil?
messages.eachdo|msg|
ifmsg.project
@project_messages<<msg
elsifmsg.course
@course_messages<<msg
end
end
end
# 查询user在课程中发布的通知,项目中发的新闻
@course_news=(course_ids&&!course_ids.empty?)?News.find_by_sql("select DISTINCT n.* from news n
@user_journal_messages=user.journals_for_messages.where("m_parent_id IS NULL and (created_on between '#{date_from}' and '#{date_to}')").order('created_on DESC')
# 查询user新建贴吧或发布帖子
@forums=Forum.find_by_sql("select DISTINCT * from forums where creator_id = #{user.id} and (created_at between '#{date_from}' and '#{date_to}') order by created_at desc")
@memos=Memo.find_by_sql("select DISTINCT m.* from memos m, forums f where (m.author_id = #{user.id} or (m.forum_id = f.id and f.creator_id = #{user.id}))
@course_journal_messages=JournalsForMessage.find_by_sql("select DISTINCT * from journals_for_messages where
@ -114,15 +160,15 @@ class Mailer < ActionMailer::Base
@forums=Forum.find_by_sql("select DISTINCT * from forums where creator_id = #{user.id} and (created_at between '#{date_from}' and '#{date_to}') order by created_at desc")
@memos=Memo.find_by_sql("select DISTINCT m.* from memos m, forums f where (m.author_id = #{user.id} or (m.forum_id = f.id and f.creator_id = #{user.id}))
:joins=>"LEFT JOIN #{Course.table_name} ON ( #{Poll.table_name}.polls_type='Course' AND #{Poll.table_name}.polls_status= 2 AND #{Poll.table_name}.polls_group_id = #{Course.table_name}.id )"},
sql_select="SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches
WHEREmembers.course_id=#{course_id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{course_id}) AND members.user_id = homework_attaches.user_id
ANDhomework_attaches.bid_idin(SELECTbid_idFROMhomework_for_coursesWHEREcourse_id=#{course_id}) GROUP BY members.user_id
UNIONall
SELECTmembers.*,0asscoreFROMmembers,homework_attaches,students_for_coursesWHEREmembers.course_id=#{course_id} AND
students_for_courses.course_id=#{course_id} and members.user_id = students_for_courses.student_id AND
sql_select="SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches
WHEREmembers.course_id=#{course_id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{course_id}) AND members.user_id = homework_attaches.user_id
ANDhomework_attaches.bid_idin(SELECTbid_idFROMhomework_for_coursesWHEREcourse_id=#{course_id}) GROUP BY members.user_id
UNIONall
SELECTmembers.*,0asscoreFROMmembers,homework_attaches,students_for_coursesWHEREmembers.course_id=#{course_id} AND
students_for_courses.course_id=#{course_id} and members.user_id = students_for_courses.student_id AND
sql_select="SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches
WHEREmembers.course_id=#{course_id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{course_id}) AND members.user_id = homework_attaches.user_id
andmembers.course_group_id=#{groupid} AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id})