2013-09-12 17:19:51 +08:00
|
|
|
class CoursesController < ApplicationController
|
2014-06-12 16:01:38 +08:00
|
|
|
layout 'base_courses'
|
2014-03-17 22:43:38 +08:00
|
|
|
include CoursesHelper
|
2014-06-06 08:50:46 +08:00
|
|
|
helper :activities
|
2014-06-09 14:23:31 +08:00
|
|
|
helper :members
|
2014-06-12 11:34:47 +08:00
|
|
|
helper :words
|
2014-05-29 16:35:34 +08:00
|
|
|
|
2014-06-26 14:47:29 +08:00
|
|
|
menu_item :overview
|
|
|
|
menu_item :feedback, :only => :feedback
|
|
|
|
menu_item :homework, :only => :homework
|
|
|
|
|
2014-05-29 16:35:34 +08:00
|
|
|
menu_item l(:label_sort_by_time), :only => :index
|
|
|
|
menu_item l(:label_sort_by_active), :only => :index
|
|
|
|
menu_item l(:label_sort_by_influence), :only => :index
|
|
|
|
|
2014-06-16 17:14:05 +08:00
|
|
|
before_filter :find_course, :except => [ :index, :search,:list, :new,:join,:unjoin, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches]
|
2014-06-06 13:56:48 +08:00
|
|
|
before_filter :authorize_course, :only => [:show, :settings, :edit, :update, :modules, :close, :reopen, :view_homework_attaches, :course]
|
|
|
|
before_filter :authorize_course_global, :only => [:view_homework_attaches, :new,:create]
|
2014-06-04 15:47:09 +08:00
|
|
|
before_filter :require_admin, :only => [:copy, :archive, :unarchive, :destroy, :calendar]
|
2014-06-05 10:33:32 +08:00
|
|
|
before_filter :toggleCourse, only: [:finishcourse, :restartcourse]
|
2014-05-29 16:35:34 +08:00
|
|
|
|
2013-09-12 10:41:15 +08:00
|
|
|
before_filter :require_login, :only => [:join, :unjoin]
|
2014-03-17 22:43:38 +08:00
|
|
|
before_filter :allow_join, :only => [:join]
|
2014-05-29 16:35:34 +08:00
|
|
|
|
2013-09-12 10:41:15 +08:00
|
|
|
def join
|
|
|
|
if User.current.logged?
|
2014-06-16 17:14:05 +08:00
|
|
|
course = Course.find(params[:object_id])
|
|
|
|
if params[:course_password] == course.password
|
2014-03-17 22:43:38 +08:00
|
|
|
members = []
|
|
|
|
members << Member.new(:role_ids => [10], :user_id => User.current.id)
|
|
|
|
course.members << members
|
2014-06-04 15:47:09 +08:00
|
|
|
|
2014-03-17 22:43:38 +08:00
|
|
|
StudentsForCourse.create(:student_id => User.current.id, :course_id => params[:object_id])
|
|
|
|
@state = 0
|
2013-09-12 10:41:15 +08:00
|
|
|
else
|
2014-03-19 15:50:02 +08:00
|
|
|
@state = 1
|
2013-09-12 10:41:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
respond_to do |format|
|
|
|
|
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
|
2014-06-16 17:14:05 +08:00
|
|
|
format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Course.find(params[:object_id]), :object_id => params[:object_id]} }
|
2013-09-12 10:41:15 +08:00
|
|
|
end
|
|
|
|
end
|
2014-06-04 15:47:09 +08:00
|
|
|
|
2013-09-12 10:41:15 +08:00
|
|
|
def unjoin
|
|
|
|
if User.current.logged?
|
2014-06-04 15:47:09 +08:00
|
|
|
|
2014-06-16 17:14:05 +08:00
|
|
|
@member = Member.where('course_id = ? and user_id = ?', params[:object_id], User.current.id)
|
2013-09-12 10:41:15 +08:00
|
|
|
@member.first.destroy
|
2014-06-04 15:47:09 +08:00
|
|
|
|
2013-09-12 10:41:15 +08:00
|
|
|
joined = StudentsForCourse.where('student_id = ? and course_id = ?', User.current.id, params[:object_id])
|
|
|
|
joined.each do |join|
|
|
|
|
join.delete
|
|
|
|
end
|
|
|
|
end
|
|
|
|
respond_to do |format|
|
|
|
|
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
|
2014-06-16 17:14:05 +08:00
|
|
|
format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Course.find(params[:object_id]), :object_id => params[:object_id]} }
|
2013-09-12 10:41:15 +08:00
|
|
|
end
|
|
|
|
end
|
2014-03-17 22:43:38 +08:00
|
|
|
|
2014-06-13 16:18:03 +08:00
|
|
|
#更新课程信息
|
2014-06-09 14:23:31 +08:00
|
|
|
def update
|
|
|
|
@course.safe_attributes = params[:course]
|
|
|
|
@course.class_period = params[:class_period]
|
|
|
|
if @course.save
|
|
|
|
if params[:course][:is_public] == '0'
|
|
|
|
course_status = CourseStatus.find_by_course_id(@course.id)
|
|
|
|
course_status.destroy if course_status
|
|
|
|
elsif params[:course][:is_public] == '1'
|
2014-06-11 11:04:38 +08:00
|
|
|
course_status = CourseStatus.find_by_course_id(@course.id)
|
|
|
|
course_status.destroy if course_status
|
2014-06-09 14:23:31 +08:00
|
|
|
course_status = CourseStatus.create(:course_id => @course.id, :grade => 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
flash[:notice] = l(:notice_successful_update)
|
|
|
|
redirect_to settings_course_path(@course)
|
|
|
|
}
|
|
|
|
format.api { render_api_ok }
|
|
|
|
end
|
|
|
|
else
|
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
settings
|
|
|
|
render :action => 'settings'
|
|
|
|
}
|
|
|
|
format.api { render_validation_errors(@course) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-16 17:14:05 +08:00
|
|
|
def new_join
|
|
|
|
@course = Course.find(params[:object_id])
|
|
|
|
end
|
|
|
|
|
2014-06-12 16:55:56 +08:00
|
|
|
# 课程搜索
|
|
|
|
# add by nwb
|
|
|
|
def search
|
|
|
|
courses_all = Course.all_course
|
|
|
|
|
|
|
|
@courses = courses_all.visible
|
|
|
|
if params[:name].present?
|
|
|
|
@courses_all = @courses.like(params[:name])
|
|
|
|
else
|
|
|
|
@courses_all = @courses;
|
|
|
|
end
|
|
|
|
@course_count = @courses_all.count
|
|
|
|
@course_pages = Paginator.new @course_count, per_page_option, params['page']
|
|
|
|
|
2014-06-18 11:08:44 +08:00
|
|
|
# 课程的动态数
|
2014-06-12 16:55:56 +08:00
|
|
|
@course_activity_count=Hash.new
|
|
|
|
@courses_all.each do |course|
|
|
|
|
@course_activity_count[course.id]=0
|
|
|
|
end
|
|
|
|
|
|
|
|
case params[:course_sort_type]
|
|
|
|
when '0'
|
|
|
|
@courses = @courses_all.order("created_at desc")
|
|
|
|
@s_type = 0
|
|
|
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
|
|
|
|
|
|
|
@course_activity_count=get_course_activity @courses,@course_activity_count
|
|
|
|
|
|
|
|
when '1'
|
|
|
|
@courses = @courses_all.order("course_ac_para desc")
|
|
|
|
@s_type = 1
|
|
|
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
|
|
|
|
|
|
|
@course_activity_count=get_course_activity @courses,@course_activity_count
|
|
|
|
|
|
|
|
when '2'
|
|
|
|
@courses = @courses_all.order("watchers_count desc")
|
|
|
|
@s_type = 2
|
|
|
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
|
|
|
|
|
|
|
@course_activity_count=get_course_activity @courses,@course_activity_count
|
|
|
|
|
|
|
|
when '3'
|
|
|
|
@course_activity_count=get_course_activity @courses_all,@course_activity_count_array
|
|
|
|
@courses=handle_course @courses_all,@course_activity_count
|
|
|
|
@s_type = 3
|
|
|
|
@courses = @courses[@course_pages.offset, @course_pages.per_page]
|
|
|
|
|
|
|
|
else
|
|
|
|
@s_type = 0
|
|
|
|
@courses = @courses_all.order("created_at desc")
|
|
|
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
|
|
|
|
|
|
|
@course_activity_count=get_course_activity @courses,@course_activity_count
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
render :layout => 'base'
|
|
|
|
scope = Course
|
|
|
|
unless params[:closed]
|
|
|
|
scope = scope.active
|
|
|
|
end
|
|
|
|
}
|
|
|
|
format.atom {
|
|
|
|
courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all
|
|
|
|
render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}")
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-12 14:57:25 +08:00
|
|
|
def member
|
|
|
|
## 有角色参数的才是课程,没有的就是项目
|
|
|
|
@render_file = 'member_list'
|
|
|
|
@teachers= searchTeacherAndAssistant(@course)
|
|
|
|
@canShowCode = isCourseTeacher(User.current.id)
|
|
|
|
case params[:role]
|
|
|
|
when '1'
|
|
|
|
@subPage_title = l :label_teacher_list
|
|
|
|
@members = searchTeacherAndAssistant(@course)
|
|
|
|
when '2'
|
|
|
|
@subPage_title = l :label_student_list
|
|
|
|
@members = searchStudent(@course)
|
|
|
|
else
|
|
|
|
@subPage_title = ''
|
|
|
|
@members = @course.member_principals.includes(:roles, :principal).all.sort
|
|
|
|
end
|
|
|
|
@members = paginateHelper @members
|
|
|
|
render :layout => 'base_courses'
|
|
|
|
end
|
|
|
|
|
|
|
|
#判断指定用户是否为课程教师
|
|
|
|
def isCourseTeacher(id)
|
|
|
|
result = false
|
|
|
|
if @teachers.find_by_user_id(id) != nil
|
|
|
|
result = true
|
|
|
|
end
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
2014-06-04 15:47:09 +08:00
|
|
|
def handle_course courses, activities
|
2014-06-03 16:21:00 +08:00
|
|
|
course_activity_count_array=activities.values()
|
|
|
|
|
|
|
|
course_array=[]
|
|
|
|
i=0;
|
|
|
|
courses.each do |course|
|
|
|
|
course_array[i]=course
|
|
|
|
i=i+1
|
|
|
|
end
|
|
|
|
|
2014-06-04 15:47:09 +08:00
|
|
|
courses=desc_sort_course_by_avtivity(course_activity_count_array, course_array)
|
2014-06-03 16:21:00 +08:00
|
|
|
|
|
|
|
return courses
|
|
|
|
end
|
|
|
|
|
2014-06-04 16:45:20 +08:00
|
|
|
def settings
|
|
|
|
@issue_custom_fields = IssueCustomField.sorted.all
|
|
|
|
@issue_category ||= IssueCategory.new
|
2014-06-09 14:23:31 +08:00
|
|
|
@member ||= @course.members.new
|
2014-06-04 16:45:20 +08:00
|
|
|
@trackers = Tracker.sorted.all
|
2014-06-09 14:23:31 +08:00
|
|
|
end
|
2014-06-04 16:45:20 +08:00
|
|
|
|
2014-06-04 15:47:09 +08:00
|
|
|
def create
|
|
|
|
if User.current.user_extensions.identity
|
|
|
|
@course = Course.new
|
|
|
|
@course.extra='course' + DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d_%H-%M-%S').to_s
|
|
|
|
@course.safe_attributes = params[:course]
|
|
|
|
@course.tea_id = User.current.id
|
|
|
|
# added by bai
|
|
|
|
@course.term = params[:term]
|
|
|
|
@course.time = params[:time]
|
|
|
|
#@course.school_id = params[:occupation]
|
|
|
|
@course.school_id = User.current.user_extensions.school_id
|
|
|
|
@course.setup_time = params[:setup_time]
|
|
|
|
@course.endup_time = params[:endup_time]
|
|
|
|
@course.class_period = params[:class_period]
|
|
|
|
end
|
|
|
|
|
|
|
|
@issue_custom_fields = IssueCustomField.sorted.all
|
|
|
|
@trackers = Tracker.sorted.all
|
|
|
|
|
|
|
|
if User.current.user_extensions.identity == 0
|
2014-06-09 10:26:45 +08:00
|
|
|
if @course.save
|
2014-06-19 09:37:58 +08:00
|
|
|
#unless User.current.admin?
|
2014-06-04 15:47:09 +08:00
|
|
|
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
|
|
|
|
m = Member.new(:user => User.current, :roles => [r])
|
2014-06-09 10:26:45 +08:00
|
|
|
m.project_id = -1
|
2014-06-05 16:41:05 +08:00
|
|
|
course = CourseInfos.new(:user_id => User.current.id, :course_id => @course.id)
|
2014-06-04 16:45:20 +08:00
|
|
|
#user_grades = UserGrade.create(:user_id => User.current.id, :course_id => @course.id)
|
2014-06-04 15:47:09 +08:00
|
|
|
if params[:course][:is_public] == '1'
|
|
|
|
course_status = CourseStatus.create(:course_id => @course.id, :watchers_count => 0, :changesets_count => 0, :grade => 0, :course_type => @course_tag)
|
|
|
|
end
|
|
|
|
@course.members << m
|
2014-06-05 16:41:05 +08:00
|
|
|
@course.course_infos << course
|
2014-06-19 09:37:58 +08:00
|
|
|
#end
|
2014-06-04 15:47:09 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
flash[:notice] = l(:notice_successful_create)
|
|
|
|
if params[:continue]
|
|
|
|
redirect_to new_course_path(attrs, :course => '0')
|
|
|
|
elsif params[:course_continue]
|
|
|
|
redirect_to new_course_path(:course => '1')
|
|
|
|
else
|
|
|
|
redirect_to settings_course_path(@course, :course_type => 1)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'courses', :action => 'show', :id => @course.id) }
|
|
|
|
end
|
|
|
|
else
|
|
|
|
@course.destroy
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { render :action => 'new', :layout => 'base' } #Added by young
|
|
|
|
format.api { render_validation_errors(@course) }
|
|
|
|
end
|
|
|
|
end
|
2014-06-09 10:26:45 +08:00
|
|
|
end
|
2014-06-04 15:47:09 +08:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-06-10 17:03:02 +08:00
|
|
|
def course
|
|
|
|
@school_id = params[:school_id]
|
|
|
|
per_page_option = 10
|
|
|
|
if @school_id == "0" or @school_id.nil?
|
|
|
|
@courses_all = Course.active.visible.
|
|
|
|
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id").
|
|
|
|
where("#{Course.table_name}.course_type = ? ", Course::CourseType_course)
|
|
|
|
else
|
|
|
|
@courses_all = Course.active.visible.
|
|
|
|
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id").
|
|
|
|
joins(:course_extra).
|
|
|
|
where("#{Course.table_name}.course_type = ? AND #{Course.table_name}.school_id = ?", Course::CourseType_course, @school_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
@course_count = @courses_all.count
|
|
|
|
@course_pages = Paginator.new @course_count, per_page_option, params['page']
|
|
|
|
|
|
|
|
#gcm activity count
|
|
|
|
|
|
|
|
@course_activity_count=Hash.new
|
|
|
|
#count initialize
|
|
|
|
@courses_all.each do |course|
|
|
|
|
@course_activity_count[course.id]=0
|
|
|
|
end
|
|
|
|
|
|
|
|
#@course_activity_count=get_course_activity @courses_all,@course_activity_count
|
|
|
|
#gcm end
|
|
|
|
|
|
|
|
|
|
|
|
case params[:course_sort_type]
|
|
|
|
when '0'
|
|
|
|
@courses = @courses_all.order("created_on desc")
|
|
|
|
@s_type = 0
|
|
|
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
|
|
|
|
|
|
|
#gcm
|
|
|
|
@course_activity_count=get_course_activity @courses,@course_activity_count
|
|
|
|
#gcmend
|
|
|
|
|
|
|
|
when '1'
|
|
|
|
@courses = @courses_all.order("course_ac_para desc")
|
|
|
|
@s_type = 1
|
|
|
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
|
|
|
|
|
|
|
#gcm
|
|
|
|
@course_activity_count=get_course_activity @courses,@course_activity_count
|
|
|
|
#gcmend
|
|
|
|
|
|
|
|
when '2'
|
|
|
|
@courses = @courses_all.order("watchers_count desc")
|
|
|
|
@s_type = 2
|
|
|
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
|
|
|
|
|
|
|
#gcm
|
|
|
|
@course_activity_count=get_course_activity @courses,@course_activity_count
|
|
|
|
#gcmend
|
|
|
|
|
|
|
|
#gcm
|
|
|
|
when '3'
|
|
|
|
|
|
|
|
#gcm
|
|
|
|
@course_activity_count=get_course_activity @courses_all,@course_activity_count
|
|
|
|
#gcmend
|
|
|
|
|
|
|
|
@courses=handle_course @courses_all,@course_activity_count
|
|
|
|
@s_type = 3
|
|
|
|
@courses = @courses[@course_pages.offset, @course_pages.per_page]
|
|
|
|
else
|
|
|
|
@s_type = 0
|
|
|
|
@courses = @courses_all.order("created_on desc")
|
|
|
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
|
|
|
|
|
|
|
#gcm
|
|
|
|
@course_activity_count=get_course_activity @courses,@course_activity_count
|
|
|
|
#gcmend
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
render :layout => 'base'
|
|
|
|
}
|
|
|
|
format.api {
|
|
|
|
# @offset, @limit = api_offset_and_limit
|
|
|
|
# @course_count = Course.visible.count
|
|
|
|
# @courses = Course.visible.offset(@offset).limit(@limit).order('lft').all
|
|
|
|
}
|
|
|
|
format.atom {
|
|
|
|
courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all
|
|
|
|
render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}")
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-04 15:47:09 +08:00
|
|
|
|
2014-06-04 14:09:37 +08:00
|
|
|
def new
|
2014-06-04 15:47:09 +08:00
|
|
|
@course_type = params[:course_type] ||= params[:course]
|
2014-06-04 14:09:37 +08:00
|
|
|
@issue_custom_fields = IssueCustomField.sorted.all
|
2014-06-04 15:47:09 +08:00
|
|
|
@trackers = Tracker.sorted.all
|
2014-06-04 14:09:37 +08:00
|
|
|
|
2014-06-04 15:47:09 +08:00
|
|
|
@course = Course.new
|
|
|
|
@course.safe_attributes = params[:course]
|
2014-06-04 14:09:37 +08:00
|
|
|
|
|
|
|
render :layout => 'base'
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2014-06-04 15:47:09 +08:00
|
|
|
def desc_sort_course_by_avtivity(activity_count, courses)
|
2014-06-03 16:21:00 +08:00
|
|
|
return courses if activity_count.size<2
|
|
|
|
(activity_count.size-2).downto(0) do |i|
|
|
|
|
(0..i).each do |j|
|
|
|
|
if activity_count[j]<activity_count[j+1]
|
2014-06-04 15:47:09 +08:00
|
|
|
courses[j], courses[j+1]=courses[j+1], courses[j]
|
|
|
|
activity_count[j], activity_count[j+1]=activity_count[j+1], activity_count[j]
|
2014-06-03 16:21:00 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return courses
|
|
|
|
end
|
2014-05-29 16:35:34 +08:00
|
|
|
|
2014-06-03 09:39:33 +08:00
|
|
|
def index
|
|
|
|
@course_type = params[:course_type]
|
2014-05-29 16:35:34 +08:00
|
|
|
@school_id = params[:school_id]
|
|
|
|
per_page_option = 10
|
2014-06-03 16:21:00 +08:00
|
|
|
|
|
|
|
|
2014-05-29 16:35:34 +08:00
|
|
|
if @school_id == "0" or @school_id.nil?
|
2014-06-03 11:16:06 +08:00
|
|
|
@courses_all = Course.active.visible.
|
|
|
|
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id")
|
2014-05-29 16:35:34 +08:00
|
|
|
else
|
2014-06-03 11:16:06 +08:00
|
|
|
@courses_all = Course.active.visible.
|
|
|
|
joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.course_id").
|
2014-05-29 16:35:34 +08:00
|
|
|
joins(:course_extra).
|
2014-06-03 11:16:06 +08:00
|
|
|
where("#{Course.table_name}.course_type = ? AND #{Course.table_name}.school_id = ?", Course::CourseType_course, @school_id)
|
2014-05-29 16:35:34 +08:00
|
|
|
end
|
|
|
|
|
2014-06-03 09:39:33 +08:00
|
|
|
@course_count = @courses_all.count
|
|
|
|
@course_pages = Paginator.new @course_count, per_page_option, params['page']
|
2014-05-29 16:35:34 +08:00
|
|
|
|
2014-06-03 09:39:33 +08:00
|
|
|
@course_activity_count=Hash.new
|
|
|
|
@courses_all.each do |course|
|
|
|
|
@course_activity_count[course.id]=0
|
2014-05-29 16:35:34 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2014-06-03 09:39:33 +08:00
|
|
|
case params[:course_sort_type]
|
2014-05-29 16:35:34 +08:00
|
|
|
when '0'
|
2014-06-04 15:47:09 +08:00
|
|
|
@courses = @courses_all.order("created_at desc")
|
2014-05-29 16:35:34 +08:00
|
|
|
@s_type = 0
|
2014-06-04 15:47:09 +08:00
|
|
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
2014-05-29 16:35:34 +08:00
|
|
|
|
2014-06-13 11:49:28 +08:00
|
|
|
@course_activity_count=get_course_activity @courses, @course_activity_count
|
2014-05-29 16:35:34 +08:00
|
|
|
when '1'
|
2014-06-03 09:39:33 +08:00
|
|
|
@courses = @courses_all.order("course_ac_para desc")
|
2014-05-29 16:35:34 +08:00
|
|
|
@s_type = 1
|
2014-06-04 15:47:09 +08:00
|
|
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
2014-05-29 16:35:34 +08:00
|
|
|
|
2014-06-04 15:47:09 +08:00
|
|
|
@course_activity_count=get_course_activity @courses, @course_activity_count
|
2014-05-29 16:35:34 +08:00
|
|
|
when '2'
|
2014-06-03 09:39:33 +08:00
|
|
|
@courses = @courses_all.order("watchers_count desc")
|
2014-05-29 16:35:34 +08:00
|
|
|
@s_type = 2
|
2014-06-04 15:47:09 +08:00
|
|
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
2014-05-29 16:35:34 +08:00
|
|
|
|
2014-06-04 15:47:09 +08:00
|
|
|
@course_activity_count=get_course_activity @courses, @course_activity_count
|
2014-05-29 16:35:34 +08:00
|
|
|
|
|
|
|
when '3'
|
|
|
|
|
2014-06-04 15:47:09 +08:00
|
|
|
@course_activity_count=get_course_activity @courses_all, @course_activity_count
|
2014-05-29 16:35:34 +08:00
|
|
|
|
2014-06-04 15:47:09 +08:00
|
|
|
@courses=handle_course @courses_all, @course_activity_count
|
2014-06-11 11:04:38 +08:00
|
|
|
|
2014-05-29 16:35:34 +08:00
|
|
|
@s_type = 3
|
2014-06-04 15:47:09 +08:00
|
|
|
@courses = @courses[@course_pages.offset, @course_pages.per_page]
|
2014-05-29 16:35:34 +08:00
|
|
|
else
|
|
|
|
@s_type = 0
|
2014-06-03 16:21:00 +08:00
|
|
|
@courses = @courses_all.order("created_at desc")
|
2014-06-04 15:47:09 +08:00
|
|
|
@courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page)
|
2014-05-29 16:35:34 +08:00
|
|
|
|
2014-06-04 15:47:09 +08:00
|
|
|
@course_activity_count=get_course_activity @courses, @course_activity_count
|
2014-05-29 16:35:34 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
render :layout => 'base'
|
|
|
|
}
|
|
|
|
format.atom {
|
2014-06-03 11:16:06 +08:00
|
|
|
courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all
|
2014-06-03 09:39:33 +08:00
|
|
|
render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}")
|
2014-05-29 16:35:34 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-04 17:06:28 +08:00
|
|
|
def homework
|
|
|
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
|
|
|
@bids = @course.homeworks.order('deadline DESC')
|
|
|
|
@bids = @bids.like(params[:name]) if params[:name].present?
|
|
|
|
@bid_count = @bids.count
|
|
|
|
@bid_pages = Paginator.new @bid_count, @limit, params['page']
|
|
|
|
|
|
|
|
@offset ||= @bid_pages.reverse_offset
|
|
|
|
unless @offset == 0
|
|
|
|
@bids = @bids.offset(@offset).limit(@limit).all.reverse
|
|
|
|
else
|
|
|
|
limit = @bid_count % @limit
|
2014-06-24 09:58:05 +08:00
|
|
|
if limit == 0
|
|
|
|
limit = 10
|
|
|
|
end
|
2014-06-04 17:06:28 +08:00
|
|
|
@bids = @bids.offset(@offset).limit(limit).all.reverse
|
|
|
|
end
|
|
|
|
render :layout => 'base_courses'
|
2014-06-09 14:23:31 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# 新建作业
|
|
|
|
def new_homework
|
|
|
|
if (User.current.logged? &&
|
|
|
|
(User.current.admin? ||
|
|
|
|
(
|
|
|
|
!Member.where('user_id = ? and course_id = ?', User.current.id, @course.id).first.nil? &&
|
|
|
|
(
|
|
|
|
Member.where('user_id = ? and course_id = ?', User.current.id, @course.id).first.roles &&
|
|
|
|
( Role.where(id: [3, 4, 7, 9]).size > 0 )
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@homework = Bid.new
|
|
|
|
@homework.safe_attributes = params[:bid]
|
|
|
|
render :layout => 'base_courses'
|
|
|
|
else
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2014-06-03 16:21:00 +08:00
|
|
|
|
2014-06-04 15:47:09 +08:00
|
|
|
def get_course_activity courses, activities
|
2014-06-03 11:16:06 +08:00
|
|
|
@course_ids=activities.keys()
|
|
|
|
|
|
|
|
days = Setting.activity_days_default.to_i
|
|
|
|
date_to ||= Date.today + 1
|
|
|
|
date_from = date_to - days-1.years
|
|
|
|
|
|
|
|
#file_count
|
2014-06-10 17:03:02 +08:00
|
|
|
Attachment.where(container_id: @course_ids, container_type: Course).where("created_on>?", date_from).each do |attachment|
|
2014-06-03 11:16:06 +08:00
|
|
|
activities[attachment.container_id]+=1
|
|
|
|
end
|
|
|
|
|
|
|
|
#message_count
|
|
|
|
Board.where(course_id: @course_ids).each do |board|
|
|
|
|
# activities[board.course_id]+=1
|
2014-06-04 15:47:09 +08:00
|
|
|
activities[board.course_id]+=board.messages.where("updated_on>?", date_from).count
|
2014-06-03 11:16:06 +08:00
|
|
|
end
|
|
|
|
|
2014-06-18 15:18:30 +08:00
|
|
|
#news
|
|
|
|
News.where(course_id: @course_ids).where("created_on>?",date_from).each do |news|
|
|
|
|
activities[news.course_id]+=1
|
|
|
|
end
|
|
|
|
|
2014-06-03 11:16:06 +08:00
|
|
|
#feedbackc_count
|
2014-06-10 17:03:02 +08:00
|
|
|
JournalsForMessage.where(jour_id: @course_ids, jour_type: Course).each do |jourformess|
|
2014-06-03 11:16:06 +08:00
|
|
|
activities[jourformess.jour_id]+=1
|
|
|
|
end
|
|
|
|
|
|
|
|
#activities!=0
|
|
|
|
i=0;
|
|
|
|
courses.each do |course|
|
|
|
|
id=course.id
|
|
|
|
if activities[id]==0
|
|
|
|
activities[id]=1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return activities
|
|
|
|
end
|
|
|
|
|
2014-06-05 10:33:32 +08:00
|
|
|
def toggleCourse
|
|
|
|
@course_prefs = Course.find_by_extra(@course.extra)
|
|
|
|
unless (@course_prefs.teacher == User.current || User.current.admin?)
|
|
|
|
render_403
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def finishcourse
|
|
|
|
yesterday = Date.today.prev_day.to_time
|
|
|
|
|
|
|
|
@course_prefs.endup_time = yesterday
|
|
|
|
@save_flag = @course_prefs.save
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-05 10:40:14 +08:00
|
|
|
def restartcourse
|
|
|
|
day = Time.parse("3000-01-01")
|
|
|
|
|
|
|
|
@course_prefs.endup_time = day
|
|
|
|
@save_flag = @course_prefs.save
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.js {
|
|
|
|
render action:'finishcourse'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-05 11:01:46 +08:00
|
|
|
def show
|
|
|
|
# try to redirect to the requested menu item
|
|
|
|
if params[:jump] && redirect_to_course_menu_item(@course, params[:jump])
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
@users_by_role = @course.users_by_role
|
2014-06-05 11:55:46 +08:00
|
|
|
if(User.find_by_id(CourseInfos.find_by_course_id(@course.id).try(:user_id)))
|
|
|
|
@user = User.find_by_id(CourseInfos.find_by_course_id(@course.id).user_id)
|
2014-06-05 11:01:46 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
@key = User.current.rss_key
|
|
|
|
#新增内容
|
|
|
|
@days = Setting.activity_days_default.to_i
|
|
|
|
|
|
|
|
if params[:from]
|
|
|
|
begin; @date_to = params[:from].to_date + 1; rescue; end
|
|
|
|
end
|
2014-06-05 10:40:14 +08:00
|
|
|
|
2014-06-05 11:01:46 +08:00
|
|
|
has = {
|
2014-06-11 11:04:38 +08:00
|
|
|
"show_course_files" => true,
|
2014-06-16 10:38:38 +08:00
|
|
|
"show_course_news" => true,
|
2014-06-13 11:49:28 +08:00
|
|
|
"show_course_messages" => true,
|
2014-06-05 11:01:46 +08:00
|
|
|
"show_bids" => true,
|
2014-06-13 11:49:28 +08:00
|
|
|
"show_course_journals_for_messages" => true
|
2014-06-05 11:01:46 +08:00
|
|
|
}
|
|
|
|
@date_to ||= Date.today + 1
|
|
|
|
@date_from = @date_to - @days-1.years
|
|
|
|
@author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id]))
|
|
|
|
# 决定显示所用用户或单个用户活动
|
2014-06-10 11:49:28 +08:00
|
|
|
@activity = Redmine::Activity::Fetcher.new(User.current, :course => @course,
|
|
|
|
:with_subprojects => false,
|
|
|
|
:author => @author)
|
2014-06-16 10:38:38 +08:00
|
|
|
@activity.scope_select {|t| has["show_#{t}"]}
|
2014-06-10 11:49:28 +08:00
|
|
|
events = @activity.events(@date_from, @date_to)
|
|
|
|
|
2014-06-05 11:01:46 +08:00
|
|
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
|
|
|
@events_count = events.count
|
|
|
|
@events_pages = Paginator.new @events_count, @limit, params['page']
|
|
|
|
@offset ||= @events_pages.offset
|
|
|
|
events = events.slice(@offset,@limit)
|
2014-06-09 10:26:45 +08:00
|
|
|
|
2014-06-05 11:01:46 +08:00
|
|
|
@events_by_day = events.group_by {|event| User.current.time_to_date(event.event_datetime)}
|
|
|
|
# documents
|
|
|
|
@sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category'
|
|
|
|
#
|
2014-06-05 16:41:05 +08:00
|
|
|
@teachers= searchTeacherAndAssistant(@course)
|
|
|
|
@canShowRealName = isCourseTeacher(User.current.id)
|
|
|
|
|
|
|
|
if(User.find_by_id(CourseInfos.find_by_course_id(@course.id).try(:user_id)))
|
|
|
|
@user = User.find_by_id(CourseInfos.find_by_course_id(@course.id).user_id)
|
|
|
|
end
|
|
|
|
|
2014-06-05 11:01:46 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html{render :layout => 'base_courses'}
|
|
|
|
format.api
|
|
|
|
end
|
|
|
|
end
|
2014-06-05 10:40:14 +08:00
|
|
|
|
2014-06-05 16:41:05 +08:00
|
|
|
#判断指定用户是否为课程教师
|
|
|
|
def isCourseTeacher(id)
|
|
|
|
result = false
|
|
|
|
if @teachers && @teachers.find_by_user_id(id) != nil
|
|
|
|
result = true
|
|
|
|
end
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
2014-06-05 15:42:49 +08:00
|
|
|
def feedback
|
|
|
|
page = params[:page]
|
|
|
|
# Find the page of the requested reply
|
|
|
|
@jours = @course.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
|
|
|
|
@limit = 10
|
|
|
|
if params[:r] && page.nil?
|
|
|
|
offset = @jours.count(:conditions => ["#{JournalsForMessage.table_name}.id > ?", params[:r].to_i])
|
|
|
|
page = 1 + offset / @limit
|
|
|
|
end
|
|
|
|
|
|
|
|
@feedback_count = @jours.count
|
|
|
|
@feedback_pages = Paginator.new @feedback_count, @limit, page
|
|
|
|
@offset ||= @feedback_pages.offset
|
|
|
|
@jour = @jours[@offset, @limit]
|
|
|
|
@state = false
|
|
|
|
respond_to do |format|
|
2014-06-12 11:34:47 +08:00
|
|
|
format.html{render :layout => 'base_courses'}
|
2014-06-05 15:42:49 +08:00
|
|
|
format.api
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-03 11:16:06 +08:00
|
|
|
private
|
|
|
|
|
|
|
|
def allow_join
|
2014-06-16 17:14:05 +08:00
|
|
|
if course_endTime_timeout? Course.find(params[:object_id])
|
2014-06-03 11:16:06 +08:00
|
|
|
respond_to do |format|
|
2014-06-04 15:47:09 +08:00
|
|
|
format.js {
|
2014-06-03 11:16:06 +08:00
|
|
|
@state = 2
|
2014-06-04 15:47:09 +08:00
|
|
|
render :partial => 'set_join',
|
|
|
|
:locals => {:user => User.current,
|
2014-06-16 17:14:05 +08:00
|
|
|
:course => Course.find(params[:object_id]),
|
2014-06-04 15:47:09 +08:00
|
|
|
:object_id => params[:object_id]
|
|
|
|
}
|
2014-06-03 11:16:06 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2014-05-29 16:35:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-09-12 10:41:15 +08:00
|
|
|
end
|