diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index 06f6b3278..0015c0a8d 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -8,109 +8,316 @@ class ManagementsController < ApplicationController include ApplicationHelper # 单位部门列表 def departments - @department =Department.all + @menu_type = 6 + @sub_type = 2 + @department =Department.where("0=0") + search=params[:search] + if search.blank? + @department = @department + else + @department = @department.where("name like '%#{search}%'") + end + @department_count =@department.count + limit = 20 + @is_remote = true + @department_pages = Paginator.new @department_count, limit, params['page'] || 1 + @offset ||=@department_pages.offset + @department = paginateHelper @department, limit + respond_to do |format| + format.js + format.html + end end # 单位列表 def departments_part - @schools = School.all - @schools_count = @schools.count + @menu_type = 6 + @sub_type = 1 + @schools = School.where("0=0") + search=params[:search] + if search.blank? + @schools = @schools + else + @schools = @schools.where("name like '%#{search}%'") + end + @schools_count = @schools.count limit = 20 @is_remote = true @schools_pages = Paginator.new @schools_count, limit, params['page'] || 1 @offset ||= @schools_pages.offset - @schools = paginateHelper @schools, limit + @schools= paginateHelper @schools, limit + + respond_to do |format| + format.js + format.html + end end # 部门审核 def depart - @apply_status = ApplyAddSchools.all + @menu_type = 10 + @sub_type = 3 + search = params[:search] + @apply_status = ApplyAddDepartment.where("0=0") + if search.blank? + @apply_status = @apply_status.where("0=0") + else + @apply_status= @apply_status.where("name like '%#{search}%'") + end @apply_status_count = @apply_status.count limit = 20 @is_remote = true @apply_status_pages = Paginator.new @apply_status_count, limit, params['page'] || 1 @offset ||=@apply_status_pages.offset @apply_status = paginateHelper @apply_status, limit + respond_to do |format| + format.js + format.html + end end # 单位审批 def unit - @apply_status= ApplyAddSchools.all + @menu_type = 10 + @sub_type = 4 + search = params[:search] + @apply_status = ApplyAddSchools.where("0=0") + if search.blank? + @apply_status = @apply_status.where("0=0") + else + @apply_status= @apply_status.where("name like '%#{search}%'") + end @apply_status_count = @apply_status.count limit = 20 @is_remote = true @apply_status_pages = Paginator.new @apply_status_count, limit, params['page'] || 1 - @offset ||=@apply_status_pages.offset + @offset ||= @apply_status_pages.offset @apply_status = paginateHelper @apply_status, limit + + respond_to do |format| + format.js + format.html + end end # 课堂列表 def classroom - @syllabus = Syllabus.all + @menu_type = 2 + @sub_type = 1 + @syllabus = Syllabus.where("0=0") + unless params[:school_id] || params[:search] || params[:keyword] || params[:status] + user_exs=UserExtensions.where(:user_id=> @syllabus.map(&:user_id)) + @schools = School.where(:id =>user_exs.map(&:school_id)) + end + major_level_option=params[:major_level_option] + discipline_category_option=params[:discipline_category_option] + first_level_discipline_option=params[:first_level_discipline_option] + syllabus_major_option=params[:syllabus_major_option] + keyword=params[:keyword] + search=params[:search] + if major_level_option!='0' + @syllabus=@syllabus.where(:major_level=>major_level_option) + else + @syllabus=@syllabus + end + if discipline_category_option !=nil + @syllabus=@syllabus.where(:discipline_category_id=>discipline_category_option) + end + if first_level_discipline_option!=nil + @syllabus=@syllabus.where(:first_level_discipline_id=>first_level_discipline_option) + end + if syllabus_major_option!=nil + @syllabus=@syllabus.where(:major_id=>syllabus_major_option) + end + if params[:school_id] && params[:school_id] != '0' + @syllabus = Syllabus.includes(:user => {:user_extensions => []}).where("user_extensions.school_id = #{params[:school_id]}") + else + @syllabus = @syllabus.where("0=0") + end + if "u_name" == keyword + if search.blank? + @syllabus = @syllabus + else + user_id = User.where("concat(lastname, firstname) like '%#{search}%'") + @syllabus = @syllabus.includes(:user).where("concat(users.lastname, users.firstname) like '%#{search}%'") + end + else + @syllabus= @syllabus.where("user_id like '%#{search}%'") + end @syllabus_count = @syllabus.count limit = 20 @is_remote = true @syllabus_pages = Paginator.new @syllabus_count, limit, params['page'] || 1 @offset ||= @syllabus_pages.offset @syllabus = paginateHelper @syllabus, limit + respond_to do |format| + format.html + format.js + end end # 班级列表 def classroom_classment + @menu_type = 2 + @sub_type = 2 @courses = Course.where("0=0") - @courses = @courses.select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc") - @course_count = @courses.count + # @courses = @courses.select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc") + @timing=Course.where(:is_end=>false).count + @end=Course.where(:is_end=>true).count + unless params[:school_id] || params[:search] || params[:keyword] || params[:status] + user_exs=UserExtensions.where(:school_id=> @courses.map(&:school_id)) + @schools = School.where(:id =>user_exs.map(&:school_id)) + end + search = params[:search] # 搜索字 + keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/课程名搜索 + status = params[:status].to_i + if params[:school_id] && params[:school_id] != '0' + @courses =Course.joins("join users u on courses.tea_id = u.id").joins("join user_extensions ue on u.id = ue.user_id").where("ue.school_id = #{params[:school_id]}") + else + @courses = Course.where("0=0") + end + if params[:status] && params[:status]!='' + @courses =@courses.where(:is_end =>status) + end + if "u_name" == keyword + if search.blank? + @courses = @courses + else + user_id = User.where("concat(lastname, firstname) like '%#{search}%'") + @courses = @courses.joins("join users u on courses.tea_id = u.id").where("concat(u.lastname, u.firstname) like '%#{search}%'") + end + else + @courses= @courses.where("name like '%#{search}%'") + end + @courses = @courses.select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").reorder("updatetime desc") + @courses_count = @courses.count limit = 20 @is_remote = true - @course_pages = Paginator.new @course_count, limit, params['page'] || 1 - @offset ||= @course_pages.offset + @courses_pages = Paginator.new @courses_count, limit, params['page'] || 1 + @offset ||= @courses_pages.offset @courses = paginateHelper @courses, limit + respond_to do |format| + format.js + format.html + end end # 课程实训 def class_shixuns - @c_shixuns = Subject.all + @menu_type = 4 + @sub_type = 1 + @edit_class_sx_num=Subject.where(:status => 0).count + @audit_class_sx_num=Subject.where(:status => 1).count + @publish_class_sx_num=Subject.where(:status => 2).count + search = params[:search] # 搜索字 + keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/课程名搜索 + status = params[:status].to_i + if params[:school_id] && params[:school_id] != '0' + @c_shixuns = Subject.includes(:user => {:user_extensions => []}).where("user_extensions.school_id = #{params[:school_id]}") + else + @c_shixuns = Subject.where("0=0") + end + if params[:status] && params[:status]!='' + @c_shixuns= @c_shixuns.where(:status =>status) + end + if search.blank? + @c_shixuns = @c_shixuns + else + if "u_name" == keyword + user_id = User.where("concat(lastname, firstname) like '%#{search}%'") + @c_shixuns = @c_shixuns.includes(:user).where("concat(users.lastname, users.firstname) like '%#{search}%'") + else + @c_shixuns= @c_shixuns.where("name like '%#{search}%'") + end + end + unless params[:school_id] || params[:search] || params[:keyword] || params[:status] + user_exs = UserExtensions.where(:user_id => @c_shixuns.map(&:user_id)) + @schools = School.where(:id => user_exs.map(&:school_id)) + end + respond_to do |format| + format.js + format.html + end end + # 已发布课程实训 def class_publish_shixuns - @c_shixuns = Subject.where(:status => 1) + @menu_type = 4 + @sub_type = 2 + search = params[:search] # 搜索字 + keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/课程名搜索 + if params[:school_id] && params[:school_id] != '0' + @c_shixuns = Subject.includes(:user => {:user_extensions => []}).where("subjects.status = 2 and user_extensions.school_id = #{params[:school_id]}") + else + @c_shixuns = Subject.where(:status => 2) + end + if search.blank? + @c_shixuns = @c_shixuns + else + if "u_name" == keyword + # 如果用户搜索为空,不用遍历user表,直接查找所有实训, 有搜索时才查找user + user_id = User.where("concat(lastname, firstname) like '%#{search}%'") + @c_shixuns = @c_shixuns.includes(:user).where("concat(users.lastname, users.firstname) like '%#{search}%'") + else + @c_shixuns= @c_shixuns.where("name like '%#{search}%'") + end + end + unless params[:school_id] || params[:search] || params[:keyword] + user_exs = UserExtensions.where(:user_id => @c_shixuns.map(&:user_id)) + @schools = School.where(:id => user_exs.map(&:school_id)) + end + respond_to do |format| + format.js + format.html + end + end + + def delete_subject + @subject = Subject.find params[:subject_id] + if @subject + @subject.destroy + respond_to do |format| + format.js + end + end end # 0 全部;1 活动的; 2 已注册; 3 锁定 def users - status = params[:user_status].nil? ? 0 : params[:user_status].to_i - @us_order = params[:us_order].blank? ? "desc" : params[:us_order] # 排序 - @order_key = params[:order_key].blank? ? "created_on" : params[:order_key] # 排序关键字 + @menu_type =7 + @sub_type = 1 + status = params[:user_status].nil? ? 0 : params[:user_status].to_i + @us_order = params[:us_order].blank? ? "desc" : params[:us_order] # 排序 + @order_key = params[:order_key].blank? ? "created_on" : params[:order_key] # 排序关键字 condition = (params[:research_condition].nil? || params[:research_condition] == "name") ? "concat(lastname, firstname)" : params[:research_condition] if 0 == status if params[:research_condition] == "phone" && params[:research_contents].blank? - @users = User.order("#{@order_key} #{@us_order}").all + @users = User.order("#{@order_key} #{@us_order}").all else - @users = User.where("#{condition} like '%#{params[:research_contents]}%'").order("#{@order_key} #{@us_order}").all + @users = User.where("#{condition} like '%#{params[:research_contents]}%'").order("#{@order_key} #{@us_order}").all end else if params[:research_condition] == "phone" && params[:research_contents].blank? - @users = User.where(:status => status).order("#{@order_key} #{@us_order}").all + @users = User.where(:status => status).order("#{@order_key} #{@us_order}").all else - @users = User.where("status = #{status} and #{condition} like '%#{params[:research_contents]}%'").order("#{@order_key} #{@us_order}").all + @users = User.where("status = #{status} and #{condition} like '%#{params[:research_contents]}%'").order("#{@order_key} #{@us_order}").all end end - @users_count = @users.count @limit = 20 @is_remote = true @users_pages = Paginator.new @users_count, @limit, params['page'] || 1 @offset ||= @users_pages.offset @users = paginateHelper @users, @limit - respond_to do |format| - format.js + format.js format.html end end def shixuns @menu_type = 3 + @sub_type = 1 sx_status = params[:status].blank? ? [0, 1, 2, 3] : params[:status].to_i # 搜索实训的状态 keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/实训名搜索 search = params[:search] # 搜索的字 @@ -130,7 +337,6 @@ class ManagementsController < ApplicationController @audit_sx_num = Shixun.where(:status => 1).count @publish_sx_num =Shixun.where(:status => 2).count @close_sx_num = Shixun.where(:status => 3).count - @shixuns_count = @shixuns.count limit = 20 @shixuns_pages = Paginator.new @shixuns_count, limit, params['page'] || 1 @@ -145,6 +351,7 @@ class ManagementsController < ApplicationController # 已发布的实训 def publish_shixuns @menu_type = 3 + @sub_type = 2 @sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order] # 排序 search = params[:search] # 搜索字 keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/实训名搜索 @@ -168,7 +375,6 @@ class ManagementsController < ApplicationController @shixuns_pages = Paginator.new @shixuns_count, limit, params['page'] || 1 @offset ||= @shixuns_pages.offset @shixuns = paginateHelper @shixuns, limit - respond_to do |format| format.js format.html @@ -178,11 +384,11 @@ class ManagementsController < ApplicationController # 已关闭的实训 def close_shixuns @menu_type = 3 + @sub_type = 3 @sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order] # 排序 search = params[:search] # 搜索字 keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/实训名搜索 reopen = params[:reopen] # 从新开启实训,参数是实训的Id - unless reopen.blank? Shixun.find(reopen).update_attribute(:status, 2) end @@ -202,7 +408,6 @@ class ManagementsController < ApplicationController @shixuns_pages = Paginator.new @shixuns_count, limit, params['page'] || 1 @offset ||= @shixuns_pages.offset @shixuns = paginateHelper @shixuns, limit - respond_to do |format| format.js format.html @@ -210,7 +415,8 @@ class ManagementsController < ApplicationController end def users_trial - @menu_type = 6 + @menu_type = 7 + @sub_type = 2 @users = User.where(:status => 1).order("created_on desc").all @users_count = @users.count @limit = 20 @@ -218,7 +424,6 @@ class ManagementsController < ApplicationController @users_pages = Paginator.new @users_count, @limit, params['page'] || 1 @offset ||= @users_pages.offset @users = paginateHelper @users, @limit - end def search_user @@ -322,7 +527,8 @@ class ManagementsController < ApplicationController def trial_authorization - @menu_type = 9 + @menu_type =10 + @sub_type = 2 search = params[:search] @status = trial_authorization_status(params[:status]) # @status = (params[:status].blank? || params[:status] == "0") ? 0 : [1,2] @@ -380,7 +586,8 @@ class ManagementsController < ApplicationController # copy from admin def identity_authentication - @menu_type = 9 + @menu_type = 10 + @sub_type = 1 @type = trial_authorization_status(params[:type]) type = params[:type] || 0 # 存在type 就用type 没有就为 0 user_id = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{params[:name]}%'") @@ -413,10 +620,18 @@ class ManagementsController < ApplicationController end def subject_authorization + @menu_type = 10 + @sub_type == 6 @type = trial_authorization_status params[:type] - @subject = ApplyAction.where(:container_type => "ApplySubject", :status => @type).order("created_at desc") + @authorizations = ApplyAction.where(:container_type => "ApplySubject", :status => @type).order("created_at desc") # @subject=Subject.all + @authorizations_count = @authorizations.count + @limit = 15 + @is_remote = true + @authorizations_pages = Paginator.new @authorizations_count, @limit, params['page'] || 1 + @offset ||= @authorizations_pages.offset + @authorizations = paginateHelper @authorizations, @limit respond_to do |format| format.js format.html @@ -424,6 +639,8 @@ class ManagementsController < ApplicationController end def shixun_authorization + @menu_type = 10 + @sub_type == 5 @type = trial_authorization_status params[:type] @authorizations = ApplyAction.where(:container_type => "ApplyShixun", :status => @type).order("created_at desc") search = params[:search] @@ -446,27 +663,26 @@ class ManagementsController < ApplicationController def deal_subject_authorization apply_action = ApplyAction.find(params[:apply_id]) type = params[:type].to_i - subject = subject.find apply_action.container_id + subject = Subject.find apply_action.container_id if type == 0 #拒绝 subject.update_column('status', 0) apply_action.update_attributes(:status => 2, :reason => params[:reject_reason], :dealer_id => User.current.id) - notes = "您所在团队提交的项目实训发布申请:#{subject.name},审核未通过。
原因:#{params[:reject_reason]}" + notes = "您所在团队提交的课程实训发布申请:#{subject.name},审核未通过。
原因:#{params[:reject_reason]}" JournalsForMessage.create(:jour_id => subject.user_id, :jour_type => 'Principal', :user_id => User.current.id, :notes => notes, :private => 1, :reply_id => 0) else #同意 subject.update_column('status', 2) apply_action.update_attributes(:status => 1, :dealer_id => User.current.id) - subject_modify_status_without_publish subject, 1 end - # @authorizations = ApplyAction.where(:container_type => "ApplyShixun", :status => 0) - # @authorizations_count = @authorizations.count - # @limit = 15 - # @is_remote = true - # @authorizations_pages = Paginator.new @authorizations_count, @limit, params['page'] || 1 - # @offset ||= @authorizations_pages.offset - # @authorizations = paginateHelper @authorizations, @limit - # respond_to do |format| - # format.js - # end + @authorizations = ApplyAction.where(:container_type => "ApplySubject", :status => 0) + @authorizations_count = @authorizations.count + @limit = 15 + @is_remote = true + @authorizations_pages = Paginator.new @authorizations_count, @limit, params['page'] || 1 + @offset ||= @authorizations_pages.offset + @authorizations = paginateHelper @authorizations, @limit + respond_to do |format| + format.js + end end # 项目实训发布审批 def deal_shixun_authorization diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 728a8324a..3d4969b0c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -5179,3 +5179,69 @@ def quote_homework_bank homework, course end 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_major_option fir_dis = 213 + content = [] + option0 = [] + option0 << "选择课程所属专业" + option0 << 0 + content << option0 + Major.where(:first_level_discipline_id => fir_dis).each do |major| + option = [] + option << major.name.to_s + option << major.id + content << option + end + content +end + diff --git a/app/helpers/syllabuses_helper.rb b/app/helpers/syllabuses_helper.rb index bfb5b199b..91b951d46 100644 --- a/app/helpers/syllabuses_helper.rb +++ b/app/helpers/syllabuses_helper.rb @@ -51,72 +51,6 @@ module SyllabusesHelper 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_major_option fir_dis = 213 - content = [] - option0 = [] - option0 << "选择课程所属专业" - option0 << 0 - content << option0 - Major.where(:first_level_discipline_id => fir_dis).each do |major| - option = [] - option << major.name.to_s - option << major.id - content << option - end - content - end - def syllabus_type_option content = [] option0 = [] diff --git a/app/models/course.rb b/app/models/course.rb index 77bc0e757..ccb4579a3 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -1,552 +1,552 @@ -#coding=utf-8 - -require 'elasticsearch/model' -class Course < ActiveRecord::Base - include Redmine::SafeAttributes - - include CoursesHelper - - STATUS_ACTIVE = 1 - STATUS_CLOSED = 5 - STATUS_ARCHIVED = 9 - - #elasticsearch - include Elasticsearch::Model - - #elasticsearch kaminari init - Kaminari::Hooks.init - Elasticsearch::Model::Response::Response.__send__ :include, Elasticsearch::Model::Response::Pagination::Kaminari - settings index: { number_of_shards: 5 } do - mappings dynamic: 'false' do - indexes :name, analyzer: 'smartcn',index_options: 'offsets' - indexes :description, analyzer: 'smartcn',index_options: 'offsets' - indexes :updated_at, index:"not_analyzed",type:"date" - end - end - - attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period, :open_student, :enterprise_name, :is_delete, :syllabus_id, :end_time, :end_term, :choose_group_allow, :is_end - #belongs_to :project, :class_name => 'Course', :foreign_key => :extra, primary_key: :identifier - belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher,该方法通过tea_id来调用User表 - belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school,该方法通过school_id来调用School表 - belongs_to :syllabus - # has_many :bid - has_many :members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}" - has_many :memberships, :class_name => 'Member' - has_many :member_principals, :class_name => 'Member', - :include => :principal, - :conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE})" - has_many :principals, :through => :member_principals, :source => :principal - has_many :users, :through => :members - has_many :org_courses, :dependent => :destroy - has_many :organizations, :through => :org_courses - # has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy - has_many :journals_for_messages, :as => :jour, :dependent => :destroy - # has_many :homework_for_courses, :dependent => :destroy - has_many :student, :class_name => 'StudentsForCourse', :source => :user - has_many :course_infos, :class_name => 'CourseInfos',:dependent => :destroy - has_many :enabled_modules, :dependent => :delete_all - has_many :boards, :dependent => :destroy, :order => "position ASC" - #has_many :course_journals_for_messages, :class_name => 'CourseJournalsForMessage', :as => :jour, :dependent => :destroy - has_many :news, :dependent => :destroy, :include => :author - has_one :course_status, :class_name => "CourseStatus", :dependent => :destroy - has_many :student_work_projects, :dependent => :destroy - - has_many :homework_commons, :dependent => :destroy - has_many :student_works, :through => :homework_commons, :dependent => :destroy - - has_many :course_groups, :dependent => :destroy, :order => "name ASC" - has_many :course_homework_statisticss, :dependent => :destroy - # 课程动态 - has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy - - has_many :course_activities - # 课程消息 - has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy - has_many :exercises, :dependent => :destroy - # 课程贡献榜 - has_many :course_contributor_scores, :dependent => :destroy - - #课程模块 - has_many :course_modules, :dependent => :destroy - acts_as_taggable - acts_as_nested_set :order => 'name', :dependent => :destroy - acts_as_attachable :view_permission => :view_course_files, - :delete_permission => :manage_files - - validates_presence_of :name - #validates_format_of :class_period, :with =>/^[1-9]\d*$/ - #validates_format_of :time, :with => /^\d{4}$/ - validates_format_of :name,:with =>/^[^ ]+[a-zA-Z0-9_\u4e00-\u9fa5\s\S]*$/ - validates_length_of :description, :maximum => 10000 - - before_save :self_validate - # 公开课程变成私有课程,所有资源都变成私有 - after_update :update_files_public,:update_course_ealasticsearch_index - after_create :create_board_sync, :act_as_course_activity, :act_as_course_message,:create_course_ealasticsearch_index - before_destroy :delete_all_members,:delete_course_ealasticsearch_index - after_save :log_infor - - safe_attributes 'extra', - 'time', - 'name', - 'extra', - 'code', - 'location', - 'tea_id', - 'password', - 'term', - 'is_public', - 'description', - 'class_period', - 'open_student', - 'is_delete', - 'syllabus_id', - 'end_time', - 'end_term', - 'os_allow', - 'choose_group_allow', - 'credit' - - acts_as_customizable - - scope :not_deleted, lambda{where(is_delete: 0)} - scope :not_deleted_not_end, lambda{where(is_delete: 0, is_end: 0)} - scope :not_deleted_but_is_end, lambda{where(is_end: 1, is_delete: 0)} - scope :all_course - scope :active, lambda { where(:status => STATUS_ACTIVE) } - scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) } - scope :all_public, lambda { where(:is_public => true) } - scope :visible, lambda {|*args| where(Course.where("is_delete =?", 0).visible_condition(args.shift || User.current, *args)) } - scope :allowed_to, lambda {|*args| - user = User.current - permission = nil - if args.first.is_a?(Symbol) - permission = args.shift - else - user = args.shift - permission = args.shift - end - where(Course.allowed_to_condition(user, permission, *args)) - } - scope :like, lambda {|arg| - if arg.blank? - where(nil) - else - pattern = "%#{arg.to_s.strip.downcase}%" - where(" LOWER(name) LIKE :p ", :p => pattern) - end - } - scope :indexable,lambda { where('is_public = 1 and is_delete = 0') } - def self.search(query) - __elasticsearch__.search( - { - query: { - multi_match: { - query: query, - type:"most_fields", - operator: "or", - fields: ['name', 'description^0.5'] - } - }, - sort: { - _score:{order: "desc" }, - updated_at:{order:"desc"} - - }, - highlight: { - pre_tags: [''], - post_tags: [''], - fields: { - name: {}, - description: {} - } - } - } - ) - end - - def self.e_search(query) - __elasticsearch__.search( - { - query: { - multi_match: { - query: query, - type:"most_fields", - operator: "or", - fields: ['name', 'description^0.5'] - } - }, - sort: { - _score:{order: "desc" }, - updated_at:{order:"desc"} - - } - } - ) - end - - def delete! - update_attribute(:is_delete, true) - end - - def visible?(user=User.current) - user.allowed_to?(:view_course, self) - end - - def parent_id_changed? - false - end - - # Returns the mail adresses of users that should be always notified on project events - def recipients - notified_users.collect {|user| user.mail} - end - - # Returns the users that should be notified on project events - def notified_users - # TODO: User part should be extracted to User#notify_about? - members.select {|m| m.principal.present? && (m.mail_notification? || m.principal.mail_notification == 'all')}.collect {|m| m.principal} - end - - - # 课程的短描述信息 - def short_description(length = 255) - description.gsub(/<\/?.*?>/,"").html_safe if description - #description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description - end - - # 课程的短名称信息 - def short_name(length = 8) - name.gsub(/<\/?.*?>/,"").html_safe if name - end - - def strip_html(html) - return html if html.empty? || !html.include?('<') - output = "" - tokenizer = HTML::Tokenizer.new(html) - while token = tokenizer.next - node = HTML::Node.parse(nil, 0, 0, token, false) - output += token unless (node.kind_of? HTML::Tag) or (token =~ /^ ["#{Attachmentstype.table_name}.typeId= ?",self.attachmenttype ]) - end - - - # 获取资源后缀名列表 - def contenttypes - attachmenttypes - if @attachmenttypes.length >0 - @attachmenttypes.last().suffixArr - end - end - - def active? - self.status == STATUS_ACTIVE - end - - #课程权限判断 - def allows_to?(action) - if archived? - # No action allowed on archived projects - return false - end - unless active? || Redmine::AccessControl.read_action?(action) - # No write action allowed on closed projects - return false - end - # No action allowed on disabled modules - if action.is_a? Hash - allowed_actions.include? "#{action[:controller]}/#{action[:action]}" - else - allowed_permissions.include? action - end - end - - # 课程允许的权限集合 - def allowed_permissions - @allowed_permissions ||= begin - module_names = enabled_modules.all(:select => :name).collect {|m| m.name} - Redmine::AccessControl.modules_permissions(module_names).collect {|p| p.name} - end - end - - # 课程允许的动作集合 - def allowed_actions - @actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten - end - - # 返回用户组可以访问的课程 - def users_by_role - members.includes(:user, :roles).all.inject({}) do |h, m| - m.roles.each do |r| - h[r] ||= [] - h[r] << m.user - end - h - end - end - - #自定义验证 - def self_validate - - end - - def update_files_public - unless self.is_public? - self.attachments.each do |a| - a.update_attributes(:is_public => false) - end - end - end - - - def update_default_value - self.time = Time.now.year unless time - self.term = cur_course_term unless term - self.class_period = 10 unless class_period - end - - # 创建课程讨论区 - def create_board_sync - @board = self.boards.build - #self.name=" #{l(:label_borad_course) }" - @board.name = " #{l(:label_borad_course) }"#self.name - @board.description = self.name.to_s - @board.project_id = -1 - if @board.save - logger.debug "[Course Model] ===> #{@board.to_json}" - else - logger.error "[Course Model] ===> Auto create board when course saved, because #{@board.full_messages}" - end - end - - # 新增课程留言 - # add by nwb - def self.add_new_jour(user, notes, id, options={}) - course = Course.find(id) - if options.count == 0 - pjfm = course.journals_for_messages.build(:user_id => user.id, :notes => notes, :reply_id => 0) - else - pjfm = course.journals_for_messages.build(options) - end - pjfm.save - pjfm - end - - # 删除课程所有成员 - def delete_all_members - if self.members && self.members.count > 0 - me, mr = Member.table_name, MemberRole.table_name - connection.delete("DELETE FROM #{mr} WHERE #{mr}.member_id IN (SELECT #{me}.id FROM #{me} WHERE #{me}.course_id = #{id})") - Member.delete_all(['course_id = ?', id]) - end - end - - # 创建课程模块 - def create_course_modules - mod = self.course_modules - if mod.blank? - type = ["news", "boards", "attachment", "homework", "poll", "exercises", "statistics"] - for i in 0..6 - CourseModule.create(:course_id => self.id, :module_type => type[i], :position => i + 1, :hidden => 0 ) - end - mod = self.course_modules - end - return mod - end - - def get_endup_time - begin - end_time = Time.parse(self.endup_time) - rescue Exception => e - end_time = Time.parse("3000-01-01") - Rails.logger.error "[Error] course endup_time error. ===> #{e}" - ensure - return end_time - end - end - - def get_time - begin - time = Date.new(self.time).to_time - rescue Exception => e - time = Time.parse("3000-01-01") - Rails.logger.error "[Error] course time error. ===> #{e}" - ensure - return time - end - end - - def self.allowed_to_condition(user, permission, options={}) - perm = Redmine::AccessControl.permission(permission) - base_statement = (perm && perm.read? ? "#{Course.table_name}.status <> #{Course::STATUS_ARCHIVED}" : "#{Course.table_name}.status = #{Course::STATUS_ACTIVE}") - if perm && perm.course_module - base_statement << " AND #{Course.table_name}.id IN (SELECT em.course_id FROM #{EnabledModule.table_name} em WHERE em.name='#{perm.course_module}')" - end - - if options[:course] - course_statement = "#{Course.table_name}.id = #{options[:course].id}" - course_statement << " OR (#{Course.table_name}.lft > #{options[:course].lft} AND #{Course.table_name}.rgt < #{options[:course].rgt})" if options[:with_subcourses] - base_statement = "(#{course_statement}) AND (#{base_statement})" - end - - if user.admin? - base_statement - else - statement_by_role = {} - unless options[:member] - role = user.logged? ? Role.non_member : Role.anonymous - if role.allowed_to?(permission) - statement_by_role[role] = "#{Course.table_name}.is_public = #{connection.quoted_true}" - end - end - if user.logged? - user.courses_by_role.each do |role, courses| - if role.allowed_to?(permission) && courses.any? - statement_by_role[role] = "#{Course.table_name}.id IN (#{courses.collect(&:id).join(',')})" - end - end - end - if statement_by_role.empty? - "1=0" - else - if block_given? - statement_by_role.each do |role, statement| - if s = yield(role, user) - statement_by_role[role] = "(#{statement} AND (#{s}))" - end - end - end - "((#{base_statement}) AND (#{statement_by_role.values.join(' OR ')}))" - end - end - end - - #课程动态公共表记录 - def act_as_course_activity - self.course_acts << CourseActivity.new(:user_id => self.tea_id,:course_id => self.id) - end - - #创建课程后,给该用户发送消息 - def act_as_course_message - self.course_messages << CourseMessage.new(:user_id => self.tea_id, :course_id => self.id, :viewed => false) - end - - - #项目与课程分离后,很多课程的名称等信息为空,这些数据信息存储在项目表中!!就是数据兼容的问题 - #def name - # read_attribute('name') || Project.find_by_identifier(self.extra).try(:name) - #end - - # after_commit on: [:create] do - # __elasticsearch__.index_document - # end - # - # after_commit on: [:update] do - # __elasticsearch__.update_document - # end - # - # after_commit on: [:destroy] do - # __elasticsearch__.delete_document - # end - def create_course_ealasticsearch_index - return if Rails.env.development? - if self.is_public == 1 and self.is_delete == 0 #公开 和 没有被删除的课程才被索引 - self.__elasticsearch__.index_document - end - end - - def update_course_ealasticsearch_index - return if Rails.env.development? - if self.is_public == 1 and self.is_delete == 0 #如果是初次更新成为公开或者恢复被删除的情况,会报错,那么这条记录尚未被索引过。没有报错就是更新的其他属性 - begin - self.__elasticsearch__.update_document - rescue => e - self.__elasticsearch__.index_document - end - else #如果是更新成为私有的,那么索引就要被删除 - begin - self.__elasticsearch__.delete_document - rescue => e - - end - end - end - - def delete_course_ealasticsearch_index - return if Rails.env.development? - begin - self.__elasticsearch__.delete_document - rescue => e - - end - end - - # 延迟生成邀请码 - def invite_code - return generate_invite_code - end - - # 生成邀请码 - CODES = %W(2 3 4 5 6 7 8 9 A B C D E F G H J K L N M O P Q R S T U V W X Y Z) - def generate_invite_code - code = read_attribute(:invite_code) - if !code || code.size <5 - code = CODES.sample(5).join - return generate_invite_code if Course.where(invite_code: code).present? - update_attribute(:invite_code, code) - end - code - end - - - def generate_qrcode - ticket = self.qrcode - if !ticket || ticket.size < 10 || (Time.now.to_i > self.qrcode_expiretime) - response = Wechat.api.qrcode_create_scene(invite_code, 2592000) - logger.debug "response = #{response}" - self.qrcode = response['ticket'] - self.qrcode_expiretime = Time.now.to_i+response['expire_seconds'] - save! && reload - ticket = qrcode - end - ticket - end - - def log_infor - Rails.logger.info "##########################################################course's syllabus_id is #{self.syllabus_id}." - end - -end - - - -# Delete the previous articles index in Elasticsearch -# Course.__elasticsearch__.client.indices.delete index: Course.index_name rescue nil -# -# # Create the new index with the new mapping -# Course.__elasticsearch__.client.indices.create \ -# index: Course.index_name, -# body: { settings: Course.settings.to_hash, mappings: Course.mappings.to_hash } - -# Index all article records from the DB to Elasticsearch -#Course.where('is_public = 1').import :force=>true - - +#coding=utf-8 + +require 'elasticsearch/model' +class Course < ActiveRecord::Base + include Redmine::SafeAttributes + + include CoursesHelper + + STATUS_ACTIVE = 1 + STATUS_CLOSED = 5 + STATUS_ARCHIVED = 9 + + #elasticsearch + include Elasticsearch::Model + + #elasticsearch kaminari init + Kaminari::Hooks.init + Elasticsearch::Model::Response::Response.__send__ :include, Elasticsearch::Model::Response::Pagination::Kaminari + settings index: { number_of_shards: 5 } do + mappings dynamic: 'false' do + indexes :name, analyzer: 'smartcn',index_options: 'offsets' + indexes :description, analyzer: 'smartcn',index_options: 'offsets' + indexes :updated_at, index:"not_analyzed",type:"date" + end + end + + attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period, :open_student, :enterprise_name, :is_delete, :syllabus_id, :end_time, :end_term, :choose_group_allow, :is_end + #belongs_to :project, :class_name => 'Course', :foreign_key => :extra, primary_key: :identifier + belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id, :dependent => :destroy # 定义一个方法teacher,该方法通过tea_id来调用User表 + belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school,该方法通过school_id来调用School表 + belongs_to :syllabus + # has_many :bid + has_many :members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}" + has_many :memberships, :class_name => 'Member' + has_many :member_principals, :class_name => 'Member', + :include => :principal, + :conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE})" + has_many :principals, :through => :member_principals, :source => :principal + has_many :users, :through => :members + has_many :org_courses, :dependent => :destroy + has_many :organizations, :through => :org_courses + # has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy + has_many :journals_for_messages, :as => :jour, :dependent => :destroy + # has_many :homework_for_courses, :dependent => :destroy + has_many :student, :class_name => 'StudentsForCourse', :source => :user + has_many :course_infos, :class_name => 'CourseInfos',:dependent => :destroy + has_many :enabled_modules, :dependent => :delete_all + has_many :boards, :dependent => :destroy, :order => "position ASC" + #has_many :course_journals_for_messages, :class_name => 'CourseJournalsForMessage', :as => :jour, :dependent => :destroy + has_many :news, :dependent => :destroy, :include => :author + has_one :course_status, :class_name => "CourseStatus", :dependent => :destroy + has_many :student_work_projects, :dependent => :destroy + + has_many :homework_commons, :dependent => :destroy + has_many :student_works, :through => :homework_commons, :dependent => :destroy + + has_many :course_groups, :dependent => :destroy, :order => "name ASC" + has_many :course_homework_statisticss, :dependent => :destroy + # 课程动态 + has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy + + has_many :course_activities + # 课程消息 + has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy + has_many :exercises, :dependent => :destroy + # 课程贡献榜 + has_many :course_contributor_scores, :dependent => :destroy + + #课程模块 + has_many :course_modules, :dependent => :destroy + acts_as_taggable + acts_as_nested_set :order => 'name', :dependent => :destroy + acts_as_attachable :view_permission => :view_course_files, + :delete_permission => :manage_files + + validates_presence_of :name + #validates_format_of :class_period, :with =>/^[1-9]\d*$/ + #validates_format_of :time, :with => /^\d{4}$/ + validates_format_of :name,:with =>/^[^ ]+[a-zA-Z0-9_\u4e00-\u9fa5\s\S]*$/ + validates_length_of :description, :maximum => 10000 + + before_save :self_validate + # 公开课程变成私有课程,所有资源都变成私有 + after_update :update_files_public,:update_course_ealasticsearch_index + after_create :create_board_sync, :act_as_course_activity, :act_as_course_message,:create_course_ealasticsearch_index + before_destroy :delete_all_members,:delete_course_ealasticsearch_index + after_save :log_infor + + safe_attributes 'extra', + 'time', + 'name', + 'extra', + 'code', + 'location', + 'tea_id', + 'password', + 'term', + 'is_public', + 'description', + 'class_period', + 'open_student', + 'is_delete', + 'syllabus_id', + 'end_time', + 'end_term', + 'os_allow', + 'choose_group_allow', + 'credit' + + acts_as_customizable + + scope :not_deleted, lambda{where(is_delete: 0)} + scope :not_deleted_not_end, lambda{where(is_delete: 0, is_end: 0)} + scope :not_deleted_but_is_end, lambda{where(is_end: 1, is_delete: 0)} + scope :all_course + scope :active, lambda { where(:status => STATUS_ACTIVE) } + scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) } + scope :all_public, lambda { where(:is_public => true) } + scope :visible, lambda {|*args| where(Course.where("is_delete =?", 0).visible_condition(args.shift || User.current, *args)) } + scope :allowed_to, lambda {|*args| + user = User.current + permission = nil + if args.first.is_a?(Symbol) + permission = args.shift + else + user = args.shift + permission = args.shift + end + where(Course.allowed_to_condition(user, permission, *args)) + } + scope :like, lambda {|arg| + if arg.blank? + where(nil) + else + pattern = "%#{arg.to_s.strip.downcase}%" + where(" LOWER(name) LIKE :p ", :p => pattern) + end + } + scope :indexable,lambda { where('is_public = 1 and is_delete = 0') } + def self.search(query) + __elasticsearch__.search( + { + query: { + multi_match: { + query: query, + type:"most_fields", + operator: "or", + fields: ['name', 'description^0.5'] + } + }, + sort: { + _score:{order: "desc" }, + updated_at:{order:"desc"} + + }, + highlight: { + pre_tags: [''], + post_tags: [''], + fields: { + name: {}, + description: {} + } + } + } + ) + end + + def self.e_search(query) + __elasticsearch__.search( + { + query: { + multi_match: { + query: query, + type:"most_fields", + operator: "or", + fields: ['name', 'description^0.5'] + } + }, + sort: { + _score:{order: "desc" }, + updated_at:{order:"desc"} + + } + } + ) + end + + def delete! + update_attribute(:is_delete, true) + end + + def visible?(user=User.current) + user.allowed_to?(:view_course, self) + end + + def parent_id_changed? + false + end + + # Returns the mail adresses of users that should be always notified on project events + def recipients + notified_users.collect {|user| user.mail} + end + + # Returns the users that should be notified on project events + def notified_users + # TODO: User part should be extracted to User#notify_about? + members.select {|m| m.principal.present? && (m.mail_notification? || m.principal.mail_notification == 'all')}.collect {|m| m.principal} + end + + + # 课程的短描述信息 + def short_description(length = 255) + description.gsub(/<\/?.*?>/,"").html_safe if description + #description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description + end + + # 课程的短名称信息 + def short_name(length = 8) + name.gsub(/<\/?.*?>/,"").html_safe if name + end + + def strip_html(html) + return html if html.empty? || !html.include?('<') + output = "" + tokenizer = HTML::Tokenizer.new(html) + while token = tokenizer.next + node = HTML::Node.parse(nil, 0, 0, token, false) + output += token unless (node.kind_of? HTML::Tag) or (token =~ /^ ["#{Attachmentstype.table_name}.typeId= ?",self.attachmenttype ]) + end + + + # 获取资源后缀名列表 + def contenttypes + attachmenttypes + if @attachmenttypes.length >0 + @attachmenttypes.last().suffixArr + end + end + + def active? + self.status == STATUS_ACTIVE + end + + #课程权限判断 + def allows_to?(action) + if archived? + # No action allowed on archived projects + return false + end + unless active? || Redmine::AccessControl.read_action?(action) + # No write action allowed on closed projects + return false + end + # No action allowed on disabled modules + if action.is_a? Hash + allowed_actions.include? "#{action[:controller]}/#{action[:action]}" + else + allowed_permissions.include? action + end + end + + # 课程允许的权限集合 + def allowed_permissions + @allowed_permissions ||= begin + module_names = enabled_modules.all(:select => :name).collect {|m| m.name} + Redmine::AccessControl.modules_permissions(module_names).collect {|p| p.name} + end + end + + # 课程允许的动作集合 + def allowed_actions + @actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten + end + + # 返回用户组可以访问的课程 + def users_by_role + members.includes(:user, :roles).all.inject({}) do |h, m| + m.roles.each do |r| + h[r] ||= [] + h[r] << m.user + end + h + end + end + + #自定义验证 + def self_validate + + end + + def update_files_public + unless self.is_public? + self.attachments.each do |a| + a.update_attributes(:is_public => false) + end + end + end + + + def update_default_value + self.time = Time.now.year unless time + self.term = cur_course_term unless term + self.class_period = 10 unless class_period + end + + # 创建课程讨论区 + def create_board_sync + @board = self.boards.build + #self.name=" #{l(:label_borad_course) }" + @board.name = " #{l(:label_borad_course) }"#self.name + @board.description = self.name.to_s + @board.project_id = -1 + if @board.save + logger.debug "[Course Model] ===> #{@board.to_json}" + else + logger.error "[Course Model] ===> Auto create board when course saved, because #{@board.full_messages}" + end + end + + # 新增课程留言 + # add by nwb + def self.add_new_jour(user, notes, id, options={}) + course = Course.find(id) + if options.count == 0 + pjfm = course.journals_for_messages.build(:user_id => user.id, :notes => notes, :reply_id => 0) + else + pjfm = course.journals_for_messages.build(options) + end + pjfm.save + pjfm + end + + # 删除课程所有成员 + def delete_all_members + if self.members && self.members.count > 0 + me, mr = Member.table_name, MemberRole.table_name + connection.delete("DELETE FROM #{mr} WHERE #{mr}.member_id IN (SELECT #{me}.id FROM #{me} WHERE #{me}.course_id = #{id})") + Member.delete_all(['course_id = ?', id]) + end + end + + # 创建课程模块 + def create_course_modules + mod = self.course_modules + if mod.blank? + type = ["news", "boards", "attachment", "homework", "poll", "exercises", "statistics"] + for i in 0..6 + CourseModule.create(:course_id => self.id, :module_type => type[i], :position => i + 1, :hidden => 0 ) + end + mod = self.course_modules + end + return mod + end + + def get_endup_time + begin + end_time = Time.parse(self.endup_time) + rescue Exception => e + end_time = Time.parse("3000-01-01") + Rails.logger.error "[Error] course endup_time error. ===> #{e}" + ensure + return end_time + end + end + + def get_time + begin + time = Date.new(self.time).to_time + rescue Exception => e + time = Time.parse("3000-01-01") + Rails.logger.error "[Error] course time error. ===> #{e}" + ensure + return time + end + end + + def self.allowed_to_condition(user, permission, options={}) + perm = Redmine::AccessControl.permission(permission) + base_statement = (perm && perm.read? ? "#{Course.table_name}.status <> #{Course::STATUS_ARCHIVED}" : "#{Course.table_name}.status = #{Course::STATUS_ACTIVE}") + if perm && perm.course_module + base_statement << " AND #{Course.table_name}.id IN (SELECT em.course_id FROM #{EnabledModule.table_name} em WHERE em.name='#{perm.course_module}')" + end + + if options[:course] + course_statement = "#{Course.table_name}.id = #{options[:course].id}" + course_statement << " OR (#{Course.table_name}.lft > #{options[:course].lft} AND #{Course.table_name}.rgt < #{options[:course].rgt})" if options[:with_subcourses] + base_statement = "(#{course_statement}) AND (#{base_statement})" + end + + if user.admin? + base_statement + else + statement_by_role = {} + unless options[:member] + role = user.logged? ? Role.non_member : Role.anonymous + if role.allowed_to?(permission) + statement_by_role[role] = "#{Course.table_name}.is_public = #{connection.quoted_true}" + end + end + if user.logged? + user.courses_by_role.each do |role, courses| + if role.allowed_to?(permission) && courses.any? + statement_by_role[role] = "#{Course.table_name}.id IN (#{courses.collect(&:id).join(',')})" + end + end + end + if statement_by_role.empty? + "1=0" + else + if block_given? + statement_by_role.each do |role, statement| + if s = yield(role, user) + statement_by_role[role] = "(#{statement} AND (#{s}))" + end + end + end + "((#{base_statement}) AND (#{statement_by_role.values.join(' OR ')}))" + end + end + end + + #课程动态公共表记录 + def act_as_course_activity + self.course_acts << CourseActivity.new(:user_id => self.tea_id,:course_id => self.id) + end + + #创建课程后,给该用户发送消息 + def act_as_course_message + self.course_messages << CourseMessage.new(:user_id => self.tea_id, :course_id => self.id, :viewed => false) + end + + + #项目与课程分离后,很多课程的名称等信息为空,这些数据信息存储在项目表中!!就是数据兼容的问题 + #def name + # read_attribute('name') || Project.find_by_identifier(self.extra).try(:name) + #end + + # after_commit on: [:create] do + # __elasticsearch__.index_document + # end + # + # after_commit on: [:update] do + # __elasticsearch__.update_document + # end + # + # after_commit on: [:destroy] do + # __elasticsearch__.delete_document + # end + def create_course_ealasticsearch_index + return if Rails.env.development? + if self.is_public == 1 and self.is_delete == 0 #公开 和 没有被删除的课程才被索引 + self.__elasticsearch__.index_document + end + end + + def update_course_ealasticsearch_index + return if Rails.env.development? + if self.is_public == 1 and self.is_delete == 0 #如果是初次更新成为公开或者恢复被删除的情况,会报错,那么这条记录尚未被索引过。没有报错就是更新的其他属性 + begin + self.__elasticsearch__.update_document + rescue => e + self.__elasticsearch__.index_document + end + else #如果是更新成为私有的,那么索引就要被删除 + begin + self.__elasticsearch__.delete_document + rescue => e + + end + end + end + + def delete_course_ealasticsearch_index + return if Rails.env.development? + begin + self.__elasticsearch__.delete_document + rescue => e + + end + end + + # 延迟生成邀请码 + def invite_code + return generate_invite_code + end + + # 生成邀请码 + CODES = %W(2 3 4 5 6 7 8 9 A B C D E F G H J K L N M O P Q R S T U V W X Y Z) + def generate_invite_code + code = read_attribute(:invite_code) + if !code || code.size <5 + code = CODES.sample(5).join + return generate_invite_code if Course.where(invite_code: code).present? + update_attribute(:invite_code, code) + end + code + end + + + def generate_qrcode + ticket = self.qrcode + if !ticket || ticket.size < 10 || (Time.now.to_i > self.qrcode_expiretime) + response = Wechat.api.qrcode_create_scene(invite_code, 2592000) + logger.debug "response = #{response}" + self.qrcode = response['ticket'] + self.qrcode_expiretime = Time.now.to_i+response['expire_seconds'] + save! && reload + ticket = qrcode + end + ticket + end + + def log_infor + Rails.logger.info "##########################################################course's syllabus_id is #{self.syllabus_id}." + end + +end + + + +# Delete the previous articles index in Elasticsearch +# Course.__elasticsearch__.client.indices.delete index: Course.index_name rescue nil +# +# # Create the new index with the new mapping +# Course.__elasticsearch__.client.indices.create \ +# index: Course.index_name, +# body: { settings: Course.settings.to_hash, mappings: Course.mappings.to_hash } + +# Index all article records from the DB to Elasticsearch +#Course.where('is_public = 1').import :force=>true + + diff --git a/app/views/layouts/base_management.html.erb b/app/views/layouts/base_management.html.erb index 849d7aa30..886ffca0d 100644 --- a/app/views/layouts/base_management.html.erb +++ b/app/views/layouts/base_management.html.erb @@ -22,15 +22,41 @@

- 胡莎莎 > 班级列表 + <%= link_to User.current.show_real_name, user_path(User.current) %> > + + <% case @menu_type %> + <% when 2 %> + <%= @sub_type == 1 ? "课程列表" : "班级列表" %> + <% when 3 %> + <%= @sub_type == 1 ? "实训列表" :(@sub_type == 2? "已发布的实训":"已关闭的实训") %> + <% when 4 %> + <%= @sub_type == 1 ? "实训套件" : "已发布实训套件" %> + <% when 5 %> + 竞赛 + <% when 6 %> + <%= @sub_type == 1 ? "单位列表" :"单位部门列表" %> + <% when 7 %> + <%= @sub_type == 1 ? "用户列表" :"适用授权列表" %> + <% when 8 %> + 消息 + <% when 9 %> + 留言 + <% when 10 %> + <%= @sub_type == 1 ? "身份认证":(@sub_type == 2? "适用授权":(@sub_type == 3?"部门审批":(@sub_type == 4?"单位审批":(@sub_type == 5?"项目实训发布":"课程实训发布"))))%> + <% when 11 %> + 工程认证+ + <% when 12 %> + 其他 + <% end %> +

-
  • 课程实训+ +
  • 实训套件+ <%#= link_to "实训+", shixuns_managements_path, :class => "edu-admin-nav-a" %>
      -
    • <%= link_to "课程实训列表", class_shixuns_managements_path %>
    • -
    • <%= link_to "已发布课程实训", class_publish_shixuns_managements_path %>
    • +
    • <%= link_to "实训套件列表", class_shixuns_managements_path %>
    • +
    • <%= link_to "已发布实训套件", class_publish_shixuns_managements_path %>
  • 竞赛+
  • 单位 -
      -
    • <%= link_to "单位列表", departments_part_managements_path, :class => "edu-admin-nav-a" %>
    • -
    • <%= link_to "单位部门列表", departments_managements_path%>
    • -
    + + + +
  • -
  • 用户 +
  • 用户
    • <%= link_to "用户列表", users_managements_path %>
    • <%= link_to "试用授权列表", users_trial_managements_path %>
    • @@ -62,12 +88,12 @@
    • 消息
    • 留言
    • -
    • 审批 +
    • 审批
      • <%= link_to "身份认证", :controller => "managements", :action => "identity_authentication" %>
      • <%= link_to "试用授权", :controller => "managements", :action => "trial_authorization" %>
      • -
      • <%= link_to "部门审批", depart_managements_path %>
      • -
      • <%= link_to '单位审批', unit_managements_path %>
      • + +
      • <%= link_to '项目实训发布', shixun_authorization_managements_path %>
      • <%= link_to '课程实训发布', subject_authorization_managements_path %>
      diff --git a/app/views/managements/_class_publish_shixuns_list.html.erb b/app/views/managements/_class_publish_shixuns_list.html.erb new file mode 100644 index 000000000..1172b44a0 --- /dev/null +++ b/app/views/managements/_class_publish_shixuns_list.html.erb @@ -0,0 +1,23 @@ + + + + + + + + + + + + <% @c_shixuns.each_with_index do |c_shixun, index| %> + + + + + + + + <% end %> + + +
      ID实训套件名称单位创建者发布时间 color-light-green ml5" title="功能完善中,敬请期待">
      <%= index + 1 %><%= link_to c_shixun.name, subject_path(c_shixun) %><%= c_shixun.user.try(:user_extensions).try(:school).try(:name).blank? ? "--" : c_shixun.user.try(:user_extensions).try(:school) %><%= c_shixun.user.show_real_name %><%= format_time c_shixun.created_at %>
      diff --git a/app/views/managements/_class_shixuns_list.html.erb b/app/views/managements/_class_shixuns_list.html.erb new file mode 100644 index 000000000..bbda3dfd3 --- /dev/null +++ b/app/views/managements/_class_shixuns_list.html.erb @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + <% @c_shixuns.each_with_index do |c_shixun, index| %> + + + + + + + + + + + + <% end %> + + +
      ID实训套件名称阶段实训状态单位创建者创建时间操作
      <%= index + 1 %><%= link_to c_shixun.name, subject_path(c_shixun) %><%= c_shixun.stages.count %><%= c_shixun.stage_shixuns.count %><%= c_shixun.status == 0 ? "编辑中" : (c_shixun.status == 1 ? "审核中" : "发布") %><%= c_shixun.user.try(:user_extensions).try(:school).try(:name).blank? ? "--" : c_shixun.user.try(:user_extensions).try(:school) %><%= c_shixun.user.show_real_name %><%= format_time c_shixun.created_at %> + 删除 +
      \ No newline at end of file diff --git a/app/views/managements/_classroom_classment_list.html.erb b/app/views/managements/_classroom_classment_list.html.erb new file mode 100644 index 000000000..ed9231566 --- /dev/null +++ b/app/views/managements/_classroom_classment_list.html.erb @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + +<% @courses.each do |course| %> + + + + + + + + + + + + + + + +<% end %> + +
      ID班级名称成员资源作业试卷私有模版状态创建者单位创建者动态时间首页显示
      <%= course.id %><%= link_to(course.name, course_path(course.id)) %><%= course.members.count %><%= course.attachments.count %><%= course.homework_commons.count%><%= course.exercises.count %><%= course.is_public.to_i == 1 ? '--' : '√' %><%= course.is_end ? "已结束" : "正在进行" %><%= course.teacher.try(:user_extensions).try(:school).try(:name).blank? ? "--" : course.teacher.try(:user_extensions).try(:school) %> <%= link_to course.teacher.show_name, user_path(course.teacher) %> <%= format_time(course.updatetime) %> + + +
      +
      +
      +
        + <%= pagination_links_full @courses_pages, @courses_count, :per_page_links => false, :remote => @is_remote, :flag => true, :is_new => true %> +
      +
      +
      +
      diff --git a/app/views/managements/_classroom_list.html.erb b/app/views/managements/_classroom_list.html.erb new file mode 100644 index 000000000..8564e12e4 --- /dev/null +++ b/app/views/managements/_classroom_list.html.erb @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + <% @syllabus.each do |syllabus| %> + + + + + + + + + + + + <% end %> + +
      ID层级学科门类一级学科专业名称课程名称创建者创建于课堂模版
      <%= syllabus.id %><%= syllabus.syllabus_major_level == '' ? "--" : syllabus.syllabus_major_level %><%= syllabus.syllabus_discipline_category == '' ? "--" : syllabus.syllabus_discipline_category %><%= syllabus.syllabus_first_level_discipline == "" ? "--" : syllabus.syllabus_first_level_discipline %><%= syllabus.syllabus_major == "" ? "--" : syllabus.syllabus_major %> <%= render :partial => 'admin/rename_syllabus_title', :locals => {:syllabus => syllabus} %> <%= link_to syllabus.user.show_name, user_path(syllabus.user) %> <%= format_time(syllabus.created_at) %> + + +
      +
      +
      +
        + <%= pagination_links_full @syllabus_pages, @syllabus_count, :per_page_links => false, :remote => false, :flag => true, :is_new => true %> +
      +
      +
      +
      diff --git a/app/views/managements/_depart_list.html.erb b/app/views/managements/_depart_list.html.erb new file mode 100644 index 000000000..aed44629f --- /dev/null +++ b/app/views/managements/_depart_list.html.erb @@ -0,0 +1,44 @@ + + + + + + + + + + + + <% @apply_status.each do |apply| %> + + + + + + + + <% end %> + +
      序号部门名称单位名称创建于
      <%= apply.id %> <%= apply.name %> <%= apply.school.name %> <%= format_date(apply.created_at) %> + <%= link_to( l(:label_approve), { :controller => 'admin', :action => 'approve_applied_departments', :id => apply.id }, :class => "application-default-link" ) %> + <%= link_to( l(:button_delete), { :controller => 'admin', :action => 'delete_applied_departments', :id => apply.id, :tip => 'unapplied' },:method => :delete, :confirm => l(:text_are_you_sure), :class => "application-default-link") %> + <%=link_to '更改', admin_all_schools_path(:school_id =>apply.id), :remote => true, :class => "application-default-link" %> +
      +
      +
      +
        + <%= pagination_links_full @apply_status_pages, @apply_status_count, :per_page_links => false, :remote => false, :flag => true, :is_new => true %> +
      +
      +
      +
      + diff --git a/app/views/managements/_departments_list.html.erb b/app/views/managements/_departments_list.html.erb new file mode 100644 index 000000000..35c5fba7c --- /dev/null +++ b/app/views/managements/_departments_list.html.erb @@ -0,0 +1,42 @@ + + + + + + + + + + + + + <% @department.each do |department| %> + + + + + + + + + <% end %> + +
      序号部门名称用户数已认证职业创建于
      <%=department.id %><%=department.name %><%= UserExtensions.where(:department_id => department.id).count %>3<%= format_time department.created_at %> 修改
      +
      +
      +
        + <%= pagination_links_full @department_pages, @department_count, :per_page_links => false, :remote => false, :flag => true, :is_new => true %> +
      +
      +
      +
      + diff --git a/app/views/managements/_departments_part_list.html.erb b/app/views/managements/_departments_part_list.html.erb new file mode 100644 index 000000000..0edd89ed7 --- /dev/null +++ b/app/views/managements/_departments_part_list.html.erb @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + <% @schools.each do |schools| %> + + + + + + + + + + + + <% end %> + +
      IDLOGO单位名称地区详细地址用户数部门数创建于
      <%= schools.id %> + <%= image_tag(schools.logo_link,width:40,height:40) %> + + + + <%= link_to schools.name,"http://#{Setting.host_name}/?schools_id=#{schools.id}" %> + + <%= schools.province %><%= schools.address == nil ? "--" :schools.address %><%= UserExtensions.where(:school_id => schools.id).count %><%= schools.departments.count %><%= format_time schools.created_at %> + + <%= link_to("修改", upload_logo_school_path(schools.id,:schools_name => @schools_name), :class => 'icon icon-copy') %> +
      + +
      +
      +
        + <%= pagination_links_full @schools_pages, @schools_count, :per_page_links => false, :remote => @is_remote, :flag => true, :is_new => true %> +
      +
      +
      +
      + + diff --git a/app/views/managements/_subject_authorization_list.html.erb b/app/views/managements/_subject_authorization_list.html.erb new file mode 100644 index 000000000..403933b91 --- /dev/null +++ b/app/views/managements/_subject_authorization_list.html.erb @@ -0,0 +1,48 @@ +<% @authorizations.each do |authorization| %> +
      + <% user = authorization.user %> + <% subject = Subject.find authorization.container_id %> + + + <%= image_tag(url_to_avatar(user), :class => "fl with10 edu-ad-user", :alt => "头像", :width => "50", :height => "50" ) %> + + +
      +
        +
      • + <%= link_to user.show_real_name, user_path(user), :class => "fl" %> + 拒绝 + 同意 +
      • +
      • + <%=link_to subject.name, subject_path(subject), :target => "_blank" %> +
      • +
      • + <%= subject.stages.count %> 阶段<%= subject.stage_shixuns.count %> 实训<%= subject.subject_challenges %> 关卡 +
      • +
        +
      • + + +
      • +
      • + 确定 + 取消 +
      • +
        +
      +
      +
      +<% end %> + + \ No newline at end of file diff --git a/app/views/managements/_subject_authorization_passed_list.html.erb b/app/views/managements/_subject_authorization_passed_list.html.erb new file mode 100644 index 000000000..972bed970 --- /dev/null +++ b/app/views/managements/_subject_authorization_passed_list.html.erb @@ -0,0 +1,40 @@ +<% unless @authorizations.blank? %> +<% @authorizations.each do |authorization| %> +<% user = authorization.user %> +<% subject = Subject.find authorization.container_id %> +
      + + <%= image_tag(url_to_avatar(user), :class => "fl with10 edu-ad-user", :alt => "头像", :width => "50", :height => "50" ) %> + +
      +
        +
      • + <%= user.try(:show_name) %> + <%= time_from_now(authorization.created_at) %> + <%= authorization.status == 1 ? "已同意" : "已拒绝" %> +
      • +
      • + 课程实训名称:<%= link_to subject.name, subject_path(subject), :target => "_blank" %> +
      • +
      • + <%= subject.stages.count %> 阶段<%= subject.stage_shixuns.count %> 实训<%= subject.subject_challenges %> 关卡 +
      • + <% if authorization.status == 2 %> +
      • 原因:<%= authorization.reason.blank? ? "空" : authorization.reason %>
      • + <% end %> +
      +
      +
      +<% end %> + + + + + + + + + +<% else %> +<%= render :partial => "welcome/no_data" %> +<% end %> diff --git a/app/views/managements/_unit_list.html.erb b/app/views/managements/_unit_list.html.erb new file mode 100644 index 000000000..a98edb7d4 --- /dev/null +++ b/app/views/managements/_unit_list.html.erb @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + <% @apply_status.each do |apply| %> + + + + + + + + + + <% end %> + +
      序号单位名称地区详细地址申请者创建于
      <%= apply.id %><%= apply.name %> + + <%= (apply.province.nil? ? "" : apply.province) + (apply.city.nil? ? "" : apply.city) %> + + + + + + <%= apply.address %> + + + <% user = User.where("id=?", apply.user_id).first %> + <% unless user.nil? %> + <%=link_to user.show_name, user_path(user),:target => '_blank', :class => "application-default-link" %> + <% end %> + + <%= format_date(apply.created_at) %> + + <%= link_to( l(:label_approve), { :controller => 'admin', :action => 'approve_applied_schools', :id => apply.id }, :class => "application-default-link" ) %> + <%= link_to( l(:button_delete), { :controller => 'admin', :action => 'delete_applied_schools', :id => apply.id, :tip => 'unapplied' },:method => :delete, :confirm => l(:text_are_you_sure), :class => "application-default-link") %> + <%=link_to '更改', admin_all_schools_path(:school_id =>apply.id), :remote => true, :class => "application-default-link" %> + +
      +
      +
      +
        + <%= pagination_links_full @apply_status_pages, @apply_status_count, :per_page_links => false, :remote => false, :flag => true, :is_new => true %> +
      +
      +
      +
      + \ No newline at end of file diff --git a/app/views/managements/class_publish_shixuns.html.erb b/app/views/managements/class_publish_shixuns.html.erb index d215c35f2..aa493eb2c 100644 --- a/app/views/managements/class_publish_shixuns.html.erb +++ b/app/views/managements/class_publish_shixuns.html.erb @@ -1,43 +1,29 @@ +<%= form_tag(url_for(class_publish_shixuns_managements_path), :id => "class_publish_shixuns_search", :method => "post", :remote => true ) do %>
      - + + <% @schools.each do |school| %> + + <% end %> - + + - - 搜索 - 清除 + + 搜索 + 清除 +
      +<% end %> +
      + <%= render :partial => "managements/class_publish_shixuns_list" %>
      - - - - - - - - - - - - <% @c_shixuns.each do |c_shixun| %> - - - - - - - - <% end %> - - -
      ID课程实训名称单位创建者发布时间
      <%= c_shixun.id %><%= c_shixun.name %><%= c_shixun.user.try(:my_workplace) %><%= c_shixun.user.try(:show_name) %><%= format_time c_shixun.created_at %>
      \ No newline at end of file diff --git a/app/views/managements/class_publish_shixuns.js.erb b/app/views/managements/class_publish_shixuns.js.erb new file mode 100644 index 000000000..063b3360c --- /dev/null +++ b/app/views/managements/class_publish_shixuns.js.erb @@ -0,0 +1 @@ +$("#management_class_shixun_list").html("<%= j(render :partial => "managements/class_publish_shixuns_list") %>"); \ No newline at end of file diff --git a/app/views/managements/class_shixuns.html.erb b/app/views/managements/class_shixuns.html.erb index 39a493d4c..5de5090ea 100644 --- a/app/views/managements/class_shixuns.html.erb +++ b/app/views/managements/class_shixuns.html.erb @@ -1,58 +1,36 @@ +<%= form_tag(url_for(class_shixuns_managements_path), :id => "class_shixuns_search", :method => "post", :remote => true ) do %>
      - - - - - + + + - + + <% @schools.each do |school| %> + + <% end %> - + + - - 搜索 - 清除 + + 搜索 + 清除
      - - - - - - - - - - - - - - - - <% @c_shixuns.each do |c_shixun| %> - - - - - - - - - - - - <% end %> - - -
      ID课程实训名称阶段实训状态单位创建者创建时间操作
      1<%= c_shixun.name %><%= c_shixun.stages.count %><%= c_shixun.stage_shixuns.count %><%= c_shixun.status == 0 ? "编辑中" : (c_shixun.status == 1 ? "审核中" : "发布") %><%= c_shixun.user.try(:my_workplace) %><%= c_shixun.user.try(:show_name) %><%= format_time c_shixun.created_at %>删除
      +
      + <%= render :partial => "managements/class_shixuns_list" %> +
      +<% end%> \ No newline at end of file diff --git a/app/views/managements/class_shixuns.js.erb b/app/views/managements/class_shixuns.js.erb new file mode 100644 index 000000000..9c46f911f --- /dev/null +++ b/app/views/managements/class_shixuns.js.erb @@ -0,0 +1 @@ +$("#managements_class_shixuns_list").html("<%= j(render :partial => "managements/class_shixuns_list") %>"); \ No newline at end of file diff --git a/app/views/managements/classroom.html.erb b/app/views/managements/classroom.html.erb index 2566e0bd8..bdbd11dd8 100644 --- a/app/views/managements/classroom.html.erb +++ b/app/views/managements/classroom.html.erb @@ -1,88 +1,28 @@ +<%= form_tag(url_for(classroom_managements_path),:id=>"classroom",:method => "post",:remote=>true) do %>
      - + + <%= @schools.each do |school|%> + + <% end%> - - - - - + + - 搜索 + 搜索 清除 - -
      - - - - - - - - - - - - - - - - <% @syllabus.each do |syllabus| %> - - - - - - - - - - - - <% end %> - -
      ID层级学科门类一级学科专业名称课程名称创建者创建于课堂模版
      <%= syllabus.id %><%= syllabus.syllabus_major_level == '' ? "--" : syllabus.syllabus_major_level %><%= syllabus.syllabus_discipline_category == '' ? "--" : syllabus.syllabus_discipline_category %><%= syllabus.syllabus_first_level_discipline == "" ? "--" : syllabus.syllabus_first_level_discipline %><%= syllabus.syllabus_major == "" ? "--" : syllabus.syllabus_major %> <%= render :partial => 'admin/rename_syllabus_title', :locals => {:syllabus => syllabus} %> <%= link_to syllabus.user.show_name, user_path(syllabus.user) %> <%= format_time(syllabus.created_at) %> - - -
      -
      -
      -
        - <%= pagination_links_full @syllabus_pages, @syllabus_count, :per_page_links => false, :remote => false, :flag => true, :is_new => true %> -
      -
      -
      +<% end %> +
      + <%= render :partial => "managements/classroom_list" %> +
      \ No newline at end of file diff --git a/app/views/managements/classroom.js.erb b/app/views/managements/classroom.js.erb new file mode 100644 index 000000000..1fdcabff4 --- /dev/null +++ b/app/views/managements/classroom.js.erb @@ -0,0 +1 @@ +$("#classroom_list").html("<%= j(render :partial => "managements/classroom_list") %>") \ No newline at end of file diff --git a/app/views/managements/classroom_classment.erb b/app/views/managements/classroom_classment.erb deleted file mode 100644 index 95567a06e..000000000 --- a/app/views/managements/classroom_classment.erb +++ /dev/null @@ -1,74 +0,0 @@ -
      - - - - - 搜索 - 清除 - - - - -
      - - - - - - - - - - - - - - - - - - - - <% @courses.each do |syllabus| %> - - - - - - - - - - - - - - - - <% end %> - -
      ID班级名称成员资源作业试卷私有模版状态创建者单位创建者动态时间首页显示
      <%= syllabus.id %><%= link_to(syllabus.name, course_path(syllabus.id)) %><%= studentCount(syllabus) %><%= syllabus.boards.first.topics.count + Message.where("board_id =? and parent_id is not ?", syllabus.boards.first.id, nil).count %><%= syllabus.homework_commons.count%><%= @obj_count%>正在进行国防科技大学 <%= link_to syllabus.teacher.show_name, user_path(syllabus.teacher) %> <%= format_time(syllabus.created_at) %> - - -
      -
      -
      -
        - <%= pagination_links_full @course_pages, @course_count, :per_page_links => false, :remote => false, :flag => true, :is_new => true %> -
      -
      -
      -
      - diff --git a/app/views/managements/classroom_classment.html.erb b/app/views/managements/classroom_classment.html.erb new file mode 100644 index 000000000..1d1dbb815 --- /dev/null +++ b/app/views/managements/classroom_classment.html.erb @@ -0,0 +1,37 @@ +<%= form_tag(url_for(classroom_classment_managements_path), :id => "class_publish_shixuns_search", :method => "post", :remote => true ) do %> +
      + + + + + 搜索 + 清除 + + + + +
      +<% end%> +
      + <%= render :partial => "managements/classroom_classment_list" %> +
      + \ No newline at end of file diff --git a/app/views/managements/classroom_classment.js.erb b/app/views/managements/classroom_classment.js.erb new file mode 100644 index 000000000..de9e9f519 --- /dev/null +++ b/app/views/managements/classroom_classment.js.erb @@ -0,0 +1 @@ +$("#managements_classroom_classment").html("<%= j(render :partial => "managements/classroom_classment_list") %>"); diff --git a/app/views/managements/deal_subject_authorization.js.erb b/app/views/managements/deal_subject_authorization.js.erb new file mode 100644 index 000000000..d41167a91 --- /dev/null +++ b/app/views/managements/deal_subject_authorization.js.erb @@ -0,0 +1 @@ +$("#subject_authentication_list").html("<%= j( render :partial => "managements/subject_authorization_list" ) %>"); \ No newline at end of file diff --git a/app/views/managements/delete_subject.js.erb b/app/views/managements/delete_subject.js.erb new file mode 100644 index 000000000..7bb230009 --- /dev/null +++ b/app/views/managements/delete_subject.js.erb @@ -0,0 +1 @@ +$("#subject_shixun_<%= @subject.id %>").remove(); \ No newline at end of file diff --git a/app/views/managements/depart.html.erb b/app/views/managements/depart.html.erb index 8cbe7eaeb..f2cd9251b 100644 --- a/app/views/managements/depart.html.erb +++ b/app/views/managements/depart.html.erb @@ -1,77 +1,37 @@ -
      +<%= form_tag(url_for(depart_managements_path), :id => "depart_search", :method => "post", :remote => true ) do %> +
      - 搜索 + 搜索 清除 - - + + + + + + + + + + + + + + + + + + + + + + + + + + +
      - - - - - - - - - - - -<% @apply_status.each do |apply| %> - - - - - - - -<% end %> - -
      序号部门名称单位名称创建于
      <%= apply.id %> <%= apply.name %> <%= apply.school.name %> <%= format_date(apply.created_at) %> - <%= link_to( l(:label_approve), { :controller => 'admin', :action => 'approve_applied_departments', :id => apply.id }, :class => "application-default-link" ) %> - <%= link_to( l(:button_delete), { :controller => 'admin', :action => 'delete_applied_departments', :id => apply.id, :tip => 'unapplied' },:method => :delete, :confirm => l(:text_are_you_sure), :class => "application-default-link") %> - <%=link_to '更改', admin_all_schools_path(:school_id =>apply.id), :remote => true, :class => "application-default-link" %> -
      -
      -
      -
        - <%= pagination_links_full @apply_status_pages, @apply_status_count, :per_page_links => false, :remote => false, :flag => true, :is_new => true %> -
      -
      -
      +<% end%> +
      + <%= render :partial => "managements/depart_list" %>
      - diff --git a/app/views/managements/depart.js.erb b/app/views/managements/depart.js.erb new file mode 100644 index 000000000..6a05cf4b8 --- /dev/null +++ b/app/views/managements/depart.js.erb @@ -0,0 +1 @@ +$("#managements_user_list").html("<%= j( render :partial => "managements/depart_list" ) %>"); \ No newline at end of file diff --git a/app/views/managements/departments.html.erb b/app/views/managements/departments.html.erb index e07eb4402..24562720e 100644 --- a/app/views/managements/departments.html.erb +++ b/app/views/managements/departments.html.erb @@ -1,6 +1,9 @@ +<%= form_tag(url_for(departments_managements_path),:id=>"department_search",:method => "post",:remote=>true) do %>
      - 创建 + 搜索 + 清除 + 创建
      - - - - - - - - - - - - - <% @department.each do |department| %> - - - - - - - - - <% end %> - -
      序号部门名称用户数已认证职业创建于
      <%=department.id %><%=department.name %><%= UserExtensions.where(:school_id => department.id).count %>3<%= format_time department.created_at %> 修改
      - +<% end %> +
      + <%= render :partial => "managements/departments_list" %> +
      \ No newline at end of file diff --git a/app/views/managements/departments.js.erb b/app/views/managements/departments.js.erb new file mode 100644 index 000000000..0d1bdb45c --- /dev/null +++ b/app/views/managements/departments.js.erb @@ -0,0 +1 @@ +$("#managements_departments_list").html("<%= j( render :partial => "managements/departments_list" ) %>") \ No newline at end of file diff --git a/app/views/managements/departments_part.html.erb b/app/views/managements/departments_part.html.erb index 4ce6085b9..b26407a55 100644 --- a/app/views/managements/departments_part.html.erb +++ b/app/views/managements/departments_part.html.erb @@ -1,6 +1,9 @@ +<%= form_tag(url_for(departments_part_managements_path),:id=>"department_part_search",:method => "post",:remote=>true) do %>
      - 新建单位 + 搜索 + 清除 + 新建单位
      - - - - - - - - - - - - - - - - <% @schools.each do |schools| %> - - - - - - - - - - - - - <% end %> - -
      IDLOGO单位名称地区详细地址用户数部门数创建于
      <%= schools.id %> - <%= image_tag(schools.logo_link,width:40,height:40) %> - - - - <%= link_to schools.name,"http://#{Setting.host_name}/?schools_id=#{schools.id}" %> - - <%= schools.province %><%= schools.address == nil ? "--" :schools.address %><%= UserExtensions.where(:school_id => schools.id).count %><%= schools.departments.count %><%= format_time schools.created_at %> - - <%= link_to("修改", upload_logo_school_path(schools.id,:schools_name => @schools_name), :class => 'icon icon-copy') %> -
      -
      -
      -
        - <%= pagination_links_full @schools_pages, @schools_count, :per_page_links => false, :remote => false, :flag => true, :is_new => true %> -
      -
      -
      -
      - - +<% end %> +
      + <%= render :partial => "managements/departments_part_list" %> +
      \ No newline at end of file diff --git a/app/views/managements/departments_part.js.erb b/app/views/managements/departments_part.js.erb new file mode 100644 index 000000000..d1ba0d02f --- /dev/null +++ b/app/views/managements/departments_part.js.erb @@ -0,0 +1 @@ +$("#managements_department_part_list").html("<%= j( render :partial => "managements/departments_part_list" ) %>") \ No newline at end of file diff --git a/app/views/managements/identity_authentication.html.erb b/app/views/managements/identity_authentication.html.erb index 44736dd36..2bacddd95 100644 --- a/app/views/managements/identity_authentication.html.erb +++ b/app/views/managements/identity_authentication.html.erb @@ -1,8 +1,20 @@
      -
      -

      身份认证

      -
      -
      + + + + + + + + + + + + + +
      + +
      • @@ -45,6 +57,51 @@
      + +
      +
      +
        +
      • + <%= link_to "待审批" %> +
      • +
      • + <%= link_to "已审批" %> +
      • +
      +
      +
      +
      +
      + + +
      +
      +
      + +
      +
      +
      + +
      +
      +

      + 全部 + 同意 + 拒绝 +

      +
      + + +
      +
      + + +
      +
      +
      +
      +
      +
      @@ -132,5 +189,10 @@ data: { name: iName, type: type} }); }); - +// 身份认证和职业认证 + $("#edu-tab-nav-auth li").click(function(){ + var index=$(this).index(); + $("#edu-tab-nav-auth li").eq(index).addClass("edu-new-tab-hover").siblings().removeClass("edu-new-tab-hover"); + $(".authentization").eq(index).removeClass("undis").siblings().addClass("undis"); + }) \ No newline at end of file diff --git a/app/views/managements/subject_authorization.html.erb b/app/views/managements/subject_authorization.html.erb index 979885c26..b04eda5b3 100644 --- a/app/views/managements/subject_authorization.html.erb +++ b/app/views/managements/subject_authorization.html.erb @@ -17,40 +17,8 @@
      -
      - <% @subject.each do |subject| %> -
      - <% user = subject.user %> - <%= image_tag(url_to_avatar(user),:class => "fl with10 edu-ad-user", :alt => "头像", :width => "50", :height => "50" ) %> - -
      -
        -
      • - <%= link_to user.show_real_nam, user_path(user), :class => "fl" %> - 拒绝 - 同意 -
      • -
      • - :<%=link_to subject.name, subject_path(subject), :target => "_blank" %> -
      • -
      • - <%= subject.stages.count %> 阶段<%= subject.stage_shixuns.count %> 实训<%= subject.subject_challenges %> 关卡 -
      • -
        -
      • - - -
      • -
      • - 确定 - 取消 -
      • -
        -
      -
      -
      - - <% end %> +
      + <%= render :partial => "managements/subject_authorization_list" %>
      @@ -65,28 +33,8 @@
      -
      - - 头像 - - -
      - - -
      -
      +
      @@ -94,9 +42,26 @@
  • \ No newline at end of file diff --git a/app/views/managements/subject_authorization.js.erb b/app/views/managements/subject_authorization.js.erb index 7d355cd92..92167b545 100644 --- a/app/views/managements/subject_authorization.js.erb +++ b/app/views/managements/subject_authorization.js.erb @@ -5,13 +5,13 @@ var nTabNav_2 = $("#edu-tab-nav-2"); var nAudit = $("#subject_all_authentication").parent(); <% if @type == 0 %> -$("#authentication_list").html("<%= j( render :partial => "managements/shixun_authorization_list" ) %>"); +$("#subject_authentication_list").html("<%= j( render :partial => "managements/subject_authorization_list" ) %>"); nTabNav_1.addClass("edu-new-tab-hover"); nTabNav_2.removeClass("edu-new-tab-hover"); nTabIcon_1.show(); nTabIcon_2.hide(); <% else %> -$("#shixun_authentication_list").html("<%= j( render :partial => "managements/shixun_authorization_passed_list" ) %>"); +$("#subject_authorization_list").html("<%= j( render :partial => "managements/subject_authorization_passed_list" ) %>"); nTabNav_1.removeClass("edu-new-tab-hover"); nTabNav_2.addClass("edu-new-tab-hover"); nTabIcon_1.hide(); diff --git a/app/views/managements/unit.html.erb b/app/views/managements/unit.html.erb index 5e1cc4bd2..0320255a9 100644 --- a/app/views/managements/unit.html.erb +++ b/app/views/managements/unit.html.erb @@ -1,137 +1,11 @@ +<%= form_tag(url_for(unit_managements_path), :id => "unit", :method => "post", :remote => true ) do %>
    - - 搜索 + + 搜索 清除 - - +
    +<% end%> +
    + <%= render :partial => "managements/unit_list" %>
    - - - - - - - - - - - - - - - <% @apply_status.each do |apply| %> - - - - - - - - - - <% end %> - -
    序号单位名称地区详细地址申请者创建于
    <%= apply.id %><%= apply.name %> - - <%= (apply.province.nil? ? "" : apply.province) + (apply.city.nil? ? "" : apply.city) %> - - - - - - <%= apply.address %> - - - <% user = User.where("id=?", apply.user_id).first %> - <% unless user.nil? %> - <%=link_to user.show_name, user_path(user),:target => '_blank', :class => "application-default-link" %> - <% end %> - - <%= format_date(apply.created_at) %> - - <%= link_to( l(:label_approve), { :controller => 'admin', :action => 'approve_applied_schools', :id => apply.id }, :class => "application-default-link" ) %> - <%= link_to( l(:button_delete), { :controller => 'admin', :action => 'delete_applied_schools', :id => apply.id, :tip => 'unapplied' },:method => :delete, :confirm => l(:text_are_you_sure), :class => "application-default-link") %> - <%=link_to '更改', admin_all_schools_path(:school_id =>apply.id), :remote => true, :class => "application-default-link" %> - -
    -
    -
    -
      - <%= pagination_links_full @apply_status_pages, @apply_status_count, :per_page_links => false, :remote => false, :flag => true, :is_new => true %> -
    -
    -
    -
    - \ No newline at end of file diff --git a/app/views/managements/unit.js.erb b/app/views/managements/unit.js.erb new file mode 100644 index 000000000..bf34606df --- /dev/null +++ b/app/views/managements/unit.js.erb @@ -0,0 +1 @@ +$("#managements_unit_list").html("<%= j(render :partial => "managements/unit_list") %>"); \ No newline at end of file diff --git a/app/views/managements/users.html.erb b/app/views/managements/users.html.erb index 0062fa0d4..506df5b60 100644 --- a/app/views/managements/users.html.erb +++ b/app/views/managements/users.html.erb @@ -1,32 +1,32 @@ -
    - <%= form_tag(url_for(users_managements_path), :id => "managements_users_search", :method => "post", :remote => true) do %> -
    -

    全部状态

    - -
      -
    • 全部状态
    • -
    • 活动的(<%= query_user_status_num 1 %>)
    • -
    • 未激活(<%= query_user_status_num 2 %>)
    • -
    • 已锁定(<%= query_user_status_num 3 %>)
    • -
    -
    -
    -

    真实姓名搜索

    - -
      -
    • 真实姓名搜索
    • -
    • 邮箱地址搜索
    • -
    • 手机号码搜索
    • -
    -
    -
    - - 搜索 - 清除 -
    - - <% end %> -
    -
    - <%= render :partial => "managements/user_list" %> +
    + <%= form_tag(url_for(users_managements_path), :id => "managements_users_search", :method => "post", :remote => true) do %> +
    +

    全部状态

    + +
      +
    • 全部状态
    • +
    • 活动的(<%= query_user_status_num 1 %>)
    • +
    • 未激活(<%= query_user_status_num 2 %>)
    • +
    • 已锁定(<%= query_user_status_num 3 %>)
    • +
    +
    +
    +

    真实姓名搜索

    + +
      +
    • 真实姓名搜索
    • +
    • 邮箱地址搜索
    • +
    • 手机号码搜索
    • +
    +
    +
    + + 搜索 + 清除 +
    + + <% end %> +
    +
    + <%= render :partial => "managements/user_list" %>
    \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 4dcd2a279..a1e1e43e9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -154,7 +154,17 @@ RedmineApp::Application.routes.draw do get 'approve' get 'trial_authorization', :as => 'trial_authorization' get 'shixun_authorization' + get 'subject_authorization' + match 'classroom', :via => [:get, :post] + match 'departments', :via => [:get, :post] + match 'departments_part', :via => [:get, :post] + match 'depart', :via => [:get, :post] + match 'unit', :via => [:get, :post] + match 'classroom_classment', :via => [:get, :post] + match 'class_shixuns', :via => [:get, :post] + match 'class_publish_shixuns', :via => [:get, :post] get 'deal_shixun_authorization' + get 'deal_subject_authorization' get 'batch_authorization', :as => 'batch_authorization' match 'search_user', :via => [:get, :post] match 'affirm_cancel_auth', :via => [:get, :post] @@ -167,6 +177,7 @@ RedmineApp::Application.routes.draw do match 'users_authorization_agree' match 'users_authorization_cancel' get 'update_webssh' + get 'delete_subject' end end # Enable Grack support diff --git a/public/javascripts/edu/base_edu.js b/public/javascripts/edu/base_edu.js index a9ea17630..2ad86cdd2 100644 --- a/public/javascripts/edu/base_edu.js +++ b/public/javascripts/edu/base_edu.js @@ -7,6 +7,8 @@ $(function(){ success: function(data){ if (data.result == 1){ $("#discipline_category_id").html(""); + $("#first_level_discipline_id").html(""); + $("#major_id").html(""); for(var i=0; i" + data.options[i][0] + ""); } @@ -27,6 +29,7 @@ $(function(){ success: function(data){ if (data.result == 1){ $("#first_level_discipline_id").html(""); + $("#major_id").html(""); for(var i=0; i" + data.options[i][0] + ""); } diff --git a/public/stylesheets/css/edu-public.css b/public/stylesheets/css/edu-public.css index 8a495ed90..dc95eab46 100644 --- a/public/stylesheets/css/edu-public.css +++ b/public/stylesheets/css/edu-public.css @@ -29,7 +29,7 @@ select.header-search-select{ border:none; font-size:14px; padding:5px; backgroun .task-user-dropdown-nav li:hover{ background:#eee;} .task-line{ display: block; height: 1px!important; line-height: 1px!important; border-bottom:1px solid #eee; margin:0;} .inner-nav-user:hover .task-user-dropdown{ display:block;} -dropdown{display: inline-block; height:30px; line-height:1.9; font-size:12px; } +dropdown { display: inline-block; height:30px; line-height:1.9; font-size:12px; } dropdown label, dropdown ul li{ display: block; width:42px; padding:4px 10px; text-align: center;border-radius:3px; color:#666;} dropdown ul li:hover{background: #eee; color:#666;cursor: pointer;} dropdown label{color: #666;border-radius: 3px 0 0 3px; position: relative; z-index: 2; width:50px; text-align: center; height:22px;} @@ -260,8 +260,8 @@ img.edu-nodata-img{ width:200px; margin:50px auto 20px; display: block;} /* new tab */ .edu-tab{ width: 100%; background:#fff;} -#edu-tab-nav{height:47px;background: #fff; border-bottom:2px solid #5faee3;} -#edu-tab-nav li.new-tab-nav {float:left; width: 150px; text-align:center;height:48px;line-height:48px; } +#edu-tab-nav,#edu-tab-nav-auth{height:47px;background: #fff; border-bottom:2px solid #5faee3;} +#edu-tab-nav li.new-tab-nav,#edu-tab-nav-auth li.new-tab-nav {float:left; width: 150px; text-align:center;height:48px;line-height:48px; } #edu-tab-nav li a{font-size:14px; } #edu-user-tab-nav{height:47px;background: #f5f5f5; border-bottom:2px solid #FF6610;} #edu-user-tab-nav li.new-tab-nav {float:left; width: 150px; text-align:center;height:48px;line-height:48px; }