191 lines
6.3 KiB
Ruby
191 lines
6.3 KiB
Ruby
# encoding: utf-8
|
|
module SyllabusesHelper
|
|
def get_syllabuses_by_tag(tag_name)
|
|
Syllabus.tagged_with(tag_name).order('updated_at desc')
|
|
end
|
|
|
|
def find_user_not_in_current_syllabus_by_name syllabus
|
|
if params[:q] && params[:q].lstrip.rstrip != ""
|
|
scope = Principal.active.sorted.not_member_of_syllabus(syllabus).like(params[:q])
|
|
else
|
|
scope = []
|
|
end
|
|
principals = paginateHelper scope,10
|
|
s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :id => 'principals', :class => 'sy_new_tchlist')
|
|
links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true){|text, parameters, options|
|
|
link_to text, host_with_protocol + "/syllabus_member/syl_member_autocomplete?" + parameters.merge(:q => params[:q],:flag => true,:syllabus=> syllabus, :format => 'js').to_query, :remote => true
|
|
}
|
|
s + content_tag('ul', links,:class => 'wlist',:style=>'float:left !important', :id => "syllabus_member_pagination_links" )
|
|
end
|
|
|
|
def teacher_count syllabus
|
|
count = 0
|
|
courses = syllabus.courses
|
|
unless courses.empty?
|
|
courses.each do |c|
|
|
count += TeacherAndAssistantCount c
|
|
end
|
|
end
|
|
count
|
|
end
|
|
|
|
def student_count syllabus
|
|
count = 0
|
|
courses = syllabus.courses
|
|
unless courses.empty?
|
|
courses.each do |c|
|
|
count += studentCount c
|
|
end
|
|
end
|
|
count
|
|
end
|
|
|
|
def file_count syllabus
|
|
count = 0
|
|
courses = syllabus.courses
|
|
unless courses.empty?
|
|
courses.each do |c|
|
|
count += visable_attachemnts_incourse(c).count
|
|
end
|
|
end
|
|
count
|
|
end
|
|
|
|
def major_level_option
|
|
content = []
|
|
option0 = []
|
|
option0 << "选择课程所属专业层级"
|
|
option0 << 0
|
|
option1 = []
|
|
option1 << "专科"
|
|
option1 << 3
|
|
option2 = []
|
|
option2 << "本科"
|
|
option2 << 2
|
|
option3 = []
|
|
option3 << "研究生"
|
|
option3 << 1
|
|
content << option0
|
|
content << option1
|
|
content << option2
|
|
content << option3
|
|
content
|
|
end
|
|
|
|
def discipline_category_option major_level = 3
|
|
content = []
|
|
option0 = []
|
|
option0 << "选择课程所属学科门类"
|
|
option0 << 0
|
|
content << option0
|
|
DisciplineCategory.where(:major_level => major_level).each do |dis|
|
|
option = []
|
|
option << dis.name.to_s
|
|
option << dis.id
|
|
content << option
|
|
end
|
|
content
|
|
end
|
|
|
|
def first_level_discipline_option disc_ca = 27
|
|
content = []
|
|
option0 = []
|
|
option0 << "选择课程所属一级学科"
|
|
option0 << 0
|
|
content << option0
|
|
FirstLevelDiscipline.where(:discipline_category_id => disc_ca).each do |fir_dis|
|
|
option = []
|
|
option << fir_dis.name.to_s
|
|
option << fir_dis.id
|
|
content << option
|
|
end
|
|
content
|
|
end
|
|
|
|
def syllabus_type_option
|
|
content = []
|
|
option0 = []
|
|
option0 << "请选择课程性质"
|
|
option0 << 0
|
|
option1 = []
|
|
option1 << "专业选修课"
|
|
option1 << 3
|
|
option2 = []
|
|
option2 << "学科必修课"
|
|
option2 << 2
|
|
option3 = []
|
|
option3 << "公共必修课"
|
|
option3 << 1
|
|
option4 = []
|
|
option4 << "实践选修课"
|
|
option4 << 5
|
|
option5 = []
|
|
option5 << "实践必修课"
|
|
option5 << 4
|
|
content << option0
|
|
content << option1
|
|
content << option2
|
|
content << option3
|
|
content << option4
|
|
content << option5
|
|
content
|
|
end
|
|
|
|
def quote_resource_bank resource, course
|
|
atta = Attachment.new(:filename => resource.filename, :disk_filename => resource.disk_filename, :filesize => resource.filesize, :digest => resource.digest, :downloads => 0, :is_publish => 0,
|
|
:author_id => User.current.id, :description => resource.description, :disk_directory => resource.disk_directory, :is_public => 0, :copy_from => resource.copy_from.nil? ? resource.id : resource.copy_from,
|
|
:quotes => 0, :resource_bank_id => resource.id, :created_on => Time.now, :content_type =>resource.content_type)
|
|
if course.attachments << atta
|
|
# 更新引用次数
|
|
quotes = resource.quotes.to_i + 1
|
|
resource.update_attribute(:quotes, quotes)
|
|
end
|
|
end
|
|
|
|
def quote_homework_bank homework, course
|
|
new_homework = HomeworkCommon.new(:name => homework.name, :user_id => User.current.id, :description => homework.description, :homework_type => homework.homework_type, :late_penalty => 0,
|
|
:course_id => course.id, :teacher_priority => 1, :anonymous_comment => 1, :quotes => 0, :is_open => 0,
|
|
:homework_bank_id => homework.id, :score_open => 1, :anonymous_appeal => 0)
|
|
|
|
new_homework.homework_detail_manual = HomeworkDetailManual.new
|
|
new_homework_detail_manual = new_homework.homework_detail_manual
|
|
new_homework_detail_manual.ta_proportion = new_homework.homework_type == 2 ? 0.4 : 1.0
|
|
new_homework_detail_manual.comment_status = 0
|
|
new_homework_detail_manual.evaluation_num = 3
|
|
new_homework_detail_manual.absence_penalty = 0
|
|
|
|
if new_homework.homework_type == 2
|
|
new_homework.homework_detail_programing = HomeworkDetailPrograming.new
|
|
new_homework.homework_detail_programing.ta_proportion = 0.6
|
|
new_homework.homework_detail_programing.language = homework.language
|
|
homework.homework_bank_tests.each_with_index do |homework_test|
|
|
if homework_test.test_type
|
|
new_homework.homework_tests << HomeworkTest.new(
|
|
input: homework_test.input,
|
|
output: homework_test.output
|
|
)
|
|
else
|
|
new_homework.homework_samples << HomeworkSample.new(
|
|
input: homework_test.input,
|
|
output: homework_test.output
|
|
)
|
|
end
|
|
end
|
|
end
|
|
|
|
if new_homework.homework_type == 3
|
|
new_homework.homework_detail_group = HomeworkDetailGroup.new
|
|
new_homework.homework_detail_group.min_num = homework.min_num
|
|
new_homework.homework_detail_group.max_num = homework.max_num
|
|
new_homework.homework_detail_group.base_on_project = homework.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
|
|
homework.update_column(:quotes, homework.quotes+1)
|
|
end
|
|
end
|
|
end
|