复制课程时可复制资源和作业
This commit is contained in:
parent
c93b4d109a
commit
09c8e57f1c
|
@ -450,6 +450,93 @@ class CoursesController < ApplicationController
|
|||
#copy avatar
|
||||
copy_avatar(@course, copy_course)
|
||||
|
||||
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
|
||||
if params[:checkAll]
|
||||
attachments = copy_course.attachments
|
||||
attachments.each do |attachment|
|
||||
|
@ -513,6 +600,7 @@ class CoursesController < ApplicationController
|
|||
end
|
||||
end
|
||||
end
|
||||
=end
|
||||
end
|
||||
if @course
|
||||
respond_to do |format|
|
||||
|
|
|
@ -88,7 +88,8 @@ class Attachment < ActiveRecord::Base
|
|||
cattr_accessor :thumbnails_storage_path
|
||||
@@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails")
|
||||
|
||||
before_save :files_to_final_location,:act_as_course_activity
|
||||
before_save :files_to_final_location
|
||||
after_save :act_as_course_activity
|
||||
after_create :office_conver, :be_user_score,:act_as_forge_activity,:create_attachment_ealasticsearch_index
|
||||
after_update :office_conver, :be_user_score,:update_attachment_ealasticsearch_index
|
||||
after_destroy :delete_from_disk,:down_user_score,:delete_attachment_ealasticsearch_index, :decrease_attchments_count
|
||||
|
@ -606,8 +607,14 @@ class Attachment < ActiveRecord::Base
|
|||
|
||||
#课程动态公共表记录
|
||||
def act_as_course_activity
|
||||
if self.container_type == "Course" && self.course_acts.empty?
|
||||
self.course_acts << CourseActivity.new(:user_id => self.author_id,:course_id => self.container_id)
|
||||
if self.container_type == "Course"
|
||||
if self.is_publish == 0
|
||||
self.course_acts.destroy_all
|
||||
else
|
||||
if self.is_publish == 1 && self.course_acts.empty?
|
||||
self.course_acts << CourseActivity.new(:user_id => self.author_id,:course_id => self.container_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -93,15 +93,23 @@
|
|||
<div class="cl"></div>
|
||||
</li>
|
||||
<li class="ml58">
|
||||
<label class="fl">复制资源 :</label>
|
||||
<label class="fl">复制 :</label>
|
||||
<ul class="fl" id="copyResource">
|
||||
<li class="sendCourseName fl mr15 ml5">
|
||||
<label>
|
||||
<input name="checkAll" type="checkbox" id="allResource" value="0" class="resourceCopy"/>
|
||||
全部</label>
|
||||
<input name="course_content_type[]" type="checkbox" value="0" class="resourceCopy"/>
|
||||
作业</label>
|
||||
</li>
|
||||
<span class="c_red ml5 fl mb10">复制到新课中的作业将在1个月后发布、2个月后提交截止,请您调整作业的发布时间、截止时间等时间节点。</span>
|
||||
<div class="cl"></div>
|
||||
<li class="sendCourseName fl mr15">
|
||||
<label>
|
||||
<input name="course_content_type[]" type="checkbox" value="1" class="resourceCopy"/>
|
||||
资源</label>
|
||||
</li>
|
||||
<span class="c_red ml5 fl mb10">复制到新课的资源将在1个月后发布,请您调整资源的发布时间,否则学生可能看不到资源。</span>
|
||||
</ul>
|
||||
<ul class="fl" id="copyResource2">
|
||||
<!--<ul class="fl" id="copyResource2">
|
||||
<li class="sendCourseName fl mr15">
|
||||
<label>
|
||||
<input name="course_attachment_type[]" type="checkbox" value="1" class="resourceCopy"/>
|
||||
|
@ -134,7 +142,7 @@
|
|||
</li>
|
||||
<div class="cl"></div>
|
||||
</ul>
|
||||
<span class="c_red ml5 fl mb10">您可以通过选择资源类型,将对应资源复制到新课程中。</span>
|
||||
<span class="c_red ml5 fl mb10">您可以通过选择类型,将对应类型复制到新课程中。</span>-->
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<% end %>
|
||||
|
|
Loading…
Reference in New Issue