diff --git a/.gitignore b/.gitignore
index bb4b68554..1b56839ee 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,39 +1,39 @@
-*.swp
-/.project
-/.idea
-/.bundle
-*.swp
-/config/database.yml
-/config/configuration.yml
-/config/additional_environment.rb
-/config/oneapm.yml
-/config/environments/production.rb
-
-
-/files/*
-/log/*
-/public/tmp/*
-/tmp/*
-/public/cache/*
-/config/newrelic.yml
-/public/images/avatars/*
-/db/schema.rb
-/Gemfile.lock
-/lib/plugins/acts_as_versioned/test/debug.log
-.rbenv-gemsets
-.DS_Store
-public/api_doc/
-/.metadata
-vendor/cache
-/files
-/public/images/avatars
-/public/files
-/tags
-/config/initializers/gitlab_config.rb
-1234567
-public/javascripts/wechat/node_modules/
-.ruby-version
-.access_token
-tmux*.log
-config/wechat.yml
-config/oneapm.yml
+*.swp
+/.project
+/.idea/*
+/.bundle
+*.swp
+/config/database.yml
+/config/configuration.yml
+/config/additional_environment.rb
+/config/oneapm.yml
+/config/environments/production.rb
+
+
+/files/*
+/log/*
+/public/tmp/*
+/tmp/*
+/public/cache/*
+/config/newrelic.yml
+/public/images/avatars/*
+/db/schema.rb
+/Gemfile.lock
+/lib/plugins/acts_as_versioned/test/debug.log
+.rbenv-gemsets
+.DS_Store
+public/api_doc/
+/.metadata
+vendor/cache
+/files
+/public/images/avatars
+/public/files
+/tags
+/config/initializers/gitlab_config.rb
+1234567
+public/javascripts/wechat/node_modules/
+.ruby-version
+.access_token
+tmux*.log
+config/wechat.yml
+config/oneapm.yml
diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb
index 400fad766..0015c0a8d 100644
--- a/app/controllers/managements_controller.rb
+++ b/app/controllers/managements_controller.rb
@@ -1,393 +1,715 @@
-# encoding: utf-8
-class ManagementsController < ApplicationController
- before_filter :require_admin
- layout 'base_management'
- include ManagementsHelper
- include SortHelper
- include UsersHelper
- include ApplicationHelper
-
- # 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] # 排序关键字
- 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
- else
- @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
- else
- @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.html
- end
- end
-
- def shixuns
- @menu_type = 3
- sx_status = params[:status].blank? ? [0, 1, 2, 3] : params[:status].to_i # 搜索实训的状态
- keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/实训名搜索
- search = params[:search] # 搜索的字
- @sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order] # 排序
- if "u_name" == keyword
- # 如果用户搜索为空,不用遍历user表,直接查找所有实训, 有搜索时才查找user
- if search.blank?
- @shixuns = Shixun.where(:status => sx_status).order("created_at #{@sx_order}")
- else
- user_id = User.where("concat(lastname, firstname) like '%#{search}%'")
- @shixuns = Shixun.where(:user_id => user_id, :status => sx_status).order("created_at #{@sx_order}")
- end
- else
- @shixuns = Shixun.where("name like '%#{search}%'").where(:status => sx_status).order("created_at #{@sx_order}")
- end
- @edit_sx_num = Shixun.where(:status => 0).count
- @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
- @offset ||= @shixuns_pages.offset
- @shixuns = paginateHelper @shixuns, limit
- respond_to do |format|
- format.js
- format.html
- end
- end
-
- # 已发布的实训
- def publish_shixuns
- @menu_type = 3
- @sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order] # 排序
- search = params[:search] # 搜索字
- keyword = params[:keyword].blank? ? "u_name" : params[:keyword] # 根据姓名/实训名搜索
- close = params[:close] # 关闭实训,参数是实训的Id
- unless close.blank?
- Shixun.find(close).update_attribute(:status, 3)
- end
- if "u_name" == keyword
- # 如果用户搜索为空,不用遍历user表,直接查找所有实训, 有搜索时才查找user
- if search.blank?
- @shixuns = Shixun.where(:status => 2).order("created_at #{@sx_order}")
- else
- user_id = User.where("concat(lastname, firstname) like '%#{search}%'")
- @shixuns = Shixun.where(:user_id => user_id, :status => 2).order("created_at #{@sx_order}")
- end
- else
- @shixuns = Shixun.where("name like '%#{search}%'").where(:status => 2).order("created_at #{@sx_order}")
- end
- @shixuns_count = @shixuns.count
- limit = 20
- @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
- end
- end
-
- # 已关闭的实训
- def close_shixuns
- @menu_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
- if "u_name" == keyword
- # 如果用户搜索为空,不用遍历user表,直接查找所有实训, 有搜索时才查找user
- if search.blank?
- @shixuns = Shixun.where(:status => 3).order("updated_at #{@sx_order}")
- else
- user_id = User.where("concat(lastname, firstname) like '%#{search}%'")
- @shixuns = Shixun.where(:user_id => user_id, :status => 3).order("updated_at #{@sx_order}")
- end
- else
- @shixuns = Shixun.where("name like '%#{search}%'").where(:status => 3).order("updated_at #{@sx_order}")
- end
- @shixuns_count = @shixuns.count
- limit = 20
- @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
- end
- end
-
- def users_trial
- @menu_type = 6
- @users = User.where(:status => 1).order("created_on desc").all
- @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
-
- end
-
- def search_user
-
-=begin
- auth = ApplyUserAuthentication.where(:status => params[:authentication])
- auth_id = auth.blank? ? User.where(:status => 1).id : "(" + auth.map{|a| a.user_id }.join(",") + ")"
-=end
-
- if params[:member_ids] && params[:trial_whether] == "trial_agree"
- params[:member_ids].each do |member|
- aUser = ApplyAction.where(:user_id => member, :container_type => "TrialAuthorization")
- if aUser.blank?
- ApplyAction.create(:user_id => member, :container_type => "TrialAuthorization", :status => 1)
- else
- aUser.update_all(:status => 1)
- end
- end
- elsif params[:member_ids] && params[:trial_whether] == "trial_cancel"
- ApplyAction.where(:user_id => params[:member_ids], :container_type => "TrialAuthorization").update_all(:status => 2)
- end
-
- if params[:member_ids] && (params[:occupation] == "occupation_agree" || params[:realname] == "realname_agree")
- User.where(:id => params[:member_ids]).update_all(:authentication => true)
- elsif params[:member_ids] && (params[:occupation] == "occupation_agree" || params[:realname] == "realname_cancel")
- User.where(:id => params[:member_ids]).update_all(:authentication => false)
- end
-
- if params[:trial] == "-1"
- apply = ApplyAction.where(:container_type => "TrialAuthorization")
- apply_id = apply.blank? ? -1 : "(" + apply.map{|a| a.user_id}.join(",") + ")"
- apply_user_id = User.where("id not in #{apply_id} and status = 1").all
- apply_user_id = apply_user_id.blank? ? [-1] : apply_user_id.map{|a| a.id}.split(",")[0]
- elsif params[:trial] == "-2"
- apply_user_id = User.where(:status => 1).all
- apply_user_id = apply_user_id.blank? ? [-1] : apply_user_id.map{|a| a.id}.split(",")[0]
- else
- apply = ApplyAction.where(:status => params[:trial])
- apply_user_id = apply.blank? ? [-1] : apply.map{|a| a.user_id}.split(",")[0]
- end
-
- if params[:school] == ""
- s_user_id = User.where(:status => 1).all
- s_user_id = s_user_id.blank? ? [-1] : s_user_id.map{|s| s.id}.split(",")[0]
- else
- school = School.where("name like '%#{params[:school]}%'")
- school_id = school.blank? ? -1 : school.map{|s| s.id }.split(",")[0]
- usr = UserExtensions.where(:school_id => school_id)
- s_user_id = usr.blank? ? [-1] : usr.map{|u| u.user_id}.split(",")[0]
- end
-
- if params[:department] == ""
- d_user_id = User.where(:status => 1).all
- d_user_id = d_user_id.blank? ? [-1] : d_user_id.map{|d| d.id}.split(",")[0]
- else
- department = Department.where("name like '%#{params[:department]}%'").all
- dep_id = department.blank? ? -1 : department.map{|d| d.id}.split(",")
- usr = UserExtensions.where(:department_id => dep_id)
- d_user_id = usr.blank? ? [-1] : usr.map{|u| u.user_id}.split(",")[0]
- end
-
- user_id = s_user_id & d_user_id & apply_user_id
-
- if params[:research_condition] == "name"
- @users = User.where(:id => user_id).where("concat(lastname, firstname) like '%#{params[:research_contents]}%'").order("created_on desc")
- elsif params[:research_condition] == "email"
- @users = User.where(:id => user_id).where("mail like '%#{params[:research_contents]}%'").order("created_on desc")
- elsif params[:research_condition] == "phone"
- if params[:research_contents].blank?
- @users = User.where(:id => user_id).order("created_on desc")
- else
- @users = User.where(:id => user_id).where("phone like '%#{params[:research_contents]}%'").order("created_on desc")
- 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
- end
- end
-
- def update_webssh
- webssh = params[:status] == "true" ? true : false
- @shixuns = Shixun.find(params[:shixun_id])
- @shixuns.update_column(:webssh, webssh)
- respond_to do |format|
- format.js
- end
- end
-
- def affirm_cancel_auth
- user_id = params[:users]
- end
-
-
- def trial_authorization
- @menu_type = 9
- search = params[:search]
- @status = trial_authorization_status(params[:status])
- # @status = (params[:status].blank? || params[:status] == "0") ? 0 : [1,2]
- if search.blank?
- @authorizations = ApplyAction.where(:container_type => "TrialAuthorization", :status => @status).includes(:user)
- else
- user_id = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{search}%'")
- @authorizations = ApplyAction.where(:container_type => "TrialAuthorization", :status => @status, :user_id => user_id).includes(:user)
- end
-
- @autu_count = @authorizations.count
- @limit = 15
- @is_remote = true
- @autu_pages = Paginator.new @autu_count, @limit, params['page'] || 1
- @offset ||= @autu_pages.offset
- @authorizations = paginateHelper @authorizations, @limit
-
- end
-
- # 批量授权
- def batch_authorization
-
- end
-
- # params[:type] 1:拒绝 0:同意
- # authentication 会有一个初始值,不同的值代表不同的权限
- # REDO: 后面权限改了后,一并要改
- def trial_authorization_operation
- apply_action = ApplyAction.find(params[:apply_id])
- type = params[:type]
- search = params[:search]
- if type == "0"
- authentication_user = AuthenticationsUsers.where(:user_id => apply_action.user_id).first
- if authentication_user.blank?
- AuthenticationsUsers.create(:user_id => apply_action.user_id, :authentication_id => 1)
- end
- end
- apply_action.update_attributes(:status => (params[:type] == "1" ? 2 : 1), :reason => params[:reject_reason], :dealer_id => User.current.id)
- user_id = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{search}%'")
- @authorizations = ApplyAction.where(:container_type => "TrialAuthorization", :status => 0, :user_id => user_id).includes(:user)
- @autu_count = @authorizations.count
- @limit = 15
- @is_remote = true
- @autu_pages = Paginator.new @autu_count, @limit, params['page'] || 1
- @offset ||= @autu_pages.offset
- @authorizations = paginateHelper @authorizations, @limit
- respond_to do |format|
- format.js
- end
- end
-
- def index
-
- end
-
- # copy from admin
- def identity_authentication
- @menu_type = 9
- @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]}%'")
- @unapproved_user = ApplyUserAuthentication.where(:status => @type, :user_id => user_id).order("updated_at desc")
- respond_to do |format|
- format.html
- format.js
- end
- end
-
- # 拒绝身份认证
- # copy from admin
- def reject_authentication
- apply_user = ApplyUserAuthentication.find(params[:apply_id])
- reason = apply_user.update_attributes(:status => 2, :remarks => params[:reject_reason])
- render :json => {success: reason}
- end
-
- # 统一身份认证
- # copy from admin
- def agree_authentication
- apply_user = ApplyUserAuthentication.find(params[:apply_id])
- user = User.find(apply_user.user_id)
- apply_user.update_attribute(:status, 1)
- user.update_attribute(:authentication, true)
- @unapproved_user = ApplyUserAuthentication.where(:status => 0).order("updated_at desc")
- respond_to do |format|
- format.js
- end
- end
-
- def shixun_authorization
- @type = trial_authorization_status params[:type]
- @authorizations = ApplyAction.where(:container_type => "ApplyShixun", :status => @type).order("created_at desc")
- search = params[:search]
- unless search.blank?
- @authorizations = @authorizations.where(:container_id => Shixun.where(:id => @authorizations.map(&:container_id)).where("name like '%#{search}%'").map(&:id)).order("created_at desc")
- end
-
- @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
- end
- end
-
- def deal_shixun_authorization
- apply_action = ApplyAction.find(params[:apply_id])
- type = params[:type].to_i
- shixun = Shixun.find apply_action.container_id
- if type == 0
- shixun.update_column('status', 0)
- apply_action.update_attributes(:status => 2, :reason => params[:reject_reason], :dealer_id => User.current.id)
- notes = "您所在团队提交的项目实训发布申请:#{shixun.name},审核未通过。
原因:#{params[:reject_reason]}"
- shixun.shixun_members.each do |member|
- JournalsForMessage.create(:jour_id => member.user_id, :jour_type => 'Principal', :user_id => User.current.id, :notes => notes, :private => 1, :reply_id => 0)
- end
- else
- shixun.update_column('status', 2)
- apply_action.update_attributes(:status => 1, :dealer_id => User.current.id)
- shixun_modify_status_without_publish shixun, 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
- end
-end
+# encoding: utf-8
+class ManagementsController < ApplicationController
+ before_filter :require_admin
+ layout 'base_management'
+ include ManagementsHelper
+ include SortHelper
+ include UsersHelper
+ include ApplicationHelper
+ # 单位部门列表
+ def departments
+ @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
+ @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
+
+ respond_to do |format|
+ format.js
+ format.html
+ end
+ end
+
+ # 部门审核
+ def depart
+ @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
+ @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
+ @apply_status = paginateHelper @apply_status, limit
+
+ respond_to do |format|
+ format.js
+ format.html
+ end
+ end
+
+ # 课堂列表
+ def classroom
+ @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")
+ @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
+ @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
+ @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
+ @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
+ @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
+ else
+ @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
+ else
+ @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.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] # 搜索的字
+ @sx_order = params[:sx_order].blank? ? "desc" : params[:sx_order] # 排序
+ if "u_name" == keyword
+ # 如果用户搜索为空,不用遍历user表,直接查找所有实训, 有搜索时才查找user
+ if search.blank?
+ @shixuns = Shixun.where(:status => sx_status).order("created_at #{@sx_order}")
+ else
+ user_id = User.where("concat(lastname, firstname) like '%#{search}%'")
+ @shixuns = Shixun.where(:user_id => user_id, :status => sx_status).order("created_at #{@sx_order}")
+ end
+ else
+ @shixuns = Shixun.where("name like '%#{search}%'").where(:status => sx_status).order("created_at #{@sx_order}")
+ end
+ @edit_sx_num = Shixun.where(:status => 0).count
+ @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
+ @offset ||= @shixuns_pages.offset
+ @shixuns = paginateHelper @shixuns, limit
+ respond_to do |format|
+ format.js
+ format.html
+ end
+ end
+
+ # 已发布的实训
+ 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] # 根据姓名/实训名搜索
+ close = params[:close] # 关闭实训,参数是实训的Id
+ unless close.blank?
+ Shixun.find(close).update_attribute(:status, 3)
+ end
+ if "u_name" == keyword
+ # 如果用户搜索为空,不用遍历user表,直接查找所有实训, 有搜索时才查找user
+ if search.blank?
+ @shixuns = Shixun.where(:status => 2).order("created_at #{@sx_order}")
+ else
+ user_id = User.where("concat(lastname, firstname) like '%#{search}%'")
+ @shixuns = Shixun.where(:user_id => user_id, :status => 2).order("created_at #{@sx_order}")
+ end
+ else
+ @shixuns = Shixun.where("name like '%#{search}%'").where(:status => 2).order("created_at #{@sx_order}")
+ end
+ @shixuns_count = @shixuns.count
+ limit = 20
+ @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
+ end
+ end
+
+ # 已关闭的实训
+ 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
+ if "u_name" == keyword
+ # 如果用户搜索为空,不用遍历user表,直接查找所有实训, 有搜索时才查找user
+ if search.blank?
+ @shixuns = Shixun.where(:status => 3).order("updated_at #{@sx_order}")
+ else
+ user_id = User.where("concat(lastname, firstname) like '%#{search}%'")
+ @shixuns = Shixun.where(:user_id => user_id, :status => 3).order("updated_at #{@sx_order}")
+ end
+ else
+ @shixuns = Shixun.where("name like '%#{search}%'").where(:status => 3).order("updated_at #{@sx_order}")
+ end
+ @shixuns_count = @shixuns.count
+ limit = 20
+ @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
+ end
+ end
+
+ def users_trial
+ @menu_type = 7
+ @sub_type = 2
+ @users = User.where(:status => 1).order("created_on desc").all
+ @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
+ end
+
+ def search_user
+
+=begin
+ auth = ApplyUserAuthentication.where(:status => params[:authentication])
+ auth_id = auth.blank? ? User.where(:status => 1).id : "(" + auth.map{|a| a.user_id }.join(",") + ")"
+=end
+
+ if params[:member_ids] && params[:trial_whether] == "trial_agree"
+ params[:member_ids].each do |member|
+ aUser = ApplyAction.where(:user_id => member, :container_type => "TrialAuthorization")
+ if aUser.blank?
+ ApplyAction.create(:user_id => member, :container_type => "TrialAuthorization", :status => 1)
+ else
+ aUser.update_all(:status => 1)
+ end
+ end
+ elsif params[:member_ids] && params[:trial_whether] == "trial_cancel"
+ ApplyAction.where(:user_id => params[:member_ids], :container_type => "TrialAuthorization").update_all(:status => 2)
+ end
+
+ if params[:member_ids] && (params[:occupation] == "occupation_agree" || params[:realname] == "realname_agree")
+ User.where(:id => params[:member_ids]).update_all(:authentication => true)
+ elsif params[:member_ids] && (params[:occupation] == "occupation_agree" || params[:realname] == "realname_cancel")
+ User.where(:id => params[:member_ids]).update_all(:authentication => false)
+ end
+
+ if params[:trial] == "-1"
+ apply = ApplyAction.where(:container_type => "TrialAuthorization")
+ apply_id = apply.blank? ? -1 : "(" + apply.map{|a| a.user_id}.join(",") + ")"
+ apply_user_id = User.where("id not in #{apply_id} and status = 1").all
+ apply_user_id = apply_user_id.blank? ? [-1] : apply_user_id.map{|a| a.id}.split(",")[0]
+ elsif params[:trial] == "-2"
+ apply_user_id = User.where(:status => 1).all
+ apply_user_id = apply_user_id.blank? ? [-1] : apply_user_id.map{|a| a.id}.split(",")[0]
+ else
+ apply = ApplyAction.where(:status => params[:trial])
+ apply_user_id = apply.blank? ? [-1] : apply.map{|a| a.user_id}.split(",")[0]
+ end
+
+ if params[:school] == ""
+ s_user_id = User.where(:status => 1).all
+ s_user_id = s_user_id.blank? ? [-1] : s_user_id.map{|s| s.id}.split(",")[0]
+ else
+ school = School.where("name like '%#{params[:school]}%'")
+ school_id = school.blank? ? -1 : school.map{|s| s.id }.split(",")[0]
+ usr = UserExtensions.where(:school_id => school_id)
+ s_user_id = usr.blank? ? [-1] : usr.map{|u| u.user_id}.split(",")[0]
+ end
+
+ if params[:department] == ""
+ d_user_id = User.where(:status => 1).all
+ d_user_id = d_user_id.blank? ? [-1] : d_user_id.map{|d| d.id}.split(",")[0]
+ else
+ department = Department.where("name like '%#{params[:department]}%'").all
+ dep_id = department.blank? ? -1 : department.map{|d| d.id}.split(",")
+ usr = UserExtensions.where(:department_id => dep_id)
+ d_user_id = usr.blank? ? [-1] : usr.map{|u| u.user_id}.split(",")[0]
+ end
+
+ user_id = s_user_id & d_user_id & apply_user_id
+
+ if params[:research_condition] == "name"
+ @users = User.where(:id => user_id).where("concat(lastname, firstname) like '%#{params[:research_contents]}%'").order("created_on desc")
+ elsif params[:research_condition] == "email"
+ @users = User.where(:id => user_id).where("mail like '%#{params[:research_contents]}%'").order("created_on desc")
+ elsif params[:research_condition] == "phone"
+ if params[:research_contents].blank?
+ @users = User.where(:id => user_id).order("created_on desc")
+ else
+ @users = User.where(:id => user_id).where("phone like '%#{params[:research_contents]}%'").order("created_on desc")
+ 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
+ end
+ end
+
+ def update_webssh
+ webssh = params[:status] == "true" ? true : false
+ @shixuns = Shixun.find(params[:shixun_id])
+ @shixuns.update_column(:webssh, webssh)
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def affirm_cancel_auth
+ user_id = params[:users]
+ end
+
+
+ def trial_authorization
+ @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]
+ if search.blank?
+ @authorizations = ApplyAction.where(:container_type => "TrialAuthorization", :status => @status).includes(:user)
+ else
+ user_id = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{search}%'")
+ @authorizations = ApplyAction.where(:container_type => "TrialAuthorization", :status => @status, :user_id => user_id).includes(:user)
+ end
+
+ @autu_count = @authorizations.count
+ @limit = 15
+ @is_remote = true
+ @autu_pages = Paginator.new @autu_count, @limit, params['page'] || 1
+ @offset ||= @autu_pages.offset
+ @authorizations = paginateHelper @authorizations, @limit
+
+ end
+
+ # 批量授权
+ def batch_authorization
+
+ end
+
+ # params[:type] 1:拒绝 0:同意
+ # authentication 会有一个初始值,不同的值代表不同的权限
+ # REDO: 后面权限改了后,一并要改
+ def trial_authorization_operation
+ apply_action = ApplyAction.find(params[:apply_id])
+ type = params[:type]
+ search = params[:search]
+ if type == "0"
+ authentication_user = AuthenticationsUsers.where(:user_id => apply_action.user_id).first
+ if authentication_user.blank?
+ AuthenticationsUsers.create(:user_id => apply_action.user_id, :authentication_id => 1)
+ end
+ end
+ apply_action.update_attributes(:status => (params[:type] == "1" ? 2 : 1), :reason => params[:reject_reason], :dealer_id => User.current.id)
+ user_id = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{search}%'")
+ @authorizations = ApplyAction.where(:container_type => "TrialAuthorization", :status => 0, :user_id => user_id).includes(:user)
+ @autu_count = @authorizations.count
+ @limit = 15
+ @is_remote = true
+ @autu_pages = Paginator.new @autu_count, @limit, params['page'] || 1
+ @offset ||= @autu_pages.offset
+ @authorizations = paginateHelper @authorizations, @limit
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def index
+
+ end
+
+ # copy from admin
+ def identity_authentication
+ @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]}%'")
+ @unapproved_user = ApplyUserAuthentication.where(:status => @type, :user_id => user_id).order("updated_at desc")
+ respond_to do |format|
+ format.html
+ format.js
+ end
+ end
+
+ # 拒绝身份认证
+ # copy from admin
+ def reject_authentication
+ apply_user = ApplyUserAuthentication.find(params[:apply_id])
+ reason = apply_user.update_attributes(:status => 2, :remarks => params[:reject_reason])
+ render :json => {success: reason}
+ end
+
+ # 统一身份认证
+ # copy from admin
+ def agree_authentication
+ apply_user = ApplyUserAuthentication.find(params[:apply_id])
+ user = User.find(apply_user.user_id)
+ apply_user.update_attribute(:status, 1)
+ user.update_attribute(:authentication, true)
+ @unapproved_user = ApplyUserAuthentication.where(:status => 0).order("updated_at desc")
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def subject_authorization
+ @menu_type = 10
+ @sub_type == 6
+ @type = trial_authorization_status params[:type]
+ @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
+ end
+ 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]
+ unless search.blank?
+ @authorizations = @authorizations.where(:container_id => Shixun.where(:id => @authorizations.map(&:container_id)).where("name like '%#{search}%'").map(&:id)).order("created_at desc")
+ end
+
+ @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
+ end
+ end
+ # 课程实训发布审批
+ def deal_subject_authorization
+ apply_action = ApplyAction.find(params[:apply_id])
+ type = params[:type].to_i
+ 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]}"
+ 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)
+ 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
+ apply_action = ApplyAction.find(params[:apply_id])
+ type = params[:type].to_i
+ shixun = Shixun.find apply_action.container_id
+ if type == 0 #拒绝
+ shixun.update_column('status', 0)
+ apply_action.update_attributes(:status => 2, :reason => params[:reject_reason], :dealer_id => User.current.id)
+ notes = "您所在团队提交的项目实训发布申请:#{shixun.name},审核未通过。
原因:#{params[:reject_reason]}"
+ shixun.shixun_members.each do |member|
+ JournalsForMessage.create(:jour_id => member.user_id, :jour_type => 'Principal', :user_id => User.current.id, :notes => notes, :private => 1, :reply_id => 0)
+ end
+ else #同意
+ shixun.update_column('status', 2)
+ apply_action.update_attributes(:status => 1, :dealer_id => User.current.id)
+ shixun_modify_status_without_publish shixun, 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
+ end
+end
diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb
index d75511204..1f72f00e0 100644
--- a/app/controllers/subjects_controller.rb
+++ b/app/controllers/subjects_controller.rb
@@ -42,6 +42,17 @@ class SubjectsController < ApplicationController
redirect_to subject_path(subject)
end
+ def edit
+ render :layout => "base_edu"
+ end
+
+ def update
+ if params[:subject]
+ subject = @subject.update_attributes(:name => params[:subject][:name], :description => params[:subject][:description])
+ end
+ redirect_to subject_path(@subject)
+ end
+
def update_attr
if params[:name]
@subject.update_attributes(:name => params[:name])
@@ -88,7 +99,6 @@ class SubjectsController < ApplicationController
end
def publish
- @subject.update_attributes(:status => 1)
apply = ApplyAction.where(:container_type => "ApplySubject", :container_id => @subject.id).order("created_at desc").first
if apply && apply.status == 0
@status = 0
@@ -96,6 +106,7 @@ class SubjectsController < ApplicationController
if Shixun.where(:id => @subject.stage_shixuns.map(&:shixun_id), :status => [0, 1]).count > 0
@status = 2
else
+ @subject.update_attributes(:status => 1)
ApplyAction.create(:container_type => "ApplySubject", :container_id => @subject.id, :user_id => User.current.id, :status => 0)
notes = User.current.show_name.to_s + " 申请发布课程实训:#{@subject.name}"
JournalsForMessage.create(:jour_id => 1, :jour_type => 'Principal', :user_id => User.current.id, :notes => notes, :private => 1, :reply_id => 0)
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 29fbf65f0..b2327fc2c 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -225,6 +225,10 @@ module ApplicationHelper
myshixun = Myshixun.where(:shixun_id => shixun.id, :user_id => user.id).first
if myshixun.nil?
0
+ elsif !myshixun.nil? && myshixun.games.select{|game| game.status == 2}.count == 0
+ -1
+ elsif myshixun.games.select{|game| game.status == 0}.count > 0
+ [myshixun.games.select{|game| game.status == 0}.count + 1]
else
myshixun.games.select{|game| game.status == 2}.count
end
@@ -1972,8 +1976,7 @@ module ApplicationHelper
title << @user.show_name
end
elsif @syllabus
- title << (@syllabus.title.nil? ? "在线课堂" : @syllabus.title)
- else
+ title << (@syllabus.title.nil? ? "在线课堂" : @syllabus.title) else
title << (User.current.id == 2 ? "未登录" : User.current.try(:realname))
end
# if first_page.nil? || first_page.web_title.nil?
@@ -5191,3 +5194,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/models/school.rb b/app/models/school.rb
index 81e1743b2..63d180e9f 100644
--- a/app/models/school.rb
+++ b/app/models/school.rb
@@ -1,10 +1,10 @@
-class School < ActiveRecord::Base
- attr_accessible :name, :province,:pinyin
- has_many :courses
- has_many :departments, :dependent => :destroy
-
- def to_s
- self.name.to_s
- end
-
-end
+class School < ActiveRecord::Base
+ default_scope :order => 'created_at desc'
+ attr_accessible :name, :province,:pinyin
+ has_many :courses
+ has_many :departments, :dependent => :destroy
+
+ def to_s
+ self.name.to_s
+ end
+end
diff --git a/app/models/syllabus.rb b/app/models/syllabus.rb
index f1d9cb34e..e893d9791 100644
--- a/app/models/syllabus.rb
+++ b/app/models/syllabus.rb
@@ -1,161 +1,165 @@
-# encoding: utf-8
-class Syllabus < ActiveRecord::Base
- include Redmine::SafeAttributes
- include ApplicationHelper
- #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 :title, analyzer: 'smartcn',index_options: 'offsets'
- indexes :description, analyzer: 'smartcn',index_options: 'offsets'
- indexes :updated_at, index:"not_analyzed", type:'date'
- end
- end
- acts_as_taggable
- acts_as_attachable
- has_many_kindeditor_assets :assets, :dependent => :destroy
-
- belongs_to :user
- has_many :courses
- has_many :homework_banks
- has_many :reference_materials, :dependent => :destroy
- has_many :syllabus_update_records, :dependent => :destroy
- has_many :journals_for_messages, :as => :jour, :dependent => :destroy
- has_many :syllabus_members, :dependent => :destroy
- has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
- has_one :praise_tread_cache, as: :object, dependent: :destroy
- belongs_to :discipline_category
- belongs_to :first_level_discipline
- belongs_to :major
- attr_accessible :description, :user_id, :title, :eng_name, :syllabus_type, :credit, :hours, :theory_hours, :practice_hours, :applicable_major, :pre_course, :major_level, :discipline_category_id, :first_level_discipline_id, :major_id
- safe_attributes 'title','user', 'description', 'eng_name', 'syllabus_type', 'credit', 'hours', 'theory_hours', 'practice_hours', 'credit', 'applicable_major', 'pre_course', 'major_level', 'discipline_category_id', "first_level_discipline_id"
-
- validates :title, :user_id, presence: true
-
- after_update :update_syllabus_ealasticsearch_index
- after_create :create_syllabus_ealasticsearch_index
- before_destroy :delete_syllabus_ealasticsearch_index
-
- scope :indexable,lambda { where(nil) }#用于elastic建索引的scope
-
- scope :like, lambda {|arg|
- if arg.blank?
- where(nil)
- else
- pattern = "%#{arg.to_s.strip.downcase}%"
- where(" LOWER(title) LIKE :p ", :p => pattern)
- end
- }
-
- def delete_kindeditor_assets
- delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::SYLLABUS
- end
-
- def syllabus_major_level
- type = ""
- case self.major_level
- when 1
- type = "研究生"
- when 2
- type = "本科"
- when 3
- type = "专科"
- end
- type
- end
-
- def syllabus_type_str
- type = ""
- case self.syllabus_type
- when 1
- type = "公共必修课"
- when 2
- type = "学科必修课"
- when 3
- type = "专业选修课"
- when 4
- type = "实践必修课"
- when 5
- type = "实践选修课"
- end
- type
- end
-
- def syllabus_discipline_category
- self.discipline_category ? self.discipline_category.name : ''
- end
-
- def syllabus_first_level_discipline
- self.first_level_discipline ? self.first_level_discipline.name : ''
- end
-
- def syllabus_major
- self.major ? self.major.name : ''
- end
-
- ###添加回复
- def self.add_syllabus_jour(user, notes, id, root_id, options = {})
- syllabus = Syllabus.find(id)
- if options.count == 0
- jfm = syllabus.journals_for_messages.build(:user_id => user.id, :notes => notes, :reply_id => 0, :root_id => root_id)
- else
- jfm = syllabus.journals_for_messages.build(options)
- end
- jfm.save
- jfm
- end
-
- def create_syllabus_ealasticsearch_index
- return if Rails.env.development?
- self.__elasticsearch__.index_document
- end
-
- def update_syllabus_ealasticsearch_index
- return if Rails.env.development?
- begin
- self.__elasticsearch__.update_document
- rescue => e
- self.__elasticsearch__.index_document
- end
- end
-
- def delete_syllabus_ealasticsearch_index
- return if Rails.env.development?
- begin
- self.__elasticsearch__.delete_document
- rescue => e
-
- end
- end
-
- def self.search(query)
- __elasticsearch__.search(
- {
- query: {
- multi_match: {
- query: query,
- type:"most_fields",
- operator: "or",
- fields: ['title']
- }
- },
- sort: {
- _score:{order: "desc" },
- updated_at:{order:"desc"}
-
- },
- highlight: {
- pre_tags: [''],
- post_tags: [''],
- fields: {
- title: {},
- description: {}
- }
- }
- }
- )
- end
-end
+# encoding: utf-8
+class Syllabus < ActiveRecord::Base
+ include Redmine::SafeAttributes
+ include ApplicationHelper
+ #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 :title, analyzer: 'smartcn',index_options: 'offsets'
+ indexes :description, analyzer: 'smartcn',index_options: 'offsets'
+ indexes :updated_at, index:"not_analyzed", type:'date'
+ end
+ end
+ acts_as_taggable
+ acts_as_attachable
+ has_many_kindeditor_assets :assets, :dependent => :destroy
+
+ belongs_to :user
+ has_many :courses
+ has_many :homework_banks
+ has_many :reference_materials, :dependent => :destroy
+ has_many :syllabus_update_records, :dependent => :destroy
+ has_many :journals_for_messages, :as => :jour, :dependent => :destroy
+ has_many :syllabus_members, :dependent => :destroy
+ has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
+ has_one :praise_tread_cache, as: :object, dependent: :destroy
+ belongs_to :discipline_category
+ belongs_to :first_level_discipline
+ belongs_to :major
+ attr_accessible :description, :user_id, :title, :eng_name, :syllabus_type, :credit, :hours, :theory_hours, :practice_hours, :applicable_major, :pre_course, :major_level, :discipline_category_id, :first_level_discipline_id, :major_id
+ safe_attributes 'title','user', 'description', 'eng_name', 'syllabus_type', 'credit', 'hours', 'theory_hours', 'practice_hours', 'credit', 'applicable_major', 'pre_course', 'major_level', 'discipline_category_id', "first_level_discipline_id"
+
+ validates :title, :user_id, presence: true
+
+ after_update :update_syllabus_ealasticsearch_index
+ after_create :create_syllabus_ealasticsearch_index
+ before_destroy :delete_syllabus_ealasticsearch_index
+
+ scope :indexable,lambda { where(nil) }#用于elastic建索引的scope
+
+ scope :like, lambda {|arg|
+ if arg.blank?
+ where(nil)
+ else
+ pattern = "%#{arg.to_s.strip.downcase}%"
+ where(" LOWER(title) LIKE :p ", :p => pattern)
+ end
+ }
+
+ def delete_kindeditor_assets
+ delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::SYLLABUS
+ end
+
+ # 课程层级
+ def syllabus_major_level
+ type = ""
+ case self.major_level
+ when 1
+ type = "研究生"
+ when 2
+ type = "本科"
+ when 3
+ type = "专科"
+ end
+ type
+ end
+
+ def syllabus_type_str
+ type = ""
+ case self.syllabus_type
+ when 1
+ type = "公共必修课"
+ when 2
+ type = "学科必修课"
+ when 3
+ type = "专业选修课"
+ when 4
+ type = "实践必修课"
+ when 5
+ type = "实践选修课"
+ end
+ type
+ end
+
+ # 课程的学科门类
+ def syllabus_discipline_category
+ self.discipline_category ? self.discipline_category.name : ''
+ end
+
+ # 课程的一级学科
+ def syllabus_first_level_discipline
+ self.first_level_discipline ? self.first_level_discipline.name : ''
+ end
+
+ # 课程的专业
+ def syllabus_major
+ self.major ? self.major.name : ''
+ end
+
+ ###添加回复
+ def self.add_syllabus_jour(user, notes, id, root_id, options = {})
+ syllabus = Syllabus.find(id)
+ if options.count == 0
+ jfm = syllabus.journals_for_messages.build(:user_id => user.id, :notes => notes, :reply_id => 0, :root_id => root_id)
+ else
+ jfm = syllabus.journals_for_messages.build(options)
+ end
+ jfm.save
+ jfm
+ end
+
+ def create_syllabus_ealasticsearch_index
+ return if Rails.env.development?
+ self.__elasticsearch__.index_document
+ end
+
+ def update_syllabus_ealasticsearch_index
+ return if Rails.env.development?
+ begin
+ self.__elasticsearch__.update_document
+ rescue => e
+ self.__elasticsearch__.index_document
+ end
+ end
+
+ def delete_syllabus_ealasticsearch_index
+ return if Rails.env.development?
+ begin
+ self.__elasticsearch__.delete_document
+ rescue => e
+
+ end
+ end
+
+ def self.search(query)
+ __elasticsearch__.search(
+ {
+ query: {
+ multi_match: {
+ query: query,
+ type:"most_fields",
+ operator: "or",
+ fields: ['title']
+ }
+ },
+ sort: {
+ _score:{order: "desc" },
+ updated_at:{order:"desc"}
+
+ },
+ highlight: {
+ pre_tags: [''],
+ post_tags: [''],
+ fields: {
+ title: {},
+ description: {}
+ }
+ }
+ }
+ )
+ end
+end
diff --git a/app/views/admin/projects.html.erb b/app/views/admin/projects.html.erb
index e7d796e6f..ed173930a 100644
--- a/app/views/admin/projects.html.erb
+++ b/app/views/admin/projects.html.erb
@@ -1,92 +1,92 @@
-
| - 序号 - | -- <%=l(:label_project)%> - | -- <%=l(:field_is_public)%> - | -- <%=l(:field_created_on)%> - | -- |
|---|---|---|---|---|
| - <%= project.id %> - | - -- <%= checked_image project.is_public? %> - | -- <%= format_date(project.created_on) %> - | -- <%= link_to(l(:button_archive), { :controller => 'projects', :action => 'archive', :id => project, :status => params[:status] }, :data => {:confirm => l(:text_are_you_sure)}, :method => :post, :class => 'icon icon-lock') unless project.archived? %> - <%= link_to(l(:button_unarchive), { :controller => 'projects', :action => 'unarchive', :id => project, :status => params[:status] }, :method => :post, :class => 'icon icon-unlock') if project.archived? && (project.parent.nil? || !project.parent.archived?) %> - <%= link_to(l(:button_delete), project_path(project), :method => :delete, :class => 'icon icon-del', :onClick=>"delcfm()" ) %> - | -