Merge branch 'dev_daiao' of https://bdgit.trustie.net/hushasha/bigdata into dev_daiao
This commit is contained in:
commit
349f2c5a7e
|
|
@ -77,6 +77,8 @@
|
|||
<RAILS_SERVER_CONFIG_SETTINGS_ID NAME="RAILS_SERVER_TYPE" VALUE="Default" />
|
||||
<RAILS_SERVER_CONFIG_SETTINGS_ID NAME="ENVIRONMENT_TYPE" VALUE="production" />
|
||||
<RAILS_SERVER_CONFIG_SETTINGS_ID NAME="LAUNCH_JS" VALUE="false" />
|
||||
<RunnerSettings RunnerId="RubyDebugRunner" />
|
||||
<ConfigurationWrapper RunnerId="RubyDebugRunner" />
|
||||
<method />
|
||||
</configuration>
|
||||
<configuration default="false" name="Development: bigdate" type="RailsRunConfigurationType" factoryName="Rails">
|
||||
|
|
@ -100,7 +102,9 @@
|
|||
<RAILS_SERVER_CONFIG_SETTINGS_ID NAME="ENVIRONMENT_TYPE" VALUE="development" />
|
||||
<RAILS_SERVER_CONFIG_SETTINGS_ID NAME="LAUNCH_JS" VALUE="false" />
|
||||
<RunnerSettings RunnerId="RubyDebugRunner" />
|
||||
<RunnerSettings RunnerId="RubyRunner" />
|
||||
<ConfigurationWrapper RunnerId="RubyDebugRunner" />
|
||||
<ConfigurationWrapper RunnerId="RubyRunner" />
|
||||
<method />
|
||||
</configuration>
|
||||
</component>
|
||||
|
|
@ -196,6 +200,7 @@
|
|||
<orderEntry type="library" scope="PROVIDED" name="delayed_job (v4.0.6, ruby-1.9.3-p484) [gem]" level="application" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="delayed_job_active_record (v4.0.3, ruby-1.9.3-p484) [gem]" level="application" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="descendants_tracker (v0.0.4, ruby-1.9.3-p484) [gem]" level="application" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.2.5, ruby-1.9.3-p484) [gem]" level="application" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="domain_name (v0.5.24, ruby-1.9.3-p484) [gem]" level="application" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="elasticsearch (v1.0.14, ruby-1.9.3-p484) [gem]" level="application" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="elasticsearch-api (v1.0.14, ruby-1.9.3-p484) [gem]" level="application" />
|
||||
|
|
@ -256,6 +261,11 @@
|
|||
<orderEntry type="library" scope="PROVIDED" name="redis-store (v1.1.4, ruby-1.9.3-p484) [gem]" level="application" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="rest-client (v1.8.0, ruby-1.9.3-p484) [gem]" level="application" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="rich (v1.4.6, ruby-1.9.3-p484) [gem]" level="application" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.2.3, ruby-1.9.3-p484) [gem]" level="application" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.2.1, ruby-1.9.3-p484) [gem]" level="application" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.2.1, ruby-1.9.3-p484) [gem]" level="application" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="rspec-rails (v3.2.1, ruby-1.9.3-p484) [gem]" level="application" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.2.2, ruby-1.9.3-p484) [gem]" level="application" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="ruby-ole (v1.2.11.8, ruby-1.9.3-p484) [gem]" level="application" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="ruby-openid (v2.1.8, ruby-1.9.3-p484) [gem]" level="application" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="rubyzip (v1.1.7, ruby-1.9.3-p484) [gem]" level="application" />
|
||||
|
|
|
|||
|
|
@ -28,25 +28,25 @@
|
|||
<data-source source="LOCAL" name="Rails bigdata: production" uuid="a2967bb5-941b-447d-ba0e-5e62ade5fb7d">
|
||||
<driver-ref>mysql</driver-ref>
|
||||
<jdbc-driver>com.mysql.jdbc.Driver</jdbc-driver>
|
||||
<jdbc-url>jdbc:mysql://127.0.0.1/trustie2</jdbc-url>
|
||||
<jdbc-url>jdbc:mysql://127.0.0.1/0604new</jdbc-url>
|
||||
<user-name>root</user-name>
|
||||
<user-password>df9bdf98df99df9edf9fdf9c</user-password>
|
||||
<user-password>df9bdf98df99df9e</user-password>
|
||||
<libraries />
|
||||
</data-source>
|
||||
<data-source source="LOCAL" name="Rails bigdata: development" uuid="ea7cc5a3-1ef5-4a23-93bb-2c9650c10d07">
|
||||
<driver-ref>mysql</driver-ref>
|
||||
<jdbc-driver>com.mysql.jdbc.Driver</jdbc-driver>
|
||||
<jdbc-url>jdbc:mysql://127.0.0.1/trustie2</jdbc-url>
|
||||
<jdbc-url>jdbc:mysql://127.0.0.1/20161227data</jdbc-url>
|
||||
<user-name>root</user-name>
|
||||
<user-password>df9bdf98df99df9edf9fdf9c</user-password>
|
||||
<user-password>df9bdf98df99df9e</user-password>
|
||||
<libraries />
|
||||
</data-source>
|
||||
<data-source source="LOCAL" name="Rails bigdata: test" uuid="9f93a163-6133-42ac-a16d-9bd67f458fd6">
|
||||
<driver-ref>mysql</driver-ref>
|
||||
<jdbc-driver>com.mysql.jdbc.Driver</jdbc-driver>
|
||||
<jdbc-url>jdbc:mysql://127.0.0.1/trustie2</jdbc-url>
|
||||
<jdbc-url>jdbc:mysql://127.0.0.1/0623newblank</jdbc-url>
|
||||
<user-name>root</user-name>
|
||||
<user-password>df9bdf98df99df9edf9fdf9c</user-password>
|
||||
<user-password>df9bdf98df99df9e</user-password>
|
||||
<libraries />
|
||||
</data-source>
|
||||
</component>
|
||||
|
|
|
|||
2
Gemfile
2
Gemfile
|
|
@ -75,7 +75,7 @@ group :development, :test do
|
|||
gem 'pry-byebug'
|
||||
gem "test-unit", "~>3.0"
|
||||
end
|
||||
# gem 'rspec-rails', '~> 3.0'
|
||||
gem 'rspec-rails', '~> 3.0'
|
||||
gem 'factory_girl_rails'
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the discusses controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the HomeworkBank controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the management controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the managements controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the stages controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the subjects controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
@ -22,6 +22,7 @@ class AccountController < ApplicationController
|
|||
|
||||
# prevents login action to be filtered by check_if_login_required application scope filter
|
||||
skip_before_filter :check_if_login_required
|
||||
skip_before_filter :check_authentication, :only => [:login, :logout, :user_join, :avatar, :authentication, :security_settings, :change_psd]
|
||||
before_filter :auth_login1, :only => [:avatar, :authentication, :security_settings, :change_psd]
|
||||
|
||||
before_filter :require_login, only: [:avatar, :authentication, :security_settings, :change_psd, :user_auth]
|
||||
|
|
@ -47,7 +48,7 @@ class AccountController < ApplicationController
|
|||
redirect_to user_path(User.current)
|
||||
end
|
||||
else
|
||||
render :layout => 'login_bigdata'
|
||||
render :layout => 'login_bigdata'
|
||||
end
|
||||
else
|
||||
authenticate_user
|
||||
|
|
@ -83,7 +84,7 @@ class AccountController < ApplicationController
|
|||
|
||||
# 服务协议
|
||||
def agreement
|
||||
render :layout => 'static_base'
|
||||
render :layout => 'base_edu'
|
||||
end
|
||||
|
||||
def about_us
|
||||
|
|
@ -405,7 +406,7 @@ class AccountController < ApplicationController
|
|||
user = User.current
|
||||
token = Token.new(:user => user, :action => "bind")
|
||||
if token.save
|
||||
Mailer.run.bind_email(token, verification_code)
|
||||
Mailer.run.bind_email(token, verification_code, params[:value])
|
||||
VerificationCode.create(:email => params[:value], :status => 1, :code_type => 5, :code => verification_code)
|
||||
end
|
||||
rescue => e
|
||||
|
|
@ -451,6 +452,16 @@ class AccountController < ApplicationController
|
|||
render :layout => 'base_edu_account'
|
||||
end
|
||||
|
||||
def apply_trail
|
||||
apply_action = ApplyAction.where(:user_id => User.current.id, :container_type => "TrialAuthorization", :status => 0).first
|
||||
if apply_action.blank?
|
||||
ApplyAction.create(:user_id => User.current.id, :status => 0, :container_type => "TrialAuthorization")
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def user_auth
|
||||
@user = User.current
|
||||
diskfile1 = disk_auth_filename('UserAuthentication', @user.id, 'ID')
|
||||
|
|
@ -483,6 +494,15 @@ class AccountController < ApplicationController
|
|||
render :layout => 'base_edu_account'
|
||||
end
|
||||
|
||||
# 修改密码时判断密码是否输入正确
|
||||
def valid_psd
|
||||
@user = User.current
|
||||
req = Hash.new(false)
|
||||
req[:valid] = false
|
||||
req[:valid] = @user.check_password?(params[:value])
|
||||
render :json => req
|
||||
end
|
||||
|
||||
def change_or_bind
|
||||
@user = User.current
|
||||
@type = params[:type]
|
||||
|
|
|
|||
|
|
@ -939,6 +939,39 @@ class AdminController < ApplicationController
|
|||
|
||||
end
|
||||
|
||||
# 身份认证
|
||||
def identity_authentication
|
||||
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{ render :layout => 'base_edu' }
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
# 拒绝身份认证
|
||||
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
|
||||
|
||||
# 统一身份认证
|
||||
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 create_version
|
||||
@versions = PhoneAppVersion.reorder('created_at desc')
|
||||
@new_version = PhoneAppVersion.new
|
||||
|
|
|
|||
|
|
@ -60,6 +60,20 @@ class ApplicationController < ActionController::Base
|
|||
logger.info "HTTP_USER_AGENT #{request.env["HTTP_USER_AGENT"]}"
|
||||
end
|
||||
|
||||
# 判断用户是否认证
|
||||
# def check_authentication
|
||||
# # return true
|
||||
# if params[:action] == "on_search" || params[:action] == "apply_trail" # 之所以这样处理是为了避开account页面ajax加载
|
||||
# return true
|
||||
# end
|
||||
# authentication = ApplyAction.where(:user_id => User.current.id, :status => 1).first
|
||||
# user_identity = User.current.try(:user_extensions).try(:identity)
|
||||
# if user_identity.blank? || authentication.blank?
|
||||
# redirect_to my_account_path
|
||||
# return
|
||||
# end
|
||||
# end
|
||||
|
||||
def session_expiration
|
||||
if session[:user_id]
|
||||
if session_expired? && !try_to_autologin
|
||||
|
|
@ -106,6 +120,7 @@ class ApplicationController < ActionController::Base
|
|||
def current_user
|
||||
find_current_user
|
||||
end
|
||||
|
||||
def find_current_user
|
||||
user = nil
|
||||
unless api_request?
|
||||
|
|
@ -948,6 +963,20 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
# gitlab分页定制
|
||||
def paginateHelperForGitlab obj, pre_size=15
|
||||
@obj_count = obj.count
|
||||
@obj_pages = Paginator.new @obj_count, pre_size, params['page']
|
||||
if obj.kind_of? ActiveRecord::Base or obj.kind_of? ActiveRecord::Relation
|
||||
obj.limit(@obj_pages.per_page).offset(@obj_pages.offset)
|
||||
elsif obj.kind_of? Array
|
||||
obj[0, @obj_pages.per_page]
|
||||
else
|
||||
logger.error "[ApplicationController] Error : application_controller#paginateHelper ===> unknow category: #{obj.class}"
|
||||
raise RuntimeError, 'unknow type, Please input you type into this helper.'
|
||||
end
|
||||
end
|
||||
|
||||
#查找首页相关信息
|
||||
def find_first_page
|
||||
@first_page = FirstPage.find_by_page_type('project')
|
||||
|
|
|
|||
|
|
@ -371,7 +371,7 @@ class AttachmentsController < ApplicationController
|
|||
@attachment = Attachment.find(params[:attachments ].first[1][:attachment_id])
|
||||
#将需要修改的记录保存到历史记录
|
||||
@history = AttachmentHistory.new
|
||||
@history.attributes = @old_attachment.attributes.dup.except("id")
|
||||
@history.attributes = @old_attachment.attributes.dup.except("id", "resource_bank_id")
|
||||
@history.attachment_id = params[:old_attachment_id]
|
||||
#需要更新版本号,需要拿到原来该文件最大的历史版本号
|
||||
@old_history = @old_attachment.attachment_histories.reorder('version desc').first
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#encoding: utf-8
|
||||
class AvatarController < ApplicationController
|
||||
|
||||
include ActionView::Helpers::NumberHelper
|
||||
|
|
@ -92,7 +93,9 @@ class AvatarController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
if @source_type == 'Contest'
|
||||
if @source_type == 'UserAuthentication'
|
||||
|
||||
elsif @source_type == 'Contest'
|
||||
Trustie::Utils::Image.new(diskfile,true).compress(900)
|
||||
else
|
||||
Trustie::Utils::Image.new(diskfile,true).compress(300)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class BoardsController < ApplicationController
|
|||
layout 'base_projects'#by young
|
||||
default_search_scope :messages
|
||||
before_filter :find_project_by_project_id, :find_board_if_available, :except => [:join_to_org_subfields]
|
||||
before_filter :authorize, :except => [:new, :show, :create, :index, :join_to_org_subfields, :update_position, :update_name]
|
||||
before_filter :authorize, :except => [:new, :show, :create, :index, :join_to_org_subfields, :update_position, :update_name, :update_boards_position, :update_boards_name]
|
||||
accept_rss_auth :index, :show
|
||||
|
||||
|
||||
|
|
@ -183,7 +183,7 @@ class BoardsController < ApplicationController
|
|||
end
|
||||
|
||||
#分页
|
||||
@limit = 15
|
||||
@limit = 1
|
||||
@is_remote = true
|
||||
@atta_count = @topics.count
|
||||
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
|
||||
|
|
@ -260,6 +260,10 @@ class BoardsController < ApplicationController
|
|||
board.project_id = -1
|
||||
board.position = parent.children.count + 1
|
||||
parent.children << board
|
||||
|
||||
@course_board = @course.boards.where("parent_id is NULL").first
|
||||
@board = @course_board.children.order("position asc")
|
||||
@board_count = @board.count
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
|
|
@ -298,6 +302,11 @@ class BoardsController < ApplicationController
|
|||
after_boards = @board.parent.children.where("position > #{@board.position}")
|
||||
after_boards.update_all("position = position - 1")
|
||||
@board.destroy
|
||||
|
||||
@course_board = @course.boards.where("parent_id is NULL").first
|
||||
@board = @course_board.children.order("position asc")
|
||||
@board_count = @board.count
|
||||
|
||||
if @course || @contest
|
||||
respond_to do |format|
|
||||
format.js
|
||||
|
|
@ -327,6 +336,29 @@ class BoardsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def update_boards_position
|
||||
boards = @board.parent.children
|
||||
if params[:opr] == 'up' && @board.position > 1
|
||||
before_board = boards.where("position = #{@board.position - 1}").first
|
||||
if before_board && @board.update_attribute('position', @board.position - 1)
|
||||
before_board.update_attribute('position', before_board.position + 1)
|
||||
end
|
||||
elsif params[:opr] == 'down' && @board.position < boards.count
|
||||
after_board = boards.where("position = #{@board.position + 1}").first
|
||||
if after_board && @board.update_attribute('position', @board.position + 1)
|
||||
after_board.update_attribute('position', after_board.position - 1)
|
||||
end
|
||||
end
|
||||
|
||||
@course_board = @course.boards.where("parent_id is NULL").first
|
||||
@board = @course_board.children.order("position asc")
|
||||
@board_count = @board.count
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def update_name
|
||||
if @course || @contest
|
||||
@board.update_attribute("name", params[:name])
|
||||
|
|
@ -337,6 +369,19 @@ class BoardsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def update_boards_name
|
||||
@board.update_attribute("name", params[:name])
|
||||
@board.update_attribute("description", params[:name])
|
||||
|
||||
@course_board = @course.boards.where("parent_id is NULL").first
|
||||
@board = @course_board.children.order("position asc")
|
||||
@board_count = @board.count
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def join_to_org_subfields
|
||||
if params[:id]
|
||||
@board = Board.find(params[:id])
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
# encoding: utf-8
|
||||
class ChallengesController < ApplicationController
|
||||
layout "base_shixun"
|
||||
before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build]
|
||||
before_filter :find_challenge, :only => [:show, :edit, :update, :challenge_build, :index_up, :index_down, :destroy]
|
||||
before_filter :check_authentication
|
||||
before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build, :update_evaluation]
|
||||
before_filter :find_challenge, :only => [:show, :edit, :update, :challenge_build, :index_up, :index_down, :destroy, :update_evaluation]
|
||||
before_filter :build_challege_from_params, :only => [:new, :create]
|
||||
before_filter :tpi_manager_allowed, :only => [:challenge_build, :destroy, :edit, :new, :create]
|
||||
before_filter :allowed_view, :only => [:show]
|
||||
before_filter :query_challeges, :only => [:show, :edit, :update]
|
||||
before_filter :query_challeges, :only => [:show, :edit, :update, :update_evaluation]
|
||||
before_filter :find_shixun_language, :only => [:show, :new, :edit]
|
||||
|
||||
include ApplicationHelper
|
||||
|
|
@ -25,6 +26,13 @@ class ChallengesController < ApplicationController
|
|||
@challenge.position = challenge_count + 1
|
||||
@challenge.shixun = @shixun
|
||||
@challenge.user = User.current
|
||||
@challenge.save!
|
||||
|
||||
respond_to do |format|
|
||||
format.html {redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun)}
|
||||
end
|
||||
|
||||
=begin
|
||||
ActiveRecord::Base.transaction do
|
||||
begin
|
||||
@challenge.save!
|
||||
|
|
@ -41,23 +49,10 @@ class ChallengesController < ApplicationController
|
|||
ChallengeTag.create(:name => input, :challenge_id => @challenge.id)
|
||||
end
|
||||
end
|
||||
# 向jenkins端发送请求,构建pipeline片段,实时返回结果
|
||||
jenkins_shixuns = Redmine::Configuration['jenkins_shixuns']
|
||||
params = {:challengeStage => "#{@challenge.position}", :challengeType => "#{@challenge.evaluation_way.to_i}", :challengeProgramName => "#{@challenge.exec_path}", :trainingID => "#{@shixun.id}"}
|
||||
uri = URI("#{jenkins_shixuns}/jenkins-exec/game/generatePipelineScriptForChallenge")
|
||||
res = uri_exec uri, {challengeInfo: params.to_json}
|
||||
if res['code'] == 0
|
||||
@challenge.update_attribute(:pipeline_script, res['msg'])
|
||||
respond_to do |format|
|
||||
format.html {redirect_to shixun_challenge_path(@challenge, :shixun_id => @shixun)}
|
||||
end
|
||||
else
|
||||
logger.error("res['code'] is #{res['code']}, res['msg'] is #{res['msg']}")
|
||||
# unless res['msg'].blank?
|
||||
# test_msg = Base64.decode64(res['msg'])
|
||||
# end
|
||||
# logger.info("###############{test_msg}")
|
||||
raise("脚本构建失败:本关执行文件名格式错误")
|
||||
# 更新shixun公共测试用例
|
||||
add_shixun_modify_status(@shixun, 1)
|
||||
respond_to do |format|
|
||||
format.html {redirect_to shixun_challenge_path(@challenge, :shixun_id => @shixun)}
|
||||
end
|
||||
rescue Exception => e
|
||||
flash[:error] = "#{e.message}"
|
||||
|
|
@ -65,6 +60,7 @@ class ChallengesController < ApplicationController
|
|||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
=end
|
||||
end
|
||||
|
||||
# 处理新建challenge返回的pipeline片段
|
||||
|
|
@ -84,6 +80,11 @@ class ChallengesController < ApplicationController
|
|||
end
|
||||
|
||||
def show
|
||||
challenge_num = Challenge.where(:shixun_id => @shixun).count
|
||||
challenge_pos = @challenge.position
|
||||
if challenge_pos < challenge_num
|
||||
@next_challenge = Challenge.where(:shixun_id => @shixun, :position => challenge_pos+1).first
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js
|
||||
|
|
@ -91,6 +92,13 @@ class ChallengesController < ApplicationController
|
|||
end
|
||||
|
||||
def edit
|
||||
challenge_num = Challenge.where(:shixun_id => @shixun).count
|
||||
challenge_pos = @challenge.position
|
||||
if challenge_pos < challenge_num
|
||||
@next_challenge = Challenge.where(:shixun_id => @shixun, :position => challenge_pos+1).first
|
||||
end
|
||||
@tab = params[:tab].blank? ? 1 : params[:tab].to_i
|
||||
@editor = params[:editor] # 编辑模式
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
|
@ -101,9 +109,13 @@ class ChallengesController < ApplicationController
|
|||
end
|
||||
|
||||
def update
|
||||
@challenge.update_attributes(params[:challenge])
|
||||
redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab])
|
||||
=begin
|
||||
respond_to do |format|
|
||||
if @challenge.update_attributes(params[:challenge])
|
||||
ActiveRecord::Base.transaction do
|
||||
ActiveRecord::Base.transaction do
|
||||
@challenge.update_attributes(params[:challenge])
|
||||
begin
|
||||
@test_sets.delete_all unless @test_sets.blank?
|
||||
@challenge_tags.delete_all unless @challenge_tags.blank?
|
||||
if params[:test_set][:hidden].length > 0
|
||||
|
|
@ -119,34 +131,60 @@ class ChallengesController < ApplicationController
|
|||
ChallengeTag.create(:name => input, :challenge_id => @challenge.id)
|
||||
end
|
||||
end
|
||||
# 向jenkins端发送请求,构建pipeline片段,实时返回结果
|
||||
jenkins_shixuns = Redmine::Configuration['jenkins_shixuns']
|
||||
params = {:challengeStage => "#{@challenge.position}", :challengeType => "#{@challenge.evaluation_way.to_i}", :challengeProgramName => "#{@challenge.exec_path}", :trainingID => "#{@shixun.id}"}
|
||||
uri = URI("#{jenkins_shixuns}/jenkins-exec/game/generatePipelineScriptForChallenge")
|
||||
res = uri_exec uri, {challengeInfo: params.to_json}
|
||||
if res['code'] == 0
|
||||
@challenge.update_attribute(:pipeline_script, res['msg'])
|
||||
else
|
||||
logger.error("res['code'] is #{res['code']}, res['msg'] is #{res['code']}")
|
||||
raise("脚本构建失败")
|
||||
# 向jenkins端发送请求,构建公共测试用例
|
||||
add_shixun_modify_status(@shixun, 1)
|
||||
format.html {redirect_to shixun_challenge_path(@challenge, :shixun_id => @shixun), notice: '更新成功!'}
|
||||
rescue Exception => e
|
||||
flash[:error] = "#{e.message}"
|
||||
format.html{redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun)}
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
end
|
||||
=end
|
||||
end
|
||||
|
||||
def update_evaluation
|
||||
ActiveRecord::Base.transaction do
|
||||
@challenge.update_attributes(params[:challenge])
|
||||
begin
|
||||
if params[:tab].to_i == 2
|
||||
@test_sets.delete_all unless @test_sets.blank?
|
||||
if params[:test_set][:hidden].length > 0
|
||||
params[:test_set][:input].each_with_index do |input, index|
|
||||
unless (input[index] == params[:test_set][:output][index] && input[index].nil?)
|
||||
params[:test_set][:hidden][index].to_i == 0 ? open = 1 : open = 0
|
||||
TestSet.create(:challenge_id => @challenge.id, :input => input, :output => params[:test_set][:output][index], :is_public => open, :position => (index + 1))
|
||||
end
|
||||
end
|
||||
end
|
||||
elsif params[:tab].to_i == 5
|
||||
@challenge_tags.delete_all unless @challenge_tags.blank?
|
||||
unless params[:knowledge].blank?
|
||||
params[:knowledge][:input].each do |input|
|
||||
ChallengeTag.create(:name => input, :challenge_id => @challenge.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
format.html {redirect_to shixun_challenge_path(@challenge, :shixun_id => @shixun), notice: '更新成功!'}
|
||||
format.json { head :no_content }
|
||||
else
|
||||
format.html { render action: "edit" }
|
||||
format.json { render json: @challenge.errors }
|
||||
# 向jenkins端发送请求,构建公共测试用例
|
||||
add_shixun_modify_status(@shixun, 1)
|
||||
redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab])
|
||||
rescue Exception => e
|
||||
flash[:error] = "#{e.message}"
|
||||
redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => params[:tab])
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def index_down
|
||||
next_challenge = @challenge.next_challenge
|
||||
position = @challenge.position
|
||||
@challenge.update_attribute(:position, (position + 1))
|
||||
next_challenge.update_attribute(:position, next_challenge.position - 1)
|
||||
@challenges = @shixun.challenges
|
||||
# 向jenkins端发送请求,构建公共测试用例
|
||||
add_shixun_modify_status(@shixun, 1)
|
||||
end
|
||||
|
||||
def index_up
|
||||
|
|
@ -155,6 +193,8 @@ class ChallengesController < ApplicationController
|
|||
@challenge.update_attribute(:position, (position - 1))
|
||||
last_challenge.update_attribute(:position, last_challenge.position + 1)
|
||||
@challenges = @shixun.challenges
|
||||
# 向jenkins端发送请求,构建公共测试用例
|
||||
add_shixun_modify_status(@shixun, 1)
|
||||
end
|
||||
|
||||
# build job 只负责发送请求
|
||||
|
|
@ -194,7 +234,7 @@ class ChallengesController < ApplicationController
|
|||
end
|
||||
|
||||
def allowed_view
|
||||
unless allow_to_view_challenge(@challenge, @shixun)
|
||||
unless (allow_to_view_challenge(@challenge, @shixun) || User.current.manager_of_shixun?(@shixun))
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
|
@ -230,6 +270,11 @@ class ChallengesController < ApplicationController
|
|||
if @shixun.nil?
|
||||
render_404
|
||||
return
|
||||
else
|
||||
if (@shixun.status == 0 && !(User.current.manager_of_shixun?(@shixun) || User.current.admin?))
|
||||
render_403
|
||||
return
|
||||
end
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ class CoursesController < ApplicationController
|
|||
helper SyllabusesHelper
|
||||
|
||||
before_filter :auth_login1, :only => [:show, :course_activity, :feedback]
|
||||
skip_before_filter :verify_authenticity_token, :only => [:update_position]
|
||||
before_filter :check_authentication, :except => [:update_position]
|
||||
menu_item :overview
|
||||
menu_item :feedback, :only => :feedback
|
||||
menu_item :homework, :only => :homework
|
||||
|
|
@ -40,28 +42,49 @@ class CoursesController < ApplicationController
|
|||
#
|
||||
def index
|
||||
@user = User.current
|
||||
sy_courses = @user.courses.visible.not_deleted
|
||||
syllabus_ids = sy_courses.empty? ? '(-1)' : "(" + sy_courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")"
|
||||
syllabus_members = SyllabusMember.where("user_id = #{@user.id}")
|
||||
syllabus_member_ids = syllabus_members.empty? ? "(-1)" : "(" + syllabus_members.map{|syl_mem| syl_mem.syllabus_id}.join(',') + ")"
|
||||
@search = params[:search].nil? ? '' : params[:search]
|
||||
@select = params[:select].nil? ? '' : params[:select]
|
||||
@is_end = params[:is_end].nil? ? 0 : params[:is_end].to_i #是否归档
|
||||
|
||||
search = params[:search].nil? ? '' : params[:search]
|
||||
# 我发布的课程
|
||||
create_syllabuses = Syllabus.where("user_id = #{@user.id} and title like '%#{search}%'").order("created_at desc")
|
||||
# 我参与的课程
|
||||
join_syllabuses = Syllabus.where("(id in #{syllabus_ids} or id in #{syllabus_member_ids}) and user_id != #{@user.id} and title like '%#{search}%'").order("created_at desc")
|
||||
# 我的所有课程
|
||||
all_syllabuses = Syllabus.where("(id in #{syllabus_ids} or id in #{syllabus_member_ids}) and title like '%#{search}%'").order("created_at desc")
|
||||
@syllabuses_num = Course.where("is_end = #{@is_end} and is_delete = 0").count
|
||||
#@syllabus_count = all_syllabuses.count
|
||||
# 我创建的课堂
|
||||
create_syllabuses = Course.where(:tea_id => @user.id).where("is_end = #{@is_end} and is_delete = 0 and name like '%#{@search}%'")
|
||||
# 我参与的课堂
|
||||
join_syllabuses = @user.courses.where("is_end = #{@is_end} and is_delete = 0 and tea_id != #{@user.id} and name like '%#{@search}%'")
|
||||
@join_syllabuses_count = join_syllabuses.count
|
||||
@create_syllabuses_count = create_syllabuses.count
|
||||
|
||||
# 页面筛选的课程
|
||||
if params[:select] == "create"
|
||||
if @select == "create"
|
||||
@syllabuses = create_syllabuses
|
||||
elsif params[:select] == "join"
|
||||
elsif @select == "join"
|
||||
@syllabuses = join_syllabuses
|
||||
elsif @select == "end"
|
||||
# 归档的课堂
|
||||
end_syllabuses = Course.where("is_end = #{@is_end} and name like '%#{@search}%'")
|
||||
@syllabuses = end_syllabuses
|
||||
else
|
||||
# 全部课堂
|
||||
all_syllabuses = Course.where("is_end = #{@is_end} and is_delete = 0 and name like '%#{@search}%'")
|
||||
@syllabuses = all_syllabuses
|
||||
end
|
||||
|
||||
@syllabuses.each do |course|
|
||||
course[:infocount] = course.members.count
|
||||
#course[:infocount] = (User.current.admin? || User.current.allowed_to?(:as_teacher,course)) ? (course.homework_commons.count + visable_attachemnts_incourse(course).count + course.members.count) : (course.homework_commons.where("publish_time <= '#{Time.now}'").count + visable_attachemnts_incourse(course).count + course.members.count)
|
||||
if course[:infocount] < 0
|
||||
course[:infocount] = 0
|
||||
end
|
||||
end
|
||||
@syllabuses = @syllabuses.sort{|x,y| y[:infocount] <=> x[:infocount] }
|
||||
|
||||
@syllabuses_count = @syllabuses.count
|
||||
@limit = 16
|
||||
@is_remote = true
|
||||
@syllabuses_pages = Paginator.new @syllabuses_count, @limit, params['page'] || 1
|
||||
@offset ||= @syllabuses_pages.offset
|
||||
@syllabuses = paginateHelper @syllabuses, @limit
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html { render :layout => "base_edu" }
|
||||
|
|
@ -162,18 +185,18 @@ class CoursesController < ApplicationController
|
|||
@course = c[:course]
|
||||
if @course.errors.full_messages.count <= 0
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
format.js {
|
||||
# render :layout => 'base_courses'
|
||||
#flash[:notice] = l(:notice_successful_update)
|
||||
redirect_to settings_course_url(@course)
|
||||
#redirect_to settings_course_url(@course)
|
||||
}
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
settings
|
||||
redirect_to settings_course_url(@course)
|
||||
format.js {
|
||||
# settings
|
||||
# redirect_to settings_course_url(@course)
|
||||
}
|
||||
format.api { render_validation_errors(@course) }
|
||||
end
|
||||
|
|
@ -340,7 +363,9 @@ class CoursesController < ApplicationController
|
|||
member.update_attributes(:course_group_id => params[:course_group_id].to_i) if member
|
||||
end
|
||||
end
|
||||
@no_group_student = @course.student.count - @course.members.where("course_group_id != 0").count
|
||||
@teacher_count = searchTeacherAndAssistant(@course).count
|
||||
@student_count = @course.student.count
|
||||
@no_group_count = @course.members.where("course_group_id = 0").select{|m| m.roles.to_s.include?("Student")}.count
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
|
|
@ -388,9 +413,9 @@ class CoursesController < ApplicationController
|
|||
@search = params[:search]
|
||||
q = params[:search] ? "#{params[:search].strip}" : ""
|
||||
if @order == "student_id"
|
||||
@members = @course.members.joins("join user_extensions on members.user_id = user_extensions.user_id").order("student_id #{@sort}").select{|m| m.roles.to_s.include?("Student")}
|
||||
@members = @course.members.joins("join user_extensions on members.user_id = user_extensions.user_id").order("student_id #{@r_sort}").select{|m| m.roles.to_s.include?("Student")}
|
||||
else
|
||||
@members = @course.members.joins("join users on members.user_id = users.id").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@sort}, login #{@b_sort}").select{|m| m.roles.to_s.include?("Student")}
|
||||
@members = @course.members.joins("join users on members.user_id = users.id").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@r_sort}, login #{@r_sort}").select{|m| m.roles.to_s.include?("Student")}
|
||||
end
|
||||
if q.nil? || q == ""
|
||||
else
|
||||
|
|
@ -414,7 +439,7 @@ class CoursesController < ApplicationController
|
|||
|
||||
@teacher_count = TeacherAndAssistantCount @course
|
||||
@student_count = studentCount(@course)
|
||||
@no_group_count = @student_count - @course.members.where("course_group_id != 0").count
|
||||
@no_group_count = @course.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.count
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
|
|
@ -453,7 +478,7 @@ class CoursesController < ApplicationController
|
|||
|
||||
@teacher_count = TeacherAndAssistantCount @course
|
||||
@student_count = studentCount(@course)
|
||||
@no_group_count = @student_count - @course.members.where("course_group_id != 0").count
|
||||
@no_group_count = @course.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.count
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
|
|
@ -493,7 +518,7 @@ class CoursesController < ApplicationController
|
|||
|
||||
@teacher_count = TeacherAndAssistantCount @course
|
||||
@student_count = studentCount(@course)
|
||||
@no_group_count = @student_count - @course.members.where("course_group_id != 0").count
|
||||
@no_group_count = @course.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.count
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
|
|
@ -568,6 +593,10 @@ class CoursesController < ApplicationController
|
|||
member.course_group_id = 0
|
||||
member.save
|
||||
@group = group
|
||||
@course = @group.course
|
||||
@teacher_count = searchTeacherAndAssistant(@course).count
|
||||
@student_count = @course.student.count
|
||||
@no_group_count = @course.members.where("course_group_id = 0").select{|m| m.roles.to_s.include?("Student")}.count
|
||||
end
|
||||
|
||||
def searchgroupmembers
|
||||
|
|
@ -589,7 +618,7 @@ class CoursesController < ApplicationController
|
|||
page_from = params[:page].nil? ? 0 : (params[:page].to_i - 1)
|
||||
@results = student_homework_score(0,page_from, 10,"desc")
|
||||
end
|
||||
@no_group_count = @course.student.count - @course.members.where("course_group_id != 0").count
|
||||
@no_group_count = @course.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.count
|
||||
@course_groups = @course.course_groups
|
||||
@limit = 50
|
||||
@page = params[:page].nil? ? 1 : params['page'].to_i
|
||||
|
|
@ -675,7 +704,7 @@ class CoursesController < ApplicationController
|
|||
|
||||
@teacher_count = TeacherAndAssistantCount @course
|
||||
@student_count = studentCount(@course)
|
||||
@no_group_count = @student_count - @course.members.where("course_group_id != 0").count
|
||||
@no_group_count = @course.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.count
|
||||
|
||||
respond_to do |format|
|
||||
if @search
|
||||
|
|
@ -704,7 +733,7 @@ class CoursesController < ApplicationController
|
|||
end
|
||||
|
||||
@homeworks = @course.homework_commons.where("publish_time <= '#{Time.now}'").order("created_at asc")
|
||||
filename="#{@course.teacher.lastname.to_s + @course.teacher.firstname.to_s }_#{@course.name}_#{@course.time.to_s + @course.term}#{l(:excel_member_list)}";
|
||||
filename="#{@course.teacher.lastname.to_s + @course.teacher.firstname.to_s }_#{@course.name}_#{l(:excel_member_list)}";
|
||||
|
||||
respond_to do |format|
|
||||
format.xls {
|
||||
|
|
@ -751,7 +780,7 @@ class CoursesController < ApplicationController
|
|||
@limit = 50
|
||||
@page = params[:page].nil? ? 1 : params['page'].to_i
|
||||
@members_count = @results.count
|
||||
@no_group_count = @members_count - @course.members.where("course_group_id != 0").count
|
||||
@no_group_count = @course.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.count
|
||||
@mem_pages = Paginator.new @members_count, @limit, @page
|
||||
@results = paginateHelper @results, @limit
|
||||
end
|
||||
|
|
@ -797,7 +826,7 @@ class CoursesController < ApplicationController
|
|||
CourseMessage.create(:user_id => member.user_id, :course_id => @course.id, :course_message_type => "RemoveFromCourse", :viewed => false, :course_message_id => User.current.id)
|
||||
|
||||
@course_groups = @course.course_groups
|
||||
@no_group_count = @course.student.count - @course.members.where("course_group_id != 0").count
|
||||
@no_group_count = @course.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.count
|
||||
@canShowCode = isCourseTeacher(User.current.id,@course)
|
||||
respond_to do |format|
|
||||
format.js
|
||||
|
|
@ -824,6 +853,7 @@ class CoursesController < ApplicationController
|
|||
|
||||
if User.current.allowed_to?(:as_teacher,@course)
|
||||
@select_tab = params[:tab]
|
||||
@role = params[:role] if params[:role]
|
||||
@issue_custom_fields = IssueCustomField.sorted.all
|
||||
@issue_category ||= IssueCategory.new
|
||||
@member ||= @course.members.new
|
||||
|
|
@ -832,19 +862,26 @@ class CoursesController < ApplicationController
|
|||
@teachers = searchTeacherAndAssistant(@course)
|
||||
@teacher_count = @teachers.count
|
||||
@student_count = studentCount(@course)
|
||||
@no_group_count = @student_count - @course.members.where("course_group_id != 0").count
|
||||
@no_group_count = @course.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.count
|
||||
@apply_users = CourseMessage.where(:course_id => @course.id,:course_message_type => 'JoinCourseRequest', :status => 0)
|
||||
|
||||
@roles = Role.givable.all[3..5]
|
||||
@members = @course.member_principals.includes(:roles, :principal).all.sort
|
||||
|
||||
course_org_ids = OrgCourse.find_by_sql("select distinct organization_id from org_courses where course_id = #{@course.id}").map(&:organization_id)
|
||||
if course_org_ids.empty?
|
||||
@orgs_not_in_course = User.current.organizations
|
||||
else
|
||||
course_org_ids = "(" + course_org_ids.join(',') + ")"
|
||||
@orgs_not_in_course = User.current.organizations.where("organizations.id not in #{course_org_ids}")
|
||||
course_module = @course.course_modules
|
||||
if course_module.blank?
|
||||
type = ["news", "boards", "homework", "exercises", "poll", "statistics", "attachment"]
|
||||
for i in 0..6
|
||||
CourseModule.create(:course_id => @course.id, :type => type[i], :position => i + 1, :hidden => 0 )
|
||||
end
|
||||
course_module = @course.course_modules
|
||||
end
|
||||
|
||||
|
||||
@modules = course_module.order("position asc")
|
||||
|
||||
@course_board = @course.boards.where("parent_id is NULL").first
|
||||
@board = @course_board.children.order("position asc")
|
||||
@board_count = @board.count
|
||||
|
||||
|
||||
@curr_page = '设置'
|
||||
respond_to do |format|
|
||||
format.html { render :layout => 'base_edu_course' }
|
||||
|
|
@ -856,6 +893,47 @@ class CoursesController < ApplicationController
|
|||
|
||||
end
|
||||
|
||||
def update_position
|
||||
|
||||
course_module = @course.course_modules
|
||||
|
||||
for i in 0..6
|
||||
case params[:position][i]
|
||||
when "boards"
|
||||
course_module.where(:module_type => 'boards').first.update_attribute('position', i+1)
|
||||
when "news"
|
||||
course_module.where(:module_type => 'news').first.update_attribute('position', i+1)
|
||||
when "homework"
|
||||
course_module.where(:module_type => 'homework').first.update_attribute('position', i+1)
|
||||
when "exercises"
|
||||
course_module.where(:module_type => 'exercises').first.update_attribute('position', i+1)
|
||||
when "poll"
|
||||
course_module.where(:module_type => 'poll').first.update_attribute('position', i+1)
|
||||
when "statistics"
|
||||
course_module.where(:module_type => 'statistics').first.update_attribute('position', i+1)
|
||||
when "attachment"
|
||||
course_module.where(:module_type => 'attachment').first.update_attribute('position', i+1)
|
||||
end
|
||||
end
|
||||
|
||||
# params[:message] 有值 就更行字段: 0为不隐藏,1为隐藏
|
||||
type = ["news", "boards", "attachment", "homework", "poll", "exercises", "statistics"]
|
||||
|
||||
hidden = type - params[:message]
|
||||
course_module.where(:module_type => params[:message]).update_all(:hidden => 0)
|
||||
course_module.where(:module_type => hidden).update_all(:hidden => 1)
|
||||
|
||||
|
||||
@modules = @course.course_modules.order("position asc")
|
||||
@course_board = @course.boards.where("parent_id is NULL").first
|
||||
@board = @course_board.children.order("position asc")
|
||||
@board_count = @board.count
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def private_or_public
|
||||
if @course.is_public == 0
|
||||
@course.update_attributes(:is_public => 1)
|
||||
|
|
@ -1250,7 +1328,7 @@ class CoursesController < ApplicationController
|
|||
# course_request_messages = CourseMessage.where("user_id =? and course_id =? and course_message_type =? and viewed =?", User.current.id, @course.id, 'CourseRequestDealResult', false)
|
||||
# course_request_messages.update_all(:viewed => true)
|
||||
|
||||
course_activities = @course.course_activities
|
||||
course_activities = @course.course_activities.where("course_act_type in ('HomeworkCommon', 'Attachment', 'Course')")
|
||||
@canShowRealName = User.current.member_of_course? @course
|
||||
@page = params[:page] ? params[:page].to_i + 1 : 0
|
||||
if params[:type].present?
|
||||
|
|
@ -1336,6 +1414,7 @@ class CoursesController < ApplicationController
|
|||
# 作业查重
|
||||
def code_repeat
|
||||
#代码查重新加的
|
||||
@index = params[:index]
|
||||
@order,@b_sort,@name,@group = params[:order] || "score",params[:sort] || "desc",params[:name] || "",params[:group]
|
||||
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
||||
|
|
@ -1356,13 +1435,13 @@ class CoursesController < ApplicationController
|
|||
puts tmpwork.id
|
||||
end
|
||||
|
||||
#respond_to do |format|
|
||||
#format.html {render :layout => 'base_courses'}
|
||||
#end
|
||||
respond_to do |format|
|
||||
format.html {render :layout => 'base_edu'}
|
||||
end
|
||||
end
|
||||
|
||||
def show_comparecode
|
||||
|
||||
@index = params[:index]
|
||||
src_id = params[:src_id]
|
||||
dst_id = params[:dst_id]
|
||||
|
||||
|
|
@ -1393,7 +1472,7 @@ class CoursesController < ApplicationController
|
|||
@dst_username = dst_user.try(:realname) != " " ? dst_user.lastname + dst_user.firstname : dst_user.try(:login)
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html{render :layout => 'base_edu'}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1586,7 +1665,7 @@ class CoursesController < ApplicationController
|
|||
def search_not_students
|
||||
if !params[:search].nil?
|
||||
members = @course.members.select{|m| m.roles.to_s.include?("Student")}
|
||||
member_ids = "(" + members.map(&:user_id).join(',') + ")"
|
||||
member_ids = members.empty? ? "(-1)" : "(" + members.map(&:user_id).join(',') + ")"
|
||||
condition = "%#{params[:search].strip}%".gsub(" ","")
|
||||
@users = User.joins(:user_extensions).where("users.id not in #{member_ids} and status = 1 and (LOWER(concat(lastname, firstname)) LIKE '#{condition}' or user_extensions.student_id LIKE '#{condition}')")
|
||||
end
|
||||
|
|
@ -1762,27 +1841,25 @@ class CoursesController < ApplicationController
|
|||
sheet1[1,1] = course.syllabus.title
|
||||
sheet1[2,0] = "班级编号"
|
||||
sheet1[2,1] = course.id
|
||||
sheet1[3,0] = "班级学期"
|
||||
sheet1[3,1] = course.time.to_s+"年"+course.term
|
||||
sheet1[4,0] = "班级名称"
|
||||
sheet1[4,1] = course.name
|
||||
sheet1[5,0] = "教师团队"
|
||||
sheet1[5,1] = (searchTeacherAndAssistant course).map{|member| member.user.show_name}.join('、')
|
||||
sheet1[6,0] = "主讲教师"
|
||||
sheet1[6,1] = course.teacher.show_name
|
||||
sheet1[7,0] = "排名"
|
||||
sheet1[7,1] = "学生姓名"
|
||||
sheet1[7,2] = "昵称"
|
||||
sheet1[7,3] = "学号"
|
||||
sheet1[3,0] = "班级名称"
|
||||
sheet1[3,1] = course.name
|
||||
sheet1[4,0] = "教师团队"
|
||||
sheet1[4,1] = (searchTeacherAndAssistant course).map{|member| member.user.show_name}.join('、')
|
||||
sheet1[5,0] = "主讲教师"
|
||||
sheet1[5,1] = course.teacher.show_name
|
||||
sheet1[6,0] = "排名"
|
||||
sheet1[6,1] = "学生姓名"
|
||||
sheet1[6,2] = "昵称"
|
||||
sheet1[6,3] = "学号"
|
||||
for i in 0 ... homeworks.count
|
||||
sheet1[7,i+4] = "第"+(i+1).to_s+"次"
|
||||
sheet1[6,i+4] = "第"+(i+1).to_s+"次"
|
||||
end
|
||||
sheet1[7,homeworks.count+4] = "作业得分"
|
||||
sheet1[7,homeworks.count+5] = "测评得分"
|
||||
sheet1[7,homeworks.count+6] = "社区得分"
|
||||
sheet1[7,homeworks.count+7] = "总得分"
|
||||
sheet1[7,homeworks.count+8] = "分班"
|
||||
count_row = 8
|
||||
sheet1[6,homeworks.count+4] = "作业得分"
|
||||
sheet1[6,homeworks.count+5] = "测评得分"
|
||||
sheet1[6,homeworks.count+6] = "社区得分"
|
||||
sheet1[6,homeworks.count+7] = "总得分"
|
||||
sheet1[6,homeworks.count+8] = "分班"
|
||||
count_row = 7
|
||||
members.each_with_index do |member, i|
|
||||
sheet1[count_row,0]= i+1
|
||||
sheet1[count_row,1] = member.user.lastname.to_s + member.user.firstname.to_s
|
||||
|
|
@ -1817,27 +1894,25 @@ class CoursesController < ApplicationController
|
|||
sheet[1,1] = course.syllabus.title
|
||||
sheet[2,0] = "班级编号"
|
||||
sheet[2,1] = course.id
|
||||
sheet[3,0] = "班级学期"
|
||||
sheet[3,1] = course.time.to_s+"年"+course.term
|
||||
sheet[4,0] = "班级名称"
|
||||
sheet[4,1] = course.name
|
||||
sheet[5,0] = "教师团队"
|
||||
sheet[5,1] = (searchTeacherAndAssistant course).map{|member| member.user.show_name}.join('、')
|
||||
sheet[6,0] = "主讲教师"
|
||||
sheet[6,1] = course.teacher.show_name
|
||||
sheet[6,0] = "作业批次"
|
||||
sheet[6,1] = "第#{i+1}次作业"
|
||||
sheet[6,0] = "作业名称"
|
||||
sheet[6,1] = home.name
|
||||
sheet[3,0] = "班级名称"
|
||||
sheet[3,1] = course.name
|
||||
sheet[4,0] = "教师团队"
|
||||
sheet[4,1] = (searchTeacherAndAssistant course).map{|member| member.user.show_name}.join('、')
|
||||
sheet[5,0] = "主讲教师"
|
||||
sheet[5,1] = course.teacher.show_name
|
||||
sheet[5,0] = "作业批次"
|
||||
sheet[5,1] = "第#{i+1}次作业"
|
||||
sheet[5,0] = "作业名称"
|
||||
sheet[5,1] = home.name
|
||||
if home.homework_type == 1 #普通作业
|
||||
if home.anonymous_comment ==0
|
||||
sheet.row(7).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_name),l(:excel_homework_des),
|
||||
sheet.row(6).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_name),l(:excel_homework_des),
|
||||
l(:excel_t_score),l(:excel_ta_score), l(:excel_n_score),l(:excel_a_penalty),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)])
|
||||
else
|
||||
sheet.row(7).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_name),l(:excel_homework_des),
|
||||
sheet.row(6).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_name),l(:excel_homework_des),
|
||||
l(:excel_t_score),l(:excel_ta_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)])
|
||||
end
|
||||
count_row = 8
|
||||
count_row = 7
|
||||
items = home.student_works.order("work_score desc")
|
||||
items.each_with_index do |stu, j|
|
||||
sheet[count_row,0]= j + 1
|
||||
|
|
@ -1863,13 +1938,13 @@ class CoursesController < ApplicationController
|
|||
end
|
||||
elsif home.homework_type == 2 #编程作业
|
||||
if home.anonymous_comment ==0
|
||||
sheet.row(7).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_name),l(:excel_homework_des),
|
||||
sheet.row(6).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_name),l(:excel_homework_des),
|
||||
l(:excel_t_score),l(:excel_ta_score), l(:excel_s_score),l(:excel_n_score),l(:excel_a_penalty),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)])
|
||||
else
|
||||
sheet.row(7).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_name),l(:excel_homework_des),
|
||||
sheet.row(6).concat([l(:excel_rank),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_homework_name),l(:excel_homework_des),
|
||||
l(:excel_t_score),l(:excel_ta_score), l(:excel_s_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)])
|
||||
end
|
||||
count_row = 8
|
||||
count_row = 7
|
||||
items = home.student_works.order("work_score desc")
|
||||
items.each_with_index do |stu, j|
|
||||
sheet[count_row,0]= j + 1
|
||||
|
|
@ -1896,13 +1971,13 @@ class CoursesController < ApplicationController
|
|||
end
|
||||
elsif home.homework_type == 3 #分组作业
|
||||
if home.anonymous_comment ==0
|
||||
sheet.row(7).concat([l(:excel_rank),l(:excel_group_member),l(:excel_homework_name),l(:excel_homework_project),l(:excel_homework_des),
|
||||
sheet.row(6).concat([l(:excel_rank),l(:excel_group_member),l(:excel_homework_name),l(:excel_homework_project),l(:excel_homework_des),
|
||||
l(:excel_t_score),l(:excel_ta_score),l(:excel_n_score),l(:excel_a_penalty),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)])
|
||||
else
|
||||
sheet.row(7).concat([l(:excel_rank),l(:excel_group_member),l(:excel_homework_name),l(:excel_homework_project),l(:excel_homework_des),
|
||||
sheet.row(6).concat([l(:excel_rank),l(:excel_group_member),l(:excel_homework_name),l(:excel_homework_project),l(:excel_homework_des),
|
||||
l(:excel_t_score),l(:excel_ta_score),l(:excel_l_penalty),l(:excel_f_score),l(:excel_commit_time)])
|
||||
end
|
||||
count_row = 8
|
||||
count_row = 7
|
||||
items = home.student_works.order("work_score desc")
|
||||
items.each_with_index do |stu, j|
|
||||
sheet[count_row,0] = j + 1
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
class DiscussesController < ApplicationController
|
||||
include ApplicationHelper
|
||||
before_filter :find_dis_object, :except => [:destroy]
|
||||
before_filter :find_discuss, :only => [:destroy]
|
||||
|
||||
def create
|
||||
if @model
|
||||
if params[:reply_id].blank?
|
||||
@model.discusses << Discuss.new(:content => params[:content], :user_id => User.current.id, :praise_count => 0)
|
||||
else
|
||||
@model.discusses << Discuss.new(:content => params[:content], :user_id => User.current.id, :parent_id => params[:reply_id], :root_id => params[:reply_id], :praise_count => 0)
|
||||
end
|
||||
if params[:dis_type] == "Shixun"
|
||||
redirect_to shixun_discuss_shixun_path(@model)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @discuss
|
||||
if @discuss.dis_type == "Shixun"
|
||||
@shixun = @discuss.dis
|
||||
end
|
||||
@discuss.destroy
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_discuss
|
||||
@discuss = Discuss.find params[:id]
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_dis_object
|
||||
unless params[:dis_id] && params[:dis_type]
|
||||
render_404
|
||||
else
|
||||
case params[:dis_type]
|
||||
when 'Shixun'
|
||||
@model = Shixun.find params[:dis_id]
|
||||
end
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
|
@ -8,6 +8,7 @@ class ForumsController < ApplicationController
|
|||
before_filter :authenticate_user_edit, :only => [:edit, :update]
|
||||
before_filter :authenticate_user_destroy, :only => [:destroy]
|
||||
before_filter :require_login, :only => [:new, :create,:destroy,:update,:edit]
|
||||
before_filter :check_authentication
|
||||
|
||||
helper :sort
|
||||
include SortHelper
|
||||
|
|
|
|||
|
|
@ -3,8 +3,9 @@ class GamesController < ApplicationController
|
|||
layout "base_myshixun"
|
||||
skip_before_filter :verify_authenticity_token, :only => [:file_update]
|
||||
before_filter :find_myshixun, :only => [:index]
|
||||
before_filter :find_game, :only => [:show, :game_build, :entry,:next_step, :outputs_show, :file_edit, :file_update, :game_status, :change_status, :answer, :minus_score]
|
||||
before_filter :find_repository, :only => [:show, :entry, :file_edit, :file_update]
|
||||
before_filter :find_game, :only => [:show, :game_build, :entry,:next_step, :outputs_show, :file_edit, :file_update,
|
||||
:game_status, :change_status, :answer, :minus_score, :refresh_game_list, :reset_original_code, :reset_new_code]
|
||||
before_filter :find_repository, :only => [:show, :entry, :file_edit, :file_update, :reset_original_code, :reset_new_code]
|
||||
before_filter :allowd_manager
|
||||
before_filter :allowd_view, :only => [:show]
|
||||
before_filter :find__shixun_language, :only => [:show, :entry]
|
||||
|
|
@ -23,15 +24,19 @@ class GamesController < ApplicationController
|
|||
# 首次进入版本库自动打开文件
|
||||
# path:"" && path: @game.path
|
||||
# @praise 判断是否点赞
|
||||
# @praise 判断是否踩
|
||||
# @tread 判断是否踩
|
||||
# git_repository_url @myshixun, "Myshixun"
|
||||
def show
|
||||
# 展示全部实训
|
||||
if @game.status == 1
|
||||
# 放置页面ajax数据还没获取就关闭
|
||||
@game.update_attribute(:status, 0)
|
||||
end
|
||||
@games = @myshixun.games.includes(:challenge)
|
||||
@games_count = @games.count
|
||||
# logger.info("#################%%%%%%#{@game.outputs.first.out_put}")
|
||||
# @games = @myshixun.games.includes(:challenge)
|
||||
@challenges = Challenge.where(:shixun_id => @myshixun.shixun_id)
|
||||
@shixun = @myshixun.shixun
|
||||
# @games_count = @games.count
|
||||
@game_challenge = @game.challenge
|
||||
@had_done = @game.had_done
|
||||
@praise = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?", @game_challenge.id, @game_challenge.class.to_s, User.current.id).first
|
||||
|
|
@ -57,7 +62,7 @@ class GamesController < ApplicationController
|
|||
end
|
||||
end
|
||||
end
|
||||
@content = Base64.urlsafe_decode64(file_content) unless file_content.blank?
|
||||
@content = Base64.decode64(file_content) unless file_content.blank?
|
||||
end
|
||||
if @content.nil?
|
||||
@entries = @repository.entries(@path, @rev)
|
||||
|
|
@ -77,11 +82,13 @@ class GamesController < ApplicationController
|
|||
@had_passed_testsests_error_count = had_test.blank? ? 0 : had_test.select{|had_test| had_test.result == false}.count
|
||||
@had_passed_testsests_hidden_count = had_test.blank? ? 0 : had_test.select{|had_test| had_test.result == true && had_test.is_public == false}.count
|
||||
@had_passed_testsests_public_count = had_test.blank? ? 0 : had_test.select{|had_test| had_test.result == true && had_test.is_public == true}.count
|
||||
@final_score = @game.final_score.to_i
|
||||
@final_score = ((@game.answer_open? || @shixun.status <= 1) ? 0 : @game.final_score.to_i)
|
||||
@had_done = ((@myshixun.games.where(:status => 2).count == @myshixun.games.count && @game_challenge.position == @myshixun.games.count) ? 1 : 0)
|
||||
error_position = had_test.blank? ? nil : had_test.select{|had_test| had_test.result == false}.last
|
||||
logger.info("latest output id is #{error_position.id unless error_position.blank?}")
|
||||
@latest_output = error_position.try(:out_put).gsub("\r\n", "<br />").gsub("\n", "<br />").html_safe unless error_position.try(:out_put).blank?
|
||||
@latest_output = error_position.try(:out_put).gsub(/\n/, '<br />').gsub(/\t/, ' ').to_json unless error_position.try(:out_put).blank?
|
||||
logger.info(@latest_output)
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js
|
||||
|
|
@ -109,7 +116,7 @@ class GamesController < ApplicationController
|
|||
|
||||
def file_update
|
||||
@g = Gitlab.client
|
||||
content = params[:content].strip
|
||||
content = params[:content].try(:strip)
|
||||
code_file = @g.edit_file(@myshixun.gpid, :content => params[:content], :file_path => @path, :branch_name => @rev, :commit_message => "shixun exec")
|
||||
unless code_file.blank?
|
||||
render :json => {:success => "success"}
|
||||
|
|
@ -134,29 +141,50 @@ class GamesController < ApplicationController
|
|||
end
|
||||
|
||||
# status 0: 未提交测评或者提交测评失败后报错;1:中间状态还没返回值;2:返回值并成功
|
||||
# resubmit 唯一随机码,为了区分每一次重新评测结果
|
||||
CODES = %W(1 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 game_build
|
||||
game_challenge = @game.challenge
|
||||
gitUrl = git_repository_url(@myshixun, "Myshixun")
|
||||
shixun = @myshixun.shixun
|
||||
gitUrl = git_myshixun_url_ip(@myshixun, @myshixun.try(:user_id))
|
||||
gitUrl = Base64.encode64(gitUrl)
|
||||
taskId = @game.id
|
||||
jobName = "myshixun_#{@myshixun.id}"
|
||||
resubmit = (@game.status == 2 ? "1" : "0")
|
||||
# 过关后重评不更新状态
|
||||
unless resubmit == "1"
|
||||
code = CODES.sample(8).join
|
||||
# status为2说明是重新评测
|
||||
if @game.status == 2
|
||||
resubmit = "#{code}_#{@myshixun.id}"
|
||||
else
|
||||
@game.update_attributes!(:status => 1)
|
||||
end
|
||||
|
||||
# 过关后重评不更新状态
|
||||
# if resubmit.nil?
|
||||
# @game.update_attributes!(:status => 1)
|
||||
# end
|
||||
|
||||
# 如果shixun有改动,增需要进行后台的一些更新
|
||||
shixun_mod = ShixunModify.where(:myshixun_id => @myshixun.id, :status => 1).first
|
||||
modifyStatus = 0
|
||||
unless shixun_mod.nil?
|
||||
modifyStatus = 1
|
||||
gameInfo = shixun.gameInfo
|
||||
end
|
||||
jenkins_shixuns = Redmine::Configuration['jenkins_shixuns']
|
||||
step = game_challenge.try(:position)
|
||||
params = {:jobNameForInstance => "#{jobName}", :buildID => "#{taskId}", :step => "#{step}", :instanceGitURL => "#{gitUrl}", :instanceChallenge => "#{step}", :resubmit => resubmit}
|
||||
# 注意:这个地方的参数写的时候不能换行
|
||||
params = {:jobNameForInstance => "#{jobName}", :buildID => "#{taskId}", :instanceGitURL => "#{gitUrl}", :instanceChallenge => "#{step}", :resubmit => resubmit, :modifyStatus => "#{modifyStatus}", :gameInfo => "#{gameInfo}"}
|
||||
uri = URI("#{jenkins_shixuns}/jenkins-exec/api/buildJobForInstance")
|
||||
res = uri_exec uri, params
|
||||
logger.info("#####################buildJobForInstance result is #{res}")
|
||||
logger.info("#####################buildJobForInstance params is #{params}")
|
||||
if (res && res['code'] != 0)
|
||||
raise("Build job failed")
|
||||
@message = "实训云平台繁忙(繁忙等级:86)"
|
||||
raise("实训云平台繁忙(繁忙等级:86)")
|
||||
end
|
||||
render :json => {:result => "success"}
|
||||
render :json => {:result => "success", :resubmit => resubmit}
|
||||
rescue
|
||||
unless resubmit == "1"
|
||||
if resubmit.nil?
|
||||
@game.update_attributes!(:status => 0)
|
||||
end
|
||||
#REDO Jenkins服务异常弹框抛出
|
||||
|
|
@ -165,27 +193,43 @@ class GamesController < ApplicationController
|
|||
|
||||
# @myshixun -status 1:完成实训
|
||||
# 全部通关奖励1000分
|
||||
# retry_status不等于0则说明是重新评测,重新评测对以前已产生的结果不造成影响
|
||||
# retry_status 评测的唯一标识,重新评测对以前已产生的结果不造成影响
|
||||
# params[:resubmit] 不为空表示已通过该关后重新评测, 重新评测必须是通过该关后才能执行
|
||||
# @had_done 1 通关所有关
|
||||
def game_status
|
||||
game_challenge = @game.challenge
|
||||
had_done = @game.had_done
|
||||
# 重新评测不需要全部通关效果
|
||||
if @game.retry_status != 0
|
||||
game_status = (@game.retry_status == 2 ? 2 : 0)
|
||||
had_done = 0
|
||||
else
|
||||
if had_done == 1
|
||||
reward_grade(@game.user, @game.id, @game.class, 1000)
|
||||
resubmit_identifier = @game.resubmit_identifier
|
||||
shixun = @myshixun.shixun
|
||||
logger.info("##### resubmit_identifier is #{resubmit_identifier}")
|
||||
if params[:resubmit].blank? # 非重新评测
|
||||
if had_done == 1 # 通过最后一关,即所有关卡
|
||||
@myshixun.update_attribute(:status, 1)
|
||||
else
|
||||
# 通过当前一关
|
||||
if @game.status == 2
|
||||
@game.next_game.update_attribute(:status, 0)
|
||||
end
|
||||
# 通过当前一关
|
||||
if @game.status == 2
|
||||
@game.update_attribute(:end_time, Time.now)
|
||||
game_passed_code(@game.id, game_challenge.try(:path), @myshixun.try(:gpid), 1)
|
||||
if !@game.answer_open && shixun.status > 1
|
||||
reward_grade(@game.user, @game.id, @game.class, game_challenge.score)
|
||||
reward_experience(@game.user, @game.id, @game.class, game_challenge.score)
|
||||
end
|
||||
end
|
||||
game_status = @game.status
|
||||
else # 重新评测
|
||||
if params[:resubmit] == resubmit_identifier # 本次重新评测结果已经返回并存入数据库
|
||||
game_status = (@game.retry_status == 2 ? 2 : 0) # retry_status 2:成功 1: 失败
|
||||
if game_status == 2 && had_done == 1 # 重新评测如果评测成功
|
||||
had_done =1
|
||||
game_passed_code(@game.id, game_challenge.try(:path), @myshixun.try(:gpid), 1)
|
||||
else
|
||||
had_done = 0
|
||||
end
|
||||
else
|
||||
# game_status 在前端有行为判断,2表示通关;0表示失败;1表示评测中的中间状态
|
||||
game_status = 1
|
||||
had_done = 0
|
||||
end
|
||||
end
|
||||
test_sets = game_challenge.test_sets
|
||||
unless test_sets.blank?
|
||||
|
|
@ -201,9 +245,9 @@ class GamesController < ApplicationController
|
|||
@had_passed_testsests_error_count = had_test.blank? ? 0 : had_test.select{|had_test| had_test.result == false}.count
|
||||
@had_passed_testsests_hidden_count = had_test.blank? ? 0 : had_test.select{|had_test| had_test.result == true && had_test.is_public == false}.count
|
||||
@had_passed_testsests_public_count = had_test.blank? ? 0 : had_test.select{|had_test| had_test.result == true && had_test.is_public == true}.count
|
||||
@final_score = @game.final_score.to_i
|
||||
@final_score = ((@game.answer_open? || shixun.status <= 1) ? 0 : @game.final_score.to_i)
|
||||
error_position = had_test.blank? ? nil : had_test.select{|had_test| had_test.result == false}.last
|
||||
@latest_output = error_position.try(:out_put).gsub("\r\n", "<br />").gsub("\n", "<br />") unless error_position.try(:out_put).blank?
|
||||
@latest_output = error_position.try(:out_put).gsub(/\n/, '<br />').gsub(/\t/, ' ') unless error_position.try(:out_put).blank?
|
||||
render :json => {test_sets: total_test_sets,
|
||||
test_sets_count: @test_sets_count,
|
||||
test_sets_hidden_count: @test_sets_hidden_count,
|
||||
|
|
@ -229,6 +273,27 @@ class GamesController < ApplicationController
|
|||
render :json => {status: @game.status, output: "服务器网络异常", results: outputs, had_done: 0}
|
||||
end
|
||||
|
||||
# 获取等待的任务数
|
||||
# 如果没有等待任务页面上将不显示
|
||||
# msg: -1 不存在等待的任务
|
||||
# 如果该方法异常则直接返回0,跳过等待
|
||||
def waiting_info
|
||||
begin
|
||||
jenkins_shixuns = Redmine::Configuration['jenkins_shixuns']
|
||||
params = {:buildID => "#{@game.id}"}
|
||||
uri = URI("#{jenkins_shixuns}/jenkins-exec/api/getWaitingTime")
|
||||
res = uri_exec uri, params
|
||||
if (res && res['code'] != 0)
|
||||
raise("获取等待任务数异常")
|
||||
end
|
||||
task_count = res['msg'].to_i
|
||||
task_count > 0 ? task_count : 0
|
||||
render :json => {task_count: task_count}
|
||||
rescue
|
||||
render :json => {task_count: 0}
|
||||
end
|
||||
end
|
||||
|
||||
# 自动推送下一个任务
|
||||
def next_step
|
||||
render_403 if @game.status != 2
|
||||
|
|
@ -244,52 +309,115 @@ class GamesController < ApplicationController
|
|||
# viewed 1: 直接查看 2:弹框提示将要扣除积分,确定后显示内容 3:弹框提示分数不够
|
||||
def answer
|
||||
challenge = @game.challenge
|
||||
user = User.current
|
||||
@challenge_score = challenge.score.to_i
|
||||
user_score = user.grade.to_i
|
||||
@score = user_score - @challenge_score
|
||||
# 已经开启过
|
||||
@score = User.current.grade.to_i - @challenge_score
|
||||
@answer = challenge.answer
|
||||
if @game.answer_open
|
||||
if challenge.shixun.status < 2 || @game.answer_open
|
||||
@viewed = 1
|
||||
logger.info("1 is #{@viewed}")
|
||||
else
|
||||
if @score >= 0
|
||||
@viewed = 2
|
||||
logger.info("2 is #{@viewed}")
|
||||
else
|
||||
@viewed = 3
|
||||
logger.info("3 is #{@viewed}")
|
||||
end
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def minus_score
|
||||
challenge = @game.challenge
|
||||
@game_challenge = @game.challenge
|
||||
user = User.current
|
||||
challenge_score = challenge.score.to_i
|
||||
user_score = user.grade.to_i
|
||||
@score = user_score - challenge_score
|
||||
@answer = challenge.answer
|
||||
|
||||
user.update_column(:grade, @score)
|
||||
challenge_score = @game_challenge.score.to_i
|
||||
reward_grade(user, @game.id, 'Answer', -challenge_score)
|
||||
@answer = @game_challenge.answer
|
||||
@game.update_column(:answer_open, true)
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def refresh_game_list
|
||||
myshixun_id = params[:myshixun_id]
|
||||
@myshixun = Myshixun.find_by_identifier(myshixun_id)
|
||||
@challenges = Challenge.where(:shixun_id => @myshixun.shixun_id)
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def reset_original_code
|
||||
begin
|
||||
@shixun = @myshixun.shixun
|
||||
@g = Gitlab.client
|
||||
game_code = GameCode.where(:game_id => @game.id).first
|
||||
content = game_code.try(:original_code)
|
||||
if content.nil?
|
||||
raise("初始代码为空,代码重置失败")
|
||||
end
|
||||
@path = params[:path]
|
||||
@rev = @rev.nil? ? "master" : @rev
|
||||
message = "file reset"
|
||||
update_gitlab_file(content, @path, @rev, message)
|
||||
file_content = @g.files(@myshixun.gpid, @path, @rev).content
|
||||
@content = Base64.decode64(file_content) unless file_content.blank?
|
||||
if @content.nil?
|
||||
raise("初始代码为空,代码重置失败")
|
||||
# @entries = @repository.entries(@path, @rev)
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
rescue Exception => e
|
||||
@error_messages = e.message
|
||||
end
|
||||
end
|
||||
|
||||
def reset_new_code
|
||||
begin
|
||||
@shixun = @myshixun.shixun
|
||||
@g = Gitlab.client
|
||||
game_code = GameCode.where(:game_id => @game.id).first
|
||||
content = game_code.try(:new_code)
|
||||
if content.nil?
|
||||
raise("示例代码为空,代码重置失败")
|
||||
end
|
||||
@path = params[:path]
|
||||
@rev = @rev.nil? ? "master" : @rev
|
||||
message = "file reset"
|
||||
update_gitlab_file(content, @path, @rev, message)
|
||||
file_content = @g.files(@myshixun.gpid, @path, @rev).content
|
||||
@content = Base64.decode64(file_content) unless file_content.blank?
|
||||
if @content.nil?
|
||||
raise("示例代码为空,代码重置失败")
|
||||
# @entries = @repository.entries(@path, @rev)
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
rescue Exception => e
|
||||
@error_messages = e.message
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def update_gitlab_file content, path, rev, message
|
||||
code_file = @g.edit_file(@myshixun.gpid, :content => content, :file_path => path, :branch_name => rev, :commit_message => "#{message}")
|
||||
if code_file.nil?
|
||||
raise("网络异常,文件更新失败")
|
||||
end
|
||||
end
|
||||
|
||||
def test_set_static_data test_sets
|
||||
test_result = []
|
||||
unless test_sets.blank?
|
||||
test_sets.each do |test_set|
|
||||
output = Output.where(:game_id => @game.id, :test_set_position => test_set.position).first
|
||||
actual_output = output.try(:actual_output)
|
||||
actual_output = (output.try(:actual_output).gsub(/\n/, '<br />').gsub(/\t/, ' ') unless output.try(:actual_output).blank?)
|
||||
result = output.try(:result)
|
||||
public_result = {:is_public => (test_set.is_public ? 1 : 0), :result => result, :input => test_set.input,
|
||||
:actual_output => actual_output, :output => test_set.output}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,236 @@
|
|||
class HomeworkBankController < ApplicationController
|
||||
before_filter :require_login, :only => [:index, :show, :new, :create, :edit, :update, :destroy, :destroy_all, :choose_user_course, :send_h_bank_to_course]
|
||||
before_filter :find_homework_bank, :only => [:show, :edit, :update, :destroy, :set_public]
|
||||
|
||||
def index
|
||||
@order,@b_sort = params[:order] || "updated_at",params[:sort] || "desc"
|
||||
@user = User.current
|
||||
@r_sort = @b_sort == "desc" ? "asc" : "desc"
|
||||
@search = params[:search]
|
||||
if(params[:type].blank? || params[:type] == "1") #我的题库
|
||||
@homeworks = @user.homework_banks.where("name like ?", "%#{@search}%")
|
||||
elsif params[:type] == "2" #公共题库
|
||||
@homeworks = HomeworkBank.where(:is_public => true).where("name like ?", "%#{@search}%")
|
||||
end
|
||||
if params[:property]
|
||||
@property = params[:property].to_i
|
||||
@homeworks = @homeworks.where(:homework_type => params[:property].to_i)
|
||||
end
|
||||
@homeworks = @homeworks.reorder("#{@order} #{@b_sort}")
|
||||
@type = params[:type] ? params[:type] : '1'
|
||||
@limit = 15
|
||||
@is_remote = true
|
||||
@hw_count = @homeworks.count
|
||||
@hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1
|
||||
@offset ||= @hw_pages.offset
|
||||
@homeworks = paginateHelper @homeworks,15
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html {render :layout => 'base_edu'}
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@is_admin = User.current == @homework.user || User.current.admin?
|
||||
respond_to do |format|
|
||||
format.html {render :layout => 'base_edu'}
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@homework_type = params[:homework_type].to_i
|
||||
@homework = HomeworkBank.new
|
||||
respond_to do |format|
|
||||
format.html{render :layout => 'base_edu'}
|
||||
end
|
||||
end
|
||||
|
||||
# 新建实训作业
|
||||
def shixuns
|
||||
search = params[:search]
|
||||
@homework = HomeworkBank.new
|
||||
@shixuns = Shixun.where(:status => 2).where("name like ?", "%#{search}%")
|
||||
@shixuns_count = @shixuns.count
|
||||
@limit = 10
|
||||
@is_remote = true
|
||||
@shixun_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1
|
||||
@offset ||= @shixun_pages.offset
|
||||
@shixuns = paginateHelper @shixuns, @limit
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
if params[:homework_bank] || params[:shixun_homework]
|
||||
homework = HomeworkBank.new
|
||||
if params[:shixun_homework]
|
||||
shixun = Shixun.find(params[:shixun_homework])
|
||||
homework.name = shixun.name
|
||||
homework.description = shixun.description
|
||||
else
|
||||
homework.name = params[:homework_bank][:name]
|
||||
homework.description = params[:homework_bank][:description]
|
||||
homework.reference_answer = params[:homework_bank][:reference_answer]
|
||||
homework.save_attachments(params[:attachments])
|
||||
render_attachment_warning_if_needed(homework)
|
||||
end
|
||||
homework.is_public = 0
|
||||
homework.quotes = 0
|
||||
homework.homework_type = params[:shixun_homework] ? 4 : (params[:homework_type].to_i || 1)
|
||||
homework.user_id = User.current.id
|
||||
homework.syllabus_id = params[:syllabus_id] if params[:syllabus_id] && params[:syllabus_id] != '0'
|
||||
|
||||
#编程作业相关属性
|
||||
if homework.homework_type == 2
|
||||
homework.language = params[:language_type].to_i
|
||||
|
||||
sample_inputs = params[:sample][:input]
|
||||
if Array === sample_inputs
|
||||
sample_inputs.each_with_index do |val, i|
|
||||
homework.homework_bank_samples << HomeworkBankSample.new(
|
||||
input: val,
|
||||
output: params[:sample][:output][i]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
inputs = params[:program][:input]
|
||||
if Array === inputs
|
||||
inputs.each_with_index do |val, i|
|
||||
homework.homework_bank_tests << HomeworkBankTest.new(
|
||||
input: val,
|
||||
output: params[:program][:output][i]
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#分组作业
|
||||
if homework.homework_type == 3
|
||||
homework.min_num = params[:min_num].to_i
|
||||
homework.max_num = params[:max_num].to_i
|
||||
end
|
||||
|
||||
if homework.save
|
||||
if homework.homework_type == 4
|
||||
HomeworkBankShixun.create(:homework_bank_id => homework.id, :shixun_id => shixun.id)
|
||||
end
|
||||
redirect_to homework_bank_path(homework)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@homework_type = @homework.homework_type
|
||||
respond_to do |format|
|
||||
format.html{render :layout => 'base_edu'}
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if params[:homework_bank]
|
||||
@homework.name = params[:homework_bank][:name]
|
||||
@homework.description = params[:homework_bank][:description]
|
||||
@homework.reference_answer = params[:homework_bank][:reference_answer]
|
||||
@homework.syllabus_id = params[:syllabus_id] ? (params[:syllabus_id] == '0' ? nil : params[:syllabus_id].to_i) : nil
|
||||
@homework.save_attachments(params[:attachments])
|
||||
render_attachment_warning_if_needed(@homework)
|
||||
|
||||
#编程作业相关属性
|
||||
if @homework.homework_type == 2
|
||||
@homework.language = params[:language_type].to_i if params[:language_type]
|
||||
|
||||
@homework.homework_bank_samples.delete_all if params[:sample]
|
||||
sample_inputs = params[:sample][:input] if params[:sample]
|
||||
if Array === sample_inputs
|
||||
sample_inputs.each_with_index do |val, i|
|
||||
@homework.homework_bank_samples << HomeworkBankSample.new(
|
||||
input: val,
|
||||
output: params[:sample][:output][i]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@homework.homework_bank_tests.delete_all if params[:program]
|
||||
inputs = params[:program][:input] if params[:program]
|
||||
if Array === inputs
|
||||
inputs.each_with_index do |val, i|
|
||||
@homework.homework_bank_tests << HomeworkBankTest.new(
|
||||
input: val,
|
||||
output: params[:program][:output][i]
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#分组作业
|
||||
if @homework.homework_type == 3
|
||||
@homework.min_num = params[:min_num].to_i if params[:min_num]
|
||||
@homework.max_num = params[:max_num].to_i if params[:max_num]
|
||||
end
|
||||
|
||||
if @homework.save
|
||||
redirect_to homework_bank_path(@homework)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@homework.homework_commons.update_all(:homework_bank_id => nil)
|
||||
@homework.destroy
|
||||
redirect_to homework_bank_index_path()
|
||||
end
|
||||
|
||||
def destroy_all
|
||||
if params[:check_homework_bank] && !params[:check_homework_bank].blank?
|
||||
params[:check_homework_bank].each do |hb_id|
|
||||
homework = HomeworkBank.find hb_id
|
||||
if homework && homework.user == User.current
|
||||
HomeworkCommon.where(:homework_bank_id => homework.id).update_all(:homework_bank_id => nil)
|
||||
homework.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
redirect_to homework_bank_index_path
|
||||
end
|
||||
|
||||
def choose_user_course
|
||||
if !params[:search].nil?
|
||||
search = "%#{params[:search].to_s.strip.downcase}%"
|
||||
@courses = User.current.courses.where("is_delete = 0 and is_end = 0 and (#{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p)",:p=>search).select{ |course| User.current.has_teacher_role(course)}
|
||||
else
|
||||
@courses = User.current.courses.where("is_delete = 0 and is_end = 0").select{ |course| User.current.has_teacher_role(course)}
|
||||
end
|
||||
@homework_ids = params[:check_homework_bank] if params[:check_homework_bank]
|
||||
@search = params[:search]
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def send_h_bank_to_course
|
||||
course = Course.find params[:course_id]
|
||||
if course
|
||||
params[:homework_id].each do |homework_id|
|
||||
homework = HomeworkBank.find homework_id
|
||||
quote_homework_bank homework, course
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def set_public
|
||||
@homework.update_attributes(:is_public => true)
|
||||
respond_to do |format|
|
||||
format.html{ redirect_to homework_bank_path(@homework) }
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_homework_bank
|
||||
@homework = HomeworkBank.find params[:id]
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
|
@ -8,34 +8,50 @@ class HomeworkCommonController < ApplicationController
|
|||
before_filter :find_course, :only => [:index,:new,:create]
|
||||
before_filter :find_homework, :only => [:edit,:update,:alert_anonymous_comment,:start_anonymous_comment,:stop_anonymous_comment,:destroy,:start_evaluation_set,
|
||||
:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment,:alert_open_student_works,:open_student_works,
|
||||
:set_score_open,:alert_score_open_modal,:add_to_homework_bank,:publish_homework]
|
||||
:set_score_open,:alert_score_open_modal,:add_to_homework_bank,:publish_homework,:setting,:set_public,:homework_setting]
|
||||
before_filter :teacher_of_course, :only => [:new, :create, :edit, :update, :destroy, :start_anonymous_comment, :stop_anonymous_comment, :alert_anonymous_comment,
|
||||
:start_evaluation_set,:set_evaluation_attr,:score_rule_set,:alert_forbidden_anonymous_comment,:alert_open_student_works,
|
||||
:open_student_works,:add_to_homework_bank,:publish_homework]
|
||||
before_filter :member_of_course, :only => [:index]
|
||||
before_filter :member_of_course, :only => [:index,:setting]
|
||||
|
||||
def index
|
||||
#unless params[:page]
|
||||
# update_homework_time(@course.homework_commons)
|
||||
#end
|
||||
search = "%#{params[:search].to_s.strip.downcase}%"
|
||||
@new_homework = HomeworkCommon.new
|
||||
@new_homework.homework_detail_manual = HomeworkDetailManual.new
|
||||
@new_homework.course = @course
|
||||
@search = "#{params[:search].to_s.strip.downcase}" if params[:search]
|
||||
@order = params[:order]
|
||||
@page = params[:page] ? params[:page].to_i + 1 : 0
|
||||
@homework_type = params[:homework_type].to_i
|
||||
@is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course))
|
||||
if @is_teacher
|
||||
#@homeworks = @course.homework_commons.order("created_at desc").limit(10).offset(@page * 10)
|
||||
@homework_commons = @course.homework_commons.where("name like '%#{search}%'").order("created_at desc")
|
||||
if @search
|
||||
@homework_commons = @course.homework_commons.where(:homework_type => @homework_type).where("name like '%#{@search}%'")
|
||||
else
|
||||
#@homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at desc").limit(10).offset(@page * 10)
|
||||
@homework_commons = @course.homework_commons.where("name like '%#{search}%' and publish_time <= '#{Time.now}'").order("created_at desc")
|
||||
@homework_commons = @course.homework_commons.where(:homework_type => @homework_type)
|
||||
end
|
||||
if @order.blank?
|
||||
if @is_teacher
|
||||
@homework_commons = @homework_commons.order("created_at desc")
|
||||
else
|
||||
@homework_commons = @homework_commons.where("publish_time <= '#{Time.now}'").order("created_at desc")
|
||||
end
|
||||
else
|
||||
case @order
|
||||
when '1'
|
||||
@homework_commons = @homework_commons.includes(:homework_detail_manual).where("homework_detail_manuals.comment_status = #{@order} and end_time > '#{Time.now}'").order("homework_commons.created_at desc")
|
||||
when '3'
|
||||
@homework_commons = @homework_commons.includes(:homework_detail_manual).where("homework_detail_manuals.comment_status = #{@order} and homework_detail_manuals.evaluation_end > '#{Time.now}'").order("homework_commons.created_at desc")
|
||||
when '4'
|
||||
@homework_commons = @homework_commons.includes(:homework_detail_manual).where("(homework_detail_manuals.comment_status = #{@order} and homework_detail_manuals.appeal_time > '#{Time.now}')").order("homework_commons.created_at desc")
|
||||
when '5'
|
||||
@homework_commons = @homework_commons.includes(:homework_detail_manual).where("(homework_detail_manuals.comment_status = #{@order} and archive_time > '#{Time.now}')").order("homework_commons.created_at desc")
|
||||
else
|
||||
@homework_commons = @homework_commons.includes(:homework_detail_manual).where("homework_detail_manuals.comment_status = #{@order}").order("homework_commons.created_at desc")
|
||||
end
|
||||
end
|
||||
#update_homework_time @homework_commons
|
||||
@is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher))
|
||||
@is_new = params[:is_new]
|
||||
|
||||
@homeworks = paginateHelper @homework_commons,10
|
||||
@homeworks = paginateHelper @homework_commons,15
|
||||
#设置at已读
|
||||
ids = @homeworks.inject([]) do |ids, homework|
|
||||
jids = homework.journals_for_messages.map(&:id)
|
||||
|
|
@ -58,33 +74,286 @@ class HomeworkCommonController < ApplicationController
|
|||
|
||||
#新建作业,在个人作业列表创建作业
|
||||
def new
|
||||
render_404
|
||||
@homework_type = params[:homework_type].to_i
|
||||
@homework = HomeworkCommon.new
|
||||
@ref_answer = HomeworkReferenceAnswer.new
|
||||
respond_to do |format|
|
||||
format.html{render :layout => 'base_edu'}
|
||||
end
|
||||
end
|
||||
|
||||
# 新建实训作业
|
||||
def shixuns
|
||||
search = params[:search]
|
||||
@course = Course.find(params[:course])
|
||||
@homework = HomeworkCommon.new
|
||||
@shixuns = Shixun.where(:status => 2).where("name like ?", "%#{search}%")
|
||||
@shixuns_count = @shixuns.count
|
||||
@limit = 8
|
||||
@is_remote = true
|
||||
@shixun_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1
|
||||
@offset ||= @shixun_pages.offset
|
||||
@shixuns = paginateHelper @shixuns, @limit
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
#新建作业,在个人作业列表创建作业
|
||||
def create
|
||||
redirect_to user_homeworks_user_path(User.current.id)
|
||||
if params[:homework_common] || params[:shixun_homework]
|
||||
homework = HomeworkCommon.new
|
||||
if params[:shixun_homework]
|
||||
shixun = Shixun.find(params[:shixun_homework])
|
||||
homework.name = shixun.name
|
||||
homework.description = shixun.description
|
||||
else
|
||||
homework.name = params[:homework_common][:name]
|
||||
homework.description = params[:homework_common][:description]
|
||||
homework.reference_answer = params[:homework_common][:reference_answer]
|
||||
homework.save_attachments(params[:attachments])
|
||||
render_attachment_warning_if_needed(homework)
|
||||
end
|
||||
homework.anonymous_comment = 1
|
||||
homework.homework_type = params[:shixun_homework] ? 4 : (params[:homework_type].to_i || 1)
|
||||
homework.late_penalty = 0
|
||||
homework.teacher_priority = 1
|
||||
homework.user_id = User.current.id
|
||||
homework.course_id = params[:course]
|
||||
|
||||
|
||||
homework_detail_manual = HomeworkDetailManual.new
|
||||
homework_detail_manual.te_proportion = 1.0
|
||||
homework_detail_manual.ta_proportion = 0
|
||||
homework_detail_manual.comment_status = 0
|
||||
|
||||
homework_detail_manual.evaluation_num = 0
|
||||
homework_detail_manual.absence_penalty = 0
|
||||
homework.homework_detail_manual = homework_detail_manual
|
||||
|
||||
#编程作业相关属性
|
||||
if homework.homework_type == 2
|
||||
homework_detail_programing = HomeworkDetailPrograming.new
|
||||
homework.homework_detail_programing = homework_detail_programing
|
||||
homework_detail_programing.ta_proportion = 0
|
||||
homework_detail_programing.language = params[:language_type].to_i
|
||||
|
||||
sample_inputs = params[:sample][:input]
|
||||
if Array === sample_inputs
|
||||
sample_inputs.each_with_index do |val, i|
|
||||
homework.homework_samples << HomeworkSample.new(
|
||||
input: val,
|
||||
output: params[:sample][:output][i]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
inputs = params[:program][:input]
|
||||
if Array === inputs
|
||||
inputs.each_with_index do |val, i|
|
||||
homework.homework_tests << HomeworkTest.new(
|
||||
input: val,
|
||||
output: params[:program][:output][i]
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#分组作业
|
||||
if homework.homework_type == 3
|
||||
homework_detail_group = HomeworkDetailGroup.new
|
||||
homework.homework_detail_group = homework_detail_group
|
||||
homework_detail_group.min_num = params[:min_num].to_i
|
||||
homework_detail_group.max_num = params[:max_num].to_i
|
||||
homework_detail_group.base_on_project = 0
|
||||
end
|
||||
|
||||
if homework.save
|
||||
homework_detail_manual.save if homework_detail_manual
|
||||
homework_detail_programing.save if homework_detail_programing
|
||||
homework_detail_group.save if homework_detail_group
|
||||
|
||||
if homework.homework_type != 4 && homework_detail_manual.comment_status == 1
|
||||
create_works_list homework
|
||||
elsif homework.homework_type == 4
|
||||
HomeworkCommonsShixuns.create(:homework_common_id => homework.id, :shixun_id => shixun.id)
|
||||
end
|
||||
|
||||
if params[:quotes] && !params[:quotes].blank?
|
||||
quotes_homework = HomeworkBank.find params[:quotes].to_i
|
||||
quotes_homework.update_column(:quotes, quotes_homework.quotes+1)
|
||||
homework.update_attributes(:homework_bank_id => quotes_homework.id)
|
||||
end
|
||||
|
||||
# if params[:add_to_bank]
|
||||
# homework_bank = add_to_homework_bank_f homework
|
||||
# homework_bank.save
|
||||
# homework.update_attributes(:homework_bank_id => homework_bank.id)
|
||||
# end
|
||||
redirect_to setting_homework_common_path(homework, :is_new => 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def setting
|
||||
@is_new = params[:is_new].to_i if params[:is_new]
|
||||
@is_empty = @homework.publish_time.nil?
|
||||
@is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course))
|
||||
respond_to do |format|
|
||||
format.html{render :layout => 'base_edu'}
|
||||
end
|
||||
end
|
||||
|
||||
def homework_setting
|
||||
@homework.publish_time = params[:homework_publish_time] if params[:homework_publish_time]
|
||||
@homework.end_time = params[:homework_end_time] if params[:homework_end_time]
|
||||
@homework.archive_time = params[:homework_archive_time] if params[:homework_archive_time]
|
||||
if @homework.archive_time < Time.now && @homework_detail_manual.comment_status < 6
|
||||
@homework_detail_manual.comment_status = 6
|
||||
elsif @homework.archive_time > Time.now && @homework_detail_manual.comment_status == 6
|
||||
@homework_detail_manual.comment_status = 5
|
||||
end
|
||||
|
||||
if params[:homework_allow_late] == '1'
|
||||
@homework.allow_late = true
|
||||
@homework.late_penalty = params[:homework_late_penalty].to_i
|
||||
else
|
||||
@homework.allow_late = false
|
||||
@homework.late_penalty = 0
|
||||
end
|
||||
|
||||
anonymous_comment = @homework.anonymous_comment
|
||||
absence_penalty = @homework_detail_manual.absence_penalty
|
||||
appeal_penalty = @homework_detail_manual.appeal_penalty
|
||||
if @homework_detail_manual.comment_status < 3
|
||||
if params[:homework_anonymous_comment]
|
||||
@homework.anonymous_comment = 0
|
||||
@homework_detail_manual.evaluation_start = params[:homework_evaluation_start] if params[:homework_evaluation_start]
|
||||
@homework_detail_manual.evaluation_end = params[:homework_evaluation_end] if params[:homework_evaluation_end]
|
||||
@homework_detail_manual.evaluation_num = params[:homework_evaluation_num] if params[:homework_evaluation_num]
|
||||
@homework_detail_manual.absence_penalty = params[:homework_absence_penalty] if params[:homework_absence_penalty]
|
||||
else
|
||||
@homework.anonymous_comment = 1
|
||||
@homework_detail_manual.evaluation_start = nil
|
||||
@homework_detail_manual.evaluation_end = nil
|
||||
@homework_detail_manual.evaluation_num = 0
|
||||
@homework_detail_manual.absence_penalty = 0
|
||||
end
|
||||
else
|
||||
@homework_detail_manual.evaluation_end = params[:homework_evaluation_end] if params[:homework_evaluation_end]
|
||||
@homework_detail_manual.evaluation_num = params[:homework_evaluation_num] if params[:homework_evaluation_num]
|
||||
@homework_detail_manual.absence_penalty = params[:homework_absence_penalty] if params[:homework_absence_penalty]
|
||||
end
|
||||
if anonymous_comment != @homework.anonymous_comment
|
||||
@homework_detail_manual.te_proportion = 1
|
||||
@homework_detail_manual.ta_proportion = 0
|
||||
@homework_detail_programing.ta_proportion = 0 if @homework_detail_programing
|
||||
end
|
||||
if @homework_detail_manual.comment_status < 4
|
||||
if params[:homework_anonymous_appeal]
|
||||
@homework.anonymous_appeal = 1
|
||||
@homework_detail_manual.appeal_time = params[:homework_appeal_time] if params[:homework_appeal_time]
|
||||
@homework_detail_manual.appeal_penalty = params[:homework_appeal_penalty] if params[:homework_appeal_penalty]
|
||||
else
|
||||
@homework.anonymous_appeal = 0
|
||||
@homework_detail_manual.appeal_time = nil
|
||||
@homework_detail_manual.appeal_penalty = 0
|
||||
end
|
||||
else
|
||||
@homework_detail_manual.appeal_time = params[:homework_appeal_time] if params[:homework_appeal_time]
|
||||
@homework_detail_manual.appeal_penalty = params[:homework_appeal_penalty] if params[:homework_appeal_penalty]
|
||||
end
|
||||
if absence_penalty != @homework_detail_manual.absence_penalty && @homework_detail_manual.comment_status >= 4
|
||||
all_dis_eva = StudentWorksEvaluationDistribution.where(:student_work_id => @homework.student_works.map(&:id))
|
||||
has_sw_count = all_dis_eva.select("distinct user_id").count
|
||||
anon_count = all_dis_eva.count / has_sw_count
|
||||
@homework.student_works.where("work_status != 0").each do |student_work|
|
||||
absence_penalty_count = student_work.user.student_works_evaluation_distributions.where(:student_work_id => @homework.student_works.map(&:id)).count - student_work.user.student_works_scores.where(:student_work_id => @homework.student_works.map(&:id), :reviewer_role => 3).count
|
||||
student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0
|
||||
student_work.save
|
||||
end
|
||||
end
|
||||
if appeal_penalty != @homework_detail_manual.appeal_penalty && @homework_detail_manual.comment_status >= 4
|
||||
@homework.student_works.each do |student_work|
|
||||
appeal_penalty_count = student_work.user.student_works_scores.where(:student_work_id => @homework.student_works.map(&:id), :appeal_status => 3).count
|
||||
student_work.appeal_penalty = appeal_penalty_count > 0 ? appeal_penalty_count * @homework_detail_manual.absence_penalty : 0
|
||||
student_work.save
|
||||
end
|
||||
end
|
||||
|
||||
if params[:homework_ta_mode] && @homework_detail_manual.ta_mode.to_i != params[:homework_ta_mode].to_i
|
||||
@homework_detail_manual.ta_mode = params[:ta_mode].to_i
|
||||
@homework_detail_manual.save
|
||||
if @homework_detail_manual.ta_mode == 1
|
||||
@homework.student_works.where("work_status != 0").each do |student_work|
|
||||
ts_score = StudentWorksScore.find_by_sql("SELECT AVG(score) AS score FROM (SELECT * FROM (SELECT * FROM student_works_scores WHERE student_work_id = #{student_work.id} AND reviewer_role = 2 AND score IS NOT NULL ORDER BY created_at DESC) AS t GROUP BY user_id) AS a")
|
||||
student_work.teaching_asistant_score = ts_score.first.score.nil? ? nil : ts_score.first.score.try(:round, 2).to_f
|
||||
student_work.save
|
||||
end
|
||||
else
|
||||
@homework.student_works.where("work_status != 0").each do |student_work|
|
||||
ts_score = StudentWorksScore.where("student_work_id = #{student_work.id} AND reviewer_role = 2 AND score IS NOT NULL").order("created_at DESC")
|
||||
student_work.teaching_asistant_score = ts_score.first.nil? ? nil : ts_score.first.score
|
||||
student_work.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if params[:homework_final_mode] && params[:homework_final_mode].to_i != @homework_detail_manual.final_mode
|
||||
@homework_detail_manual.final_mode = params[:homework_final_mode].to_i
|
||||
if params[:homework_final_mode].to_i == 0
|
||||
@homework_detail_manual.te_proportion = params[:te_proportion]
|
||||
@homework_detail_manual.ta_proportion = params[:ta_proportion]
|
||||
@homework_detail_programing.ta_proportion = params[:sy_proportion] if @homework_detail_programing
|
||||
@homework_detail_programing.save if @homework_detail_programing
|
||||
end
|
||||
@homework_detail_manual.save if @homework_detail_manual
|
||||
@homework.save
|
||||
@homework = HomeworkCommon.find @homework.id
|
||||
@homework.student_works.each do |student_work|
|
||||
set_final_score @homework,student_work
|
||||
student_work.save
|
||||
end
|
||||
elsif params[:homework_final_mode] && @homework_detail_manual.final_mode == 0
|
||||
if (params[:te_proportion] && params[:te_proportion].to_s != @homework_detail_manual.te_proportion.to_s) || (params[:ta_proportion] && params[:ta_proportion].to_s != @homework_detail_manual.ta_proportion.to_s) || (@homework_detail_programing && @homework_detail_programing.ta_proportion.to_s != params[:sy_proportion].to_s)
|
||||
@homework_detail_manual.te_proportion = params[:te_proportion]
|
||||
@homework_detail_manual.ta_proportion = params[:ta_proportion]
|
||||
@homework_detail_programing.ta_proportion = params[:sy_proportion] if @homework_detail_programing
|
||||
|
||||
@homework_detail_manual.save if @homework_detail_manual
|
||||
@homework_detail_programing.save if @homework_detail_programing
|
||||
@homework.save
|
||||
@homework = HomeworkCommon.find @homework.id
|
||||
@homework.student_works.each do |student_work|
|
||||
set_final_score @homework,student_work
|
||||
student_work.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if @homework.homework_type == 4
|
||||
@homework.score_open = params[:homework_score_open] ? 1 : 0
|
||||
else
|
||||
@homework.work_public = params[:homework_work_public] ? 1 : 0
|
||||
@homework.score_open = params[:homework_score_open] ? 1 : 0
|
||||
@homework.answer_public = params[:homework_answer_public] ? 1 : 0
|
||||
end
|
||||
@homework.save
|
||||
@homework_detail_manual.save
|
||||
redirect_to setting_homework_common_path(@homework)
|
||||
end
|
||||
|
||||
def edit
|
||||
@user = User.current
|
||||
@hw_status = params[:hw_status].to_i
|
||||
@is_manage = params[:is_manage]
|
||||
if @hw_status != 1
|
||||
@left_nav_type = 3
|
||||
respond_to do |format|
|
||||
format.html{render :layout => 'base_courses'}
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html{render :layout => 'base_course_community'}
|
||||
end
|
||||
@homework_type = @homework.homework_type
|
||||
respond_to do |format|
|
||||
format.html{render :layout => 'base_edu'}
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if params[:homework_common]
|
||||
is_update = @homework.name != params[:homework_common][:name] || @homework.description != params[:homework_common][:description] || params[:homework_type].to_i != @homework.homework_type
|
||||
is_update = @homework.name != params[:homework_common][:name] || @homework.description != params[:homework_common][:description] || @homework.reference_answer != params[:homework_common][:reference_answer]
|
||||
if params[:homework_type].to_i == 2
|
||||
is_update = is_update || params[:language_type] != @homework.homework_detail_programing.language
|
||||
if !is_update && params[:sample] && params[:program]
|
||||
|
|
@ -98,92 +367,8 @@ class HomeworkCommonController < ApplicationController
|
|||
|
||||
@homework.name = params[:homework_common][:name]
|
||||
@homework.description = params[:homework_common][:description]
|
||||
homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new
|
||||
if params[:homework_common][:end_time] != ""
|
||||
if params[:homework_common][:publish_time] == ""
|
||||
@homework.publish_time = Time.now
|
||||
else
|
||||
@homework.publish_time = params[:homework_common][:publish_time]
|
||||
end
|
||||
param_end_time = Time.parse(params[:homework_common][:end_time]).to_s
|
||||
homework_end_time = @homework.end_time ? @homework.end_time.to_s : ''
|
||||
if homework_end_time != param_end_time
|
||||
if homework_end_time > param_end_time
|
||||
@homework.student_works.where("work_status = 1").each do |st|
|
||||
if param_end_time < st.commit_time
|
||||
st.late_penalty = @homework.late_penalty
|
||||
st.work_status = 2
|
||||
st.save
|
||||
#更新CourseHomeworkStatistics中学生的迟交作品数
|
||||
course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(@homework.course_id, st.user_id)
|
||||
course_statistics.update_attribute('late_commit_work_num', course_statistics.late_commit_work_num + 1) if course_statistics
|
||||
end
|
||||
end
|
||||
else
|
||||
@homework.student_works.where("work_status = 2").each do |st|
|
||||
if param_end_time >= Time.parse(st.commit_time.to_s).strftime("%Y-%m-%d")
|
||||
st.late_penalty = 0
|
||||
st.work_status = 1
|
||||
st.save
|
||||
#更新CourseHomeworkStatistics中学生的迟交作品数
|
||||
course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(@homework.course_id, st.user_id)
|
||||
course_statistics.update_attribute('late_commit_work_num', (course_statistics.late_commit_work_num - 1) < 0 ? 0 : (course_statistics.late_commit_work_num - 1)) if course_statistics
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@homework.end_time = params[:homework_common][:end_time] || Time.now
|
||||
|
||||
status = false
|
||||
if @homework.publish_time > Time.now && homework_detail_manual.comment_status == 1
|
||||
homework_detail_manual.comment_status = 0
|
||||
@homework.student_works.destroy_all
|
||||
#更新CourseHomeworkStatistics中每个学生的未交作品数
|
||||
@homework.course.student.each do |student|
|
||||
course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(@homework.course_id, student.student_id)
|
||||
course_statistics.update_attribute('un_commit_work_num', (course_statistics.un_commit_work_num - 1) < 0 ? 0 : (course_statistics.un_commit_work_num - 1)) if course_statistics
|
||||
end
|
||||
elsif @homework.publish_time <= Time.now && homework_detail_manual.comment_status == 0
|
||||
homework_detail_manual.comment_status = 1
|
||||
create_works_list @homework if params[:homework_type].to_i != 3
|
||||
status = true
|
||||
#更新CourseHomeworkStatistics中每个学生的未交作品数
|
||||
@homework.course.student.each do |student|
|
||||
course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(@homework.course_id, student.student_id)
|
||||
course_statistics.update_attribute('un_commit_work_num', course_statistics.un_commit_work_num + 1) if course_statistics
|
||||
end
|
||||
end
|
||||
|
||||
eval_start = homework_detail_manual.evaluation_start
|
||||
if eval_start.nil? || (Time.parse(eval_start.to_s) <= @homework.end_time && homework_detail_manual.comment_status <= 1)
|
||||
homework_detail_manual.evaluation_start = (@homework.end_time + 7*24*60*60).strftime("%Y-%m-%d")
|
||||
homework_detail_manual.evaluation_end = homework_detail_manual.evaluation_start + 7
|
||||
end
|
||||
end
|
||||
|
||||
if params[:homework_type] && params[:homework_type].to_i != @homework.homework_type
|
||||
if @homework.homework_type == 2
|
||||
@homework.homework_detail_programing.destroy if @homework.homework_detail_programing
|
||||
@homework.homework_tests.destroy_all
|
||||
elsif @homework.homework_type == 3
|
||||
@homework.homework_detail_group.destroy if @homework.homework_detail_group
|
||||
create_works_list @homework if homework_detail_manual.comment_status > 0 && @homework.student_works.empty?
|
||||
end
|
||||
if params[:homework_type].to_i == 3
|
||||
@homework.student_works.destroy_all
|
||||
end
|
||||
@homework.homework_type = params[:homework_type].to_i
|
||||
end
|
||||
anonymous = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment].to_i : 1
|
||||
if anonymous != @homework.anonymous_comment
|
||||
if anonymous == 1
|
||||
homework_detail_manual.ta_proportion = @homework.homework_type == 2 ? 0.4 : 1.0
|
||||
else
|
||||
homework_detail_manual.ta_proportion = @homework.homework_type == 2 ? 0.3 : 0.6
|
||||
end
|
||||
end
|
||||
|
||||
@homework.save_attachments(params[:attachments])
|
||||
@homework.reference_answer = params[:homework_common][:reference_answer]
|
||||
render_attachment_warning_if_needed(@homework)
|
||||
|
||||
#编程作业相关属性
|
||||
|
|
@ -191,13 +376,6 @@ class HomeworkCommonController < ApplicationController
|
|||
@homework.homework_detail_programing ||= HomeworkDetailPrograming.new
|
||||
@homework_detail_programing = @homework.homework_detail_programing
|
||||
@homework_detail_programing.language = params[:language_type].to_i if params[:language_type]
|
||||
if anonymous != @homework.anonymous_comment
|
||||
if anonymous == 1
|
||||
@homework_detail_programing.ta_proportion = 0.6
|
||||
else
|
||||
@homework_detail_programing.ta_proportion = 0.5
|
||||
end
|
||||
end
|
||||
|
||||
@homework.homework_samples.delete_all if params[:sample]
|
||||
sample_inputs = params[:sample][:input] if params[:sample]
|
||||
|
|
@ -231,15 +409,7 @@ class HomeworkCommonController < ApplicationController
|
|||
@homework_detail_group.base_on_project = params[:base_on_project] ? 1 : 0
|
||||
end
|
||||
|
||||
if anonymous != @homework.anonymous_comment
|
||||
@homework.student_works.where("work_status != 0").each do |student_work|
|
||||
student_work.save
|
||||
end
|
||||
end
|
||||
|
||||
@homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment].to_i : 1
|
||||
if @homework.save
|
||||
homework_detail_manual.save if homework_detail_manual
|
||||
@homework_detail_programing.save if @homework_detail_programing
|
||||
@homework_detail_group.save if @homework_detail_group
|
||||
|
||||
|
|
@ -247,20 +417,7 @@ class HomeworkCommonController < ApplicationController
|
|||
# create_works_list @homework
|
||||
# end
|
||||
|
||||
@hw_status = params[:hw_status].to_i
|
||||
if params[:is_manage] == "1"
|
||||
redirect_to user_manage_homeworks_user_path(User.current.id)
|
||||
elsif params[:is_manage] == "2"
|
||||
redirect_to user_receive_homeworks_user_path(User.current.id)
|
||||
elsif @hw_status == 1
|
||||
redirect_to user_course_community_path(User.current.id)
|
||||
elsif @hw_status == 2
|
||||
redirect_to course_path(@course.id)
|
||||
elsif @hw_status == 5
|
||||
redirect_to student_work_index_url(:homework => @homework.id)
|
||||
else
|
||||
redirect_to homework_common_index_path(:course => @course.id)
|
||||
end
|
||||
redirect_to student_work_index_url(:homework => @homework.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -299,14 +456,7 @@ class HomeworkCommonController < ApplicationController
|
|||
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
@hw_status = params[:hw_status].to_i
|
||||
if @hw_status == 1
|
||||
redirect_to user_path(User.current.id)
|
||||
elsif @hw_status == 2
|
||||
redirect_to course_path(@course.id)
|
||||
else
|
||||
redirect_to homework_common_index_path(:course => @course.id)
|
||||
end
|
||||
redirect_to homework_common_index_path(:course => @course.id, :homework_type => @homework.homework_type)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
@ -325,24 +475,25 @@ class HomeworkCommonController < ApplicationController
|
|||
end
|
||||
homework_bank = add_to_homework_bank_f @homework
|
||||
homework_bank.save
|
||||
if @homework.homework_type == 4
|
||||
HomeworkBankShixun.create(:homework_bank_id => homework_bank.id, :shixun_id => @homework.homework_commons_shixuns.shixun_id)
|
||||
end
|
||||
@homework.update_attributes(:homework_bank_id => homework_bank.id)
|
||||
elsif params[:type].to_i == 2
|
||||
homework_bank = HomeworkBank.where(:id => @homework.homework_bank_id).first
|
||||
if homework_bank
|
||||
homework_bank.update_attributes(:name => @homework.name, :description => @homework.description, :homework_type => @homework.homework_type)
|
||||
homework_bank.update_attributes(:name => @homework.name, :description => @homework.description, :homework_type => @homework.homework_type, :reference_answer => @homework.reference_answer)
|
||||
if @homework.homework_type == 2 && @homework.homework_detail_programing
|
||||
homework_bank.update_attributes(:language => @homework.homework_detail_programing.language)
|
||||
homework_bank.homework_bank_tests.destroy_all
|
||||
@homework.homework_tests.each_with_index do |homework_test|
|
||||
homework_bank.homework_bank_tests << HomeworkBankTest.new(
|
||||
test_type: 1,
|
||||
input: homework_test.input,
|
||||
output: homework_test.output
|
||||
)
|
||||
end
|
||||
@homework.homework_samples.each_with_index do |homework_test|
|
||||
homework_bank.homework_bank_tests << HomeworkBankTest.new(
|
||||
test_type: 0,
|
||||
homework_bank.homework_bank_samples << HomeworkBankSample.new(
|
||||
input: homework_test.input,
|
||||
output: homework_test.output
|
||||
)
|
||||
|
|
@ -355,9 +506,14 @@ class HomeworkCommonController < ApplicationController
|
|||
if @homework.is_update
|
||||
@homework.update_attributes(:is_update => 0)
|
||||
end
|
||||
@user_activity_id = params[:user_activity_id].to_i
|
||||
@hw_status = params[:hw_status].to_i
|
||||
@is_teacher = User.current.admin? || User.current.allowed_to?(:as_teacher, @course)
|
||||
end
|
||||
|
||||
def set_public
|
||||
@homework.update_attributes(:is_public => true)
|
||||
respond_to do |format|
|
||||
format.html{ redirect_to student_work_index_path(:homework => @homework.id) }
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def publish_homework
|
||||
|
|
|
|||
|
|
@ -0,0 +1,393 @@
|
|||
# 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 = "您所在团队提交的项目实训发布申请:<a href='#{shixun_path(shixun)}'>#{shixun.name}</a>,审核未通过。<br/>原因:#{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
|
||||
|
|
@ -251,7 +251,6 @@ class MembersController < ApplicationController
|
|||
member = @course.members.where(:user_id => user_id).first
|
||||
member_role = MemberRole.new(:role_id => params[:membership][:role_ids][0], :is_current => 0)
|
||||
member.member_roles << member_role
|
||||
member_role.save
|
||||
end
|
||||
role_ids = params[:membership][:role_ids]
|
||||
#role = Role.find(params[:membership][:role_ids])
|
||||
|
|
@ -286,9 +285,11 @@ class MembersController < ApplicationController
|
|||
end
|
||||
@course.members << members
|
||||
@course.course_infos << course_info
|
||||
|
||||
@roles = Role.givable.all[3..5]
|
||||
members = @course.member_principals.includes(:roles, :principal).all.sort
|
||||
#@teacher_count = searchTeacherAndAssistant(@course).count
|
||||
#@student_count = @course.student.count
|
||||
#@no_group_count = @course.members.where("course_group_id = 0").select{|m| m.roles.to_s.include?("Student")}.count
|
||||
#@roles = Role.givable.all[3..5]
|
||||
#members = @course.member_principals.includes(:roles, :principal).all.sort
|
||||
else
|
||||
@create_member_error_messages = l(:label_user_role_null)
|
||||
end
|
||||
|
|
@ -461,6 +462,7 @@ class MembersController < ApplicationController
|
|||
else
|
||||
@member.member_roles.where("role_id = 10").destroy_all
|
||||
joined = StudentsForCourse.where('student_id = ? and course_id = ?', @member.user_id,@course.id).destroy_all
|
||||
@member.update_attributes(:course_group_id => 0)
|
||||
if params[:group_id] == '0'
|
||||
@members = @course.members.select{|m| m.roles.to_s.include?("Student")}
|
||||
else
|
||||
|
|
@ -469,8 +471,8 @@ class MembersController < ApplicationController
|
|||
@member.member_roles.where("role_id = 7 or role_id = 9").first.update_attributes(:is_current => 1)
|
||||
end
|
||||
end
|
||||
@teachers = searchTeacherAndAssistant(@course)
|
||||
@all_student_count = @course.student.count
|
||||
@teacher_count = searchTeacherAndAssistant(@course).count
|
||||
@student_count = @course.student.count
|
||||
@no_group_count = @course.members.where("course_group_id = 0").select{|m| m.roles.to_s.include?("Student")}.count
|
||||
# user_admin = CourseInfos.where("user_id = ? and course_id = ?", @member.user_id, @course.id)
|
||||
# if user_admin.size > 0
|
||||
|
|
|
|||
|
|
@ -18,9 +18,8 @@
|
|||
class MyController < ApplicationController
|
||||
include ApplicationHelper
|
||||
layout "users_base"
|
||||
# edit
|
||||
skip_before_filter :check_authentication, :only => [:account]
|
||||
before_filter :auth_login1, :only => [:account]
|
||||
#
|
||||
before_filter :require_login, except: [:change_mail_notification]
|
||||
|
||||
helper :issues
|
||||
|
|
@ -148,18 +147,35 @@ class MyController < ApplicationController
|
|||
end
|
||||
@user = User.current
|
||||
|
||||
# 基本资料不完善 @force为false, 完善 @force为true
|
||||
@force = false
|
||||
if params[:tip]
|
||||
@force = true
|
||||
# 认证
|
||||
ue = @user.user_extensions
|
||||
@trail_authentication = ApplyAction.where(:user_id => User.current.id).order("created_at desc").first
|
||||
@authentication = @user.authentication
|
||||
if ue.identity.nil?
|
||||
@require_auth = true
|
||||
else
|
||||
user = UserExtensions.where(:user_id => User.current.id).first
|
||||
if user.gender.nil? || user.school_id.nil? || User.current.lastname.nil?
|
||||
@force = true
|
||||
elsif user.identity == 3 && user.school_id.nil?
|
||||
@force = true
|
||||
if @trail_authentication.blank? || (@trail_authentication.status == 2 && (@trail_authentication.updated_at.to_i + 24*60*60) < Time.now.to_i)
|
||||
@require_trail_auth = true
|
||||
end
|
||||
end
|
||||
# @require_auth = true
|
||||
#
|
||||
# # 基本资料不完善 @force为false, 完善 @force为true
|
||||
# @force = false
|
||||
# # @authentication = @user.authentication
|
||||
# @trail_authentication = AuthenticationsUsers.where(:user_id => User.current.id).first
|
||||
# if params[:tip]
|
||||
# @force = true
|
||||
# else
|
||||
# user = UserExtensions.where(:user_id => User.current.id).first
|
||||
# if user.identity.nil? || user.school_id.nil? || User.current.lastname.nil?
|
||||
# @force = false
|
||||
# else
|
||||
# @force = @trail_authentication.blank? ? false : true
|
||||
# end
|
||||
# end
|
||||
# # 用户认证
|
||||
# @auth = @user.authentication ? false : true
|
||||
|
||||
@s_message = AppliedMessage.where(:status => 3, :user_id => User.current.id, :viewed => 0, :applied_type => 'ApplyAddSchools').first
|
||||
@d_message = AppliedMessage.where(:status => 3, :user_id => User.current.id, :viewed => 0, :applied_type => 'ApplyAddDepartment').first
|
||||
|
|
@ -176,8 +192,10 @@ class MyController < ApplicationController
|
|||
#changed_login = (@user.login != params[:login])
|
||||
#changed_mail = (@user.mail != params[:user][:mail])
|
||||
#@user.safe_attributes = params[:user]
|
||||
@user.nickname = params[:nickname]
|
||||
@user.lastname = params[:lastname]
|
||||
@user.firstname = ""
|
||||
@user.show_realname = params[:show_realname] ? 0 : 1
|
||||
@user.pref.attributes = params[:pref]
|
||||
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
|
||||
#@user.login = params[:login].strip
|
||||
|
|
@ -196,6 +214,7 @@ class MyController < ApplicationController
|
|||
# @se.occupation = params[:occupation]
|
||||
# end
|
||||
@se.school_id = params[:occupation]
|
||||
@se.department_id = params[:department_id]
|
||||
@se.gender = params[:sex]
|
||||
@se.location = params[:province] if params[:province]
|
||||
@se.location_city = params[:city] if params[:city]
|
||||
|
|
@ -214,6 +233,7 @@ class MyController < ApplicationController
|
|||
@se.brief_introduction = params[:brief_introduction]
|
||||
|
||||
if @user.save && @se.save
|
||||
|
||||
reward_grade(@user, @user.id, 'Account', 500)
|
||||
# 修改邮箱的时候同步修改到gitlab
|
||||
# if changed_mail || changed_login
|
||||
|
|
|
|||
|
|
@ -1,39 +1,101 @@
|
|||
# encoding: utf-8
|
||||
class MyshixunsController < ApplicationController
|
||||
layout 'base_myshixun'
|
||||
skip_before_filter :verify_authenticity_token, :only => [:training_task_status]
|
||||
before_filter :require_login, :except => [:training_task_status]
|
||||
before_filter :find_myshixun, :only => [:show, :myshixun_reset]
|
||||
skip_before_filter :verify_authenticity_token, :only => [:training_task_status, :close_webssh]
|
||||
before_filter :require_login, :except => [:training_task_status, :close_webssh]
|
||||
before_filter :check_authentication, :except => [:training_task_status, :close_webssh]
|
||||
before_filter :find_myshixun, :only => [:show, :myshixun_reset, :open_webssh]
|
||||
|
||||
|
||||
include ApplicationHelper
|
||||
|
||||
# 将代码重置到开启状态
|
||||
# 方法:使用文件更新,非Git重置
|
||||
def code_reset
|
||||
|
||||
end
|
||||
|
||||
def code_reset_success
|
||||
|
||||
end
|
||||
|
||||
# 连接webssh
|
||||
def open_webssh
|
||||
username = Redmine::Configuration['webssh_username']
|
||||
password = Redmine::Configuration['webssh_password']
|
||||
begin
|
||||
jenkins_shixuns = Redmine::Configuration['jenkins_shixuns']
|
||||
uri = URI("#{jenkins_shixuns}/jenkins-exec/webssh/getConnectInfo")
|
||||
user_id = User.current.id
|
||||
params = {gameID:@myshixun.id}
|
||||
res = uri_exec uri, params
|
||||
if res && res['code'].to_i != 0
|
||||
raise("实训云平台繁忙(繁忙等级:92)")
|
||||
end
|
||||
render :json => {:host => res['address'], :port => res['port'], :username => username, :password => password, :game_id => @myshixun.id}
|
||||
rescue Exception => e
|
||||
logger.error(e)
|
||||
render :json => {:error => e.try(:message)}
|
||||
# @message = e.try(:message)
|
||||
end
|
||||
end
|
||||
|
||||
# 断开webssh连接
|
||||
def close_webssh
|
||||
username = Redmine::Configuration['webssh_username']
|
||||
password = Redmine::Configuration['webssh_password']
|
||||
begin
|
||||
jenkins_shixuns = Redmine::Configuration['jenkins_shixuns']
|
||||
uri = URI("#{jenkins_shixuns}/jenkins-exec/webssh/deleteSSH")
|
||||
user_id = User.current.id
|
||||
params = {gameID:@_params[:id]} # @_params[:id] 是webssh传过来的gameId
|
||||
res = uri_exec uri, params
|
||||
if res && res['code'].to_i != 0
|
||||
raise("实训云平台繁忙(繁忙等级:93)")
|
||||
end
|
||||
render :jsonp => {:host => res['address'], :port => res['port'], :username => username, :password => password}
|
||||
rescue Exception => e
|
||||
logger.error(e)
|
||||
@message = e.try(:message)
|
||||
end
|
||||
end
|
||||
|
||||
# 实训重置只更新脚本
|
||||
def myshixun_reset
|
||||
ActiveRecord::Base.transaction do
|
||||
begin
|
||||
g = Gitlab.client
|
||||
jenkins_shixuns = Redmine::Configuration['jenkins_shixuns']
|
||||
shixun = @myshixun.shixun
|
||||
myshixun_job = Base64.encode64("myshixun_#{@myshixun.id}")
|
||||
StudentWork.where(:myshixun_id => @myshixun.id).update_all(:myshixun_id => nil, :work_status => 0)
|
||||
@myshixun.destroy
|
||||
myshixun_member = @myshixun
|
||||
repository = @myshixun.repository
|
||||
repository.destroy
|
||||
g = Gitlab.client
|
||||
g_project = g.project(@myshixun.gpid)
|
||||
unless g_project.id.nil?
|
||||
git_rep = g.delete_project(@myshixun.gpid)
|
||||
logger.info("### delete repository result is #{git_rep}")
|
||||
params = {:jobName => "#{myshixun_job}"}
|
||||
if git_rep != true
|
||||
raise("版本库删除异常")
|
||||
raise("实训云平台繁忙(繁忙等级:87)")
|
||||
end
|
||||
end
|
||||
uri = URI("#{jenkins_shixuns}/jenkins-exec/game/deleteJob")
|
||||
res = uri_exec uri, params
|
||||
# job的删除放异步里面处理
|
||||
# params = {:jobName => "#{myshixun_job}"}
|
||||
# uri = URI("#{jenkins_shixuns}/jenkins-exec/game/deleteJob")
|
||||
# res = uri_exec uri, params
|
||||
# if res && res['code'].to_i != 0 && res['code'].to_i != 1
|
||||
# raise("实训云平台繁忙(繁忙等级:89)")
|
||||
# end
|
||||
redirect_to shixun_exec_shixun_path(shixun, :type => 1)
|
||||
rescue Exception => e
|
||||
flash[:error] = "实训云平台繁忙(繁忙等级:89)"
|
||||
g.delete_project(@myshixun.gpid) if !g_project.try(:id).nil?
|
||||
redirect_to myshixun_path(@myshixun)
|
||||
logger.error("myshixun reset failed #{e}")
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
redirect_to shixun_exec_shixun_path(shixun)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -68,28 +130,18 @@ class MyshixunsController < ApplicationController
|
|||
end
|
||||
end
|
||||
end
|
||||
# if status == "0"
|
||||
# if game.status == 2
|
||||
# game.update_attributes!(:retry_status => 2)
|
||||
# else
|
||||
# game.update_attributes!(:status => 2, :final_score => challenge.score, :end_time => Time.now)
|
||||
# end
|
||||
# else
|
||||
# if game.status == 2
|
||||
# game.update_attribute(:retry_status, 1)
|
||||
# else
|
||||
# game.update_attribute(:status, 0)
|
||||
# end
|
||||
# end
|
||||
if status == "0"
|
||||
if resubmit == "1"
|
||||
game.update_attributes!(:retry_status => 2)
|
||||
if !resubmit.blank?
|
||||
game.update_attributes(:retry_status => 2, :resubmit_identifier => resubmit)
|
||||
else
|
||||
game.update_attributes!(:status => 2, :final_score => challenge.score, :end_time => Time.now)
|
||||
game.update_attributes(:status => 2, :end_time => Time.now)
|
||||
unless game.answer_open? # 如果没有查看答案,则获得该关卡得分
|
||||
game.update_attribute(:final_score, challenge.score)
|
||||
end
|
||||
end
|
||||
else
|
||||
if resubmit == "1"
|
||||
game.update_attribute(:retry_status, 1)
|
||||
else # status == "-1" 表示返回结果错误
|
||||
if !resubmit.blank?
|
||||
game.update_attributes(:retry_status => 1, :resubmit_identifier => resubmit)
|
||||
else
|
||||
game.update_attribute(:status, 0)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -149,6 +149,8 @@ class PraiseTreadController < ApplicationController
|
|||
@obj = Work.find_by_id(id)
|
||||
when 'Challenge' || 'ChallengeTread'
|
||||
@obj = Challenge.find_by_id(id)
|
||||
when 'Discuss'
|
||||
@obj = Discuss.find_by_id(id)
|
||||
else
|
||||
@obj = nil
|
||||
end
|
||||
|
|
|
|||
|
|
@ -929,10 +929,10 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def uri_exec uri, params
|
||||
res = Net::HTTP.post_form(uri, params).body
|
||||
res = JSON.parse(res)
|
||||
end
|
||||
# def uri_exec uri, params
|
||||
# # res = Net::HTTP.post_form(uri, params).body
|
||||
# # res = JSON.parse(res)
|
||||
# end
|
||||
|
||||
# 开启实训项目,学生会fork一个项目并自动发送任务
|
||||
def training_project_extend
|
||||
|
|
|
|||
|
|
@ -36,17 +36,17 @@ class RepositoriesController < ApplicationController
|
|||
before_filter :find_repository, :only => [:edit, :update, :destroy, :committers]
|
||||
|
||||
before_filter :find_project_repository, :except => [:commits, :shixun_show, :new, :create, :newcreate, :edit, :update, :destroy, :committers,
|
||||
:newrepo, :to_gitlab, :forked, :export_rep_static, :training_project_extend, :shixun_entry]
|
||||
:newrepo, :to_gitlab, :forked, :export_rep_static, :training_project_extend, :shixun_entry, :shixun_commit_diff]
|
||||
|
||||
# 实训项目新增
|
||||
before_filter :find_project_and_repository, :only => [:commits, :shixun_show, :shixun_entry]
|
||||
before_filter :find_project_and_repository, :only => [:commits, :shixun_show, :shixun_entry, :shixun_commit_diff]
|
||||
|
||||
# 连接gitlab
|
||||
# before_filter :connect_gitlab, :only => [:quality_analysis, :commit_diff]
|
||||
|
||||
before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue]
|
||||
# before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis, :commit_diff]
|
||||
before_filter :authorize_visible , :except => [:shixun_show, :newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis, :commit_diff]
|
||||
before_filter :authorize_visible , :except => [:shixun_show, :newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis, :commit_diff, :shixun_commit_diff]
|
||||
# 版本库新增权限
|
||||
# before_filter :show_rep, :only => [:show, :stats, :revisions, :revision, :diff, :commit_diff ]
|
||||
accept_rss_auth :revisions
|
||||
|
|
@ -620,11 +620,15 @@ update
|
|||
@project_menu_type = 5
|
||||
@entry = @repository.entry(@path, @rev)
|
||||
(show_error_not_found; return) unless @entry
|
||||
limit = 10
|
||||
limit = 15
|
||||
# 每次页面的换回值从1开始,但是gitlab的页面查询是从0开始,所以先改变page的类型减一在改回来
|
||||
@commits = @g.commits(@shixun.gpid, page:(params[:page].to_i - 1).to_s, ref_name:@rev)
|
||||
@commits_count = params[:commit_count].nil? ? @g.user_static(@shixun.gpid, :rev => @rev).count : params[:commit_count].to_i
|
||||
@commits_pages = Paginator.new @commits_count, limit, params[:page]
|
||||
# @commits_pages = Paginator.new @commits_count, limit, params[:page]
|
||||
|
||||
@commits_pages = Paginator.new @commits_count, limit, params['page'] || 1
|
||||
@offset ||= @commits_pages.offset
|
||||
@commits = paginateHelperForGitlab @commits, limit
|
||||
|
||||
render :layout => 'base_shixun'
|
||||
end
|
||||
|
|
@ -798,6 +802,17 @@ update
|
|||
render :layout => 'base_projects'
|
||||
end
|
||||
|
||||
def shixun_commit_diff
|
||||
@commit_diff = @g.commit_diff(@shixun.gpid, params[:changeset_id])
|
||||
diff = ActiveSupport::JSON.decode(@commit_diff.to_json).first
|
||||
diff = OpenStruct.new(diff)
|
||||
@diff_file = Trustie::Gitlab::Diff::File.new(diff)
|
||||
|
||||
|
||||
# @commit_details = @g.commit(@project.gpid, params[:changeset])
|
||||
render :layout => 'base_shixun'
|
||||
end
|
||||
|
||||
# 实训项目
|
||||
# 每次提交对应的文件差异
|
||||
def commit
|
||||
|
|
|
|||
|
|
@ -3,12 +3,58 @@
|
|||
class ShixunsController < ApplicationController
|
||||
layout 'base_shixun'
|
||||
before_filter :require_login
|
||||
before_filter :find_shixun, :except => [ :index, :new, :create, :index, :search]
|
||||
before_filter :check_authentication
|
||||
before_filter :find_shixun, :except => [ :index, :new, :create, :index, :search, :shixun_courses, :new_disscuss]
|
||||
before_filter :shixun_view_allow, :only => [:show]
|
||||
before_filter :require_manager, :only => [ :settings, :add_script, :publish]
|
||||
before_filter :require_manager, :only => [ :settings, :add_script, :publish, :collaborators_delete, :shixun_members_added, :add_collaborators]
|
||||
#skip_before_filter :verify_authenticity_token, :only => :update_propaedeutics
|
||||
|
||||
include ApplicationHelper
|
||||
|
||||
def shixun_test
|
||||
jenkins_shixuns = Redmine::Configuration['jenkins_shixuns']
|
||||
uri = URI("#{jenkins_shixuns}/jenkins-exec/webssh/getConnectInfo")
|
||||
user_id = User.current.id
|
||||
params = {userID:user_id}
|
||||
res = uri_exec uri, params
|
||||
render :json => {data:"succesed"}
|
||||
end
|
||||
|
||||
def delete_shixun_test
|
||||
jenkins_shixuns = Redmine::Configuration['jenkins_shixuns']
|
||||
uri = URI("#{jenkins_shixuns}/jenkins-exec/webssh/deleteSSH")
|
||||
user_id = User.current.id
|
||||
params = {userID:user_id}
|
||||
res = uri_exec uri, params
|
||||
render :json => {data:"succesed"}
|
||||
end
|
||||
|
||||
def game_webssh
|
||||
|
||||
end
|
||||
|
||||
def entry_edit
|
||||
g = Gitlab.client
|
||||
@path = params[:path]
|
||||
@rev = params[:rev]
|
||||
file_content = g.files(@shixun.gpid, @path, @rev).content
|
||||
@content = Base64.decode64(file_content) unless file_content.blank?
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def entry_update
|
||||
g = Gitlab.client
|
||||
@path = params[:path]
|
||||
@rev = params[:rev]
|
||||
@content = params[:content]
|
||||
code_file = g.edit_file(@shixun.gpid, :content => params[:content], :file_path => @path, :branch_name => @rev, :commit_message => "shixun entry")
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def shixun_monitor
|
||||
# monitor_filter
|
||||
# if @had_exec
|
||||
|
|
@ -22,29 +68,169 @@ class ShixunsController < ApplicationController
|
|||
|
||||
def statistics
|
||||
@challenges = @shixun.challenges
|
||||
@top_students = @shixun
|
||||
@top_students = @shixun.myshixuns.where(:status => 1)
|
||||
myshixuns = @shixun.myshixuns.includes(:games)
|
||||
@latest_myshixuns = myshixuns.order("created_at desc").limit(4)
|
||||
end
|
||||
|
||||
def autocompletion
|
||||
|
||||
end
|
||||
|
||||
def index
|
||||
@shixuns = Shixun.where(:authentication => 1).order('updated_at desc')
|
||||
@shixun_my_score = Game.where(:user_id => User.current).sum(:final_score)
|
||||
@current_user_had_passed = Myshixun.where(:status => 1).count
|
||||
@order = "created_at"
|
||||
@sort = "desc"
|
||||
search = params[:search]
|
||||
@shixun_all_count = Shixun.all.count
|
||||
@shixuns = Shixun.find_by_sql("select * from shixuns where id in (SELECT distinct(shixun_id) FROM `challenges`) and name like '%#{search}%' order by created_at desc")
|
||||
#@shixuns = Shixun.where("name like ?", "%#{search}%").reorder("created_at desc")
|
||||
# @shixun_my_score = Game.find_by_sql("select sum(final_score) as score from games where myshixun_id in (select id from myshixuns where status =1
|
||||
# and user_id=#{User.current.id} and shixun_id in (SELECT id FROM `shixuns` where status > 1))").first.try(:score).to_i
|
||||
@shixun_my_score = Experience.find_by_sql("SELECT sum(score) as score FROM `experiences` where user_id=#{User.current.id}").first.try(:score).to_i
|
||||
@current_user_had_passed = Myshixun.find_by_sql("select count(*) as had_passed from myshixuns where status =1 and user_id=#{User.current.id}
|
||||
and shixun_id in (SELECT id FROM `shixuns` where status > 1)").first.try(:had_passed).to_i
|
||||
@majors = Major.where(:id => [635, 636, 637, 638, 639, 622, 619])
|
||||
@courses = CourseList.where(:id => MajorCourse.where(:major_id => @majors.map(&:id)).map(&:course_list_id))
|
||||
@shixuns_count = @shixuns.count
|
||||
@limit = 16
|
||||
@is_remote = true
|
||||
@shixun_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1
|
||||
@offset ||= @shixun_pages.offset
|
||||
@shixuns = paginateHelper @shixuns, @limit
|
||||
render :layout => "base_edu"
|
||||
end
|
||||
|
||||
def propaedeutics
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def update_propaedeutics
|
||||
@shixun = Shixun.where(:identifier => params[:id]).first
|
||||
@shixun.update_attribute("propaedeutics", params[:shixun][:propaedeutics])
|
||||
redirect_to propaedeutics_shixun_path(@shixun)
|
||||
end
|
||||
|
||||
def collaborators
|
||||
@collaborators = @shixun.collaborators
|
||||
end
|
||||
|
||||
def new_disscuss
|
||||
render :layout => 'base_edu'
|
||||
end
|
||||
|
||||
def collaborators_delete
|
||||
user_id = params[:c_id]
|
||||
shixun_member = ShixunMember.where(:user_id => user_id, :shixun_id => @shixun.id, :role => 2).first
|
||||
shixun_member.delete
|
||||
@collaborators = @shixun.collaborators
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
# 已存在的成员不添加
|
||||
def add_collaborators
|
||||
if !params[:search].nil?
|
||||
# members = searchTeacherAndAssistant @course
|
||||
member_ids = "(" + @shixun.shixun_members.map(&:user_id).join(',') + ")"
|
||||
condition = "%#{params[:search].strip}%".gsub(" ","")
|
||||
@users = User.where("id not in #{member_ids} and status = 1 and LOWER(concat(lastname, firstname)) LIKE '#{condition}'").includes(:user_extensions)
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def shixun_members_added
|
||||
unless params[:membership][:user_ids].blank?
|
||||
memberships = params[:membership][:user_ids]
|
||||
memberships.each do |member|
|
||||
ShixunMember.create(:user_id => member, :shixun_id => @shixun.id, :role => 2)
|
||||
end
|
||||
@collaborators = @shixun.collaborators
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def search
|
||||
# 确定 sort 1升序 2 降序
|
||||
if params[:time_reorder]
|
||||
order = "#{Shixun.table_name}.created_at #{params[:time_reorder]}"
|
||||
elsif params[:hot_reorder]
|
||||
order = "myshixun_count #{params[:hot_reorder]}, #{Shixun.table_name}.updated_at #{params[:hot_reorder]}"
|
||||
@order = params[:order] || "created_at"
|
||||
bsort = params[:sort] || "desc"
|
||||
@sort = bsort == "desc" ? "asc" : "desc"
|
||||
if @order == "created_at"
|
||||
order_str = "#{Shixun.table_name}.created_at #{bsort}"
|
||||
else
|
||||
order = "#{Shixun.table_name}.created_at desc"
|
||||
order_str = "myshixun_count #{bsort}, #{Shixun.table_name}.updated_at #{bsort}"
|
||||
end
|
||||
@shixuns = Shixun.where(:authentication => 1).reorder(order)
|
||||
@language = params[:language]
|
||||
@status = params[:status].to_i
|
||||
@shixun_status = params[:shixun_status] # 2是已发布 3是未发布
|
||||
@search = params[:search]
|
||||
@major = params[:major]
|
||||
@course = params[:course]
|
||||
@trainee = params[:trainee]
|
||||
ids = Shixun.find_by_sql("select group_concat(id) as allId from shixuns where id in (SELECT distinct(shixun_id) FROM `challenges`)")
|
||||
@shixuns = Shixun.where(:id => ids[0].allId.split(","))
|
||||
@shixuns = @shixuns.where(:language => @language) unless @language.blank?
|
||||
@shixuns = @shixuns.where("name like ?", "%#{@search}%") unless @search.blank?
|
||||
if !@major.blank?
|
||||
@shixuns = @shixuns.where(:major_id => @major.to_i)
|
||||
@courses = CourseList.where(:id => MajorCourse.where(:major_id => @major).map(&:course_list_id))
|
||||
else
|
||||
@courses = CourseList.where(:id => MajorCourse.where(:major_id => [635, 636, 637, 638, 639, 622, 619]).map(&:course_list_id))
|
||||
end
|
||||
if !@course.blank? && (@major.blank? || MajorCourse.where(:major_id => @major, :course_list_id => @course).count == 1)
|
||||
@shixuns = @shixuns.where(:id => ShixunMajorCourse.where(:course_list_id => @course).map(&:shixun_id))
|
||||
end
|
||||
if !@major.blank? && MajorCourse.where(:major_id => @major, :course_list_id => @course).count == 0
|
||||
@course = nil
|
||||
end
|
||||
@shixuns = @shixuns.where(:trainee => @trainee) unless @trainee.blank?
|
||||
case @status
|
||||
when 1, 0
|
||||
@shixuns = @shixuns
|
||||
when 2
|
||||
@shixuns = @shixuns.where(:user_id => User.current)
|
||||
when 3
|
||||
shixun_ids = Myshixun.where(:user_id => User.current).blank? ? "(-1)" : "(" + Myshixun.where(:user_id => User.current).map(&:shixun_id).join(',') +")"
|
||||
@shixuns = @shixuns.where("id not in #{shixun_ids}")
|
||||
when 4
|
||||
shixun_ids = Myshixun.where(:user_id => User.current, :status => 0).map(&:shixun_id)
|
||||
@shixuns = @shixuns.where(:id => shixun_ids)
|
||||
when 5
|
||||
shixun_ids = Myshixun.where(:user_id => User.current, :status => 1).map(&:shixun_id)
|
||||
@shixuns = @shixuns.where(:id => shixun_ids)
|
||||
end
|
||||
case @shixun_status
|
||||
when "1"
|
||||
@shixuns = @shixuns.where(:status => [0, 1])
|
||||
when "2"
|
||||
@shixuns = @shixuns.where(:status => 2)
|
||||
when "3"
|
||||
@shixuns = @shixuns.where(:status => 3)
|
||||
when nil, "0"
|
||||
@shixuns = @shixuns
|
||||
end
|
||||
if @order == "created_at"
|
||||
@shixuns =@shixuns.reorder(order_str)
|
||||
else
|
||||
# 最热排序
|
||||
@shixuns.each do |shixun|
|
||||
shixun[:myshixunCount] = shixun.myshixuns.count
|
||||
end
|
||||
@shixuns = @shixuns.sort{|x, y| y[:myshixunCount] <=> x[:myshixunCount]}
|
||||
end
|
||||
# @shixuns = Shixun.where(:authentication => 1).reorder(order)
|
||||
@shixuns_count = @shixuns.count
|
||||
@limit = 16
|
||||
@is_remote = true
|
||||
@shixun_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1
|
||||
@offset ||= @shixun_pages.offset
|
||||
@shixuns = paginateHelper @shixuns, @limit
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
|
|
@ -54,50 +240,74 @@ class ShixunsController < ApplicationController
|
|||
# gameID 及实训ID
|
||||
def publish
|
||||
jenkins_shixuns = Redmine::Configuration['jenkins_shixuns']
|
||||
fragments = []
|
||||
testSet = []
|
||||
testCases = []
|
||||
begin
|
||||
challenges = @shixun.challenges.includes(:test_sets)
|
||||
challenges.each do |challenge|
|
||||
pipeline_script = challenge.try(:pipeline_script)
|
||||
challenge_script = {:challengeStage => "#{challenge.position}", :challengePipeline => "#{pipeline_script}"}
|
||||
fragments << challenge_script
|
||||
# 每一关所有的测试集
|
||||
challenge.test_sets.each do |test_set|
|
||||
test_cases = {:caseId => test_set.id.to_s, :input => test_set.input, :output => test_set.output, :isPublic => (test_set.is_public ? "1" : "0")}
|
||||
testSet << test_cases
|
||||
end
|
||||
test_sets_list = {:challengeStage => challenge.position.to_s, :challengeTestCases => testSet}
|
||||
testCases << test_sets_list
|
||||
testSet = []
|
||||
end
|
||||
gameInfo = {:trainingID => @shixun.id.to_s, :operationEnvironment => @shixun.language, :challengePipelines => fragments, :testCases => testCases}
|
||||
fragments = fragments.to_json
|
||||
gameInfo = @shixun.gameInfo
|
||||
uri = URI("#{jenkins_shixuns}/jenkins-exec/game/publishGame")
|
||||
params = {gameInfo:gameInfo.to_json}
|
||||
logger.info(gameInfo)
|
||||
params = {gameInfo:gameInfo}
|
||||
logger.info(params)
|
||||
res = uri_exec uri, params
|
||||
if res['code'] == 0
|
||||
@shixun.update_attribute(:status, 1)
|
||||
@shixun.update_attribute(:script, res["msg"])
|
||||
logger.info("###################{res['code']}")
|
||||
if res && res['code'].to_i == 0
|
||||
logger.info("1111###################{res['code']}")
|
||||
@shixun.update_attributes(:status => 1)
|
||||
apply = ApplyAction.where(:container_type => "ApplyShixun", :container_id => @shixun.id).order("created_at desc").first
|
||||
if apply && apply.status == 0
|
||||
@status = 0
|
||||
else
|
||||
ApplyAction.create(:container_type => "ApplyShixun", :container_id => @shixun.id, :user_id => User.current.id, :status => 0)
|
||||
notes = User.current.show_name.to_s + " 申请发布实训:<a href='#{shixun_path(@shixun)}'>#{@shixun.name}</a>"
|
||||
JournalsForMessage.create(:jour_id => 1, :jour_type => 'Principal', :user_id => User.current.id, :notes => notes, :private => 1, :reply_id => 0)
|
||||
@status = 1
|
||||
end
|
||||
shixun_modify_status_without_publish(@shixun, 1)
|
||||
else
|
||||
logger.error("res['code'] is #{res['code']}, res['msg'] is #{res['code']}")
|
||||
@jenkin_error = true
|
||||
raise("当前系统繁忙,请稍后再试")
|
||||
end
|
||||
rescue
|
||||
rescue Exception => e
|
||||
@jenkin_error = true
|
||||
logger.error("pushlish game #{e}")
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def apply_publish
|
||||
apply = ApplyAction.where(:container_type => "ApplyShixun", :container_id => @shixun.id).last
|
||||
if apply && apply.status == 0
|
||||
@status = 0
|
||||
else
|
||||
ApplyAction.create(:container_type => "ApplyShixun", :container_id => @shixun.id, :user_id => User.current.id, :status => 0)
|
||||
notes = User.current.show_name.to_s + " 申请发布实训:<a href='#{shixun_path(@shixun)}'>#{@shixun.name}</a>"
|
||||
JournalsForMessage.create(:jour_id => 1, :jour_type => 'Principal', :user_id => User.current.id, :notes => notes, :private => 1, :reply_id => 0)
|
||||
@shixun.update_column('status', 1)
|
||||
@status = 1
|
||||
end
|
||||
end
|
||||
|
||||
def cancel_publish
|
||||
apply = ApplyAction.where(:container_type => "ApplyShixun", :container_id => @shixun.id).order("created_at desc").first
|
||||
if apply && apply.status == 0
|
||||
apply.update_attributes(:status => 3)
|
||||
@shixun.update_column('status', 0)
|
||||
end
|
||||
redirect_to shixun_path(@shixun)
|
||||
end
|
||||
|
||||
def close
|
||||
@shixun.update_column('status', 3)
|
||||
redirect_to shixun_path(@shixun)
|
||||
end
|
||||
|
||||
# copy_shixun:复制一个新的实训模块包括版本库
|
||||
# copy_myshixun自动创建系列game,game中只包含状态等信息,公共信息从Challeges中读取
|
||||
# 开启过实训的则直接跳入my实训页面
|
||||
def shixun_exec
|
||||
unless allow_shixun_exec(@shixun)
|
||||
unless allow_shixun_exec(@shixun) && (User.current.manager_of_shixun?(@shixun) || @shixun.status > 0)
|
||||
render_403
|
||||
return
|
||||
end
|
||||
myshixun = Myshixun.where(:user_id => User.current.id, :shixun_id => @shixun.id).first
|
||||
unless myshixun.blank?
|
||||
|
|
@ -117,17 +327,48 @@ class ShixunsController < ApplicationController
|
|||
logger.info("#############gshixun is #{gshixun}")
|
||||
if !gshixun.id.nil?
|
||||
myshixun = copy_myshixun(@shixun, gshixun)
|
||||
@shixun.update_attribute(:myshixun_count, (@shixun.myshixun_count + 1))
|
||||
# @shixun.update_attribute(:myshixun_count, (@shixun.myshixun_count + 1))
|
||||
challenges = @shixun.challenges
|
||||
# 之所以增加user_id是为了方便统计查询性能
|
||||
challenges.each_with_index do |challenge, index|
|
||||
status = (index == 0 ? 0 : 3)
|
||||
code = CODES.sample(12).join
|
||||
code = CODES.sample(12).join if Game.where(identifier: code).present?
|
||||
Game.create!(:challenge_id => challenge.id, :myshixun_id => myshixun.id, :status => status, :user_id => myshixun.user_id, :open_time => Time.now, :identifier => code)
|
||||
game =Game.create!(:challenge_id => challenge.id, :myshixun_id => myshixun.id, :status => status, :user_id => myshixun.user_id, :open_time => Time.now, :identifier => code)
|
||||
# 记录刚开始时默认代开文件原始代码
|
||||
# 刚开始fork的一段时间是获取不了content内容的
|
||||
game_passed_code(game.try(:id), challenge.try(:path), myshixun.try(:gpid), 0)
|
||||
end
|
||||
if params[:type] == "1" # 重置过来的请求
|
||||
shixun_mod = ShixunModify.where(:shixun_id => myshixun.try(:shixun_id), :myshixun_id => myshixun.try(:id)).first
|
||||
if shixun_mod.nil?
|
||||
ShixunModify.create(:shixun_id => myshixun.shixun_id, :myshixun_id => myshixun.id, :status => 0)
|
||||
else
|
||||
shixun_mod.update_attributes(:status => 0)
|
||||
end
|
||||
end
|
||||
# webssh类型开始实训的时候建立webssh连接
|
||||
# if @shixun.webssh
|
||||
# # username = Redmine::Configuration['webssh_username']
|
||||
# # password = Redmine::Configuration['webssh_password']
|
||||
# jenkins_shixuns = Redmine::Configuration['jenkins_shixuns']
|
||||
# uri = URI("#{jenkins_shixuns}/jenkins-exec/webssh/getConnectInfo")
|
||||
# user_id = User.current.id
|
||||
# params = {userID:user_id}
|
||||
# res = uri_exec uri, params
|
||||
# if res && res['code'].to_i == 0
|
||||
# myshixun_webssh = Webssh.where(:myshixun_id => myshixun.id).first
|
||||
# if myshixun_webssh.nil?
|
||||
# Webssh.create(:myshixun_id => myshixun.id, :host => @temp, :port => @temp)
|
||||
# else
|
||||
# myshixun_webssh.update_attributes(:host => @temp, :port => @temp)
|
||||
# end
|
||||
# else
|
||||
# raise("实训云平台繁忙(繁忙等级:92)")
|
||||
# end
|
||||
# end
|
||||
else
|
||||
raise("网络异常,请稍后重试")
|
||||
raise("实训云平台繁忙(繁忙等级:81)")
|
||||
end
|
||||
logger.info("myshixun id si #{myshixun.id} and current_task id is#{myshixun.current_task.id}")
|
||||
redirect_to myshixun_game_path(myshixun.current_task, :myshixun_id => myshixun)
|
||||
|
|
@ -141,11 +382,33 @@ class ShixunsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def shixun_courses
|
||||
data = {result:0,options:[]}
|
||||
if params[:major_id] != 0
|
||||
major = Major.find params[:major_id]
|
||||
if major
|
||||
data[:result] = 1
|
||||
major_courses = major.major_courses
|
||||
CourseList.where(:id => major_courses.map(&:course_list_id)).each do |course|
|
||||
option = []
|
||||
option << course.name.to_s
|
||||
option << course.id
|
||||
data[:options] << option
|
||||
end
|
||||
else
|
||||
data[:result] = 0
|
||||
end
|
||||
else
|
||||
data[:result] = 0
|
||||
end
|
||||
render :json =>data
|
||||
end
|
||||
|
||||
def new
|
||||
@shixun = Shixun.new
|
||||
|
||||
respond_to do |format|
|
||||
format.html{render :layout => 'new_base'}
|
||||
format.html{render :layout => 'base_edu'}
|
||||
format.json
|
||||
end
|
||||
end
|
||||
|
|
@ -156,7 +419,14 @@ class ShixunsController < ApplicationController
|
|||
@shixun = Shixun.new(params[:shixun])
|
||||
@shixun.user_id = User.current.id
|
||||
@shixun.language = params[:language]
|
||||
@shixun.major_id = params[:major_id]
|
||||
@shixun.trainee = params[:trainee]
|
||||
@shixun.identifier = identifier
|
||||
if params[:course_id]
|
||||
params[:course_id].each do |course_id|
|
||||
@shixun.shixun_major_courses << ShixunMajorCourse.new(:major_id => params[:major_id], :course_list_id => course_id)
|
||||
end
|
||||
end
|
||||
(params[:shixun][:is_public] == "1" ? @shixun.is_public = true : @shixun.is_public = false)
|
||||
respond_to do |format|
|
||||
if @shixun.save
|
||||
|
|
@ -176,7 +446,7 @@ class ShixunsController < ApplicationController
|
|||
raise "sync failed" if @shixun.gpid.blank?
|
||||
rescue Exception => e
|
||||
@shixun.update_attribute(:gpid, nil)
|
||||
if @repository.id
|
||||
if @repository && @repository.id
|
||||
@repository.destroy
|
||||
end
|
||||
end
|
||||
|
|
@ -208,17 +478,55 @@ class ShixunsController < ApplicationController
|
|||
end
|
||||
|
||||
def update
|
||||
@shixun.attributes = params[:shixun]
|
||||
@shixun.language = params[:language]
|
||||
params[:shixun][:is_public] == "on" ? @shixun.is_public = 1 : @shixun.is_public = 0
|
||||
@shixun.save
|
||||
if @shixun.status == 0
|
||||
language = @shixun.language
|
||||
@shixun.attributes = params[:shixun]
|
||||
@shixun.language = params[:language]
|
||||
@shixun.trainee = params[:trainee]
|
||||
if params[:course_id]
|
||||
@shixun.shixun_major_courses.destroy_all
|
||||
params[:course_id].each do |course_id|
|
||||
@shixun.shixun_major_courses << ShixunMajorCourse.new(:major_id => params[:major_id], :course_list_id => course_id)
|
||||
end
|
||||
end
|
||||
@shixun.major_id = params[:major_id]
|
||||
params[:shixun][:is_public] == "on" ? @shixun.is_public = 1 : @shixun.is_public = 0
|
||||
if @shixun.save
|
||||
# 实训语言更改了会影响后续的评测,所以需要更新is_updated
|
||||
if language != params[:language]
|
||||
add_shixun_modify_status(@shixun, 1)
|
||||
end
|
||||
end
|
||||
else
|
||||
@error = "该实训已申请发布了,暂不能编辑"
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html{redirect_to settings_shixun_url(@shixun)}
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
def shixun_discuss
|
||||
@discusses = @shixun.discusses.where(:parent_id => nil).reorder("created_at desc")
|
||||
@discusses_count = @discusses.count
|
||||
@limit = 15
|
||||
@is_remote = true
|
||||
@discusses_pages = Paginator.new @discusses_count, @limit, params['page'] || 1
|
||||
@offset ||= @discusses_pages.offset
|
||||
@discusses = paginateHelper @discusses, @limit
|
||||
end
|
||||
|
||||
def destroy
|
||||
unless User.current.admin?
|
||||
render_403
|
||||
return
|
||||
end
|
||||
Subject.where(:id => @shixun.stage_shixuns.map(&:subject_id)).destroy_all
|
||||
@shixun.destroy
|
||||
respond_to do |format|
|
||||
format.html{ redirect_to shixuns_managements_path }
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def settings
|
||||
|
|
@ -286,6 +594,14 @@ class ShixunsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# 实训行为操作
|
||||
def operation
|
||||
@myshixun = Myshixun.where(:id => params[:myshixun_id]).first
|
||||
@is_modify = ShixunModify.where(:myshixun_id => params[:myshixun_id], :shixun_id => @shixun.try(:id), :status => 1).first
|
||||
@mail = User.current.mail.blank?
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
# REDO: 新增类型copy的时候
|
||||
# 复制项目
|
||||
|
|
@ -293,7 +609,7 @@ class ShixunsController < ApplicationController
|
|||
CODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z)
|
||||
def copy_myshixun shixun, gshixun
|
||||
myshixun = Myshixun.new
|
||||
myshixun.attributes = shixun.attributes.dup.except("id","user_id","visits","gpid","status", "identifier")
|
||||
myshixun.attributes = shixun.attributes.dup.except("id","user_id","visits","gpid","status", "identifier","propaedeutics")
|
||||
myshixun.shixun_id = shixun.id
|
||||
myshixun.user_id = User.current.id
|
||||
myshixun.gpid = gshixun.id
|
||||
|
|
@ -307,13 +623,14 @@ class ShixunsController < ApplicationController
|
|||
rep.type = "Repository::Gitlab"
|
||||
rep.save!
|
||||
login = User.find_by_mail("educoder@163.com").try(:login)
|
||||
rep_url = Base64.encode64(git_shixun_url shixun, login)
|
||||
rep_url = Base64.encode64(git_shixun_url_ip shixun, login)
|
||||
uri = URI("#{jenkins_shixuns}/jenkins-exec/game/openGameInstance")
|
||||
pipeLine = "#{shixun.script}"
|
||||
params = {jobNameForInstance: "myshixun_#{myshixun.id}", gamePipelineScript: pipeLine, instanceGitURL:rep_url}
|
||||
params = {jobNameForInstance: "myshixun_#{myshixun.id}", gameInfo: shixun.gameInfo, instanceGitURL:rep_url}
|
||||
logger.info("openGameInstance params is #{params}")
|
||||
res = uri_exec uri, params
|
||||
if (res && res['code'] != 0)
|
||||
raise("Job 创建失败")
|
||||
if (res && res['code'].to_i != 0)
|
||||
raise("实训云平台繁忙(繁忙等级:83)")
|
||||
end
|
||||
return myshixun
|
||||
end
|
||||
|
|
@ -329,11 +646,7 @@ class ShixunsController < ApplicationController
|
|||
|
||||
# 权限控制
|
||||
def shixun_view_allow
|
||||
if @shixun.is_public?
|
||||
true
|
||||
else
|
||||
User.current.member_of?(@shixun) ? true : false
|
||||
end
|
||||
render_403 if (@shixun.status == 0 && !(User.current.manager_of_shixun?(@shixun) || User.current.admin?))
|
||||
end
|
||||
|
||||
# 实训管理员或者超级管理员
|
||||
|
|
|
|||
|
|
@ -0,0 +1,83 @@
|
|||
class StagesController < ApplicationController
|
||||
before_filter :check_authentication
|
||||
before_filter :find_subject, :only => [ :create]
|
||||
before_filter :find_stage, :only => [:edit, :update, :destroy]
|
||||
include ApplicationHelper
|
||||
|
||||
def create
|
||||
if params[:stage_name] && params[:shixun_id]
|
||||
stage = Stage.new
|
||||
stage.name = params[:stage_name]
|
||||
stage.subject_id = @subject.id
|
||||
stage.user_id = User.current.id
|
||||
stage.position = @subject.stages.count + 1
|
||||
ActiveRecord::Base.transaction do
|
||||
if stage.save
|
||||
begin
|
||||
params[:shixun_id].each do |shixun_id|
|
||||
shixun = Shixun.find shixun_id
|
||||
stage.stage_shixuns << StageShixun.new(:subject_id => @subject.id, :shixun_id => shixun_id, :position => stage.stage_shixuns.count + 1) if shixun
|
||||
end
|
||||
rescue Exception => e
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
redirect_to subject_path(@subject)
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if params[:stage_name] && params[:shixun_id]
|
||||
@stage.name = params[:stage_name]
|
||||
ActiveRecord::Base.transaction do
|
||||
if @stage.save
|
||||
begin
|
||||
@stage.stage_shixuns.destroy_all
|
||||
params[:shixun_id].each do |shixun_id|
|
||||
shixun = Shixun.find shixun_id
|
||||
@stage.stage_shixuns << StageShixun.new(:subject_id => @subject.id, :shixun_id => shixun_id, :position => @stage.stage_shixuns.count + 1) if shixun
|
||||
end
|
||||
rescue Exception => e
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
redirect_to subject_path(@subject)
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if User.current.manager_of_subject?(@subject)
|
||||
@subject.stages.where("position > #{@stage.position}").update_all("position = position - 1")
|
||||
@stage.destroy
|
||||
@status = 1
|
||||
else
|
||||
@status = 0
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_subject
|
||||
@subject = Subject.find_by_id(params[:subject])
|
||||
if @subject.nil?
|
||||
render_404
|
||||
return
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_stage
|
||||
@stage = Stage.find(params[:id])
|
||||
@subject = @stage.subject
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
|
@ -7,8 +7,8 @@ class StudentWorkController < ApplicationController
|
|||
require "base64"
|
||||
before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:program_test_ex,
|
||||
:set_score_rule,:forbidden_anonymous_comment,:delete_work,:new_student_work_project,:student_work_project,:cancel_relate_project,
|
||||
:search_course_students,:work_canrepeat,:add_group_member,:change_project]
|
||||
before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work, :retry_work, :revise_attachment, :hide_score_detail]
|
||||
:search_course_students,:work_canrepeat,:add_group_member,:change_project,:relate_myshixun]
|
||||
before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work, :retry_work, :revise_attachment, :hide_score_detail, :destroy_score]
|
||||
before_filter :member_of_course, :only => [:new, :create, :show, :add_score, :praise_student_work]
|
||||
before_filter :author_of_work, :only => [:edit, :update, :destroy]
|
||||
before_filter :teacher_of_course, :only => [:student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :set_score_rule, :forbidden_anonymous_comment]
|
||||
|
|
@ -157,14 +157,9 @@ class StudentWorkController < ApplicationController
|
|||
unless student_work.save
|
||||
resultObj[:status] = 200
|
||||
else
|
||||
student_work.name = params[:title]
|
||||
student_work.name = @homework.name.to_s + "的作品提交"
|
||||
student_work.description = params[:src]
|
||||
|
||||
if !is_test && @homework.end_time < Time.now.to_s
|
||||
student_work.late_penalty = @homework.late_penalty
|
||||
else
|
||||
student_work.late_penalty = 0
|
||||
end
|
||||
|
||||
#每次从数据库取出上次的结果加上本次的结果再存入数据库
|
||||
if result["status"].to_i != -2
|
||||
|
|
@ -364,94 +359,44 @@ class StudentWorkController < ApplicationController
|
|||
end
|
||||
end
|
||||
##################################################################################################################
|
||||
@order,@b_sort,@name,@group = params[:order] || "score",params[:sort] || "desc",params[:name].to_s.strip || "",params[:group]
|
||||
@order,@b_sort,@name,@group,@comment,@status = params[:order] || "updated_at",params[:sort] || "desc",params[:name].to_s.strip || "",params[:group], params[:comment], params[:status]
|
||||
@homework_commons = @course.homework_commons.where("publish_time <= ?",Time.now).order("created_at desc")
|
||||
@all_homework_commons = @course.homework_commons.order("created_at desc")
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
||||
@is_evaluation = @homework.homework_detail_manual && @homework.homework_detail_manual.comment_status == 2 && !@is_teacher #是不是匿评
|
||||
@is_evaluation = @homework.homework_detail_manual && (@homework.homework_detail_manual.comment_status == 3 || @homework.homework_detail_manual.comment_status == 4) && !@is_teacher #是不是匿评
|
||||
@show_all = false
|
||||
|
||||
# 0表示没有分组的学生,-1表示所有分组的学生
|
||||
if @group
|
||||
if @group == "0"
|
||||
none_group_students = @course.members.select{ |member| member.course_group_id == 0 }
|
||||
if none_group_students.empty?
|
||||
student_in_group = '(0)'
|
||||
else
|
||||
student_in_group = '(' + none_group_students.map{ |member| member.user_id }.join(',') + ')'
|
||||
end
|
||||
elsif @group == "-1"
|
||||
all_group_students = @course.members.select{ |member| member.course_group_id }
|
||||
if all_group_students.empty?
|
||||
student_in_group = '(0)'
|
||||
else
|
||||
student_in_group = '(' + all_group_students.map{ |member| member.user_id }.join(',') + ')'
|
||||
end
|
||||
group_students = @course.members.where(:course_group_id => @group).joins("join users on members.user_id = users.id").select{|m| m.roles.to_s.include?("Student")}
|
||||
|
||||
if group_students.empty?
|
||||
student_in_group = '(-1)'
|
||||
else
|
||||
course_group = CourseGroup.find_by_id(@group)
|
||||
group_students = course_group.users
|
||||
if group_students.empty?
|
||||
student_in_group = '(0)'
|
||||
else
|
||||
student_in_group = '(' + group_students.map{ |user| user.id }.join(',') + ')'
|
||||
end
|
||||
student_in_group = '(' + group_students.map{ |member| member.user_id }.join(',') + ')'
|
||||
end
|
||||
|
||||
#开放作品 || 老师 || 超级管理员 || 禁用匿评&&作业截止&&已提交作品 显示所有列表
|
||||
if (@homework.is_open == 1 && @course.is_public == 1) || (@homework.is_open == 1 && @course.is_public == 0 && User.current.member_of_course?(@course)) || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @homework.anonymous_comment == 1 && @homework.end_time < Time.now && !@homework.student_works.has_committed.where(:user_id => User.current.id).empty?)
|
||||
if @order == 'lastname'
|
||||
@stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name
|
||||
elsif @order == 'student_id'
|
||||
@stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name
|
||||
else
|
||||
@stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name
|
||||
end
|
||||
if (@homework.is_open == 1 && @course.is_public == 1) || (@homework.is_open == 1 && @course.is_public == 0 && User.current.member_of_course?(@course)) || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @homework.homework_detail_manual.comment_status == 6)
|
||||
@stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}")
|
||||
@show_all = true
|
||||
elsif User.current.member_of_course?(@course)
|
||||
if @homework.homework_detail_manual.comment_status == 1 #学生 && 未开启匿评 只看到自己的
|
||||
if @homework.homework_detail_manual.comment_status == 1 || @homework.homework_detail_manual.comment_status == 2 #学生 && 未开启匿评 只看到自己的
|
||||
if @homework.homework_type == 3
|
||||
pro = @homework.student_work_projects.where(:user_id => User.current.id).first
|
||||
if pro.nil?
|
||||
@stundet_works = []
|
||||
else
|
||||
@stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => pro.student_work_id)
|
||||
end
|
||||
my_work = @homework.student_works.where(:user_id => User.current.id).first
|
||||
@stundet_works = my_work ? @homework.student_works.select("student_works.*,student_works.work_score as score").where(:group_id => my_work.group_id) : []
|
||||
else
|
||||
@stundet_works = @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id)
|
||||
end
|
||||
elsif @homework.homework_detail_manual.comment_status == 2 #学生 && 开启匿评 看到匿评列表
|
||||
if @homework.homework_type == 3
|
||||
pro = @homework.student_work_projects.where(:user_id => User.current.id).first
|
||||
if pro.nil?
|
||||
my_work = []
|
||||
else
|
||||
my_work = @homework.student_works.where(:id => pro.student_work_id)
|
||||
end
|
||||
else
|
||||
my_work = @homework.student_works.has_committed.where(:user_id => User.current.id)
|
||||
@stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id)
|
||||
end
|
||||
elsif @homework.homework_detail_manual.comment_status == 3 || @homework.homework_detail_manual.comment_status == 4 #学生 && 开启匿评 看到匿评列表
|
||||
my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id)
|
||||
@stundet_works = my_work + User.current.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == @homework.id}
|
||||
elsif @homework.homework_detail_manual.comment_status == 3 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的
|
||||
if @homework.homework_type == 3
|
||||
pro = @homework.student_work_projects.where(:user_id => User.current.id).first
|
||||
if pro.nil?
|
||||
my_work = []
|
||||
else
|
||||
my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => pro.student_work_id)
|
||||
end
|
||||
else
|
||||
my_work = @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id)
|
||||
end
|
||||
if my_work.empty?
|
||||
elsif @homework.homework_detail_manual.comment_status == 5 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的
|
||||
my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id)
|
||||
if !my_work || my_work.status == 0
|
||||
@stundet_works = []
|
||||
else
|
||||
if @order == 'lastname'
|
||||
@stundet_works = search_homework_member @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name
|
||||
elsif @order == 'student_id'
|
||||
@stundet_works = search_homework_member @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name
|
||||
else
|
||||
@stundet_works = search_homework_member @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name
|
||||
end
|
||||
@stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}")
|
||||
@show_all = true
|
||||
end
|
||||
else
|
||||
|
|
@ -462,62 +407,27 @@ class StudentWorkController < ApplicationController
|
|||
return
|
||||
end
|
||||
|
||||
@student_work_count = (search_homework_member @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name).count
|
||||
else
|
||||
if (@homework.is_open == 1 &&@course.is_public == 1) || (@homework.is_open == 1 && @course.is_public == 0 && User.current.member_of_course?(@course)) || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @homework.anonymous_comment == 1 && @homework.end_time < Time.now && !@homework.student_works.has_committed.where(:user_id => User.current.id).empty?)
|
||||
if @order == 'lastname'
|
||||
@stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").joins(:user).order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name
|
||||
elsif @order == 'student_id'
|
||||
@stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name
|
||||
else
|
||||
@stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").includes(:user => {:user_extensions => []}, :project => {}, :student_works_scores => {}).order("#{@order} #{@b_sort}"),@name
|
||||
end
|
||||
if (@homework.is_open == 1 && @course.is_public == 1) || (@homework.is_open == 1 && @course.is_public == 0 && User.current.member_of_course?(@course)) || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @homework.homework_detail_manual.comment_status == 6)
|
||||
@stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").includes(:user => {:user_extensions => []}, :project => {}, :student_works_scores => {}).order("#{@order} #{@b_sort}")
|
||||
@show_all = true
|
||||
elsif User.current.member_of_course?(@course)
|
||||
if @homework.homework_detail_manual.comment_status == 1 #学生 && 未开启匿评 只看到自己的
|
||||
if @homework.homework_detail_manual.comment_status == 1 || @homework.homework_detail_manual.comment_status == 2 #学生 && 未开启匿评 只看到自己的
|
||||
if @homework.homework_type == 3
|
||||
pro = @homework.student_work_projects.where(:user_id => User.current.id).first
|
||||
if pro.nil?
|
||||
@stundet_works = []
|
||||
else
|
||||
@stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => pro.student_work_id)
|
||||
end
|
||||
my_work = @homework.student_works.where(:user_id => User.current.id).first
|
||||
@stundet_works = my_work ? @homework.student_works.select("student_works.*,student_works.work_score as score").where(:group_id => my_work.group_id) : []
|
||||
else
|
||||
@stundet_works = @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id)
|
||||
end
|
||||
elsif @homework.homework_detail_manual.comment_status == 2 #学生 && 开启匿评 看到匿评列表
|
||||
if @homework.homework_type == 3
|
||||
pro = @homework.student_work_projects.where(:user_id => User.current.id).first
|
||||
if pro.nil?
|
||||
my_work = []
|
||||
else
|
||||
my_work = @homework.student_works.where(:id => pro.student_work_id)
|
||||
end
|
||||
else
|
||||
my_work = @homework.student_works.has_committed.where(:user_id => User.current.id)
|
||||
@stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id)
|
||||
end
|
||||
elsif @homework.homework_detail_manual.comment_status == 3 || @homework.homework_detail_manual.comment_status == 4 #学生 && 开启匿评 看到匿评列表
|
||||
my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id)
|
||||
@stundet_works = my_work + User.current.student_works_evaluation_distributions.map(&:student_work).select { |work| work.homework_common_id == @homework.id}
|
||||
elsif @homework.homework_detail_manual.comment_status == 3 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的
|
||||
if @homework.homework_type == 3
|
||||
pro = @homework.student_work_projects.where(:user_id => User.current.id).first
|
||||
if pro.nil?
|
||||
my_work = []
|
||||
else
|
||||
my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => pro.student_work_id)
|
||||
end
|
||||
else
|
||||
my_work = @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id)
|
||||
end
|
||||
if my_work.empty?
|
||||
elsif @homework.homework_detail_manual.comment_status == 5 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的
|
||||
my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id)
|
||||
if !my_work || my_work.status == 0
|
||||
@stundet_works = []
|
||||
else
|
||||
if @order == 'lastname'
|
||||
@stundet_works = search_homework_member @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").joins(:user).order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name
|
||||
elsif @order == 'student_id'
|
||||
@stundet_works = search_homework_member @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name
|
||||
else
|
||||
@stundet_works = search_homework_member @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").order("#{@order} #{@b_sort}"),@name
|
||||
end
|
||||
@stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").order("#{@order} #{@b_sort}")
|
||||
@show_all = true
|
||||
end
|
||||
else
|
||||
|
|
@ -527,21 +437,46 @@ class StudentWorkController < ApplicationController
|
|||
render_403
|
||||
return
|
||||
end
|
||||
@student_work_count = (search_homework_member @homework.student_works.has_committed.select("student_works.*,student_works.work_score as score").order("#{@order} #{@b_sort}"),@name).count
|
||||
|
||||
end
|
||||
|
||||
unless @comment.blank?
|
||||
has_comment_works = User.current.student_works_scores.where(:student_work_id => @homework.student_works.map(&:id), :reviewer_role => [1, 2])
|
||||
student_work_ids = has_comment_works.blank? ? '(-1)' : '(' + has_comment_works.map(&:student_work_id).join(',') + ')'
|
||||
if @comment.include?('0')
|
||||
@stundet_works = @stundet_works.where("student_works.id not in #{student_work_ids}")
|
||||
else
|
||||
@stundet_works = @stundet_works.where("work_status != 0 and student_works.id in #{student_work_ids}")
|
||||
end
|
||||
end
|
||||
|
||||
unless @status.blank?
|
||||
@stundet_works = @stundet_works.where(:work_status => @status)
|
||||
end
|
||||
|
||||
@stundet_works = search_homework_member @stundet_works, @name
|
||||
|
||||
@score = @b_sort == "desc" ? "asc" : "desc"
|
||||
@is_focus = params[:is_focus] ? params[:is_focus].to_i : 0
|
||||
# 消息传过来的ID
|
||||
@message_student_work_id = params[:student_work_id]
|
||||
@no_group_count = @course.members.where(:course_group_id => 0).select{|m| m.roles.to_s.include?("Student")}.count
|
||||
@left_nav_type = 3
|
||||
@tab = params[:tab].to_i
|
||||
@all_student_works = @stundet_works
|
||||
@student_work_count = @stundet_works.count
|
||||
@limit = 50
|
||||
@is_remote = true
|
||||
@page = (params['page'] || 1).to_i
|
||||
@student_work_pages = Paginator.new @student_work_count, @limit, @page
|
||||
@offset ||= @student_work_pages.offset
|
||||
@stundet_works = paginateHelper @stundet_works, @limit
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html
|
||||
format.html { render :layout => 'base_edu'}
|
||||
format.xls {
|
||||
filename = "#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@homework.name}#{l(:excel_homework_list)}.xls"
|
||||
send_data(homework_to_xls(@stundet_works), :type => "text/excel;charset=utf-8; header=present",
|
||||
filename = "#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@homework.name}#{l(:excel_homework_list)}.xls"
|
||||
send_data(homework_to_xls(@all_student_works), :type => "text/excel;charset=utf-8; header=present",
|
||||
:filename => filename_for_content_disposition(filename))
|
||||
}
|
||||
end
|
||||
|
|
@ -552,17 +487,21 @@ class StudentWorkController < ApplicationController
|
|||
noEvaluation = @homework.course_messages.where("user_id =? and viewed =?", User.current.id, 0)
|
||||
noEvaluation.update_all(:viewed => true)
|
||||
|
||||
if @homework.homework_type==2
|
||||
redirect_to new_user_commit_homework_users_path(homework_id: @homework.id)
|
||||
# if @homework.homework_type==2
|
||||
# redirect_to new_user_commit_homework_users_path(homework_id: @homework.id)
|
||||
# return
|
||||
# end
|
||||
@is_test = params[:is_test] == 'true'
|
||||
@user = User.current
|
||||
@student_work = @homework.student_works.where("user_id = ?",User.current.id).first
|
||||
if @student_work.nil?
|
||||
@student_work = StudentWork.new
|
||||
elsif @student_work.work_status != 0
|
||||
render_403
|
||||
return
|
||||
end
|
||||
@user = User.current
|
||||
#@student_work = @homework.student_works.where("user_id = ?",User.current.id).first
|
||||
#if @student_work.nil?
|
||||
@student_work = StudentWork.new
|
||||
#end
|
||||
respond_to do |format|
|
||||
format.html{ render :layout => "base_courses"}
|
||||
format.html{ render :layout => "base_edu"}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -574,21 +513,21 @@ class StudentWorkController < ApplicationController
|
|||
@has_commit = true;
|
||||
#flash[:notice] = l(:notice_successful_create)
|
||||
#redirect_to edit_student_work_url(params[:student_work])
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
return
|
||||
end
|
||||
if params[:student_work]
|
||||
@submit_result = true
|
||||
# respond_to do |format|
|
||||
# format.js
|
||||
# end
|
||||
# return
|
||||
elsif params[:student_work]
|
||||
student_work = StudentWork.find(params[:student_work_id]) if params[:student_work_id]
|
||||
student_work = StudentWork.where("user_id =? and homework_common_id =? and work_status = 0", User.current.id, @homework.id).first
|
||||
student_work ||= StudentWork.new
|
||||
student_work.name = params[:student_work][:name] == "#{@homework.name}的作品提交(可修改)" ? "#{@homework.name}的作品提交" : params[:student_work][:name]
|
||||
student_work.name = @homework.name.to_s + "的作品提交"
|
||||
student_work.description = params[:student_work][:description]
|
||||
student_work.homework_common_id = @homework.id
|
||||
student_work.user_id = User.current.id
|
||||
student_work.commit_time = Time.now
|
||||
#student_work.late_reason = params[:late_reason] if params[:late_reason]
|
||||
student_work.group_id = @homework.homework_type == 3 ? @homework.student_works.all_commit.select("distinct group_id").count + 1 : 0
|
||||
student_work.save_attachments(params[:attachments])
|
||||
render_attachment_warning_if_needed(student_work)
|
||||
if @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1
|
||||
|
|
@ -600,7 +539,7 @@ class StudentWorkController < ApplicationController
|
|||
student_work.late_penalty = @homework.late_penalty
|
||||
student_work.work_status = 2
|
||||
# 缺评扣分
|
||||
if @homework.homework_detail_manual.no_anon_penalty == 0 && @homework.homework_detail_manual.comment_status == 3 && @homework.anonymous_comment == 0
|
||||
if @homework.homework_detail_manual.no_anon_penalty == 0 && @homework.homework_detail_manual.comment_status == 5 && @homework.anonymous_comment == 0
|
||||
work_ids = "(" + @homework.student_works.has_committed.map(&:id).join(",") + ")"
|
||||
all_dis_eva = StudentWorksEvaluationDistribution.where("student_work_id IN #{work_ids}")
|
||||
has_sw_count = all_dis_eva.select("distinct user_id").count
|
||||
|
|
@ -626,14 +565,15 @@ class StudentWorkController < ApplicationController
|
|||
@student_work_project.student_work_id = student_work.id
|
||||
@student_work_project.save
|
||||
elsif @homework.homework_detail_group.base_on_project == 0
|
||||
stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => student_work.id, :project_id => student_work.project_id, :user_id => student_work.user_id, :is_leader => 1, :course_id => @homework.course_id)
|
||||
stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => student_work.id, :project_id => 0, :user_id => student_work.user_id, :is_leader => 1, :course_id => @homework.course_id)
|
||||
stu_project.save
|
||||
end
|
||||
members = params[:group_member_ids].split(',')
|
||||
members = params[:user_id]
|
||||
for i in 1 .. members.count-1
|
||||
stu_work = StudentWork.new(:name => student_work.name, :description => student_work.description,:user_id =>members[i].to_i, :homework_common_id => @homework.id,:project_id => student_work.project_id, :late_penalty => student_work.late_penalty,:work_status => 3, :commit_time => student_work.commit_time)
|
||||
stu_work = @homework.student_works.where(:user_id=> members[i].to_i).empty? ? StudentWork.new : @homework.student_works.where(:user_id=> members[i].to_i).first
|
||||
stu_work.update_attributes(:name => student_work.name, :description => student_work.description, :homework_common_id => @homework.id,:project_id => student_work.project_id, :late_penalty => student_work.late_penalty,:work_status => student_work.work_status, :commit_time => Time.now, :group_id => student_work.group_id)
|
||||
if stu_work.save
|
||||
stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => student_work.id, :project_id => stu_work.project_id == 0 ? -1 : stu_work.project_id, :user_id => members[i].to_i, :is_leader => 0, :course_id => @homework.course_id)
|
||||
stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => student_work.id, :project_id => stu_work.project_id == 0 ? 0 : stu_work.project_id, :user_id => members[i].to_i, :is_leader => 0, :course_id => @homework.course_id)
|
||||
stu_project.save
|
||||
end
|
||||
|
||||
|
|
@ -655,33 +595,27 @@ class StudentWorkController < ApplicationController
|
|||
course_message.save
|
||||
|
||||
@student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id).first
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
@submit_result = false
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
redirect_to student_work_index_path(:homework => @homework.id)
|
||||
end
|
||||
|
||||
def edit
|
||||
@user = User.current
|
||||
if (!User.current.admin? && @homework.homework_type == 2) || @homework.end_time < Time.now #编程作业不能修改作业|| 截止日期已到不能修改作业
|
||||
if @homework.end_time < Time.now #截止日期已到不能修改作业
|
||||
render_403
|
||||
else
|
||||
if @homework.homework_type == 3
|
||||
@commit_users = User.where(:id => @work.student_work_projects.map(&:user_id))
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html{ render :layout => "base_courses"}
|
||||
format.html{ render :layout => "base_edu"}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if params[:student_work]
|
||||
@submit_result = true
|
||||
@work.name = params[:student_work][:name]
|
||||
@work.description = params[:student_work][:description]
|
||||
@work.save_attachments(params[:attachments])
|
||||
render_attachment_warning_if_needed(@work)
|
||||
|
|
@ -701,11 +635,12 @@ class StudentWorkController < ApplicationController
|
|||
course_statistics.update_attribute('committed_work_num', (course_statistics.committed_work_num - 1) < 0 ? 0 : (course_statistics.committed_work_num - 1)) if course_statistics
|
||||
course_statistics.update_attribute('un_commit_work_num', course_statistics.un_commit_work_num + 1) if course_statistics
|
||||
end
|
||||
student_works.delete_all
|
||||
student_works.update_all(:work_status => 0, :description => nil, :project_id => 0, :late_penalty => 0,:work_status => 0, :commit_time => nil)
|
||||
student_work_projects.delete_all
|
||||
members = params[:group_member_ids].split(',')
|
||||
members = params[:user_id]
|
||||
for i in 1 .. members.count-1
|
||||
stu_work = StudentWork.new(:name => @work.name, :description => @work.description,:user_id=> members[i].to_i, :homework_common_id => @homework.id, :project_id => @work.project_id, :late_penalty => @work.late_penalty,:work_status => 3, :commit_time => @work.commit_time)
|
||||
stu_work = @homework.student_works.where(:user_id=> members[i].to_i).empty? ? StudentWork.new : @homework.student_works.where(:user_id=> members[i].to_i).first
|
||||
stu_work.update_attributes(:name => @work.name, :description => @work.description, :homework_common_id => @homework.id,:project_id => @work.project_id, :late_penalty => @work.late_penalty,:work_status => @work.work_status, :commit_time => Time.now, :group_id => @work.group_id)
|
||||
if stu_work.save
|
||||
stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => @work.id, :project_id => stu_work.project_id == 0 ? -1 : stu_work.project_id, :user_id => members[i].to_i, :is_leader => 0, :course_id => @homework.course_id)
|
||||
stu_project.save
|
||||
|
|
@ -724,25 +659,16 @@ class StudentWorkController < ApplicationController
|
|||
course_message = CourseMessage.new(:user_id =>User.current.id,:content=>"edit",:course_message_id=>@work.id,:course_id => @course.id,:course_message_type=>"StudentWork", :status => 9) #作品提交记录
|
||||
course_message.save
|
||||
@student_work = @work
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
=begin
|
||||
respond_to do |format|
|
||||
format.html{redirect_to edit_student_work_url(@work)}
|
||||
end
|
||||
=end
|
||||
@submit_result = false
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html{redirect_to student_work_index_path(:homework => @homework.id)}
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
#匿评申诉消息状态更新
|
||||
@index = params[:index]
|
||||
if @work && !@work.student_works_scores.where("reviewer_role = 3 and appeal_status != 0").blank?
|
||||
score_ids = "(" + @work.student_works_scores.where("reviewer_role = 3 and appeal_status != 0").map{|score| score.id}.join(",") + ")"
|
||||
score_appeal_ids = StudentWorksScoresAppeal.where("student_works_score_id in #{score_ids}").blank? ? "(-1)" : "(" + StudentWorksScoresAppeal.where("student_works_score_id in #{score_ids}").map{|score_appeal| score_appeal.id}.join(",") + ")"
|
||||
|
|
@ -752,15 +678,24 @@ class StudentWorkController < ApplicationController
|
|||
appeal_message.update_all(:viewed => true)
|
||||
end
|
||||
|
||||
@is_focus = params[:is_focus] if params[:is_focus]
|
||||
@score = student_work_score @work,User.current
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
||||
if @homework.homework_detail_manual.comment_status == 2 && !@is_teacher && @work.user != User.current
|
||||
if (@homework.homework_detail_manual.comment_status == 3 || @homework.homework_detail_manual.comment_status == 4) && !@is_teacher && @work.user != User.current
|
||||
@student_work_scores = @work.student_works_scores.where("user_id = #{User.current.id} and reviewer_role = 3").order("updated_at desc")
|
||||
else
|
||||
@student_work_scores = student_work_score_record(@work)
|
||||
end
|
||||
if @homework.homework_type == 3 && @work.work_status != 0
|
||||
student_works = @homework.student_works.where("group_id = #{@work.group_id} and user_id != #{@work.user_id}")
|
||||
@team_work = User.where(:id => student_works.map(&:user_id))
|
||||
elsif @homework.homework_type == 4
|
||||
@shixun = @homework.homework_commons_shixuns.shixun
|
||||
@myshixun = Myshixun.find @work.myshixun_id
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html{render :layout => 'base_edu'}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -770,6 +705,7 @@ class StudentWorkController < ApplicationController
|
|||
user_ids = pros.empty? ? "(-1)" : "(" + pros.map{|stu|stu.user_id}.join(",") + ")"
|
||||
student_works = @homework.student_works.where("user_id in #{user_ids}")
|
||||
|
||||
|
||||
#更新CourseHomeworkStatistics中每个学生的未交作品数、已交作品数、迟交作品数
|
||||
student_works.each do |sw|
|
||||
course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(@homework.course_id, sw.user_id)
|
||||
|
|
@ -779,7 +715,7 @@ class StudentWorkController < ApplicationController
|
|||
course_statistics.update_attribute('committed_work_num', (course_statistics.committed_work_num - 1) < 0 ? 0 : (course_statistics.committed_work_num - 1)) if course_statistics
|
||||
course_statistics.update_attribute('un_commit_work_num', course_statistics.un_commit_work_num + 1) if course_statistics
|
||||
end
|
||||
student_works.delete_all
|
||||
student_works.update_all(:work_status => 0, :description => nil, :project_id => 0, :late_penalty => 0,:work_status => 0, :commit_time => nil)
|
||||
pros.delete_all
|
||||
|
||||
project = @work.student_work_projects.where("is_leader = 1").first
|
||||
|
|
@ -788,7 +724,9 @@ class StudentWorkController < ApplicationController
|
|||
else
|
||||
project.destroy
|
||||
end
|
||||
@work.destroy
|
||||
|
||||
@homework.student_works.all_commit.where("group_id > #{@work.group_id}").update_all("group_id = group_id - 1")
|
||||
@work.update_all(:work_status => 0, :description => nil, :project_id => 0, :late_penalty => 0,:work_status => 0, :commit_time => nil)
|
||||
else
|
||||
#更新CourseHomeworkStatistics中学生的已交作品数、迟交作品数
|
||||
course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(@homework.course_id, @work.user_id)
|
||||
|
|
@ -900,12 +838,57 @@ class StudentWorkController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def relate_myshixun
|
||||
myshixun = Myshixun.where(:shixun_id => @homework.homework_commons_shixuns.shixun_id, :user_id => User.current.id).first
|
||||
if myshixun
|
||||
work = @homework.student_works.where(:user_id => User.current.id).first
|
||||
work = work || StudentWork.new(:homework_common_id => @homework.id, :user_id => User.current.id, :work_status => 0)
|
||||
if work.work_status == 0
|
||||
work.myshixun_id = myshixun.id
|
||||
work.commit_time = Time.now
|
||||
if @homework.end_time < Time.now
|
||||
work.late_penalty = @homework.late_penalty
|
||||
work.work_status = 2
|
||||
|
||||
#更新CourseHomeworkStatistics中学生的迟交作品数
|
||||
course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(@homework.course_id, User.current.id)
|
||||
course_statistics.update_attribute('late_commit_work_num', course_statistics.late_commit_work_num + 1) if course_statistics
|
||||
else
|
||||
work.late_penalty = 0
|
||||
work.work_status = 1
|
||||
end
|
||||
if work.save
|
||||
#更新CourseHomeworkStatistics中学生的未交作品数、已交作品数
|
||||
course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(@homework.course_id, User.current.id)
|
||||
course_statistics.update_attribute('committed_work_num', course_statistics.committed_work_num + 1) if course_statistics
|
||||
course_statistics.update_attribute('un_commit_work_num', (course_statistics.un_commit_work_num - 1) < 0 ? 0 : (course_statistics.un_commit_work_num - 1)) if course_statistics
|
||||
|
||||
@homework.update_column(:updated_at, Time.now)
|
||||
update_course_activity(@homework.class,@homework.id)
|
||||
update_user_activity(@homework.class,@homework.id)
|
||||
update_org_activity(@homework.class,@homework.id)
|
||||
|
||||
course_message = CourseMessage.new(:user_id =>User.current.id,:content=>"new",:course_message_id=>work.id,:course_id => @course.id,:course_message_type=>"StudentWork", :status => 9) #作品提交记录
|
||||
course_message.save
|
||||
@status = 1
|
||||
end
|
||||
else
|
||||
@status = 2
|
||||
end
|
||||
else
|
||||
@status = 0
|
||||
end
|
||||
end
|
||||
|
||||
#添加评分,已评分则为修改评分
|
||||
def add_score
|
||||
@is_last = params[:is_last] == "true"
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
||||
#老师、教辅可以随时评分,学生只能在匿评作业的匿评阶段进行评分
|
||||
render_403 and return unless @is_teacher || @homework.homework_detail_manual.comment_status == 2
|
||||
unless @is_teacher || @homework.homework_detail_manual.comment_status == 3
|
||||
render_403
|
||||
return
|
||||
end
|
||||
@score = student_work_score @work,User.current
|
||||
#@score.comment = params[:new_form][:user_message] if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != ""
|
||||
#@score.score = params[:score] if params[:score]
|
||||
|
|
@ -928,6 +911,11 @@ class StudentWorkController < ApplicationController
|
|||
@new_score.student_work_id = @work.id
|
||||
if @is_teacher && !@new_score.score.nil? && @work.work_status == 0
|
||||
@work.update_attributes(:work_status => 1, :commit_time => Time.now)
|
||||
if @homework.homework_type == 3
|
||||
@work.update_attributes(:group_id => @homework.student_works.all_commit.select("distinct group_id").count + 1)
|
||||
stu_project = StudentWorkProject.new(:homework_common_id => @homework.id, :student_work_id => @work.id, :project_id => 0, :user_id => @work.user_id, :is_leader => 1, :course_id => @homework.course_id)
|
||||
stu_project.save
|
||||
end
|
||||
#更新CourseHomeworkStatistics中学生的已交作品数、未交作品数
|
||||
course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(@homework.course_id, @work.user_id)
|
||||
course_statistics.update_attribute('committed_work_num', course_statistics.committed_work_num + 1) if course_statistics
|
||||
|
|
@ -963,7 +951,7 @@ class StudentWorkController < ApplicationController
|
|||
case @new_score.reviewer_role
|
||||
when 1 #教师评分:最后一个教师评分为最终评分
|
||||
@work.teacher_score = @new_score.score
|
||||
if @is_group_leader && params[:same_score]
|
||||
if params[:same_score]
|
||||
add_score_to_member @work, @homework, @new_score
|
||||
end
|
||||
when 2 #教辅评分 教辅评分显示平均分
|
||||
|
|
@ -974,7 +962,7 @@ class StudentWorkController < ApplicationController
|
|||
else
|
||||
@work.teaching_asistant_score = @new_score.score
|
||||
end
|
||||
if @is_group_leader && params[:same_score]
|
||||
if params[:same_score]
|
||||
add_score_to_member @work, @homework, @new_score
|
||||
end
|
||||
when 3 #学生评分 学生评分显示平均分
|
||||
|
|
@ -997,8 +985,13 @@ class StudentWorkController < ApplicationController
|
|||
update_org_activity(@homework.class,@homework.id)
|
||||
if @work.save
|
||||
@work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => @work.id).first
|
||||
@count = @homework.student_works.has_committed.count
|
||||
@student_work_scores = student_work_score_record @work
|
||||
@score = @new_score
|
||||
if @homework.homework_detail_manual.comment_status == 3 && !@is_teacher && @work.user != User.current
|
||||
@student_work_scores = @work.student_works_scores.where("user_id = #{User.current.id} and reviewer_role = 3").order("updated_at desc")
|
||||
else
|
||||
@student_work_scores = student_work_score_record(@work)
|
||||
end
|
||||
@count = @student_work_scores.count
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
|
|
@ -1022,6 +1015,14 @@ class StudentWorkController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# 删除教师/教辅的评分记录
|
||||
def destroy_score
|
||||
@score = @work.student_works_scores.where(:id => params[:score_id]).first
|
||||
if @score
|
||||
@score.destroy
|
||||
end
|
||||
end
|
||||
|
||||
#删除评分的回复
|
||||
def destroy_score_reply
|
||||
@jour = JournalsForMessage.find params[:jour_id]
|
||||
|
|
@ -1275,6 +1276,27 @@ class StudentWorkController < ApplicationController
|
|||
@is_last = params[:is_last]
|
||||
end
|
||||
|
||||
# 删除评论记录,最新的一条不删除
|
||||
def delete_score_comment
|
||||
begin
|
||||
student_work_score = StudentWorksScore.where(:id => params[:score_id]).first
|
||||
@work = student_work_score.student_work
|
||||
@count = @work.student_works_scores.count
|
||||
student_work_id = student_work_score.student_work_id
|
||||
can_delete = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? || User.current.id == student_work_score.user_id
|
||||
unless can_delete
|
||||
render_403
|
||||
return
|
||||
end
|
||||
student_work_score.destroy
|
||||
respond_to do |format|
|
||||
format.html{redirect_to student_work_path(student_work_id)}
|
||||
end
|
||||
rescue Exception => e
|
||||
logger.error("###{e}")
|
||||
end
|
||||
end
|
||||
|
||||
def deal_appeal_score
|
||||
@student_work_score = StudentWorksScore.where("id = #{params[:score_id].to_i}").first
|
||||
@is_last = params[:is_last] == "true" ? true : false
|
||||
|
|
@ -1369,10 +1391,7 @@ class StudentWorkController < ApplicationController
|
|||
CourseMessage.create(:user_id => student_work.homework_common.user_id, :course_id => student_work.homework_common.course_id, :viewed => false,:course_message_id=>attachment.container_id,:course_message_type=>'StudentWork',:status=>2)
|
||||
end
|
||||
@work.update_attributes(:re_commit => 1)
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
@homework = @work.homework_common
|
||||
redirect_to student_work_path(@work)
|
||||
end
|
||||
|
||||
def new_student_work_project
|
||||
|
|
@ -1445,16 +1464,19 @@ class StudentWorkController < ApplicationController
|
|||
unless params[:name].nil?
|
||||
name = params[:name]
|
||||
end
|
||||
if @homework.homework_detail_group.base_on_project == 0
|
||||
all_student_ids = "(" + @homework.course.student.map{|student| student.student_id}.join(",") + ")"
|
||||
else
|
||||
pro = Project.find @homework.student_work_projects.where("user_id=?",User.current.id).first.project_id
|
||||
all_student_ids = "(" + pro.members.map{|member| member.user_id}.join(",") + ")"
|
||||
end
|
||||
all_students = User.where("id in #{all_student_ids}")
|
||||
student_work_id = @homework.student_work_projects.where("user_id=? and student_work_id is not null",User.current.id).first.nil? ? -1 : @homework.student_work_projects.where("user_id=?",User.current.id).first.student_work_id
|
||||
@commit_student_ids = @homework.student_works.where("id != #{student_work_id}").map{|student| student.user_id}
|
||||
@users = searchstudent_by_name all_students,name
|
||||
|
||||
student_works = @homework.student_works.where("work_status != 0")
|
||||
com_student_ids = student_works.blank? ? '(-1)' : '(' + student_works.map(&:user_id).join(",") + ')'
|
||||
@users = User.includes(:user_extensions).where(:id => @course.student.where("student_id not in #{com_student_ids} and student_id != #{User.current.id}").map(&:student_id))
|
||||
@users = searchstudent_by_name @users,name
|
||||
|
||||
@limit = 10
|
||||
@page = (params['page'] || 1).to_i
|
||||
@user_count = @users.count
|
||||
@user_pages = Paginator.new @user_count, @limit, params['page'] || 1
|
||||
@offset ||= @user_pages.offset
|
||||
@users = paginateHelper @users,@limit
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
|
|
@ -1590,8 +1612,7 @@ class StudentWorkController < ApplicationController
|
|||
select_homework = homeworks
|
||||
else
|
||||
name = name.downcase
|
||||
select_homework = homeworks.select{ |homework|
|
||||
homework.user[:login].to_s.downcase.include?(name) || homework.user.user_extensions[:student_id].to_s.downcase.include?(name) || (homework.user[:lastname].to_s.downcase + homework.user[:firstname].to_s.downcase).include?(name)
|
||||
select_homework = homeworks.select{ |homework| homework.user.user_extensions[:student_id].to_s.downcase.include?(name) || (homework.user[:lastname].to_s.downcase + homework.user[:firstname].to_s.downcase).include?(name)
|
||||
}
|
||||
end
|
||||
select_homework
|
||||
|
|
@ -1758,7 +1779,7 @@ class StudentWorkController < ApplicationController
|
|||
student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id, is_test: is_test).first
|
||||
if student_work.nil?
|
||||
@homework.student_works.build(
|
||||
name: params[:title],
|
||||
name: @homework.name.to_s + "的作品提交",
|
||||
description: params[:src],
|
||||
user_id: User.current.id,
|
||||
is_test: is_test
|
||||
|
|
@ -1816,129 +1837,4 @@ class StudentWorkController < ApplicationController
|
|||
end
|
||||
JSON.parse(res.body)
|
||||
end
|
||||
|
||||
#成绩计算
|
||||
def set_final_score homework,student_work
|
||||
if homework && homework.homework_detail_manual
|
||||
if homework.homework_type != 2 #非编程作业
|
||||
if homework.teacher_priority == 1 #教师优先
|
||||
if student_work.teacher_score
|
||||
student_work.final_score = student_work.teacher_score
|
||||
student_work.work_score = student_work.teacher_score - student_work.absence_penalty - student_work.late_penalty
|
||||
else
|
||||
if student_work.teaching_asistant_score.nil?
|
||||
student_work.final_score = student_work.student_score
|
||||
elsif student_work.student_score.nil?
|
||||
student_work.final_score = student_work.teaching_asistant_score
|
||||
else
|
||||
ta_proportion = homework.homework_detail_manual.ta_proportion
|
||||
final_ta_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * BigDecimal.new("#{ta_proportion}")
|
||||
final_s_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
||||
final_score = final_ta_score + final_s_score
|
||||
student_work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
if student_work.final_score
|
||||
score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty - student_work.appeal_penalty
|
||||
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
|
||||
else
|
||||
student_work.work_score = nil
|
||||
end
|
||||
end
|
||||
else #不考虑教师评分
|
||||
if student_work.teaching_asistant_score.nil?
|
||||
student_work.final_score = student_work.student_score
|
||||
elsif student_work.student_score.nil?
|
||||
student_work.final_score = student_work.teaching_asistant_score
|
||||
else
|
||||
ta_proportion = homework.homework_detail_manual.ta_proportion
|
||||
final_ta_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * BigDecimal.new("#{ta_proportion}")
|
||||
final_s_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
||||
final_score = final_ta_score + final_s_score
|
||||
student_work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
if student_work.final_score
|
||||
score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty - student_work.appeal_penalty
|
||||
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
|
||||
else
|
||||
student_work.work_score = nil
|
||||
end
|
||||
end
|
||||
elsif homework.homework_type == 2 && homework.homework_detail_programing #编程作业-----设定:系统评分必定不为空
|
||||
if homework.teacher_priority == 1 #教师优先
|
||||
if student_work.teacher_score
|
||||
student_work.final_score = student_work.teacher_score
|
||||
student_work.work_score = student_work.teacher_score - student_work.absence_penalty - student_work.late_penalty - student_work.appeal_penalty
|
||||
else
|
||||
if student_work.teaching_asistant_score.nil? #教辅未评分
|
||||
if student_work.student_score.nil?
|
||||
student_work.final_score = student_work.system_score
|
||||
else
|
||||
ta_proportion = homework.homework_detail_programing.ta_proportion + homework.homework_detail_manual.ta_proportion / 2
|
||||
final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{ta_proportion}")
|
||||
final_st_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
||||
final_score = final_sy_score + final_st_score
|
||||
student_work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
elsif student_work.student_score.nil? #学生未评分
|
||||
if student_work.teaching_asistant_score.nil?
|
||||
student_work.final_score = student_work.system_score
|
||||
else
|
||||
ta_proportion = homework.homework_detail_programing.ta_proportion + (1.0 - homework.homework_detail_manual.ta_proportion - homework.homework_detail_programing.ta_proportion) / 2
|
||||
final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{ta_proportion}")
|
||||
final_ts_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
||||
final_score = final_sy_score + final_ts_score
|
||||
student_work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
else
|
||||
final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{homework.homework_detail_programing.ta_proportion}")
|
||||
final_ts_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * BigDecimal.new("#{homework.homework_detail_manual.ta_proportion}")
|
||||
final_st_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{homework.homework_detail_programing.ta_proportion}") - BigDecimal.new("#{homework.homework_detail_manual.ta_proportion}"))
|
||||
final_score = final_sy_score + final_ts_score + final_st_score
|
||||
student_work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
if student_work.final_score
|
||||
score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty - student_work.appeal_penalty
|
||||
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
|
||||
else
|
||||
student_work.work_score = nil
|
||||
end
|
||||
end
|
||||
else #不考虑教师评分
|
||||
if student_work.teaching_asistant_score.nil? #教辅未评分
|
||||
if student_work.student_score.nil?
|
||||
student_work.final_score = student_work.system_score
|
||||
else
|
||||
ta_proportion = homework.homework_detail_programing.ta_proportion + homework.homework_detail_manual.ta_proportion / 2
|
||||
final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{ta_proportion}")
|
||||
final_st_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
||||
final_score = final_sy_score + final_st_score
|
||||
student_work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
elsif student_work.student_score.nil? #学生未评分
|
||||
if student_work.teaching_asistant_score.nil?
|
||||
student_work.final_score = student_work.system_score
|
||||
else
|
||||
ta_proportion = homework.homework_detail_programing.ta_proportion + (1.0 - homework.homework_detail_manual.ta_proportion - homework.homework_detail_programing.ta_proportion) / 2
|
||||
final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{ta_proportion}")
|
||||
final_ts_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
||||
final_score = final_sy_score + final_ts_score
|
||||
student_work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
else
|
||||
final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{homework.homework_detail_programing.ta_proportion}")
|
||||
final_ts_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * BigDecimal.new("#{homework.homework_detail_manual.ta_proportion}")
|
||||
final_st_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{homework.homework_detail_programing.ta_proportion}") - BigDecimal.new("#{homework.homework_detail_manual.ta_proportion}"))
|
||||
final_score = final_sy_score + final_ts_score + final_st_score
|
||||
student_work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
if student_work.final_score
|
||||
score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty - student_work.appeal_penalty
|
||||
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
|
||||
else
|
||||
student_work.work_score = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,99 @@
|
|||
# encoding: utf-8
|
||||
class SubjectsController < ApplicationController
|
||||
layout 'base_subject'
|
||||
before_filter :require_login
|
||||
before_filter :check_authentication
|
||||
before_filter :find_subject, :except => [:index, :create_subject, :new_subject, :append_to_stage]
|
||||
|
||||
include ApplicationHelper
|
||||
|
||||
def index
|
||||
@order = params[:order] || "created_at"
|
||||
bsort = params[:sort] || "desc"
|
||||
@sort = bsort == "desc" ? "asc" : "desc"
|
||||
search = params[:search]
|
||||
ids = Subject.find_by_sql("select group_concat(id) as allId from subjects where id in (SELECT distinct(subject_id) FROM `stages`)")
|
||||
@subjects = Subject.where(:id => ids[0].allId.nil? ? "-1" : ids[0].allId.split(",")).reorder("#{@order} #{bsort}")
|
||||
@subject_created_count = Subject.find_by_sql("select count(*) as count from subjects where id in (SELECT distinct(subject_id) FROM `stages`) and user_id=#{User.current.id};").first.try(:count)
|
||||
@subjects_all_count = @subjects.count
|
||||
#@subjects = Subject.where("name like ?", "%#{search}%").reorder("#{@order} #{@sort}")
|
||||
@subjects_count = @subjects.count
|
||||
@limit = 16
|
||||
@is_remote = true
|
||||
@subject_pages = Paginator.new @subjects_count, @limit, params['page'] || 1
|
||||
@offset ||= @subject_pages.offset
|
||||
@subjects = paginateHelper @subjects, @limit
|
||||
render :layout => "base_edu"
|
||||
end
|
||||
|
||||
def show
|
||||
@stages = @subject.stages
|
||||
end
|
||||
|
||||
def new_subject
|
||||
if Course.where(:tea_id => User.current.id).count > 0
|
||||
@status = 1
|
||||
@course_lists = CourseList.where(:id => ShixunMajorCourse.where(:shixun_id => Shixun.where(:user_id => User.current.id).map(&:id)).map(&:course_list_id))
|
||||
else
|
||||
@status = 0
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def create_subject
|
||||
if params[:course_list_id]
|
||||
course = CourseList.find params[:course_list_id]
|
||||
if course
|
||||
subject = Subject.create(:name => course.name, :user_id => User.current.id, :visits => 0, :status => 0, :course_list_id => course.id)
|
||||
end
|
||||
end
|
||||
redirect_to subject_path(subject)
|
||||
end
|
||||
|
||||
def choose_subject_shixun
|
||||
course_list = @subject.course_list
|
||||
@shixuns = Shixun.where(:user_id => User.current.id, :status => [0, 1, 2], :id => course_list.shixun_major_courses.map(&:shixun_id))
|
||||
@shixuns_count = @shixuns.count
|
||||
@limit = 8
|
||||
@shixuns_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1
|
||||
@offset ||= @shixuns_pages.offset
|
||||
@shixuns = paginateHelper @shixuns, @limit
|
||||
end
|
||||
|
||||
def append_to_stage
|
||||
@shixuns = Shixun.where(:id => params[:shixun_id])
|
||||
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
|
||||
else
|
||||
ApplyAction.create(:container_type => "ApplySubject", :container_id => @subject.id, :user_id => User.current.id, :status => 0)
|
||||
notes = User.current.show_name.to_s + " 申请发布课程实训:<a href='#{subject_path(@subject)}'>#{@subject.name}</a>"
|
||||
JournalsForMessage.create(:jour_id => 1, :jour_type => 'Principal', :user_id => User.current.id, :notes => notes, :private => 1, :reply_id => 0)
|
||||
@status = 1
|
||||
end
|
||||
end
|
||||
|
||||
def cancel_publish
|
||||
apply = ApplyAction.where(:container_type => "ApplySubject", :container_id => @subject.id).order("created_at desc").first
|
||||
if apply && apply.status == 0
|
||||
apply.update_attributes(:status => 3)
|
||||
@subject.update_column('status', 0)
|
||||
end
|
||||
redirect_to subject_path(@subject)
|
||||
end
|
||||
|
||||
private
|
||||
# Find subject of id params[:id]
|
||||
def find_subject
|
||||
@subject = Subject.find_by_id(params[:id])
|
||||
render_404 if @subject.nil?
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
|
@ -5,18 +5,45 @@ class SyllabusesController < ApplicationController
|
|||
include AttachmentsHelper
|
||||
include CoursesHelper
|
||||
include SyllabusesHelper
|
||||
|
||||
include UsersHelper
|
||||
before_filter :is_logged, :only => [:index, :show, :edit, :new, :update, :destroy, :delete_syllabus, :syllabus_resources, :syllabus_homeworks]
|
||||
before_filter :check_authentication
|
||||
before_filter :find_syllabus, :only => [:show, :edit, :update, :destroy, :syllabus_courselist, :edit_syllabus_eng_name, :edit_syllabus_title, :update_base_info, :delete_syllabus,
|
||||
:delete_des, :members, :update_des, :edit_ref, :update_ref, :add_sy_member_alert, :search_not_sy_member, :syllabus_resources, :syllabus_homeworks,
|
||||
:send_homeworks_to_course, :choose_user_course, :send_resources_to_course, :send_r_and_h_to_course]
|
||||
|
||||
def index
|
||||
@status = params[:type].nil? ? 1 : params[:type].to_i # 1表示正在进行,2表示已结束
|
||||
|
||||
user = User.current
|
||||
@syllabuses = user.syllabuses
|
||||
@my_syllabuses = user.syllabuses
|
||||
|
||||
archive_ids = Course.where("tea_id = #{user.id} and is_delete = 1 and syllabus_id is NOT NULL").blank? ? "(-1)" : "(" + Course.where("tea_id = #{user.id} and is_delete = 1 and syllabus_id is NOT NULL").map{|course| course.syllabus_id}.join(",") + ")"
|
||||
@archive_syllabuses = Syllabus.where("id in #{archive_ids}")
|
||||
|
||||
sy_courses = user.courses.visible.not_deleted
|
||||
syllabus_ids = sy_courses.empty? ? '(-1)' : "(" + sy_courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")"
|
||||
syllabus_members = SyllabusMember.where("user_id = #{user.id}")
|
||||
syllabus_member_ids = syllabus_members.empty? ? "(-1)" : "(" + syllabus_members.map{|syl_mem| syl_mem.syllabus_id}.join(',') + ")"
|
||||
@join_syllabuses = Syllabus.where("(id in #{syllabus_ids} or id in #{syllabus_member_ids}) and user_id != #{user.id}")
|
||||
|
||||
@my_syllabuses = syllabus_course_list_sort @my_syllabuses
|
||||
@join_syllabuses = syllabus_course_list_sort @join_syllabuses
|
||||
@my_syllabuses = @my_syllabuses.sort{|x,y| y[:last_update] <=> x[:last_update]}
|
||||
@join_syllabuses = @join_syllabuses.sort{|x,y| y[:last_update] <=> x[:last_update]}
|
||||
@is_course = 1
|
||||
|
||||
respond_to do |format|
|
||||
format.html{ render :layout => 'base_edu'}
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@is_syllabus_member = User.current.admin? || @syllabus.syllabus_members.map{|sm| sm.user_id}.include?(User.current.id)
|
||||
@is_syllabus_teacher = User.current.admin? || @syllabus.syllabus_members.map{|sm| sm.user_id}.include?(User.current.id) || !@syllabus.courses.not_deleted_not_end.select { |course| User.current.has_teacher_role(course)}.blank?
|
||||
@is_syllabus_member = !@syllabus.courses.not_deleted_not_end.select { |course| User.current.member_of_course?(course)}.blank?
|
||||
@is_syllabus_admin = User.current.admin? || @syllabus.syllabus_members.map{|sm| sm.user_id}.include?(User.current.id)
|
||||
@is_authen_teacher = User.current.authentication && User.current.user_extensions.try(:identity) != 1
|
||||
@reference_materials = @syllabus.reference_materials
|
||||
@members = @syllabus.syllabus_members.includes(:user => {:user_extensions => []}).order("rank asc")
|
||||
@courses = @syllabus.courses.where("is_delete = 0 and is_end = 0").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS ca_update").order("ca_update desc")
|
||||
|
|
@ -42,6 +69,7 @@ class SyllabusesController < ApplicationController
|
|||
@syllabus.major_level = params[:major_level].to_i
|
||||
@syllabus.discipline_category_id = params[:discipline_category_id].to_i
|
||||
@syllabus.first_level_discipline_id = params[:first_level_discipline_id].to_i
|
||||
@syllabus.major_id = params[:major_id].to_i
|
||||
@syllabus.syllabus_type = params[:syllabus_type].to_i
|
||||
@syllabus.description = Message.where("id = 19412").first.nil? ? '' : Message.where("id = 19412").first.content
|
||||
if @syllabus && @syllabus.save
|
||||
|
|
@ -89,6 +117,7 @@ class SyllabusesController < ApplicationController
|
|||
@syllabus.major_level = params[:major_level].to_i
|
||||
@syllabus.discipline_category_id = params[:discipline_category_id].to_i
|
||||
@syllabus.first_level_discipline_id = params[:first_level_discipline_id].to_i
|
||||
@syllabus.major_id = params[:major_id].to_i
|
||||
@syllabus.syllabus_type = params[:syllabus_type].to_i
|
||||
if @syllabus.save
|
||||
if title != params[:title].to_s.strip
|
||||
|
|
@ -123,7 +152,7 @@ class SyllabusesController < ApplicationController
|
|||
sy_update_record = SyllabusUpdateRecord.new(:property => 2, :user_id => User.current.id)
|
||||
@syllabus.syllabus_update_records << sy_update_record
|
||||
@reference_materials = @syllabus.reference_materials
|
||||
@is_syllabus_member = User.current.admin? || @syllabus.syllabus_members.map{|sm| sm.user_id}.include?(User.current.id)
|
||||
@is_syllabus_admin = User.current.admin? || @syllabus.syllabus_members.map{|sm| sm.user_id}.include?(User.current.id)
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
|
|
@ -159,6 +188,10 @@ class SyllabusesController < ApplicationController
|
|||
end
|
||||
|
||||
def syllabus_resources
|
||||
@is_syllabus_teacher = User.current.admin? || @syllabus.syllabus_members.map{|sm| sm.user_id}.include?(User.current.id) || !@syllabus.courses.not_deleted_not_end.select { |course| User.current.has_teacher_role(course)}.blank?
|
||||
@is_syllabus_member = !@syllabus.courses.not_deleted_not_end.select { |course| User.current.member_of_course?(course)}.blank?
|
||||
@is_syllabus_admin = User.current.admin? || @syllabus.syllabus_members.map{|sm| sm.user_id}.include?(User.current.id)
|
||||
@is_authen_teacher = User.current.authentication && User.current.user_extensions.try(:identity) != 1
|
||||
@order, @r_sort = params[:order] || "created_at", params[:sort] || "asc"
|
||||
@sort = @r_sort == "desc" ? "asc" : "desc"
|
||||
@resources = sy_resources @syllabus
|
||||
|
|
@ -170,10 +203,16 @@ class SyllabusesController < ApplicationController
|
|||
@resource_count = @resources.count
|
||||
@public_resource_count = @resources.where(:is_public => 1).count
|
||||
@private_resource_count = @resources.where(:is_public => 0).count
|
||||
|
||||
if !(@is_syllabus_admin || @is_syllabus_member)
|
||||
@resources = @resources.where(:is_public => 1)
|
||||
end
|
||||
|
||||
#分页
|
||||
@page_resource_count = @resources.count
|
||||
@limit = 10
|
||||
@is_remote = true
|
||||
@resource_pages = Paginator.new @resource_count, @limit, params['page'] || 1
|
||||
@resource_pages = Paginator.new @page_resource_count, @limit, params['page'] || 1
|
||||
@offset ||= @resource_pages.offset
|
||||
@resources = paginateHelper @resources,@limit
|
||||
respond_to do |format|
|
||||
|
|
@ -182,16 +221,25 @@ class SyllabusesController < ApplicationController
|
|||
end
|
||||
|
||||
def syllabus_homeworks
|
||||
@is_syllabus_teacher = User.current.admin? || @syllabus.syllabus_members.map{|sm| sm.user_id}.include?(User.current.id) || !@syllabus.courses.not_deleted_not_end.select { |course| User.current.has_teacher_role(course)}.blank?
|
||||
@is_syllabus_member = !@syllabus.courses.not_deleted_not_end.select { |course| User.current.member_of_course?(course)}.blank?
|
||||
@is_syllabus_admin = User.current.admin? || @syllabus.syllabus_members.map{|sm| sm.user_id}.include?(User.current.id)
|
||||
@is_authen_teacher = User.current.authentication && User.current.user_extensions.try(:identity) != 1
|
||||
@order, @r_sort = params[:order] || "created_at", params[:sort] || "asc"
|
||||
@sort = @r_sort == "desc" ? "asc" : "desc"
|
||||
@homeworks = (sy_homeworks @syllabus).order("#{@order} #{@sort}")
|
||||
@homeworks = @syllabus.homework_banks.order("#{@order} #{@sort}")
|
||||
@homework_count = @homeworks.count
|
||||
@public_homework_count = @homeworks.where(:is_public => 1).count
|
||||
@private_homework_count = @homeworks.where(:is_public => 0).count
|
||||
|
||||
if !(@is_syllabus_admin || @is_syllabus_member)
|
||||
@homeworks = @homeworks.where(:is_public => 1)
|
||||
end
|
||||
|
||||
@page_homework_count = @homeworks.count
|
||||
@limit = 10
|
||||
@is_remote = true
|
||||
@homework_pages = Paginator.new @homework_count, @limit, params['page'] || 1
|
||||
@homework_pages = Paginator.new @page_homework_count, @limit, params['page'] || 1
|
||||
@offset ||= @homework_pages.offset
|
||||
@homeworks = paginateHelper @homeworks, @limit
|
||||
respond_to do |format|
|
||||
|
|
@ -202,9 +250,9 @@ class SyllabusesController < ApplicationController
|
|||
def choose_user_course
|
||||
if !params[:search].nil?
|
||||
search = "%#{params[:search].to_s.strip.downcase}%"
|
||||
@courses = User.current.courses.where("is_delete = 0 and is_end = 0 and (#{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p)",:p=>search).select { |course| User.current.allowed_to?(:as_teacher,course)}
|
||||
@courses = User.current.courses.where("is_delete = 0 and is_end = 0 and (#{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p)",:p=>search).select { |course| User.current.has_teacher_role(course)}
|
||||
else
|
||||
@courses = User.current.courses.where("is_delete = 0 and is_end = 0").select { |course| User.current.allowed_to?(:as_teacher,course)}
|
||||
@courses = User.current.courses.where("is_delete = 0 and is_end = 0").select { |course| User.current.has_teacher_role(course)}
|
||||
end
|
||||
@resource_ids = params[:check_resource] if params[:check_resource]
|
||||
@homework_ids = params[:check_homework] if params[:check_homework]
|
||||
|
|
@ -240,7 +288,7 @@ class SyllabusesController < ApplicationController
|
|||
course = Course.find params[:course_id]
|
||||
if course
|
||||
resources = sy_resources @syllabus
|
||||
homeworks = (sy_homeworks @syllabus).order("#{@order} #{@sort}")
|
||||
homeworks = @syllabus.homework_banks.order("#{@order} #{@sort}")
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
begin
|
||||
|
|
@ -279,7 +327,7 @@ class SyllabusesController < ApplicationController
|
|||
def destroy
|
||||
if @syllabus && @syllabus.courses.not_deleted.empty?
|
||||
@syllabus.destroy
|
||||
redirect_to user_courselist_user_path(User.current)
|
||||
redirect_to syllabuses_path()
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -404,6 +452,23 @@ class SyllabusesController < ApplicationController
|
|||
render :json =>data
|
||||
end
|
||||
|
||||
def get_major
|
||||
data = {result:0,options:[]}
|
||||
if params[:first_level_discipline_id]
|
||||
if Major.where(:first_level_discipline_id => params[:first_level_discipline_id].to_i).count > 0
|
||||
data[:result] = 1
|
||||
Major.where(:first_level_discipline_id => params[:first_level_discipline_id].to_i).each do |dis|
|
||||
option = []
|
||||
option << dis.name.to_s
|
||||
option << dis.id
|
||||
data[:options] << option
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
render :json =>data
|
||||
end
|
||||
|
||||
private
|
||||
def find_syllabus
|
||||
@syllabus = Syllabus.find params[:id]
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ class UsersController < ApplicationController
|
|||
|
||||
#
|
||||
before_filter :can_show_course, :only => [:user_courses,:user_homeworks]
|
||||
before_filter :check_authentication
|
||||
|
||||
before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses, :unsolved_issues_list, :unfinished_homework_list, :user_manage_homeworks,
|
||||
:unfinished_poll_list, :user_homeworks,:student_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments, :update_message_viewed,
|
||||
:anonymous_evaluation_list,:unfinished_test_list, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index, :user_receive_homeworks,
|
||||
|
|
@ -43,7 +45,7 @@ class UsersController < ApplicationController
|
|||
:user_courses4show,:user_projects4show,:user_contests4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction,
|
||||
:user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course,:user_courselist,:user_projectlist,:sort_syllabus_list,
|
||||
:sort_project_list,:my_homeworks,:manage_or_receive_homeworks,:search_m_r_homeworks, :cancel_or_collect,:expand_courses,:homepage, :user_issues, :course_community, :project_community, :contest_community,
|
||||
:user_shixuns]
|
||||
:shixuns, :user_show_course_list, :shixuns_or_courses_filter]
|
||||
before_filter :auth_user_extension, only: :show
|
||||
before_filter :show_system_message, :only => [:show]
|
||||
#before_filter :rest_user_score, only: :show
|
||||
|
|
@ -354,6 +356,7 @@ class UsersController < ApplicationController
|
|||
case @type
|
||||
when 'HomeworkCommon'
|
||||
@root = HomeworkCommon.find reply.jour_id
|
||||
@homework = @root
|
||||
options = {:notes => params[:reply_message], :reply_id => reply.user_id,:user_id => User.current.id,:m_parent_id => params[:reply_id].to_i,:m_reply_id => params[:reply_id].to_i, :root_id => reply.root_id}
|
||||
comment = HomeworkCommon.add_homework_jour(User.current, params[:reply_message], reply.jour_id, reply.root_id, options)
|
||||
@root.update_column('updated_at', Time.now)
|
||||
|
|
@ -500,9 +503,9 @@ class UsersController < ApplicationController
|
|||
# 初始化/更新 点击按钮时间, 24小时内显示系统消息
|
||||
update_onclick_time
|
||||
# 全部设为已读
|
||||
# if params[:viewed] == "all"
|
||||
# if params[:viewed] == "all"
|
||||
# update_message_viewed(@user)
|
||||
# end
|
||||
# end
|
||||
# @new_message_count = forge_querys.count + forum_querys.count + course_querys.count + user_querys.count
|
||||
courses = @user.courses.where("is_delete = 1")
|
||||
course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")"
|
||||
|
|
@ -584,24 +587,24 @@ class UsersController < ApplicationController
|
|||
# 消息设置为已读
|
||||
def update_message_viewed
|
||||
if User.current.id == @user.id
|
||||
course_querys = CourseMessage.where("user_id =? and viewed =?", @user.id, 0)
|
||||
forge_querys = ForgeMessage.where("user_id =? and viewed =?", @user.id, 0)
|
||||
user_querys = UserFeedbackMessage.where("user_id =? and viewed =?", @user.id, 0)
|
||||
forum_querys = MemoMessage.where("user_id =? and viewed =?", @user.id, 0)
|
||||
org_querys = OrgMessage.where("user_id=? and viewed=0", @user.id)
|
||||
at_querys = AtMessage.where("user_id=? and viewed=0", @user.id)
|
||||
contest_querys = ContestMessage.where(:user_id => @user.id, :viewed => 0)
|
||||
blog_querys = BlogMessage.where(:user_id => @user.id, :viewed => 0)
|
||||
applied_querys = AppliedMessage.where("user_id=? and viewed =?", @user.id, 0)
|
||||
course_querys.update_all(:viewed => true) unless course_querys.nil?
|
||||
forge_querys.update_all(:viewed => true) unless forge_querys.nil?
|
||||
user_querys.update_all(:viewed => true) unless user_querys.nil?
|
||||
forum_querys.update_all(:viewed => true) unless forum_querys.nil?
|
||||
org_querys.update_all(:viewed => true) unless org_querys.nil?
|
||||
at_querys.update_all(:viewed => true) unless at_querys.nil?
|
||||
contest_querys.update_all(:viewed => true) unless contest_querys.nil?
|
||||
blog_querys.update_all(:viewed => true) unless blog_querys.nil?
|
||||
applied_querys.update_all(:viewed => true) unless applied_querys.nil?
|
||||
course_querys = CourseMessage.where("user_id =? and viewed =?", @user.id, 0)
|
||||
forge_querys = ForgeMessage.where("user_id =? and viewed =?", @user.id, 0)
|
||||
user_querys = UserFeedbackMessage.where("user_id =? and viewed =?", @user.id, 0)
|
||||
forum_querys = MemoMessage.where("user_id =? and viewed =?", @user.id, 0)
|
||||
org_querys = OrgMessage.where("user_id=? and viewed=0", @user.id)
|
||||
at_querys = AtMessage.where("user_id=? and viewed=0", @user.id)
|
||||
contest_querys = ContestMessage.where(:user_id => @user.id, :viewed => 0)
|
||||
blog_querys = BlogMessage.where(:user_id => @user.id, :viewed => 0)
|
||||
applied_querys = AppliedMessage.where("user_id=? and viewed =?", @user.id, 0)
|
||||
course_querys.update_all(:viewed => true) unless course_querys.nil?
|
||||
forge_querys.update_all(:viewed => true) unless forge_querys.nil?
|
||||
user_querys.update_all(:viewed => true) unless user_querys.nil?
|
||||
forum_querys.update_all(:viewed => true) unless forum_querys.nil?
|
||||
org_querys.update_all(:viewed => true) unless org_querys.nil?
|
||||
at_querys.update_all(:viewed => true) unless at_querys.nil?
|
||||
contest_querys.update_all(:viewed => true) unless contest_querys.nil?
|
||||
blog_querys.update_all(:viewed => true) unless blog_querys.nil?
|
||||
applied_querys.update_all(:viewed => true) unless applied_querys.nil?
|
||||
end
|
||||
redirect_to user_path(@user)
|
||||
end
|
||||
|
|
@ -652,11 +655,72 @@ class UsersController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# 我发布的实训
|
||||
def shixuns_zone
|
||||
@shixuns = Shixun.where(:user_id => User.current)
|
||||
# params: index 1 课程 / 2 实训
|
||||
# search 搜索关键字
|
||||
def search_shixuns_or_courses
|
||||
@index = params[:index].to_i
|
||||
@search = params[:search]
|
||||
@limit = 16
|
||||
if 1 == @index
|
||||
@course_result = Course.where("is_end = 0 and is_delete = 0 and name like '%#{@search}%'").order("created_at desc")
|
||||
@course_result_count = @course_result.count
|
||||
@course_result_pages = Paginator.new @course_result_count, @limit, params['page'] || 1
|
||||
@offset ||= @course_result_pages.offset
|
||||
@course_result = paginateHelper @course_result, @limit
|
||||
else
|
||||
@shixuns_result = Shixun.where(:status => [2,3]).where("name like ?", "%#{@search}%").reorder("created_at desc")
|
||||
@shixuns_result_count = @shixuns_result.count
|
||||
@shixun_pages = Paginator.new @shixuns_result_count, @limit, params['page'] || 1
|
||||
@offset ||= @shixun_pages.offset
|
||||
@shixuns_result = paginateHelper @shixuns_result, @limit
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html{render :layout=>'base_users_new'}
|
||||
format.html{render :layout=>'base_edu'}
|
||||
end
|
||||
end
|
||||
|
||||
# 我发布的实训
|
||||
def shixuns
|
||||
@my_shixun = true
|
||||
@type = params[:type]
|
||||
if @type == "1"
|
||||
ids = Shixun.find_by_sql("select shixun_id from shixun_members where role=2 and user_id=#{@user.id}")
|
||||
ids2 = Shixun.find_by_sql("select id from shixuns where id in (select shixun_id from myshixuns where user_id = #{@user.id})")
|
||||
ids = ids.map{|shixun| shixun.shixun_id} unless ids.blank?
|
||||
ids2 = ids2.map{|shixun| shixun.id} unless ids2.blank?
|
||||
id = ids + ids2
|
||||
id = id.uniq
|
||||
@shixuns = Shixun.where(:id => id)
|
||||
else
|
||||
@shixuns = Shixun.where(:user_id => @user.id)
|
||||
end
|
||||
@shixuns_count = @shixuns.count
|
||||
@limit = 10
|
||||
@shixun_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1
|
||||
@offset ||= @shixun_pages.offset
|
||||
@shixuns = paginateHelper @shixuns, @limit
|
||||
respond_to do |format|
|
||||
format.html{render :layout=> 'base_edu'}
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def my_join_shixuns
|
||||
# 我参入的
|
||||
ids = Shixun.find_by_sql("select id from shixun_members where role=2 and user_id=#{@user.id}")
|
||||
ids2 = Shixun.find_by_sql("select id from shixuns where id in (select shixun_id from myshixuns where user_id = #{@user.id})")
|
||||
ids = ids.map{|shixun| shixun.id} unless ids.blank?
|
||||
ids2 = ids2.map{|shixun| shixun.id} unless ids2.blank?
|
||||
id = ids + ids2
|
||||
id = id.uniq
|
||||
@shixuns = Shixun.where(:id => id)
|
||||
@shixuns_count = @shixuns.count
|
||||
@limit = 10
|
||||
@shixun_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1
|
||||
@offset ||= @shixun_pages.offset
|
||||
@shixuns = paginateHelper @shixuns, @limit
|
||||
respond_to do |format|
|
||||
format.html{render :layout=> 'base_edu'}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -720,11 +784,8 @@ class UsersController < ApplicationController
|
|||
c = Course.find(@msg.course_id)
|
||||
cs.send_wechat_join_class_notice apply_user,c,7,1
|
||||
end
|
||||
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
redirect_to settings_course_path(@msg.course_id, :tab => 'member')
|
||||
end
|
||||
|
||||
# 处理资源引用请求
|
||||
|
|
@ -1007,72 +1068,7 @@ class UsersController < ApplicationController
|
|||
course_ids = params[:course_ids]
|
||||
course_ids.each do |course_id|
|
||||
course = Course.find course_id.to_i
|
||||
new_homework = HomeworkCommon.new
|
||||
new_homework.name = homework.name
|
||||
new_homework.user_id = User.current.id
|
||||
new_homework.description = homework.description
|
||||
new_homework.homework_type = homework.homework_type
|
||||
new_homework.late_penalty = 0
|
||||
new_homework.course_id = course.id
|
||||
new_homework.teacher_priority = 1
|
||||
new_homework.anonymous_comment = 1
|
||||
new_homework.quotes = 0
|
||||
new_homework.is_open = 0
|
||||
new_homework.homework_bank_id = homework.id
|
||||
homework.attachments.each do |attachment|
|
||||
att = attachment.copy
|
||||
att.container_id = nil
|
||||
att.container_type = nil
|
||||
att.copy_from = attachment.id
|
||||
att.save
|
||||
new_homework.attachments << att
|
||||
end
|
||||
#homework_detail_manual = homework.homework_detail_manual
|
||||
#homework_detail_programing = homework.homework_detail_programing
|
||||
#homework_detail_group = homework.homework_detail_group
|
||||
#if homework_detail_manual
|
||||
new_homework.homework_detail_manual = HomeworkDetailManual.new
|
||||
new_homework_detail_manual = new_homework.homework_detail_manual
|
||||
new_homework_detail_manual.ta_proportion = new_homework.homework_type == 2 ? 0.4 : 1.0
|
||||
new_homework_detail_manual.comment_status = 0
|
||||
new_homework_detail_manual.evaluation_num = 3
|
||||
new_homework_detail_manual.absence_penalty = 0
|
||||
#end
|
||||
#if homework_detail_programing
|
||||
if new_homework.homework_type == 2
|
||||
new_homework.homework_detail_programing = HomeworkDetailPrograming.new
|
||||
new_homework.homework_detail_programing.ta_proportion = 0.6
|
||||
new_homework.homework_detail_programing.language = homework.language
|
||||
homework.homework_bank_tests.each_with_index do |homework_test|
|
||||
if homework_test.test_type
|
||||
new_homework.homework_tests << HomeworkTest.new(
|
||||
input: homework_test.input,
|
||||
output: homework_test.output
|
||||
)
|
||||
else
|
||||
new_homework.homework_samples << HomeworkSample.new(
|
||||
input: homework_test.input,
|
||||
output: homework_test.output
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
#end
|
||||
|
||||
#if homework_detail_group
|
||||
if new_homework.homework_type == 3
|
||||
new_homework.homework_detail_group = HomeworkDetailGroup.new
|
||||
new_homework.homework_detail_group.min_num = homework.min_num
|
||||
new_homework.homework_detail_group.max_num = homework.max_num
|
||||
new_homework.homework_detail_group.base_on_project = homework.base_on_project
|
||||
end
|
||||
#end
|
||||
if new_homework.save
|
||||
new_homework_detail_manual.save if new_homework_detail_manual
|
||||
new_homework.homework_detail_programing.save if new_homework.homework_detail_programing
|
||||
new_homework.homework_detail_group.save if new_homework.homework_detail_group
|
||||
end
|
||||
homework.update_column(:quotes, homework.quotes+1)
|
||||
quote_homework_bank homework, course
|
||||
end
|
||||
@homework = homework
|
||||
respond_to do |format|
|
||||
|
|
@ -1083,64 +1079,37 @@ class UsersController < ApplicationController
|
|||
#导入作业
|
||||
def user_import_homeworks
|
||||
@user = User.current
|
||||
@select_course = params[:select_course] ? 1 : 0
|
||||
#@user_homeworks = HomeworkCommon.where(:user_id => @user.id).order("created_at desc")
|
||||
#courses = @user.courses.where("is_delete = 1")
|
||||
#course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")"
|
||||
@homeworks = @user.homework_banks.order("#{@order} #{@b_sort}")
|
||||
@type = params[:type]
|
||||
@limit = 15
|
||||
@select_course = params[:select_course]
|
||||
@homework_type = params[:homework_type].to_i
|
||||
search = params[:search].to_s.strip.downcase
|
||||
if(params[:type].blank? || params[:type] == "1") #我的题库
|
||||
@homeworks = @user.homework_banks.where(:homework_type => @homework_type)
|
||||
elsif params[:type] == "2" #公共题库
|
||||
@homeworks = HomeworkBank.where(:is_public => true, :homework_type => @homework_type)
|
||||
end
|
||||
@type = params[:type] || "1"
|
||||
@homeworks = @homeworks.where("name like '%#{search}%'").reorder("created_at desc")
|
||||
@limit = 10
|
||||
@is_remote = true
|
||||
@hw_count = @homeworks.count
|
||||
@hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1
|
||||
@offset ||= @hw_pages.offset
|
||||
@homeworks = paginateHelper @homeworks,15
|
||||
@homeworks = paginateHelper @homeworks,@limit
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def user_homework_type
|
||||
@order,@b_sort = params[:order] || "created_at",params[:sort] || "desc"
|
||||
@r_sort = @b_sort == "desc" ? "asc" : "desc"
|
||||
@user = User.current
|
||||
if(params[:type].blank? || params[:type] == "1") #我的题库
|
||||
#courses = @user.courses.where("is_delete = 1")
|
||||
#course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")"
|
||||
@homeworks = @user.homework_banks
|
||||
elsif params[:type] == "2" #公共题库
|
||||
#visible_course = Course.where("is_public = 1 && is_delete = 0")
|
||||
#visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")"
|
||||
@homeworks = HomeworkBank.where(:is_public => true)
|
||||
# elsif params[:type] == "3" #申请题库
|
||||
# none_visible_course = Course.where("is_delete = 1")
|
||||
# none_visible_course_ids = none_visible_course.empty? ? "(-1)" : "(" + none_visible_course.map{|course| course.id}.join(",") + ")"
|
||||
# #apply_homeworks = ApplyHomework.where("user_id = ?",@user.id).order('created_at desc')
|
||||
# #homework_ids = apply_homeworks.empty? ? "(-1)" : "(" + apply_homeworks.map{|ah| ah.homework_common_id}.join(",") + ")"
|
||||
# #@homeworks = HomeworkCommon.where("id in #{homework_ids} and course_id not in #{none_visible_course_ids}")
|
||||
#
|
||||
# sql = "SELECT homework_commons.* FROM homework_commons INNER JOIN apply_homeworks as ah ON homework_commons.id = ah.homework_common_id where ah.user_id = #{@user.id} and homework_commons.course_id not in #{none_visible_course_ids} order by ah.created_at desc"
|
||||
# @homeworks = HomeworkCommon.find_by_sql(sql)
|
||||
end
|
||||
if params[:property]
|
||||
@homeworks = @homeworks.where(:homework_type => params[:property].to_i)
|
||||
# all_homework_ids = @homeworks.empty? ? "(-1)" : "(" + @homeworks.map{|h| h.id}.join(",") + ")"
|
||||
# if params[:property] == "1"
|
||||
# @homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 1")
|
||||
# #@homeworks = @homeworks.where("homework_type = 1").reorder("#{@order} #{@b_sort}")
|
||||
# elsif params[:property] == "2"
|
||||
# @homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 2")
|
||||
# #@homeworks = @homeworks.where("homework_type = 2").reorder("#{@order} #{@b_sort}")
|
||||
# elsif params[:property] == "3"
|
||||
# @homeworks = HomeworkCommon.find_by_sql("select * from homework_commons where id in #{all_homework_ids} and homework_type = 3")
|
||||
# #@homeworks = @homeworks.where("homework_type = 3").reorder("#{@order} #{@b_sort}")
|
||||
# end
|
||||
end
|
||||
@homeworks = @homeworks.reorder("#{@order} #{@b_sort}")
|
||||
@homeworks = @homeworks.reorder("created_at desc")
|
||||
@type = params[:type] ? params[:type] : '1'
|
||||
@property = params[:property]
|
||||
@is_import = params[:is_import]
|
||||
@limit = params[:is_import].to_i == 1 ? 15 : 10
|
||||
@limit = 10
|
||||
@is_remote = true
|
||||
@hw_count = @homeworks.count
|
||||
@hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1
|
||||
|
|
@ -1266,58 +1235,12 @@ class UsersController < ApplicationController
|
|||
|
||||
#导入作业,确定按钮
|
||||
def user_select_homework
|
||||
homework = HomeworkBank.find_by_id params[:checkMenu]
|
||||
#homework_detail_programing = homework.homework_detail_programing
|
||||
#homework_detail_group = homework.homework_detail_group
|
||||
@homework = HomeworkCommon.new
|
||||
@select_course = params[:select_course] || 0
|
||||
if homework
|
||||
@ref_homework = homework
|
||||
@homework.name = homework.name
|
||||
@homework.description = homework.description
|
||||
#@homework.end_time = homework.end_time
|
||||
@homework.homework_type = homework.homework_type
|
||||
#@homework.course_id = homework.course_id
|
||||
homework.attachments.each do |attachment|
|
||||
att = attachment.copy
|
||||
att.container_id = nil
|
||||
att.container_type = nil
|
||||
att.copy_from = attachment.id
|
||||
att.save
|
||||
@homework.attachments << att
|
||||
params[:checkMenu].each do |homework_bank|
|
||||
homework = HomeworkBank.find_by_id homework_bank
|
||||
@select_course = Course.find params[:select_course]
|
||||
if homework && @select_course
|
||||
quote_homework_bank homework, @select_course
|
||||
end
|
||||
|
||||
#if homework_detail_programing
|
||||
if homework.homework_type == 2
|
||||
@homework.homework_detail_programing = HomeworkDetailPrograming.new
|
||||
@homework_detail_programing = @homework.homework_detail_programing
|
||||
#@homework_detail_programing.ta_proportion = homework_detail_programing.ta_proportion
|
||||
@homework_detail_programing.language = homework.language
|
||||
homework.homework_bank_tests.each_with_index do |homework_test|
|
||||
if homework_test.test_type
|
||||
@homework.homework_tests << HomeworkTest.new(
|
||||
input: homework_test.input,
|
||||
output: homework_test.output
|
||||
)
|
||||
else
|
||||
@homework.homework_samples << HomeworkSample.new(
|
||||
input: homework_test.input,
|
||||
output: homework_test.output
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
#end
|
||||
|
||||
#if homework_detail_group
|
||||
if homework.homework_type == 3
|
||||
@homework.homework_detail_group = HomeworkDetailGroup.new
|
||||
@homework_detail_group = @homework.homework_detail_group
|
||||
@homework_detail_group.min_num = homework.min_num
|
||||
@homework_detail_group.max_num = homework.max_num
|
||||
@homework_detail_group.base_on_project = homework.base_on_project
|
||||
end
|
||||
#end
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
|
|
@ -1682,6 +1605,7 @@ class UsersController < ApplicationController
|
|||
redirect_to signin_url
|
||||
return
|
||||
end
|
||||
update_onclick_time
|
||||
# 自己访问自己的页面才更新消息状态
|
||||
UserFeedbackMessage.where("user_id =? and viewed =? and journals_for_message_type =? ", User.current.id, 0, "JournalsForMessage").update_all(:viewed => true)
|
||||
# end
|
||||
|
|
@ -1709,7 +1633,7 @@ class UsersController < ApplicationController
|
|||
# end
|
||||
# end
|
||||
@state = false
|
||||
render :layout=>'new_base_user'
|
||||
render :layout => 'edu_new_base_user'
|
||||
end
|
||||
|
||||
#给某人留言
|
||||
|
|
@ -2102,15 +2026,45 @@ class UsersController < ApplicationController
|
|||
@blog_list = @blog_list.limit(3)
|
||||
watch_query = User.watched_by(@user.id);
|
||||
@user_watchlist_count = watch_query.count();
|
||||
@user_watchlist = watch_query.order("#{Watcher.table_name}.id desc").limit(12);
|
||||
@user_watchlist = watch_query.order("#{Watcher.table_name}.id desc").limit(12)
|
||||
fan_query = @user.watcher_users;
|
||||
@user_fanlist_count = fan_query.count();
|
||||
@user_fanlist = fan_query.order("#{Watcher.table_name}.id desc").limit(12);
|
||||
@courses = @user.courses.visible.not_deleted
|
||||
@courses_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").limit(8)
|
||||
@shixuns = []
|
||||
@shixuns_count = 0
|
||||
@user_fanlist = fan_query.order("#{Watcher.table_name}.id desc").limit(12)
|
||||
|
||||
# 我创建的实训数
|
||||
@create_num = (@user == User.current ? Shixun.where(:user_id => @user).count : Shixun.where(:status => [2, 3], :user_id => @user).count)
|
||||
# 我合作的实训数
|
||||
coop_id = Shixun.find_by_sql("select shixun_id from shixun_members where user_id=#{@user.id} and role = 2").map(&:shixun_id) # 合作者的实训id
|
||||
@cooperative_num = (@user == User.current ? Shixun.where(:id => coop_id).count : Shixun.where(:status => [2, 3], :id => coop_id).count)
|
||||
# 我挑战的实训数
|
||||
ch_id = Shixun.find_by_sql("select id from shixuns where id in (select shixun_id from myshixuns where user_id = #{@user.id})")
|
||||
@challenge_num = (@user == User.current ? Shixun.where(:id => ch_id).count : Shixun.where(:status => [2, 3], :id => ch_id))
|
||||
# 我的所有课程数
|
||||
@all_courses_count = @user.courses.not_deleted_not_end.count
|
||||
# 我创建的课程数
|
||||
@create_courses_count = @user.courses.not_deleted_not_end.where(:tea_id => @user.id).count
|
||||
# 我参与的课程数
|
||||
@join_courses_count = @user.courses.not_deleted_not_end.where("tea_id != #{@user.id}").count
|
||||
|
||||
# 合作者及创建者
|
||||
ids = Shixun.find_by_sql("select shixun_id from shixun_members where user_id=#{@user.id}")
|
||||
# 已挑战过
|
||||
ids2 = Shixun.find_by_sql("select id from shixuns where id in (select shixun_id from myshixuns where user_id = #{@user.id})")
|
||||
ids = ids.map{|shixun| shixun.shixun_id} unless ids.blank?
|
||||
ids2 = ids2.map{|shixun| shixun.id} unless ids2.blank?
|
||||
id = ids + ids2
|
||||
id = id.uniq
|
||||
if @user == User.current
|
||||
@shixuns = Shixun.where(:id => id).order("created_at desc")
|
||||
else
|
||||
@shixuns = Shixun.where(:status => [2, 3], :id => id).order("created_at desc")
|
||||
end
|
||||
@limit = 5
|
||||
@is_remote = true
|
||||
@shixuns_count = @shixuns.count
|
||||
@shixuns_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1
|
||||
@offset ||= @shixuns_pages.offset
|
||||
@shixuns = paginateHelper @shixuns, @limit
|
||||
# if User.current == @user
|
||||
# # 点击小铃铛,更新点击时间
|
||||
# update_onclick_time if params[:click_user_message] == 'true'
|
||||
|
|
@ -2255,6 +2209,88 @@ class UsersController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# @params: index表示 "实训" 或 "课程" 那个的筛选
|
||||
# filter 表示筛选的条件[challenge => "我挑战的", create => "我创建的", cooperative => "合作者"]
|
||||
def shixuns_or_courses_filter
|
||||
if params[:index] == "shixun"
|
||||
if params[:filter] == "challenge"
|
||||
# 已挑战过
|
||||
id = Shixun.find_by_sql("select id from shixuns where id in (select shixun_id from myshixuns where user_id = #{@user.id})")
|
||||
if @user == User.current
|
||||
@shixuns = Shixun.where(:id => id).order("created_at desc")
|
||||
else
|
||||
@shixuns = Shixun.where(:status => [2, 3], :id => id).order("created_at desc")
|
||||
end
|
||||
elsif params[:filter] == "create"
|
||||
if @user == User.current
|
||||
@shixuns = Shixun.where(:user_id => @user).order("created_at desc")
|
||||
else
|
||||
@shixuns = Shixun.where(:status => [2, 3], :user_id => @user).order("created_at desc")
|
||||
end
|
||||
elsif params[:filter] == "cooperative"
|
||||
# 合作者的实训id
|
||||
id = Shixun.find_by_sql("select shixun_id from shixun_members where user_id=#{@user.id} and role = 2").map(&:shixun_id)
|
||||
if @user == User.current
|
||||
@shixuns = Shixun.where(:id => id).order("created_at desc")
|
||||
else
|
||||
@shixuns = Shixun.where(:status => [2, 3], :id => id).order("created_at desc")
|
||||
end
|
||||
elsif params[:filter] == "all"
|
||||
# 合作者及创建者
|
||||
ids = Shixun.find_by_sql("select shixun_id from shixun_members where user_id=#{@user.id}")
|
||||
# 已挑战过
|
||||
ids2 = Shixun.find_by_sql("select id from shixuns where id in (select shixun_id from myshixuns where user_id = #{@user.id})")
|
||||
ids = ids.map{|shixun| shixun.shixun_id} unless ids.blank?
|
||||
ids2 = ids2.map{|shixun| shixun.id} unless ids2.blank?
|
||||
id = ids + ids2
|
||||
id = id.uniq
|
||||
if @user == User.current
|
||||
@shixuns = Shixun.where(:id => id).order("created_at desc")
|
||||
else
|
||||
@shixuns = Shixun.where(:status => [2, 3], :id => id).order("created_at desc")
|
||||
end
|
||||
end
|
||||
@limit = 5
|
||||
@is_remote = true
|
||||
@shixuns_count = @shixuns.count
|
||||
@shixuns_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1
|
||||
@offset ||= @shixuns_pages.offset
|
||||
@shixuns = paginateHelper @shixuns, @limit
|
||||
elsif params[:index] == "course"
|
||||
if params[:filter] == "manage"
|
||||
@courses = @user.courses.not_deleted_not_end.where(:tea_id => @user.id).order("updated_at desc")
|
||||
elsif params[:filter] == "join"
|
||||
@courses = @user.courses.not_deleted_not_end.where("tea_id != #{@user.id}").order("updated_at desc")
|
||||
elsif params[:filter] == "all"
|
||||
@courses = @user.courses.not_deleted_not_end.order("updated_at desc")
|
||||
end
|
||||
@limit = 5
|
||||
@is_remote = true
|
||||
@courses_count = @courses.count
|
||||
@courses_pages = Paginator.new @courses_count, @limit, params['page'] || 1
|
||||
@offset ||= @courses_pages.offset
|
||||
@courses = paginateHelper @courses, @limit
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def user_show_course_list
|
||||
@courses = @user.courses.not_deleted_not_end.where(:tea_id => @user.id).order("updated_at desc")
|
||||
@courses_count = @courses.count
|
||||
@limit = 5
|
||||
@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
|
||||
end
|
||||
end
|
||||
|
||||
# 待解决的Issue
|
||||
def unsolved_issues_list
|
||||
@unsolved_issues = Issue.where(:assigned_to_id => @user.id, :status_id => [1, 2, 4, 6]).includes(:author, :project).order("updated_on desc")
|
||||
|
|
@ -2967,16 +3003,15 @@ class UsersController < ApplicationController
|
|||
@user = User.current
|
||||
if !params[:search].nil?
|
||||
search = "%#{params[:search].to_s.strip.downcase}%"
|
||||
@course = @user.courses.not_deleted.where(" #{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p",:p=>search)
|
||||
@course = @user.courses.not_deleted_not_end.where(" #{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p",:p=>search)
|
||||
else
|
||||
@course = @user.courses.not_deleted
|
||||
@course = @user.courses.not_deleted_not_end
|
||||
end
|
||||
@search = params[:search]
|
||||
@type = params[:type]
|
||||
#这里仅仅是传递需要发送的资源id
|
||||
@send_id = params[:send_id]
|
||||
@send_ids = params[:checkbox1] || params[:send_ids]
|
||||
@hidden_unproject = hidden_unproject_infos
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
|
|
@ -3054,60 +3089,61 @@ class UsersController < ApplicationController
|
|||
else
|
||||
@flag = false
|
||||
end
|
||||
@order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
|
||||
@score = @b_sort == "desc" ? "asc" : "desc"
|
||||
user_project_ids = User.current.projects.map {|p| p.id}
|
||||
user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
|
||||
if(params[:type] == "1") # 我的资源
|
||||
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
|
||||
if params[:status] == "2"
|
||||
@attachments = get_course_resources(User.current.id, user_course_ids, @order, @score)
|
||||
elsif params[:status] == "3"
|
||||
@attachments = get_project_resources(User.current.id, user_project_ids, @order, @score)
|
||||
elsif params[:status] == "4"
|
||||
@attachments = get_attch_resources(User.current.id, @order, @score)
|
||||
elsif params[:status] == "5"
|
||||
@attachments = get_principal_resources(User.current.id, @order, @score)
|
||||
else
|
||||
# 公共资源库:所有公开资源或者我上传的私有资源
|
||||
@attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score)
|
||||
end
|
||||
elsif (params[:type].blank? || params[:type] == "6") # 公共资源
|
||||
if params[:status] == "2"
|
||||
@attachments = get_course_resources_public( user_course_ids, @order, @score)
|
||||
elsif params[:status] == "3"
|
||||
@attachments = get_project_resources_public(user_project_ids, @order, @score)
|
||||
elsif params[:status] == "4"
|
||||
@attachments = get_attch_resources_public(@order, @score)
|
||||
elsif params[:status] == "5"
|
||||
@attachments = get_principal_resources_public(@order, @score)
|
||||
else
|
||||
# 公共资源库:所有公开资源或者我上传的私有资源
|
||||
@attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score)
|
||||
end
|
||||
# elsif params[:type] == "2"
|
||||
# apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id}
|
||||
# if params[:status] == "2"
|
||||
# resource_type = "'Course'"
|
||||
# elsif params[:status] == "3"
|
||||
# resource_type = "'Project'"
|
||||
# elsif params[:status] == "5"
|
||||
# resource_type = "'Principal'"
|
||||
# else
|
||||
# resource_type = "'Project','OrgSubfield','Principal','Course'"
|
||||
# end
|
||||
# @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score)
|
||||
end
|
||||
@type = params[:type]
|
||||
@limit = 25
|
||||
@path = user_resource_user_path(User.current, :type => @type)
|
||||
@user = User.current
|
||||
@is_remote = true
|
||||
@atta_count = @attachments.count
|
||||
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
|
||||
@offset ||= @atta_pages.offset
|
||||
#@curse_attachments_all = @all_attachments[@offset, @limit]
|
||||
@attachments = paginateHelper @attachments,25
|
||||
# @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
|
||||
# @score = @b_sort == "desc" ? "asc" : "desc"
|
||||
# user_project_ids = User.current.projects.map {|p| p.id}
|
||||
# user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
|
||||
# if(params[:type] == "1") # 我的资源
|
||||
# # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
|
||||
# if params[:status] == "2"
|
||||
# @attachments = get_course_resources(User.current.id, user_course_ids, @order, @score)
|
||||
# elsif params[:status] == "3"
|
||||
# @attachments = get_project_resources(User.current.id, user_project_ids, @order, @score)
|
||||
# elsif params[:status] == "4"
|
||||
# @attachments = get_attch_resources(User.current.id, @order, @score)
|
||||
# elsif params[:status] == "5"
|
||||
# @attachments = get_principal_resources(User.current.id, @order, @score)
|
||||
# else
|
||||
# # 公共资源库:所有公开资源或者我上传的私有资源
|
||||
# @attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score)
|
||||
# end
|
||||
# elsif (params[:type].blank? || params[:type] == "6") # 公共资源
|
||||
# if params[:status] == "2"
|
||||
# @attachments = get_course_resources_public( user_course_ids, @order, @score)
|
||||
# elsif params[:status] == "3"
|
||||
# @attachments = get_project_resources_public(user_project_ids, @order, @score)
|
||||
# elsif params[:status] == "4"
|
||||
# @attachments = get_attch_resources_public(@order, @score)
|
||||
# elsif params[:status] == "5"
|
||||
# @attachments = get_principal_resources_public(@order, @score)
|
||||
# else
|
||||
# # 公共资源库:所有公开资源或者我上传的私有资源
|
||||
# @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score)
|
||||
# end
|
||||
# # elsif params[:type] == "2"
|
||||
# # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id}
|
||||
# # if params[:status] == "2"
|
||||
# # resource_type = "'Course'"
|
||||
# # elsif params[:status] == "3"
|
||||
# # resource_type = "'Project'"
|
||||
# # elsif params[:status] == "5"
|
||||
# # resource_type = "'Principal'"
|
||||
# # else
|
||||
# # resource_type = "'Project','OrgSubfield','Principal','Course'"
|
||||
# # end
|
||||
# # @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score)
|
||||
# end
|
||||
# @type = params[:type]
|
||||
# @limit = 25
|
||||
# @path = user_resource_user_path(User.current, :type => @type)
|
||||
# @user = User.current
|
||||
# @is_remote = true
|
||||
# @atta_count = @attachments.count
|
||||
# @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
|
||||
# @offset ||= @atta_pages.offset
|
||||
# #@curse_attachments_all = @all_attachments[@offset, @limit]
|
||||
# @attachments = paginateHelper @attachments,25
|
||||
@course = @ori.course
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
|
|
@ -3566,7 +3602,7 @@ class UsersController < ApplicationController
|
|||
def destroy
|
||||
@user.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_back_or_default(admin_users_path) }
|
||||
format.html { redirect_back_or_default(params[:back_url]) }
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
end
|
||||
|
|
@ -4480,7 +4516,7 @@ class UsersController < ApplicationController
|
|||
|
||||
private
|
||||
def show_system_message
|
||||
# 系统消息总显示在最前面,显示周期30天
|
||||
# 系统消息总显示在最前面,显示周期30天
|
||||
@system_messages = SystemMessage.where("created_at > ?", Time.now - 86400 * 30)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ class WelcomeController < ApplicationController
|
|||
#before_filter :find_first_page, :only => [:index]
|
||||
# before_filter :fake, :only => [:index, :course]
|
||||
before_filter :entry_select, :only => [:index]
|
||||
skip_before_filter :check_authentication, :only => [:index]
|
||||
|
||||
def index
|
||||
# @welcome是因为有的页面不需要导航
|
||||
|
|
|
|||
|
|
@ -342,23 +342,23 @@ class WordsController < ApplicationController
|
|||
def leave_homework_message
|
||||
if User.current.logged?
|
||||
@user = User.current
|
||||
@homework_common = HomeworkCommon.find(params[:id]);
|
||||
@homework = HomeworkCommon.find(params[:id]);
|
||||
if params[:homework_message].size>0 && User.current.logged? && @user
|
||||
feedback = HomeworkCommon.add_homework_jour(@user, params[:homework_message], params[:id], @homework_common.id)
|
||||
feedback = HomeworkCommon.add_homework_jour(@user, params[:homework_message], params[:id], @homework.id)
|
||||
if (feedback.errors.empty?)
|
||||
if params[:asset_id]
|
||||
ids = params[:asset_id].split(',')
|
||||
update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE
|
||||
end
|
||||
@homework_common.update_column('updated_at', Time.now)
|
||||
update_course_activity(@homework_common.class,@homework_common.id)
|
||||
update_user_activity(@homework_common.class,@homework_common.id)
|
||||
update_org_activity(@homework_common.class,@homework_common.id)
|
||||
@homework.update_column('updated_at', Time.now)
|
||||
update_course_activity(@homework.class,@homework.id)
|
||||
update_user_activity(@homework.class,@homework.id)
|
||||
update_org_activity(@homework.class,@homework.id)
|
||||
respond_to do |format|
|
||||
format.js{
|
||||
@user_activity_id = params[:user_activity_id].to_i
|
||||
@hw_status = params[:hw_status].to_i if params[:hw_status]
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher, @homework_common.course) || User.current.admin?
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher, @homework.course) || User.current.admin?
|
||||
}
|
||||
end
|
||||
else
|
||||
|
|
@ -375,7 +375,7 @@ class WordsController < ApplicationController
|
|||
if User.current.logged?
|
||||
@user = User.current
|
||||
reply = JournalsForMessage.find params[:id].to_i
|
||||
@homework_common = HomeworkCommon.find reply.jour_id
|
||||
@homework = HomeworkCommon.find reply.jour_id
|
||||
if params[:reply_message].size>0 && User.current.logged? && @user
|
||||
options = {:notes => params[:reply_message], :reply_id => reply.user_id,:user_id => @user.id,:m_parent_id => params[:id].to_i,:m_reply_id => params[:id].to_i, :root_id => reply.root_id}
|
||||
feedback = HomeworkCommon.add_homework_jour(@user, params[:reply_message], reply.jour_id, reply.root_id, options)
|
||||
|
|
@ -384,15 +384,15 @@ class WordsController < ApplicationController
|
|||
ids = params[:asset_id].split(',')
|
||||
update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE
|
||||
end
|
||||
@homework_common.update_column('updated_at', Time.now)
|
||||
update_course_activity(@homework_common.class,@homework_common.id)
|
||||
update_user_activity(@homework_common.class,@homework_common.id)
|
||||
update_org_activity(@homework_common.class,@homework_common.id)
|
||||
@homework.update_column('updated_at', Time.now)
|
||||
update_course_activity(@homework.class,@homework.id)
|
||||
update_user_activity(@homework.class,@homework.id)
|
||||
update_org_activity(@homework.class,@homework.id)
|
||||
respond_to do |format|
|
||||
format.js{
|
||||
@user_activity_id = params[:user_activity_id].to_i
|
||||
@hw_status = params[:hw_status].to_i if params[:hw_status]
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher, @homework_common.course) || User.current.admin?
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher, @homework.course) || User.current.admin?
|
||||
}
|
||||
end
|
||||
else
|
||||
|
|
|
|||
|
|
@ -205,6 +205,45 @@ module ApiHelper
|
|||
|
||||
end
|
||||
|
||||
# 获取当前时间
|
||||
def time_from_future time
|
||||
lastUpdateTime = time.to_i*1000
|
||||
|
||||
currentTime = Time.now.to_i*1000
|
||||
timePassed = lastUpdateTime - currentTime;
|
||||
timeIntoFormat = 0
|
||||
updateAtValue = ""
|
||||
if timePassed < 0
|
||||
updateAtValue = "马上"
|
||||
elsif timePassed < ONE_MINUTE
|
||||
updateAtValue = "1分钟"
|
||||
elsif timePassed < ONE_HOUR
|
||||
timeIntoFormat = timePassed / ONE_MINUTE
|
||||
updateAtValue = timeIntoFormat.to_s + "分钟"
|
||||
elsif (timePassed < ONE_DAY)
|
||||
timeIntoFormat = timePassed / ONE_HOUR
|
||||
updateAtValue = timeIntoFormat.to_s + "小时"
|
||||
elsif (timePassed < ONE_MONTH)
|
||||
timeIntoFormat = timePassed / ONE_DAY
|
||||
updateAtValue = timeIntoFormat.to_s + "天"
|
||||
elsif (timePassed < ONE_YEAR)
|
||||
timeIntoFormat = timePassed / ONE_MONTH
|
||||
updateAtValue = timeIntoFormat.to_s + "个月"
|
||||
else
|
||||
timeIntoFormat = timePassed / ONE_YEAR
|
||||
updateAtValue = timeIntoFormat.to_s + "年"
|
||||
end
|
||||
updateAtValue
|
||||
end
|
||||
|
||||
# 计算到结束还有多长时间 **天**小时**分
|
||||
def how_much_time time
|
||||
result = ""
|
||||
result = ((time - Time.now.to_i).to_i / (24*60*60)).to_s + " 天 "
|
||||
result += (((time - Time.now.to_i).to_i % (24*60*60)) / (60*60)).to_s + " 小时 "
|
||||
result += ((((time - Time.now.to_i).to_i % (24*60*60)) % (60*60)) / 60).to_s + " 分 "
|
||||
end
|
||||
|
||||
#日期转换为时间
|
||||
def convert_to_time date, num
|
||||
if num == 0
|
||||
|
|
|
|||
|
|
@ -33,13 +33,117 @@ module ApplicationHelper
|
|||
extend Forwardable
|
||||
def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter
|
||||
|
||||
def open_webssh
|
||||
# 如果我webssh类型, 开启webssh
|
||||
jenkins_shixuns = Redmine::Configuration['jenkins_shixuns']
|
||||
uri = URI("#{jenkins_shixuns}/jenkins-exec/webssh/getConnectInfo")
|
||||
user_id = User.current.id
|
||||
params = {userID:user_id}
|
||||
res = uri_exec uri, params
|
||||
return [host, port, username, password]
|
||||
end
|
||||
|
||||
# 若实训有更改,则修改已发不实训的标记为已更改
|
||||
# shixun_modifies表中1表示已更改,进入myshixun需要强制重置,0表示没有修改
|
||||
# type 0:表示已经是最新的了;1:表示已经有修改
|
||||
# 功能:1、产生变更记录;2、生成pipeline脚本
|
||||
def add_shixun_modify_status shixun, type
|
||||
jenkins_shixuns = Redmine::Configuration['jenkins_shixuns']
|
||||
gameInfo = shixun.gameInfo
|
||||
uri = URI("#{jenkins_shixuns}/jenkins-exec/game/publishGame")
|
||||
params = {gameInfo:gameInfo}
|
||||
res = uri_exec uri, params
|
||||
if res && res['code'].to_i != 0
|
||||
raise("实训云平台繁忙(繁忙等级:90)")
|
||||
end
|
||||
myshixuns = shixun.myshixuns
|
||||
unless myshixuns.blank?
|
||||
myshixuns.each do |myshixun|
|
||||
shixun_modify = ShixunModify.where(:shixun_id => shixun.id, :myshixun_id => myshixun.id).first
|
||||
if shixun_modify.nil?
|
||||
ShixunModify.create(:shixun_id => shixun.id, :myshixun_id => myshixun.id, :status => type)
|
||||
else
|
||||
shixun_modify.update_attribute(:status, type)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 仅仅产生记录,用于已执行publish的方法
|
||||
def shixun_modify_status_without_publish shixun, type
|
||||
myshixuns = shixun.myshixuns
|
||||
unless myshixuns.blank?
|
||||
myshixuns.each do |myshixun|
|
||||
shixun_modify = ShixunModify.where(:shixun_id => shixun.id, :myshixun_id => myshixun.id).first
|
||||
if shixun_modify.nil?
|
||||
ShixunModify.create(:shixun_id => shixun.id, :myshixun_id => myshixun.id, :status => type)
|
||||
else
|
||||
shixun_modify.update_attribute(:status, type)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 通关后,把最后一次成功的代码存到数据库
|
||||
# type 0 创始内容, 1 最新内容
|
||||
def game_passed_code game_id, path, myshixun_gpid, type
|
||||
g = Gitlab.client
|
||||
rev = rev.nil? ? "master" : rev
|
||||
file_content = g.files(myshixun_gpid, path, rev).content
|
||||
if file_content.blank?
|
||||
# gitlab缺陷:forked完成,短暂时间内取不了内容的,所以做一个小轮询,间隔0.1秒
|
||||
# 超过2秒则失败,需通过页面刷新
|
||||
for i in 0..30 do
|
||||
sleep(0.1)
|
||||
file_content = g.files(myshixun_gpid, path, rev).content
|
||||
unless file_content.blank?
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
file_content = Base64.decode64(file_content) unless file_content.blank?
|
||||
game_code = GameCode.where(:game_id => game_id).first
|
||||
if game_code.nil?
|
||||
if type == 0
|
||||
GameCode.create!(:game_id => game_id, :original_code => file_content, :path => path)
|
||||
else
|
||||
# 这种情况正常是不会出现的,因为没创建成功抛异常,之所以这样写为了防止异常没处理的问题
|
||||
GameCode.create!(:game_id => game_id, :original_code => file_content, :new_code => file_content, :path => path)
|
||||
end
|
||||
else
|
||||
game_code.update_attribute(:new_code, file_content)
|
||||
end
|
||||
end
|
||||
|
||||
# 判断用户是否认证
|
||||
def check_authentication
|
||||
# return true
|
||||
# if params[:action] == "on_search" || params[:action] == "apply_trail" # 之所以这样处理是为了避开account页面ajax加载
|
||||
# return true
|
||||
# end
|
||||
authentication = ApplyAction.where(:user_id => User.current.id, :status => 1).first
|
||||
user_identity = User.current.try(:user_extensions).try(:identity)
|
||||
if user_identity.blank? || authentication.blank?
|
||||
redirect_to my_account_path
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
# 积分表中建立记录行为,有过奖励则不重复奖励
|
||||
def reward_grade(user, container_id, container_type, score)
|
||||
grade = Grade.where(:user_id => user.id, :container_id => container_id, :container_type => container_type).first
|
||||
if grade.nil?
|
||||
user.update_column(:grade, (score.to_i + user.grade.to_i))
|
||||
Grade.create!(:user_id => user.id, :container_id => container_id, :container_type => container_type, :score => score)
|
||||
end
|
||||
user.update_column(:grade, (score.to_i + user.grade.to_i))
|
||||
end
|
||||
|
||||
def reward_experience(user, container_id, container_type, score)
|
||||
experience = Experience.where(:user_id => user.id, :container_id => container_id, :container_type => container_type).first
|
||||
if experience.nil?
|
||||
Experience.create!(:user_id => user.id, :container_id => container_id, :container_type => container_type, :score => score)
|
||||
end
|
||||
user.update_column(:experience, (score.to_i + user.experience.to_i))
|
||||
end
|
||||
|
||||
# codeMirror语言转换
|
||||
|
|
@ -58,16 +162,74 @@ module ApplicationHelper
|
|||
end
|
||||
end
|
||||
|
||||
# 实训语言的种类
|
||||
def shixun_language
|
||||
["Java", "C", "C++", "Python", "MySQL/Java"]
|
||||
end
|
||||
|
||||
# 实训试用专业
|
||||
def shixun_major_option
|
||||
content = []
|
||||
content << ["选择实训适用的专业", 0]
|
||||
content << ["计算机科学与技术", 635]
|
||||
content << ["软件工程", 636]
|
||||
content << ["网络工程", 637]
|
||||
content << ["信息安全", 638]
|
||||
content << ["物联网工程", 639]
|
||||
content << ["信息工程", 622]
|
||||
content << ["通信工程", 619]
|
||||
end
|
||||
|
||||
# 实训面向学员
|
||||
def shixun_trainee
|
||||
content = []
|
||||
content << ["初级学员", 1]
|
||||
content << ["中级学员", 2]
|
||||
content << ["高级学员", 3]
|
||||
content << ["顶级学员", 4]
|
||||
end
|
||||
|
||||
# 班级设置排序中文
|
||||
def switch_to_chinese word
|
||||
case word
|
||||
when "boards"
|
||||
result = "讨论区"
|
||||
when "news"
|
||||
result = "通知"
|
||||
when "homework"
|
||||
result = "作业"
|
||||
when "exercises"
|
||||
result = "试卷"
|
||||
when "poll"
|
||||
result = "问卷"
|
||||
when "statistics"
|
||||
result = "统计"
|
||||
when "attachment"
|
||||
result ="资源"
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
def allow_to_view_challenge challenge, shixun
|
||||
# 判断对应关卡的game是否开启,如果开启则允许查看
|
||||
game_count = Game.where(:challenge_id => challenge, :user_id => User.current, :status => [0,1,2]).count
|
||||
if (User.current.manager_of_shixun?(shixun) || game_count > 0)
|
||||
if game_count > 0
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
# 已通过的关卡数
|
||||
def had_passed_changllenge_count shixun, user
|
||||
myshixun = Myshixun.where(:shixun_id => shixun.id, :user_id => user.id).first
|
||||
if myshixun.nil?
|
||||
0
|
||||
else
|
||||
myshixun.games.select{|game| game.status == 2}.count
|
||||
end
|
||||
end
|
||||
|
||||
# 定义实训相关方法
|
||||
def sum_final_score
|
||||
Game.find_by_sql("SELECT sum(final_score) as total_score FROM `games` where user_id=#{User.current.id}").first.try(:total_score)
|
||||
|
|
@ -210,6 +372,19 @@ module ApplicationHelper
|
|||
gitUrl = gitlab_address.to_s+"/"+login+"/"+ rep_identify + "."+"git"
|
||||
end
|
||||
|
||||
def git_shixun_url_ip shixun, login
|
||||
rep_identify = Repository.where(:shixun_id => shixun.id, :type => "Repository::Gitlab").first.try(:identifier)
|
||||
gitlab_address = Redmine::Configuration['gitlab_address_ip']
|
||||
gitUrl = gitlab_address.to_s+"/"+login+"/"+ rep_identify + "."+"git"
|
||||
end
|
||||
|
||||
def git_myshixun_url_ip myshixun, user_id
|
||||
login = User.where(:id => user_id).first.try(:login)
|
||||
rep_identify = Repository.where(:myshixun_id => myshixun.id, :type => "Repository::Gitlab").first.try(:identifier)
|
||||
gitlab_address = Redmine::Configuration['gitlab_address_ip']
|
||||
gitUrl = gitlab_address.to_s+"/"+login+"/"+ rep_identify + "."+"git"
|
||||
end
|
||||
|
||||
def uri_exec uri, params
|
||||
begin
|
||||
logger.error("@parmas is #{params}, url is #{uri}")
|
||||
|
|
@ -217,7 +392,7 @@ module ApplicationHelper
|
|||
res = JSON.parse(res)
|
||||
rescue => e
|
||||
logger.error("failed to create challenge by 'generatePipelineScriptForChallenge'! #{e}")
|
||||
raise("Jenkins服务器异常")
|
||||
raise("实训云平台繁忙(繁忙等级:84)")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -231,6 +406,119 @@ module ApplicationHelper
|
|||
res = JSON.parse(res)
|
||||
end
|
||||
|
||||
def last_reply_time container_id
|
||||
message = Message.where(:root_id => container_id).order("created_on desc").first
|
||||
time = message.created_on
|
||||
return time
|
||||
end
|
||||
|
||||
# homework_common状态
|
||||
# 0:挂起;1:提交中;2:匿评中;3:评阅中
|
||||
def new_homework_common_status status
|
||||
case status
|
||||
when 0
|
||||
"挂起"
|
||||
when 1
|
||||
"提交中"
|
||||
when 2
|
||||
"补交中"
|
||||
when 3
|
||||
"匿评中"
|
||||
when 4
|
||||
"申诉中"
|
||||
when 5
|
||||
"评阅中"
|
||||
when 6
|
||||
"已结束"
|
||||
end
|
||||
end
|
||||
|
||||
# 作业不同状态的不同样式
|
||||
def homework_status_color status
|
||||
style = ""
|
||||
case status
|
||||
when '挂起'
|
||||
style = 'edu-filter-btn-yellow'
|
||||
when '提交中'
|
||||
style = 'edu-filter-btn-blue'
|
||||
when '补交中'
|
||||
style = 'edu-filter-btn-orange'
|
||||
when '匿评中'
|
||||
style = 'edu-filter-btn-green'
|
||||
when '申诉中'
|
||||
style = 'edu-filter-btn-red'
|
||||
when '评阅中'
|
||||
style = 'edu-filter-btn-green'
|
||||
when '已结束'
|
||||
style = 'edu-filter-btn'
|
||||
when '已开启补交'
|
||||
style = 'edu-filter-btn-late'
|
||||
when '未开启补交'
|
||||
style = 'edu-filter-btn-no-late'
|
||||
end
|
||||
end
|
||||
|
||||
# 判断作业有多少人提交了
|
||||
#
|
||||
def had_commit_studentwork_count homework_common
|
||||
StudentWork.where("work_status !=? and homework_common_id=? and is_delete = 0",0, homework_common.id).count
|
||||
end
|
||||
|
||||
# 未提交作品数统计
|
||||
def had_uncommit_studentwork_count homework_common
|
||||
homework_common.course.student.count - homework_common.student_works.where("work_status !=?", 0).count
|
||||
end
|
||||
|
||||
# 未评阅
|
||||
def had_unevaluate_count homework_common
|
||||
count = StudentWorksScore.find_by_sql("SELECT count(distinct student_work_id) as count FROM student_works_scores sws, student_works sw, homework_commons hc where hc.id =#{homework_common.id} and sw.homework_common_id=hc.id and sw.is_delete = 0 and sws.student_work_id = sw.id and sws.user_id=#{User.current.id};").first.try(:count).to_i
|
||||
student_count = homework_common.course.student.count
|
||||
return student_count - count
|
||||
end
|
||||
|
||||
# 该阶段还有多长时间结束/距下一阶段还有多长时间
|
||||
def homework_curr_time homework_common
|
||||
result = {}
|
||||
status = ""
|
||||
time = ""
|
||||
ho_detail_manual = homework_common.homework_detail_manual
|
||||
if ho_detail_manual
|
||||
case ho_detail_manual.comment_status
|
||||
when 0
|
||||
status = "挂起"
|
||||
when 1
|
||||
if homework_common.end_time && homework_common.end_time >= Time.now
|
||||
status = "提交中"
|
||||
time = how_much_time(homework_common.end_time)
|
||||
end
|
||||
when 3
|
||||
if ho_detail_manual.evaluation_end && ho_detail_manual.evaluation_end > Time.now
|
||||
status = "匿评中"
|
||||
time = how_much_time(ho_detail_manual.evaluation_end)
|
||||
end
|
||||
when 4
|
||||
if ho_detail_manual.appeal_time && ho_detail_manual.appeal_time > Time.now
|
||||
status = "申诉中"
|
||||
time = how_much_time(ho_detail_manual.appeal_time)
|
||||
end
|
||||
when 5
|
||||
if homework_common.archive_time && homework_common.archive_time > Time.now
|
||||
status = "评阅中"
|
||||
time = how_much_time(homework_common.archive_time)
|
||||
end
|
||||
when 6
|
||||
status = "已结束"
|
||||
time = format_time homework_common.archive_time
|
||||
end
|
||||
end
|
||||
if status == "" && homework_common.allow_late && homework_common.archive_time > Time.now
|
||||
time = how_much_time homework_common.archive_time
|
||||
end
|
||||
result[:status] = status
|
||||
result[:time] = time
|
||||
result
|
||||
end
|
||||
|
||||
# 公共分页
|
||||
def paginator_list objs, objs_count, limit, is_remote
|
||||
@is_remote = is_remote
|
||||
|
|
@ -336,6 +624,20 @@ module ApplicationHelper
|
|||
(User.current.logged? && shixun.challenges.count > 0 && !shixun.repository.blank?)
|
||||
end
|
||||
|
||||
# 判断当前用户是否可以开始实战
|
||||
def link_to_shixun_exec myshixun, shixun, str
|
||||
is_modify = ShixunModify.where(:myshixun_id => myshixun.try(:id), :shixun_id => shixun.try(:id), :status => 1).first.blank?
|
||||
if User.current.mail.blank?
|
||||
link_to str, "javascript:void(0);", :onclick => "notice_box_redirect('#{security_settings_path}', '开启实训,请先绑定邮箱')", :class => "fr shixun-task-btn task-btn-orange mr15", :target => "_blank"
|
||||
else
|
||||
if is_modify || myshixun.blank?
|
||||
link_to str, shixun_exec_shixun_path(shixun), :class => "fr shixun-task-btn task-btn-orange mr15", :target => "_blank"
|
||||
else
|
||||
link_to str, "javascript:void(0);", :onclick => "sure_box_redirect('#{myshixun_reset_myshixun_path(myshixun)}', '实训已经更新啦,系统正在为您重置')", :class => "fr shixun-task-btn task-btn-orange mr15"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 通过系统外部邮箱查找用户,如果用户不存在则用邮箱替换
|
||||
def get_user_by_mail mail
|
||||
user = User.find_by_mail(mail)
|
||||
|
|
@ -1612,22 +1914,38 @@ module ApplicationHelper
|
|||
if args.empty?
|
||||
title = @html_title || []
|
||||
if @project
|
||||
title << (@project.name.nil? ? "让创新更美好" : @project.name)
|
||||
title << (@project.name.nil? ? "创新源于实践" : @project.name)
|
||||
elsif @welcome
|
||||
title << "高校教育大数据服务平台"
|
||||
title << "创新源于实践"
|
||||
elsif @course
|
||||
title << (@course.name.nil? ? "智能课堂" : @course.name)
|
||||
title << (@course.name.nil? ? "实训课堂" : @course.name)
|
||||
elsif params[:controller] == "homework_bank"
|
||||
title << ("题库")
|
||||
elsif params[:controller] == "courses" && params[:action] == "index"
|
||||
title << ("实训课堂")
|
||||
elsif @contest
|
||||
title << (@contest.name.nil? ? "让创新更美好" : @contest.name)
|
||||
title << (@contest.name.nil? ? "创新源于实践" : @contest.name)
|
||||
elsif @shixun
|
||||
title << (@shixun.name.nil? ? "实训分类" : @shixun.name)
|
||||
elsif @my_shixun
|
||||
title << ("我的实训")
|
||||
elsif params[:controller] == "shixuns" && params[:action] == "index"
|
||||
title << ("实训分类")
|
||||
elsif @subject
|
||||
title << (@subject.name.nil? ? "课程实训" : @subject.name)
|
||||
elsif params[:controller] == "subjects" && params[:action] == "index"
|
||||
title << ("课程实训")
|
||||
elsif @organization
|
||||
title << (@organization.name.nil? ? "让创新更美好" : @organization.name)
|
||||
title << (@organization.name.nil? ? "创新源于实践" : @organization.name)
|
||||
elsif @forum || params[:controller] == "forums"
|
||||
title << "问吧"
|
||||
elsif @my_syllabuses
|
||||
title << "我的课堂"
|
||||
elsif @user
|
||||
if !@project_community.blank? || !@user_projectlist.blank?
|
||||
title << "项目"
|
||||
elsif !@course_community.blank? || !@user_courselist.blank?
|
||||
title << "智能课堂"
|
||||
title << "实训课堂"
|
||||
elsif !@contest_community.blank?
|
||||
title << @contest_community
|
||||
elsif !@manage_issues.blank?
|
||||
|
|
@ -1639,10 +1957,10 @@ module ApplicationHelper
|
|||
elsif !@receive_homeworks.blank?
|
||||
title << @receive_homeworks
|
||||
else
|
||||
title << @user.try(:realname)
|
||||
title << @user.show_name
|
||||
end
|
||||
elsif @syllabus
|
||||
title << (@syllabus.title.nil? ? "智能课堂" : @syllabus.title)
|
||||
title << (@syllabus.title.nil? ? "实训课堂" : @syllabus.title)
|
||||
else
|
||||
title << (User.current.id == 2 ? "未登录" : User.current.try(:realname))
|
||||
end
|
||||
|
|
@ -2285,6 +2603,19 @@ module ApplicationHelper
|
|||
link_to l(:button_delete), url, options
|
||||
end
|
||||
|
||||
def update_status_link(user)
|
||||
url = {:controller => 'users', :action => 'update', :id => user, :page => params[:page], :status => params[:status], :tab => nil}
|
||||
|
||||
if user.locked?
|
||||
link_to "解锁", url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :put, :class => 'mr10 link-color-blue'
|
||||
elsif user.registered?
|
||||
link_to "激活", url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :put, :class => 'mr10 link-color-blue'
|
||||
elsif user != User.current
|
||||
link_to "加锁", url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :put, :class => 'mr10 link-color-blue'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def delete_version_link(url, options={})
|
||||
options = {
|
||||
:method => :delete,
|
||||
|
|
@ -2566,7 +2897,7 @@ module ApplicationHelper
|
|||
|
||||
# Returns the javascript tags that are included in the html layout head
|
||||
def javascript_heads
|
||||
tags = javascript_include_tag('jquery-1.8.3-ui-1.9.2-ujs-2.0.3', 'application', 'jquery.colorbox-min')
|
||||
tags = javascript_include_tag('jquery-1.8.3-ui-1.9.2-ujs-2.0.3', 'application', 'jquery.colorbox-min', 'baiduTemplate')
|
||||
unless User.current.pref.warn_on_leaving_unsaved == '0'
|
||||
tags << "\n".html_safe + javascript_tag("$(window).load(function(){ warnLeavingUnsaved('#{escape_javascript l(:text_warn_on_leaving_unsaved)}'); });")
|
||||
end
|
||||
|
|
@ -2638,7 +2969,34 @@ module ApplicationHelper
|
|||
if File.exist?(disk_auth_filename("UserAuthentication",user_id,type))
|
||||
File.join(relative_path,avatar_directory("UserAuthentication"), auth_filename(user_id,type))
|
||||
else
|
||||
File.join(relative_path,avatar_directory("UserAuthentication"),'0')
|
||||
File.join(relative_path,avatar_directory("UserAuthentication"),type)
|
||||
end
|
||||
end
|
||||
|
||||
def identity_authentication_status user_id
|
||||
apply = ApplyAction.where(:user_id => user_id).first
|
||||
case apply.try(:status)
|
||||
when nil
|
||||
"未授权"
|
||||
when 0
|
||||
"处理中"
|
||||
when 1
|
||||
"已授权"
|
||||
when 2
|
||||
"被拒绝"
|
||||
end
|
||||
end
|
||||
|
||||
def shixun_authentication_status shixun
|
||||
case shixun.try(:status)
|
||||
when 0,nil
|
||||
"编辑中"
|
||||
when 1
|
||||
"待审核"
|
||||
when 2
|
||||
"已发布"
|
||||
when 3
|
||||
"已关闭"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -2729,13 +3087,30 @@ module ApplicationHelper
|
|||
|
||||
def resource_bank_candown resource,type
|
||||
candown = false
|
||||
if resource.is_public
|
||||
candown = true
|
||||
end
|
||||
if type == 'syllabus'
|
||||
syllabus = resource.course.syllabus
|
||||
candown = User.current.member_of_syl?(syllabus) || User.current.admin?
|
||||
candown = syllabus_course_member(User.current, resource.course) || User.current.admin?
|
||||
end
|
||||
candown
|
||||
end
|
||||
|
||||
# 课程某个班级的成员
|
||||
def syllabus_course_member user, course
|
||||
result = false
|
||||
syllabus = course.syllabus
|
||||
if syllabus
|
||||
syllabus.courses.each do |course|
|
||||
if user.member_of_course?(course)
|
||||
result = true
|
||||
return result
|
||||
end
|
||||
end
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
def attachment_candown attachment
|
||||
candown = false
|
||||
if attachment.container
|
||||
|
|
@ -2797,6 +3172,10 @@ module ApplicationHelper
|
|||
else
|
||||
candown = (attachment.is_public == 1 || attachment.is_public == true)
|
||||
end
|
||||
else
|
||||
if attachment.container_type == "Shixun"
|
||||
candown = true
|
||||
end
|
||||
end
|
||||
candown
|
||||
end
|
||||
|
|
@ -3378,50 +3757,57 @@ module ApplicationHelper
|
|||
if User.current.logged?
|
||||
if User.current.member_of_course?(homework.course)
|
||||
if is_teacher #老师显示作品数量
|
||||
link_to "作品(#{count})", student_work_index_url_in_org(homework.id, 2), :class => "c_blue"
|
||||
link_to "作品(#{count})", student_work_index_url_in_org(homework.id, 2), :class => "c_blue homepagePostSubmit"
|
||||
else #学生显示提交作品、修改作品等按钮
|
||||
work = cur_user_works_for_homework homework
|
||||
project = cur_user_projects_for_homework homework
|
||||
if work.nil? && homework.end_time >= Time.now
|
||||
if homework.homework_type ==3 && project.nil? && homework.homework_detail_group.base_on_project == 1
|
||||
link_to "提交作品(#{count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再提交作品'
|
||||
if homework.homework_type == 4
|
||||
if work.nil?
|
||||
link_to "开始实战(#{count})", shixun_path(homework.homework_commons_shixuns.shixun),:class => 'c_blue homepagePostSubmit',:target => "_blank"
|
||||
else
|
||||
link_to "提交作品(#{count})", new_student_work_url_without_domain(homework.id),:class => 'c_blue'
|
||||
myshixun = Myshixun.find work.myshixun_id
|
||||
link_to "继续实战(#{count})", myshixun_game_path(myshixun.current_task, :myshixun_id => myshixun), :class => "c_blue homepagePostSubmit",:target => "_blank" if myshixun
|
||||
end
|
||||
elsif work.nil? && homework.end_time >= Time.now
|
||||
if homework.homework_type ==3 && project.nil? && homework.homework_detail_group.base_on_project == 1
|
||||
link_to "提交作品(#{count})","javascript:void(0)", :class => 'c_grey homepagePostSubmit',:style=>"cursor:not-allowed",:title => '请先关联项目再提交作品'
|
||||
else
|
||||
link_to "提交作品(#{count})", new_student_work_url_without_domain(homework.id),:class => 'c_blue homepagePostSubmit'
|
||||
end
|
||||
elsif work.nil? && homework.end_time < Time.now
|
||||
if homework.homework_type ==3 && project.nil? && homework.homework_detail_group.base_on_project == 1
|
||||
link_to "补交作品(#{count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再补交作品'
|
||||
else
|
||||
link_to "补交作品(#{count})", new_student_work_url_without_domain(homework.id),:class => 'c_red'
|
||||
if homework.allow_late && homework.homework_detail_manual.comment_status < 6
|
||||
if homework.homework_type ==3 && project.nil? && homework.homework_detail_group.base_on_project == 1
|
||||
link_to "补交作品(#{count})","javascript:void(0)", :class => 'c_grey homepagePostSubmit',:style=>"cursor:not-allowed",:title => '请先关联项目再补交作品'
|
||||
else
|
||||
link_to "补交作品(#{count})", new_student_work_url_without_domain(homework.id),:class => 'c_red homepagePostSubmit'
|
||||
end
|
||||
end
|
||||
else
|
||||
if homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 2 && StudentWorksEvaluationDistribution.where("student_work_id = #{work.id}").count > 0 #匿评作业,且作业状态不是在开启匿评之前
|
||||
elsif work
|
||||
if homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 3 && StudentWorksEvaluationDistribution.where("student_work_id = #{work.id}").count > 0 #匿评作业,且作业状态不是在开启匿评之前
|
||||
if homework.homework_type != 3
|
||||
link_to "作品匿评", student_work_index_url_in_org(homework.id, 2), :class => 'c_blue', :title => "开启匿评后不可修改作品"
|
||||
link_to "作品匿评", student_work_index_url_in_org(homework.id, 2), :class => 'c_blue homepagePostSubmit', :title => "开启匿评后不可修改作品"
|
||||
else
|
||||
work_ids = "(" + homework.student_works.has_committed.map(&:id).join(",") + ")"
|
||||
if User.current.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count > 0
|
||||
link_to "作品匿评", student_work_index_url_in_org(homework.id, 2), :class => 'c_blue', :title => "开启匿评后不可修改作品"
|
||||
link_to "作品匿评", student_work_index_url_in_org(homework.id, 2), :class => 'c_blue homepagePostSubmit', :title => "开启匿评后不可修改作品"
|
||||
else
|
||||
link_to "查看作品(#{count})",student_work_index_url_in_org(homework.id, 2), :class => 'c_blue', :title => "匿评开启后提交的作品不参与匿评"
|
||||
link_to "查看作品(#{count})",student_work_index_url_in_org(homework.id, 2), :class => 'c_blue homepagePostSubmit', :title => "匿评开启后提交的作品不参与匿评"
|
||||
end
|
||||
end
|
||||
elsif homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 3
|
||||
link_to "查看作品(#{count})",student_work_index_url_in_org(homework.id, 2), :class => 'c_blue', :title => "匿评已结束"
|
||||
elsif homework.homework_type == 2 && homework.end_time >= Time.now#编程作业不能修改作品
|
||||
link_to "修改作品(#{count})", new_student_work_url_without_domain(homework.id),:class => 'c_blue'
|
||||
elsif homework.homework_detail_manual && homework.homework_detail_manual.comment_status > 3
|
||||
link_to "查看作品(#{count})",student_work_index_url_in_org(homework.id, 2), :class => 'c_blue homepagePostSubmit', :title => "匿评已结束"
|
||||
elsif homework.end_time >= Time.now && work.user_id == User.current.id
|
||||
link_to "修改作品(#{count})", edit_student_work_url_without_domain(work.id),:class => 'c_blue'
|
||||
link_to "修改作品(#{count})", edit_student_work_url_without_domain(work.id),:class => 'c_blue homepagePostSubmit'
|
||||
else
|
||||
link_to "查看作品(#{count})", student_work_index_url_in_org(homework.id, 2), :class => 'c_blue', :title => "作业截止后不可修改作品"
|
||||
link_to "查看作品(#{count})", student_work_index_url_in_org(homework.id, 2), :class => 'c_blue homepagePostSubmit', :title => "作业截止后不可修改作品"
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
link_to "作品(#{count})", "javascript:void(0)", :class => "c_blue", :onclick => "notice_sure_box('您不是班级成员,不能提交作品<br/>请先从老师处获取邀请码后加入班级,再提交作品')"
|
||||
link_to "作品(#{count})", "javascript:void(0)", :class => "c_blue homepagePostSubmit", :onclick => "notice_sure_box('您不是班级成员,不能提交作品<br/>请先从老师处获取邀请码后加入班级,再提交作品')"
|
||||
end
|
||||
else
|
||||
link_to "作品(#{count})", "javascript:void(0)", :class => "c_blue", :onclick => "login_notice_box('#{signin_url_without_domain}');"
|
||||
link_to "作品(#{count})", "javascript:void(0)", :class => "c_blue homepagePostSubmit", :onclick => "login_notice_box('#{signin_url_without_domain}');"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -4237,11 +4623,20 @@ def get_work_index(hw,is_teacher)
|
|||
return index
|
||||
end
|
||||
|
||||
def get_hw_index(hw,is_teacher)
|
||||
def get_hw_index(hw,is_teacher,type=0)
|
||||
homework_commons = hw.course.homework_commons
|
||||
if is_teacher
|
||||
homeworks = hw.course.homework_commons.order("created_at asc")
|
||||
if type != 0
|
||||
homeworks = homework_commons.where("homework_commons.homework_type = #{type}").order("created_at asc")
|
||||
else
|
||||
homeworks = homework_commons.order("created_at asc")
|
||||
end
|
||||
else
|
||||
homeworks = hw.course.homework_commons.where("publish_time <= '#{Time.now}'").order("created_at asc")
|
||||
if type != 0
|
||||
homeworks = homework_commons.where("homework_commons.homework_type = #{type} and publish_time <= '#{Time.now}'").order("created_at asc")
|
||||
else
|
||||
homeworks = homework_commons.where("publish_time <= '#{Time.now}'").order("created_at asc")
|
||||
end
|
||||
end
|
||||
hw_ids = homeworks.map{|hw| hw.id} if !homeworks.empty?
|
||||
index = hw_ids.index(hw.id)
|
||||
|
|
@ -4344,9 +4739,13 @@ def get_contest_group_member_names work
|
|||
result
|
||||
end
|
||||
|
||||
def course_syllabus_option user = User.current
|
||||
syllabus_members = SyllabusMember.where("user_id = #{user.id}")
|
||||
syllabus_ids = syllabus_members.empty? ? "(-1)" : "(" + syllabus_members.map{|mem| mem.syllabus_id}.join(',') + ")"
|
||||
def course_syllabus_option syllabus_id = nil
|
||||
syllabus_members = SyllabusMember.where("user_id = #{User.current.id}")
|
||||
syllabus_ids = syllabus_members.map{|mem| mem.syllabus_id}
|
||||
if syllabus_id && !syllabus_ids.include?(syllabus_id)
|
||||
syllabus_ids << syllabus_id
|
||||
end
|
||||
syllabus_ids = syllabus_ids.empty? ? "(-1)" : "(" + syllabus_ids.join(',') + ")"
|
||||
syllabuses = Syllabus.where("id in #{syllabus_ids}")
|
||||
type = []
|
||||
option1 = []
|
||||
|
|
@ -4384,20 +4783,19 @@ def create_works_list homework
|
|||
end
|
||||
|
||||
def add_to_homework_bank_f homework
|
||||
homework_bank = HomeworkBank.new(:name => homework.name, :description => homework.description, :user_id => homework.user_id, :homework_type => homework.homework_type,
|
||||
:quotes => 1, :is_public => homework.course.is_public, :applicable_syllabus => homework.course.syllabus.title, :homework_common_id => homework.id)
|
||||
homework_bank = HomeworkBank.new(:name => homework.name, :description => homework.description, :user_id => User.current.id, :homework_type => homework.homework_type,
|
||||
:quotes => 1, :is_public => homework.course.is_public, :applicable_syllabus => homework.course.syllabus.title, :homework_common_id => homework.id,
|
||||
:reference_answer => homework.reference_answer, :syllabus_id => homework.course.syllabus_id)
|
||||
if homework.homework_type == 2 && homework.homework_detail_programing
|
||||
homework_bank.language = homework.homework_detail_programing.language
|
||||
homework.homework_tests.each_with_index do |homework_test|
|
||||
homework_bank.homework_bank_tests << HomeworkBankTest.new(
|
||||
test_type: 1,
|
||||
input: homework_test.input,
|
||||
output: homework_test.output
|
||||
)
|
||||
end
|
||||
homework.homework_samples.each_with_index do |homework_test|
|
||||
homework_bank.homework_bank_tests << HomeworkBankTest.new(
|
||||
test_type: 0,
|
||||
homework_bank.homework_bank_samples << HomeworkBankSample.new(
|
||||
input: homework_test.input,
|
||||
output: homework_test.output
|
||||
)
|
||||
|
|
@ -4485,7 +4883,7 @@ def searchstudent_by_name users, name
|
|||
name = name.to_s.downcase
|
||||
users.each do |m|
|
||||
username = m.lastname.to_s.downcase + m.firstname.to_s.downcase
|
||||
if(m.login.to_s.downcase.include?(name) || m.user_extensions[:student_id].to_s.downcase.include?(name) || username.include?(name))
|
||||
if(m.login.to_s.downcase.include?(name) || m.user_extensions[:student_id].to_s.downcase.include?(name) || username.include?(name))
|
||||
mems << m
|
||||
end
|
||||
end
|
||||
|
|
@ -4541,3 +4939,243 @@ def add_reply_adapter obj, options
|
|||
# end
|
||||
end
|
||||
|
||||
def sy_resources syllabus
|
||||
courses = syllabus.courses.not_deleted
|
||||
attachments = Attachment.where(:container_type => 'Course', :container_id => courses.map(&:id))
|
||||
resources = ResourceBank.where(:id => attachments.map(&:resource_bank_id))
|
||||
resources
|
||||
end
|
||||
|
||||
def sy_homeworks syllabus
|
||||
courses = syllabus.courses.not_deleted
|
||||
homeworks = HomeworkCommon.where(:course_id => courses.map(&:id))
|
||||
homeworks = HomeworkBank.where(:id => homeworks.map(&:homework_bank_id))
|
||||
homeworks
|
||||
end
|
||||
|
||||
# 可以查看到资源库的资源
|
||||
def visable_attachemnts_incourse course
|
||||
return[] unless course
|
||||
result = []
|
||||
course.attachments.each do |attachment|
|
||||
if attachment.is_public? && attachment.is_publish == 1 || User.current == attachment.author || User.current.allowed_to?(:as_teacher,course) || (User.current.member_of_course?(course) && attachment.is_publish == 1) || User.current.admin?
|
||||
result << attachment
|
||||
end
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
def visable_course_homework course, type=0
|
||||
if User.current.admin? || User.current.allowed_to?(:as_teacher,course)
|
||||
if type != 0
|
||||
homework_num = course.homework_commons.where(:homework_type => type).count
|
||||
else
|
||||
homework_num = course.homework_commons.count
|
||||
end
|
||||
else
|
||||
if type != 0
|
||||
homework_num = course.homework_commons.where(:homework_type => type).where("publish_time <= '#{Time.now}'").count
|
||||
else
|
||||
homework_num = course.homework_commons.where("publish_time <= '#{Time.now}'").count
|
||||
end
|
||||
end
|
||||
homework_num
|
||||
end
|
||||
|
||||
#成绩计算
|
||||
def set_final_score homework,student_work
|
||||
if homework && homework.homework_detail_manual
|
||||
if homework.homework_type != 2 #非编程作业
|
||||
if homework.teacher_priority == 1 #教师优先
|
||||
if student_work.teacher_score
|
||||
student_work.final_score = student_work.teacher_score
|
||||
student_work.work_score = student_work.teacher_score - student_work.absence_penalty - student_work.late_penalty
|
||||
else
|
||||
if student_work.teaching_asistant_score.nil?
|
||||
student_work.final_score = student_work.student_score
|
||||
elsif student_work.student_score.nil?
|
||||
student_work.final_score = student_work.teaching_asistant_score
|
||||
else
|
||||
ta_proportion = homework.homework_detail_manual.ta_proportion
|
||||
final_ta_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * BigDecimal.new("#{ta_proportion}")
|
||||
final_s_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
||||
final_score = final_ta_score + final_s_score
|
||||
student_work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
if student_work.final_score
|
||||
score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty - student_work.appeal_penalty
|
||||
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
|
||||
else
|
||||
student_work.work_score = nil
|
||||
end
|
||||
end
|
||||
else #不考虑教师评分
|
||||
if student_work.teaching_asistant_score.nil?
|
||||
student_work.final_score = student_work.student_score
|
||||
elsif student_work.student_score.nil?
|
||||
student_work.final_score = student_work.teaching_asistant_score
|
||||
else
|
||||
ta_proportion = homework.homework_detail_manual.ta_proportion
|
||||
final_ta_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * BigDecimal.new("#{ta_proportion}")
|
||||
final_s_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
||||
final_score = final_ta_score + final_s_score
|
||||
student_work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
if student_work.final_score
|
||||
score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty - student_work.appeal_penalty
|
||||
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
|
||||
else
|
||||
student_work.work_score = nil
|
||||
end
|
||||
end
|
||||
elsif homework.homework_type == 2 && homework.homework_detail_programing #编程作业-----设定:系统评分必定不为空
|
||||
if homework.teacher_priority == 1 #教师优先
|
||||
if student_work.teacher_score
|
||||
student_work.final_score = student_work.teacher_score
|
||||
student_work.work_score = student_work.teacher_score - student_work.absence_penalty - student_work.late_penalty - student_work.appeal_penalty
|
||||
else
|
||||
if student_work.teaching_asistant_score.nil? #教辅未评分
|
||||
if student_work.student_score.nil?
|
||||
student_work.final_score = student_work.system_score
|
||||
else
|
||||
ta_proportion = homework.homework_detail_programing.ta_proportion + homework.homework_detail_manual.ta_proportion / 2
|
||||
final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{ta_proportion}")
|
||||
final_st_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
||||
final_score = final_sy_score + final_st_score
|
||||
student_work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
elsif student_work.student_score.nil? #学生未评分
|
||||
if student_work.teaching_asistant_score.nil?
|
||||
student_work.final_score = student_work.system_score
|
||||
else
|
||||
ta_proportion = homework.homework_detail_programing.ta_proportion + (1.0 - homework.homework_detail_manual.ta_proportion - homework.homework_detail_programing.ta_proportion) / 2
|
||||
final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{ta_proportion}")
|
||||
final_ts_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
||||
final_score = final_sy_score + final_ts_score
|
||||
student_work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
else
|
||||
final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{homework.homework_detail_programing.ta_proportion}")
|
||||
final_ts_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * BigDecimal.new("#{homework.homework_detail_manual.ta_proportion}")
|
||||
final_st_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{homework.homework_detail_programing.ta_proportion}") - BigDecimal.new("#{homework.homework_detail_manual.ta_proportion}"))
|
||||
final_score = final_sy_score + final_ts_score + final_st_score
|
||||
student_work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
if student_work.final_score
|
||||
score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty - student_work.appeal_penalty
|
||||
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
|
||||
else
|
||||
student_work.work_score = nil
|
||||
end
|
||||
end
|
||||
else #不考虑教师评分
|
||||
if student_work.teaching_asistant_score.nil? #教辅未评分
|
||||
if student_work.student_score.nil?
|
||||
student_work.final_score = student_work.system_score
|
||||
else
|
||||
ta_proportion = homework.homework_detail_programing.ta_proportion + homework.homework_detail_manual.ta_proportion / 2
|
||||
final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{ta_proportion}")
|
||||
final_st_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
||||
final_score = final_sy_score + final_st_score
|
||||
student_work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
elsif student_work.student_score.nil? #学生未评分
|
||||
if student_work.teaching_asistant_score.nil?
|
||||
student_work.final_score = student_work.system_score
|
||||
else
|
||||
ta_proportion = homework.homework_detail_programing.ta_proportion + (1.0 - homework.homework_detail_manual.ta_proportion - homework.homework_detail_programing.ta_proportion) / 2
|
||||
final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{ta_proportion}")
|
||||
final_ts_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
||||
final_score = final_sy_score + final_ts_score
|
||||
student_work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
else
|
||||
final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{homework.homework_detail_programing.ta_proportion}")
|
||||
final_ts_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * BigDecimal.new("#{homework.homework_detail_manual.ta_proportion}")
|
||||
final_st_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{homework.homework_detail_programing.ta_proportion}") - BigDecimal.new("#{homework.homework_detail_manual.ta_proportion}"))
|
||||
final_score = final_sy_score + final_ts_score + final_st_score
|
||||
student_work.final_score = format("%.2f",final_score.to_f)
|
||||
end
|
||||
if student_work.final_score
|
||||
score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty - student_work.appeal_penalty
|
||||
student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
|
||||
else
|
||||
student_work.work_score = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def quote_resource_bank resource, course
|
||||
atta = Attachment.new(:filename => resource.filename, :disk_filename => resource.disk_filename, :filesize => resource.filesize, :digest => resource.digest, :downloads => 0, :is_publish => 0,
|
||||
:author_id => User.current.id, :description => resource.description, :disk_directory => resource.disk_directory, :is_public => 0, :copy_from => resource.copy_from.nil? ? resource.id : resource.copy_from,
|
||||
:quotes => 0, :resource_bank_id => resource.id, :created_on => Time.now, :content_type =>resource.content_type)
|
||||
if course.attachments << atta
|
||||
# 更新引用次数
|
||||
quotes = resource.quotes.to_i + 1
|
||||
resource.update_attribute(:quotes, quotes)
|
||||
end
|
||||
end
|
||||
|
||||
def quote_homework_bank homework, course
|
||||
new_homework = HomeworkCommon.new(:name => homework.name, :user_id => User.current.id, :description => homework.description, :homework_type => homework.homework_type, :late_penalty => 0,
|
||||
:course_id => course.id, :teacher_priority => 1, :anonymous_comment => 1, :quotes => 0, :is_open => 0, :homework_bank_id => homework.id, :score_open => 1,
|
||||
:anonymous_appeal => 0, :is_public => 0, :reference_answer => homework.reference_answer, :answer_public => 1, :allow_late => 1)
|
||||
|
||||
new_homework.homework_detail_manual = HomeworkDetailManual.new
|
||||
new_homework_detail_manual = new_homework.homework_detail_manual
|
||||
new_homework_detail_manual.te_proportion = 1.0
|
||||
new_homework_detail_manual.ta_proportion = 0
|
||||
new_homework_detail_manual.comment_status = 0
|
||||
|
||||
new_homework_detail_manual.evaluation_num = 0
|
||||
new_homework_detail_manual.absence_penalty = 0
|
||||
|
||||
if new_homework.homework_type == 2
|
||||
new_homework.homework_detail_programing = HomeworkDetailPrograming.new
|
||||
new_homework.homework_detail_programing.ta_proportion = 0
|
||||
new_homework.homework_detail_programing.language = homework.language
|
||||
homework.homework_bank_tests.each_with_index do |homework_test|
|
||||
new_homework.homework_tests << HomeworkTest.new(
|
||||
input: homework_test.input,
|
||||
output: homework_test.output
|
||||
)
|
||||
end
|
||||
homework.homework_bank_samples.each_with_index do |homework_test|
|
||||
new_homework.homework_samples << HomeworkSample.new(
|
||||
input: homework_test.input,
|
||||
output: homework_test.output
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
if new_homework.homework_type == 3
|
||||
new_homework.homework_detail_group = HomeworkDetailGroup.new
|
||||
new_homework.homework_detail_group.min_num = homework.min_num
|
||||
new_homework.homework_detail_group.max_num = homework.max_num
|
||||
new_homework.homework_detail_group.base_on_project = homework.base_on_project
|
||||
end
|
||||
|
||||
homework.attachments.each do |attachment|
|
||||
att = attachment.copy
|
||||
att.container_id = nil
|
||||
att.container_type = nil
|
||||
att.author_id = homework.user_id
|
||||
att.copy_from = attachment.id
|
||||
att.save
|
||||
new_homework.attachments << att
|
||||
end
|
||||
|
||||
if new_homework.save
|
||||
if new_homework.homework_type == 4
|
||||
HomeworkCommonsShixuns.create(:homework_common_id => new_homework.id, :shixun_id => homework.homework_bank_shixun.shixun_id)
|
||||
end
|
||||
new_homework_detail_manual.save if new_homework_detail_manual
|
||||
new_homework.homework_detail_programing.save if new_homework.homework_detail_programing
|
||||
new_homework.homework_detail_group.save if new_homework.homework_detail_group
|
||||
homework.update_column(:quotes, homework.quotes+1)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -11,4 +11,18 @@ module ChallengesHelper
|
|||
"复杂"
|
||||
end
|
||||
end
|
||||
|
||||
def find_game_status challenge_id
|
||||
game = Game.where(:challenge_id => challenge_id, :user_id => User.current.id).first
|
||||
case game.try(:status)
|
||||
when 0
|
||||
"<a title='待完成'><i class='fa fa-unlock-alt fr font-18 mt5 -text-danger w20_center'></i></a>".html_safe
|
||||
when 1
|
||||
"评测中"
|
||||
when 2
|
||||
"<a title='已解决'><i class='fa fa-unlock fr font-18 mt5 color-light-green w20_center' ></i></a>".html_safe
|
||||
when 3,nil
|
||||
"<a title='未解锁'><i class='fa fa-lock fr font-18 mt5 color-grey w20_center' ></i></a>".html_safe
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -78,7 +78,9 @@ module CoursesHelper
|
|||
|
||||
#生成课程老师成员链接
|
||||
def course_teacher_link teacher_num
|
||||
if User.current.member_of_course?(@course) || User.current.admin?
|
||||
if User.current.allowed_to?(:as_teacher, @course)
|
||||
link_to "#{teacher_num}", settings_course_path(@course, :tab => 'member'), :class => 'mr5 link-color-blue', :id => 'teacher_number'
|
||||
elsif User.current.member_of_course?(@course)
|
||||
link_to "#{teacher_num}", course_member_path(@course, :role => 't'), :class => 'mr5 link-color-blue', :id => 'teacher_number'
|
||||
else
|
||||
content_tag 'span',teacher_num, :class => 'mr5 color-blue'
|
||||
|
|
@ -87,7 +89,9 @@ module CoursesHelper
|
|||
|
||||
#生成课程学生列表连接
|
||||
def course_student_link student_num
|
||||
if (User.current.logged? && @course.open_student == 1) || (User.current.member_of_course?(@course)) || User.current.admin?
|
||||
if User.current.allowed_to?(:as_teacher, @course)
|
||||
link_to "#{student_num}", settings_course_path(@course, :tab => 'member', :role => 'as'), :class => 'mr5 link-color-blue', :id => 'student_number'
|
||||
elsif (User.current.logged? && @course.open_student == 1) || (User.current.member_of_course?(@course))
|
||||
link_to "#{student_num}", course_member_path(@course, :role => 'as'), :class => 'mr5 link-color-blue', :id => "student_number"
|
||||
else
|
||||
content_tag 'span',student_num, :class => 'mr5 color-blue'
|
||||
|
|
@ -96,8 +100,10 @@ module CoursesHelper
|
|||
|
||||
# 生成分班列表连接
|
||||
def course_group_link group_num
|
||||
if (User.current.logged? && @course.open_student == 1) || (User.current.member_of_course?(@course)) || User.current.admin?
|
||||
link_to "#{group_num}", course_member_path(@course, :role => @course.course_groups.first.id), :class => 'sy_cblue', :id => "student_number"
|
||||
if User.current.allowed_to?(:as_teacher, @course)
|
||||
link_to "#{group_num}", settings_course_path(@course, :tab => 'member', :role => @course.course_groups.first.id), :class => 'mr5 link-color-blue', :id => 'group_number'
|
||||
elsif (User.current.logged? && @course.open_student == 1) || (User.current.member_of_course?(@course))
|
||||
link_to "#{group_num}", course_member_path(@course, :role => @course.course_groups.first.id), :class => 'mr5 link-color-blue', :id => "group_number"
|
||||
else
|
||||
content_tag 'span',group_num, :class => 'sy_cblue'
|
||||
end
|
||||
|
|
@ -827,26 +833,6 @@ module CoursesHelper
|
|||
link.html_safe
|
||||
end
|
||||
|
||||
# 可以查看到资源库的资源
|
||||
def visable_attachemnts_incourse course
|
||||
return[] unless course
|
||||
result = []
|
||||
course.attachments.each do |attachment|
|
||||
if attachment.is_public? && attachment.is_publish == 1 || User.current == attachment.author || User.current.allowed_to?(:as_teacher,course) || (User.current.member_of_course?(course) && attachment.is_publish == 1) || User.current.admin?
|
||||
result << attachment
|
||||
end
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
def visable_course_homework course
|
||||
if User.current.admin? || User.current.allowed_to?(:as_teacher,course)
|
||||
homework_num = course.homework_commons.count
|
||||
else
|
||||
homework_num = course.homework_commons.where("publish_time <= '#{Time.now}'").count
|
||||
end
|
||||
homework_num
|
||||
end
|
||||
|
||||
def zh_course_role role
|
||||
if role == "TeachingAsistant"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
module DiscussesHelper
|
||||
end
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
module HomeworkBankHelper
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
module ManagementHelper
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
module ManagementsHelper
|
||||
|
||||
def trial_authorization_status status
|
||||
case status
|
||||
when "0", nil
|
||||
0
|
||||
when "1"
|
||||
1
|
||||
when "2"
|
||||
2
|
||||
else
|
||||
[1,2]
|
||||
end
|
||||
end
|
||||
|
||||
def query_user_status_num status
|
||||
user = (status == 0) ? user = User.all : User.where(:status => status)
|
||||
return user.count
|
||||
end
|
||||
end
|
||||
|
|
@ -12,4 +12,7 @@ module OwnerTypeHelper
|
|||
ArticleHomepage = 11
|
||||
PROJECT = 12
|
||||
CONTEST = 13
|
||||
HOMEWORKREFERENCEANSWER = 14
|
||||
STUDENTWORK = 15
|
||||
HOMEWORKBANK = 16
|
||||
end
|
||||
|
|
@ -21,4 +21,5 @@ module ShixunsHelper
|
|||
def had_passed_challenge challenge
|
||||
Game.where(:challenge_id => challenge.id, :status => 2).limit(3).reorder("final_score desc")
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
module StagesHelper
|
||||
end
|
||||
|
|
@ -73,6 +73,73 @@ module StudentWorkHelper
|
|||
str
|
||||
end
|
||||
|
||||
# 作品列表的提交状态
|
||||
def list_work_status status
|
||||
case status
|
||||
when 0
|
||||
str = "未提交"
|
||||
when 1
|
||||
str = "按时提交"
|
||||
when 2
|
||||
str = "延时提交"
|
||||
end
|
||||
end
|
||||
|
||||
# 作品的助教评分模式
|
||||
def ta_score_mode homework
|
||||
mode = homework.homework_detail_manual.ta_mode == 1 ? '平均' : '复审'
|
||||
mode
|
||||
end
|
||||
|
||||
#根据传入作业确定显示为编辑作品还是新建作品,或者显示作品数量
|
||||
def user_work_status homework
|
||||
if User.current.logged?
|
||||
if User.current.member_of_course?(homework.course)
|
||||
work = cur_user_works_for_homework homework
|
||||
project = cur_user_projects_for_homework homework
|
||||
if work.nil? && homework.end_time >= Time.now
|
||||
if homework.homework_type == 4
|
||||
link_to "关联实战", relate_myshixun_student_work_index_path(:homework => homework.id),:class => 'task-btn task-btn-blue fr',:remote => true
|
||||
else
|
||||
link_to "提交作品", new_student_work_url_without_domain(homework.id),:class => 'task-btn task-btn-blue fr'
|
||||
end
|
||||
elsif work.nil? && homework.end_time < Time.now
|
||||
if homework.allow_late && homework.homework_detail_manual.comment_status < 6
|
||||
if homework.homework_type == 4
|
||||
link_to "关联实战", relate_myshixun_student_work_index_path(:homework => homework.id),:class => 'task-btn task-btn-blue fr',:remote => true
|
||||
else
|
||||
link_to "补交作品", new_student_work_url_without_domain(homework.id),:class => 'task-btn task-btn-blue fr'
|
||||
end
|
||||
end
|
||||
elsif work
|
||||
if homework.homework_type == 4
|
||||
myshixun = Myshixun.find work.myshixun_id
|
||||
link_to "继续实战", myshixun_game_path(myshixun.current_task, :myshixun_id => myshixun), :class => "task-btn task-btn-blue fr mr10",:target => "_blank" if myshixun
|
||||
else
|
||||
if homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 3 && StudentWorksEvaluationDistribution.where("student_work_id = #{work.id}").count > 0 #匿评作业,且作业状态不是在开启匿评之前
|
||||
if homework.homework_type != 3
|
||||
link_to "匿评作品", student_work_index_url_in_org(homework.id, 2), :class => 'task-btn task-btn-blue fr', :title => "开启匿评后不可修改作品"
|
||||
else
|
||||
work_ids = "(" + homework.student_works.has_committed.map(&:id).join(",") + ")"
|
||||
if User.current.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count > 0
|
||||
link_to "匿评作品", student_work_index_url_in_org(homework.id, 2), :class => 'task-btn task-btn-blue fr', :title => "开启匿评后不可修改作品"
|
||||
else
|
||||
link_to "查看作品", student_work_path(work), :class => 'task-btn task-btn-blue fr', :title => "匿评开启后提交的作品不参与匿评"
|
||||
end
|
||||
end
|
||||
elsif homework.homework_detail_manual && homework.homework_detail_manual.comment_status > 3
|
||||
link_to "查看作品", student_work_path(work), :class => 'task-btn task-btn-blue fr', :title => "匿评已结束"
|
||||
elsif homework.end_time >= Time.now && work.user_id == User.current.id
|
||||
link_to "修改作品", edit_student_work_url_without_domain(work.id),:class => 'task-btn task-btn-blue fr'
|
||||
else
|
||||
link_to "查看作品", student_work_path(work), :class => 'task-btn task-btn-blue fr', :title => "作业截止后不可修改作品"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#获取学生作品的评分记录:同一个教师或教辅只显示未隐藏的评分
|
||||
def student_work_score_record work
|
||||
# sql = "SELECT MAX(id) id FROM student_works_scores WHERE (reviewer_role = 2 OR reviewer_role = 1) AND score IS NOT NULL AND is_hidden = 0 AND student_work_id = #{work.id} GROUP BY user_id"
|
||||
|
|
@ -173,15 +240,29 @@ module StudentWorkHelper
|
|||
return status
|
||||
end
|
||||
|
||||
def group_student_works student_work, homework
|
||||
pros = student_work.student_work_projects.where("is_leader = 0")
|
||||
def group_member_work student_work
|
||||
member_work = nil
|
||||
if student_work.student_work_projects.count > 0
|
||||
member_work = student_work
|
||||
else
|
||||
student_work_pro = StudentWorkProject.where(:user_id => student_work.user_id, :homework_common_id => student_work.homework_common_id).first
|
||||
if student_work_pro
|
||||
member_work = StudentWork.find student_work_pro.student_work_id
|
||||
end
|
||||
end
|
||||
member_work
|
||||
end
|
||||
|
||||
def group_student_works member_work, student_work, homework
|
||||
pros = member_work.student_work_projects.where("user_id != #{student_work.user_id}")
|
||||
user_ids = pros.empty? ? "(-1)" : "(" + pros.map{|stu|stu.user_id}.join(",") + ")"
|
||||
student_works = homework.student_works.where("user_id in #{user_ids}")
|
||||
return student_works
|
||||
end
|
||||
|
||||
def add_score_to_member student_work, homework, new_score
|
||||
student_works = group_student_works student_work, homework
|
||||
member_work = group_member_work student_work
|
||||
student_works = group_student_works member_work, student_work, homework
|
||||
student_works.each do |st_work|
|
||||
st_work.student_works_scores << StudentWorksScore.create(:user_id => new_score.user_id, :score => new_score.score, :reviewer_role => new_score.reviewer_role, :comment => new_score.comment)
|
||||
if new_score.reviewer_role == 1
|
||||
|
|
@ -190,7 +271,7 @@ module StudentWorkHelper
|
|||
ts_score = StudentWorksScore.find_by_sql("SELECT AVG(score) AS score FROM (SELECT * FROM (SELECT * FROM student_works_scores WHERE student_work_id = #{st_work.id} AND reviewer_role = 2 AND score IS NOT NULL ORDER BY created_at DESC) AS t GROUP BY user_id) AS a")
|
||||
st_work.teaching_asistant_score = ts_score.first.score.nil? ? nil : ts_score.first.score.try(:round, 2).to_f
|
||||
else
|
||||
st_work.student_score = student_work.student_score
|
||||
st_work.student_score = member_work.student_score
|
||||
end
|
||||
st_work.save
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
module SubjectsHelper
|
||||
end
|
||||
|
|
@ -102,6 +102,21 @@ module SyllabusesHelper
|
|||
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 = []
|
||||
|
|
@ -131,74 +146,4 @@ module SyllabusesHelper
|
|||
content
|
||||
end
|
||||
|
||||
def sy_resources syllabus
|
||||
courses = syllabus.courses.not_deleted
|
||||
attachments = Attachment.where(:container_type => 'Course', :container_id => courses.map(&:id))
|
||||
resources = ResourceBank.where(:id => attachments.map(&:resource_bank_id))
|
||||
resources
|
||||
end
|
||||
|
||||
def sy_homeworks syllabus
|
||||
courses = syllabus.courses.not_deleted
|
||||
homeworks = HomeworkCommon.where(:course_id => courses.map(&:id))
|
||||
homeworks = HomeworkBank.where(:id => homeworks.map(&:homework_bank_id))
|
||||
homeworks
|
||||
end
|
||||
|
||||
def quote_resource_bank resource, course
|
||||
atta = Attachment.new(:filename => resource.filename, :disk_filename => resource.disk_filename, :filesize => resource.filesize, :digest => resource.digest, :downloads => 0, :is_publish => 0,
|
||||
:author_id => User.current.id, :description => resource.description, :disk_directory => resource.disk_directory, :is_public => 0, :copy_from => resource.copy_from.nil? ? resource.id : resource.copy_from,
|
||||
:quotes => 0, :resource_bank_id => resource.id, :created_on => Time.now, :content_type =>resource.content_type)
|
||||
if course.attachments << atta
|
||||
# 更新引用次数
|
||||
quotes = resource.quotes.to_i + 1
|
||||
resource.update_attribute(:quotes, quotes)
|
||||
end
|
||||
end
|
||||
|
||||
def quote_homework_bank homework, course
|
||||
new_homework = HomeworkCommon.new(:name => homework.name, :user_id => User.current.id, :description => homework.description, :homework_type => homework.homework_type, :late_penalty => 0,
|
||||
:course_id => course.id, :teacher_priority => 1, :anonymous_comment => 1, :quotes => 0, :is_open => 0,
|
||||
:homework_bank_id => homework.id, :score_open => 1, :anonymous_appeal => 0)
|
||||
|
||||
new_homework.homework_detail_manual = HomeworkDetailManual.new
|
||||
new_homework_detail_manual = new_homework.homework_detail_manual
|
||||
new_homework_detail_manual.ta_proportion = new_homework.homework_type == 2 ? 0.4 : 1.0
|
||||
new_homework_detail_manual.comment_status = 0
|
||||
new_homework_detail_manual.evaluation_num = 3
|
||||
new_homework_detail_manual.absence_penalty = 0
|
||||
|
||||
if new_homework.homework_type == 2
|
||||
new_homework.homework_detail_programing = HomeworkDetailPrograming.new
|
||||
new_homework.homework_detail_programing.ta_proportion = 0.6
|
||||
new_homework.homework_detail_programing.language = homework.language
|
||||
homework.homework_bank_tests.each_with_index do |homework_test|
|
||||
if homework_test.test_type
|
||||
new_homework.homework_tests << HomeworkTest.new(
|
||||
input: homework_test.input,
|
||||
output: homework_test.output
|
||||
)
|
||||
else
|
||||
new_homework.homework_samples << HomeworkSample.new(
|
||||
input: homework_test.input,
|
||||
output: homework_test.output
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if new_homework.homework_type == 3
|
||||
new_homework.homework_detail_group = HomeworkDetailGroup.new
|
||||
new_homework.homework_detail_group.min_num = homework.min_num
|
||||
new_homework.homework_detail_group.max_num = homework.max_num
|
||||
new_homework.homework_detail_group.base_on_project = homework.base_on_project
|
||||
end
|
||||
|
||||
if new_homework.save
|
||||
new_homework_detail_manual.save if new_homework_detail_manual
|
||||
new_homework.homework_detail_programing.save if new_homework.homework_detail_programing
|
||||
new_homework.homework_detail_group.save if new_homework.homework_detail_group
|
||||
homework.update_column(:quotes, homework.quotes+1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -325,11 +325,11 @@ module UsersHelper
|
|||
url = {:controller => 'users', :action => 'update', :id => user, :page => params[:page], :status => params[:status], :tab => nil}
|
||||
|
||||
if user.locked?
|
||||
link_to l(:button_unlock), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :put, :class => 'icon icon-unlock'
|
||||
link_to "解锁", url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :put, :class => 'mr10 link-color-blue'
|
||||
elsif user.registered?
|
||||
link_to l(:button_activate), url.merge(:user => {:status => User::STATUS_ACTIVE}), :method => :put, :class => 'icon icon-unlock'
|
||||
elsif user != User.current
|
||||
link_to l(:button_lock), url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :put, :class => 'icon icon-lock'
|
||||
link_to "加锁", url.merge(:user => {:status => User::STATUS_LOCKED}), :method => :put, :class => 'mr10 link-color-blue'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
# status:0 审核中 1 同意 2 拒绝 3 撤销
|
||||
class ApplyAction < ActiveRecord::Base
|
||||
default_scope :order => 'updated_at desc'
|
||||
attr_accessible :container_id, :container_type, :dealer_id, :reason, :user_id, :status
|
||||
|
||||
belongs_to :user
|
||||
end
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
class Authentication < ActiveRecord::Base
|
||||
attr_accessible :level, :permissions
|
||||
serialize :permissions, Array
|
||||
has_and_belongs_to_many :users
|
||||
# has_many :users_authenticationses
|
||||
# has_many :users, :through => :users_authenticationses
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
class AuthenticationsUsers < ActiveRecord::Base
|
||||
attr_accessible :authentication_id, :user_id
|
||||
end
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
#coding=utf-8
|
||||
class Challenge < ActiveRecord::Base
|
||||
default_scope :order => 'position'
|
||||
belongs_to :shixun,:touch=> true
|
||||
|
|
@ -8,10 +9,23 @@ class Challenge < ActiveRecord::Base
|
|||
has_many :games, :dependent => :destroy
|
||||
|
||||
validates_presence_of :subject
|
||||
validates_presence_of :score
|
||||
# validates_presence_of :score
|
||||
validates_presence_of :task_pass
|
||||
validates_length_of :subject, :maximum => 255
|
||||
|
||||
def game_difficulty
|
||||
str = "简单"
|
||||
case self.difficulty
|
||||
when 1
|
||||
str = "简单"
|
||||
when 2
|
||||
str = "中等"
|
||||
when 3
|
||||
str = "困难"
|
||||
end
|
||||
str
|
||||
end
|
||||
|
||||
def next_challenge
|
||||
challenge_count = Challenge.where(:shixun_id => self.shixun_id).count
|
||||
render_404 if self.position ==challenge_count
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class Course < ActiveRecord::Base
|
|||
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
|
||||
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表
|
||||
|
|
@ -66,6 +66,8 @@ class Course < ActiveRecord::Base
|
|||
# 课程贡献榜
|
||||
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,
|
||||
|
|
@ -101,12 +103,15 @@ class Course < ActiveRecord::Base
|
|||
'syllabus_id',
|
||||
'end_time',
|
||||
'end_term',
|
||||
'os_allow'
|
||||
'choose_group_allow'
|
||||
'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}) }
|
||||
|
|
@ -354,6 +359,19 @@ class Course < ActiveRecord::Base
|
|||
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)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
class CourseList < ActiveRecord::Base
|
||||
has_many :major_courses
|
||||
has_many :shixun_major_courses
|
||||
attr_accessible :name
|
||||
end
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
class CourseModule < ActiveRecord::Base
|
||||
# attr_accessible :title, :body
|
||||
belongs_to :course
|
||||
attr_accessible :course_id, :module_type, :position, :hidden
|
||||
|
||||
end
|
||||
|
|
@ -2,4 +2,5 @@ class DisciplineCategory < ActiveRecord::Base
|
|||
attr_accessible :major_level, :name
|
||||
|
||||
has_many :first_level_disciplines
|
||||
has_many :majors
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
class Discuss < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
attr_accessible :user_id, :content, :dis_id, :dis_type, :parent_id, :praise_count, :root_id
|
||||
|
||||
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
|
||||
has_one :praise_tread_cache, as: :object, dependent: :destroy
|
||||
acts_as_tree :foreign_key => 'parent_id'
|
||||
belongs_to :dis, :polymorphic => true
|
||||
validates_presence_of :dis, :user, :content
|
||||
end
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
class Experience < ActiveRecord::Base
|
||||
attr_accessible :container_id, :container_type, :score, :user_id
|
||||
end
|
||||
|
|
@ -2,4 +2,5 @@ class FirstLevelDiscipline < ActiveRecord::Base
|
|||
belongs_to :discipline_category
|
||||
attr_accessible :name
|
||||
has_many :syllabuses
|
||||
has_many :majors
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
class Game < ActiveRecord::Base
|
||||
# stauts 0: can exe 1:doing 2:successed 3:locked
|
||||
default_scope :order => 'created_at desc'
|
||||
attr_accessible :myshixun_id, :user_id, :status, :final_score, :challenge_id, :open_time, :identifier, :answer_open, :end_time, :retry_status
|
||||
attr_accessible :myshixun_id, :user_id, :status, :final_score, :challenge_id, :open_time, :identifier, :answer_open, :end_time, :retry_status, :resubmit_identifier
|
||||
belongs_to :myshixun,:touch=> true
|
||||
belongs_to :user
|
||||
belongs_to :challenge
|
||||
has_many :outputs, :dependent => :destroy
|
||||
has_many :test_sets
|
||||
has_many :test_sets, :dependent => :destroy
|
||||
has_many :challenge_samples
|
||||
has_one :game_code, :dependent => :destroy
|
||||
|
||||
def had_done
|
||||
myshixun = self.myshixun
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
class GameCode < ActiveRecord::Base
|
||||
attr_accessible :game_id, :new_code, :original_code, :path
|
||||
belongs_to :game
|
||||
end
|
||||
|
|
@ -2,7 +2,11 @@
|
|||
class HomeworkBank < ActiveRecord::Base
|
||||
# attr_accessible :title, :body
|
||||
belongs_to :user
|
||||
has_many :homework_bank_tests
|
||||
belongs_to :syllabus
|
||||
has_many :homework_bank_tests, :dependent => :destroy
|
||||
has_many :homework_bank_samples, :dependent => :destroy
|
||||
has_many :homework_commons
|
||||
has_one :homework_bank_shixun
|
||||
acts_as_attachable
|
||||
|
||||
def language_name
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
class HomeworkBankSample < ActiveRecord::Base
|
||||
belongs_to :homework_bank
|
||||
attr_accessible :input, :output, :homework_bank_id
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
class HomeworkBankShixun < ActiveRecord::Base
|
||||
belongs_to :homework_bank
|
||||
belongs_to :shixun
|
||||
attr_accessible :homework_bank_id, :shixun_id
|
||||
end
|
||||
|
|
@ -14,6 +14,7 @@ class HomeworkCommon < ActiveRecord::Base
|
|||
has_one :homework_detail_manual, :dependent => :destroy
|
||||
has_one :homework_detail_programing, :dependent => :destroy
|
||||
has_one :homework_detail_group, :dependent => :destroy
|
||||
has_one :homework_commons_shixuns
|
||||
has_many :student_work_projects, :dependent => :destroy
|
||||
has_many :homework_tests, :dependent => :destroy
|
||||
has_many :homework_samples, :dependent => :destroy
|
||||
|
|
@ -24,6 +25,7 @@ class HomeworkCommon < ActiveRecord::Base
|
|||
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
|
||||
has_one :praise_tread_cache, as: :object, dependent: :destroy
|
||||
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy #用户活动
|
||||
has_and_belongs_to_many :shixuns
|
||||
# 课程动态
|
||||
has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy
|
||||
# 课程消息
|
||||
|
|
@ -59,6 +61,8 @@ class HomeworkCommon < ActiveRecord::Base
|
|||
type = "编程"
|
||||
when 3
|
||||
type = "分组"
|
||||
when 4
|
||||
type = "实训"
|
||||
end
|
||||
type
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
class HomeworkCommonsShixuns < ActiveRecord::Base
|
||||
attr_accessible :homework_common_id, :shixun_id
|
||||
belongs_to :homework_common
|
||||
belongs_to :shixun
|
||||
end
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#手动评分作业表
|
||||
#comment_status: 1:未开启匿评,2:开启匿评,3:匿评结束
|
||||
#comment_status: 0:挂起, 1:提交,2:补交(去掉),3:匿评中,4:申诉中,5:评阅中,6:已结束
|
||||
class HomeworkDetailManual < ActiveRecord::Base
|
||||
attr_accessible :ta_proportion, :comment_status, :evaluation_start, :evaluation_end, :evaluation_num, :absence_penalty, :homework_common_id, :no_anon_penalty
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
class HomeworkReferenceAnswer < ActiveRecord::Base
|
||||
belongs_to :homework_common
|
||||
attr_accessible :answer, :homework_common_id
|
||||
|
||||
acts_as_attachable
|
||||
end
|
||||
|
|
@ -837,12 +837,12 @@ class Mailer < ActionMailer::Base
|
|||
:subject => l(:mail_subject_register, Setting.app_title)
|
||||
end
|
||||
|
||||
def bind_email(token, code="111111")
|
||||
def bind_email(token, code="111111", email)
|
||||
set_language_if_valid(token.user.language)
|
||||
@login = token.user.try(:login)
|
||||
@token = token
|
||||
@code = code
|
||||
mail :to => token.user.mail,
|
||||
mail :to => email,
|
||||
:subject => l(:mail_subject_bind_mail, Setting.app_title+"("+Setting.host_name+")")
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
class Major < ActiveRecord::Base
|
||||
belongs_to :first_level_discipline
|
||||
belongs_to :discipline_category
|
||||
has_many :major_courses
|
||||
has_many :shixun_major_courses
|
||||
has_many :subjects
|
||||
attr_accessible :major_code, :major_level, :name, :first_level_discipline_id, :discipline_category_id
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
class MajorCourse < ActiveRecord::Base
|
||||
belongs_to :course_list
|
||||
belongs_to :major
|
||||
attr_accessible :course_list_id, :major_id
|
||||
end
|
||||
|
|
@ -3,9 +3,12 @@ class Myshixun < ActiveRecord::Base
|
|||
attr_accessible :description, :name, :parent_id, :user_id, :gpid, :forked_from, :visits, :is_public, :identifier
|
||||
# has_many :users, :through => :myshixun_members
|
||||
has_many :myshixun_members, :dependent => :destroy
|
||||
has_one :repository
|
||||
has_one :repository, :dependent => :destroy
|
||||
has_many :games, :dependent => :destroy, :order => "games.id ASC"
|
||||
belongs_to :shixun
|
||||
has_one :shixun_modify, :dependent => :destroy
|
||||
has_one :webssh, :dependent => :destroy
|
||||
has_many :student_works
|
||||
|
||||
def total_stage
|
||||
self.games.count
|
||||
|
|
@ -17,6 +20,34 @@ class Myshixun < ActiveRecord::Base
|
|||
return position
|
||||
end
|
||||
|
||||
def done_time
|
||||
time = ""
|
||||
if self.status == 1
|
||||
time = self.games.order("end_time desc").first.try(:end_time)
|
||||
end
|
||||
time
|
||||
end
|
||||
|
||||
def total_spend_time
|
||||
time = 0
|
||||
self.games.each do |game|
|
||||
if game.status == 2
|
||||
time += (game.end_time -game.open_time).to_i > 0 ? (game.end_time -game.open_time).to_i : 0
|
||||
end
|
||||
end
|
||||
time
|
||||
end
|
||||
|
||||
def total_score
|
||||
score = 0
|
||||
self.games.each do |game|
|
||||
if game.status == 2
|
||||
score += game.final_score
|
||||
end
|
||||
end
|
||||
score
|
||||
end
|
||||
|
||||
# id 转换成 identifier
|
||||
def to_param
|
||||
identifier
|
||||
|
|
@ -27,10 +58,10 @@ class Myshixun < ActiveRecord::Base
|
|||
# 如果都完成,则当前任务为最后一个任务
|
||||
def current_task
|
||||
games = self.games
|
||||
current_game = games.select{|game| game.status==1 || game.status==0}.first
|
||||
current_game = games.select{|game| game.status == 1 || game.status == 0}.first
|
||||
if current_game.blank?
|
||||
passed_games = games.select{|game| game.status==2}
|
||||
current_game = passed_games.last
|
||||
passed_games = games.select{|game| game.status == 2}
|
||||
current_game = passed_games.first
|
||||
end
|
||||
return current_game
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,21 +1,104 @@
|
|||
# status 控制实训的状态,0:未开启;1: 已开启(TPM); 2:已认证
|
||||
# encoding: utf-8
|
||||
# status 控制实训的状态,0:编辑;1: 申请发布; 2:正式发布; 3:关闭
|
||||
# is_updated 字段为1表示实训的更改可能会影响到后续的评测,0表示更改不会影响后续的评测
|
||||
# 繁忙等级参数:80发布实训失败,返回code为-1;81:实训开启的时候fork失败;83:开启实训的时候,openGameInstance返回非0值;84:jenkins系统异常,post数据不成功
|
||||
# 85:challenge创建的时候Jenkins处理异常;86:实训评测失败,jenkins返回错误结果; 87:版本库删除异常;88:点击评测失败,没返回数据;89:重置链接jenkins返回失败
|
||||
# 90: 更新公共测试用例失败,返回code非0;91:实训有改动,评测的时候初始化数据,返回数据code非0;92:webssh开启失败,接口getConnectInfo返回code值非0
|
||||
# 93: 实训断开连接失败,接口deleteSSH返回code值非0
|
||||
# 116:challenge创建关卡的时候返回结果错误
|
||||
#
|
||||
class Shixun < ActiveRecord::Base
|
||||
attr_accessible :description, :is_public, :name, :changeset_num, :status, :user_id, :gpid, :language, :identifier, :authentication, :myshixun_count
|
||||
attr_accessible :description, :is_public, :name, :changeset_num, :status, :user_id, :gpid, :language, :identifier, :authentication,
|
||||
:myshixun_count, :propaedeutics, :trainee, :major_id
|
||||
|
||||
has_many :users, :through => :shixun_members
|
||||
has_many :shixun_members
|
||||
has_one :repository
|
||||
has_many :shixun_members, :dependent => :destroy
|
||||
has_one :repository, :dependent => :destroy
|
||||
has_many :homework_commons_shixunses
|
||||
has_many :challenges, :dependent => :destroy, :order => "challenges.id ASC"
|
||||
has_many :myshixuns
|
||||
has_many :myshixuns, :dependent => :destroy
|
||||
has_many :stage_shixuns, :dependent => :destroy
|
||||
belongs_to :major
|
||||
belongs_to :major_course
|
||||
has_many :shixun_major_courses, :dependent => :destroy
|
||||
has_and_belongs_to_many :homework_commons
|
||||
has_many :discusses, :as => :dis, :dependent => :destroy
|
||||
|
||||
# 获取特定格式的实训测试用例
|
||||
# params = {:challengeStage => "#{@challenge.position}", :challengeType => "#{@challenge.evaluation_way.to_i}",
|
||||
# :challengeProgramName => "#{@challenge.exec_path}",
|
||||
# :trainingID => "#{@shixun.id}", :operationEnvironment => @shixun.language}
|
||||
def gameInfo
|
||||
fragments = []
|
||||
testSet = []
|
||||
testCases = []
|
||||
challenges = self.challenges.includes(:test_sets)
|
||||
challenges.each do |challenge|
|
||||
pipeline_script = {:challengeStage => "#{challenge.position}", :challengeType => "#{challenge.evaluation_way.to_i}", :challengeProgramName => "#{challenge.exec_path}", :operationEnvironment => "#{self.language}", :trainingID => "#{self.id}"}
|
||||
fragments << pipeline_script
|
||||
# 每一关所有的测试集
|
||||
challenge.test_sets.each do |test_set|
|
||||
test_cases = {:caseId => test_set.id.to_s, :input => test_set.input, :output => test_set.output, :isPublic => (test_set.is_public ? "1" : "0")}
|
||||
testSet << test_cases
|
||||
end
|
||||
test_sets_list = {:challengeStage => challenge.position.to_s, :challengeTestCases => testSet}
|
||||
testCases << test_sets_list
|
||||
testSet = []
|
||||
end
|
||||
gameInfo = {:trainingID => self.id.to_s, :operationEnvironment => self.language, :challengeInfo => fragments, :testCases => testCases}
|
||||
gameInfo = Base64.strict_encode64(gameInfo.to_json) unless gameInfo.blank?
|
||||
return gameInfo
|
||||
end
|
||||
|
||||
# id 转换成 identifier
|
||||
def to_param
|
||||
identifier
|
||||
end
|
||||
|
||||
def shixun_trainee
|
||||
trainee = ""
|
||||
case self.trainee
|
||||
when 1
|
||||
trainee = "初级学员"
|
||||
when 2
|
||||
trainee = "中级学员"
|
||||
when 3
|
||||
trainee = "高级学员"
|
||||
when 4
|
||||
trainee = "顶级学员"
|
||||
end
|
||||
trainee
|
||||
end
|
||||
|
||||
def owner
|
||||
User.find(self.user_id)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def shixun_score
|
||||
score = 0
|
||||
self.challenges.each do |challenge|
|
||||
score += challenge.score.to_i
|
||||
end
|
||||
score
|
||||
end
|
||||
|
||||
def shixun_status
|
||||
status = ""
|
||||
case self.status
|
||||
when 0
|
||||
status = "编辑中"
|
||||
when 1
|
||||
status = "审核中"
|
||||
when 2
|
||||
status = "已发布"
|
||||
when 3
|
||||
status = "已关闭"
|
||||
end
|
||||
end
|
||||
|
||||
def collaborators
|
||||
self.shixun_members.select{|member| member.role == 2} unless self.shixun_members.blank?
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
class ShixunMajorCourse < ActiveRecord::Base
|
||||
belongs_to :shixun
|
||||
belongs_to :major
|
||||
belongs_to :course_list
|
||||
#attr_accessible :course_list
|
||||
end
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
class ShixunMember < ActiveRecord::Base
|
||||
# role 实训角色: 1 创建者 2 合作者
|
||||
attr_accessible :shixun_id, :user_id, :role
|
||||
belongs_to :shixun
|
||||
belongs_to :user
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
class ShixunModify < ActiveRecord::Base
|
||||
attr_accessible :myshixun_id, :shixun_id, :status
|
||||
belongs_to :myshixun
|
||||
end
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
class Stage < ActiveRecord::Base
|
||||
belongs_to :subject
|
||||
belongs_to :user
|
||||
attr_accessible :description, :name, :position, :subject_id, :user_id
|
||||
|
||||
has_many :stage_shixuns, :dependent => :destroy, :order => "stage_shixuns.position ASC"
|
||||
end
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
class StageShixun < ActiveRecord::Base
|
||||
belongs_to :subject
|
||||
belongs_to :stage
|
||||
belongs_to :shixun
|
||||
attr_accessible :position, :subject_id, :stage_id, :shixun_id
|
||||
end
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
#学生提交作品表 #work_status :0 未提交 1 已提交 2 迟交 3 分组作品复制的组员作品
|
||||
class StudentWork < ActiveRecord::Base
|
||||
attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :system_score, :work_score, :project_id, :is_test, :simi_id, :simi_value, :work_status, :commit_time, :late_penalty, :absence_penalty, :re_commit
|
||||
attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :system_score, :work_score, :project_id, :is_test, :simi_id,
|
||||
:simi_value, :work_status, :commit_time, :late_penalty, :absence_penalty, :re_commit, :late_reason, :group_id
|
||||
|
||||
belongs_to :homework_common
|
||||
belongs_to :user
|
||||
|
|
@ -12,9 +13,10 @@ class StudentWork < ActiveRecord::Base
|
|||
# course's message
|
||||
has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy
|
||||
has_many :attachments, :dependent => :destroy
|
||||
has_one :myshixun
|
||||
|
||||
scope :has_committed, lambda{where("work_status != 0 and work_status != 3")}
|
||||
scope :no_copy, lambda{where("work_status != 3")}
|
||||
scope :all_commit, lambda{where("work_status != 0")}
|
||||
|
||||
before_destroy :delete_praise
|
||||
before_save :set_program_score, :set_src
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class StudentsForCourse < ActiveRecord::Base
|
|||
validates_uniqueness_of :student_id, :scope => :course_id
|
||||
|
||||
after_destroy :delete_student_works, :delete_course_homework_statistic
|
||||
after_create :recovery_student_works, :create_student_works, :create_course_homework_statistic, :create_course_contribute_score
|
||||
after_create :recovery_student_works, :create_student_works
|
||||
|
||||
#退出班级或删除学生时隐藏学生的作品
|
||||
def delete_student_works
|
||||
|
|
@ -23,50 +23,59 @@ class StudentsForCourse < ActiveRecord::Base
|
|||
#加入班级时还原作品
|
||||
def recovery_student_works
|
||||
course = self.course
|
||||
homework_ids = course.homework_commons.blank? ? "(-1)" : "(" + course.homework_commons.map{|hw| hw.id}.join(",") + ")"
|
||||
student_works = StudentWork.where("user_id = #{self.student_id} && homework_common_id in #{homework_ids}")
|
||||
homework_ids = course.homework_commons.map(&:id)
|
||||
student_works = StudentWork.where(:user_id => self.student_id, :homework_common_id => homework_ids)
|
||||
student_works.update_all(:is_delete => 0)
|
||||
end
|
||||
|
||||
#加入班级时创建已发布作业的作品
|
||||
def create_student_works
|
||||
course = self.course
|
||||
course.homework_commons.includes(:homework_detail_manual).where("homework_detail_manuals.comment_status > 0").each do |hw|
|
||||
if hw.homework_type != 3 && hw.student_works.where("user_id = #{self.student_id}").count == 0
|
||||
hw.student_works << StudentWork.new(:user_id => self.student_id, :name => hw.name.to_s+"的作品提交", :work_status => 0)
|
||||
str = ""
|
||||
homeworks = course.homework_commons.includes(:homework_detail_manual).where("homework_detail_manuals.comment_status != 0")
|
||||
if homeworks.count != 0
|
||||
homeworks.each do |hw|
|
||||
if hw.student_works.where("user_id = #{self.student_id}").count == 0
|
||||
if str != ""
|
||||
str += ","
|
||||
end
|
||||
str += "('#{hw.name}的作品提交',#{hw.id},#{self.student_id}, '#{format_time(Time.now)}', '#{format_time(Time.now)}')"
|
||||
end
|
||||
end
|
||||
sql = "insert into student_works (name, homework_common_id,user_id, created_at, updated_at) values" + str
|
||||
ActiveRecord::Base.connection.execute sql
|
||||
end
|
||||
end
|
||||
|
||||
#加入班级时创建一条记录
|
||||
def create_course_homework_statistic
|
||||
if CourseHomeworkStatistics.where(:user_id => self.student_id, :course_id => self.course_id).count == 0
|
||||
course = self.course
|
||||
user = self.student
|
||||
hw_count = course.homework_commons.includes(:homework_detail_manual).where("homework_detail_manuals.comment_status > 0").count
|
||||
homework_ids = course.homework_commons.empty? ? "(-1)" : "(" + course.homework_commons.map{|hw| hw.id}.join(",") + ")"
|
||||
student_works = StudentWork.where("homework_common_id in #{homework_ids} and work_status !=0")
|
||||
is_eva_homeworks = course.homework_commons.includes(:homework_detail_manual).where("homework_commons.anonymous_comment = 0 and homework_detail_manuals.comment_status = 2")
|
||||
is_eva_student_works = StudentWork.where(:homework_common_id => is_eva_homeworks.map{|hw| hw.id})
|
||||
has_eva_homeworks = course.homework_commons.includes(:homework_detail_manual).where("homework_commons.anonymous_comment = 0 and homework_detail_manuals.comment_status = 3")
|
||||
has_eva_student_works = StudentWork.where(:homework_common_id => has_eva_homeworks.map{|hw| hw.id})
|
||||
|
||||
committed_work_num = user.student_works.where("homework_common_id in #{homework_ids} and work_status != 0").count
|
||||
un_commit_work_num = (hw_count - committed_work_num) < 0 ? 0 : (hw_count - committed_work_num)
|
||||
late_commit_work_num = user.student_works.where("homework_common_id in #{homework_ids} and work_status = 2").count
|
||||
absence_evaluation_work_num = user.student_works_evaluation_distributions.where(:student_work_id => has_eva_student_works.map(&:id)).count -
|
||||
user.student_works_scores.where(:reviewer_role => 3, :student_work_id => has_eva_student_works.map(&:id)).group_by(&:student_work_id).count
|
||||
absence_evaluation_work_num = absence_evaluation_work_num < 0 ? 0 : absence_evaluation_work_num
|
||||
un_evaluation_work_num = user.student_works_evaluation_distributions.where(:student_work_id => is_eva_student_works.map(&:id)).count -
|
||||
user.student_works_scores.where(:reviewer_role => 3, :student_work_id => is_eva_student_works.map(&:id)).group_by(&:student_work_id).count
|
||||
un_evaluation_work_num = un_evaluation_work_num < 0 ? 0 : un_evaluation_work_num
|
||||
appeal_num = user.student_works_scores.where(:student_work_id => student_works.map(&:id), :appeal_status => 3).count
|
||||
average_score = user.student_works.where(:id => student_works.map(&:id)).select("AVG(student_works.work_score) as score").first ? user.student_works.where(:id => student_works.map(&:id)).select("AVG(student_works.work_score) as score").first.score : 0
|
||||
total_score = user.student_works.where(:id => student_works.map(&:id)).select("SUM(student_works.work_score) as score").first ? user.student_works.where(:id => student_works.map(&:id)).select("SUM(student_works.work_score) as score").first.score : 0
|
||||
CourseHomeworkStatistics.create(:course_id => course.id, :user_id => user.id, :committed_work_num => committed_work_num, :un_commit_work_num => un_commit_work_num,
|
||||
:late_commit_work_num => late_commit_work_num, :absence_evaluation_work_num => absence_evaluation_work_num, :un_evaluation_work_num => un_evaluation_work_num,
|
||||
:appeal_num => appeal_num, :average_score => average_score, :total_score => total_score)
|
||||
end
|
||||
# if CourseHomeworkStatistics.where(:user_id => self.student_id, :course_id => self.course_id).count == 0
|
||||
# course = self.course
|
||||
# user = self.student
|
||||
# hw_count = course.homework_commons.includes(:homework_detail_manual).where("homework_detail_manuals.comment_status > 0").count
|
||||
# homework_ids = course.homework_commons.empty? ? "(-1)" : "(" + course.homework_commons.map{|hw| hw.id}.join(",") + ")"
|
||||
# student_works = StudentWork.where("homework_common_id in #{homework_ids} and work_status !=0")
|
||||
# is_eva_homeworks = course.homework_commons.includes(:homework_detail_manual).where("homework_commons.anonymous_comment = 0 and homework_detail_manuals.comment_status = 2")
|
||||
# is_eva_student_works = StudentWork.where(:homework_common_id => is_eva_homeworks.map{|hw| hw.id})
|
||||
# has_eva_homeworks = course.homework_commons.includes(:homework_detail_manual).where("homework_commons.anonymous_comment = 0 and homework_detail_manuals.comment_status = 3")
|
||||
# has_eva_student_works = StudentWork.where(:homework_common_id => has_eva_homeworks.map{|hw| hw.id})
|
||||
#
|
||||
# committed_work_num = user.student_works.where("homework_common_id in #{homework_ids} and work_status != 0").count
|
||||
# un_commit_work_num = (hw_count - committed_work_num) < 0 ? 0 : (hw_count - committed_work_num)
|
||||
# late_commit_work_num = user.student_works.where("homework_common_id in #{homework_ids} and work_status = 2").count
|
||||
# absence_evaluation_work_num = user.student_works_evaluation_distributions.where(:student_work_id => has_eva_student_works.map(&:id)).count -
|
||||
# user.student_works_scores.where(:reviewer_role => 3, :student_work_id => has_eva_student_works.map(&:id)).group_by(&:student_work_id).count
|
||||
# absence_evaluation_work_num = absence_evaluation_work_num < 0 ? 0 : absence_evaluation_work_num
|
||||
# un_evaluation_work_num = user.student_works_evaluation_distributions.where(:student_work_id => is_eva_student_works.map(&:id)).count -
|
||||
# user.student_works_scores.where(:reviewer_role => 3, :student_work_id => is_eva_student_works.map(&:id)).group_by(&:student_work_id).count
|
||||
# un_evaluation_work_num = un_evaluation_work_num < 0 ? 0 : un_evaluation_work_num
|
||||
# appeal_num = user.student_works_scores.where(:student_work_id => student_works.map(&:id), :appeal_status => 3).count
|
||||
# average_score = user.student_works.where(:id => student_works.map(&:id)).select("AVG(student_works.work_score) as score").first ? user.student_works.where(:id => student_works.map(&:id)).select("AVG(student_works.work_score) as score").first.score : 0
|
||||
# total_score = user.student_works.where(:id => student_works.map(&:id)).select("SUM(student_works.work_score) as score").first ? user.student_works.where(:id => student_works.map(&:id)).select("SUM(student_works.work_score) as score").first.score : 0
|
||||
# CourseHomeworkStatistics.create(:course_id => course.id, :user_id => user.id, :committed_work_num => committed_work_num, :un_commit_work_num => un_commit_work_num,
|
||||
# :late_commit_work_num => late_commit_work_num, :absence_evaluation_work_num => absence_evaluation_work_num, :un_evaluation_work_num => un_evaluation_work_num,
|
||||
# :appeal_num => appeal_num, :average_score => average_score, :total_score => total_score)
|
||||
# end
|
||||
end
|
||||
|
||||
def delete_course_homework_statistic
|
||||
|
|
@ -74,23 +83,23 @@ class StudentsForCourse < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def create_course_contribute_score
|
||||
ccs = CourseContributorScore.where("course_id =? and user_id =?", self.course_id, self.student_id).first
|
||||
unless ccs
|
||||
course = self.course
|
||||
user_id = self.student_id
|
||||
message_num = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{user_id} and me.parent_id is null;").count
|
||||
message_reply_num = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{user_id} and me.parent_id is not null").count
|
||||
news_reply_num = Comment.find_by_sql("select cm.* from comments cm, news n where cm.author_id = #{user_id} and n.course_id = #{course.id} and cm.commented_id = n.id and cm.commented_type ='News'").count
|
||||
|
||||
resource_num = Attachment.find_by_sql("SELECT * FROM `attachments` where container_id = #{course.id} and author_id = #{user_id} and container_type ='Course'").count
|
||||
journal_num = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =?", user_id, course.id, "Course").count
|
||||
journal_reply_num = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =? and m_parent_id is not null", user_id, course.id, "Course").count
|
||||
homework_ids = course.homework_commons.empty? ? "(-1)" : "(" + course.homework_commons.map(&:id).join(',') + ")"
|
||||
homework_journal_num = JournalsForMessage.where("user_id =? and jour_id in #{homework_ids} and jour_type =?", user_id, "HomeworkCommon").count
|
||||
news_num = News.where("author_id = #{user_id} and course_id =#{course.id}").count
|
||||
total = message_num*2 + message_reply_num*1 + news_reply_num*1 + news_num*1 + resource_num*5 + journal_num*1 + homework_journal_num*1
|
||||
CourseContributorScore.create(:course_id => self.course_id, :user_id => self.student_id, :message_num => message_num, :message_reply_num => message_reply_num, :news_reply_num => news_reply_num,
|
||||
:resource_num => resource_num, :journal_num => journal_num, :journal_reply_num => journal_reply_num, :total_score => total, :homework_journal_num => homework_journal_num, :news_num => news_num)
|
||||
end
|
||||
# ccs = CourseContributorScore.where("course_id =? and user_id =?", self.course_id, self.student_id).first
|
||||
# unless ccs
|
||||
# course = self.course
|
||||
# user_id = self.student_id
|
||||
# message_num = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{user_id} and me.parent_id is null;").count
|
||||
# message_reply_num = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{user_id} and me.parent_id is not null").count
|
||||
# news_reply_num = Comment.find_by_sql("select cm.* from comments cm, news n where cm.author_id = #{user_id} and n.course_id = #{course.id} and cm.commented_id = n.id and cm.commented_type ='News'").count
|
||||
#
|
||||
# resource_num = Attachment.find_by_sql("SELECT * FROM `attachments` where container_id = #{course.id} and author_id = #{user_id} and container_type ='Course'").count
|
||||
# journal_num = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =?", user_id, course.id, "Course").count
|
||||
# journal_reply_num = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =? and m_parent_id is not null", user_id, course.id, "Course").count
|
||||
# homework_ids = course.homework_commons.empty? ? "(-1)" : "(" + course.homework_commons.map(&:id).join(',') + ")"
|
||||
# homework_journal_num = JournalsForMessage.where("user_id =? and jour_id in #{homework_ids} and jour_type =?", user_id, "HomeworkCommon").count
|
||||
# news_num = News.where("author_id = #{user_id} and course_id =#{course.id}").count
|
||||
# total = message_num*2 + message_reply_num*1 + news_reply_num*1 + news_num*1 + resource_num*5 + journal_num*1 + homework_journal_num*1
|
||||
# CourseContributorScore.create(:course_id => self.course_id, :user_id => self.student_id, :message_num => message_num, :message_reply_num => message_reply_num, :news_reply_num => news_reply_num,
|
||||
# :resource_num => resource_num, :journal_num => journal_num, :journal_reply_num => journal_reply_num, :total_score => total, :homework_journal_num => homework_journal_num, :news_num => news_num)
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
class Subject < ActiveRecord::Base
|
||||
#status :0 编辑中 1 审核中 2 发布
|
||||
belongs_to :user
|
||||
belongs_to :course_list
|
||||
belongs_to :major
|
||||
attr_accessible :description, :name, :status, :visits, :user_id, :course_list_id, :major_id
|
||||
|
||||
has_many :stages, :dependent => :destroy, :order => "stages.id ASC"
|
||||
has_many :stage_shixuns, :dependent => :destroy
|
||||
|
||||
def subject_challenges
|
||||
count = 0
|
||||
self.stage_shixuns.each do |stage_shixun|
|
||||
shixun = stage_shixun.shixun
|
||||
count += shixun.challenges.count
|
||||
end
|
||||
count
|
||||
end
|
||||
|
||||
def subject_score
|
||||
score = 0
|
||||
self.stage_shixuns.each do |stage_shixun|
|
||||
shixun = stage_shixun.shixun
|
||||
score += shixun.shixun_score
|
||||
end
|
||||
score
|
||||
end
|
||||
end
|
||||
|
|
@ -20,6 +20,7 @@ class Syllabus < ActiveRecord::Base
|
|||
|
||||
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
|
||||
|
|
@ -28,7 +29,8 @@ class Syllabus < ActiveRecord::Base
|
|||
has_one :praise_tread_cache, as: :object, dependent: :destroy
|
||||
belongs_to :discipline_category
|
||||
belongs_to :first_level_discipline
|
||||
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
|
||||
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
|
||||
|
|
@ -90,6 +92,10 @@ class Syllabus < ActiveRecord::Base
|
|||
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)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
# encoding: utf-8
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
|
|
@ -86,7 +87,9 @@ class User < Principal
|
|||
# ['all', :label_user_mail_option_all],
|
||||
# ['none', :label_user_mail_option_none]
|
||||
# ]
|
||||
|
||||
# has_many :users_authenticationses
|
||||
# has_many :authentications, :through => :users_authenticationses
|
||||
has_and_belongs_to_many :authentications, :order => "#{Authentication.table_name}.level"
|
||||
has_many :homework_users
|
||||
has_many :homework_attaches, :through => :homework_users
|
||||
has_many :homework_evaluations
|
||||
|
|
@ -124,9 +127,12 @@ class User < Principal
|
|||
has_many :contestant_work_scores
|
||||
has_many :contestant_work_projects
|
||||
|
||||
has_many :shixuns, :through => :shixun_members
|
||||
has_many :shixun_members, :dependent => :destroy
|
||||
has_many :challenges, :dependent => :destroy
|
||||
|
||||
has_many :subjects
|
||||
|
||||
has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)},
|
||||
:after_remove => Proc.new {|user, group| group.user_removed(user)}
|
||||
has_many :changesets, :dependent => :nullify
|
||||
|
|
@ -196,9 +202,13 @@ class User < Principal
|
|||
#####
|
||||
has_many :shares ,:dependent => :destroy
|
||||
|
||||
###
|
||||
has_many :apply_actions, :dependent => :destroy
|
||||
|
||||
has_one :user_wechat
|
||||
|
||||
has_one :sso
|
||||
has_many :apply_user_authentication
|
||||
|
||||
# add by zjc
|
||||
has_one :level, :class_name => 'UserLevels', :dependent => :destroy
|
||||
|
|
@ -251,6 +261,7 @@ class User < Principal
|
|||
validates_presence_of :login, :if => Proc.new { |user| !user.is_a?(AnonymousUser) }
|
||||
validates_uniqueness_of :login, :if => Proc.new { |user| user.login_changed? && user.login.present? }, :case_sensitive => false
|
||||
validates_uniqueness_of :mail, :if => Proc.new { |user| user.mail_changed? && user.mail.present? }, :case_sensitive => false
|
||||
validates_uniqueness_of :phone, :if => Proc.new { |user| user.phone_changed? && user.phone.present? }, :case_sensitive => false
|
||||
# Login must contain letters, numbers, underscores only
|
||||
validates_format_of :login, :with => /\A[a-z0-9_\-\.]*\z/i
|
||||
validates_length_of :login, :maximum => LOGIN_LENGTH_LIMIT
|
||||
|
|
@ -474,8 +485,17 @@ class User < Principal
|
|||
end
|
||||
|
||||
def show_name
|
||||
if self.show_realname
|
||||
name = lastname + firstname
|
||||
else
|
||||
name = nickname
|
||||
end
|
||||
name.blank? ? login : name
|
||||
end
|
||||
|
||||
def show_real_name
|
||||
name = lastname + firstname
|
||||
name.empty? || name.nil? ? login : name
|
||||
name.blank? ? login : name
|
||||
end
|
||||
|
||||
def show_occupation
|
||||
|
|
@ -537,6 +557,18 @@ class User < Principal
|
|||
self.read_attribute(:identity_url)
|
||||
end
|
||||
|
||||
# 判断用户的身份
|
||||
def identity
|
||||
ue = self.user_extensions
|
||||
unless ue.blank?
|
||||
if ue.technical_title.blank?
|
||||
ue.identity == 0 ? "老师" : (ue.identity == 1 ? "学生" : "专业人士")
|
||||
else
|
||||
result = ue.technical_title
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
|
||||
VALID_PHONE_REGEX = /^1\d{10}$/
|
||||
# VALID_EMAIL_REGEX = /^[0-9a-zA-Z_-]+@[0-9a-zA-Z_-]+(\.[0-9a-zA-Z_-]+)+$/
|
||||
|
|
@ -625,10 +657,6 @@ class User < Principal
|
|||
end
|
||||
end
|
||||
|
||||
def nickname(formatter = nil)
|
||||
login.nil? || (login && login.empty?) ? "AnonymousUser" : login
|
||||
end
|
||||
|
||||
def name(formatter = nil)
|
||||
login
|
||||
end
|
||||
|
|
@ -845,6 +873,10 @@ class User < Principal
|
|||
!logged?
|
||||
end
|
||||
|
||||
def system_authentication?
|
||||
self.authentication.blank? ? false : true
|
||||
end
|
||||
|
||||
# Returns user's membership for the given project
|
||||
# or nil if the user is not a member of project
|
||||
def membership(project)
|
||||
|
|
@ -912,9 +944,15 @@ class User < Principal
|
|||
projects.to_a.include?(project)
|
||||
end
|
||||
|
||||
# 超级管理员或者创建者
|
||||
def manager_of_subject?(subject)
|
||||
(subject.user == User.current || User.current.admin?) ? true : false
|
||||
end
|
||||
|
||||
|
||||
# 超级管理员或者role为1
|
||||
def manager_of_shixun?(shixun)
|
||||
member = ShixunMember.where(:user_id => self.id, :shixun_id => shixun, :role => 1)
|
||||
member = ShixunMember.where(:user_id => self.id, :shixun_id => shixun, :role => [1,2])
|
||||
(!member.blank? || User.current.admin?) ? true : false
|
||||
end
|
||||
|
||||
|
|
@ -1086,6 +1124,17 @@ class User < Principal
|
|||
end
|
||||
end
|
||||
|
||||
#是否是老师(不包括助教)
|
||||
def teacher_of_course(course)
|
||||
member = course.members.where("user_id = #{self.id}").first
|
||||
if !member.nil?
|
||||
role = MemberRole.where("member_id = #{member.id} and role_id in (3, 9)")
|
||||
!role.blank?
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
#是否具有老师角色
|
||||
def has_teacher_role(course)
|
||||
member = course.members.where("user_id = #{self.id}").first
|
||||
|
|
@ -1210,7 +1259,8 @@ class User < Principal
|
|||
'custom_fields',
|
||||
'identity_url',
|
||||
'phone',
|
||||
'authentication'
|
||||
'authentication',
|
||||
'nickname'
|
||||
|
||||
safe_attributes 'status',
|
||||
'auth_source_id',
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
class Webssh < ActiveRecord::Base
|
||||
attr_accessible :host, :myshixun_id, :password, :port, :username
|
||||
belongs_to :myshixun
|
||||
end
|
||||
|
|
@ -110,7 +110,7 @@ class CoursesService
|
|||
|
||||
#双重身份 学生列表中不显示
|
||||
# unless (params[:role] == '2' && role_ids.length >= 2)
|
||||
users << {:id => m.user.id, :img_url => img_url, :nickname => m.user.login, :gender => gender,
|
||||
users << {:id => m.user.id, :img_url => img_url, :nickname => m.user.nickname, :gender => gender,
|
||||
:work_unit => work_unit, :mail => m.user.mail, :location => location,
|
||||
role_name: m.roles.first.name,
|
||||
name: m.user.show_name,
|
||||
|
|
@ -138,7 +138,7 @@ class CoursesService
|
|||
work_unit = get_user_work_unit user
|
||||
location = get_user_location user
|
||||
roles_ids = m.content.split(",")
|
||||
reviewers << {:id => user.id, :img_url => img_url, :nickname => user.login, :gender => gender,
|
||||
reviewers << {:id => user.id, :img_url => img_url, :nickname => user.nickname, :gender => gender,
|
||||
:work_unit => work_unit, :mail => user.mail, :location => location,
|
||||
role_name: "",
|
||||
name: user.show_name,
|
||||
|
|
@ -168,7 +168,7 @@ class CoursesService
|
|||
work_unit = get_user_work_unit user
|
||||
location = get_user_location user
|
||||
roles_ids = messages.content.split(",")
|
||||
info = {:id => user.id, :img_url => img_url, :nickname => user.login, :gender => gender,
|
||||
info = {:id => user.id, :img_url => img_url, :nickname => user.nickname, :gender => gender,
|
||||
:work_unit => work_unit, :mail => user.mail, :location => location,
|
||||
role_name: "",
|
||||
name: user.show_name,
|
||||
|
|
@ -370,7 +370,7 @@ class CoursesService
|
|||
#@course.setup_time = params[:setup_time]
|
||||
#@course.endup_time = params[:endup_time]
|
||||
@course.class_period = params[:period].to_i if params[:period]
|
||||
@course.credit = params[:credit].to_i if params[:credit]
|
||||
@course.credit = params[:credit] if params[:credit]
|
||||
@course.end_date = params[:end_date] if params[:end_date]
|
||||
params[:course][:is_public] ? @course.is_public = 1 : @course.is_public = 0
|
||||
@course.open_student = 0
|
||||
|
|
@ -430,7 +430,7 @@ class CoursesService
|
|||
#course.end_time = params[:end_time]
|
||||
#course.end_term = params[:end_term]
|
||||
course.class_period = params[:period].to_i if params[:period]
|
||||
course.credit = params[:credit].to_i if params[:credit]
|
||||
course.credit = params[:credit] if params[:credit]
|
||||
course.end_date = params[:end_date] if params[:end_date]
|
||||
params[:course][:is_public] ? course.is_public = 1 : course.is_public = 0
|
||||
if course.save
|
||||
|
|
|
|||
|
|
@ -215,7 +215,7 @@ class ProjectsService
|
|||
gender = user.user_extensions.gender.nil? ? 0 : user.user_extensions.gender
|
||||
work_unit = get_user_work_unit user
|
||||
location = get_user_location user
|
||||
review_members << {:id => user.id, :img_url => img_url, :nickname => user.login, :gender => gender,
|
||||
review_members << {:id => user.id, :img_url => img_url, :nickname => user.nickname, :gender => gender,
|
||||
:work_unit => work_unit, :mail => user.mail, :location => location,
|
||||
role_name: "",
|
||||
name: user.show_name,
|
||||
|
|
@ -244,7 +244,7 @@ class ProjectsService
|
|||
gender = user.user_extensions.gender.nil? ? 0 : user.user_extensions.gender
|
||||
work_unit = get_user_work_unit user
|
||||
location = get_user_location user
|
||||
info = {:id => user.id, :img_url => img_url, :nickname => user.login, :gender => gender,
|
||||
info = {:id => user.id, :img_url => img_url, :nickname => user.nickname, :gender => gender,
|
||||
:work_unit => work_unit, :mail => user.mail, :location => location,
|
||||
role_name: "",
|
||||
name: user.show_name,
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ class UsersService
|
|||
gender = @user.user_extensions.gender.nil? ? 0 : @user.user_extensions.gender
|
||||
work_unit = get_user_work_unit @user
|
||||
location = get_user_location @user
|
||||
{:id => @user.id, :img_url => img_url,:realname => @user.realname, :nickname => @user.login, :gender => gender, :work_unit => work_unit, :mail => @user.mail, :location => location, :brief_introduction => @user.user_extensions.brief_introduction}
|
||||
{:id => @user.id, :img_url => img_url,:realname => @user.realname, :nickname => @user.nickname, :gender => gender, :work_unit => work_unit, :mail => @user.mail, :location => location, :brief_introduction => @user.user_extensions.brief_introduction}
|
||||
end
|
||||
|
||||
#忘记密码
|
||||
|
|
|
|||
|
|
@ -55,18 +55,5 @@
|
|||
}
|
||||
});
|
||||
|
||||
function submit_user_emails(){
|
||||
if($mail_correct == false){
|
||||
return
|
||||
}else{
|
||||
$.get('<%= account_change_email_path(:user_id => @user.id) %>',
|
||||
{ valid: "mail",
|
||||
value: document.getElementById("user_mail").value },
|
||||
function (data){
|
||||
$("#user_email_show").html(data.email);
|
||||
hideModal();
|
||||
return;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
|
@ -5,13 +5,28 @@
|
|||
已认证
|
||||
<% end %>
|
||||
</div>
|
||||
<% if false %>
|
||||
<%= render :partial => "welcome/one_btn_mask_pop",
|
||||
:locals => {
|
||||
:tip1 => "更多功能,需要经过管理员的授权审核",
|
||||
:tip2 => "认证申请已提交,我们将在1个工作日内完成审核",
|
||||
:btn => "试用申请",
|
||||
:url => "javascript:void(0);"
|
||||
}
|
||||
%>
|
||||
<% end %>
|
||||
<div class="mr15 ml50">
|
||||
<div class="clearfix ml50 mb30 mt30">
|
||||
<div class="user-liucheng fl <%= @user.authentication ? 'user-liucheng-grey' : '' %>">1.上传图片</div>
|
||||
<div class="task-arrow-right fl mr10 <%= @user.authentication ? 'task-arrow-right-grey' : '' %>"></div>
|
||||
<div class="user-liucheng fl <%= @user.authentication ? '' : 'user-liucheng-grey' %>">2.审核并完成认证</div>
|
||||
<div class="task-arrow-right fl <%= @user.authentication ? '' : 'task-arrow-right-grey' %>"></div>
|
||||
<div class="user-liucheng fl">1.上传图片</div>
|
||||
<% if !@user.authentication %>
|
||||
<div class="task-arrow-right task-arrow-right02 fl"></div>
|
||||
<div class="user-liucheng fl user-liucheng-grey">2.审核并完成认证</div>
|
||||
<% else %>
|
||||
<div class="task-arrow-right fl"></div>
|
||||
<div class="user-liucheng user-liucheng-bgblue fl">2.审核并完成认证</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class=" ml50 clearfix mb30">
|
||||
<span class="fl font-16 font-bd">职业证明:</span>
|
||||
<div class="fl font-12" >
|
||||
|
|
@ -61,4 +76,4 @@
|
|||
</div>
|
||||
<a href="javascript:void(0);" class="task-btn task-btn-grey fr" disabled style="margin-right:100px;">提交认证申请</a>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,29 +1,29 @@
|
|||
<%= stylesheet_link_tag 'css/public'%>
|
||||
<!--<div class="homepageContentContainer mb20" >-->
|
||||
<div class="homepageContent BgBox mt10">
|
||||
<h2 class="BgBox_h2">Trustie服务协议</h2>
|
||||
<h2 class="BgBox_h2">服务协议</h2>
|
||||
<div class="AgreementBox">
|
||||
<p>尊敬的用户,您好!<br />
|
||||
欢迎使用Trustie平台,在您使用Trustie平台前,请您认真阅读并遵守《Trustie服务协议》(以下简称"本协议"),请您务必审慎阅读、充分理解协议的各条款内容。<br />
|
||||
当您在注册过程中点击查看"看过并同意本服务协议",按照注册流程成功注册为Trustie平台的用户即表示您已充分阅读、理解并完全接受本协议中的全部条款。您承诺接受并遵守本协议的约定,届时您不应以未阅读本协议的内容等理由,主张本协议无效或本协议中的某些条款无效,或要求撤销本协议。</p>
|
||||
<h4 class="Agreementh4">一、Trustie平台权利和义务</h4>
|
||||
<p>1、尊重用户隐私:尊重用户隐私,保障用户隐私安全是Trustie平台的一项基本政策;<br />
|
||||
2、管理平台用户:Trustie平台依据国家法律、地方法律和国际法律等的标准以及本行业的规则来管理平台注册用户;<br />
|
||||
3、处理用户反馈:Trustie平台的相关人员会及时处理用户反馈的问题并给予及时回复。</p>
|
||||
欢迎使用本网站,在您使用本网站前,请您认真阅读并遵守《服务协议》(以下简称"本协议"),请您务必审慎阅读、充分理解协议的各条款内容。<br />
|
||||
当您在注册过程中点击查看"看过并同意本服务协议",按照注册流程成功注册为网站的用户即表示您已充分阅读、理解并完全接受本协议中的全部条款。您承诺接受并遵守本协议的约定,届时您不应以未阅读本协议的内容等理由,主张本协议无效或本协议中的某些条款无效,或要求撤销本协议。</p>
|
||||
<h4 class="Agreementh4">一、本网站权利和义务</h4>
|
||||
<p>1、尊重用户隐私:尊重用户隐私,保障用户隐私安全是网站的一项基本政策;<br />
|
||||
2、管理网站用户:网站依据国家法律、地方法律和国际法律等的标准以及本行业的规则来管理网站注册用户;<br />
|
||||
3、处理用户反馈:网站的相关人员会及时处理用户反馈的问题并给予及时回复。</p>
|
||||
<h4 class="Agreementh4">二、用户权利和义务</h4>
|
||||
<p>用户在使用Trustie平台的过程中,必须遵守如下原则:<br />
|
||||
<p>用户在使用网站的过程中,必须遵守如下原则:<br />
|
||||
1、遵守中国的有关法律和法规;<br />
|
||||
2、使用网络服务不作非法用途;<br />
|
||||
3、不干扰和混乱网络服务;<br />
|
||||
4、遵守所有使用网络服务的网络协议、规定、程序和惯例;<br />
|
||||
5、不传输任何非法的、骚扰性的、中伤他人的、辱骂性的、恐吓性的、伤害性的、庸俗的,淫秽等信息资料;<br />
|
||||
6、不传输任何教唆他人构成犯罪行为的资料;<br />
|
||||
7、用户不得故意或者过失损害Trustie平台合法权利和利益。及时回复。</p>
|
||||
7、用户不得故意或者过失损害网站合法权利和利益。及时回复。</p>
|
||||
<h4 class="Agreementh4">三、关于责任</h4>
|
||||
<p>鉴于网络服务的特殊性,用户同意Trustie团队有权在事先通知的情况下,变更、中断、升级部分网络服务。Trustie团队不担保网络服务不会中断,但承诺在用户可承受的时间内快速恢复服务,同时确保用户数据的安全性和可靠性。</p>
|
||||
<p>鉴于网络服务的特殊性,本网站有权在事先通知的情况下,变更、中断、升级部分网络服务。本网站不担保网络服务不会中断,但承诺在用户可承受的时间内快速恢复服务,同时确保用户数据的安全性和可靠性。</p>
|
||||
<h4 class="Agreementh4">四、服务条款的修改</h4>
|
||||
<p>Trustie团队保留在必要时对本协议修改的权利,一旦发生变动,这些条款可由Trustie团队及时更新,且毋须另行通知,修改后的条款一旦在网页上公布即有效代替原来的服务条款。您可随时查阅最新版服务条款。</p>
|
||||
<p class=" mt15 fb">本协议最终解释权归Trustie团队所有。</p>
|
||||
<p>本网站保留在必要时对本协议修改的权利,一旦发生变动,这些条款可由网站项目组及时更新,且毋须另行通知,修改后的条款一旦在网页上公布即有效代替原来的服务条款。您可随时查阅最新版服务条款。</p>
|
||||
<p class=" mt15 fb">本协议最终解释权归本网站所有。</p>
|
||||
</div>
|
||||
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue