2016-01-07 15:29:25 +08:00
#encoding: utf-8
2014-09-24 14:47:53 +08:00
class CoursesController < ApplicationController
2015-04-10 15:01:33 +08:00
# layout 'base_courses'
2014-09-24 14:47:53 +08:00
include CoursesHelper
2015-04-03 11:30:48 +08:00
include ActivitiesHelper
2014-09-24 14:47:53 +08:00
helper :activities
helper :members
helper :words
2015-05-13 16:44:12 +08:00
helper :attachments
2016-03-18 15:15:25 +08:00
helper :files
2015-06-05 16:20:26 +08:00
helper :activity_notifys
2014-09-24 14:47:53 +08:00
2015-09-24 16:30:14 +08:00
before_filter :auth_login1 , :only = > [ :show , :course_activity , :feedback ]
2014-09-24 14:47:53 +08:00
menu_item :overview
menu_item :feedback , :only = > :feedback
menu_item :homework , :only = > :homework
2015-01-27 15:29:09 +08:00
2014-11-12 16:51:07 +08:00
menu_item :new_homework , :only = > :new_homework
2014-09-24 14:47:53 +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
before_filter :can_show_course , :except = > [ ]
2015-07-23 16:17:13 +08:00
before_filter :logged_user_by_apptoken , :only = > [ :show , :feedback ]
2016-07-29 19:19:58 +08:00
before_filter :find_course , :except = > [ :index , :search , :new , :join , :unjoin , :create , :new_join , :course , :join_private_courses , :join_course_multi_role ]
2015-07-23 16:17:13 +08:00
before_filter :authorize_course , :only = > [ :show , :settings , :update , :course ]
before_filter :authorize_course_global , :only = > [ :new , :create ]
2015-01-07 09:37:35 +08:00
before_filter :toggleCourse , :only = > [ :finishcourse , :restartcourse ]
2015-12-10 18:59:54 +08:00
before_filter :is_deleted , :only = > [ :show , :settings ]
2014-09-24 14:47:53 +08:00
before_filter :require_login , :only = > [ :join , :unjoin ]
2014-10-20 17:31:45 +08:00
#before_filter :allow_join, :only => [:join]
2014-12-29 16:57:31 +08:00
2015-11-17 17:34:50 +08:00
#查找组织
def search_public_orgs_not_in_course
condition = '%%'
if ! params [ :name ] . nil?
condition = " % #{ params [ :name ] . strip } % " . gsub ( " " , " " )
end
2015-12-17 10:01:28 +08:00
limit = 15
2015-11-17 17:34:50 +08:00
course_org_ids = OrgCourse . find_by_sql ( " select distinct organization_id from org_courses where course_id = #{ params [ :id ] } " ) . map ( & :organization_id )
2016-01-08 21:46:10 +08:00
#@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
if course_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 ( ',' ) + " ) "
2016-01-08 22:30:04 +08:00
@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 )
@org_count = @orgs_not_in_course . empty? ? 0 : @orgs_not_in_course . count
2016-01-08 21:46:10 +08:00
end
@course_count = Project . course_entities . visible . like ( params [ :name ] ) . page ( params [ :page ] ) . count
2015-12-17 10:01:28 +08:00
@orgs_page = Paginator . new @org_count , limit , params [ :page ]
2015-11-18 16:52:03 +08:00
@hint_flag = params [ :hint_flag ]
2015-11-17 17:34:50 +08:00
#render :json => {:orgs => @orgs_not_in_course, :count => @org_count}.to_json
respond_to do | format |
format . js
end
end
2014-09-24 14:47:53 +08:00
def join
if User . current . logged?
2015-12-04 00:15:47 +08:00
cs = CoursesService . new
@user = User . current
join = cs . join_course params , @user
@state = join [ :state ]
@course = join [ :course ]
2015-10-24 12:03:36 +08:00
# else
# @course = Course.find_by_id params[:object_id]
# CourseMessage.create(:user_id => @course.tea_id, :course_id => @course.id, :viewed => false,:content=> params[:role],:course_message_id=>User.current.id,:course_message_type=>'JoinCourseRequest')
# @state = 6
# end
2014-10-17 08:59:14 +08:00
else
2014-12-12 14:54:01 +08:00
@state = 5 #未登录
2014-09-24 14:47:53 +08:00
end
2016-06-24 16:12:24 +08:00
@object_id = @course . id if @course
2014-10-16 11:55:42 +08:00
respond_to do | format |
2015-12-04 00:15:47 +08:00
format . js #{ render :partial => 'set_join', :locals => {:user => @user, :course => @course, :object_id => params[:object_id]} }
2014-10-16 11:55:42 +08:00
end
2015-10-20 17:27:06 +08:00
2014-09-24 14:47:53 +08:00
end
2016-07-29 19:19:58 +08:00
def join_course_multi_role
if User . current . logged?
cs = CoursesService . new
@user = User . current
join = cs . join_course_roles params , @user
@state = join [ :state ]
@course = join [ :course ]
else
@state = 5 #未登录
end
@object_id = @course . id if @course
respond_to do | format |
format . js
end
end
2014-09-24 14:47:53 +08:00
def unjoin
if User . current . logged?
2014-12-12 14:54:01 +08:00
cs = CoursesService . new
cs . exit_course params , User . current
2014-09-24 14:47:53 +08:00
end
respond_to do | format |
format . js { render :partial = > 'set_join' , :locals = > { :user = > User . current , :course = > Course . find ( params [ :object_id ] ) , :object_id = > params [ :object_id ] } }
end
end
2015-12-04 00:15:47 +08:00
2014-10-16 10:56:13 +08:00
def join_private_courses
respond_to do | format |
format . js
end
end
2014-09-24 14:47:53 +08:00
#更新课程信息
def update
2014-12-12 14:54:01 +08:00
cs = CoursesService . new
2015-03-01 17:31:38 +08:00
c = cs . edit_course params , @course , User . current
@course = c [ :course ]
2014-12-12 14:54:01 +08:00
if @course . errors . full_messages . count < = 0
2015-12-04 00:15:47 +08:00
respond_to do | format |
format . html {
# render :layout => 'base_courses'
flash [ :notice ] = l ( :notice_successful_update )
redirect_to settings_course_url ( @course )
}
format . api { render_api_ok }
end
2014-09-24 14:47:53 +08:00
else
respond_to do | format |
format . html {
2014-10-17 13:51:18 +08:00
settings
2015-04-10 15:01:33 +08:00
redirect_to settings_course_url ( @course )
2014-09-24 14:47:53 +08:00
}
format . api { render_validation_errors ( @course ) }
end
end
end
def new_join
@course = Course . find ( params [ :object_id ] )
2015-06-13 10:55:51 +08:00
respond_to do | format |
format . js
end
2014-09-24 14:47:53 +08:00
end
# 课程搜索
# add by nwb
def search
2015-08-14 16:24:43 +08:00
if params [ :name ] . empty?
courses = Course . visible
@courses = paginateHelper courses , 10
2014-09-24 14:47:53 +08:00
else
2015-11-02 15:46:21 +08:00
courses = Course . visible . where ( " LOWER(name) like '% #{ params [ :name ] . to_s . downcase } %' " ) . order ( " time desc, created_at desc " )
2015-08-14 16:24:43 +08:00
@courses = paginateHelper courses , 10
2014-09-24 14:47:53 +08:00
end
2015-12-04 00:15:47 +08:00
@name = params [ :name ]
@type = 'courses'
2014-09-24 14:47:53 +08:00
respond_to do | format |
format . html {
render :layout = > 'course_base'
}
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
2014-12-10 18:26:38 +08:00
rescue Exception = > e
if e . message == 'sumbit empty'
( redirect_to courses_url , :notice = > l ( :label_sumbit_empty ) ; return )
end
2014-09-24 14:47:53 +08:00
end
2014-12-03 19:17:10 +08:00
def searchmembers
2014-12-06 12:34:02 +08:00
@subPage_title = l :label_student_list
2015-03-25 20:38:07 +08:00
@canShowCode = User . current . allowed_to? ( :as_teacher , @course ) && params [ :role ] != '1'
# @is_remote = true
2016-05-17 14:18:14 +08:00
@sort_type = 'score'
2014-12-29 20:46:27 +08:00
@score_sort_by = " desc "
2014-12-03 19:17:10 +08:00
q = " #{ params [ :name ] . strip } "
2014-12-09 14:57:10 +08:00
if params [ :incourse ]
2015-03-25 20:38:07 +08:00
results = searchmember_by_name ( student_homework_score ( 0 , 0 , 0 , " desc " ) , q )
2014-12-09 15:16:43 +08:00
elsif params [ :ingroup ]
2016-09-29 11:29:37 +08:00
if params [ :search_group_id ] == " -1 "
@group = - 1
results = searchmember_by_name ( student_homework_score ( - 1 , 0 , 0 , " desc " ) , q )
else
@group = CourseGroup . find ( params [ :search_group_id ] )
results = searchmember_by_name ( student_homework_score ( @group . id , 0 , 0 , " desc " ) , q )
end
2014-12-09 14:57:10 +08:00
end
2014-12-26 17:31:01 +08:00
@is_remote = true
2015-04-21 17:54:49 +08:00
#@result_count = results.count
#@results = paginateHelper results, 10
@results = results
2015-02-02 17:01:07 +08:00
@search_name = q
2016-09-29 11:29:37 +08:00
@limit = 50
@page = params [ :page ] . nil? ? 1 : params [ 'page' ] . to_i
@members_count = @results . count
@mem_pages = Paginator . new @members_count , @limit , @page
@results = paginateHelper @results , @limit
2014-12-03 19:17:10 +08:00
end
def addgroups
2014-12-06 12:34:02 +08:00
@subPage_title = l :label_student_list
2014-12-04 19:09:10 +08:00
if params [ :group_name ]
group = CourseGroup . new
group . name = params [ :group_name ]
group . course_id = @course . id
group . save
end
2016-05-17 14:18:14 +08:00
@sort_type = 'score'
@score_sort_by = " desc "
2015-03-26 11:30:00 +08:00
@canShowCode = User . current . allowed_to? ( :as_teacher , @course ) && params [ :role ] != '1'
2014-12-05 16:21:53 +08:00
@is_remote = true
2016-05-17 14:18:14 +08:00
@members = student_homework_score ( 0 , 0 , 10 , @score_sort_by )
2014-12-04 19:09:10 +08:00
@course_groups = @course . course_groups
2016-09-29 11:29:37 +08:00
@limit = 50
@page = params [ :page ] . nil? ? 1 : params [ 'page' ] . to_i
@members_count = @members . count
@no_group_count = @members_count - @course . members . where ( " course_group_id != 0 " ) . count
@mem_pages = Paginator . new @members_count , @limit , @page
@members = paginateHelper @members , @limit
2014-12-03 19:17:10 +08:00
end
2014-12-08 16:50:20 +08:00
def deletegroup
CourseGroup . delete ( params [ :group_id ] )
@subPage_title = l :label_student_list
@canShowCode = isCourseTeacher ( User . current . id , @course ) && params [ :role ] != '1'
@is_remote = true
2016-05-17 14:18:14 +08:00
@sort_type = 'score'
@score_sort_by = " desc "
@members = student_homework_score ( 0 , 0 , 10 , @score_sort_by )
2014-12-08 16:50:20 +08:00
@course_groups = @course . course_groups
2016-09-29 11:29:37 +08:00
@limit = 50
@page = params [ :page ] . nil? ? 1 : params [ 'page' ] . to_i
@members_count = @members . count
@no_group_count = @members_count - @course . members . where ( " course_group_id != 0 " ) . count
@mem_pages = Paginator . new @members_count , @limit , @page
@members = paginateHelper @members , @limit
2014-12-08 16:50:20 +08:00
end
2014-12-03 19:17:10 +08:00
def updategroupname
2014-12-06 12:34:02 +08:00
@subPage_title = l :label_student_list
2014-12-04 19:09:10 +08:00
if params [ :group_name ]
group = CourseGroup . find ( params [ :group_id ] )
group . name = params [ :group_name ]
group . save
end
2014-12-05 10:53:43 +08:00
@canShowCode = isCourseTeacher ( User . current . id , @course ) && params [ :role ] != '1'
@is_remote = true
2016-04-14 17:24:56 +08:00
@members = student_homework_score ( 0 , 0 , 10 , " desc " )
2014-12-04 19:09:10 +08:00
@course_groups = @course . course_groups
2016-09-29 11:29:37 +08:00
@limit = 50
@page = params [ :page ] . nil? ? 1 : params [ 'page' ] . to_i
@members_count = @members . count
@no_group_count = @members_count - @course . members . where ( " course_group_id != 0 " ) . count
@mem_pages = Paginator . new @members_count , @limit , @page
@members = paginateHelper @members , @limit
2014-12-03 19:17:10 +08:00
end
2014-12-19 23:12:32 +08:00
def valid_ajax
req = Hash . new ( false )
req [ :message ] = ''
valid_attr = params [ :valid ]
valid_value = params [ :value ]
2015-03-26 11:30:00 +08:00
group_id = params [ :group_id ]
# faker = CourseGroup.new
2014-12-19 23:12:32 +08:00
if valid_attr . eql? ( 'name' )
2015-03-26 11:30:00 +08:00
course = Course . find params [ :course_id ]
group_names = course . course_groups . map { | group | group . name unless group . id . to_s == group_id } . select { | group | ! group . nil? }
if group_names . include? ( valid_value )
req [ :valid ] = false
req [ :message ] = l ( :modal_valid_unpassing )
else
req [ :valid ] = true
req [ :message ] = l ( :modal_valid_passing )
end
# faker.name = valid_value
# faker.course_id = params[:course_id]
# faker.valid?
# req[:valid] = faker.errors[:name].blank?
# req[:message] = faker.errors[:name]
2014-12-19 23:12:32 +08:00
end
2015-03-26 11:30:00 +08:00
# req[:message] = l(:modal_valid_passing) if req[:message].blank?
2014-12-19 23:12:32 +08:00
render :json = > req
end
2016-03-10 17:04:26 +08:00
def teacher_assign_group
2016-03-10 17:41:53 +08:00
member = Member . where ( :course_id = > @course . id , :user_id = > params [ :user_id ] ) . first
2016-03-10 17:04:26 +08:00
member . course_group_id = params [ :course_group_id ] . to_i
member . save
2016-03-10 17:41:53 +08:00
@course_groups = @course . course_groups
2016-09-29 11:29:37 +08:00
@no_group_count = @course . student . count - @course . members . where ( " course_group_id != 0 " ) . count
2016-03-10 17:41:53 +08:00
@canShowCode = isCourseTeacher ( User . current . id , @course ) && params [ :role ] != '1'
respond_to do | format |
format . js
end
2016-03-10 17:04:26 +08:00
end
2014-12-04 22:02:10 +08:00
def join_group
2014-12-06 12:34:02 +08:00
@subPage_title = l :label_student_list
2014-12-04 22:02:10 +08:00
group = CourseGroup . find ( params [ :object_id ] )
member = Member . where ( :course_id = > @course . id , :user_id = > User . current . id ) . first
member . course_group_id = group . id
member . save
@group = group
2014-12-29 16:57:31 +08:00
2014-12-05 16:44:05 +08:00
@course_groups = @course . course_groups
2016-09-29 11:29:37 +08:00
@no_group_count = @course . student . count - @course . members . where ( " course_group_id != 0 " ) . count
2014-12-29 16:57:31 +08:00
2014-12-04 22:02:10 +08:00
search_group_members group
end
def unjoin_group
2014-12-06 12:34:02 +08:00
@subPage_title = l :label_student_list
2014-12-04 22:02:10 +08:00
group = CourseGroup . find ( params [ :object_id ] )
member = Member . where ( :course_id = > @course . id , :user_id = > User . current . id ) . first
member . course_group_id = 0
member . save
@group = group
2014-12-05 16:44:05 +08:00
@course_groups = @course . course_groups
2016-09-29 11:29:37 +08:00
@no_group_count = @course . student . count - @course . members . where ( " course_group_id != 0 " ) . count
2014-12-29 16:57:31 +08:00
2014-12-04 22:02:10 +08:00
search_group_members group
end
2014-12-03 19:17:10 +08:00
def searchgroupmembers
2014-12-06 12:34:02 +08:00
@subPage_title = l :label_student_list
2015-03-26 10:25:54 +08:00
@render_file = 'new_member_list'
2014-12-04 19:09:10 +08:00
@canShowCode = isCourseTeacher ( User . current . id , @course ) && params [ :role ] != '1'
@is_remote = true
2016-05-17 14:18:14 +08:00
@sort_type = 'score'
2014-12-29 20:46:27 +08:00
@score_sort_by = " desc "
2016-09-29 11:29:37 +08:00
if params [ :group_id ] && params [ :group_id ] != " 0 " && params [ :group_id ] != " -1 "
2014-12-04 19:09:10 +08:00
@group = CourseGroup . find ( params [ :group_id ] )
2014-12-29 20:46:27 +08:00
@results = student_homework_score ( @group . id , 0 , 0 , " desc " )
2015-07-06 11:12:29 +08:00
# @results = paginateHelper @results, 10
2016-09-29 11:29:37 +08:00
elsif params [ :group_id ] && params [ :group_id ] == " -1 "
@group = - 1
@results = student_homework_score ( - 1 , 0 , 10 , " desc " )
2014-12-04 19:09:10 +08:00
else
2014-12-29 16:57:31 +08:00
page_from = params [ :page ] . nil? ? 0 : ( params [ :page ] . to_i - 1 )
2014-12-31 08:48:14 +08:00
@results = student_homework_score ( 0 , page_from , 10 , " desc " )
2014-12-04 19:09:10 +08:00
end
2016-09-29 11:29:37 +08:00
@limit = 50
@page = params [ :page ] . nil? ? 1 : params [ 'page' ] . to_i
@members_count = @results . count
@mem_pages = Paginator . new @members_count , @limit , @page
@results = paginateHelper @results , @limit
2014-12-04 22:02:10 +08:00
end
2014-12-24 18:31:45 +08:00
2014-09-24 14:47:53 +08:00
def member
## 有角色参数的才是课程,没有的就是项目
2014-12-05 14:48:33 +08:00
if ( User . current . admin? || @course . is_public == 1 || ( @course . is_public == 0 && User . current . member_of_course? ( @course ) ) )
2015-03-26 10:25:54 +08:00
@render_file = 'new_member_list'
2014-12-29 20:46:27 +08:00
@score_sort_by = " desc "
2016-06-01 14:58:59 +08:00
@sort_type = params [ :sort_type ] ? params [ :sort_type ] : " score "
2015-03-25 20:13:48 +08:00
@canShowCode = User . current . allowed_to? ( :as_teacher , @course ) && params [ :role ] != '1'
2014-12-29 16:57:31 +08:00
@role = params [ :role ] . nil? ? '2' :params [ :role ]
@is_remote = true
2014-12-05 14:48:33 +08:00
@course_groups = @course . course_groups if @course . course_groups
2014-12-06 11:00:15 +08:00
@show_serch = params [ :role ] == '2'
2014-12-29 16:57:31 +08:00
case @role
2014-12-05 14:48:33 +08:00
when '1'
@subPage_title = l :label_teacher_list
2014-12-30 17:49:48 +08:00
@all_members = searchTeacherAndAssistant ( @course )
2015-04-21 17:54:49 +08:00
@members = @all_members
2014-12-05 14:48:33 +08:00
when '2'
2016-09-02 15:35:20 +08:00
if @course . open_student == 1 || User . current . member_of_course? ( @course ) || User . current . admin?
2016-09-29 11:29:37 +08:00
@limit = 50
2015-12-24 15:28:11 +08:00
@subPage_title = l :label_student_list
2016-09-29 11:29:37 +08:00
@page = params [ :page ] . nil? ? 1 : params [ 'page' ] . to_i
@all_members = student_homework_score ( 0 , @page - 1 , @limit , @score_sort_by , @sort_type )
@members_count = @all_members . count
@no_group_count = @members_count - @course . members . where ( " course_group_id != 0 " ) . count
@mem_pages = Paginator . new @members_count , @limit , @page
@members = paginateHelper @all_members , @limit
2016-09-30 17:12:40 +08:00
@left_nav_type = 9
2015-12-24 15:28:11 +08:00
else
render_403
return
end
2014-12-29 16:57:31 +08:00
end
respond_to do | format |
if params [ :page ]
2015-03-30 17:03:20 +08:00
format . html { render :layout = > 'base_courses' }
2014-12-29 16:57:31 +08:00
format . js
2014-12-02 14:41:36 +08:00
else
2014-12-29 16:57:31 +08:00
format . html { render :layout = > 'base_courses' }
end
2014-12-05 14:48:33 +08:00
end
else
render_403
2014-09-24 14:47:53 +08:00
end
2014-12-17 17:36:12 +08:00
end
2014-12-18 18:24:37 +08:00
2014-12-30 17:49:48 +08:00
def export_course_member_excel
@all_members = student_homework_score ( 0 , 0 , 0 , " desc " )
2016-05-20 16:19:10 +08:00
@homeworks = @course . homework_commons . where ( " publish_time <= ' #{ Date . today } ' " ) . order ( " created_at asc " )
2015-05-19 15:23:13 +08:00
filename = " #{ @course . teacher . lastname . to_s + @course . teacher . firstname . to_s } _ #{ @course . name } _ #{ @course . time . to_s + @course . term } #{ l ( :excel_member_list ) } " ;
2015-12-04 00:15:47 +08:00
2014-12-30 17:49:48 +08:00
respond_to do | format |
format . xls {
2016-01-29 11:02:57 +08:00
send_data ( member_to_xls ( @homeworks , @course , @all_members , @course . course_groups ) , :type = > " text/excel;charset=utf-8; header=present " ,
2015-10-27 12:04:52 +08:00
:filename = > filename_for_content_disposition ( " #{ filename } .xls " ) )
2014-12-30 17:49:48 +08:00
}
end
end
2014-12-18 18:24:37 +08:00
def member_score_sort
2014-12-29 20:46:27 +08:00
@canShowCode = isCourseTeacher ( User . current . id , @course ) && params [ :role ] != '1'
@subPage_title = l :label_student_list
2015-03-26 10:25:54 +08:00
@render_file = 'new_member_list'
2014-12-29 20:46:27 +08:00
@is_remote = true
2016-05-17 14:18:14 +08:00
@sort_type = params [ :sort_type ] if params [ :sort_type ]
2014-12-29 20:46:27 +08:00
@score_sort_by = params [ :sort_by ] if params [ :sort_by ]
2015-02-02 17:01:07 +08:00
@search_name = params [ :search_name ] if params [ :search_name ]
2014-12-29 20:46:27 +08:00
group_id = params [ :group_id ]
2015-02-02 17:01:07 +08:00
if ! @search_name . nil?
if group_id == '0'
2016-09-29 11:29:37 +08:00
#page = params[:page].nil? ? 0 : (params['page'].to_i - 1)
2016-05-17 14:18:14 +08:00
@results = searchmember_by_name ( student_homework_score ( 0 , 0 , 0 , @score_sort_by , @sort_type ) , @search_name )
2015-07-06 11:12:29 +08:00
# @results = paginateHelper @results, 10
2016-09-29 11:29:37 +08:00
elsif group_id == '-1'
@group = - 1
@results = searchmember_by_name ( student_homework_score ( - 1 , 0 , 0 , @score_sort_by , @sort_type ) , @search_name )
2015-02-02 17:01:07 +08:00
else
@group = CourseGroup . find ( group_id )
2016-05-17 14:18:14 +08:00
@results = searchmember_by_name ( student_homework_score ( group_id , 0 , 0 , @score_sort_by , @sort_type ) , @search_name )
2015-07-06 11:12:29 +08:00
# @results = paginateHelper @results, 10
2015-02-02 17:01:07 +08:00
end
2014-12-29 20:46:27 +08:00
else
2015-02-02 17:01:07 +08:00
if group_id == '0'
page = params [ :page ] . nil? ? 0 : ( params [ 'page' ] . to_i - 1 )
2016-05-17 14:18:14 +08:00
@results = student_homework_score ( 0 , page , 10 , @score_sort_by , @sort_type )
2016-09-29 11:29:37 +08:00
elsif group_id == '-1'
@group = - 1
@results = student_homework_score ( - 1 , 0 , 10 , @score_sort_by , @sort_type )
2015-02-02 17:01:07 +08:00
else
@group = CourseGroup . find ( group_id )
2016-05-17 14:18:14 +08:00
@results = student_homework_score ( group_id , 0 , 0 , @score_sort_by , @sort_type )
2015-02-02 17:01:07 +08:00
end
2014-12-29 20:46:27 +08:00
end
2016-09-29 11:29:37 +08:00
@limit = 50
@page = params [ :page ] . nil? ? 1 : params [ 'page' ] . to_i
@members_count = @results . count
@no_group_count = @members_count - @course . members . where ( " course_group_id != 0 " ) . count
@mem_pages = Paginator . new @members_count , @limit , @page
@results = paginateHelper @results , @limit
2014-12-18 18:24:37 +08:00
end
2014-12-17 17:36:12 +08:00
# 显示每个学生的作业评分详情
def show_member_score
@member_score = Member . find ( params [ :member_id ] ) if params [ :member_id ]
respond_to do | format |
format . html { render :layout = > 'course_base' }
format . js
2014-09-24 14:47:53 +08:00
end
end
2016-05-17 14:18:14 +08:00
# 显示每个学生的作业评分详情
def show_member_act_score
@member = Member . find ( params [ :member_id ] ) if params [ :member_id ]
respond_to do | format |
format . html { render :layout = > 'course_base' }
format . js
end
end
2014-09-24 14:47:53 +08:00
def handle_course courses , activities
course_activity_count_array = activities . values ( )
course_array = [ ]
i = 0 ;
courses . each do | course |
course_array [ i ] = course
i = i + 1
end
courses = desc_sort_course_by_avtivity ( course_activity_count_array , course_array )
return courses
end
def settings
2016-07-18 11:19:56 +08:00
#添加成员消息状态
join_course_messages = CourseMessage . where ( " user_id =? and course_message_type =? and course_id =? and status = ? and viewed =? " , User . current . id , 'JoinCourse' , @course . id , 1 , 0 )
join_course_messages . update_all ( :viewed = > true )
2014-10-08 15:06:29 +08:00
if User . current . allowed_to? ( :as_teacher , @course )
2015-12-04 16:33:56 +08:00
@select_tab = params [ :tab ]
2014-10-08 15:06:29 +08:00
@issue_custom_fields = IssueCustomField . sorted . all
@issue_category || = IssueCategory . new
@member || = @course . members . new
@trackers = Tracker . sorted . all
2015-03-30 11:20:16 +08:00
@roles = Role . givable . all [ 3 .. 5 ]
@members = @course . member_principals . includes ( :roles , :principal ) . all . sort
2015-04-10 15:01:33 +08:00
respond_to do | format |
format . html { render :layout = > 'base_courses' }
format . api { render_validation_errors ( @course ) }
end
2014-10-08 15:06:29 +08:00
else
render_403
end
2014-09-24 14:47:53 +08:00
end
2015-12-29 10:15:53 +08:00
def private_or_public
if @course . is_public == 0
@course . update_attributes ( :is_public = > 1 )
else
@course . update_attributes ( :is_public = > 0 )
end
if @course . is_public == 0
course_status = CourseStatus . find_by_course_id ( @course . id )
course_status . destroy if course_status
elsif @course . is_public == 1
course_status = CourseStatus . find_by_course_id ( @course . id )
course_status . destroy if course_status
course_status = CourseStatus . create ( :course_id = > @course . id , :grade = > 0 )
end
respond_to do | format |
format . js
end
end
2015-04-16 17:28:08 +08:00
def search_member
2015-04-17 11:48:47 +08:00
if User . current . allowed_to? ( :as_teacher , @course ) || User . current . admin
q = " #{ params [ :name ] . strip } "
2015-04-16 17:28:08 +08:00
@roles = Role . givable . all [ 3 .. 5 ]
if q . nil? || q == " "
@members = @course . member_principals . includes ( :roles , :principal ) . all . sort
else
@members = searchmember_by_name ( @course . member_principals . includes ( :roles , :principal ) . all . sort , q )
end
else
render_403
end
end
2014-09-24 14:47:53 +08:00
def create
2014-12-11 17:11:05 +08:00
cs = CoursesService . new
2015-03-02 14:33:35 +08:00
@course = cs . create_course ( params , User . current ) [ :course ]
2016-01-07 15:29:25 +08:00
if params [ :copy_course ]
copy_course = Course . find params [ :copy_course ] . to_i
2016-01-29 22:09:16 +08:00
@course . is_copy = params [ :copy_course ] . to_i
2016-01-26 15:05:45 +08:00
@course . open_student = copy_course . open_student
@course . publish_resource = copy_course . publish_resource
@course . save
2016-01-29 22:09:16 +08:00
#copy avatar
copy_avatar ( @course , copy_course )
2016-02-26 10:41:14 +08:00
if params [ :course_content_type ]
params [ :course_content_type ] . each do | type |
case type
when " 0 "
homeworks = copy_course . homework_commons
homeworks . each do | homework |
new_homework = HomeworkCommon . new
new_homework . name = homework . name
new_homework . user_id = User . current . id
new_homework . description = homework . description
new_homework . publish_time = Date . today + 30
new_homework . end_time = Date . today + 60
new_homework . homework_type = homework . homework_type
new_homework . late_penalty = homework . late_penalty
new_homework . course_id = @course . id
new_homework . teacher_priority = homework . teacher_priority
new_homework . anonymous_comment = homework . anonymous_comment
new_homework . quotes = 0
new_homework . is_open = homework . is_open
homework . attachments . each do | attachment |
att = attachment . copy
att . container_id = nil
att . container_type = nil
att . copy_from = attachment . id
att . save
new_homework . attachments << att
end
homework_detail_manual = homework . homework_detail_manual
homework_detail_programing = homework . homework_detail_programing
homework_detail_group = homework . homework_detail_group
if homework_detail_manual
new_homework . homework_detail_manual = HomeworkDetailManual . new
new_homework_detail_manual = new_homework . homework_detail_manual
new_homework_detail_manual . ta_proportion = homework_detail_manual . ta_proportion
new_homework_detail_manual . comment_status = 0
new_homework_detail_manual . evaluation_start = Date . today + 67
new_homework_detail_manual . evaluation_end = Date . today + 74
new_homework_detail_manual . evaluation_num = homework_detail_manual . evaluation_num
new_homework_detail_manual . absence_penalty = homework_detail_manual . absence_penalty
end
if homework_detail_programing
new_homework . homework_detail_programing = HomeworkDetailPrograming . new
new_homework . homework_detail_programing . ta_proportion = homework_detail_programing . ta_proportion
new_homework . homework_detail_programing . language = homework_detail_programing . language
homework . homework_tests . each_with_index do | homework_test |
new_homework . homework_tests << HomeworkTest . new (
input : homework_test . input ,
output : homework_test . output
)
end
end
if homework_detail_group
new_homework . homework_detail_group = HomeworkDetailGroup . new
new_homework . homework_detail_group . min_num = homework_detail_group . min_num
new_homework . homework_detail_group . max_num = homework_detail_group . max_num
new_homework . homework_detail_group . base_on_project = homework_detail_group . base_on_project
end
if new_homework . save
new_homework_detail_manual . save if new_homework_detail_manual
new_homework . homework_detail_programing . save if new_homework . homework_detail_programing
new_homework . homework_detail_group . save if new_homework . homework_detail_group
end
homework . update_attribute ( :quotes , homework . quotes + 1 )
end
when " 1 "
attachments = copy_course . attachments
attachments . each do | attachment |
attach_copied_obj = attachment . copy
attach_copied_obj . tag_list . add ( attachment . tag_list ) # tag关联
attach_copied_obj . container = @course
attach_copied_obj . created_on = Time . now
attach_copied_obj . author_id = User . current . id
attach_copied_obj . copy_from = attachment . copy_from . nil? ? attachment . id : attachment . copy_from
attach_copied_obj . is_publish = 0
attach_copied_obj . publish_time = Date . today + 30
if attach_copied_obj . attachtype == nil
attach_copied_obj . attachtype = 4
end
attach_copied_obj . save
update_quotes attach_copied_obj
end
end
end
end
= begin
2016-01-07 15:29:25 +08:00
if params [ :checkAll ]
attachments = copy_course . attachments
attachments . each do | attachment |
attach_copied_obj = attachment . copy
attach_copied_obj . tag_list . add ( attachment . tag_list ) # tag关联
attach_copied_obj . container = @course
attach_copied_obj . created_on = Time . now
attach_copied_obj . author_id = User . current . id
attach_copied_obj . copy_from = attachment . copy_from . nil? ? attachment . id : attachment . copy_from
if attach_copied_obj . attachtype == nil
attach_copied_obj . attachtype = 4
end
attach_copied_obj . save
update_quotes attach_copied_obj
end
elsif params [ :course_attachment_type ]
copy_attachments = [ ]
params [ :course_attachment_type ] . each do | type |
case type
when " 1 "
tag_name = l ( :label_courseware )
when " 2 "
tag_name = l ( :label_software )
when " 3 "
tag_name = l ( :label_media )
when " 4 "
tag_name = l ( :label_code )
when " 6 "
tag_name = " 论文 "
else
tag_name = " "
end
if tag_name == " "
tag_attachments = copy_course . attachments . select { | attachment |
! attachment . tag_list . include? ( '课件' ) &&
! attachment . tag_list . include? ( '软件' ) &&
! attachment . tag_list . include? ( '媒体' ) &&
! attachment . tag_list . include? ( '代码' ) &&
! attachment . tag_list . include? ( '论文' ) }
else
tag_attachments = copy_course . attachments . select { | attachment | attachment . tag_list . include? ( tag_name ) }
end
tag_attachments . each do | attach |
next if copy_attachments . include? ( attach )
copy_attachments << attach
end
end
unless copy_attachments . blank?
copy_attachments . each do | c_attach |
attach_copied_obj = c_attach . copy
attach_copied_obj . tag_list . add ( c_attach . tag_list ) # tag关联
attach_copied_obj . container = @course
attach_copied_obj . created_on = Time . now
attach_copied_obj . author_id = User . current . id
attach_copied_obj . copy_from = c_attach . copy_from . nil? ? c_attach . id : c_attach . copy_from
if attach_copied_obj . attachtype == nil
attach_copied_obj . attachtype = 4
end
attach_copied_obj . save
update_quotes attach_copied_obj
end
end
end
2016-02-26 10:41:14 +08:00
= end
2016-01-07 15:29:25 +08:00
end
2015-07-01 10:02:50 +08:00
if @course
2016-07-12 17:00:01 +08:00
#发送微信消息
2016-07-22 15:37:25 +08:00
count = ShieldWechatMessage . where ( " container_type='User' and container_id= #{ User . current . id } and shield_type='Course' and shield_id= #{ @course . id } " ) . count
if count == 0
ss = SyllabusesService . new
ss . send_wechat_create_class_notice User . current , @course
end
2014-12-11 17:11:05 +08:00
respond_to do | format |
2015-07-01 10:02:50 +08:00
flash [ :notice ] = l ( :notice_successful_create )
2016-01-18 17:16:33 +08:00
format . html { redirect_to course_url ( @course ) }
2015-07-01 10:02:50 +08:00
format . api { render :action = > 'show' , :status = > :created , :location = > url_for ( :controller = > 'courses' , :action = > 'show' , :id = > @course . id ) }
2014-12-11 17:11:05 +08:00
end
else
respond_to do | format |
2015-07-01 10:02:50 +08:00
flash [ :notice ] = l ( :notice_create_failed )
# @course = Course.new
format . html { redirect_to new_course_path } #Added by young
format . api { render_validation_errors ( @course ) }
end
2014-12-11 17:11:05 +08:00
end
2014-09-24 14:47:53 +08:00
end
2015-01-17 15:21:18 +08:00
def course
2015-12-04 00:15:47 +08:00
@school_id = params [ :school_id ]
2014-09-24 14:47:53 +08:00
per_page_option = 10
if @school_id == " 0 " or @school_id . nil?
@courses_all = Course . active . visible .
2014-12-31 17:02:55 +08:00
joins ( " LEFT JOIN #{ CourseStatus . table_name } ON #{ Course . table_name } .id = #{ CourseStatus . table_name } .course_id " )
2014-09-24 14:47:53 +08:00
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 } .school_id = ? " , @school_id )
end
@course_count = @courses_all . count
@course_pages = Paginator . new @course_count , per_page_option , params [ 'page' ]
@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_on 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
@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 )
@course_activity_count = get_course_activity @courses , @course_activity_count
end
respond_to do | format |
format . html {
2015-04-16 10:49:58 +08:00
render :layout = > 'new_base'
2014-09-24 14:47:53 +08:00
}
format . api {
}
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
def new
2015-09-11 11:40:07 +08:00
if User . current . login?
@course_type = params [ :course_type ] || = params [ :course ]
@issue_custom_fields = IssueCustomField . sorted . all
@trackers = Tracker . sorted . all
@course = Course . new
@course . safe_attributes = params [ :course ]
2016-06-28 15:13:04 +08:00
@syllabus = Syllabus . where ( " id = #{ params [ :syllabus_id ] . to_i } " ) . first if params [ :syllabus_id ]
2015-09-11 11:40:07 +08:00
# month = Time.now.month
render :layout = > 'new_base'
else
redirect_to signin_url
end
2014-09-24 14:47:53 +08:00
end
def desc_sort_course_by_avtivity ( activity_count , courses )
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 ]
courses [ j ] , courses [ j + 1 ] = courses [ j + 1 ] , courses [ j ]
activity_count [ j ] , activity_count [ j + 1 ] = activity_count [ j + 1 ] , activity_count [ j ]
end
end
end
return courses
end
def index
2015-01-27 15:29:09 +08:00
if ! User . current . admin?
2015-12-04 00:15:47 +08:00
render_404
return
2015-01-27 15:29:09 +08:00
end
2014-09-24 14:47:53 +08:00
@course_type = params [ :course_type ]
@school_id = params [ :school_id ]
per_page_option = 10
2014-10-21 15:33:48 +08:00
if @school_id == " 0 " || @school_id . nil?
2014-09-24 14:47:53 +08:00
@courses_all = Course . active . visible .
joins ( " LEFT JOIN #{ CourseStatus . table_name } ON #{ Course . table_name } .id = #{ CourseStatus . table_name } .course_id " )
else
@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 } .school_id = ? " , @school_id )
end
@course_count = @courses_all . count
@course_pages = Paginator . new @course_count , per_page_option , params [ 'page' ]
@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 )
2014-10-21 15:33:48 +08:00
@course_activity_count = get_course_activity @courses , @course_activity_count
2014-09-24 14:47:53 +08:00
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
@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 {
2015-12-04 00:15:47 +08:00
render :layout = > 'base'
2014-09-24 14:47:53 +08:00
}
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
def toggleCourse
@course_prefs = Course . find_by_extra ( @course . extra )
2015-07-24 14:36:53 +08:00
unless ( User . current . allowed_to? ( :as_teacher , @course_prefs ) || User . current . admin? )
2014-09-24 14:47:53 +08:00
render_403
end
end
2015-12-10 18:59:54 +08:00
def is_deleted
if @course . is_delete == 1 and ! User . current . admin?
render_404
return
end
end
2014-09-24 14:47:53 +08:00
def get_courses
@user = User . current
membership = @user . coursememberships . all
membership . sort! { | older , newer | newer . created_on < = > older . created_on }
@memberships = [ ]
membership . collect { | e |
@memberships . push ( e )
}
@memberships_doing = [ ]
@memberships_done = [ ]
now_time = Time . now . year
@memberships . map { | e |
end_time = e . course . get_time . year
isDone = course_endTime_timeout? ( e . course )
if isDone
@memberships_done . push e
else
@memberships_doing . push e
end
}
end
def finishcourse
yesterday = Date . today . prev_day . to_time
@course_prefs . endup_time = yesterday
@save_flag = @course_prefs . save
get_courses
respond_to do | format |
format . js
end
end
def restartcourse
day = Time . parse ( " 3000-01-01 " )
@course_prefs . endup_time = day
@save_flag = @course_prefs . save
get_courses
respond_to do | format |
format . js {
render action : 'finishcourse'
}
end
end
2015-09-24 16:30:14 +08:00
def course_activity
redirect_to course_url ( @course , type : params [ :type ] , page : params [ :page ] )
end
2014-09-24 14:47:53 +08:00
def show
2015-12-10 17:26:03 +08:00
# 被删除的课程只有超级管理员才能看到, is_delete为1的时候, 标记课程被删除
2015-12-10 18:59:54 +08:00
# if @course.is_delete == 1 && !User.current.admin?
# render_403
# return
# end
2015-10-19 15:45:24 +08:00
#更新创建课程消息状态
2016-09-14 11:31:48 +08:00
course_request_messages = CourseMessage . where ( :user_id = > User . current . id , :course_id = > @course . id , :course_message_type = > [ " CourseRequestDealResult " , " Course " ] , :viewed = > false )
course_request_messages . update_all ( :viewed = > true )
# 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)
2015-10-19 15:45:24 +08:00
2015-10-26 13:26:49 +08:00
#更新申请结果反馈消息的状态
2016-09-14 11:31:48 +08:00
# course_request_messages = CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =?", User.current.id, @course.id, 'CourseRequestDealResult', false)
# course_request_messages.update_all(:viewed => true)
2015-10-26 13:26:49 +08:00
2015-09-24 16:30:14 +08:00
course_activities = @course . course_activities
2015-08-12 16:24:27 +08:00
@canShowRealName = User . current . member_of_course? @course
2015-09-24 16:30:14 +08:00
@page = params [ :page ] ? params [ :page ] . to_i + 1 : 0
if params [ :type ] . present?
case params [ :type ]
when " homework "
2016-07-22 16:50:32 +08:00
@course_activities = course_activities . where ( " course_act_type = 'HomeworkCommon' " ) . order ( 'updated_at desc' )
2015-09-24 16:30:14 +08:00
when " news "
2016-07-22 16:50:32 +08:00
@course_activities = course_activities . where ( " course_act_type = 'News' " ) . order ( 'updated_at desc' )
2015-09-24 16:30:14 +08:00
when " message "
2016-07-22 16:50:32 +08:00
@course_activities = course_activities . where ( " course_act_type = 'Message' " ) . order ( 'updated_at desc' )
2015-09-24 16:30:14 +08:00
when " poll "
2016-07-22 16:50:32 +08:00
@course_activities = course_activities . where ( " course_act_type = 'Poll' " ) . order ( 'updated_at desc' )
2015-09-24 16:30:14 +08:00
when " attachment "
2016-07-22 16:50:32 +08:00
@course_activities = course_activities . where ( " course_act_type = 'Attachment' " ) . order ( 'updated_at desc' )
2015-09-24 16:30:14 +08:00
when " journalsForMessage "
2016-07-22 16:50:32 +08:00
@course_activities = course_activities . where ( " course_act_type = 'JournalsForMessage' " ) . order ( 'updated_at desc' )
2015-09-24 16:30:14 +08:00
else
2016-07-22 16:50:32 +08:00
@course_activities = course_activities . order ( 'updated_at desc' )
2015-09-24 16:30:14 +08:00
end
else
2016-07-22 16:50:32 +08:00
@course_activities = course_activities . order ( 'updated_at desc' )
2015-09-24 16:30:14 +08:00
end
2016-07-22 16:50:32 +08:00
@course_activities_count = @course_activities . count
@course_activities = @course_activities . limit ( 10 ) . offset ( @page * 10 )
2015-09-24 16:30:14 +08:00
@type = params [ :type ]
2016-04-14 11:29:22 +08:00
2016-07-22 15:32:37 +08:00
@left_nav_type = 1
2014-09-24 14:47:53 +08:00
respond_to do | format |
2015-09-24 16:30:14 +08:00
format . js
2014-09-24 14:47:53 +08:00
format . html { render :layout = > 'base_courses' }
format . api
end
end
#判断指定用户是否为课程教师
def isCourseTeacher ( id , course )
result = false
user = User . find ( id )
2014-09-29 16:49:47 +08:00
if ! user . nil? && user . allowed_to? ( :as_teacher , course )
2014-09-24 14:47:53 +08:00
result = true
end
result
end
def feedback
2016-03-11 09:40:10 +08:00
CourseMessage . where ( " user_id = ? and course_id = ? " , User . current , @course . id ) . update_all ( :viewed = > true )
2015-09-16 12:38:01 +08:00
2014-12-05 14:48:33 +08:00
if ( User . current . admin? || @course . is_public == 1 || ( @course . is_public == 0 && User . current . member_of_course? ( @course ) ) )
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
@jour = paginateHelper @jours , 10
@state = false
2016-07-22 15:32:37 +08:00
@left_nav_type = 6
2014-12-05 14:48:33 +08:00
respond_to do | format |
format . html { render :layout = > 'base_courses' }
format . api
end
else
render_403
2014-09-24 14:47:53 +08:00
end
end
2016-04-14 11:29:22 +08:00
def search_homework_member homeworks , name
if name == " "
select_homework = homeworks
else
name = name . downcase
select_homework = homeworks . select { | homework |
homework . user [ :login ] . to_s . downcase . include? ( name ) || homework . user . user_extensions [ :student_id ] . to_s . downcase . include? ( name ) || ( homework . user [ :lastname ] . to_s . downcase + homework . user [ :firstname ] . to_s . downcase ) . include? ( name )
}
end
select_homework
end
# 作业查重
def code_repeat
#代码查重新加的
@order , @b_sort , @name , @group = params [ :order ] || " score " , params [ :sort ] || " desc " , params [ :name ] || " " , params [ :group ]
@is_teacher = User . current . allowed_to? ( :as_teacher , @course ) || User . current . admin?
2016-04-15 11:28:20 +08:00
if ! @is_teacher
render_403
return
end
2016-04-14 11:29:22 +08:00
@homework = HomeworkCommon . find params [ :homework ]
#order("#{@order} #{@b_sort}"
2016-07-14 10:06:37 +08:00
@student_works = search_homework_member @homework . student_works . select ( " student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score " ) . order ( " simi_value desc " ) . has_committed , @name
2016-04-14 11:29:22 +08:00
@works_hash = { }
@student_works . each do | tmpwork |
@works_hash [ tmpwork . id ] = tmpwork
2016-04-15 18:48:39 +08:00
puts tmpwork . id
2016-04-14 11:29:22 +08:00
end
#respond_to do |format|
#format.html {render :layout => 'base_courses'}
#end
end
def show_comparecode
src_id = params [ :src_id ]
dst_id = params [ :dst_id ]
2016-04-15 11:28:20 +08:00
@is_teacher = User . current . allowed_to? ( :as_teacher , @course ) || User . current . admin?
if ! @is_teacher
render_403
return
end
2016-04-14 11:29:22 +08:00
src_work = StudentWork . where ( " id =? " , src_id ) . first
@homework = HomeworkCommon . find params [ :homework_id ]
2016-04-15 11:28:20 +08:00
@simi_value = src_work . simi_value . to_i
2016-04-14 11:29:22 +08:00
@src_code = src_work . description
src_user = User . where ( " id =? " , src_work . user_id ) . first
@src_username = src_user . try ( :realname ) != " " ? src_user . lastname + src_user . firstname : src_user . try ( :login )
#descriotion user name
dst_work = StudentWork . where ( " id =? " , dst_id ) . first
@dst_code = dst_work . description
dst_user = User . where ( " id =? " , dst_work . user_id ) . first
@dst_username = dst_user . try ( :realname ) != " " ? dst_user . lastname + dst_user . firstname : dst_user . try ( :login )
respond_to do | format |
format . js
end
end
2015-02-09 10:28:33 +08:00
#根据已有课程复制课程
#param id:已有课程ID
def copy_course
if @course
2016-01-07 15:29:25 +08:00
@new_course = Course . new
respond_to do | format |
format . js
end
= begin
2015-02-09 10:28:33 +08:00
@new_course = Course . new @course . attributes
@new_course . tea_id = User . current . id
@new_course . created_at = DateTime . now
@new_course . updated_at = DateTime . now
@new_course . endup_time = nil
if @new_course . save
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 ] )
m . project_id = - 1
course = CourseInfos . new ( :user_id = > User . current . id , :course_id = > @new_course . id )
#user_grades = UserGrade.create(:user_id => User.current.id, :course_id => @course.id)
if @new_course . is_public == 1
course_status = CourseStatus . create ( :course_id = > @new_course . id , :watchers_count = > 0 , :changesets_count = > 0 , :grade = > 0 , :course_type = > 1 )
end
@new_course . members << m
@new_course . course_infos << course
redirect_to settings_course_url @new_course
end
2016-01-07 15:29:25 +08:00
= end
2015-02-09 10:28:33 +08:00
else
render_404
end
end
2014-09-24 14:47:53 +08:00
2015-10-28 15:54:27 +08:00
#从课程创建的老师那里选择课程大纲
def course_outline
2015-12-04 00:15:47 +08:00
@teacher = User . find ( @course . tea_id )
@blog_articles = @teacher . blog . articles
@is_in_show_outline_page = params [ :is_in_show_outline_page ]
respond_to do | format |
format . js
end
2015-10-29 11:53:52 +08:00
end
#根据关键字搜索,查找方法一样的,但返回内容不一样
def search_course_outline
2015-12-04 00:15:47 +08:00
@article_title = params [ :title ]
@teacher = User . find ( @course . tea_id )
@blog_articles = @teacher . blog . articles . like ( @article_title )
render :json = > @blog_articles . to_json
2015-10-29 11:53:52 +08:00
end
2015-10-28 15:54:27 +08:00
2015-10-29 11:53:52 +08:00
#设置或者更改课程的大纲
def set_course_outline
@course . outline = params [ :outline_id ]
@course . save
2015-10-30 11:51:09 +08:00
@is_in_show_outline_page = params [ :is_in_show_outline_page ]
2015-10-29 11:53:52 +08:00
respond_to do | format |
format . js
end
2015-10-28 15:54:27 +08:00
end
2015-10-29 17:09:03 +08:00
#显示课程大纲
2015-10-30 17:21:12 +08:00
def syllabus
2015-10-29 17:09:03 +08:00
@article = BlogComment . find ( @course . outline )
respond_to do | format |
format . html { render :layout = > 'base_courses' }
end
end
2015-12-08 10:32:10 +08:00
2015-07-23 16:17:13 +08:00
#删除课程
2015-12-08 10:32:10 +08:00
#删除课程只是将课程的is_deleted状态改为false, is_deleted为false状态的课程只有管理员可以看到
2015-07-23 16:17:13 +08:00
def destroy
2016-07-04 17:04:06 +08:00
@course . delete!
2015-12-08 16:45:26 +08:00
@course = nil
redirect_to user_url ( User . current )
end
2015-07-23 16:17:13 +08:00
2015-12-08 16:45:26 +08:00
# 恢复已删除的课程
2015-12-10 18:59:54 +08:00
def renew
2015-12-08 16:45:26 +08:00
if User . current . admin?
@course . update_attributes ( :is_delete = > false )
2015-12-10 18:59:54 +08:00
redirect_to course_path ( @course )
2015-12-08 16:45:26 +08:00
else
2015-12-10 18:59:54 +08:00
return 404
2015-12-08 16:45:26 +08:00
end
2015-07-23 16:17:13 +08:00
end
2016-01-29 15:37:03 +08:00
#搜索作业
def homework_search
@search = " % #{ params [ :search ] . strip . downcase } % "
@is_teacher = User . current . logged? && ( User . current . admin? || User . current . allowed_to? ( :as_teacher , @course ) )
@page = params [ :page ] ? params [ :page ] . to_i + 1 : 0
if @is_teacher
@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
2015-07-23 16:17:13 +08:00
2016-07-22 15:32:37 +08:00
#统计
def statistics_course
2016-09-30 17:19:57 +08:00
@left_nav_type = 10
2016-07-22 15:32:37 +08:00
respond_to do | format |
format . html { render :layout = > 'base_courses' }
end
end
2016-07-29 14:34:42 +08:00
#切换身份
def switch_role
members = @course . members . where ( " user_id = #{ params [ :user_id ] } " )
unless members . blank?
#role = MemberRole.where("member_id = #{members.first.id} and role_id = #{params[:role]}").first
curr_role = MemberRole . find_by_member_id_and_role_id ( members . first . id , params [ :curr_role ] )
tar_role = MemberRole . find_by_member_id_and_role_id ( members . first . id , params [ :tar_role ] )
unless ( curr_role . nil? || tar_role . nil? )
curr_role . update_column ( 'is_current' , 0 )
tar_role . update_column ( 'is_current' , 1 )
end
end
redirect_to course_path ( @course )
end
2014-09-24 14:47:53 +08:00
private
2016-01-07 15:29:25 +08:00
def update_quotes attachment
if attachment . 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_number attachment
attachment . save
attachments . each do | att |
att . quotes = attachment . quotes
att . save
end
end
def get_qute_number attachment
if attachment . 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
if result . nil? || result . count < = 0
return 0
else
return result [ 0 ] . number
end
end
2014-10-21 08:55:55 +08:00
def allow_join course
if course_endTime_timeout? course
2014-09-24 14:47:53 +08:00
respond_to do | format |
format . js {
@state = 2
render :partial = > 'set_join' ,
:locals = > { :user = > User . current ,
:course = > Course . find ( params [ :object_id ] ) ,
:object_id = > params [ :object_id ]
}
}
end
end
end
#验证是否显示课程
def can_show_course
2014-10-16 11:09:45 +08:00
@first_page = FirstPage . find_by_page_type ( 'project' )
2015-05-15 13:39:26 +08:00
if @first_page . try ( :show_course ) == 2
2015-12-04 00:15:47 +08:00
render_404
2014-09-24 14:47:53 +08:00
end
end
2014-12-17 17:36:12 +08:00
2016-05-17 14:18:14 +08:00
def student_homework_score ( groupid , start_from , nums , score_sort_by , sort_type = 'score' )
2014-12-29 16:57:31 +08:00
start_from = start_from * nums
2014-12-31 08:48:14 +08:00
if groupid == 0
2015-06-02 16:22:15 +08:00
sql_select = " SELECT members.*,(
2016-04-27 16:21:35 +08:00
SELECT SUM ( student_works . work_score )
2015-06-02 16:22:15 +08:00
FROM student_works , homework_commons
WHERE student_works . homework_common_id = homework_commons . id
AND homework_commons . course_id = #{@course.id}
AND student_works . user_id = members . user_id
2016-09-30 18:35:08 +08:00
) AS score , ( SELECT max ( message_num * 2 + message_reply_num * 1 + news_reply_num * 1 + news_num * 1 +
2016-05-19 16:39:14 +08:00
resource_num * 5 + journal_num * 1 + homework_journal_num * 1 ) FROM ` course_contributor_scores ` AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = members.user_id
2016-09-29 11:29:37 +08:00
) AS act_score , ( SELECT SUM ( exercise_users . score ) FROM exercise_users , exercises WHERE exercise_users . exercise_id = exercises . id
AND exercises . course_id = #{@course.id} AND exercise_users.user_id = members.user_id) AS ex_score,
2016-09-30 18:35:08 +08:00
( SELECT max ( student_id ) FROM user_extensions WHERE user_extensions . user_id = members . user_id ) AS student_id ,
( SELECT max ( message_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = members.user_id) AS message_num,
( SELECT max ( message_reply_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = members.user_id) AS message_reply_num,
( SELECT max ( news_reply_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = members.user_id) AS news_reply_num,
( SELECT max ( news_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = members.user_id) AS news_num,
( SELECT max ( resource_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = members.user_id) AS resource_num,
( SELECT max ( journal_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = members.user_id) AS journal_num,
( SELECT max ( homework_journal_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = members.user_id) AS homework_journal_num,
2016-09-29 11:29:37 +08:00
( SELECT COUNT ( ss . id ) FROM student_works AS ss , homework_commons AS hc WHERE ss . homework_common_id = hc . id AND hc . course_id = #{@course.id} AND ss.work_status != 0 AND ss.user_id = members.user_id) AS homework_num,
( SELECT COUNT ( eu . id ) FROM exercise_users AS eu , exercises WHERE eu . exercise_id = exercises . id AND exercises . course_id = #{@course.id} AND exercises.end_time >= eu.created_at AND eu.user_id = members.user_id) AS exercise_num
2015-06-02 16:22:15 +08:00
FROM members
JOIN students_for_courses
ON students_for_courses . student_id = members . user_id AND students_for_courses . course_id = members . course_id
2016-05-17 14:18:14 +08:00
WHERE members . course_id = #{@course.id} ORDER BY #{sort_type} #{score_sort_by}"
2016-09-29 11:29:37 +08:00
elsif groupid == - 1
sql_select = " SELECT members.*,(
SELECT SUM ( student_works . work_score )
FROM student_works , homework_commons
WHERE student_works . homework_common_id = homework_commons . id
AND homework_commons . course_id = #{@course.id}
AND student_works . user_id = members . user_id
2016-09-30 18:35:08 +08:00
) AS score , ( SELECT max ( message_num * 2 + message_reply_num * 1 + news_reply_num * 1 + news_num * 1 +
2016-09-29 11:29:37 +08:00
resource_num * 5 + journal_num * 1 + homework_journal_num * 1 ) FROM ` course_contributor_scores ` AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = members.user_id
) AS act_score , ( SELECT SUM ( exercise_users . score ) FROM exercise_users , exercises WHERE exercise_users . exercise_id = exercises . id
AND exercises . course_id = #{@course.id} AND exercise_users.user_id = members.user_id) AS ex_score,
2016-09-30 18:35:08 +08:00
( SELECT max ( student_id ) FROM user_extensions WHERE user_extensions . user_id = members . user_id ) AS student_id ,
( SELECT max ( message_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = members.user_id) AS message_num,
( SELECT max ( message_reply_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = members.user_id) AS message_reply_num,
( SELECT max ( news_reply_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = members.user_id) AS news_reply_num,
( SELECT max ( news_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = members.user_id) AS news_num,
( SELECT max ( resource_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = members.user_id) AS resource_num,
( SELECT max ( journal_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = members.user_id) AS journal_num,
( SELECT max ( homework_journal_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = members.user_id) AS homework_journal_num,
2016-09-29 11:29:37 +08:00
( SELECT COUNT ( ss . id ) FROM student_works AS ss , homework_commons AS hc WHERE ss . homework_common_id = hc . id AND hc . course_id = #{@course.id} AND ss.work_status != 0 AND ss.user_id = members.user_id) AS homework_num,
( SELECT COUNT ( eu . id ) FROM exercise_users AS eu , exercises WHERE eu . exercise_id = exercises . id AND exercises . course_id = #{@course.id} AND exercises.end_time >= eu.created_at AND eu.user_id = members.user_id) AS exercise_num
FROM members
JOIN students_for_courses
ON students_for_courses . student_id = members . user_id AND students_for_courses . course_id = members . course_id
WHERE members . course_id = #{@course.id} AND members.course_group_id = 0 ORDER BY #{sort_type} #{score_sort_by}"
2014-12-31 08:48:14 +08:00
else
2015-06-02 16:22:15 +08:00
sql_select = " SELECT members.*,(
2016-04-27 16:21:35 +08:00
SELECT SUM ( student_works . work_score )
2015-06-02 16:22:15 +08:00
FROM student_works , homework_commons
WHERE student_works . homework_common_id = homework_commons . id
AND homework_commons . course_id = #{@course.id}
AND student_works . user_id = members . user_id
2016-05-17 14:18:14 +08:00
) AS score , ( SELECT ( message_num * 2 + message_reply_num * 1 + news_reply_num * 1 + news_num * 1 +
2016-05-19 16:39:14 +08:00
resource_num * 5 + journal_num * 1 + homework_journal_num * 1 ) FROM ` course_contributor_scores ` AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = members.user_id
2016-09-29 11:29:37 +08:00
) AS act_score , ( SELECT SUM ( exercise_users . score ) FROM exercise_users , exercises WHERE exercise_users . exercise_id = exercises . id
AND exercises . course_id = #{@course.id} AND exercise_users.user_id = members.user_id) AS ex_score,
2016-09-30 18:35:08 +08:00
( SELECT max ( student_id ) FROM user_extensions WHERE user_extensions . user_id = members . user_id ) AS student_id ,
( SELECT max ( message_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = members.user_id) AS message_num,
( SELECT max ( message_reply_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = members.user_id) AS message_reply_num,
( SELECT max ( news_reply_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = members.user_id) AS news_reply_num,
( SELECT max ( news_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = members.user_id) AS news_num,
( SELECT max ( resource_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = members.user_id) AS resource_num,
( SELECT max ( journal_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = members.user_id) AS journal_num,
( SELECT max ( homework_journal_num ) FROM course_contributor_scores AS ccs WHERE ccs . course_id = #{@course.id} AND ccs.user_id = members.user_id) AS homework_journal_num,
2016-09-29 11:29:37 +08:00
( SELECT COUNT ( ss . id ) FROM student_works AS ss , homework_commons AS hc WHERE ss . homework_common_id = hc . id AND hc . course_id = #{@course.id} AND ss.work_status != 0 AND ss.user_id = members.user_id) AS homework_num,
( SELECT COUNT ( eu . id ) FROM exercise_users AS eu , exercises WHERE eu . exercise_id = exercises . id AND exercises . course_id = #{@course.id} AND exercises.end_time >= eu.created_at AND eu.user_id = members.user_id) AS exercise_num
2015-06-02 16:22:15 +08:00
FROM members
JOIN students_for_courses
ON students_for_courses . student_id = members . user_id AND students_for_courses . course_id = members . course_id
2016-05-17 14:18:14 +08:00
WHERE members . course_id = #{@course.id} AND members.course_group_id = #{groupid} ORDER BY #{sort_type} #{score_sort_by}"
2014-12-31 08:48:14 +08:00
end
2014-12-26 14:50:14 +08:00
sql = ActiveRecord :: Base . connection ( )
2014-12-31 08:48:14 +08:00
homework_scores = Member . find_by_sql ( sql_select )
2014-12-26 14:50:14 +08:00
sql . close ( )
2014-12-31 08:48:14 +08:00
2014-12-24 18:31:45 +08:00
homework_scores
2014-12-22 10:31:09 +08:00
end
#获取课程的老师列表
def find_course_teachers course
searchTeacherAndAssistant ( course ) . map { | teacher | teacher . user_id } . join ( " , " )
end
2014-12-24 18:31:45 +08:00
#当加入,退出分班时查询分班的学生
def search_group_members group
@subPage_title = l :label_student_list
2015-03-26 10:25:54 +08:00
@render_file = 'new_member_list'
2014-12-24 18:31:45 +08:00
@canShowCode = isCourseTeacher ( User . current . id , @course ) && params [ :role ] != '1'
@is_remote = true
2014-12-29 20:46:27 +08:00
@score_sort_by = " desc "
2014-12-29 16:57:31 +08:00
page_from = params [ :page ] . nil? ? 0 : ( params [ :page ] . to_i - 1 )
2014-12-29 20:46:27 +08:00
@results = student_homework_score ( group . id , 0 , 0 , " desc " )
2014-12-29 16:57:31 +08:00
2014-12-24 18:31:45 +08:00
end
2014-12-30 17:49:48 +08:00
2016-01-29 11:02:57 +08:00
def member_to_xls homeworks , course , members , groups
2014-12-30 17:49:48 +08:00
xls_report = StringIO . new
book = Spreadsheet :: Workbook . new
2016-06-24 10:50:40 +08:00
sheet1 = book . create_worksheet :name = > " 总成绩 "
2014-12-30 17:49:48 +08:00
blue = Spreadsheet :: Format . new :color = > :blue , :weight = > :bold , :size = > 10
2016-01-29 11:02:57 +08:00
#sheet1.row(0).default_format = blue
#sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_class),l(:excel_f_score),l(:excel_commit_time)])
sheet1 [ 0 , 0 ] = " 课程编号 "
2016-09-30 17:04:19 +08:00
sheet1 [ 0 , 1 ] = course . syllabus . id
sheet1 [ 1 , 0 ] = " 课程名称 "
sheet1 [ 1 , 1 ] = course . syllabus . title
sheet1 [ 2 , 0 ] = " 班级编号 "
sheet1 [ 2 , 1 ] = course . id
sheet1 [ 3 , 0 ] = " 班级学期 "
sheet1 [ 3 , 1 ] = course . time . to_s + " 年 " + course . term
sheet1 [ 4 , 0 ] = " 班级名称 "
sheet1 [ 4 , 1 ] = course . name
sheet1 [ 5 , 0 ] = " 教师团队 "
sheet1 [ 5 , 1 ] = ( searchTeacherAndAssistant course ) . map { | member | member . user . show_name } . join ( '、' )
sheet1 [ 6 , 0 ] = " 主讲教师 "
sheet1 [ 6 , 1 ] = course . teacher . show_name
sheet1 [ 7 , 0 ] = " 排名 "
sheet1 [ 7 , 1 ] = " 学生姓名 "
sheet1 [ 7 , 2 ] = " 昵称 "
sheet1 [ 7 , 3 ] = " 学号 "
2016-01-29 11:02:57 +08:00
for i in 0 ... homeworks . count
2016-09-30 17:04:19 +08:00
sheet1 [ 7 , i + 4 ] = " 第 " + ( i + 1 ) . to_s + " 次 "
end
sheet1 [ 7 , homeworks . count + 4 ] = " 作业得分 "
sheet1 [ 7 , homeworks . count + 5 ] = " 测评得分 "
sheet1 [ 7 , homeworks . count + 6 ] = " 社区得分 "
sheet1 [ 7 , homeworks . count + 7 ] = " 总得分 "
sheet1 [ 7 , homeworks . count + 8 ] = " 分班 "
count_row = 8
2016-01-29 11:02:57 +08:00
members . each_with_index do | member , i |
sheet1 [ count_row , 0 ] = i + 1
sheet1 [ count_row , 1 ] = member . user . lastname . to_s + member . user . firstname . to_s
sheet1 [ count_row , 2 ] = member . user . login
sheet1 [ count_row , 3 ] = member . user . user_extensions . student_id
homeworks . each_with_index do | homework , j |
student_works = homework . student_works . where ( " user_id = #{ member . user . id } " )
if student_works . empty?
2016-05-17 14:18:14 +08:00
sheet1 [ count_row , j + 4 ] = 0
2016-01-29 11:02:57 +08:00
else
final_score = student_works . first . final_score . nil? ? 0 : student_works . first . final_score
score = final_score - student_works . first . absence_penalty - student_works . first . late_penalty
2016-05-17 14:18:14 +08:00
sheet1 [ count_row , j + 4 ] = score < 0 ? 0 :score . round ( 2 )
2016-01-29 11:02:57 +08:00
end
end
2016-09-29 11:29:37 +08:00
hw_score = member . score . nil? ? 0 : member . score
ex_score = member . ex_score . nil? ? 0 : member . ex_score
act_score = member . act_score . nil? ? 0 : member . act_score
sum = hw_score + ex_score + act_score
sheet1 [ count_row , homeworks . count + 4 ] = hw_score . round ( 2 )
sheet1 [ count_row , homeworks . count + 5 ] = ex_score
sheet1 [ count_row , homeworks . count + 6 ] = act_score
sheet1 [ count_row , homeworks . count + 7 ] = sum . round ( 2 )
2016-09-30 17:04:19 +08:00
sheet1 [ count_row , homeworks . count + 8 ] = member . course_group_id == 0 ? " 暂无 " : member . course_group . name
2016-01-29 11:02:57 +08:00
count_row += 1
end
2014-12-30 17:49:48 +08:00
2016-06-24 10:50:40 +08:00
homeworks . each_with_index do | home , i |
sheet = book . create_worksheet :name = > " 第 #{ i + 1 } 次作业 "
sheet [ 0 , 0 ] = " 课程编号 "
2016-09-30 17:04:19 +08:00
sheet [ 0 , 1 ] = course . syllabus . id
sheet [ 1 , 0 ] = " 课程名称 "
sheet [ 1 , 1 ] = course . syllabus . title
sheet [ 2 , 0 ] = " 班级编号 "
sheet [ 2 , 1 ] = course . id
sheet [ 3 , 0 ] = " 班级学期 "
sheet [ 3 , 1 ] = course . time . to_s + " 年 " + course . term
sheet [ 4 , 0 ] = " 班级名称 "
sheet [ 4 , 1 ] = course . name
sheet [ 5 , 0 ] = " 教师团队 "
sheet [ 5 , 1 ] = ( searchTeacherAndAssistant course ) . map { | member | member . user . show_name } . join ( '、' )
sheet [ 6 , 0 ] = " 主讲教师 "
sheet [ 6 , 1 ] = course . teacher . show_name
sheet [ 6 , 0 ] = " 作业批次 "
sheet [ 6 , 1 ] = " 第 #{ i + 1 } 次作业 "
sheet [ 6 , 0 ] = " 作业名称 "
sheet [ 6 , 1 ] = home . name
2016-06-24 10:50:40 +08:00
if home . homework_type == 1 #普通作业
if home . anonymous_comment == 0
2016-09-30 17:04:19 +08:00
sheet . row ( 7 ) . concat ( [ l ( :excel_rank ) , l ( :excel_user_name ) , l ( :excel_nickname ) , l ( :excel_student_id ) , l ( :excel_homework_name ) , l ( :excel_homework_des ) ,
2016-06-24 10:50:40 +08:00
l ( :excel_t_score ) , l ( :excel_ta_score ) , l ( :excel_n_score ) , l ( :excel_a_penalty ) , l ( :excel_l_penalty ) , l ( :excel_f_score ) , l ( :excel_commit_time ) ] )
else
2016-09-30 17:04:19 +08:00
sheet . row ( 7 ) . concat ( [ l ( :excel_rank ) , l ( :excel_user_name ) , l ( :excel_nickname ) , l ( :excel_student_id ) , l ( :excel_homework_name ) , l ( :excel_homework_des ) ,
2016-06-24 10:50:40 +08:00
l ( :excel_t_score ) , l ( :excel_ta_score ) , l ( :excel_l_penalty ) , l ( :excel_f_score ) , l ( :excel_commit_time ) ] )
end
2016-09-30 17:04:19 +08:00
count_row = 8
2016-06-24 10:50:40 +08:00
items = home . student_works . order ( " work_score desc " )
items . each_with_index do | stu , j |
sheet [ count_row , 0 ] = j + 1
sheet [ count_row , 1 ] = stu . user . show_name
sheet [ count_row , 2 ] = stu . user . login
sheet [ count_row , 3 ] = stu . user . user_extensions . student_id
sheet [ count_row , 4 ] = stu . name
sheet [ count_row , 5 ] = strip_html stu . description
sheet [ count_row , 6 ] = stu . teacher_score . nil? ? l ( :label_without_score ) : stu . teacher_score . round ( 2 )
sheet [ count_row , 7 ] = stu . teaching_asistant_score . nil? ? l ( :label_without_score ) : stu . teaching_asistant_score . round ( 2 )
if home . anonymous_comment == 0
sheet [ count_row , 8 ] = stu . student_score . nil? ? l ( :label_without_score ) : stu . student_score . round ( 2 )
2016-06-24 18:23:00 +08:00
sheet [ count_row , 9 ] = ( home . teacher_priority == 1 && ! stu . teacher_score . nil? ) ? 0 : stu . absence_penalty
sheet [ count_row , 10 ] = ( home . teacher_priority == 1 && ! stu . teacher_score . nil? ) ? 0 : stu . late_penalty
2016-06-24 10:50:40 +08:00
sheet [ count_row , 11 ] = stu . work_score . nil? ? l ( :label_without_score ) : stu . work_score . round ( 2 )
sheet [ count_row , 12 ] = format_time ( stu . created_at )
else
2016-06-24 18:23:00 +08:00
sheet [ count_row , 8 ] = ( home . teacher_priority == 1 && ! stu . teacher_score . nil? ) ? 0 : stu . late_penalty
2016-06-24 10:50:40 +08:00
sheet [ count_row , 9 ] = stu . work_score . nil? ? l ( :label_without_score ) : stu . work_score . round ( 2 )
sheet [ count_row , 10 ] = format_time ( stu . created_at )
end
count_row += 1
end
elsif home . homework_type == 2 #编程作业
if home . anonymous_comment == 0
2016-09-30 17:04:19 +08:00
sheet . row ( 7 ) . concat ( [ l ( :excel_rank ) , l ( :excel_user_name ) , l ( :excel_nickname ) , l ( :excel_student_id ) , l ( :excel_homework_name ) , l ( :excel_homework_des ) ,
2016-06-24 10:50:40 +08:00
l ( :excel_t_score ) , l ( :excel_ta_score ) , l ( :excel_s_score ) , l ( :excel_n_score ) , l ( :excel_a_penalty ) , l ( :excel_l_penalty ) , l ( :excel_f_score ) , l ( :excel_commit_time ) ] )
else
2016-09-30 17:04:19 +08:00
sheet . row ( 7 ) . concat ( [ l ( :excel_rank ) , l ( :excel_user_name ) , l ( :excel_nickname ) , l ( :excel_student_id ) , l ( :excel_homework_name ) , l ( :excel_homework_des ) ,
2016-06-24 10:50:40 +08:00
l ( :excel_t_score ) , l ( :excel_ta_score ) , l ( :excel_s_score ) , l ( :excel_l_penalty ) , l ( :excel_f_score ) , l ( :excel_commit_time ) ] )
end
2016-09-30 17:04:19 +08:00
count_row = 8
2016-06-24 10:50:40 +08:00
items = home . student_works . order ( " work_score desc " )
items . each_with_index do | stu , j |
sheet [ count_row , 0 ] = j + 1
sheet [ count_row , 1 ] = stu . user . show_name
sheet [ count_row , 2 ] = stu . user . login
sheet [ count_row , 3 ] = stu . user . user_extensions . student_id
sheet [ count_row , 4 ] = stu . name
sheet [ count_row , 5 ] = stu . description
sheet [ count_row , 6 ] = stu . teacher_score . nil? ? l ( :label_without_score ) : stu . teacher_score . round ( 2 )
sheet [ count_row , 7 ] = stu . teaching_asistant_score . nil? ? l ( :label_without_score ) : stu . teaching_asistant_score . round ( 2 )
sheet [ count_row , 8 ] = stu . system_score . nil? ? l ( :label_without_score ) : stu . system_score . round ( 2 )
if home . anonymous_comment == 0
sheet [ count_row , 9 ] = stu . student_score . nil? ? l ( :label_without_score ) : stu . student_score . round ( 2 )
2016-06-24 18:23:00 +08:00
sheet [ count_row , 10 ] = ( home . teacher_priority == 1 && ! stu . teacher_score . nil? ) ? 0 : stu . absence_penalty
sheet [ count_row , 11 ] = ( home . teacher_priority == 1 && ! stu . teacher_score . nil? ) ? 0 : stu . late_penalty
2016-06-24 10:50:40 +08:00
sheet [ count_row , 12 ] = stu . work_score . nil? ? l ( :label_without_score ) : stu . work_score . round ( 2 )
sheet [ count_row , 13 ] = format_time ( stu . created_at )
else
2016-06-24 18:23:00 +08:00
sheet [ count_row , 9 ] = ( home . teacher_priority == 1 && ! stu . teacher_score . nil? ) ? 0 : stu . late_penalty
2016-06-24 10:50:40 +08:00
sheet [ count_row , 10 ] = stu . work_score . nil? ? l ( :label_without_score ) : stu . work_score . round ( 2 )
sheet [ count_row , 11 ] = format_time ( stu . created_at )
end
count_row += 1
end
elsif home . homework_type == 3 #分组作业
if home . anonymous_comment == 0
2016-09-30 17:04:19 +08:00
sheet . row ( 7 ) . concat ( [ l ( :excel_rank ) , l ( :excel_group_member ) , l ( :excel_homework_name ) , l ( :excel_homework_project ) , l ( :excel_homework_des ) ,
2016-06-24 10:50:40 +08:00
l ( :excel_t_score ) , l ( :excel_ta_score ) , l ( :excel_n_score ) , l ( :excel_a_penalty ) , l ( :excel_l_penalty ) , l ( :excel_f_score ) , l ( :excel_commit_time ) ] )
else
2016-09-30 17:04:19 +08:00
sheet . row ( 7 ) . concat ( [ l ( :excel_rank ) , l ( :excel_group_member ) , l ( :excel_homework_name ) , l ( :excel_homework_project ) , l ( :excel_homework_des ) ,
2016-06-24 10:50:40 +08:00
l ( :excel_t_score ) , l ( :excel_ta_score ) , l ( :excel_l_penalty ) , l ( :excel_f_score ) , l ( :excel_commit_time ) ] )
end
2016-09-30 17:04:19 +08:00
count_row = 8
2016-06-24 10:50:40 +08:00
items = home . student_works . order ( " work_score desc " )
items . each_with_index do | stu , j |
sheet [ count_row , 0 ] = j + 1
sheet [ count_row , 1 ] = get_group_member_names stu
sheet [ count_row , 2 ] = stu . name
sheet [ count_row , 3 ] = ( stu . project_id == 0 || stu . project_id . nil? ) ? l ( :excel_no_project ) : stu . project . name
sheet [ count_row , 4 ] = strip_html stu . description
sheet [ count_row , 5 ] = stu . teacher_score . nil? ? l ( :label_without_score ) : stu . teacher_score . round ( 2 )
sheet [ count_row , 6 ] = stu . teaching_asistant_score . nil? ? l ( :label_without_score ) : stu . teaching_asistant_score . round ( 2 )
if home . anonymous_comment == 0
sheet [ count_row , 7 ] = stu . student_score . nil? ? l ( :label_without_score ) : stu . student_score . round ( 2 )
2016-06-24 18:23:00 +08:00
sheet [ count_row , 8 ] = ( home . teacher_priority == 1 && ! stu . teacher_score . nil? ) ? 0 : stu . absence_penalty
sheet [ count_row , 9 ] = ( home . teacher_priority == 1 && ! stu . teacher_score . nil? ) ? 0 : stu . late_penalty
2016-06-24 10:50:40 +08:00
sheet [ count_row , 10 ] = stu . work_score . nil? ? l ( :label_without_score ) : stu . work_score . round ( 2 )
sheet [ count_row , 11 ] = format_time ( stu . created_at )
else
2016-06-24 18:23:00 +08:00
sheet [ count_row , 7 ] = ( home . teacher_priority == 1 && ! stu . teacher_score . nil? ) ? 0 : stu . late_penalty
2016-06-24 10:50:40 +08:00
sheet [ count_row , 8 ] = stu . work_score . nil? ? l ( :label_without_score ) : stu . work_score . round ( 2 )
sheet [ count_row , 9 ] = format_time ( stu . created_at )
end
count_row += 1
end
end
end
2016-01-29 11:02:57 +08:00
= begin
2014-12-30 17:49:48 +08:00
group0 = CourseGroup . new ( ) ;
group0 . id = 0 ;
group0 . name = l ( :excel_member_with_out_class )
groups_dup = groups . dup
groups_dup << group0
groups_dup . each do | group |
sheet1 [ count_row , 0 ] = l ( :excel_class )
sheet1 [ count_row , 1 ] = group . name
count_row += 1
members . each do | member |
if member . course_group_id == group . id
sheet1 [ count_row , 0 ] = member . user . id
sheet1 [ count_row , 1 ] = member . user . lastname . to_s + member . user . firstname . to_s
sheet1 [ count_row , 2 ] = member . user . login
sheet1 [ count_row , 3 ] = member . user . user_extensions . student_id
sheet1 [ count_row , 4 ] = member . user . mail
2014-12-31 09:48:17 +08:00
sheet1 [ count_row , 5 ] = format ( " %0.2f " , member . score . nil? ? 0 :member . score . to_s )
2014-12-30 17:49:48 +08:00
count_row += 1
end
end
end
2016-01-29 11:02:57 +08:00
= end
2014-12-30 17:49:48 +08:00
book . write xls_report
xls_report . string
end
2014-12-31 17:02:55 +08:00
2014-09-24 14:47:53 +08:00
end