@ -581,6 +582,13 @@ class CoursesController < ApplicationController
end
end
end
end
defis_deleted
if@course.is_delete==1and!User.current.admin?
render_404
return
end
end
defget_courses
defget_courses
@user=User.current
@user=User.current
membership=@user.coursememberships.all
membership=@user.coursememberships.all
@ -634,6 +642,11 @@ class CoursesController < ApplicationController
end
end
defshow
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=@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)
create_course_messages.update_all(:viewed=>true)
@ -684,10 +697,10 @@ class CoursesController < ApplicationController
@org_activities=OrgActivity.where("org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})").order('updated_at desc').page(params[:page]||1).per(10)
whennil
else
@org_activities=OrgActivity.where("(container_id =? and container_type =?) "+
project_ids=@organization.projects.map(&:id)<<0
"or (container_type ='Project' and org_act_type in ('Issue','Message','ProjectCreateInfo') and container_id in (#{project_ids.join(',')})) "+
course_ids=@organization.courses.map(&:id)<<0
"or (container_type ='Course' and org_act_type in #{course_types} and container_id in (#{course_ids.join(',')}))",
@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)
@org_activities=OrgActivity.where("(container_id =? and container_type =?) "+
when'project_message'
"or (container_type ='Project' and org_act_type in ('Issue','Message','ProjectCreateInfo') and container_id in (#{project_ids.join(',')})) "+
@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)
"or (container_type ='Course' and org_act_type in #{course_types} and container_id in (#{course_ids.join(',')}))",
@org_activities=OrgActivity.where("container_id =? and container_type =?",@organization.id,'Organization').order('updated_at desc').page(params[:page]||1).per(10)
when'project_issue'
when'course_homework'
@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)
@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'project_message'
when'course_news'
@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)
@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'org'
when'course_message'
@org_activities=OrgActivity.where("container_id =? and container_type =?",@organization.id,'Organization').order('updated_at desc').page(params[:page]||1).per(10)
@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_homework'
when'course_poll'
@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)
@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)
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)
end
end
end
@page=params[:page]
@page=params[:page]
respond_todo|format|
respond_todo|format|
@ -142,6 +161,12 @@ class OrganizationsController < ApplicationController
# end
# end
end
end
defcancel_homepage
@org=Organization.find(params[:id])
@org.home_id=nil
@org.save
end
defautocomplete_search
defautocomplete_search
@project=Project.find(params[:project_id])
@project=Project.find(params[:project_id])
#@flag = params[:flag] || false
#@flag = params[:flag] || false
@ -220,6 +245,13 @@ class OrganizationsController < ApplicationController
@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)
#events = @activity.events(@date_from, @date_to)
else
else
@events_pages=ForgeActivity.includes(:project).where("forge_activities.project_id = ? and projects.is_public
@events_pages=ForgeActivity.includes(:project).where("forge_activities.project_id = ? and projects.is_public
@ -686,7 +697,11 @@ class ProjectsController < ApplicationController
@ -95,12 +95,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=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?
ifmy_work.empty?
@stundet_works=[]
@stundet_works=[]
else
else
@ -116,12 +131,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=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?
ifmy_work.empty?
@stundet_works=[]
@stundet_works=[]
else
else
@ -190,6 +220,10 @@ class StudentWorkController < ApplicationController
@attachments=Attachment.where("((author_id = #{params[:id]} and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
@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(',')})) )"+
" 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
end
elsifparams[:type]=="2"#课程资源
elsifparams[:type]=="2"#课程资源
ifUser.current.id.to_i==params[:id].to_i
ifUser.current.id.to_i==params[:id].to_i
user_course_ids=User.current.courses.map{|c|c.id}
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') "+
@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(',')})) )"+
"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
end
elsifparams[:type]=="3"#项目资源
elsifparams[:type]=="3"#项目资源
ifUser.current.id.to_i==params[:id].to_i
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
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
end
elsifparams[:type]=="4"#附件
elsifparams[:type]=="4"#附件
ifUser.current.id.to_i==params[:id].to_i
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
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
end
elsifparams[:type]=="5"#用户资源
elsifparams[:type]=="5"#用户资源
ifUser.current.id.to_i==params[:id].to_i
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
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")
@ -32,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})"
:conditions=>"#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE})"
has_many:members,:include=>[:principal,:roles],:conditions=>"#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}"
has_many:members,:include=>[:principal,:roles],:conditions=>"#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}"
@ -86,6 +87,7 @@ class Project < ActiveRecord::Base
<% 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)%>
<% 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)%>