diff --git a/app/controllers/personal_courses_controller.rb b/app/controllers/personal_courses_controller.rb index ab61351..2f5b2ca 100644 --- a/app/controllers/personal_courses_controller.rb +++ b/app/controllers/personal_courses_controller.rb @@ -42,7 +42,8 @@ class PersonalCoursesController < ApplicationController "course_multimedia_file", "course_material_file", "course_supplement_file", - "course_evaluation_file" + "course_evaluation_file", + "students" ] {"plugin_datas"=>plugin.get_plugin_data(fields_to_show)} diff --git a/app/helpers/admin/courses_helper.rb b/app/helpers/admin/courses_helper.rb index 644cd05..66c8453 100644 --- a/app/helpers/admin/courses_helper.rb +++ b/app/helpers/admin/courses_helper.rb @@ -1,10 +1,7 @@ module Admin::CoursesHelper def page_for_course(course_object) - page = nil - pages = Page.where(:module=>"course") - - page = pages.first if page.nil? - request.protocol+(request.host_with_port+page.url+'/'+course_object.to_param).gsub('//','/') rescue "/" + page = Page.where(:module=>"personal_course").first + ("/#{I18n.locale}"+page.url+'/'+course_object.to_param).gsub('//','/') rescue "#" end def get_data_for_excel(year_start,year_end) diff --git a/app/models/course.rb b/app/models/course.rb index 42c7954..01e6b04 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -8,7 +8,7 @@ class Course field :title, as: :slug_title, type: String, localize: true field :objective, localize: true field :year, type: Integer - + field :student_ids, type: Array, default: [] has_many :course_syllabus_files, :dependent => :destroy, :autosave => true has_many :course_progress_files, :dependent => :destroy, :autosave => true has_many :course_activity_files, :dependent => :destroy, :autosave => true @@ -31,7 +31,27 @@ class Course accepts_nested_attributes_for :course_evaluation_files, :allow_destroy => true scope :sort_for_frontend, ->{ where(:is_hidden=>false).order_by(:year=>'desc') } - + before_save do |record| + if !record.student_ids.empty? + selected_course = SelectedCourse rescue nil + if selected_course + record.student_ids.each do |student_id| + selected_course = SelectedCourse.where(:member_profile_id => student_id,:course_id=>self.id).first + if selected_course.nil? + SelectedCourse.create(:member_profile => MemberProfile.find(student_id) , :course_id=>self.id , :year=>self.year,:course_title_translations=>self.title_translations,:course_objective_translations=>self.objective_translations) rescue nil + else + selected_course.update(:year=>self.year,:course_title_translations=>self.title_translations,:course_objective_translations=>self.objective_translations) + end + end + end + end + end + def students + return MemberProfile.where(:id.in=>self.student_ids) + end + def display_students + return MemberProfile.where(:id.in=>self.student_ids).map{|m| m.name}.join(", ") + end def self.get_plugin_datas_to_member(datas) fields_to_show = [ @@ -111,6 +131,8 @@ class Course when "authors" path = OrbitHelper.url_to_plugin_show(self.member_profile.to_param, 'member') rescue '#' value = "#{self.member_profile.name}" + when "students" + value = self.display_students else value = self.send(field) rescue "" end diff --git a/app/views/admin/courses/_courses.html.erb b/app/views/admin/courses/_courses.html.erb index 043f618..f4ea125 100644 --- a/app/views/admin/courses/_courses.html.erb +++ b/app/views/admin/courses/_courses.html.erb @@ -10,6 +10,7 @@ - <%= course.member_profile.name rescue "" %> + <%= course.member_profile.name rescue "" %> + <%= course.display_students rescue "" %> <% end %> \ No newline at end of file diff --git a/app/views/admin/courses/_form.html.erb b/app/views/admin/courses/_form.html.erb index ff97edc..416afd1 100644 --- a/app/views/admin/courses/_form.html.erb +++ b/app/views/admin/courses/_form.html.erb @@ -65,7 +65,7 @@ <% files_hash = {} - ["course_syllabus_file", "course_progress_file", "course_activity_file", "course_multimedia_file", "course_material_file", "course_supplement_file", "course_evaluation_file"].each do |file| + ["selected_course_syllabus_file", "selected_course_progress_file", "selected_course_activity_file", "selected_course_multimedia_file", "selected_course_material_file", "selected_course_supplement_file", "selected_course_evaluation_file"].each do |file| hash = {} hash["html"] = add_attribute("form_file", f, file.pluralize.to_sym) hash["count"] = @course.send(file.pluralize).count rescue 0 @@ -109,6 +109,9 @@
  • <%= t(:status) %>
  • +
  • + <%= t("personal_course.students") %> +
  • @@ -133,7 +136,7 @@
    <% members = !@course.member_profile.nil? ? @course.member_profile.to_a : [] %> - <%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'course[member_profile_id]', email_members: members} %> + <%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'course[member_profile_id]', email_members: members,index:'0',select_name:'member_profile_id'} %>
    @@ -176,6 +179,14 @@ +
    +
    + +
    + <%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'course[student_ids][]', email_members: @course.students,index:'1',select_name:'student_ids'} %> +
    +
    +
    diff --git a/app/views/admin/courses/index.html.erb b/app/views/admin/courses/index.html.erb index 253462b..97c35d9 100644 --- a/app/views/admin/courses/index.html.erb +++ b/app/views/admin/courses/index.html.erb @@ -4,6 +4,7 @@ <%= t('personal_course.year') %> <%= t('module_name.courses') %> <%= t("personal_plugins.author") %> + <%= t("personal_course.students") %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 53395d0..fe337a7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -4,6 +4,7 @@ en: courses: Courses course: Course personal_course: + students: Students year: Year title: Course Title objective: Objective diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index aa3a1df..6752920 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -4,6 +4,7 @@ zh_tw: courses: 教學資料 course: 教學資料 personal_course: + students: 學生 year: 年度 title: 課程名稱 objective: 課程目標