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 @@ -