@ -38,7 +38,8 @@ class ApplicationController < ActionController::Base
protect_from_forgery
defhandle_unverified_request
super
cookies.delete(autologin_cookie_name)
raise(ActionController::InvalidAuthenticityToken)
# cookies.delete(autologin_cookie_name)
end
before_filter:find_first_page
@ -381,6 +382,11 @@ class ApplicationController < ActionController::Base
ifallowed
true
else
ifparams[:action]=='show'
#更新申请结果反馈消息的状态
messages=CourseMessage.where("course_message_type =? and course_id =? and user_id =? and viewed =?",'CourseRequestDealResult',@course.id,User.current.id,false)
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
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)
#更新申请结果反馈消息的状态
course_request_messages=CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =?",User.current.id,@course.id,'CourseRequestDealResult',false)
@ -134,8 +135,12 @@ class FilesController < ApplicationController
ifsort==""
sort="created_on DESC"
end
ifkeywords!="%%"
resultSet=Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' AND filename LIKE :like ",like:"%#{keywords}%").
reorder(sort)
else
resultSet=Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.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
@ -176,12 +181,6 @@ class FilesController < ApplicationController
absence_penalty_count=student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count-student_work.user.student_works_scores.where("student_work_id IN #{work_ids}").count
absence_penalty_count=student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count-student_work.user.student_works_scores.where("student_work_id IN #{work_ids}").count
@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
@ -69,6 +69,30 @@ class ProjectsController < ApplicationController
### added by william
includeActsAsTaggableOn::TagsHelper
#查找组织
defsearch_public_orgs_not_in_project
condition='%%'
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
@ -322,6 +349,12 @@ class ProjectsController < ApplicationController
end
defsettings
# 修改查看消息状态
applied_messages=ForgeMessage.where("user_id =? and project_id =? and forge_message_type =? and viewed =?",User.current.id,@project,"AppliedProject",0)
applied_messages.eachdo|applied_message|
applied_message.update_attributes(:viewed=>true)
end
# end
@issue_custom_fields=IssueCustomField.sorted.all
@issue_category||=IssueCategory.new
@member||=@project.members.new
@ -329,6 +362,15 @@ class ProjectsController < ApplicationController
@wiki||=@project.wiki
@select_tab=params[:tab]
#找出所有不属于项目的公共组织
project_org_ids=OrgProject.find_by_sql("select distinct organization_id from org_projects where project_id = #{@project.id}")
studentworks_scores=CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =?",User.current.id,@homework.course,"StudentWorksScore",0)
journals_for_teacher=CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =?",User.current.id,@homework.course,"JournalsForMessage",0)
no_evaluation=CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =? and status =?",User.current.id,@homework.course,"StudentWork",0,0)
no_evaluation.update_all(:viewed=>true)
# 作品留言
# 消息end
#设置作业对应的forge_messages表的viewed字段
query_student_work=@homework.course_messages
query_student_work.eachdo|query|
@ -18,8 +74,13 @@ 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("users.lastname #{@b_sort}, users.firstname #{@b_sort}"),@name
else
@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
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)
ifmy_work.empty?
@stundet_works=[]
else
if@order=="name"
@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("users.lastname #{@b_sort}, users.firstname #{@b_sort}"),@name
else
@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=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)
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)
ifmy_work.empty?
@stundet_works=[]
else
@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
@show_all=true
end
else
@stundet_works=[]
end
@student_work_count=(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).count
@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).order("users.lastname #{@b_sort}, users.firstname #{@b_sort}"),@name
else
@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
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)
ifmy_work.empty?
@stundet_works=[]
else
if@order=="name"
@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).order("users.lastname #{@b_sort}, users.firstname #{@b_sort}"),@name
else
@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=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)
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)
ifmy_work.empty?
@stundet_works=[]
else
@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
@show_all=true
end
else
@stundet_works=[]
end
@student_work_count=(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).count
absence_penalty_count=student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count-student_work.user.student_works_scores.where("student_work_id IN #{work_ids}").count
memos=Memo.where('author_id = ? AND parent_id IS NOT NULL',user.id)
memos.eachdo|m|
ifMemo.find(m.parent_id).author.id!=user.id
issue_c=issue_c+1
@ -35,18 +35,18 @@ module UserScoreHelper
issue_c=issue_c-1
end
end
pmemos=Memo.where('author_id = ? AND parent_id IS NULL',user.id)
pmemos.eachdo|pm|
issue_c=issue_c+pm.replies_count
end
############################
issue_c=issue_c+JournalsForMessage.where('user_id = ? AND reply_id IS NOT NULL AND reply_id <> ?',user.id,user.id).count+JournalsForMessage.where('reply_id = ? AND user_id <> ?',user.id,user.id).count
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|
has_many:articles,:class_name=>'BlogComment',:conditions=>"#{BlogComment.table_name}.parent_id IS NULL ",:order=>"#{BlogComment.table_name}.created_on DESC"
@ -18,6 +18,8 @@ class Course < ActiveRecord::Base
:conditions=>"#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE})"