Merge branch 'yuanke' of https://git.trustie.net/jacknudt/trustieforge into yuanke
Conflicts: db/schema.rb
This commit is contained in:
commit
f7942e4d3c
|
@ -0,0 +1 @@
|
|||
{"access_token":"b_Pc60Dd5eyg_ut3cHbsjQO9EJJdj2Qj5F99o9LH9ltKSme7_FZ3Of22lWLL-K2V0siWzv-bd9PO0Dn-L1PBvIy9LhXa0qPVaFl6vTtZHR2kA8qjo1ps2ancya0t7KmzURGbAFAAXM","expires_in":7200,"got_token_at":1467976842}
|
|
@ -7,6 +7,7 @@
|
|||
/config/configuration.yml
|
||||
/config/additional_environment.rb
|
||||
|
||||
|
||||
/files/*
|
||||
/log/*
|
||||
/public/tmp/*
|
||||
|
@ -30,3 +31,8 @@ vendor/cache
|
|||
/public/files
|
||||
/tags
|
||||
/config/initializers/gitlab_config.rb
|
||||
1234567
|
||||
public/javascripts/wechat/node_modules/
|
||||
.ruby-version
|
||||
.access_token
|
||||
tmux*.log
|
||||
|
|
25
Client.html
25
Client.html
|
@ -1,25 +0,0 @@
|
|||
<html>
|
||||
|
||||
<head>
|
||||
<title>
|
||||
Client
|
||||
</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<hr />
|
||||
<h2>这是一张图片</h2>
|
||||
<p>photo<a href="http://10.0.47.15:3000/shares/new?access_token='2d3dda45dsd'&comment='verygood'&title=davide&share_type=1&url=http://www.baidu.com"> Share A </a></p>
|
||||
<hr />
|
||||
|
||||
<h2>这是一段视频</h2>
|
||||
<p>Text<a href="http://10.0.47.15:3000/shares/new?access_token=2d3dda45dsd&comment=verygood&title=kaka&share_type=2&url=http://www.sina.com"> Share B </a></p>
|
||||
<hr />
|
||||
|
||||
<h2>这是一篇文章</h2>
|
||||
<p>Text<a href="http://10.0.47.15:3000/shares/new?access_token=2d3dda45dsd&comment=verygood&title=pepe&share_type=3&url=http://www.sina.com"> Share C </a></p>
|
||||
<hr />
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
24
Gemfile
24
Gemfile
|
@ -1,11 +1,20 @@
|
|||
source 'https://ruby.taobao.org'
|
||||
#source 'http://ruby.sdutlinux.org/'
|
||||
source 'https://ruby.taobao.org/'
|
||||
|
||||
unless RUBY_PLATFORM =~ /w32/
|
||||
# unix-like only
|
||||
gem 'iconv'
|
||||
if RUBY_PLATFORM =~ /darwin/
|
||||
gem "rmagick", "= 2.15.4" ## osx must be this version
|
||||
elsif RUBY_PLATFORM =~ /linux/
|
||||
#gem "rmagick", "= 2.13.1" ## centos yum install ImageMagick-devel
|
||||
end
|
||||
gem 'certified'
|
||||
gem 'net-ssh', '2.9.1'
|
||||
gem 'jenkins_api_client'
|
||||
gem 'nokogiri'
|
||||
end
|
||||
|
||||
gem 'wechat',path: 'lib/wechat'
|
||||
gem 'grack', path:'lib/grack'
|
||||
gem 'gitlab', path: 'lib/gitlab-cli'
|
||||
gem 'rest-client'
|
||||
|
@ -16,8 +25,9 @@ gem 'delayed_job_active_record'#, :group => :production
|
|||
gem 'daemons'
|
||||
gem 'grape', '~> 0.9.0'
|
||||
gem 'grape-entity'
|
||||
gem 'rack-cors', :require => 'rack/cors'
|
||||
gem 'seems_rateable', '~> 1.0.13'
|
||||
gem "rails", "~> 3.2.13"
|
||||
gem 'rails', '~> 3.2'
|
||||
gem "jquery-rails", "~> 2.0.2"
|
||||
gem "i18n", "~> 0.6.0"
|
||||
gem 'coderay', '~> 1.1.0'
|
||||
|
@ -27,7 +37,6 @@ gem 'acts-as-taggable-on', '2.4.1'
|
|||
gem 'spreadsheet'
|
||||
gem 'ruby-ole'
|
||||
gem 'rails_kindeditor',path:'lib/rails_kindeditor'
|
||||
#gem "rmagick", ">= 2.0.0"
|
||||
gem 'binding_of_caller'
|
||||
gem 'chinese_pinyin'
|
||||
# gem 'sunspot_rails', '~> 1.3.3'
|
||||
|
@ -40,9 +49,14 @@ gem 'kaminari'
|
|||
gem 'elasticsearch-model'
|
||||
gem 'elasticsearch-rails'
|
||||
|
||||
|
||||
### profile
|
||||
#gem 'oneapm_rpm'
|
||||
|
||||
group :development do
|
||||
gem 'grape-swagger'
|
||||
gem 'better_errors', '~> 1.1.0'
|
||||
# gem "query_reviewer"
|
||||
gem 'rack-mini-profiler', '~> 0.9.3'
|
||||
if RUBY_PLATFORM =~ /w32/
|
||||
gem 'win32console'
|
||||
|
@ -72,7 +86,7 @@ group :assets do
|
|||
gem 'coffee-rails', '~> 3.2.1'
|
||||
|
||||
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
||||
gem 'therubyracer', :platforms => :ruby
|
||||
# gem 'therubyracer', :platforms => :ruby
|
||||
|
||||
gem 'uglifier', '>= 1.0.3'
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
require_relative 'middleware/error_handler'
|
||||
require_relative 'apis/auth'
|
||||
|
@ -7,10 +9,23 @@ module Mobile
|
|||
require_relative 'apis/upgrade'
|
||||
require_relative 'apis/homeworks'
|
||||
require_relative 'apis/comments'
|
||||
require_relative 'apis/issues'
|
||||
require_relative 'apis/activities'
|
||||
require_relative 'apis/whomeworks'
|
||||
require_relative 'apis/newss'
|
||||
require_relative 'apis/journal_for_messages'
|
||||
require_relative 'apis/messages'
|
||||
require_relative 'apis/blog_comments'
|
||||
require_relative 'apis/new_comment'
|
||||
require_relative 'apis/praise'
|
||||
require_relative 'apis/resources'
|
||||
require_relative 'apis/syllabuses'
|
||||
|
||||
class API < Grape::API
|
||||
version 'v1', using: :path
|
||||
format :json
|
||||
content_type :json, "application/json;charset=UTF-8"
|
||||
use ActionDispatch::Session::CookieStore
|
||||
use Mobile::Middleware::ErrorHandler
|
||||
|
||||
helpers do
|
||||
|
@ -19,16 +34,26 @@ module Mobile
|
|||
end
|
||||
|
||||
def authenticate!
|
||||
raise('Unauthorized. Invalid or expired token.') unless current_user
|
||||
raise('Unauthorized. 用户认证失败.') unless current_user
|
||||
end
|
||||
|
||||
def session
|
||||
env['rack.session']
|
||||
end
|
||||
|
||||
def current_user
|
||||
openid = params[:openid]
|
||||
if openid
|
||||
uw = UserWechat.find_by_openid(params[:openid])
|
||||
return uw.user if uw
|
||||
end
|
||||
|
||||
token = ApiKey.where(access_token: params[:token]).first
|
||||
if token && !token.expired?
|
||||
@current_user = User.find(token.user_id)
|
||||
else
|
||||
nil
|
||||
return User.find(token.user_id)
|
||||
end
|
||||
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -39,9 +64,19 @@ module Mobile
|
|||
mount Apis::Upgrade
|
||||
mount Apis::Homeworks
|
||||
mount Apis::Comments
|
||||
mount Apis::Issues
|
||||
mount Apis::Activities
|
||||
mount Apis::Whomeworks
|
||||
mount Apis::Newss
|
||||
mount Apis::JournalForMessages
|
||||
mount Apis::Messages
|
||||
mount Apis::BlogComments
|
||||
mount Apis::NewComment
|
||||
mount Apis::Praise
|
||||
mount Apis::Resources
|
||||
mount Apis::Syllabuses
|
||||
|
||||
#add_swagger_documentation ({api_version: 'v1', base_path: 'http://u06.shellinfo.cn/trustie/api'})
|
||||
#add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development?
|
||||
add_swagger_documentation ({api_version: 'v1', base_path: '/api'}) if Rails.env.development?
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class Activities< Grape::API
|
||||
resources :activities do
|
||||
|
||||
desc "get user activities"
|
||||
|
||||
params do
|
||||
requires :page, type: Integer
|
||||
requires :token, type: String
|
||||
requires :container_type, type: String
|
||||
end
|
||||
post do
|
||||
authenticate!
|
||||
|
||||
user = current_user
|
||||
|
||||
container_type = params[:container_type] ? params[:container_type] : "All"
|
||||
|
||||
if container_type == "All" || container_type == "Project"
|
||||
shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id)
|
||||
user_project_ids = (user.projects.where("status = 1").map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.where("status = 1").map{|project| project.id}-shield_project_ids).join(",") + ")"
|
||||
project_types = "('Message','Issue','Project')"
|
||||
end
|
||||
|
||||
if container_type == "All" || container_type == "Course"
|
||||
shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id)
|
||||
user_course_ids = (user.courses.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")"
|
||||
course_types = "('Message','News','HomeworkCommon','Poll','Course')"
|
||||
end
|
||||
|
||||
page = params[:page] ? params[:page] : 0
|
||||
principal_types = "JournalsForMessage"
|
||||
watched_user_ids = User.watched_by(user.id).count == 0 ? " " : ("," + User.watched_by(user.id).map{|u| u.id.to_s }.join(','))
|
||||
user_ids = "(" + user.id.to_s + watched_user_ids + ")"
|
||||
watched_user_blog_ids = Blog.select("id").where("author_id in #{user_ids}").count == 0 ? " " :Blog.select("id").where("author_id in #{user_ids}").map { |blog| blog.id}.join(",")
|
||||
blog_ids = "(" + watched_user_blog_ids + ")"
|
||||
|
||||
if container_type == "Course"
|
||||
activities = UserActivity.where("(container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})").order('updated_at desc')
|
||||
elsif container_type == "Project"
|
||||
activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})").order('updated_at desc')
|
||||
else
|
||||
activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" +
|
||||
"or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+
|
||||
"or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{user.id}) " +
|
||||
"or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc')
|
||||
end
|
||||
all_count = activities.count
|
||||
activities = activities.limit(10).offset(page * 10)
|
||||
count = activities.count
|
||||
present :data, activities, with: Mobile::Entities::Activity,user: user
|
||||
present :all_count, all_count
|
||||
present :count, count
|
||||
present :page, page
|
||||
present :status, 0
|
||||
present :container_type, container_type
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class BlogComments< Grape::API
|
||||
resources :blog_comments do
|
||||
|
||||
desc "get special topic"
|
||||
get ':id' do
|
||||
user = current_user
|
||||
blog = BlogComment.find params[:id]
|
||||
present :data, blog, with: Mobile::Entities::BlogComment,user: user
|
||||
present :status, 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -115,7 +115,7 @@ module Mobile
|
|||
|
||||
desc '通知评论列表'
|
||||
params do
|
||||
requires :token, type: String
|
||||
#requires :token, type: String
|
||||
requires :notice_id,type:Integer,desc:'通知id'
|
||||
optional :page,type:Integer,desc:'页码'
|
||||
end
|
||||
|
|
|
@ -14,8 +14,9 @@ module Mobile
|
|||
optional :token, type: String
|
||||
end
|
||||
get do
|
||||
authenticate!
|
||||
cs = CoursesService.new
|
||||
courses = cs.course_list(params,current_user.nil? ? User.find(2):current_user)
|
||||
courses = cs.user_courses_list(current_user)
|
||||
present :data, courses, with: Mobile::Entities::Course
|
||||
present :status, 0
|
||||
end
|
||||
|
@ -98,25 +99,19 @@ module Mobile
|
|||
desc "加入课程"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :course_password, type: String
|
||||
requires :invite_code, type: String, desc: '邀请码'
|
||||
end
|
||||
post ":id" do
|
||||
post "join" do
|
||||
authenticate!
|
||||
cs = CoursesService.new
|
||||
status = cs.join_course({:object_id => params[:id],:course_password => params[:course_password]},current_user)
|
||||
out = {status: status[:state]}
|
||||
message = case status[:state]
|
||||
when 0; "加入成功"
|
||||
when 1; "密码错误"
|
||||
when 2; "课程已过期 请联系课程管理员重启课程。(在配置课程处)"
|
||||
when 3; "您已经加入了课程"
|
||||
when 4; "您加入的课程不存在"
|
||||
when 5; "您还未登录"
|
||||
else; "未知错误,请稍后再试"
|
||||
end
|
||||
out.merge(message: message)
|
||||
status = cs.join_course({role: "10", openid: params[:openid], invite_code: params[:invite_code]}, current_user)
|
||||
{
|
||||
status: status[:state],
|
||||
message:CoursesService::JoinCourseError.message(status[:state])
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
desc "退出课程"
|
||||
params do
|
||||
requires :token, type: String
|
||||
|
@ -202,6 +197,7 @@ module Mobile
|
|||
end
|
||||
route_param :id do
|
||||
get do
|
||||
authenticate!
|
||||
cs = CoursesService.new
|
||||
course = cs.show_course(params,(current_user.nil? ? User.find(2):current_user))
|
||||
#course = Course.find(params[:id])
|
||||
|
@ -389,7 +385,33 @@ module Mobile
|
|||
end
|
||||
|
||||
|
||||
desc '获取测验列表'
|
||||
params do
|
||||
requires :token, type:String
|
||||
end
|
||||
get ':course_id/exercises' do
|
||||
authenticate!
|
||||
exercises = Course.find(params[:course_id]).exercises
|
||||
present :data,exercises,with:Mobile::Entities::Exercise
|
||||
present :status,0
|
||||
end
|
||||
|
||||
desc '删除课程'
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
post ':course_id/del' do
|
||||
authenticate!
|
||||
c = Course.find(params[:course_id])
|
||||
# if c.members.count > 1
|
||||
# {status: -1, message: '已经有成员加入,不能删除'}
|
||||
# else
|
||||
c.delete!
|
||||
present :status,0
|
||||
# end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class Issues< Grape::API
|
||||
resources :issues do
|
||||
include IssuesHelper
|
||||
|
||||
desc "get special issuse"
|
||||
get ':id' do
|
||||
authenticate!
|
||||
user = current_user
|
||||
issue = Issue.find params[:id]
|
||||
present :data, issue, with: Mobile::Entities::Issue,user: user
|
||||
present :status, 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class JournalForMessages< Grape::API
|
||||
resources :journal_for_messages do
|
||||
|
||||
desc "get special journal"
|
||||
get ':id' do
|
||||
authenticate!
|
||||
user = current_user
|
||||
jour = JournalsForMessage.find params[:id]
|
||||
present :data, jour, with: Mobile::Entities::Jours,user: user
|
||||
present :status, 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class Messages< Grape::API
|
||||
resources :messages do
|
||||
|
||||
desc "get special topic"
|
||||
get ':id' do
|
||||
authenticate!
|
||||
user = current_user
|
||||
message = Message.find params[:id]
|
||||
present :data, message, with: Mobile::Entities::Message,user: user
|
||||
present :status, 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,105 @@
|
|||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class NewComment< Grape::API
|
||||
include ApplicationHelper
|
||||
include ApiHelper
|
||||
resources :new_comment do
|
||||
|
||||
desc "add a new comment"
|
||||
params do
|
||||
requires :type, type: String
|
||||
requires :content, type: String
|
||||
requires :token, type: String
|
||||
end
|
||||
post ':id' do
|
||||
authenticate!
|
||||
type = params[:type]
|
||||
result = 1
|
||||
if params[:content]!="" && current_user
|
||||
case type
|
||||
when "HomeworkCommon"
|
||||
homework_common = HomeworkCommon.find(params[:id])
|
||||
feedback = HomeworkCommon.add_homework_jour(current_user, params[:content], params[:id])
|
||||
if (feedback.errors.empty?)
|
||||
homework_common.update_column(:updated_at, Time.now)
|
||||
result = 2
|
||||
end
|
||||
when "News"
|
||||
news = News.find(params[:id])
|
||||
comment = Comment.new
|
||||
comment.comments = params[:content]
|
||||
comment.author = current_user
|
||||
if news.comments << comment
|
||||
result = 2
|
||||
end
|
||||
when "Message"
|
||||
message = Message.find(params[:id])
|
||||
board = Board.find(message.board_id)
|
||||
topic = message.root
|
||||
reply = Message.new
|
||||
reply.author = current_user
|
||||
reply.board = board
|
||||
reply.content = params[:content]
|
||||
reply.parent_id = params[:id]
|
||||
reply.subject = "RE: #{topic.subject}"
|
||||
if topic.children << reply
|
||||
result = 2
|
||||
end
|
||||
when "JournalsForMessage"
|
||||
jour = JournalsForMessage.find params[:id]
|
||||
parent_id = params[:id]
|
||||
author_id = current_user.id
|
||||
reply_user_id = jour.user_id
|
||||
reply_id = params[:id]
|
||||
content = params[:content]
|
||||
options = {:user_id => author_id,
|
||||
:status => true,
|
||||
:m_parent_id => parent_id,
|
||||
:m_reply_id => reply_id,
|
||||
:reply_id => reply_user_id,
|
||||
:notes => content,
|
||||
:is_readed => false}
|
||||
jfm = jour.user.add_jour(nil, nil, nil, options)
|
||||
if jfm.errors.empty?
|
||||
(JournalsForMessage.find parent_id).update_attribute(:updated_on,Time.now)
|
||||
result = 2
|
||||
end
|
||||
when 'Issue'
|
||||
issue = Issue.find params[:id]
|
||||
is_jour = Journal.new
|
||||
is_jour.user_id = current_user.id
|
||||
is_jour.notes = params[:content]
|
||||
is_jour.journalized = issue
|
||||
if is_jour.save
|
||||
result = 2
|
||||
end
|
||||
when 'BlogComment'
|
||||
blog = BlogComment.find(params[:id]).root
|
||||
blogComment = BlogComment.new
|
||||
blogComment.author = current_user
|
||||
blogComment.blog = blog.blog
|
||||
blogComment.content = params[:content]
|
||||
blogComment.title = "RE: #{blog.title}"
|
||||
if blog.children << blogComment
|
||||
result = 2
|
||||
end
|
||||
end
|
||||
if result == 2
|
||||
update_course_activity_api(type,params[:id])
|
||||
update_user_activity_api(type,params[:id])
|
||||
update_org_activity_api(type,params[:id])
|
||||
update_forge_activity_api(type,params[:id])
|
||||
update_principal_activity_api(type,params[:id])
|
||||
end
|
||||
else
|
||||
result = 3
|
||||
end
|
||||
present :result, result
|
||||
present :status, 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class Newss< Grape::API
|
||||
resources :newss do
|
||||
|
||||
desc "get special news"
|
||||
get ':id' do
|
||||
authenticate!
|
||||
user = current_user
|
||||
news = News.find params[:id]
|
||||
present :data, news, with: Mobile::Entities::News,user: user
|
||||
present :status, 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,42 @@
|
|||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class Praise< Grape::API
|
||||
include ApiHelper
|
||||
resources :praise do
|
||||
desc "praise an activity"
|
||||
|
||||
params do
|
||||
requires :type, type: String
|
||||
requires :token, type: String
|
||||
end
|
||||
post ':id' do
|
||||
authenticate!
|
||||
obj_id = params[:id]
|
||||
obj_type = params[:type]
|
||||
user = current_user
|
||||
pts = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",obj_id,obj_type.to_s,user.id).first
|
||||
if pts.blank?
|
||||
praise_or_cancel(obj_type,obj_id,user,1)
|
||||
obj = PraiseTreadCache.where("object_id=? and object_type=?",obj_id,obj_type.to_s).first
|
||||
num = get_activity_praise_num(obj) if !obj.blank?
|
||||
else
|
||||
pts.destroy if !pts.blank?
|
||||
#再更新praise_tread_cache表 使相应的记录减1 当为0时删除
|
||||
ptc = PraiseTreadCache.where("object_id=? and object_type=?",obj_id,obj_type.to_s).first
|
||||
ptc.praise_minus(1) if !ptc.blank?
|
||||
if ptc.praise_num == 0
|
||||
ptc.delete
|
||||
end
|
||||
obj = PraiseTreadCache.where("object_id=? and object_type=?",obj_id,obj_type.to_s).first
|
||||
num = !obj.blank? ? get_activity_praise_num(obj) : 0
|
||||
end
|
||||
|
||||
present :data, num
|
||||
present :status, 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,71 @@
|
|||
#coding=utf-8
|
||||
module Mobile
|
||||
module Apis
|
||||
class Resources < Grape::API
|
||||
|
||||
resource :resources do
|
||||
|
||||
desc '获取所有课件'
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
get do
|
||||
authenticate!
|
||||
data = current_user.course_attachments
|
||||
present :data, data, with: Mobile::Entities::Attachment
|
||||
present :status, 0
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
desc '获取所有作业'
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
get 'homeworks' do
|
||||
authenticate!
|
||||
|
||||
homeworks = current_user.homework_commons
|
||||
|
||||
present :data, homeworks, with: Mobile::Entities::Homework
|
||||
present :status, 0
|
||||
|
||||
end
|
||||
|
||||
desc '获取所有测验'
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
get 'exercies' do
|
||||
authenticate!
|
||||
|
||||
exercises = current_user.exercises
|
||||
present :data, exercises, with: Mobile::Entities::Exercise
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
|
||||
desc '发送资源'
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :course_ids, type: Array[Integer]
|
||||
requires :send_id, type: Integer
|
||||
end
|
||||
post 'send' do
|
||||
authenticate!
|
||||
|
||||
rs = ResourcesService.new
|
||||
ori, flag, save_message = rs.send_resource_to_course(current_user,params)
|
||||
if flag
|
||||
present :status, 0
|
||||
else
|
||||
{status: -1, message: save_message.first}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,103 @@
|
|||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class Syllabuses < Grape::API
|
||||
|
||||
resources :syllabuses do
|
||||
desc "获取大纲列表"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
get do
|
||||
authenticate!
|
||||
|
||||
cs = SyllabusesService.new
|
||||
courses = cs.user_syllabus(current_user)
|
||||
present :data, courses, with: Mobile::Entities::Syllabus
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "获取某个大纲"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
get ':id' do
|
||||
authenticate!
|
||||
|
||||
ss = SyllabusesService.new
|
||||
|
||||
sy = ::Syllabus.find(params[:id])
|
||||
sy.courses = sy.courses.not_deleted
|
||||
sy = ss.judge_can_setting(sy,current_user)
|
||||
|
||||
present :data, sy, with: Mobile::Entities::Syllabus
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
desc "获取新建大纲的权限"
|
||||
params do
|
||||
requires :token, type: String
|
||||
end
|
||||
post 'auth' do
|
||||
authenticate!
|
||||
|
||||
auth = 0
|
||||
|
||||
if (current_user.user_extensions && current_user.user_extensions.identity == 0 && current_user.allowed_to?(:add_course, nil, :global => true))
|
||||
auth = 1
|
||||
end
|
||||
|
||||
present :auth, auth
|
||||
end
|
||||
|
||||
desc "新建大纲"
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :title, type: String, desc: '大纲标题'
|
||||
requires :courses, type: Array[String], desc: '课程名'
|
||||
end
|
||||
post do
|
||||
authenticate!
|
||||
|
||||
ss = SyllabusesService.new
|
||||
|
||||
sy = ss.create(current_user, params[:title],
|
||||
params[:courses].map{|c| {name: c} })
|
||||
|
||||
if sy.new_record?
|
||||
{status:-1, message: '创建大纲失败' }
|
||||
else
|
||||
present :data, sy, with: Mobile::Entities::Syllabus
|
||||
present :status, 0
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
desc '编辑大纲'
|
||||
params do
|
||||
requires :token, type: String
|
||||
requires :title, type: String, desc: '大纲标题'
|
||||
# requires :add_courses, type: Array[String], desc: '课程名'
|
||||
# requires :modify_courses, type: Array[Integer,String], desc: '课程名'
|
||||
end
|
||||
post ':id/edit' do
|
||||
|
||||
authenticate!
|
||||
|
||||
ss = SyllabusesService.new
|
||||
|
||||
#修改课程大纲
|
||||
status = ss.edit(current_user, params)
|
||||
|
||||
if status == -1
|
||||
{status:status, message: '修改课程信息失败' }
|
||||
else
|
||||
present :status, status
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -4,6 +4,48 @@ module Mobile
|
|||
class Users < Grape::API
|
||||
resource :users do
|
||||
|
||||
desc "查询是否已绑定"
|
||||
params do
|
||||
requires :openid, type: String, desc: 'wechat openid'
|
||||
end
|
||||
post 'isbind' do
|
||||
openid = params[:openid]
|
||||
uw = UserWechat.where(openid: openid).first
|
||||
raise "还未绑定trustie帐户" unless uw
|
||||
|
||||
user = uw.user
|
||||
::ApiKey.delete_all(user_id: user.id)
|
||||
key = ::ApiKey.create!(user_id: user.id)
|
||||
present status: 0, token: key.access_token
|
||||
end
|
||||
|
||||
desc "绑定微信用户"
|
||||
params do
|
||||
requires :login, type: String, desc: 'username'
|
||||
requires :password, type: String, desc: 'password'
|
||||
end
|
||||
post 'wxbind' do
|
||||
openid = session[:wechat_openid]
|
||||
logger.debug "openid ============== #{openid}"
|
||||
raise "无法获取到openid,请在微信中打开本页面" unless openid
|
||||
uw = UserWechat.where(openid: openid).first
|
||||
raise "此微信号已绑定用户(#{uw.user.login}), 不能重复绑定" if uw
|
||||
|
||||
user, last_login_on = User.try_to_login(params[:login], params[:password])
|
||||
raise "用户名或密码错误,请重新输入" unless user
|
||||
#补全用户信息
|
||||
|
||||
raise "此用户已经绑定过公众号, 请换一个帐户试试" if user.user_wechat
|
||||
|
||||
UserWechat.create!(
|
||||
openid: openid,
|
||||
user: user
|
||||
)
|
||||
# ws = WechatService.new
|
||||
# ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台", user.login, format_time(Time.now))
|
||||
present status: 0, message: '您已成功绑定Trustie平台'
|
||||
end
|
||||
|
||||
desc "注册用户"
|
||||
params do
|
||||
requires :login, type: String, desc: 'username'
|
||||
|
@ -11,10 +53,20 @@ module Mobile
|
|||
requires :password, type: String, desc: 'password'
|
||||
end
|
||||
post do
|
||||
|
||||
openid = session[:wechat_openid]
|
||||
logger.debug "openid ============== #{openid}"
|
||||
raise "无法获取到openid,请在微信中打开本页面" unless openid
|
||||
|
||||
|
||||
us = UsersService.new
|
||||
user = us.register params.merge(:password_confirmation => params[:password],
|
||||
:should_confirmation_password => true)
|
||||
raise "该邮箱已经被注册过了" if user.new_record?
|
||||
raise user.errors.full_messages.first if user.new_record?
|
||||
UserWechat.create!(
|
||||
openid: openid,
|
||||
user: user
|
||||
)
|
||||
|
||||
present :data, user, with: Mobile::Entities::User
|
||||
present :status, 0
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
#coding=utf-8
|
||||
|
||||
module Mobile
|
||||
module Apis
|
||||
class Whomeworks< Grape::API
|
||||
resources :whomeworks do
|
||||
|
||||
desc "get one homework"
|
||||
get ':id' do
|
||||
authenticate!
|
||||
user = current_user
|
||||
homework = HomeworkCommon.find params[:id]
|
||||
present :data, homework, with: Mobile::Entities::Whomework,user: user
|
||||
present :status, 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,147 @@
|
|||
# encoding: utf-8
|
||||
module Mobile
|
||||
module Entities
|
||||
class Activity <Grape::Entity
|
||||
include ApplicationHelper
|
||||
include ApiHelper
|
||||
def self.act_expose(f)
|
||||
expose f do |ac,opt|
|
||||
if ac.is_a?(Hash) && ac.key?(f)
|
||||
ac[f]
|
||||
elsif ac.is_a?(::UserActivity)
|
||||
if ac.respond_to?(f)
|
||||
ac.send(f)
|
||||
else
|
||||
case f
|
||||
when :user_act
|
||||
if ac.act_type == "Project"
|
||||
ac unless ac.nil?
|
||||
else
|
||||
ac.act unless ac.nil? || ac.act.nil?
|
||||
end
|
||||
when :reply_count
|
||||
if ac.act_type == "HomeworkCommon"
|
||||
ac.nil? || ac.act.nil? ? 0 : ac.act.journals_for_messages.count
|
||||
elsif ac.act_type == "News"
|
||||
ac.nil? || ac.act.nil? ? 0 : ac.act.comments.count
|
||||
elsif ac.act_type == "Message" || ac.act_type == "BlogComment" || ac.act_type == "JournalsForMessage"
|
||||
ac.nil? || ac.act.nil? ? 0 : ac.act.children.count
|
||||
elsif ac.act_type == "Issue"
|
||||
ac.nil? || ac.act.nil? ? 0 : ac.act.journals.where("notes is not null and notes != ''").count
|
||||
end
|
||||
when :subject
|
||||
if ac.act_type == "HomeworkCommon"
|
||||
ac.act.name unless ac.nil? || ac.act.nil?
|
||||
elsif ac.act_type == "News" || ac.act_type == "BlogComment"
|
||||
ac.act.title unless ac.nil? || ac.act.nil?
|
||||
elsif ac.act_type == "Message" || ac.act_type == "Issue"
|
||||
ac.act.subject unless ac.nil? || ac.act.nil?
|
||||
elsif ac.act_type == "JournalsForMessage"
|
||||
ac.act.private == 0 ? "留言" : "私信" unless ac.nil? || ac.act.nil?
|
||||
end
|
||||
when :description
|
||||
if ac.act_type == "HomeworkCommon" || ac.act_type == "Issue" || ac.act_type == "News"
|
||||
strip_html(ac.act.description) unless ac.nil? || ac.act.nil?
|
||||
elsif ac.act_type == "Message" || ac.act_type == "BlogComment"
|
||||
strip_html(ac.act.content) unless ac.nil? || ac.act.nil?
|
||||
elsif ac.act_type == "JournalsForMessage"
|
||||
strip_html(ac.act.notes) unless ac.nil? || ac.act.nil?
|
||||
end
|
||||
when :latest_update
|
||||
time_from_now ac.updated_at unless ac.nil?
|
||||
when :praise_count
|
||||
if ac.act_type == "HomeworkCommon" || ac.act_type == "News" || ac.act_type == "Message" || ac.act_type == "BlogComment" || ac.act_type == "JournalsForMessage" || ac.act_type == "Issue"
|
||||
ac.nil? || ac.act.nil? ? 0 : get_activity_praise_num(ac.act)
|
||||
end
|
||||
#when :homework_common_detail_manual
|
||||
# if ac.act_type == "HomeworkCommon"
|
||||
# ac.act.homework_detail_manual unless ac.nil? || ac.act.nil? || ac.act.homework_detail_manual.nil?
|
||||
# end
|
||||
when :course_project_name
|
||||
if ac.container_type == "Course"
|
||||
name = (get_course(ac.container_id)).name
|
||||
name
|
||||
elsif ac.container_type == "Project"
|
||||
name = (get_project(ac.container_id)).name
|
||||
name
|
||||
elsif ac.container_type == "Blog"
|
||||
"发表博客"
|
||||
end
|
||||
when :activity_type_name
|
||||
if ac.container_type == "Course"
|
||||
case ac.act_type
|
||||
when "HomeworkCommon"
|
||||
"课程作业"
|
||||
when "News"
|
||||
"课程通知"
|
||||
when "Message"
|
||||
"课程问答区"
|
||||
when "Poll"
|
||||
"课程问卷"
|
||||
when "Course"
|
||||
"课程"
|
||||
end
|
||||
elsif ac.container_type == "Project"
|
||||
case ac.act_type
|
||||
when "Issue"
|
||||
"项目问题"
|
||||
when "Message"
|
||||
"项目讨论区"
|
||||
when "Project"
|
||||
"项目"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
expose :act_type #缺陷/作业/讨论区/留言等类型
|
||||
expose :act_id
|
||||
expose :id
|
||||
expose :container_type #课程/项目/博客/个人
|
||||
expose :author, using: Mobile::Entities::User do |a, opt| #用户信息
|
||||
if a.is_a? ::UserActivity
|
||||
if a.act_type == "Project"
|
||||
get_user(get_project(a.act_id).user_id)
|
||||
elsif !a.act.nil?
|
||||
if a.act_type == 'Issue' || a.act_type == 'News' || a.act_type == 'Message' || a.act_type == 'BlogComment'
|
||||
a.act.author
|
||||
elsif a.act_type == 'HomeworkCommon' || a.act_type == 'Poll' || a.act_type == 'JournalsForMessage'
|
||||
a.act.user
|
||||
elsif a.act_type == 'Course'
|
||||
a.act.teacher
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
expose :homework_common_detail , using: Mobile::Entities::Whomework do |a, opt| #作业相关信息
|
||||
if a.act_type == "HomeworkCommon"
|
||||
a.act
|
||||
end
|
||||
end
|
||||
expose :issue_detail, using: Mobile::Entities::Issue do |a, opt| #缺陷信息
|
||||
if a.act_type == "Issue"
|
||||
a.act
|
||||
end
|
||||
end
|
||||
act_expose :reply_count #回复数
|
||||
act_expose :praise_count #点赞数
|
||||
#act_expose :user_act #某个动态
|
||||
act_expose :subject #标题
|
||||
act_expose :description #描述
|
||||
act_expose :latest_update #最新更新时间
|
||||
act_expose :course_project_name #课程/项目名字
|
||||
act_expose :activity_type_name #课程问答区/项目缺陷等
|
||||
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||
if instance.act_type == "HomeworkCommon" || instance.act_type == "News" || instance.act_type == "Message" || instance.act_type == "BlogComment" || instance.act_type == "JournalsForMessage" || instance.act_type == "Issue"
|
||||
has_praise = false
|
||||
current_user = options[:user]
|
||||
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.act_id,instance.act_type.to_s,current_user.id)
|
||||
has_praise = obj.empty? ? false : true
|
||||
has_praise
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,66 @@
|
|||
module Mobile
|
||||
module Entities
|
||||
class BlogComment < Grape::Entity
|
||||
include ApplicationHelper
|
||||
include ApiHelper
|
||||
def self.blog_comment_expose(f)
|
||||
expose f do |u,opt|
|
||||
if u.is_a?(Hash) && u.key?(f)
|
||||
u[f]
|
||||
elsif u.is_a?(::BlogComment)
|
||||
if u.respond_to?(f)
|
||||
if f == :created_at
|
||||
format_time( u.send(f))
|
||||
else
|
||||
u.send(f)
|
||||
end
|
||||
else
|
||||
case f
|
||||
when :praise_count
|
||||
get_activity_praise_num(u)
|
||||
when :lasted_comment
|
||||
time_from_now(u.created_at)
|
||||
when :act_type
|
||||
'BlogComment'
|
||||
when :act_id
|
||||
u.id
|
||||
when :comment_count
|
||||
u.children.count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
expose :user, using: Mobile::Entities::User do |c, opt|
|
||||
if c.is_a?(::BlogComment)
|
||||
c.author
|
||||
end
|
||||
end
|
||||
blog_comment_expose :act_type
|
||||
blog_comment_expose :act_id
|
||||
blog_comment_expose :blog_id
|
||||
blog_comment_expose :title
|
||||
blog_comment_expose :content
|
||||
blog_comment_expose :comment_count
|
||||
blog_comment_expose :created_at
|
||||
blog_comment_expose :lasted_comment
|
||||
blog_comment_expose :id
|
||||
blog_comment_expose :locked
|
||||
blog_comment_expose :praise_count
|
||||
expose :blog_comment_children, using:Mobile::Entities::BlogComment do |c,opt|
|
||||
if c.is_a? (::BlogComment)
|
||||
c.children.reverse
|
||||
end
|
||||
end
|
||||
expose :has_praise, if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||
has_praise = false
|
||||
current_user = options[:user]
|
||||
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id)
|
||||
has_praise = obj.empty? ? false : true
|
||||
has_praise
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -9,7 +9,7 @@ module Mobile
|
|||
elsif f.is_a?(::Comment)
|
||||
if f.respond_to?(field)
|
||||
if field == :created_on
|
||||
format_time(f.send(field))
|
||||
time_from_now(f.send(field))
|
||||
else
|
||||
f.send(field)
|
||||
end
|
||||
|
|
|
@ -15,6 +15,8 @@ module Mobile
|
|||
#f.img_url if f.respond_to?(:img_url)
|
||||
elsif field == :created_at || field == :updated_at
|
||||
(format_time(c[field]) if (c.is_a?(Hash) && c.key?(field))) || (format_time(c.send(field)) if c.respond_to?(field))
|
||||
elsif field == :member_count
|
||||
::Course===c ? c.members.count : 0
|
||||
else
|
||||
(c[field] if (c.is_a?(Hash) && c.key?(field))) || (c.send(field) if c.respond_to?(field))
|
||||
end
|
||||
|
@ -45,8 +47,12 @@ module Mobile
|
|||
course_expose :tea_id
|
||||
course_expose :term
|
||||
course_expose :time
|
||||
course_expose :invite_code
|
||||
course_expose :qrcode
|
||||
course_expose :updated_at
|
||||
course_expose :course_student_num
|
||||
course_expose :member_count
|
||||
course_expose :can_setting
|
||||
expose :teacher, using: Mobile::Entities::User do |c, opt|
|
||||
if c.is_a? ::Course
|
||||
c.teacher
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
module Mobile
|
||||
module Entities
|
||||
class Exercise < Grape::Entity
|
||||
expose :exercise_name
|
||||
expose :exercise_description
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,67 @@
|
|||
module Mobile
|
||||
module Entities
|
||||
class Issue <Grape::Entity
|
||||
include ApiHelper
|
||||
include Redmine::I18n
|
||||
def self.issue_expose(f)
|
||||
expose f do |issue, opt|
|
||||
if issue.is_a?(Hash) && issue.key?(f)
|
||||
issue[f]
|
||||
elsif issue.is_a?(::Issue)
|
||||
if issue.respond_to?(f)
|
||||
if f == :created_on
|
||||
format_time(issue.send(f))
|
||||
else
|
||||
issue.send(f)
|
||||
end
|
||||
else
|
||||
case f
|
||||
when :issue_priority
|
||||
get_issue_priority_api issue.priority_id
|
||||
when :issue_assigned_to
|
||||
(get_user(issue.assigned_to_id)).login
|
||||
when :issue_status
|
||||
IssueStatus.find(issue.status_id).name
|
||||
when :journals_count
|
||||
issue.journals.where("notes is not null and notes != ''").count
|
||||
when :project_name
|
||||
issue.project.name
|
||||
when :praise_count
|
||||
get_activity_praise_num(issue)
|
||||
when :act_type
|
||||
'Issue'
|
||||
when :act_id
|
||||
issue.id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
expose :subject
|
||||
expose :description
|
||||
expose :author, using: Mobile::Entities::User
|
||||
expose :done_ratio
|
||||
issue_expose :act_type
|
||||
issue_expose :act_id
|
||||
issue_expose :created_on
|
||||
issue_expose :issue_priority
|
||||
issue_expose :issue_assigned_to
|
||||
issue_expose :issue_status
|
||||
issue_expose :journals_count
|
||||
issue_expose :project_name
|
||||
issue_expose :praise_count
|
||||
expose :issue_journals, using: Mobile::Entities::Journal do |f, opt|
|
||||
if f.is_a?(::Issue)
|
||||
f.journals.where("notes is not null and notes != ''").reverse
|
||||
end
|
||||
end
|
||||
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||
has_praise = false
|
||||
current_user = options[:user]
|
||||
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id)
|
||||
has_praise = obj.empty? ? false : true
|
||||
has_praise
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,44 @@
|
|||
module Mobile
|
||||
module Entities
|
||||
class Journal <Grape::Entity
|
||||
include Redmine::I18n
|
||||
=begin
|
||||
include Redmine::I18n
|
||||
include ApplicationHelper
|
||||
include ApiHelper
|
||||
include IssuesHelper
|
||||
include ActionView::Helpers::TagHelper
|
||||
include ActionView::Helpers::UrlHelper
|
||||
=end
|
||||
def self.journal_expose(f)
|
||||
expose f do |journal, opt|
|
||||
if journal.is_a?(Hash) && journal.key?(f)
|
||||
journal[f]
|
||||
elsif journal.is_a?(::Journal)
|
||||
if journal.respond_to?(f)
|
||||
if f == :created_on
|
||||
time_from_now(journal.send(f))
|
||||
else
|
||||
journal.send(f)
|
||||
end
|
||||
else
|
||||
case f
|
||||
when :detail_journal
|
||||
if journal.details.any?
|
||||
details_to_strings(journal.details)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
expose :notes
|
||||
journal_expose :created_on
|
||||
expose :user,using: Mobile::Entities::User do |f, opt|
|
||||
f.user
|
||||
end
|
||||
#journal_expose :detail_journal
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,7 +3,6 @@ module Mobile
|
|||
#普通留言
|
||||
class Jours < Grape::Entity
|
||||
include Redmine::I18n
|
||||
include WordsHelper
|
||||
def self.jours_expose(field)
|
||||
expose field do |f,opt|
|
||||
if f.is_a?(Hash) && f.key?(field)
|
||||
|
@ -15,13 +14,24 @@ module Mobile
|
|||
f.send(field)
|
||||
end
|
||||
else
|
||||
case f
|
||||
when :course_name
|
||||
f[:jour_type] == "Course" ? f.course.name : ""
|
||||
case field
|
||||
when :lasted_comment
|
||||
time_from_now f.created_on
|
||||
when :reply_count
|
||||
f.children.count
|
||||
when :praise_count
|
||||
get_activity_praise_num(f)
|
||||
when :act_type
|
||||
'JournalsForMessage'
|
||||
when :act_id
|
||||
f.id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
jours_expose :act_type
|
||||
jours_expose :act_id
|
||||
jours_expose :id
|
||||
jours_expose :jour_type
|
||||
jours_expose :jour_id
|
||||
|
@ -29,9 +39,12 @@ module Mobile
|
|||
f.user
|
||||
end
|
||||
jours_expose :created_on
|
||||
jours_expose :lasted_comment
|
||||
jours_expose :notes
|
||||
jours_expose :m_reply_id
|
||||
jours_expose :m_parent_id
|
||||
jours_expose :reply_count
|
||||
jours_expose :praise_count
|
||||
expose :course,using:Mobile::Entities::Course do |f,opt|
|
||||
if f.is_a?(::JournalsForMessage) && f[:jour_type] == "Course"
|
||||
f.course
|
||||
|
@ -42,9 +55,16 @@ module Mobile
|
|||
end
|
||||
expose :child_reply,using: Mobile::Entities::Jours do |f, opt|
|
||||
if f.is_a?(::JournalsForMessage)
|
||||
fetch_user_leaveWord_reply(f)
|
||||
f.children.reverse
|
||||
end
|
||||
end
|
||||
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||
has_praise = false
|
||||
current_user = options[:user]
|
||||
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id)
|
||||
has_praise = obj.empty? ? false : true
|
||||
has_praise
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,10 +15,22 @@ module Mobile
|
|||
u.send(f)
|
||||
end
|
||||
else
|
||||
# case f
|
||||
# when :xx
|
||||
# #
|
||||
# end
|
||||
case f
|
||||
when :course_project_name
|
||||
if u.board.project_id == -1
|
||||
u.course.name
|
||||
else
|
||||
u.project.name
|
||||
end
|
||||
when :lasted_comment
|
||||
time_from_now u.created_on
|
||||
when :praise_count
|
||||
get_activity_praise_num(u)
|
||||
when :act_type
|
||||
'Message'
|
||||
when :act_id
|
||||
u.id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -30,17 +42,30 @@ module Mobile
|
|||
c.author
|
||||
end
|
||||
end
|
||||
message_expose :act_type
|
||||
message_expose :act_id
|
||||
message_expose :course_project_name
|
||||
message_expose :board_id
|
||||
message_expose :subject
|
||||
message_expose :content
|
||||
message_expose :replies_count
|
||||
message_expose :praise_count
|
||||
message_expose :created_on
|
||||
message_expose :locked
|
||||
message_expose :id
|
||||
message_expose :lasted_comment
|
||||
expose :message_children,using:Mobile::Entities::Message do |c,opt|
|
||||
if c.is_a? (::Message)
|
||||
c.children
|
||||
c.children.reverse
|
||||
end
|
||||
end
|
||||
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||
has_praise = false
|
||||
current_user = options[:user]
|
||||
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id)
|
||||
has_praise = obj.empty? ? false : true
|
||||
has_praise
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,15 +2,29 @@ module Mobile
|
|||
module Entities
|
||||
class News < Grape::Entity
|
||||
include Redmine::I18n
|
||||
include ApiHelper
|
||||
def self.news_expose(field)
|
||||
expose field do |f,opt|
|
||||
if f.is_a?(Hash) && f.key?(field)
|
||||
f[field]
|
||||
elsif f.is_a?(::News)
|
||||
if field == :created_on
|
||||
format_time(f.send(field)) if f.respond_to?(field)
|
||||
if f.respond_to?(field)
|
||||
if field == :created_on
|
||||
format_time(f.send(field))
|
||||
else
|
||||
f.send(field)
|
||||
end
|
||||
else
|
||||
f.send(field) if f.respond_to?(field)
|
||||
case field
|
||||
when :course_name
|
||||
get_course(f.course_id).name unless f.course_id == nil
|
||||
when :praise_count
|
||||
get_activity_praise_num(f)
|
||||
when :act_type
|
||||
'News'
|
||||
when :act_id
|
||||
f.id
|
||||
end
|
||||
end
|
||||
elsif f.is_a?(Hash) && !f.key?(field)
|
||||
n = f[:news]
|
||||
|
@ -40,6 +54,8 @@ module Mobile
|
|||
end
|
||||
obj
|
||||
end
|
||||
news_expose :act_type
|
||||
news_expose :act_id
|
||||
#作者id
|
||||
news_expose :author_id
|
||||
#作者名
|
||||
|
@ -52,16 +68,24 @@ module Mobile
|
|||
news_expose :created_on
|
||||
#评论数量
|
||||
news_expose :comments_count
|
||||
news_expose :praise_count
|
||||
#课程名字
|
||||
news_expose :course_name
|
||||
#评论
|
||||
expose :comments, using: Mobile::Entities::Comment do |f, opt|
|
||||
if f.is_a?(Hash) && f.key?(:comments)
|
||||
f[:comments]
|
||||
elsif f.is_a?(::News) && f.respond_to?(:comments)
|
||||
f.send(:comments)
|
||||
f.comments.reverse
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||
has_praise = false
|
||||
current_user = options[:user]
|
||||
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id)
|
||||
has_praise = obj.empty? ? false : true
|
||||
has_praise
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -32,14 +32,14 @@ module Mobile
|
|||
end
|
||||
end
|
||||
student_work_expose :student_id
|
||||
student_work_expose :id
|
||||
student_work_expose :id
|
||||
student_work_expose :name
|
||||
student_work_expose :description
|
||||
student_work_expose :final_score
|
||||
student_work_expose :teacher_score
|
||||
student_work_expose :student_score
|
||||
student_work_expose :teacher_asistant_score
|
||||
student_work_expose :created_at
|
||||
student_work_expose :description
|
||||
student_work_expose :final_score
|
||||
student_work_expose :teacher_score
|
||||
student_work_expose :student_score
|
||||
student_work_expose :teacher_asistant_score
|
||||
student_work_expose :created_at
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,13 @@
|
|||
module Mobile
|
||||
module Entities
|
||||
class Syllabus < Grape::Entity
|
||||
include ApplicationHelper
|
||||
|
||||
expose :title
|
||||
expose :id
|
||||
expose :can_setting
|
||||
|
||||
expose :courses, using: Mobile::Entities::Course
|
||||
end
|
||||
end
|
||||
end
|
|
@ -13,7 +13,7 @@ module Mobile
|
|||
else
|
||||
case f
|
||||
when :img_url
|
||||
url_to_avatar(u)
|
||||
"/images/#{url_to_avatar(u)}"
|
||||
when :gender
|
||||
u.nil? || u.user_extensions.nil? || u.user_extensions.gender.nil? ? 0 : u.user_extensions.gender
|
||||
when :work_unit
|
||||
|
@ -24,6 +24,10 @@ module Mobile
|
|||
u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.brief_introduction
|
||||
when :student_num
|
||||
u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.student_id
|
||||
when :realname
|
||||
u.nil? ? "" : get_user_realname(u)
|
||||
when :name
|
||||
u.nil? ? "" : u.show_name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -37,7 +41,7 @@ module Mobile
|
|||
#昵称
|
||||
expose :nickname
|
||||
#真名
|
||||
expose :realname
|
||||
user_expose :realname
|
||||
#性别
|
||||
user_expose :gender
|
||||
#我的二维码
|
||||
|
@ -55,6 +59,11 @@ module Mobile
|
|||
user_expose :student_num
|
||||
# 活跃值
|
||||
user_expose :active_count
|
||||
|
||||
user_expose :role_name
|
||||
|
||||
user_expose :name
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
# encoding: utf-8
|
||||
module Mobile
|
||||
module Entities
|
||||
class Whomework <Grape::Entity
|
||||
include ApiHelper
|
||||
include ApplicationHelper
|
||||
include Redmine::I18n
|
||||
def self.whomework_expose(f)
|
||||
expose f do |wh, opt|
|
||||
if wh.is_a?(Hash) && wh.key?(f)
|
||||
wh[f]
|
||||
elsif wh.is_a?(::HomeworkCommon)
|
||||
if wh.respond_to?(f)
|
||||
if f == :created_at
|
||||
format_time(wh.send(f))
|
||||
else
|
||||
wh.send(f)
|
||||
end
|
||||
else
|
||||
case f
|
||||
when :absence_penalty
|
||||
wh.nil? || wh.homework_detail_manual.nil? ? 0 : wh.homework_detail_manual.absence_penalty
|
||||
when :evaluation_start
|
||||
wh.nil? || wh.homework_detail_manual.nil? ? nil : convert_to_time(wh.homework_detail_manual.evaluation_start, 0)
|
||||
when :evaluation_end
|
||||
wh.nil? || wh.homework_detail_manual.nil? ? nil : convert_to_time(wh.homework_detail_manual.evaluation_end, 1)
|
||||
when :praise_count
|
||||
get_activity_praise_num(wh)
|
||||
when :whomework_journal_count
|
||||
wh.journals_for_messages.count
|
||||
when :course_name
|
||||
wh.course.name
|
||||
when :act_type
|
||||
'HomeworkCommon'
|
||||
when :act_id
|
||||
wh.id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
expose :author, using: Mobile::Entities::User do |w, opt|
|
||||
if w.is_a?(::HomeworkCommon)
|
||||
w.user
|
||||
end
|
||||
end
|
||||
expose :current_user, using: Mobile::Entities::User do |w, opt|
|
||||
current_user
|
||||
end
|
||||
expose :name
|
||||
expose :description
|
||||
expose :publish_time
|
||||
expose :end_time
|
||||
expose :homework_type
|
||||
expose :late_penalty
|
||||
expose :course_id
|
||||
expose :anonymous_comment
|
||||
expose :quotes
|
||||
expose :is_open
|
||||
whomework_expose :act_type
|
||||
whomework_expose :act_id
|
||||
whomework_expose :course_name
|
||||
whomework_expose :created_at
|
||||
whomework_expose :absence_penalty
|
||||
whomework_expose :evaluation_start
|
||||
whomework_expose :evaluation_end
|
||||
whomework_expose :praise_count
|
||||
whomework_expose :whomework_journal_count
|
||||
expose :journals_for_messages, using: Mobile::Entities::Jours do |f, opt|
|
||||
#f[:journals_for_messages] if f.is_a?(Hash) && f.key?(:journals_for_messages)
|
||||
if f.is_a?(::HomeworkCommon)
|
||||
f.journals_for_messages.reverse
|
||||
end
|
||||
end
|
||||
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
|
||||
has_praise = false
|
||||
current_user = options[:user]
|
||||
obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id)
|
||||
has_praise = obj.empty? ? false : true
|
||||
has_praise
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -7,7 +7,8 @@ module Mobile
|
|||
@app.call(@env)
|
||||
rescue =>e
|
||||
message = {status: 1, message: e.message }.to_json
|
||||
puts(e.backtrace.join("\n")) if Rails.env.development?
|
||||
Rails.logger.error e.inspect
|
||||
Rails.logger.error e.backtrace.join("\n")
|
||||
status = 200
|
||||
headers = { 'Content-Type' => content_type }
|
||||
Rack::Response.new([message], status, headers).finish
|
||||
|
|
|
@ -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 QualityAnalyses 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 ShieldWechatMessages 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 sub_document_comments 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 sub_domains 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 syllabuses controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -239,14 +239,23 @@ class AccountController < ApplicationController
|
|||
|
||||
end
|
||||
def resendmail
|
||||
result = {:status=>1, :email=>""}
|
||||
user = User.find(params[:user]) if params[:user]
|
||||
result[:email] = user.mail
|
||||
token = Token.new(:user => user, :action => "register")
|
||||
if token.save
|
||||
Mailer.run.register(token)
|
||||
|
||||
# Mailer.run.register(token)
|
||||
Mailer.register(token).deliver
|
||||
else
|
||||
yield if block_given?
|
||||
result[:status] = 0
|
||||
end
|
||||
render :json => result
|
||||
end
|
||||
|
||||
def email_activation
|
||||
|
||||
|
||||
end
|
||||
private
|
||||
|
||||
|
@ -264,6 +273,7 @@ class AccountController < ApplicationController
|
|||
if user.nil?
|
||||
invalid_credentials
|
||||
elsif user.status == 2
|
||||
@user = user
|
||||
invalid_credentials_new
|
||||
elsif user.new_record?
|
||||
onthefly_creation_failed(user, {:login => user.login, :auth_source_id => user.auth_source_id })
|
||||
|
@ -375,8 +385,9 @@ class AccountController < ApplicationController
|
|||
|
||||
def invalid_credentials_new
|
||||
logger.warn "Failed login for '#{params[:username]}' from #{request.remote_ip} at #{Time.now.utc}"
|
||||
flash[:error] = l(:notice_account_invalid_creditentials_new)
|
||||
render signin_path(:login=>true)
|
||||
# flash[:error] = l(:notice_account_invalid_creditentials_new)
|
||||
# render signin_path(:login=>true)
|
||||
render :action => 'email_activation'
|
||||
end
|
||||
|
||||
# Register a user for email activation.
|
||||
|
|
|
@ -45,9 +45,62 @@ class AdminController < ApplicationController
|
|||
render :action => "projects", :layout => false if request.xhr?
|
||||
end
|
||||
|
||||
def courses
|
||||
def syllabuses
|
||||
@name = params[:name]
|
||||
@courses = Course.like(@name).order('created_at desc')
|
||||
@syllabuses = Syllabus.like(@name).order('created_at desc')
|
||||
@syllabuses = paginateHelper @syllabuses,30
|
||||
@page = (params['page'] || 1).to_i - 1
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
#为班级选择课程
|
||||
def select_course_syllabus
|
||||
@flag = false
|
||||
if params[:syllabus_id] && params[:course_id]
|
||||
course = Course.where("id = #{params[:course_id].to_i}").first
|
||||
unless course.nil?
|
||||
course.update_column('syllabus_id', params[:syllabus_id].to_i)
|
||||
@flag = true
|
||||
end
|
||||
end
|
||||
if @flag
|
||||
render :text=> "succ"
|
||||
else
|
||||
render :text=>'fail'
|
||||
end
|
||||
end
|
||||
|
||||
#新建课程
|
||||
def create_syllabus
|
||||
if params[:course_id]
|
||||
course = Course.where("id = #{params[:course_id]}").first
|
||||
if course
|
||||
@user = course.teacher
|
||||
syllabus = Syllabus.new
|
||||
syllabus.update_attributes(:title => params[:title], :eng_name => params[:eng_name], :user_id => @user.id)
|
||||
syllabus.description = Message.where("id = 19412").first.nil? ? nil : Message.where("id = 19412").first.content
|
||||
if syllabus.save
|
||||
course.update_attribute('syllabus_id', syllabus.id)
|
||||
@flag = params[:flag].to_i
|
||||
@course = course
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def courses
|
||||
@name = params[:name].to_s.strip.downcase
|
||||
if @name && @name != ""
|
||||
@courses = Course.select{ |course| (course.teacher[:lastname].to_s.downcase + course.teacher[:firstname].to_s.downcase).include?(@name) || course.name.include?(@name)}
|
||||
@courses = @courses.sort{|x, y| y.created_at <=> x.created_at}
|
||||
else
|
||||
@courses = Course.order('created_at desc')
|
||||
end
|
||||
@courses = paginateHelper @courses,30
|
||||
@page = (params['page'] || 1).to_i - 1
|
||||
respond_to do |format|
|
||||
|
@ -55,6 +108,33 @@ class AdminController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
#未配置班级列表
|
||||
def non_syllabus_courses
|
||||
@name = params[:name].to_s.strip.downcase
|
||||
if @name && @name != ""
|
||||
@courses = Course.where("syllabus_id is null and is_delete = 0").select{ |course| (course.teacher[:lastname].to_s.downcase + course.teacher[:firstname].to_s.downcase).include?(@name) || course.name.include?(@name)}
|
||||
@courses = @courses.sort{|x, y| y.created_at <=> x.created_at}
|
||||
else
|
||||
@courses = Course.where("syllabus_id is null and is_delete = 0").order('created_at desc')
|
||||
end
|
||||
@courses = paginateHelper @courses,30
|
||||
@page = (params['page'] || 1).to_i - 1
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
#修改班级名称
|
||||
def update_course_name
|
||||
@course = Course.where("id = #{params[:course_id].to_i}").first
|
||||
unless @course.nil?
|
||||
@course.update_column("name", params[:name])
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#管理员界面精品课程列表
|
||||
def excellent_courses
|
||||
@courses = Course.where("is_excellent =? or excellent_option =?", 1, 1 )
|
||||
|
@ -65,9 +145,53 @@ class AdminController < ApplicationController
|
|||
|
||||
#精品课程下的全部课程
|
||||
def excellent_all_courses
|
||||
@name = params[:name]
|
||||
@courses = Course.like(@name).order('created_at desc')
|
||||
@courses = paginateHelper @courses,30
|
||||
name = params[:name]
|
||||
@order = ""
|
||||
@sort = ""
|
||||
if params[:sort] && (params[:order] == 'act')
|
||||
courses = Course.find_by_sql("SELECT c.*,count(c.id) FROM courses c,course_activities ca WHERE c.id = ca.course_id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY count(c.id) #{params[:sort]}, c.id desc")
|
||||
@order = params[:order]
|
||||
@sort = params[:sort]
|
||||
|
||||
elsif params[:sort] && (params[:order] == 'time')
|
||||
courses = Course.find_by_sql("SELECT * FROM courses WHERE name like '%#{name}%' ORDER BY time #{params[:sort]}, id desc")
|
||||
@order = params[:order]
|
||||
@sort = params[:sort]
|
||||
|
||||
elsif params[:sort] && (params[:order] == 'post')
|
||||
courses = Course.find_by_sql("SELECT c.*, count(m.id) count FROM boards b, courses c, messages m WHERE m.board_id = b.id AND b.course_id = c.id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY count #{params[:sort]}, c.id desc")
|
||||
@order = params[:order]
|
||||
@sort = params[:sort]
|
||||
|
||||
elsif params[:sort] && (params[:order] == 'res')
|
||||
courses = Course.find_by_sql("SELECT c.*, count(at.container_id) cat FROM attachments at, courses c WHERE at.container_type = 'Course' AND at.container_id = c.id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY cat #{params[:sort]}, id desc")
|
||||
@order = params[:order]
|
||||
@sort = params[:sort]
|
||||
|
||||
elsif params[:sort] && (params[:order] == 'works')
|
||||
courses = Course.find_by_sql("SELECT c.*, count(hc.id) chc FROM courses c, homework_commons hc,student_works sw WHERE c.id = hc.course_id AND sw.homework_common_id = hc.id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY chc #{params[:sort]}, id desc")
|
||||
@order = params[:order]
|
||||
@sort = params[:sort]
|
||||
|
||||
elsif params[:sort] && (params[:order] == 'homework')
|
||||
courses = Course.find_by_sql("SELECT c.*, count(sw.id) csw FROM student_works sw, courses c, homework_commons hc WHERE c.id = hc.course_id AND sw.id = c.id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY csw #{params[:sort]}, id desc")
|
||||
@order = params[:order]
|
||||
@sort = params[:sort]
|
||||
|
||||
elsif params[:sort] && (params[:order] == 'std')
|
||||
courses = Course.find_by_sql("SELECT c.*, count(sfc.id) sfc FROM courses c, students_for_courses sfc WHERE sfc.course_id = c.id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY sfc #{params[:sort]}, id desc")
|
||||
@order = params[:order]
|
||||
@sort = params[:sort]
|
||||
|
||||
elsif params[:sort] && (params[:order] == 'open')
|
||||
courses = Course.find_by_sql("SELECT * FROM courses WHERE name like '%#{name}%' ORDER BY is_public #{params[:sort]},id desc")
|
||||
@order = params[:order]
|
||||
@sort = params[:sort]
|
||||
|
||||
else
|
||||
courses = Course.like(name).order('created_at desc')
|
||||
end
|
||||
@courses = paginateHelper courses,30
|
||||
@page = (params['page'] || 1).to_i - 1
|
||||
respond_to do |format|
|
||||
format.html
|
||||
|
@ -90,6 +214,22 @@ class AdminController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
#取消精品
|
||||
def cancel_excellent_course
|
||||
@course = Course.find params[:id]
|
||||
unless @course.nil?
|
||||
if @course.is_excellent == 1 || @course.excellent_option == 1
|
||||
@course.update_column('is_excellent', 0)
|
||||
@course.update_column('excellent_option', 0)
|
||||
end
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html{
|
||||
redirect_to excellent_courses_url
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
#管理员界面课程资源列表
|
||||
def course_resource_list
|
||||
|
||||
|
@ -584,13 +724,62 @@ class AdminController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
#代码测试列表
|
||||
#代码测试列表
|
||||
def code_work_tests
|
||||
@code_work_tests = StudentWorkTest.find_by_sql("select status,results,created_at, student_work_id from student_work_tests order by id desc ")
|
||||
#@code_work_tests = StudentWorkTest.find_by_sql("select a.status,a.results,a.created_at ,b.id as homeworkid,d.language from student_work_tests as a , homework_commons as b ,student_works as c, homework_detail_programings as d where a.student_work_id = c.id and b.id = c.homework_common_id and c.homework_common_id = d.homework_common_id order by a.id desc ")
|
||||
#@code_work_tests = StudentWorkTest.order('created_at desc')
|
||||
#求出所有条数
|
||||
tCount = CodeTests.count()
|
||||
|
||||
#设置个空的数组 以便paginateHelper来分页
|
||||
@code_work_tests = []
|
||||
if tCount >= 1
|
||||
@code_work_tests[tCount-1] = {}
|
||||
end
|
||||
@code_work_tests = paginateHelper @code_work_tests,30
|
||||
@page = (params['page'] || 1).to_i - 1
|
||||
|
||||
#取出需要的那一页数据
|
||||
tStart = @page*30
|
||||
@code_work_tests = CodeTests.find_by_sql("select * from code_tests order by id desc limit #{tStart},30 ")
|
||||
|
||||
#取出各个作品是否是模拟答题的
|
||||
is_test = {}
|
||||
#作品是否存在
|
||||
link_swork = {}
|
||||
#作业是否存在
|
||||
link_hwork = {}
|
||||
@code_work_tests.each do |test|
|
||||
#作品是否存在
|
||||
if is_test[test['student_work_id']] != nil
|
||||
test['link_swork'] = link_swork[test['student_work_id']]
|
||||
test['is_test'] = is_test[test['student_work_id']]
|
||||
else
|
||||
work = StudentWork.where("id=?",test['student_work_id']).first
|
||||
test['link_swork'] = !work.nil?
|
||||
test['is_test'] = work.nil? ? false : work.is_test
|
||||
#test['is_test'] = CodeTests.find_by_sql("select is_test from student_works where id = #{test['student_work_id']}").first['is_test']
|
||||
is_test[test['student_work_id']] = test['is_test']
|
||||
link_swork[test['student_work_id']] = test['link_swork']
|
||||
end
|
||||
|
||||
#作业是否存在
|
||||
if link_hwork[test['homework_id']] != nil
|
||||
test['link_hwork'] = link_hwork[test['homework_id']]
|
||||
else
|
||||
hwork = HomeworkCommon.where("id=?",test['homework_id']).first
|
||||
test['link_hwork'] = !hwork.nil?
|
||||
link_hwork[test['homework_id']] = test['link_hwork']
|
||||
end
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
end
|
||||
#分享作业申请
|
||||
def apply_for_homework
|
||||
homeworks = ApplyHomework.where("user_id != 0")
|
||||
@homework = paginateHelper homeworks,30
|
||||
@page = (params['page'] || 1).to_i - 1
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
|
|
|
@ -363,7 +363,11 @@ class ApplicationController < ActionController::Base
|
|||
when "contest"
|
||||
return true
|
||||
when "Course"
|
||||
allowed = User.current.allowed_to?(:course_attachments_download, @course, :global => false)
|
||||
if @attachment.get_status_by_attach(User.current.id) == 2
|
||||
return true
|
||||
else
|
||||
allowed = User.current.allowed_to?(:course_attachments_download, @course, :global => false)
|
||||
end
|
||||
else
|
||||
return true
|
||||
end
|
||||
|
@ -912,4 +916,11 @@ class ApplicationController < ActionController::Base
|
|||
call_hook(:controller_account_success_authentication_after, {:user => user })
|
||||
end
|
||||
|
||||
def user_unlogged_check
|
||||
if !User.current.logged?
|
||||
render(:partial => 'organizations/unlogged_tip')
|
||||
return false
|
||||
end
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -68,7 +68,7 @@ class AtController < ApplicationController
|
|||
end
|
||||
|
||||
def find_project(id)
|
||||
return [] if id<0
|
||||
return [] if id.to_i<0
|
||||
at_persons = Project.find(id).users
|
||||
at_persons.delete_if { |u| u.id == User.current.id }
|
||||
end
|
||||
|
|
|
@ -265,6 +265,10 @@ class AttachmentsController < ApplicationController
|
|||
@history.save #历史记录保存完毕
|
||||
#将最新保存的记录 数据替换到 需要修改的文件记录
|
||||
@old_attachment.attributes = @attachment.attributes.dup.except("id","container_id","container_type","is_public","downloads", "quotes")
|
||||
# 如果附件描述被修改,则保存附件
|
||||
unless params[:description] == @attachment.description
|
||||
@old_attachment.description = params[:description]
|
||||
end
|
||||
@old_attachment.save
|
||||
#删除当前记录
|
||||
@attachment.delete
|
||||
|
@ -608,7 +612,7 @@ class AttachmentsController < ApplicationController
|
|||
@attachment.container.board.course)
|
||||
@course = @attachment.container.board.course
|
||||
else
|
||||
unless @attachment.container_type == 'Bid' || @attachment.container_type == 'Organization' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication' || @attachment.container_type == 'PhoneAppVersion' || @attachment.container_type == 'StudentWorksScore'|| @attachment.container_type == 'StudentWork'
|
||||
unless @attachment.container_type == 'Syllabus' || @attachment.container_type == 'Bid' || @attachment.container_type == 'Organization' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication' || @attachment.container_type == 'PhoneAppVersion' || @attachment.container_type == 'StudentWorksScore'|| @attachment.container_type == 'StudentWork'
|
||||
@project = @attachment.project
|
||||
end
|
||||
end
|
||||
|
@ -660,8 +664,8 @@ class AttachmentsController < ApplicationController
|
|||
end
|
||||
|
||||
def has_login
|
||||
unless @attachment && @attachment.container_type == "Organization"
|
||||
unless @attachment && @attachment.container_type == "PhoneAppVersion"
|
||||
unless (@attachment && @attachment.container_type == "Organization").nil?
|
||||
unless (@attachment && @attachment.container_type == "PhoneAppVersion").nil?
|
||||
render_403 if !User.current.logged? && !(@attachment.container_type == 'OrgSubfield' && @attachment.container.organization.allow_guest_download) && !(@attachment.container_type == 'OrgDocumentComment' && @attachment.container.organization.allow_guest_download)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -116,6 +116,9 @@ class BlogCommentsController < ApplicationController
|
|||
|
||||
#回复
|
||||
def reply
|
||||
if params[:homepage]
|
||||
@in_user_homepage = true
|
||||
end
|
||||
if params[:in_user_center]
|
||||
@in_user_center = true
|
||||
end
|
||||
|
|
|
@ -1,9 +1,55 @@
|
|||
class BlogsController < ApplicationController
|
||||
before_filter :find_blog,:except => [:index,:create,:new,:set_homepage, :cancel_homepage]
|
||||
before_filter :find_user
|
||||
include PraiseTreadHelper
|
||||
|
||||
def index
|
||||
@article = BlogComment.new
|
||||
|
||||
@order, @b_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1
|
||||
|
||||
#确定 sort_type 1升序 2 降序
|
||||
if @order.to_i == @type.to_i
|
||||
@b_sort = @b_sort.to_i == 1 ? 2 : 1
|
||||
else
|
||||
@b_sort = 2
|
||||
end
|
||||
|
||||
sort_name = "updated_at"
|
||||
|
||||
sort_type = @b_sort == 1 ? "asc" : "desc"
|
||||
|
||||
@topics = @user.blog.articles.reorder("#{BlogComment.table_name}.sticky desc,#{BlogComment.table_name}.#{sort_name} #{sort_type}")
|
||||
|
||||
#根据 赞+回复数排序
|
||||
if @order.to_i == 2
|
||||
@type = 2
|
||||
|
||||
@topics.each do |topic|
|
||||
topic[:infocount] = get_praise_num(topic) + (topic.parent ? topic.parent.children.count : topic.children.count)
|
||||
if topic[:infocount] < 0
|
||||
topic[:infocount] = 0
|
||||
end
|
||||
end
|
||||
|
||||
@b_sort == 1 ? @topics = @topics.sort{|x,y| x[:infocount] <=> y[:infocount] } : @topics = @topics.sort{|x,y| y[:infocount] <=> x[:infocount] }
|
||||
|
||||
@topics = sort_by_sticky @topics
|
||||
@topics = sortby_time_countcommon_hassticky @topics,sort_name
|
||||
else
|
||||
@type = 1
|
||||
end
|
||||
|
||||
#分页
|
||||
@limit = 10
|
||||
@is_remote = true
|
||||
@atta_count = @topics.count
|
||||
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
|
||||
@offset ||= @atta_pages.offset
|
||||
@topics = paginateHelper @topics,@limit
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html {render :layout=>'new_base_user'}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,6 +28,7 @@ class BoardsController < ApplicationController
|
|||
helper :watchers
|
||||
helper :project_score
|
||||
helper :attachments
|
||||
include PraiseTreadHelper
|
||||
def index
|
||||
#modify by nwb
|
||||
@flag = params[:flag] || false
|
||||
|
@ -62,13 +63,24 @@ class BoardsController < ApplicationController
|
|||
else
|
||||
render_403
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def show
|
||||
# 讨论区消息状态更新(已读和未读)
|
||||
@order, @b_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1
|
||||
|
||||
#确定 sort_type 1升序 2 降序
|
||||
if @order.to_i == @type.to_i
|
||||
@b_sort = @b_sort.to_i == 1 ? 2 : 1
|
||||
else
|
||||
@b_sort = 2
|
||||
end
|
||||
|
||||
sort_name = "updated_on"
|
||||
|
||||
sort_type = @b_sort == 1 ? "asc" : "desc"
|
||||
|
||||
if @project
|
||||
ForgeMessage.where("user_id =? and project_id =? and viewed =?", User.current.id, @project.id, 0).update_all(:viewed => true)
|
||||
# 更新@消息为已读
|
||||
|
@ -82,63 +94,90 @@ class BoardsController < ApplicationController
|
|||
CourseMessage.where("user_id =? and course_id =? and viewed =?", User.current.id, @course.id, 0).update_all(:viewed => true)
|
||||
end
|
||||
|
||||
sort_init 'updated_on', 'desc'
|
||||
sort_update 'created_on' => "#{Message.table_name}.created_on",
|
||||
'replies' => "#{Message.table_name}.replies_count",
|
||||
'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)"
|
||||
# sort_init 'updated_on', 'desc'
|
||||
# sort_update 'created_on' => "#{Message.table_name}.created_on",
|
||||
# 'replies' => "#{Message.table_name}.replies_count",
|
||||
# 'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)"
|
||||
|
||||
@is_new = params[:is_new]
|
||||
@topic_count = @board ? @board.topics.count : 0
|
||||
if @project
|
||||
if @board
|
||||
limit = 10;
|
||||
@topic_count = @board.topics.count();
|
||||
@topic_pages = (params[:page] ? params[:page].to_i + 1 : 0) *10
|
||||
@topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) desc").
|
||||
limit(limit).offset(@topic_pages).includes(:last_reply).
|
||||
@topic_pages = 0#(params[:page] ? params[:page].to_i + 1 : 0) *10
|
||||
@topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) #{sort_type}").
|
||||
offset(@topic_pages).includes(:last_reply).
|
||||
preload(:author, {:last_reply => :author}).all();
|
||||
else
|
||||
@topics = [];
|
||||
end
|
||||
elsif @course
|
||||
if (@board)
|
||||
limit = 10;
|
||||
@topic_count = @board.topics.count();
|
||||
@topic_pages = (params[:page] ? params[:page].to_i + 1 : 0) *10
|
||||
@topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) desc").
|
||||
limit(limit).offset(@topic_pages).includes(:last_reply).
|
||||
preload(:author, {:last_reply => :author}).all();
|
||||
@topic_pages = 0 #(params[:page] ? params[:page].to_i + 1 : 0) *10
|
||||
@topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) #{sort_type}").offset(@topic_pages).includes(:last_reply).preload(:author, {:last_reply => :author}).all();
|
||||
else
|
||||
@topics = [];
|
||||
end
|
||||
end
|
||||
|
||||
#根据 赞+回复数排序
|
||||
if @order.to_i == 2
|
||||
@type = 2
|
||||
@topics.each do |topic|
|
||||
all_comments = []
|
||||
count=get_all_children(all_comments, topic).count
|
||||
topic[:infocount] = get_praise_num(topic) + count
|
||||
if topic[:infocount] < 0
|
||||
topic[:infocount] = 0
|
||||
end
|
||||
end
|
||||
@b_sort == 1 ? @topics = @topics.sort{|x,y| x[:infocount] <=> y[:infocount] } : @topics = @topics.sort{|x,y| y[:infocount] <=> x[:infocount] }
|
||||
@topics = sort_by_sticky @topics
|
||||
@topics = sortby_time_countcommon_hassticky @topics,sort_name
|
||||
else
|
||||
@type = 1
|
||||
end
|
||||
|
||||
#分页
|
||||
@limit = 15
|
||||
@is_remote = true
|
||||
@atta_count = @topics.count
|
||||
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
|
||||
@offset ||= @atta_pages.offset
|
||||
@topics = paginateHelper @topics,@limit
|
||||
|
||||
@page = params[:page] ? params[:page].to_i + 1 : 0
|
||||
@message = Message.new(:board => @board)
|
||||
#modify by nwb
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html {
|
||||
if @project
|
||||
render :action => 'show', :layout => 'base_projects'
|
||||
elsif @course
|
||||
@params=params
|
||||
render :action => 'show', :layout => 'base_courses'
|
||||
end
|
||||
}
|
||||
format.atom {
|
||||
@messages = @board.messages.
|
||||
reorder('created_on DESC').
|
||||
includes(:author, :board).
|
||||
limit(Setting.feeds_limit.to_i).
|
||||
all
|
||||
if @project
|
||||
render_feed(@messages, :title => "#{@project}: #{@board}")
|
||||
elsif @course
|
||||
render_feed(@messages, :title => "#{@course}: #{@board}")
|
||||
end
|
||||
|
||||
}
|
||||
if (params[:page] || params[:order])
|
||||
respond_to do |format|
|
||||
format.js{render "show.js.erb"}
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html {
|
||||
if @project
|
||||
render :action => 'show', :layout => 'base_projects'
|
||||
elsif @course
|
||||
@params=params
|
||||
render :action => 'show', :layout => 'base_courses'
|
||||
end
|
||||
}
|
||||
format.atom {
|
||||
@messages = @board.messages.
|
||||
reorder('created_on DESC').
|
||||
includes(:author, :board).
|
||||
limit(Setting.feeds_limit.to_i).
|
||||
all
|
||||
if @project
|
||||
render_feed(@messages, :title => "#{@project}: #{@board}")
|
||||
elsif @course
|
||||
render_feed(@messages, :title => "#{@course}: #{@board}")
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ class CoursesController < ApplicationController
|
|||
else
|
||||
@state = 5 #未登录
|
||||
end
|
||||
@object_id = params[:object_id]
|
||||
@object_id = @course.id if @course
|
||||
respond_to do |format|
|
||||
format.js #{ render :partial => 'set_join', :locals => {:user => @user, :course => @course, :object_id => params[:object_id]} }
|
||||
end
|
||||
|
@ -162,6 +162,7 @@ class CoursesController < ApplicationController
|
|||
@subPage_title = l :label_student_list
|
||||
@canShowCode = User.current.allowed_to?(:as_teacher,@course) && params[:role] != '1'
|
||||
# @is_remote = true
|
||||
@sort_type = 'score'
|
||||
@score_sort_by = "desc"
|
||||
q = "#{params[:name].strip}"
|
||||
if params[:incourse]
|
||||
|
@ -185,9 +186,11 @@ class CoursesController < ApplicationController
|
|||
group.course_id = @course.id
|
||||
group.save
|
||||
end
|
||||
@sort_type = 'score'
|
||||
@score_sort_by = "desc"
|
||||
@canShowCode = User.current.allowed_to?(:as_teacher,@course) && params[:role] != '1'
|
||||
@is_remote = true
|
||||
|
||||
@members = student_homework_score(0,0, 10,@score_sort_by)
|
||||
@course_groups = @course.course_groups
|
||||
end
|
||||
|
||||
|
@ -196,7 +199,9 @@ class CoursesController < ApplicationController
|
|||
@subPage_title = l :label_student_list
|
||||
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
|
||||
@is_remote = true
|
||||
|
||||
@sort_type = 'score'
|
||||
@score_sort_by = "desc"
|
||||
@members = student_homework_score(0,0, 10,@score_sort_by)
|
||||
@course_groups = @course.course_groups
|
||||
end
|
||||
|
||||
|
@ -209,7 +214,7 @@ class CoursesController < ApplicationController
|
|||
end
|
||||
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
|
||||
@is_remote = true
|
||||
|
||||
@members = student_homework_score(0,0, 10,"desc")
|
||||
@course_groups = @course.course_groups
|
||||
end
|
||||
|
||||
|
@ -281,6 +286,7 @@ class CoursesController < ApplicationController
|
|||
@render_file = 'new_member_list'
|
||||
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
|
||||
@is_remote = true
|
||||
@sort_type = 'score'
|
||||
@score_sort_by = "desc"
|
||||
if params[:group_id] && params[:group_id] != "0"
|
||||
@group = CourseGroup.find(params[:group_id])
|
||||
|
@ -298,6 +304,7 @@ class CoursesController < ApplicationController
|
|||
|
||||
@render_file = 'new_member_list'
|
||||
@score_sort_by = "desc"
|
||||
@sort_type = params[:sort_type] ? params[:sort_type] : "score"
|
||||
@canShowCode = User.current.allowed_to?(:as_teacher,@course) && params[:role] != '1'
|
||||
@role = params[:role].nil? ? '2':params[:role]
|
||||
@is_remote = true
|
||||
|
@ -312,7 +319,7 @@ class CoursesController < ApplicationController
|
|||
if @course.open_student == 1 || User.current.member_of_course?(@course)
|
||||
@subPage_title = l :label_student_list
|
||||
page = params[:page].nil? ? 0 : (params['page'].to_i - 1)
|
||||
@all_members = student_homework_score(0,page, 10,"desc")
|
||||
@all_members = student_homework_score(0,page, 10,@score_sort_by,@sort_type)
|
||||
@members = @all_members
|
||||
else
|
||||
render_403
|
||||
|
@ -334,7 +341,7 @@ class CoursesController < ApplicationController
|
|||
|
||||
def export_course_member_excel
|
||||
@all_members = student_homework_score(0,0,0,"desc")
|
||||
@homeworks = @course.homework_commons.order("created_at asc")
|
||||
@homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").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)}";
|
||||
|
||||
respond_to do |format|
|
||||
|
@ -350,28 +357,29 @@ class CoursesController < ApplicationController
|
|||
@subPage_title = l :label_student_list
|
||||
@render_file = 'new_member_list'
|
||||
@is_remote = true
|
||||
@sort_type = params[:sort_type] if params[:sort_type]
|
||||
@score_sort_by = params[:sort_by] if params[:sort_by]
|
||||
@search_name = params[:search_name] if params[:search_name]
|
||||
group_id = params[:group_id]
|
||||
if !@search_name.nil?
|
||||
if group_id == '0'
|
||||
page = params[:page].nil? ? 0 : (params['page'].to_i - 1)
|
||||
@results = searchmember_by_name(student_homework_score(0,0,0,@score_sort_by), @search_name)
|
||||
@results = searchmember_by_name(student_homework_score(0,0,0,@score_sort_by,@sort_type), @search_name)
|
||||
@result_count = @results.count
|
||||
# @results = paginateHelper @results, 10
|
||||
else
|
||||
@group = CourseGroup.find(group_id)
|
||||
@results = searchmember_by_name(student_homework_score(group_id, 0, 0,@score_sort_by),@search_name)
|
||||
@results = searchmember_by_name(student_homework_score(group_id, 0, 0,@score_sort_by,@sort_type),@search_name)
|
||||
@result_count = @results.count
|
||||
# @results = paginateHelper @results, 10
|
||||
end
|
||||
else
|
||||
if group_id == '0'
|
||||
page = params[:page].nil? ? 0 : (params['page'].to_i - 1)
|
||||
@results = student_homework_score(0,page, 10,@score_sort_by)
|
||||
@results = student_homework_score(0,page, 10,@score_sort_by,@sort_type)
|
||||
else
|
||||
@group = CourseGroup.find(group_id)
|
||||
@results = student_homework_score(group_id, 0, 0,@score_sort_by)
|
||||
@results = student_homework_score(group_id, 0, 0,@score_sort_by,@sort_type)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -384,6 +392,15 @@ class CoursesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# 显示每个学生的作业评分详情
|
||||
def show_member_act_score
|
||||
@member = Member.find(params[:member_id]) if params[:member_id]
|
||||
respond_to do |format|
|
||||
format.html {render :layout => 'course_base'}
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def handle_course courses, activities
|
||||
course_activity_count_array=activities.values()
|
||||
course_array=[]
|
||||
|
@ -698,6 +715,7 @@ class CoursesController < ApplicationController
|
|||
@trackers = Tracker.sorted.all
|
||||
@course = Course.new
|
||||
@course.safe_attributes = params[:course]
|
||||
@syllabus = Syllabus.where("id = #{params[:syllabus_id].to_i}").first if params[:syllabus_id]
|
||||
# month = Time.now.month
|
||||
render :layout => 'new_base'
|
||||
else
|
||||
|
@ -950,12 +968,13 @@ class CoursesController < ApplicationController
|
|||
|
||||
@homework = HomeworkCommon.find params[:homework]
|
||||
#order("#{@order} #{@b_sort}"
|
||||
@student_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").order("simi_value desc"),@name
|
||||
@student_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").order("simi_value desc").has_committed,@name
|
||||
|
||||
@works_hash = {}
|
||||
|
||||
@student_works.each do |tmpwork|
|
||||
@works_hash[tmpwork.id] = tmpwork
|
||||
puts tmpwork.id
|
||||
end
|
||||
|
||||
#respond_to do |format|
|
||||
|
@ -1071,7 +1090,7 @@ class CoursesController < ApplicationController
|
|||
#删除课程
|
||||
#删除课程只是将课程的is_deleted状态改为false,is_deleted为false状态的课程只有管理员可以看到
|
||||
def destroy
|
||||
@course.update_attributes(:is_delete => true)
|
||||
@course.delete!
|
||||
@course = nil
|
||||
redirect_to user_url(User.current)
|
||||
end
|
||||
|
@ -1148,33 +1167,37 @@ class CoursesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def student_homework_score(groupid,start_from, nums, score_sort_by)
|
||||
def student_homework_score(groupid,start_from, nums, score_sort_by, sort_type = 'score')
|
||||
start_from = start_from * nums
|
||||
sql_select = ""
|
||||
if groupid == 0
|
||||
sql_select = "SELECT members.*,(
|
||||
SELECT SUM(IF(student_works.final_score IS NULL,NULL,IF(student_works.final_score =0,0,IF((student_works.final_score - student_works.absence_penalty - student_works.late_penalty) < 0 , 0, student_works.final_score - student_works.absence_penalty - student_works.late_penalty))))
|
||||
SELECT SUM(student_works.work_score)
|
||||
FROM student_works,homework_commons
|
||||
WHERE student_works.homework_common_id = homework_commons.id
|
||||
AND homework_commons.course_id = #{@course.id}
|
||||
AND student_works.user_id = members.user_id
|
||||
) AS score
|
||||
) AS score,(SELECT (message_num*2 + message_reply_num*1 + news_reply_num*1 + news_num*1 +
|
||||
resource_num*5 + journal_num*1 + homework_journal_num*1 ) FROM `course_contributor_scores` AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id
|
||||
) AS act_score
|
||||
FROM members
|
||||
JOIN students_for_courses
|
||||
ON students_for_courses.student_id = members.user_id AND students_for_courses.course_id = members.course_id
|
||||
WHERE members.course_id = #{@course.id} ORDER BY score #{score_sort_by}"
|
||||
WHERE members.course_id = #{@course.id} ORDER BY #{sort_type} #{score_sort_by}"
|
||||
else
|
||||
sql_select = "SELECT members.*,(
|
||||
SELECT SUM(IF(student_works.final_score IS NULL,NULL,IF(student_works.final_score =0,0,IF((student_works.final_score - student_works.absence_penalty - student_works.late_penalty) < 0 , 0, student_works.final_score - student_works.absence_penalty - student_works.late_penalty))))
|
||||
SELECT SUM(student_works.work_score)
|
||||
FROM student_works,homework_commons
|
||||
WHERE student_works.homework_common_id = homework_commons.id
|
||||
AND homework_commons.course_id = #{@course.id}
|
||||
AND student_works.user_id = members.user_id
|
||||
) AS score
|
||||
) AS score,(SELECT (message_num*2 + message_reply_num*1 + news_reply_num*1 + news_num*1 +
|
||||
resource_num*5 + journal_num*1 + homework_journal_num*1 ) FROM `course_contributor_scores` AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = members.user_id
|
||||
) AS act_score
|
||||
FROM members
|
||||
JOIN students_for_courses
|
||||
ON students_for_courses.student_id = members.user_id AND students_for_courses.course_id = members.course_id
|
||||
WHERE members.course_id = #{@course.id} AND members.course_group_id = #{groupid} ORDER BY score #{score_sort_by}"
|
||||
WHERE members.course_id = #{@course.id} AND members.course_group_id = #{groupid} ORDER BY #{sort_type} #{score_sort_by}"
|
||||
end
|
||||
sql = ActiveRecord::Base.connection()
|
||||
homework_scores = Member.find_by_sql(sql_select)
|
||||
|
@ -1202,7 +1225,7 @@ class CoursesController < ApplicationController
|
|||
def member_to_xls homeworks, course, members,groups
|
||||
xls_report = StringIO.new
|
||||
book = Spreadsheet::Workbook.new
|
||||
sheet1 = book.create_worksheet :name => "student"
|
||||
sheet1 = book.create_worksheet :name => "总成绩"
|
||||
blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
|
||||
#sheet1.row(0).default_format = blue
|
||||
#sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_class),l(:excel_f_score),l(:excel_commit_time)])
|
||||
|
@ -1224,8 +1247,7 @@ class CoursesController < ApplicationController
|
|||
sheet1[5,i+4] = "第"+(i+1).to_s+"次"
|
||||
end
|
||||
sheet1[5,homeworks.count+4] = "总成绩"
|
||||
sheet1[5,0] = "排名"
|
||||
sheet1[5,0] = "排名"
|
||||
sheet1[5,homeworks.count+5] = "活跃度"
|
||||
count_row = 6
|
||||
members.each_with_index do |member, i|
|
||||
sheet1[count_row,0]= i+1
|
||||
|
@ -1235,17 +1257,133 @@ class CoursesController < ApplicationController
|
|||
homeworks.each_with_index do |homework, j|
|
||||
student_works = homework.student_works.where("user_id = #{member.user.id}")
|
||||
if student_works.empty?
|
||||
sheet1[count_row,j+4] = format("%0.2f",0)
|
||||
sheet1[count_row,j+4] = 0
|
||||
else
|
||||
final_score = student_works.first.final_score.nil? ? 0 : student_works.first.final_score
|
||||
score = final_score - student_works.first.absence_penalty - student_works.first.late_penalty
|
||||
sheet1[count_row,j+4] = format("%0.2f",score <0 ? 0:score)
|
||||
sheet1[count_row,j+4] = score <0 ? 0:score.round(2)
|
||||
end
|
||||
end
|
||||
sheet1[count_row,homeworks.count+4] = format("%0.2f",member.score.nil? ? 0:member.score.to_s)
|
||||
sheet1[count_row,homeworks.count+4] = member.score.nil? ? 0:member.score.round(2)
|
||||
sheet1[count_row,homeworks.count+5] = member.act_score.nil? ? 0:member.act_score
|
||||
count_row += 1
|
||||
end
|
||||
|
||||
homeworks.each_with_index do |home, i|
|
||||
sheet = book.create_worksheet :name => "第#{i+1}次作业"
|
||||
sheet[0,0] = "课程编号"
|
||||
sheet[0,1] = course.id
|
||||
sheet[1,0] = "课程学期"
|
||||
sheet[1,1] = course.time.to_s+"年"+course.term
|
||||
sheet[2,0] = "课程名称"
|
||||
sheet[2,1] = course.name
|
||||
sheet[3,0] = "教师团队"
|
||||
sheet[3,1] = (searchTeacherAndAssistant course).map{|member| member.user.show_name}.join('、')
|
||||
sheet[4,0] = "主讲教师"
|
||||
sheet[4,1] = course.teacher.show_name
|
||||
sheet[4,0] = "作业批次"
|
||||
sheet[4,1] = "第#{i+1}次作业"
|
||||
sheet[4,0] = "作业名称"
|
||||
sheet[4,1] = home.name
|
||||
if home.homework_type == 1 #普通作业
|
||||
if home.anonymous_comment ==0
|
||||
sheet.row(5).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(5).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 = 6
|
||||
items = home.student_works.order("work_score desc")
|
||||
items.each_with_index do |stu, j|
|
||||
sheet[count_row,0]= j + 1
|
||||
sheet[count_row,1] = stu.user.show_name
|
||||
sheet[count_row,2] = stu.user.login
|
||||
sheet[count_row,3] = stu.user.user_extensions.student_id
|
||||
sheet[count_row,4] = stu.name
|
||||
sheet[count_row,5] = strip_html stu.description
|
||||
sheet[count_row,6] = stu.teacher_score.nil? ? l(:label_without_score) : stu.teacher_score.round(2)
|
||||
sheet[count_row,7] = stu.teaching_asistant_score.nil? ? l(:label_without_score) : stu.teaching_asistant_score.round(2)
|
||||
if home.anonymous_comment ==0
|
||||
sheet[count_row,8] = stu.student_score.nil? ? l(:label_without_score) : stu.student_score.round(2)
|
||||
sheet[count_row,9] = (home.teacher_priority == 1 && !stu.teacher_score.nil?) ? 0 : stu.absence_penalty
|
||||
sheet[count_row,10] = (home.teacher_priority == 1 && !stu.teacher_score.nil?) ? 0 : stu.late_penalty
|
||||
sheet[count_row,11] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(2)
|
||||
sheet[count_row,12] = format_time(stu.created_at)
|
||||
else
|
||||
sheet[count_row,8] = (home.teacher_priority == 1 && !stu.teacher_score.nil?) ? 0 : stu.late_penalty
|
||||
sheet[count_row,9] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(2)
|
||||
sheet[count_row,10] = format_time(stu.created_at)
|
||||
end
|
||||
count_row += 1
|
||||
end
|
||||
elsif home.homework_type == 2 #编程作业
|
||||
if home.anonymous_comment ==0
|
||||
sheet.row(5).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(5).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 = 6
|
||||
items = home.student_works.order("work_score desc")
|
||||
items.each_with_index do |stu, j|
|
||||
sheet[count_row,0]= j + 1
|
||||
sheet[count_row,1] = stu.user.show_name
|
||||
sheet[count_row,2] = stu.user.login
|
||||
sheet[count_row,3] = stu.user.user_extensions.student_id
|
||||
sheet[count_row,4] = stu.name
|
||||
sheet[count_row,5] = stu.description
|
||||
sheet[count_row,6] = stu.teacher_score.nil? ? l(:label_without_score) : stu.teacher_score.round(2)
|
||||
sheet[count_row,7] = stu.teaching_asistant_score.nil? ? l(:label_without_score) : stu.teaching_asistant_score.round(2)
|
||||
sheet[count_row,8] = stu.system_score.nil? ? l(:label_without_score) : stu.system_score.round(2)
|
||||
if home.anonymous_comment ==0
|
||||
sheet[count_row,9] = stu.student_score.nil? ? l(:label_without_score) : stu.student_score.round(2)
|
||||
sheet[count_row,10] = (home.teacher_priority == 1 && !stu.teacher_score.nil?) ? 0 : stu.absence_penalty
|
||||
sheet[count_row,11] = (home.teacher_priority == 1 && !stu.teacher_score.nil?) ? 0 : stu.late_penalty
|
||||
sheet[count_row,12] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(2)
|
||||
sheet[count_row,13] = format_time(stu.created_at)
|
||||
else
|
||||
sheet[count_row,9] = (home.teacher_priority == 1 && !stu.teacher_score.nil?) ? 0 : stu.late_penalty
|
||||
sheet[count_row,10] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(2)
|
||||
sheet[count_row,11] = format_time(stu.created_at)
|
||||
end
|
||||
count_row += 1
|
||||
end
|
||||
elsif home.homework_type == 3 #分组作业
|
||||
if home.anonymous_comment ==0
|
||||
sheet.row(5).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(5).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 = 6
|
||||
items = home.student_works.order("work_score desc")
|
||||
items.each_with_index do |stu, j|
|
||||
sheet[count_row,0] = j + 1
|
||||
sheet[count_row,1] = get_group_member_names stu
|
||||
sheet[count_row,2] = stu.name
|
||||
sheet[count_row,3] = (stu.project_id == 0 || stu.project_id.nil?) ? l(:excel_no_project) : stu.project.name
|
||||
sheet[count_row,4] = strip_html stu.description
|
||||
sheet[count_row,5] = stu.teacher_score.nil? ? l(:label_without_score) : stu.teacher_score.round(2)
|
||||
sheet[count_row,6] = stu.teaching_asistant_score.nil? ? l(:label_without_score) : stu.teaching_asistant_score.round(2)
|
||||
if home.anonymous_comment ==0
|
||||
sheet[count_row,7] = stu.student_score.nil? ? l(:label_without_score) : stu.student_score.round(2)
|
||||
sheet[count_row,8] = (home.teacher_priority == 1 && !stu.teacher_score.nil?) ? 0 : stu.absence_penalty
|
||||
sheet[count_row,9] = (home.teacher_priority == 1 && !stu.teacher_score.nil?) ? 0 : stu.late_penalty
|
||||
sheet[count_row,10] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(2)
|
||||
sheet[count_row,11] = format_time(stu.created_at)
|
||||
else
|
||||
sheet[count_row,7] = (home.teacher_priority == 1 && !stu.teacher_score.nil?) ? 0 : stu.late_penalty
|
||||
sheet[count_row,8] = stu.work_score.nil? ? l(:label_without_score) : stu.work_score.round(2)
|
||||
sheet[count_row,9] = format_time(stu.created_at)
|
||||
end
|
||||
count_row += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
=begin
|
||||
group0 = CourseGroup.new();
|
||||
group0.id = 0;
|
||||
|
|
|
@ -49,6 +49,11 @@ class ExerciseController < ApplicationController
|
|||
return
|
||||
end
|
||||
@exercise = Exercise.find params[:id]
|
||||
@exercise.course_messages.each do |message|
|
||||
if User.current.id == message.user_id && message.viewed == 0
|
||||
message.update_attributes(:viewed => true) if message.viewed == 0
|
||||
end
|
||||
end
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
||||
exercise_end = @exercise.end_time > Time.now
|
||||
if @exercise.time == -1
|
||||
|
@ -506,7 +511,7 @@ class ExerciseController < ApplicationController
|
|||
def commit_exercise
|
||||
# 老师不需要提交
|
||||
if User.current.allowed_to?(:as_teacher,@course)
|
||||
if @exercise.publish_time.nil?
|
||||
if @exercise.publish_time.nil? || @exercise.publish_time <= Time.now
|
||||
@exercise.update_attributes(:show_result => params[:show_result])
|
||||
@exercise.update_attributes(:exercise_status => 2)
|
||||
@exercise.update_attributes(:publish_time => Time.now)
|
||||
|
|
|
@ -26,7 +26,7 @@ class FilesController < ApplicationController
|
|||
before_filter :authorize, :except => [:create,:getattachtype,:quote_resource_show,:search,:searchone4reload,:search_project,:quote_resource_show_project,
|
||||
:search_tag_attachment,:subfield_upload_file,:search_org_subfield_tag_attachment,
|
||||
:search_tag_attachment,:quote_resource_show_org_subfield,:find_org_subfield_attache,
|
||||
:search_files_in_subfield,:upload_files_menu,:file_hidden,:republish_file]
|
||||
:search_files_in_subfield,:upload_files_menu,:file_hidden,:republish_file,:update_file_description]
|
||||
|
||||
helper :sort
|
||||
include SortHelper
|
||||
|
@ -256,6 +256,13 @@ class FilesController < ApplicationController
|
|||
@order = ""
|
||||
@is_remote = false
|
||||
if params[:project_id]
|
||||
# 更新资源申请消息为已读
|
||||
# ar_ids = ApplyResource.where("user_id =? and container_id =? and container_type =?", User.current.id, params[:project_id].to_i, "Project").map{|ar| ar.id}
|
||||
# cms = CourseMessage.where("course_message_type =? and user_id =? and course_message_id in (#{ar_ids.empty? ? '0': ar_ids.join(',')})", "ApplyResource", User.current.id)
|
||||
# cms.each do |cm|
|
||||
# cm.update_column(:viewed, true)
|
||||
# end
|
||||
# over
|
||||
@page = params[:page] ? params[:page].to_i + 1 : 2
|
||||
@container_type = 0
|
||||
if params[:sort]
|
||||
|
@ -476,6 +483,7 @@ class FilesController < ApplicationController
|
|||
if !attachments.empty? && attachments[:files] && tag_name != ""
|
||||
attachments[:files].each do |attachment|
|
||||
attachment.tag_list.add(tag_name)
|
||||
attachment.description = params[:description]
|
||||
attachment.save
|
||||
end
|
||||
end
|
||||
|
@ -486,6 +494,7 @@ class FilesController < ApplicationController
|
|||
if !attachments.empty? && attachments[:files] && tag_name != ""
|
||||
attachments[:files].each do |attachment|
|
||||
attachment.tag_list.add(tag_name)
|
||||
attachment.description = params[:description]
|
||||
attachment.save
|
||||
end
|
||||
end
|
||||
|
@ -593,6 +602,7 @@ class FilesController < ApplicationController
|
|||
if !attachments.empty? && attachments[:files] && tag_name != ""
|
||||
attachments[:files].each do |attachment|
|
||||
attachment.tag_list.add(tag_name)
|
||||
attachment.description = params[:description]
|
||||
attachment.save
|
||||
end
|
||||
end
|
||||
|
@ -603,6 +613,7 @@ class FilesController < ApplicationController
|
|||
if !attachments.empty? && attachments[:files] && tag_name != ""
|
||||
attachments[:files].each do |attachment|
|
||||
attachment.tag_list.add(tag_name)
|
||||
attachment.description = params[:description]
|
||||
attachment.save
|
||||
end
|
||||
end
|
||||
|
@ -904,5 +915,10 @@ class FilesController < ApplicationController
|
|||
|
||||
def upload_files_menu
|
||||
|
||||
end
|
||||
end
|
||||
def update_file_description
|
||||
@attachment = Attachment.find(params[:id])
|
||||
@attachment.description = params[:description]
|
||||
@attachment.save
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,21 +11,27 @@ class HomeworkCommonController < ApplicationController
|
|||
before_filter :member_of_course, :only => [:index]
|
||||
|
||||
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
|
||||
@page = params[:page] ? params[:page].to_i + 1 : 0
|
||||
@is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course))
|
||||
if @is_teacher
|
||||
@homeworks = @course.homework_commons.order("updated_at desc").limit(10).offset(@page * 10)
|
||||
@homework_commons = @course.homework_commons.order("created_at desc")
|
||||
#@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")
|
||||
else
|
||||
@homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("updated_at desc").limit(10).offset(@page * 10)
|
||||
@homework_commons = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at desc")
|
||||
#@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 <= '#{Date.today}'").order("created_at desc")
|
||||
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
|
||||
#设置at已读
|
||||
@homeworks.each do |homework|
|
||||
homework.journals_for_messages.each do |j|
|
||||
|
@ -73,16 +79,23 @@ class HomeworkCommonController < ApplicationController
|
|||
else
|
||||
@homework.publish_time = params[:homework_common][:publish_time]
|
||||
end
|
||||
homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new
|
||||
@homework.end_time = params[:homework_common][:end_time] || Time.now
|
||||
@homework.course_id = params[:course_id]
|
||||
@homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment] : 0
|
||||
anonymous = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment].to_i : 0
|
||||
if anonymous != @homework.anonymous_comment
|
||||
if anonymous == 1
|
||||
homework_detail_manual.ta_proportion = @homework.homework_type == 1 ? 1.0 : 0.4
|
||||
else
|
||||
homework_detail_manual.ta_proportion = @homework.homework_type == 1 ? 0.6 : 0.3
|
||||
end
|
||||
end
|
||||
|
||||
homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new
|
||||
if @homework.publish_time <= Date.today && homework_detail_manual.comment_status == 0
|
||||
homework_detail_manual.comment_status = 1
|
||||
end
|
||||
eval_start = homework_detail_manual.evaluation_start
|
||||
if eval_start <= @homework.end_time && homework_detail_manual.comment_status <= 1
|
||||
if eval_start.nil? || (eval_start <= @homework.end_time && homework_detail_manual.comment_status <= 1)
|
||||
homework_detail_manual.evaluation_start = @homework.end_time + 7
|
||||
homework_detail_manual.evaluation_end = homework_detail_manual.evaluation_start + 7
|
||||
end
|
||||
|
@ -94,6 +107,13 @@ 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 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_tests.delete_all
|
||||
inputs = params[:program][:input]
|
||||
|
@ -116,8 +136,9 @@ class HomeworkCommonController < ApplicationController
|
|||
@homework_detail_group.base_on_project = params[:base_on_project].to_i
|
||||
end
|
||||
|
||||
@homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment].to_i : 0
|
||||
if @homework.save
|
||||
@homework_detail_manual.save if @homework_detail_manual
|
||||
homework_detail_manual.save if homework_detail_manual
|
||||
@homework_detail_programing.save if @homework_detail_programing
|
||||
@homework_detail_group.save if @homework_detail_group
|
||||
|
||||
|
@ -158,7 +179,7 @@ class HomeworkCommonController < ApplicationController
|
|||
@statue = 4 and return unless User.current.admin? || User.current.allowed_to?(:as_teacher,@course)
|
||||
@statue = 5 and return if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d")
|
||||
if @homework_detail_manual.comment_status == 1
|
||||
student_works = @homework.student_works
|
||||
student_works = @homework.student_works.has_committed
|
||||
if student_works && student_works.size >= 2
|
||||
if @homework.homework_type == 3
|
||||
student_work_projects = @homework.student_work_projects.where("student_work_id is not null")
|
||||
|
@ -212,8 +233,8 @@ class HomeworkCommonController < ApplicationController
|
|||
@homework_detail_manual.update_column('comment_status', 3)
|
||||
@homework_detail_manual.update_column('evaluation_end', Date.today)
|
||||
#计算缺评扣分
|
||||
work_ids = "(" + @homework.student_works.map(&:id).join(",") + ")"
|
||||
@homework.student_works.each do |student_work|
|
||||
work_ids = "(" + @homework.student_works.has_committed.map(&:id).join(",") + ")"
|
||||
@homework.student_works.has_committed.each do |student_work|
|
||||
absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - student_work.user.student_works_scores.where("student_work_id IN #{work_ids}").count
|
||||
student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * @homework_detail_manual.absence_penalty : 0
|
||||
student_work.save
|
||||
|
@ -243,11 +264,11 @@ class HomeworkCommonController < ApplicationController
|
|||
@totle_size = 0
|
||||
if @homework_detail_manual.comment_status == 1
|
||||
@totle_size = @course.student.count
|
||||
@cur_size = @homework.student_works.size
|
||||
@cur_size = @homework.student_works.has_committed.size
|
||||
elsif @homework_detail_manual.comment_status == 2
|
||||
@homework.student_works.map { |work| @totle_size += work.student_works_evaluation_distributions.count}
|
||||
@homework.student_works.has_committed.map { |work| @totle_size += work.student_works_evaluation_distributions.count}
|
||||
@cur_size = 0
|
||||
@homework.student_works.map { |work| @cur_size += work.student_works_scores.where(:reviewer_role => 3).count}
|
||||
@homework.student_works.has_committed.map { |work| @cur_size += work.student_works_scores.select("distinct user_id").where(:reviewer_role => 3).count}
|
||||
end
|
||||
@percent = format("%.2f",(@cur_size.to_f / ( @totle_size == 0 ? 1 : @totle_size)) * 100)
|
||||
@user_activity_id = params[:user_activity_id].to_i
|
||||
|
@ -273,9 +294,9 @@ class HomeworkCommonController < ApplicationController
|
|||
|
||||
def open_student_works
|
||||
if @homework.is_open == 0
|
||||
@homework.update_attribute(:is_open, 1)
|
||||
@homework.update_column('is_open', 1)
|
||||
else
|
||||
@homework.update_attribute(:is_open, 0)
|
||||
@homework.update_column('is_open', 0)
|
||||
end
|
||||
@user_activity_id = params[:user_activity_id]
|
||||
@is_in_course = params[:is_in_course] if params[:is_in_course]
|
||||
|
@ -385,4 +406,56 @@ class HomeworkCommonController < ApplicationController
|
|||
student_works += student_works
|
||||
student_works[index + 1 .. index + n]
|
||||
end
|
||||
|
||||
def update_homework_time homeworks
|
||||
unless homeworks.nil?
|
||||
homeworks.each do |h|
|
||||
if h.homework_type == 3 && h.homework_detail_group.base_on_project == 1
|
||||
student_works = h.student_work_projects.where("is_leader = 1 && project_id != -1")
|
||||
time = h.updated_at
|
||||
unless student_works.nil?
|
||||
student_works.each do |s|
|
||||
project = Project.find s.project_id
|
||||
unless project.nil? && project.gpid.nil?
|
||||
project_time=project.updated_on
|
||||
project_time=ForgeActivity.where("project_id=?",project.id).last.updated_at if ForgeActivity.where("project_id=?",project.id).last
|
||||
if time.strftime('%Y-%m-%d %H:%M:%S') < project_time.strftime('%Y-%m-%d %H:%M:%S')
|
||||
time = project_time
|
||||
end
|
||||
begin
|
||||
# gitlab端获取默认分支
|
||||
g = Gitlab.client
|
||||
default_branch = g.project(project.gpid).default_branch
|
||||
changesets = g.commits(project.gpid, :ref_name => default_branch)
|
||||
changesets_latest_coimmit = changesets[0]
|
||||
unless changesets[0].blank?
|
||||
if time.strftime('%Y-%m-%d %H:%M:%S') <changesets_latest_coimmit.created_at.strftime('%Y-%m-%d %H:%M:%S')
|
||||
time = changesets_latest_coimmit.created_at
|
||||
end
|
||||
end
|
||||
rescue
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
s_time = time
|
||||
if time.strftime('%Y-%m-%d %H:%M:%S') > h.updated_at.strftime('%Y-%m-%d %H:%M:%S')
|
||||
h.update_column('updated_at', s_time)
|
||||
course_activity = CourseActivity.where("course_act_type=? and course_act_id =?", 'HomeworkCommon', h.id).first
|
||||
if course_activity && (time.strftime('%Y-%m-%d %H:%M:%S') > course_activity.updated_at.strftime('%Y-%m-%d %H:%M:%S'))
|
||||
course_activity.update_column('updated_at', s_time)
|
||||
end
|
||||
user_activity = UserActivity.where("act_type=? and act_id =?", 'HomeworkCommon', h.id).first
|
||||
if user_activity && (time.strftime('%Y-%m-%d %H:%M:%S') > user_activity.updated_at.strftime('%Y-%m-%d %H:%M:%S'))
|
||||
user_activity.update_column('updated_at', s_time)
|
||||
end
|
||||
org_activity = OrgActivity.where("org_act_type=? and org_act_id =?", 'HomeworkCommon', h.id).first
|
||||
if org_activity && (time.strftime('%Y-%m-%d %H:%M:%S') > org_activity.updated_at.strftime('%Y-%m-%d %H:%M:%S'))
|
||||
org_activity.update_column('updated_at', s_time)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -44,7 +44,8 @@ class MessagesController < ApplicationController
|
|||
offset = @topic.children.count(:conditions => ["#{Message.table_name}.id < ?", params[:r].to_i])
|
||||
page = 1 + offset / REPLIES_PER_PAGE
|
||||
end
|
||||
@reply_count = @topic.children.count
|
||||
all_comments = []
|
||||
@reply_count = get_all_children(all_comments, @topic).count
|
||||
@reply = Message.new(:subject => "RE: #{@message.subject}")
|
||||
if @course
|
||||
messages_replies = @topic.children.
|
||||
|
@ -137,26 +138,32 @@ class MessagesController < ApplicationController
|
|||
|
||||
# Reply to a topic
|
||||
def reply
|
||||
if params[:reply][:content] == ""
|
||||
if params[:is_board]
|
||||
if @project
|
||||
(redirect_to project_boards_path(@project), :notice => l(:label_reply_empty);return)
|
||||
elsif @course
|
||||
(redirect_to course_boards_path(@course), :notice => l(:label_reply_empty);return)
|
||||
end
|
||||
else
|
||||
(redirect_to board_message_url(@board, @topic, :r => @reply), :notice => l(:label_reply_empty);return)
|
||||
end
|
||||
if params[:parent_id]
|
||||
parent = Message.find params[:parent_id]
|
||||
@reply = Message.new
|
||||
@reply.author = User.current
|
||||
@reply.board = parent.board
|
||||
@reply.content = params[:content]
|
||||
@reply.subject = "RE: #{parent.subject}"
|
||||
@reply.reply_id = params[:reply_id]
|
||||
# @reply.reply_id = params[:id]
|
||||
parent.children << @reply
|
||||
@topic = params[:activity_id].nil? ? parent : Message.find(params[:activity_id].to_i)
|
||||
@user_activity_id = params[:user_activity_id] if params[:user_activity_id]
|
||||
@is_course = params[:is_course] if params[:is_course]
|
||||
@is_board = params[:is_board] if params[:is_board]
|
||||
else
|
||||
@quote = params[:quote][:quote]
|
||||
@reply = Message.new
|
||||
@reply.author = User.current
|
||||
@reply.board = @board
|
||||
@reply.safe_attributes = params[:reply]
|
||||
@reply.content = @quote + @reply.content
|
||||
@reply.subject = "RE: #{@topic.subject}" unless params[:reply][:subject]
|
||||
@topic.children << @reply
|
||||
# @reply.reply_id = params[:id]
|
||||
end
|
||||
@quote = params[:quote][:quote]
|
||||
@reply = Message.new
|
||||
@reply.author = User.current
|
||||
@reply.board = @board
|
||||
@reply.safe_attributes = params[:reply]
|
||||
@reply.content = @quote + @reply.content
|
||||
@reply.subject = "RE: #{@topic.subject}" unless params[:reply][:subject]
|
||||
# @reply.reply_id = params[:id]
|
||||
@topic.children << @reply
|
||||
|
||||
update_course_activity(@topic.class,@topic.id)
|
||||
update_user_activity(@topic.class,@topic.id)
|
||||
update_forge_activity(@topic.class,@topic.id)
|
||||
|
@ -182,14 +189,10 @@ class MessagesController < ApplicationController
|
|||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
elsif params[:is_board]
|
||||
if @project
|
||||
redirect_to project_boards_path(@project)
|
||||
elsif @course
|
||||
redirect_to course_boards_path(@course)
|
||||
end
|
||||
return
|
||||
else
|
||||
redirect_to board_message_url(@board, @topic, :r => @reply)
|
||||
redirect_to board_message_url(@board, @topic)
|
||||
return
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -251,6 +254,17 @@ class MessagesController < ApplicationController
|
|||
|
||||
# Delete a messages
|
||||
def destroy
|
||||
if params[:user_activity_id]
|
||||
@message.destroy
|
||||
@topic = Message.find(params[:activity_id].to_i)
|
||||
@user_activity_id = params[:user_activity_id]
|
||||
@is_course = params[:is_course]
|
||||
@is_board = params[:is_board]
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
return
|
||||
end
|
||||
if @project
|
||||
(render_403; return false) unless @message.destroyable_by?(User.current)
|
||||
elsif @course
|
||||
|
@ -299,12 +313,12 @@ class MessagesController < ApplicationController
|
|||
end
|
||||
|
||||
def quote
|
||||
@subject = @message.subject
|
||||
@subject = "RE: #{@subject}" unless @subject.starts_with?('RE:')
|
||||
|
||||
@content = "> #{ll(Setting.default_language, :text_user_wrote, @message.author)}\n> "
|
||||
@temp = Message.new
|
||||
@temp.content = "<blockquote>#{ll(Setting.default_language, :text_user_wrote, @message.author)} <br/>#{@message.content.html_safe}</blockquote>".html_safe
|
||||
# @subject = @message.subject
|
||||
# @subject = "RE: #{@subject}" unless @subject.starts_with?('RE:')
|
||||
#
|
||||
# @content = "> #{ll(Setting.default_language, :text_user_wrote, @message.author)}\n> "
|
||||
# @temp = Message.new
|
||||
# @temp.content = "<blockquote>#{ll(Setting.default_language, :text_user_wrote, @message.author.show_name)} <br/>#{@message.content.html_safe}</blockquote>".html_safe
|
||||
end
|
||||
|
||||
def preview
|
||||
|
|
|
@ -127,12 +127,14 @@ class MyController < ApplicationController
|
|||
end
|
||||
|
||||
@user.safe_attributes = params[:user]
|
||||
@user.lastname = params[:lastname]
|
||||
@user.firstname = ""
|
||||
@user.pref.attributes = params[:pref]
|
||||
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
|
||||
#@user.login = params[:login]
|
||||
unless @user.user_extensions.nil?
|
||||
if @user.user_extensions.identity == 2
|
||||
@user.firstname = params[:enterprise_name]
|
||||
# @user.firstname = params[:enterprise_name]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -144,7 +146,7 @@ class MyController < ApplicationController
|
|||
# end
|
||||
@se.school_id = params[:occupation]
|
||||
|
||||
@se.gender = params[:gender]
|
||||
@se.gender = params[:sex]
|
||||
@se.location = params[:province] if params[:province]
|
||||
@se.location_city = params[:city] if params[:city]
|
||||
@se.identity = params[:identity].to_i if params[:identity]
|
||||
|
|
|
@ -70,25 +70,71 @@ class NewsController < ApplicationController
|
|||
end
|
||||
elsif @course
|
||||
if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course)))
|
||||
@order, @b_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1
|
||||
|
||||
#确定 sort_type 1升序 2 降序
|
||||
if @order.to_i == @type.to_i
|
||||
@b_sort = @b_sort.to_i == 1 ? 2 : 1
|
||||
else
|
||||
@b_sort = 2
|
||||
end
|
||||
|
||||
sort_name = "updated_at"
|
||||
|
||||
sort_type = @b_sort == 1 ? "asc" : "desc"
|
||||
|
||||
#scope = News.find_by_sql("select a.*,b.updated_at from news a, course_activities b where a.course_id = 532 and a.course_id = b.course_id and b.course_act_id = a.id ) ")
|
||||
|
||||
scope = @course ? @course.news.course_visible : News.course_visible
|
||||
news_arr = scope.map{|news| news.id}
|
||||
|
||||
|
||||
@page = params[:page] ? params[:page].to_i + 1 : 0
|
||||
news_page = @page *10
|
||||
news_page = 0 #@page *10
|
||||
@news_count = scope.count
|
||||
@is_new = params[:is_new]
|
||||
@q = params[:subject]
|
||||
if params[:subject].nil? || params[:subject].blank?
|
||||
scope_order = scope.reorder("#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC").limit(10).offset(news_page).includes(:author,:course).all()
|
||||
scope_order = scope.reorder("#{News.table_name}.sticky DESC, #{News.table_name}.created_on #{sort_type}").offset(news_page).includes(:author,:course).all()
|
||||
#all(:include => [:author, :course],
|
||||
#:order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC").limit(10).offset(news_page)
|
||||
else
|
||||
scope_order = scope.where("#{News.table_name}.title like '#{'%' << params[:subject].to_s << '%'}'").reorder("#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC").limit(10).offset(news_page).includes(:author,:course).all()
|
||||
scope_order = scope.where("#{News.table_name}.title like '#{'%' << params[:subject].to_s << '%'}'").reorder("#{News.table_name}.sticky DESC, #{News.table_name}.#{sort_name} #{sort_type}").offset(news_page).includes(:author,:course).all()
|
||||
#.all(:include => [:author, :course],:order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC")
|
||||
end
|
||||
|
||||
scope_order.each do |topic|
|
||||
topic[:updated_at] = topic.course_acts.first.updated_at
|
||||
#topic[:updated_at] = CourseActivity.where("course_act_type='#{topic.class}' and course_act_id =#{topic.id}").first.updated_at
|
||||
end
|
||||
|
||||
#根据 赞+回复数排序
|
||||
if @order.to_i == 2
|
||||
@type = 2
|
||||
scope_order.each do |topic|
|
||||
topic[:infocount] = get_praise_num(topic) + topic.comments.count
|
||||
if topic[:infocount] < 0
|
||||
topic[:infocount] = 0
|
||||
end
|
||||
end
|
||||
@b_sort == 1 ? scope_order = scope_order.sort{|x,y| x[:infocount] <=> y[:infocount] } : scope_order = scope_order.sort{|x,y| y[:infocount] <=> x[:infocount] }
|
||||
scope_order = sort_by_sticky scope_order
|
||||
scope_order = sortby_time_countcommon_hassticky scope_order,sort_name
|
||||
else
|
||||
@type = 1
|
||||
@b_sort == 1 ? scope_order = scope_order.sort{|x,y| x[:updated_at] <=> y[:updated_at] } : scope_order = scope_order.sort{|x,y| y[:updated_at] <=> x[:updated_at] }
|
||||
scope_order = sort_by_sticky scope_order
|
||||
end
|
||||
|
||||
@newss = scope_order
|
||||
|
||||
#分页
|
||||
@limit = 15
|
||||
@is_remote = true
|
||||
@atta_count = @newss.count
|
||||
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
|
||||
@offset ||= @atta_pages.offset
|
||||
@newss = paginateHelper @newss,@limit
|
||||
|
||||
#@newss = paginateHelper scope_order,10
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class OrgDocumentCommentsController < ApplicationController
|
||||
before_filter :find_organization, :only => [:new, :create, :show, :index]
|
||||
before_filter :authorize_allowed, :only => [:create, :add_reply]
|
||||
helper :attachments,:organizations
|
||||
layout 'base_org'
|
||||
|
||||
|
@ -12,6 +13,7 @@ class OrgDocumentCommentsController < ApplicationController
|
|||
@org_document_comment = OrgDocumentComment.new(:organization_id => @organization.id, :creator_id => User.current.id)
|
||||
@org_document_comment.title = params[:org_document_comment][:title]
|
||||
@org_document_comment.content = params[:org_document_comment][:content]
|
||||
@org_document_comment.status = params[:org_document_comment][:status] == "on" ? 1 : 0
|
||||
@org_document_comment.save_attachments(params[:attachments])
|
||||
if params[:field_id]
|
||||
@org_document_comment.org_subfield_id = params[:field_id].to_i
|
||||
|
@ -36,6 +38,11 @@ class OrgDocumentCommentsController < ApplicationController
|
|||
|
||||
def show
|
||||
@document = OrgDocumentComment.find(params[:id])
|
||||
@org_subfield = OrgSubfield.where(:id => @document.org_subfield_id).first
|
||||
@subfield_content = @organization.org_subfields.order("priority")
|
||||
respond_to do |format|
|
||||
format.html {render :layout => (@organization.switch_type && @document && !@document.org_subfield_id.blank?) ? 'base_org_custom' : 'base_org'}
|
||||
end
|
||||
end
|
||||
|
||||
def index
|
||||
|
@ -79,7 +86,7 @@ class OrgDocumentCommentsController < ApplicationController
|
|||
|
||||
def add_reply
|
||||
@document = OrgDocumentComment.find(params[:id]).root
|
||||
@act = OrgActivity.find(params[:id])
|
||||
@act = OrgActivity.find(params[:act_id])
|
||||
@comment = OrgDocumentComment.new(:organization_id => @document.organization_id, :creator_id => User.current.id, :reply_id => params[:id])
|
||||
@comment.content = params[:org_content]
|
||||
@document.children << @comment
|
||||
|
@ -89,7 +96,12 @@ class OrgDocumentCommentsController < ApplicationController
|
|||
def add_reply_in_doc
|
||||
@document = OrgDocumentComment.find(params[:id]).root
|
||||
@comment = OrgDocumentComment.new(:organization_id => @document.organization_id, :creator_id => User.current.id, :reply_id => params[:id])
|
||||
@comment.content = params[:org_comment][:org_content]
|
||||
if params[:org_comment].blank?
|
||||
@comment.content = params[:org_content]
|
||||
else
|
||||
@comment.content = params[:org_comment][:org_content]
|
||||
end
|
||||
|
||||
@document.children << @comment
|
||||
@document.save
|
||||
respond_to do |format|
|
||||
|
@ -101,8 +113,16 @@ class OrgDocumentCommentsController < ApplicationController
|
|||
@organization = Organization.find(params[:organization_id])
|
||||
end
|
||||
|
||||
def authorize_allowed
|
||||
unless User.current.logged?
|
||||
redirect_to signin_url
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@org_document_comment = OrgDocumentComment.find(params[:id])
|
||||
@org_sub_id = @org_document_comment.org_subfield_id
|
||||
org = @org_document_comment.organization
|
||||
if @org_document_comment.id == org.home_id
|
||||
org.update_attributes(:home_id => nil)
|
||||
|
|
|
@ -54,4 +54,8 @@ class OrgMemberController < ApplicationController
|
|||
def index
|
||||
|
||||
end
|
||||
|
||||
def deleteOrgMember
|
||||
destroy
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,20 +6,41 @@ class OrgSubfieldsController < ApplicationController
|
|||
if OrgSubfield.where("organization_id=#{params[:organization_id]} and name=?",params[:name]).count == 0
|
||||
@res = true
|
||||
@organization = Organization.find(params[:organization_id])
|
||||
@subfield = OrgSubfield.create(:name => params[:name], :organization_id => params[:organization_id],:priority => @organization.org_subfields.order("priority").last.priority + 1)
|
||||
@subfield = OrgSubfield.create(:name => params[:name], :organization_id => params[:organization_id], :priority => @organization.org_subfields.order("priority").last.priority + 1)
|
||||
if !params[:sub_dir].blank?
|
||||
sql = "select subfield_subdomain_dirs.* from subfield_subdomain_dirs, org_subfields where subfield_subdomain_dirs.org_subfield_id = org_subfields.id "+
|
||||
"and org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir]}'"
|
||||
"and org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir]}'"
|
||||
if SubfieldSubdomainDir.find_by_sql(sql).count == 0
|
||||
SubfieldSubdomainDir.create(:org_subfield_id => @subfield.id, :name => params[:sub_dir].downcase)
|
||||
end
|
||||
end
|
||||
@subfield.update_attributes(:field_type => params[:field_type])
|
||||
#默认类型为帖子
|
||||
@subfield.update_attributes(:field_type => params[:field_type]||"Post")
|
||||
# admin配置的类型
|
||||
update_status_by_type(@subfield, params[:field_type]||"Post")
|
||||
else
|
||||
@res = false
|
||||
end
|
||||
end
|
||||
|
||||
# status类型说明,详见SubField
|
||||
def update_status_by_type subfield, type
|
||||
case type
|
||||
when "Resource"
|
||||
subfield.update_attribute(:status, 6)
|
||||
when "Comptec"
|
||||
subfield.update_attribute(:status, 6)
|
||||
when "Compstu"
|
||||
subfield.update_attribute(:status, 7)
|
||||
when "Comppro"
|
||||
subfield.update_attribute(:status, 5)
|
||||
when "Compcou"
|
||||
subfield.update_attribute(:status, 2)
|
||||
when "Compact"
|
||||
subfield.update_attribute(:status, 4)
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@flag = params[:flag] || false
|
||||
sort = ""
|
||||
|
@ -36,6 +57,10 @@ class OrgSubfieldsController < ApplicationController
|
|||
@org_subfield = OrgSubfield.find_by_sql("select distinct org_subfields.* from org_subfields,"+
|
||||
"subfield_subdomain_dirs where org_subfields.id = subfield_subdomain_dirs.org_subfield_id and "+
|
||||
" org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir_name]}'").first
|
||||
if @org_subfield.nil?
|
||||
render_404
|
||||
return
|
||||
end
|
||||
if @org_subfield.field_type == 'Post'
|
||||
@org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0
|
||||
@org_activities = OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{@org_subfield.id})").order('updated_at desc').page(params[:page] || 1).per(10)
|
||||
|
|
|
@ -28,7 +28,9 @@ class OrganizationsController < ApplicationController
|
|||
helper :project_score
|
||||
helper :issues
|
||||
include UsersHelper
|
||||
before_filter :find_organization, :only => [:show, :members, :apply_subdomain, :select_org_layout]
|
||||
include OrganizationsHelper
|
||||
before_filter :find_organization, :only => [:show, :members, :apply_subdomain, :select_org_layout, :teachers, :students, :projects, :courses, :acts]
|
||||
# before_filter :allow_as_admin, :only => [:students, :teachers, :projects, :courses, :acts]
|
||||
layout 'base_org'
|
||||
def index
|
||||
|
||||
|
@ -76,59 +78,64 @@ class OrganizationsController < ApplicationController
|
|||
|
||||
def show
|
||||
# 组织新类型 show_mode:判断标准 1为新类型,0为旧
|
||||
if @organization.show_mode == 1 && params[:org_subfield_id].nil? && params[:list] .nil?
|
||||
if @organization.switch_type && params[:list] .nil?
|
||||
if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
|
||||
# REDO:时间紧,暂时先这样
|
||||
@org_logo_attchment = Attachment.where("container_id =? and container_type =? and attachtype =?", @organization, "Organization", 0).order("created_on desc").first
|
||||
@org_banner_attchment = Attachment.where("container_id =? and container_type =? and attachtype =?", @organization, "Organization", 1).order("created_on desc").first
|
||||
|
||||
unless params[:org_subfield_id].nil?
|
||||
@org_subfield = OrgSubfield.where(:id => params[:org_subfield_id]).first
|
||||
@subfield_acts = get_subfield_acts(@org_subfield)
|
||||
end
|
||||
@subfield_content = @organization.org_subfields.order("priority")
|
||||
@organization = Organization.find(params[:id])
|
||||
# 统计访问量
|
||||
@organization.update_column(:visits, @organization.visits.to_i + 1)
|
||||
|
||||
# @org_subfield = OrgSubfield.find(params[:org_subfield_id])
|
||||
# @org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0
|
||||
# @org_acts = OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{@org_subfield.id})").order('updated_at desc').page(params[:page] || 1).per(10)
|
||||
|
||||
shield_project_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Project'").map(&:shield_id)
|
||||
shield_course_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Course'").map(&:shield_id)
|
||||
project_ids = (@organization.projects.map(&:id)-shield_project_ids) << 0
|
||||
course_ids = (@organization.courses.map(&:id)-shield_course_ids) << 0
|
||||
course_types = "('Message','News','HomeworkCommon','Poll','Course')"
|
||||
@project_acts = get_project_activities_org @organization, project_ids
|
||||
@course_acts = get_course_activities_org @organization, course_ids
|
||||
#@org_acts = OrgActivity.where("container_id =? and container_type =?",@organization.id, 'Organization').order('updated_at desc')
|
||||
#@project_acts = OrgActivity.where("(container_id =? and container_type =?) " +
|
||||
# "or (container_type ='Project' and org_act_type in ('Issue','Message') and container_id in (#{project_ids.join(',')})) ",
|
||||
# @organization.id, 'Organization').order('updated_at desc').limit(8)
|
||||
|
||||
#@course_acts = OrgActivity.where("(container_id =? and container_type =?) " +
|
||||
# "or (container_type ='Course' and org_act_type in #{course_types} and container_id in (#{course_ids.join(',')}))",
|
||||
# @organization.id, 'Organization').order('updated_at desc').limit(8)
|
||||
|
||||
|
||||
|
||||
# 项目两种动态
|
||||
#@project_acts = get_project_activities_org @organization
|
||||
|
||||
# 课程动态
|
||||
#@project_acts_issues = get_project_activities_org @organization
|
||||
#@course_acts = get_course_activities_org @organization
|
||||
|
||||
render :layout => 'base_org_newstyle'
|
||||
shield_project_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Project'").map(&:shield_id)
|
||||
shield_course_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Course'").map(&:shield_id)
|
||||
project_ids = (@organization.projects.map(&:id) - shield_project_ids) << 0
|
||||
course_ids = (@organization.courses.map(&:id) - shield_course_ids) << 0
|
||||
course_types = "('Message','News','HomeworkCommon','Poll','Course')"
|
||||
@project_acts = get_project_activities_org @organization, project_ids
|
||||
@course_acts = get_course_activities_org @organization, course_ids
|
||||
# 精品课程, 不符合条件的组织则不查询
|
||||
if @organization.org_subfields.where(:field_type => "Compcou", :hide => 0).count > 0
|
||||
@excellent_courses = Course.find_by_sql("select c.*, (select count(*) from course_activities where course_activities.course_id = c.id) as course_count
|
||||
from courses c where c.is_delete =0 and c.is_public =1 and is_excellent =1 order by course_count desc limit 5;")
|
||||
end
|
||||
# 热门项目
|
||||
if @organization.org_subfields.where(:field_type => "Comppro", :hide => 0).count > 0
|
||||
# @excellent_projects = Project.where(:is_public => true, :status => true, :hot => true).order("project_score")
|
||||
@excellent_projects = Project.find_by_sql("select p.*, (select count(*) from forge_activities where forge_activities.project_id = p.id) as project_count
|
||||
from projects p where p.status =1 and p.is_public =1 and hot =1 order by project_count desc limit 5;")
|
||||
end
|
||||
# 最新动态, 来自我关联的项目和课程
|
||||
if @organization.org_subfields.where(:field_type => "Compact", :hide => 0).count > 0
|
||||
@acts = UserActivity.find_by_sql("SELECT * FROM `user_activities` where act_type in ('HomeworkCommon', 'News', 'Message', 'Issue') and
|
||||
((container_type = 'Course' and container_id in (#{course_ids.join(',')})) or (container_type = 'Project' and container_id in (#{project_ids.join(',')})))
|
||||
order by created_at desc limit 6;")
|
||||
end
|
||||
render :layout => 'base_org_custom'
|
||||
else
|
||||
render_403
|
||||
end
|
||||
else
|
||||
if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
|
||||
@organization = Organization.find(params[:id])
|
||||
# 统计访问量
|
||||
@organization.update_column(:visits, @organization.visits.to_i + 1)
|
||||
# params[:org_subfield_id] 存在即对应的栏目,否则进入组织动态
|
||||
if params[:org_subfield_id]
|
||||
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
|
||||
@org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0
|
||||
@org_activities = OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{@org_subfield.id})").order('updated_at desc').page(params[:page] || 1).per(10)
|
||||
if @org_subfield.field_type == "Comptec" || @org_subfield.field_type == "Compstu"
|
||||
|
||||
# @org_teachers = User.find_by_sql("select u.*, ue.technical_title, ue.school_id,( SELECT `courses`.* FROM `courses` INNER JOIN `members` ON `courses`.`id` = `members`.`course_id` WHERE `members`.`user_id` = u.id AND (courses.status<>9)) as course_count
|
||||
# from users u, user_extensions ue where u.id = ue.user_id and ue.identity=0 order by course_count desc")
|
||||
@org_teachers = User.find_by_sql("select u.*, ue.technical_title, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count from users u, user_extensions ue where u.id = ue.user_id and ue.identity=0 order by course_count desc")
|
||||
# @org_count = @org_teachers.count
|
||||
# @limit = 25
|
||||
# @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
|
||||
else
|
||||
@org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0
|
||||
@org_activities = OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{@org_subfield.id})").order('updated_at desc').page(params[:page] || 1).per(10)
|
||||
end
|
||||
else
|
||||
shield_project_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Project'").map(&:shield_id)
|
||||
shield_course_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Course'").map(&:shield_id)
|
||||
|
@ -138,7 +145,7 @@ class OrganizationsController < ApplicationController
|
|||
case params[:type]
|
||||
when nil
|
||||
@org_activities = OrgActivity.where("(container_id =? and container_type =?) " +
|
||||
"or (container_type ='Project' and org_act_type in ('Issue','Message','ProjectCreateInfo') and container_id in (#{project_ids.join(',')})) "+
|
||||
"or (container_type ='Project' and org_act_type in ('Issue','Message','Project') and container_id in (#{project_ids.join(',')})) "+
|
||||
"or (container_type ='Course' and org_act_type in #{course_types} and container_id in (#{course_ids.join(',')}))",
|
||||
@organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10)
|
||||
when 'project_issue'
|
||||
|
@ -169,6 +176,127 @@ class OrganizationsController < ApplicationController
|
|||
|
||||
end
|
||||
|
||||
def teachers
|
||||
q = params[:search].nil? ? "" : "#{params[:search].strip}"
|
||||
@field = params[:org_subfield_id].nil? ? OrgSubfield.where("organization_id =? and field_type =?", params[:id].to_i, "Comptec").first : OrgSubfield.find(params[:org_subfield_id])
|
||||
@type = params[:type]
|
||||
if @type.blank?
|
||||
@org_teachers = User.find_by_sql("select u.*, ue.technical_title, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count
|
||||
from users u, user_extensions ue where u.id = ue.user_id and ue.identity=0 and concat(lastname,firstname,login) like '%#{q}%' order by course_count desc")
|
||||
elsif @type == "famous"
|
||||
@org_teachers = User.find_by_sql("select u.*, ue.technical_title, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count
|
||||
from users u, user_extensions ue where u.id = ue.user_id and ue.identity=0 and u.excellent_teacher =1 and concat(lastname,firstname,login) like '%#{q}%' order by course_count desc")
|
||||
end
|
||||
limit = 10
|
||||
# @is_remote = true
|
||||
@teachers_count = @org_teachers.count
|
||||
@atta_pages = Paginator.new @teachers_count, limit, params['page'] || 1
|
||||
@offset ||= @atta_pages.offset
|
||||
#@curse_attachments_all = @all_attachments[@offset, @limit]
|
||||
@org_teachers = paginateHelper @org_teachers, limit
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def students
|
||||
q = params[:search].nil? ? "" : "#{params[:search].strip}"
|
||||
@field = params[:org_subfield_id].nil? ? OrgSubfield.where("organization_id =? and field_type =?", params[:id].to_i, "Compstu").first : OrgSubfield.find(params[:org_subfield_id])
|
||||
@type = params[:type]
|
||||
if @type.blank?
|
||||
@org_students = User.find_by_sql("select u.*, ue.student_id, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count
|
||||
from users u, user_extensions ue where u.id = ue.user_id and ue.identity= 1 and concat(lastname,firstname,login) like '%#{q}%' order by course_count desc")
|
||||
elsif @type == "famous"
|
||||
@org_students = User.find_by_sql("select u.*, ue.student_id, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count
|
||||
from users u, user_extensions ue where u.id = ue.user_id and ue.identity= 1 and u.excellent_student =1 and concat(lastname,firstname,login) like '%#{q}%' order by course_count desc")
|
||||
end
|
||||
limit = 10
|
||||
# @is_remote = true
|
||||
@students_count = @org_students.count
|
||||
@atta_pages = Paginator.new @students_count, limit, params['page'] || 1
|
||||
@offset ||= @atta_pages.offset
|
||||
#@curse_attachments_all = @all_attachments[@offset, @limit]
|
||||
@org_students = paginateHelper @org_students, limit
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def atta_page_public container
|
||||
limit = 10
|
||||
@containers_count = container.count
|
||||
@atta_pages = Paginator.new @containers_count, limit, params['page'] || 1
|
||||
@offset ||= @atta_pages.offset
|
||||
@containers = paginateHelper container, limit
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def projects
|
||||
q = params[:search].nil? ? "" : "#{params[:search].strip}"
|
||||
@field = params[:org_subfield_id].nil? ? OrgSubfield.where("organization_id =? and field_type =?", params[:id].to_i, "Comppro").first : OrgSubfield.find(params[:org_subfield_id])
|
||||
@type = params[:type]
|
||||
if @type.blank?
|
||||
@containers = Project.find_by_sql("select p.*, (select count(*) from forge_activities where forge_activities.project_id = p.id) as project_count
|
||||
from projects p where p.status =1 and p.is_public =1 and name like '%#{q}%' order by project_count desc;")
|
||||
elsif @type == "famous"
|
||||
@containers = Project.find_by_sql("select p.*, (select count(*) from forge_activities where forge_activities.project_id = p.id) as project_count
|
||||
from projects p where p.status =1 and p.is_public =1 and hot =1 and name like '%#{q}%' order by project_count desc;")
|
||||
end
|
||||
atta_page_public @containers
|
||||
end
|
||||
|
||||
def courses
|
||||
q = params[:search].nil? ? "" : "#{params[:search].strip}"
|
||||
@field = params[:org_subfield_id].nil? ? OrgSubfield.where("organization_id =? and field_type =?", params[:id].to_i, "Compstu").first : OrgSubfield.find(params[:org_subfield_id])
|
||||
@type = params[:type]
|
||||
if @type.blank?
|
||||
@containers = Course.find_by_sql("select c.*, (select count(*) from course_activities where course_activities.course_id = c.id) as course_count
|
||||
from courses c where c.is_delete =0 and c.is_public =1 and name like '%#{q}%' order by course_count desc;")
|
||||
elsif @type == "famous"
|
||||
@containers = Course.find_by_sql("select c.*, (select count(*) from course_activities where course_activities.course_id = c.id) as course_count
|
||||
from courses c where c.is_delete =0 and c.is_public =1 and is_excellent = 1 and name like '%#{q}%' order by course_count desc;")
|
||||
end
|
||||
atta_page_public @containers
|
||||
end
|
||||
|
||||
def acts
|
||||
@subfield_content = @organization.org_subfields.order("priority")
|
||||
@org_subfield = OrgSubfield.where(:id => params[:org_subfield_id]).first
|
||||
shield_project_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Project'").map(&:shield_id)
|
||||
shield_course_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Course'").map(&:shield_id)
|
||||
project_ids = (@organization.projects.map(&:id) - shield_project_ids) << 0
|
||||
course_ids = (@organization.courses.map(&:id) - shield_course_ids) << 0
|
||||
@org_acts = UserActivity.find_by_sql("SELECT * FROM `user_activities` where act_type in ('HomeworkCommon', 'News', 'Message', 'Issue') and
|
||||
((container_type = 'Course' and container_id in (#{course_ids.join(',')})) or (container_type = 'Project' and container_id in (#{project_ids.join(',')})))
|
||||
order by created_at desc limit 6;")
|
||||
respond_to do |format|
|
||||
format.html{render :layout => 'base_org_custom'}
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def searchmember_by_name members, name
|
||||
#searchPeopleByRoles(project, StudentRoles)
|
||||
mems = []
|
||||
if name != ""
|
||||
name = name.to_s.downcase
|
||||
members.each do |m|
|
||||
username = m.user[:lastname].to_s.downcase + m.user[:firstname].to_s.downcase
|
||||
if(m.user[:login].to_s.downcase.include?(name) || m.user.user_extensions[:student_id].to_s.downcase.include?(name) || username.include?(name))
|
||||
mems << m
|
||||
end
|
||||
end
|
||||
else
|
||||
mems = members
|
||||
end
|
||||
mems
|
||||
end
|
||||
|
||||
def get_project_message_activities_org org
|
||||
project_ids = org.projects.map{|project| project.id}.join(",")
|
||||
unless project_ids.blank?
|
||||
|
@ -192,7 +320,7 @@ class OrganizationsController < ApplicationController
|
|||
def get_project_activities_org org, project_ids
|
||||
unless project_ids.blank?
|
||||
project_acts = OrgActivity.find_by_sql("SELECT * FROM org_activities where container_id in (#{project_ids.join(',')}) and container_type = 'project'
|
||||
and org_act_type in ('Message', 'Issue') order by updated_at desc limit 8;")
|
||||
and org_act_type in ('Message', 'Issue') order by updated_at desc limit 5;")
|
||||
else
|
||||
project_acts = nil
|
||||
end
|
||||
|
@ -203,7 +331,7 @@ class OrganizationsController < ApplicationController
|
|||
def get_course_activities_org org, course_ids
|
||||
unless course_ids.blank?
|
||||
project_acts = OrgActivity.find_by_sql("SELECT * FROM org_activities where container_id in (#{course_ids.join(',')}) and container_type = 'course'
|
||||
and org_act_type in ('HomeworkCommon', 'Poll', 'Message', 'News', 'Course') order by updated_at desc limit 8;")
|
||||
and org_act_type in ('HomeworkCommon', 'Poll', 'Message', 'News', 'Course') order by updated_at desc limit 5;")
|
||||
else
|
||||
project_acts = nil
|
||||
end
|
||||
|
@ -248,6 +376,7 @@ class OrganizationsController < ApplicationController
|
|||
# @organization.domain = params[:organization][:domain]
|
||||
@organization.is_public = params[:organization][:is_public] == 'on' ? 1 : 0
|
||||
@organization.allow_guest_download = params[:organization][:allow_guest_download] == 'on' ? 1 : 0
|
||||
@organization.allow_teacher = params[:organization][:allow_teacher] == 'on' ? 1 : 0
|
||||
@organization.show_mode = params[:show_mode]
|
||||
#@organization.name = params[:organization][:name]
|
||||
@organization.save
|
||||
|
@ -281,6 +410,13 @@ class OrganizationsController < ApplicationController
|
|||
@organization = Organization.find(params[:id])
|
||||
end
|
||||
|
||||
def allow_as_admin
|
||||
unless User.current.admin?
|
||||
render_403
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
def setting
|
||||
@organization = Organization.find(params[:id])
|
||||
|
||||
|
@ -430,6 +566,40 @@ class OrganizationsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def update_field_by_admin
|
||||
@type = params[:type]
|
||||
@status = params[:status]
|
||||
if @type == "project"
|
||||
@container = Project.find(params[:container])
|
||||
@status == "reset" ? @container.update_column(:hot, 0) : @container.update_column(:hot, 1)
|
||||
else
|
||||
@container = Course.find(params[:container])
|
||||
@status == "reset" ? @container.update_column(:is_excellent, 0) : @container.update_column(:is_excellent, 1)
|
||||
end
|
||||
end
|
||||
|
||||
# 设置为名师
|
||||
def set_excellent_teacher
|
||||
@ex_teacher = User.find(params[:user])
|
||||
@ex_teacher.update_column(:excellent_teacher, 1)
|
||||
end
|
||||
|
||||
# 取消名师
|
||||
def reset_excellent_teacher
|
||||
@ex_teacher = User.find(params[:user])
|
||||
@ex_teacher.update_column(:excellent_teacher, 0)
|
||||
end
|
||||
|
||||
def set_excellent_student
|
||||
@ex_student = User.find(params[:user])
|
||||
@ex_student.update_column(:excellent_student, 1)
|
||||
end
|
||||
|
||||
def reset_excellent_student
|
||||
@ex_student = User.find(params[:user])
|
||||
@ex_student.update_column(:excellent_student, 0)
|
||||
end
|
||||
|
||||
def hide_org_subfield
|
||||
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
|
||||
@org_subfield.update_attribute(:hide, 1)
|
||||
|
|
|
@ -423,9 +423,13 @@ class PollController < ApplicationController
|
|||
# 将其他地方的问卷导出来
|
||||
def other_poll
|
||||
# 查作者是我,或者作者是当前课程的老师,且不在当前课程内的问卷 进行导入
|
||||
tea_ids = '('
|
||||
tea_ids << Course.find(params[:polls_group_id]).tea_id.to_s << ','<< User.current.id.to_s << ')'
|
||||
@polls = Poll.where("user_id in #{tea_ids} and polls_type = 'course' and polls_group_id != #{params[:polls_group_id]}")
|
||||
courses = User.current.courses.select { |course| User.current.allowed_to?(:as_teacher,course)}
|
||||
course_ids = courses.empty? ? "(-1)" : "(" + courses.map { |course| course.id}.join(',') + ")"
|
||||
none_courses = User.current.courses.where("is_delete = 1 or #{Course.table_name}.id = #{params[:polls_group_id].to_i}")
|
||||
none_course_ids = none_courses.empty? ? "(-1)" : "(" + none_courses.map { |course| course.id}.join(',') + ")"
|
||||
#tea_ids = '('
|
||||
#tea_ids << Course.find(params[:polls_group_id]).tea_id.to_s << ','<< User.current.id.to_s << ')'
|
||||
@polls = Poll.where("(user_id = #{User.current.id} or polls_group_id in #{course_ids}) and polls_type = 'course' and polls_group_id not in #{none_course_ids}")
|
||||
@polls_group_id = params[:polls_group_id]
|
||||
respond_to do |format|
|
||||
format.js
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
class PraiseTreadController < ApplicationController
|
||||
|
||||
accept_api_auth :tread_plus,:praise_plus
|
||||
before_filter :require_login,:only => [:praise_plus,:tread_plus]
|
||||
# before_filter :require_login,:only => [:praise_plus,:tread_plus]
|
||||
before_filter :user_unlogged_check,:only => [:praise_plus,:tread_plus,:praise_minus]
|
||||
|
||||
def praise_plus
|
||||
@obj = nil
|
||||
@activity = false
|
||||
|
||||
if request.get?
|
||||
@obj_id = params[:obj_id]
|
||||
@obj_type = params[:obj_type]
|
||||
|
@ -25,14 +25,14 @@ class PraiseTreadController < ApplicationController
|
|||
return
|
||||
end
|
||||
@horizontal = params[:horizontal].downcase == "false" ? false:true if params[:horizontal]
|
||||
if @obj.respond_to?("author_id")
|
||||
author_id = @obj.author_id
|
||||
elsif @obj.respond_to?("user_id")
|
||||
author_id = @obj.user_id
|
||||
end
|
||||
unless author_id == User.current.id
|
||||
praise_tread_plus(@obj_type,@obj_id,1)
|
||||
end
|
||||
# if @obj.respond_to?("author_id")
|
||||
# author_id = @obj.author_id
|
||||
# elsif @obj.respond_to?("user_id")
|
||||
# author_id = @obj.user_id
|
||||
# end
|
||||
# unless author_id == User.current.id
|
||||
praise_tread_plus(@obj_type,@obj_id,1)
|
||||
# end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
|
@ -131,6 +131,8 @@ class PraiseTreadController < ApplicationController
|
|||
@obj = Bid.find_by_id(id)
|
||||
when 'Contest'
|
||||
@obj = Contest.find_by_id(id)
|
||||
when 'Syllabus'
|
||||
@obj = Syllabus.find_by_id(id)
|
||||
else
|
||||
@obj = nil
|
||||
end
|
||||
|
|
|
@ -100,8 +100,8 @@ class ProjectsController < ApplicationController
|
|||
render_404
|
||||
end
|
||||
|
||||
def course
|
||||
render_404
|
||||
def courserender_404
|
||||
|
||||
end
|
||||
|
||||
# Time 2015-01-29 11:19:11
|
||||
|
@ -299,6 +299,8 @@ class ProjectsController < ApplicationController
|
|||
if params[:jump] && redirect_to_project_menu_item(@project, params[:jump])
|
||||
return
|
||||
end
|
||||
|
||||
logger.debug "111111111"*100
|
||||
# over
|
||||
@author = params[:user_id].blank? ? nil : User.active.find(params[:user_id])
|
||||
@page = params[:page] ? params[:page].to_i + 1 : 0
|
||||
|
@ -319,9 +321,34 @@ class ProjectsController < ApplicationController
|
|||
else
|
||||
@events_pages = ForgeActivity.includes(:project).where("forge_activities.project_id = ? and projects.is_public = ? and forge_act_type != ? ",@project,1, "Document").order("created_at desc").page(params['page'|| 1]).per(10);
|
||||
end
|
||||
g = Gitlab.client
|
||||
unless @project.gpid.nil?
|
||||
@static_total_per_user = g.rep_stats(@project.gpid)
|
||||
logger.debug "2"*100
|
||||
# g = Gitlab.client
|
||||
unless @project.gpid.nil? || @project.project_score.changeset_num == 0
|
||||
# rep_statics_commit = @project.rep_statics.order("commits_num desc")
|
||||
rep_statics_commit = RepStatics.find_by_sql("SELECT * FROM `rep_statics` where project_id = #{@project.id} order by commits_num desc limit 10")
|
||||
rep_statics_code = RepStatics.find_by_sql("SELECT * FROM `rep_statics` where project_id = #{@project.id} order by changeset desc limit 10")
|
||||
# rep_statics_code = @project.rep_statics.sort_by {|u| u.changeset}.reverse
|
||||
@a_uname = rep_statics_commit.map {|s| s.uname }
|
||||
@a_uname_code = rep_statics_code.map {|s| s.uname }
|
||||
@a_commits_num = rep_statics_commit.map {|s| s.commits_num.to_i }
|
||||
@a_commits_add = rep_statics_code.map {|s| s.add.to_i }
|
||||
@a_commits_del = rep_statics_code.map {|s| s.del.to_i }
|
||||
@a_commits_changeset = rep_statics_code.map {|s| s.changeset.to_i }
|
||||
g = Gitlab.client
|
||||
logger.debug "3"*100
|
||||
begin
|
||||
gid = @project.gpid
|
||||
logger.debug "31"*100
|
||||
g_branch = g.project(gid)
|
||||
logger.debug "4"*100
|
||||
g_branch = g_branch.default_branch.to_s
|
||||
logger.debug "5"*100
|
||||
rescue =>e
|
||||
logger.error("get gitlab project failed: " + e)
|
||||
end
|
||||
logger.debug "6"*100
|
||||
@rev = g_branch.nil? ? "master" : g_branch
|
||||
logger.debug "7"*100
|
||||
end
|
||||
# 根据对应的请求,返回对应的数据
|
||||
respond_to do |format|
|
||||
|
@ -377,7 +404,7 @@ class ProjectsController < ApplicationController
|
|||
unless @project.gpid.nil?
|
||||
g = Gitlab.client
|
||||
@gitlab_branches = g.branches(@project.gpid)
|
||||
@branch_names = g.branches(@project.gpid).map{|b| b.name}
|
||||
@branch_names = @gitlab_branches.map{|b| b.name}
|
||||
@gitlab_default_branch = g.project(@project.gpid).default_branch
|
||||
end
|
||||
end
|
||||
|
@ -626,12 +653,12 @@ class ProjectsController < ApplicationController
|
|||
def update
|
||||
@project.safe_attributes = params[:project]
|
||||
@project.organization_id = params[:organization_id]
|
||||
params[:project][:is_public] ? @project.is_public = 1 : @project.is_public = 0
|
||||
params[:project][:hidden_repo] ? @project.hidden_repo = 1 : @project.hidden_repo = 0
|
||||
params[:project][:is_public] == "on" ? @project.is_public = 1 : @project.is_public = 0
|
||||
params[:project][:hidden_repo] == "on" ? @project.hidden_repo = 1 : @project.hidden_repo = 0
|
||||
# 更新公开私有时同步gitlab公开私有
|
||||
unless @project.gpid.nil?
|
||||
if !@project.gpid.nil? && @project.is_public != (params[:project][:is_public] == "on" ? 1 : 0)
|
||||
g = Gitlab.client
|
||||
params[:project][:is_public] ? g.edit_project(@project.gpid, 20, params[:branch]) : g.edit_project(@project.gpid, 0, params[:branch])
|
||||
params[:project][:is_public] == "on" ? g.edit_project(@project.gpid, 20, params[:branch]) : g.edit_project(@project.gpid, 0, params[:branch])
|
||||
end
|
||||
# end
|
||||
if validate_parent_id && @project.save
|
||||
|
|
|
@ -0,0 +1,270 @@
|
|||
class QualityAnalysisController < ApplicationController
|
||||
before_filter :find_project_by_project_id#, :except => [:getattachtype]
|
||||
before_filter :find_quality_analysis, :only => [:edit, :update_jenkins_job]
|
||||
before_filter :authorize
|
||||
before_filter :connect_jenkins, :only => [:create, :edit, :update_jenkins_job, :index]
|
||||
layout "base_projects"
|
||||
include ApplicationHelper
|
||||
include QualityAnalysisHelper
|
||||
require 'jenkins_api_client'
|
||||
require 'nokogiri'
|
||||
require 'json'
|
||||
require 'open-uri'
|
||||
|
||||
def show
|
||||
|
||||
end
|
||||
|
||||
# params 说明:{identifier:版本库名}
|
||||
def create
|
||||
begin
|
||||
user_name = User.find(params[:user_id]).try(:login)
|
||||
identifier = params[:identifier]
|
||||
rep_id = params[:rep_id]
|
||||
|
||||
# job_name and sonar_name 前者为job名字,后者为jenkins配置名
|
||||
job_name = "#{user_name}-#{rep_id}"
|
||||
sonar_name = "#{user_name}:#{rep_id}"
|
||||
|
||||
# 考虑到历史数据:有些用户创建类job但是build失败,即sonar没有结果,这个时候需要把job删除,并且删掉quality_analyses表数据
|
||||
# 如果不要这句则需要迁移数据
|
||||
@sonar_address = Redmine::Configuration['sonar_address']
|
||||
projects_date = open(@sonar_address + "/api/projects/index").read
|
||||
arr = JSON.parse(projects_date).map {|m| m["nm"]} # eg: ["Hjqreturn:cc_rep", "Hjqreturn:putong", "Hjqreturn:sonar_rep2", "shitou:sonar_rep"]
|
||||
quality_an = QualityAnalysis.where(:sonar_name => sonar_name).first
|
||||
if @client.job.exists?(job_name) && QualityAnalysis.where(:sonar_name => sonar_name).select{|qa| arr.include?(qa.sonar_name)}.blank?
|
||||
logger.info("88888888888888888888")
|
||||
aa = @client.job.delete("#{job_name}")
|
||||
quality_an.delete unless quality_an.blank?
|
||||
end
|
||||
# Checks if the given job exists in Jenkins.
|
||||
unless @client.job.exists?(job_name)
|
||||
@g = Gitlab.client
|
||||
branch = params[:branch]
|
||||
language = swith_language_type(params[:language])
|
||||
path = params[:path].blank? ? "./" : params[:path]
|
||||
# qa = QualityAnalysis.where(:project_id => @project.id, :author_login => user_name).first
|
||||
version = quality_an.nil? ? 1 : quality_an.sonar_version + 1
|
||||
properties = "sonar.projectKey=#{sonar_name}
|
||||
sonar.projectName=#{sonar_name}
|
||||
sonar.projectVersion=#{version}
|
||||
sonar.sources=#{path}
|
||||
sonar.language=#{language.downcase}
|
||||
sonar.sourceEncoding=utf-8"
|
||||
git_url = @gitlab_address.to_s+"/"+@project.owner.to_s+"/"+ identifier + "."+"git"
|
||||
|
||||
# 替换配置文件
|
||||
@doc = Nokogiri::XML(File.open(File.join(Rails.root, 'tmp', 'config.xml')))
|
||||
@doc.at_xpath("//hudson.plugins.git.UserRemoteConfig/url").content = git_url
|
||||
@doc.at_xpath("//hudson.plugins.git.BranchSpec/name").content = "*/#{branch}"
|
||||
@doc.at_xpath("//hudson.plugins.sonar.SonarRunnerBuilder/properties").content = properties # sonar-properties
|
||||
|
||||
# jenkins job创建
|
||||
jenkins_job = @client.job.create("#{job_name}", @doc.to_xml)
|
||||
logger.info("Jenkins status of create ==> #{jenkins_job}")
|
||||
|
||||
# 将地址作为hook值添加到gitlab
|
||||
@g.add_project_hook(@project.gpid, @jenkins_address + "/project/#{job_name}")
|
||||
# job创建完成后自动运行job,如果运行成功则返回‘200’
|
||||
code = @client.job.build("#{job_name}")
|
||||
logger.error("build result ==> #{code}")
|
||||
|
||||
# 判断调用sonar分析是否成功
|
||||
# 等待启动时间处理, 最长时间为30分钟
|
||||
for i in 0..360 do
|
||||
sleep(5)
|
||||
@current_build_status = @client.job.get_current_build_status("#{job_name}")
|
||||
if (@current_build_status == "success" || @current_build_status == "failure")
|
||||
break
|
||||
if i == 360
|
||||
@build_console_result = false
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# sonar 缓冲,取数据
|
||||
sleep(5)
|
||||
|
||||
# 获取sonar output结果
|
||||
console_build = @client.job.get_console_output("#{job_name}", build_num = 0, start = 0, mode = 'text')["output"]
|
||||
logger.info("@current_build_status is ==> #{@current_build_status}")
|
||||
|
||||
# 两种情况需要删除job:
|
||||
# 1/创建成功但是build失败则删除job
|
||||
# 2/creat和build成功,调用sonar启动失败则删除job
|
||||
# 错误信息存储需存到Trustie数据库,否则一旦job删除则无法获取这些信息
|
||||
if jenkins_job == '200' && code != '201'
|
||||
@client.job.delete("#{job_name}")
|
||||
else
|
||||
if @current_build_status == "failure"
|
||||
reg_console = /Exception:.*?\r/.match(console_build)
|
||||
output = reg_console[0].gsub("\r", "") unless reg_console.nil?
|
||||
se = SonarError.where(:jenkins_job_name => job_name).first
|
||||
se.nil? ? SonarError.create(:project_id => @project.id, :jenkins_job_name => job_name, :output => output) : se.update_column(:output, output)
|
||||
@client.job.delete("#{job_name}")
|
||||
elsif @current_build_status == "success"
|
||||
if quality_an.blank?
|
||||
QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier,
|
||||
:sonar_version => version, :path => path, :branch => branch, :language => language, :sonar_name => "#{user_name}:#{rep_id}")
|
||||
else
|
||||
qa.update_attribute(:sonar_version, version)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue => e
|
||||
@message = e.message
|
||||
end
|
||||
respond_to do |format|
|
||||
if @current_build_status == "success"
|
||||
format.html{redirect_to project_quality_analysis_path(:project_id => @project.id, :resource_id => sonar_name, :branch => branch, :current_build_status => @current_build_status, :job_name => job_name)}
|
||||
elsif @current_build_status == "failure"
|
||||
format.html{redirect_to error_list_project_quality_analysi_path(:project_id => @project.id, :job_name => job_name)}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def error_list
|
||||
@error_list = SonarError.where(:jenkins_job_name => params[:job_name]).first
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
# get language type
|
||||
def swith_language_type language
|
||||
if language == "c#"
|
||||
"cs"
|
||||
elsif language == "python"
|
||||
"py"
|
||||
elsif language == "c"
|
||||
"c++"
|
||||
else
|
||||
language
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@g = Gitlab.client
|
||||
gitlab_branches = @g.branches(@project.gpid)
|
||||
@branch_names = gitlab_branches.map{|b| b.name}
|
||||
@gitlab_default_branch = @g.project(@project.gpid).default_branch
|
||||
end
|
||||
|
||||
# 更新Jenkins job,主要包括相关配置文件参数的更新,Trustie平台数据的更新
|
||||
def update_jenkins_job
|
||||
begin
|
||||
rep_id = Repository.where(:project_id => @project.id).first.try(:id)
|
||||
logger.error("#############################===>666")
|
||||
sonar_name = @quality_analysis.sonar_name
|
||||
job_name = "#{@quality_analysis.author_login}-#{rep_id}"
|
||||
version = @quality_analysis.sonar_version
|
||||
path = params[:path].blank? ? "./" : params[:path]
|
||||
language = swith_language_type(params[:language])
|
||||
branch = params[:branch]
|
||||
identifier = @quality_analysis.rep_identifier
|
||||
properties = "sonar.projectKey=#{sonar_name}
|
||||
sonar.projectName=#{sonar_name}
|
||||
sonar.projectVersion=#{version}
|
||||
sonar.sources=#{path}
|
||||
sonar.language=#{language.downcase}
|
||||
sonar.sourceEncoding=utf-8"
|
||||
git_url = @gitlab_address.to_s+"/"+@project.owner.to_s+"/"+ identifier + "."+"git"
|
||||
|
||||
# modify config.yml
|
||||
@doc = Nokogiri::XML(File.open(File.join(Rails.root, 'tmp', 'config.xml')))
|
||||
@doc.at_xpath("//hudson.plugins.git.UserRemoteConfig/url").content = git_url
|
||||
@doc.at_xpath("//hudson.plugins.git.BranchSpec/name").content = "*/#{branch}"
|
||||
@doc.at_xpath("//hudson.plugins.sonar.SonarRunnerBuilder/properties").content = properties # sonar-properties
|
||||
|
||||
# update成功则返回 ‘200’
|
||||
jenkins_job = @client.job.update("#{job_name}", @doc.to_xml)
|
||||
get_current_build_status = @client.job.get_current_build_status("Hjqreturn-1280")
|
||||
logger.error("Failed to update job: ==> #{jenkins_job}") unless jenkins_job == '200'
|
||||
|
||||
# 数据更新到Trustie数据
|
||||
if jenkins_job == '200'
|
||||
logger.info("quality_ananlysis will be updated: ==> #{jenkins_job}")
|
||||
@quality_analysis.path = path
|
||||
@quality_analysis.language = language
|
||||
@quality_analysis.branch = branch
|
||||
@quality_analysis.save
|
||||
end
|
||||
rescue Exception => e
|
||||
logger.error("Update jenkins job: #{e}")
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html{redirect_to project_quality_analysis_path(:project_id => @project.id)}
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
# resource_id: login + @repository.id
|
||||
def index
|
||||
begin
|
||||
@branch = params[:branch]
|
||||
@resource_id = params[:resource_id]
|
||||
@sonar_address = Redmine::Configuration['sonar_address']
|
||||
if params[:resource_id].nil?
|
||||
@name_flag = true
|
||||
projects_date = open(@sonar_address + "/api/projects/index").read
|
||||
arr = JSON.parse(projects_date).map {|m| m["nm"]} # eg: ["Hjqreturn:cc_rep", "Hjqreturn:putong", "Hjqreturn:sonar_rep2", "shitou:sonar_rep"]
|
||||
@quality_analyses = QualityAnalysis.where(:project_id => @project.id).select{|qa| arr.include?(qa.sonar_name)}
|
||||
else
|
||||
filter = "sqale_rating,function_complexity,duplicated_lines_density,comment_lines_density,sqale_index,lines,files,functions,classes,directories,blocker_violations,critical_violations,major_violations,minor_violations,info_violations,violations"
|
||||
complexity_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=#{filter}").read
|
||||
@complexity =JSON.parse(complexity_date).first
|
||||
|
||||
# 按名称转换成hash键值对
|
||||
@ha = {}
|
||||
@complexity["msr"].each do |com|
|
||||
key = com["key"]
|
||||
if key == "sqale_index"
|
||||
value = com["frmt_val"]
|
||||
else
|
||||
value = com["val"].to_i
|
||||
end
|
||||
@ha.store(key,value)
|
||||
end
|
||||
end
|
||||
rescue => e
|
||||
puts e
|
||||
end
|
||||
end
|
||||
|
||||
# Find project of id params[:project_id]
|
||||
def find_project_by_project_id
|
||||
@project = Project.find(params[:project_id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_quality_analysis
|
||||
begin
|
||||
@quality_analysis = QualityAnalysis.find(params[:id])
|
||||
rescue
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
# Authorize the user for the requested action
|
||||
def authorize(ctrl = params[:controller], action = params[:action], global = false)
|
||||
unless @project.archived? && @project.gpid.nil?
|
||||
true
|
||||
else
|
||||
render_403 :message => :notice_not_authorized_archived_project
|
||||
end
|
||||
end
|
||||
|
||||
def connect_jenkins
|
||||
@gitlab_address = Redmine::Configuration['gitlab_address']
|
||||
@jenkins_address = Redmine::Configuration['jenkins_address']
|
||||
|
||||
# connect jenkins
|
||||
@client = JenkinsApi::Client.new(:server_url => @jenkins_address, :username => "temp", :password => '123123')
|
||||
rescue => e
|
||||
logger.error("failed to connect Jenkins ==> #{e}")
|
||||
end
|
||||
|
||||
end
|
|
@ -20,6 +20,8 @@ require 'SVG/Graph/BarHorizontal'
|
|||
require 'digest/sha1'
|
||||
require 'redmine/scm/adapters/abstract_adapter'
|
||||
require 'tempfile'
|
||||
require 'json'
|
||||
require 'open-uri'
|
||||
|
||||
class ChangesetNotFound < Exception; end
|
||||
class InvalidRevisionParam < Exception; end
|
||||
|
@ -30,11 +32,15 @@ class RepositoriesController < ApplicationController
|
|||
menu_item :settings, :only => [:new, :create, :edit, :update, :destroy, :committers]
|
||||
default_search_scope :changesets
|
||||
|
||||
before_filter :find_project_by_project_id, :only => [:new, :create, :newrepo, :stats]
|
||||
before_filter :find_project_by_project_id, :only => [:new, :create, :newrepo, :stats, :quality_analysis]
|
||||
before_filter :find_repository, :only => [:edit, :update, :destroy, :committers]
|
||||
before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo, :to_gitlab, :forked]
|
||||
before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo, :to_gitlab, :forked, :project_archive]
|
||||
before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue]
|
||||
before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :commit_diff]
|
||||
before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :commit_diff, :project_archive, :quality_analysis]
|
||||
# 链接gitlab
|
||||
before_filter :connect_gitlab, :only => [:quality_analysis, :show]
|
||||
# 版本库新增权限
|
||||
before_filter :show_rep, :only => [:show]
|
||||
accept_rss_auth :revisions
|
||||
# hidden repositories filter // 隐藏代码过滤器
|
||||
before_filter :check_hidden_repo, :only => [:show, :stats, :revisions, :revision, :diff ]
|
||||
|
@ -43,6 +49,7 @@ class RepositoriesController < ApplicationController
|
|||
helper :project_score
|
||||
#@root_path = RepositoriesHelper::ROOT_PATH
|
||||
$g=Gitlab.client
|
||||
require 'net/ssh'
|
||||
|
||||
rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
|
||||
def new
|
||||
|
@ -95,6 +102,13 @@ class RepositoriesController < ApplicationController
|
|||
|
||||
end
|
||||
|
||||
# 一键ZIP下载
|
||||
def project_archive
|
||||
g = Gitlab.client
|
||||
g.get()
|
||||
# g.project_archive(params[:gpid].to_i, params[:rev])
|
||||
end
|
||||
|
||||
# 判断用户是否已经fork过该项目
|
||||
def has_forked?(project, user)
|
||||
projects = Project.where("user_id =?", user)
|
||||
|
@ -299,6 +313,37 @@ update
|
|||
end
|
||||
end
|
||||
|
||||
def quality_analysis
|
||||
gitlab_branches = @g.branches(@project.gpid)
|
||||
@branch_names = gitlab_branches.map{|b| b.name}
|
||||
@gitlab_default_branch = @g.project(@project.gpid).default_branch
|
||||
# language = params[:language]
|
||||
# branch = params[:branch]
|
||||
# path = params[:path]
|
||||
# user_name = User.find(@project.user_id).try(:login)
|
||||
# rep_name = params[:repository_id]
|
||||
# host = "192.168.0.200"
|
||||
# port = "1125"
|
||||
# username = "git"
|
||||
# password = "123123"
|
||||
# server_cmd1 = "sh gitclone.sh" + " " + user_name + " " + rep_name
|
||||
# # 连接到远程主机 foobar
|
||||
# ssh = Net::SSH.start(host, username, :port => port, :password => password) do |ssh|
|
||||
# result = ssh.exec!(server_cmd1)
|
||||
# path = "/home/git/repo/" + user_name + "/" + rep_name
|
||||
# # sonar 分析
|
||||
# # server_cmd2
|
||||
# # 删除clone的版本库
|
||||
# # server_cmd3
|
||||
# end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html{
|
||||
render :layout => "base_projects"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
DestroyRepositoryTask.new.destroy(User.current.id, @repository.id)
|
||||
@repository.hidden = true
|
||||
|
@ -318,60 +363,42 @@ update
|
|||
|
||||
def show
|
||||
## TODO: the below will move to filter, done.
|
||||
if !User.current.member_of?(@project)
|
||||
if @project.hidden_repo
|
||||
render_403
|
||||
return -1
|
||||
end
|
||||
end
|
||||
|
||||
# unless @repository.gitlab?
|
||||
# # redirect_to to_gitlab_project_repository_path(@project, @repository)
|
||||
# render :to_gitlab
|
||||
# return
|
||||
# end
|
||||
|
||||
#if( !User.current.member_of?(@project) || @project.hidden_repo)
|
||||
# @repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty?
|
||||
|
||||
# :name, :path, :kind, :size, :lastrev, :changeset
|
||||
# 获取版本库目录结构
|
||||
@entries = @repository.entries(@path, @rev)
|
||||
# @trees = g.trees(project, @path)
|
||||
@changeset = @repository.find_changeset_by_name(@rev)
|
||||
#@project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT
|
||||
#@ip = RepositoriesHelper::REPO_IP_ADDRESS
|
||||
|
||||
if request.xhr?
|
||||
@entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
|
||||
else
|
||||
#Modified by young
|
||||
# (show_error_not_found; return) unless @entries
|
||||
g = Gitlab.client
|
||||
@changesets = g.commits(@project.gpid, :ref_name => @rev)
|
||||
# 总的提交数
|
||||
@changesets_all_count = @project.gpid.nil? ? 0 : g.project(@project.gpid).commit_count
|
||||
# 访问该页面的是会后则刷新
|
||||
if @project.project_score.nil?
|
||||
ProjectScore.create(:project_id => @project.id, :score => false)
|
||||
end
|
||||
# 刷新改页面的时候,更新统计数
|
||||
if @changesets_all_count != @project.project_score.changeset_num && @changesets_all_count != 0
|
||||
update_commits_count(@project, @changesets_all_count)
|
||||
end
|
||||
# end
|
||||
@changesets = @g.commits(@project.gpid, :ref_name => @rev)
|
||||
# 最近一次提交
|
||||
@changesets_latest_coimmit = @changesets[0]
|
||||
unless @changesets[0].blank?
|
||||
update_commits_date(@project, @changesets_latest_coimmit)
|
||||
g_project = @g.project(@project.gpid)
|
||||
# 总的提交数
|
||||
@changesets_all_count = @g.user_static(@project.gpid, :rev => @rev).count
|
||||
|
||||
# 获取默认分支
|
||||
@g_default_branch = g_project.default_branch.nil? ? "master" : g_project.default_branch
|
||||
|
||||
# 访问版本庫后更新project_score表数据;changeset_num为提交总数
|
||||
project_score = @project.project_score
|
||||
if project_score.nil?
|
||||
ProjectScore.create(:project_id => @project.id, :score => false)
|
||||
else
|
||||
project_score.update_column(:changeset_num, @changesets_all_count)
|
||||
end
|
||||
@creator = User.where("id =?", @project.user_id).first.try(:login)
|
||||
@properties = @repository.properties(@path, @rev)
|
||||
@repositories = @project.repositories
|
||||
project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT
|
||||
ip = RepositoriesHelper::REPO_IP_ADDRESS
|
||||
|
||||
# unless @changesets_latest_coimmit.blank?
|
||||
# update_commits_date(@project, @changesets_latest_coimmit)
|
||||
# end
|
||||
@creator = @project.owner.to_s
|
||||
gitlab_address = Redmine::Configuration['gitlab_address']
|
||||
|
||||
# REDO:需优化,仅测试用
|
||||
@zip_path = Gitlab.endpoint.to_s + "/projects/" + @project.gpid.to_s + "/repository/archive?&private_token=" + Gitlab.private_token
|
||||
|
||||
# 获取版本库路径,主要分为两种,一种随Gitlab类型,另一种为Git类型,Git类型为无用数据,最终需要删掉这种类型。
|
||||
if @repository.type.to_s == "Repository::Gitlab"
|
||||
@repos_url = gitlab_address.to_s+"/"+@project.owner.to_s+"/"+@repository.identifier+"."+"git"
|
||||
@repos_url = gitlab_address.to_s+"/" + @creator + "/" + @repository.identifier+"."+"git"
|
||||
else
|
||||
@repos_url = "http://"+@repository.login.to_s+"_"+@repository.identifier.to_s+"@"+ip.to_s + @repository.url.slice(project_path_cut, @repository.url.length).to_s
|
||||
end
|
||||
|
@ -573,9 +600,17 @@ update
|
|||
g = Gitlab.client
|
||||
begin
|
||||
@static_total_per_user = g.rep_stats(project_id, :rev => rev)
|
||||
@static_total_per_user
|
||||
# @static_month__per_user = g.rep_stats(project_id, :rev => rev, :creator => creator, :period => 2)
|
||||
# @static_week_per_user = g.rep_stats(project_id, :rev => rev, :creator => creator, :period => 3)
|
||||
# 更新rep_statics统计数
|
||||
@static_total_per_user.each do |static|
|
||||
rep_static = RepStatics.where("project_id =? and email =?", @project.id, static.email.to_s).first
|
||||
if rep_static.nil?
|
||||
RepStatics.create(:project_id => @project.id, :uname => static.uname, :commits_num => static.commits_num, :email => static.email, :add => static.add, :del => static.del, :changeset => static.changes)
|
||||
else
|
||||
if @rev == params[:default_branch]
|
||||
rep_static.update_attributes(:uname => static.uname, :commits_num => static.commits_num, :email => static.email, :add => static.add, :del => static.del, :changeset => static.changes)
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue
|
||||
render_404
|
||||
return
|
||||
|
@ -616,6 +651,25 @@ update
|
|||
project.project_score.update_attribute(:commit_time, date.created_at)
|
||||
end
|
||||
|
||||
# 链接gitlab
|
||||
def connect_gitlab
|
||||
begin
|
||||
@g = Gitlab.client
|
||||
unless @project.gpid.nil?
|
||||
@g_project = @g.project(@project.gpid)
|
||||
end
|
||||
rescue => e
|
||||
logger.error("failed to connect gitlab ==> #{e}")
|
||||
end
|
||||
end
|
||||
|
||||
def show_rep
|
||||
if !User.current.member_of?(@project) && @project.hidden_repo
|
||||
render_403
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
def find_repository
|
||||
@repository = Repository.find(params[:id])
|
||||
@project = @repository.project
|
||||
|
|
|
@ -150,4 +150,59 @@ class SchoolController < ApplicationController
|
|||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
#申请高校(单位) name:名称 province:省 city:市 address:地址 remarks:备注
|
||||
def apply_add_school
|
||||
|
||||
data = {result:0,name:params[:name],school_id:0}
|
||||
#0 成功 1参数错误 2名称已存在 3.失败
|
||||
data[:result] = 0
|
||||
|
||||
#检验参数
|
||||
if params[:name] == "" || params[:province] == "" || params[:city] == "" || params[:address] == ""
|
||||
data[:result] = 1
|
||||
else
|
||||
school = School.where("name = '#{params[:name]}'").first
|
||||
if school
|
||||
data[:result] = 2
|
||||
else
|
||||
school = School.new
|
||||
school.name = params[:name].strip
|
||||
school.pinyin = Pinyin.t(params[:name].strip, splitter: '')
|
||||
|
||||
#status 0未处理 1通过 2拒绝
|
||||
applyschool = ApplyAddSchools.new
|
||||
|
||||
#用belongs_to 可以一起存数据库
|
||||
applyschool.school = school
|
||||
applyschool.name = school.name
|
||||
applyschool.province = params[:province]
|
||||
applyschool.city = params[:city]
|
||||
applyschool.address = params[:address]
|
||||
applyschool.remarks = params[:remarks]
|
||||
|
||||
if applyschool.save
|
||||
data[:school_id] = school.id
|
||||
else
|
||||
data[:result] = 3
|
||||
end
|
||||
end
|
||||
end
|
||||
render :json =>data
|
||||
end
|
||||
|
||||
def search_repeat_schoolname
|
||||
status = 0 #没有重复的
|
||||
name = params[:name]
|
||||
|
||||
if name
|
||||
school = School.where("name = '#{name}'").first
|
||||
|
||||
if school
|
||||
status = 1 #有重复的
|
||||
end
|
||||
end
|
||||
|
||||
render :json =>status
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,6 +32,10 @@ class SettingsController < ApplicationController
|
|||
hidden_non_project = Setting.find_by_name("hidden_non_project")
|
||||
@text = (hidden_non_project && hidden_non_project.value == "0") ? l(:label_show_non_project) : l(:label_hidden_non_project)
|
||||
|
||||
#1隐藏了课程信息 0显示了课程信息
|
||||
hidden_courses = Setting.find_by_name("hidden_courses")
|
||||
@text_1 = (hidden_courses && hidden_courses.value == "1") ? l(:label_show_courses) : l(:label_hidden_courses)
|
||||
|
||||
@notifiables = Redmine::Notifiable.all
|
||||
if request.post? && params[:settings] && params[:settings].is_a?(Hash)
|
||||
settings = (params[:settings] || {}).dup.symbolize_keys
|
||||
|
@ -89,4 +93,22 @@ class SettingsController < ApplicationController
|
|||
|
||||
redirect_to settings_url
|
||||
end
|
||||
|
||||
#隐藏/显示课程信息
|
||||
def hidden_courses
|
||||
@notifiable = Setting.find_by_name("hidden_courses")
|
||||
if @notifiable
|
||||
@notifiable.value == "1" ? @notifiable.value = 0 : @notifiable.value = 1
|
||||
@notifiable.save
|
||||
else
|
||||
@notifiable = Setting.new()
|
||||
@notifiable.name = "hidden_courses"
|
||||
@notifiable.value = 1
|
||||
@notifiable.save
|
||||
end
|
||||
|
||||
redirect_to settings_url
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
class ShieldWechatMessagesController < ApplicationController
|
||||
def create
|
||||
if params[:user_id]
|
||||
@user = User.find params[:user_id]
|
||||
if params[:project_id]
|
||||
ShieldWechatMessage.create(:container_type => 'User', :container_id => params[:user_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i)
|
||||
#@cp = 1
|
||||
#@projects = @user.projects.visible.select("projects.*, (SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(5)
|
||||
elsif params[:course_id]
|
||||
ShieldWechatMessage.create(:container_type => 'User', :container_id => params[:user_id].to_i, :shield_type => 'Course', :shield_id => params[:course_id].to_i)
|
||||
#@cp = 0
|
||||
#@courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def show_messages
|
||||
if params[:user_id]
|
||||
@user = User.find params[:user_id]
|
||||
if params[:project_id]
|
||||
ShieldWechatMessage.where("container_type='User' and container_id=#{params[:user_id].to_i} and shield_type='Project' and shield_id=#{params[:project_id]}").each do |act|
|
||||
act.destroy
|
||||
end
|
||||
#@cp = 1
|
||||
#@projects = @user.projects.visible.select("projects.*, (SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(5)
|
||||
# ShieldActivity.create(:container_type => 'Organization', :container_id => params[:org_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i)
|
||||
elsif params[:course_id]
|
||||
ShieldWechatMessage.where("container_type='User' and container_id=#{params[:user_id].to_i} and shield_type='Course' and shield_id=#{params[:course_id]}").each do |act|
|
||||
act.destroy
|
||||
end
|
||||
#@cp = 0
|
||||
#@courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,86 @@
|
|||
#coding=utf-8
|
||||
|
||||
require 'base64'
|
||||
require 'json'
|
||||
require 'openssl'
|
||||
|
||||
## 单点登录 <=> 北斗
|
||||
class SsosController < ApplicationController
|
||||
|
||||
skip_before_filter :check_if_login_required
|
||||
layout false
|
||||
|
||||
def show
|
||||
begin
|
||||
# suRh2nFEJd0Ai_TFbqZ-1yQXnGfIB-YD_f4KTA3O4dQGSBMiXfOMt-0mzizgXekWTjHKfn62nJ60iHM3_eY_KS0Qn8SF8vANfa46GhzZRt4T0iC5ZOSs4cWeK43OU0RoekQLZZAo5OyOVibxabmiPGzEFCnVVtdmRk9d7X_B0Is=
|
||||
@auth = params[:auth]
|
||||
@options = parse(params[:auth])
|
||||
|
||||
if params[:login].present?
|
||||
@options["name"] = params[:login]
|
||||
end
|
||||
|
||||
logger.debug @options
|
||||
## 认证
|
||||
sso = login(@options)
|
||||
|
||||
## 加入组织
|
||||
@organization = Organization.find(82)
|
||||
unless @organization.org_members.exists?(user_id: sso.user_id)
|
||||
member = OrgMember.create(:user_id => sso.user_id, :created_at => Time.now)
|
||||
# member = OrgMember.new(:user_id => sso.user_id)
|
||||
@organization.org_members << member
|
||||
OrgMemberRole.create(:org_member_id => member.id, :role_id => 12)
|
||||
end
|
||||
|
||||
## 选择性跳转
|
||||
redirect_to @organization
|
||||
rescue => e
|
||||
logger.error e
|
||||
if e.message == "exist user"
|
||||
render 'ssos/show', :layout => false
|
||||
else
|
||||
raise e
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
## 改用户名
|
||||
def create
|
||||
show and return
|
||||
end
|
||||
|
||||
private
|
||||
def base64_safe(content)
|
||||
content = content.gsub('-', '+')
|
||||
content.gsub('_', '/')
|
||||
end
|
||||
|
||||
def parse(auth)
|
||||
content = decrypt(auth)
|
||||
ActiveSupport::JSON.decode(content)
|
||||
end
|
||||
|
||||
def login(opt)
|
||||
sso = Sso.sync_user(opt)
|
||||
start_user_session(sso.user)
|
||||
sso
|
||||
end
|
||||
|
||||
def decrypt(auth)
|
||||
crypted_str = Base64.decode64(base64_safe(auth))
|
||||
pkey = OpenSSL::PKey::RSA.new(File.new(File.join(Rails.root,"config/private.key")))
|
||||
|
||||
#to large
|
||||
max_dec_len = 1024/8
|
||||
size = (crypted_str.size + max_dec_len-1) / max_dec_len
|
||||
|
||||
content = ''
|
||||
size.times do |time|
|
||||
tmps = crypted_str[time*max_dec_len, max_dec_len]
|
||||
content += pkey.private_decrypt(tmps,OpenSSL::PKey::RSA::PKCS1_PADDING)
|
||||
end
|
||||
content
|
||||
end
|
||||
|
||||
end
|
|
@ -5,7 +5,7 @@ class StudentWorkController < ApplicationController
|
|||
include ApplicationHelper
|
||||
require 'bigdecimal'
|
||||
require "base64"
|
||||
before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:program_test_ex,:code_repeattest,:work_canrepeat,:set_score_rule,:forbidden_anonymous_comment,:delete_work,:new_student_work_project,:student_work_project,:cancel_relate_project,:search_course_students]
|
||||
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]
|
||||
before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work,:retry_work,:revise_attachment]
|
||||
before_filter :member_of_course, :only => [:new, :create, :show, :add_score, :praise_student_work]
|
||||
before_filter :author_of_work, :only => [:edit, :update, :destroy]
|
||||
|
@ -17,41 +17,41 @@ class StudentWorkController < ApplicationController
|
|||
is_test = params[:is_test] == 'true'
|
||||
resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T')}
|
||||
|
||||
student_work = find_or_save_student_work(is_test)
|
||||
student_work = find_or_save_student_work(is_test)
|
||||
|
||||
unless student_work
|
||||
resultObj[:status] = 100
|
||||
else
|
||||
if @homework.homework_type == 2 && @homework.homework_detail_programing
|
||||
result = test_realtime(student_work, params[:src])
|
||||
logger.debug result
|
||||
resultObj[:status] = result["status"]
|
||||
resultObj[:results] = result["results"]
|
||||
resultObj[:error_msg] = result["error_msg"]
|
||||
results = result["results"]
|
||||
if result["status"].to_i == -2 #编译错误
|
||||
results = [result["error_msg"]]
|
||||
end
|
||||
student_work_test = student_work.student_work_tests.build(status: result["status"], results: results,
|
||||
src: params[:src])
|
||||
unless student_work.save
|
||||
resultObj[:status] = 200
|
||||
unless student_work
|
||||
resultObj[:status] = 100
|
||||
else
|
||||
if @homework.homework_type == 2 && @homework.homework_detail_programing
|
||||
result = test_realtime(student_work, params[:src])
|
||||
logger.debug result
|
||||
resultObj[:status] = result["status"]
|
||||
resultObj[:results] = result["results"]
|
||||
resultObj[:error_msg] = result["error_msg"]
|
||||
results = result["results"]
|
||||
if result["status"].to_i == -2 #编译错误
|
||||
results = [result["error_msg"]]
|
||||
end
|
||||
student_work_test = student_work.student_work_tests.build(status: result["status"], results: results,
|
||||
src: params[:src])
|
||||
unless student_work.save
|
||||
resultObj[:status] = 200
|
||||
else
|
||||
student_work.name = params[:title]
|
||||
student_work.description = params[:src]
|
||||
if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d")
|
||||
student_work.late_penalty = @homework.late_penalty
|
||||
else
|
||||
student_work.name = params[:title]
|
||||
student_work.description = params[:src]
|
||||
if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d")
|
||||
student_work.late_penalty = @homework.late_penalty
|
||||
else
|
||||
student_work.late_penalty = 0
|
||||
end
|
||||
student_work.save
|
||||
resultObj[:status] = result["status"].to_i
|
||||
resultObj[:time] = student_work_test.created_at.to_s(:db)
|
||||
resultObj[:index] = student_work.student_work_tests.count
|
||||
student_work.late_penalty = 0
|
||||
end
|
||||
student_work.save
|
||||
resultObj[:status] = result["status"].to_i
|
||||
resultObj[:time] = student_work_test.created_at.to_s(:db)
|
||||
resultObj[:index] = student_work.student_work_tests.count
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
render :json => resultObj
|
||||
end
|
||||
|
||||
|
@ -81,6 +81,7 @@ class StudentWorkController < ApplicationController
|
|||
#根据传入的tIndex确定是第几次测试
|
||||
#之后如果觉得很卡 可以改成将结果传回JS再以参数形式传回来
|
||||
def program_test_ex
|
||||
|
||||
tStarttime = Time.now
|
||||
|
||||
is_test = params[:is_test] == 'true'
|
||||
|
@ -94,58 +95,84 @@ class StudentWorkController < ApplicationController
|
|||
resultObj[:status] = 100
|
||||
else
|
||||
if @homework.homework_type == 2 && @homework.homework_detail_programing
|
||||
#找到第index个测试的输入输出
|
||||
index = params[:tIndex].to_i
|
||||
resultObj[:tseq] = index
|
||||
test = @homework.homework_tests[index - 1]
|
||||
#找到第index个测试的输入输出
|
||||
index = params[:tIndex].to_i
|
||||
resultObj[:tseq] = index
|
||||
test = @homework.homework_tests[index - 1]
|
||||
|
||||
#请求测试
|
||||
#请求测试
|
||||
begin
|
||||
result = test_realtime_ex(test, params[:src])
|
||||
rescue Timeout::Error
|
||||
tEndtime = Time.now
|
||||
tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000+(tEndtime.usec - tStarttime.usec)/1000
|
||||
logger.debug "program_test_ex user wait time = #{tUsedtime} 毫秒"
|
||||
#status 0:答案正确 -5program_test_ex 函数出错 -4judge代码出错 -3http超时 -2:编译错误 -1:答案错误 2:程序运行超时
|
||||
resultObj[:status] = -3
|
||||
CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>-3,:wait_time=>tUsedtime,:student_work_id=>student_work.id)
|
||||
rescue => e
|
||||
#-4 judge代码 出错
|
||||
logger.debug "program_test_error #{e}"
|
||||
resultObj[:status] = -4
|
||||
tmpstatus = -4
|
||||
CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>tmpstatus,:time_used=>0,:wait_time=>0,:student_work_id=>student_work.id)
|
||||
end
|
||||
|
||||
if result["status"].to_i != -2
|
||||
#result["results"].first['output'] = result["results"].first['output'].gsub(" ","□")
|
||||
#result["results"].first['result'] = result["results"].first['result'].gsub(" ","□")
|
||||
space_replace_1(result["results"].first['output'])
|
||||
space_replace_1(result["results"].first['result'])
|
||||
end
|
||||
begin
|
||||
if resultObj[:status] != -3 && resultObj[:status] != -4
|
||||
if result["status"].to_i != -2
|
||||
#result["results"].first['output'] = result["results"].first['output'].gsub(" ","□")
|
||||
#result["results"].first['result'] = result["results"].first['result'].gsub(" ","□")
|
||||
space_replace_1(result["results"].first['output'])
|
||||
space_replace_1(result["results"].first['result'])
|
||||
end
|
||||
|
||||
logger.debug result
|
||||
logger.debug result
|
||||
|
||||
#-1 默认值 0全部正确并结束 2 超时 -2 编译错误
|
||||
resultObj[:status] = -1
|
||||
resultObj[:results] = result["results"].first #本次测试结果
|
||||
resultObj[:error_msg] = result["error_msg"] #编译错误时的信息
|
||||
#-1 默认值 0全部正确并结束 2 超时 -2 编译错误
|
||||
resultObj[:status] = -1
|
||||
resultObj[:results] = result["results"].first #本次测试结果
|
||||
if result["status"].to_i == -2 #编译错误
|
||||
result["error_msg"] = result["error_msg"][0..2047]
|
||||
end
|
||||
resultObj[:error_msg] = result["error_msg"] #编译错误时的信息
|
||||
|
||||
if result["status"].to_i == -2 #编译错误
|
||||
#该状态用于存入CodeTests
|
||||
tmpstatus = -1
|
||||
if result["status"].to_i == -2 #编译错误
|
||||
resultObj[:results] = result["error_msg"]
|
||||
resultObj[:status] = -2
|
||||
elsif result["results"][0]["status"].to_i == 2
|
||||
tmpstatus = -2
|
||||
elsif result["results"][0]["status"].to_i == 2
|
||||
resultObj[:status] = 2
|
||||
end
|
||||
tmpstatus = 2
|
||||
end
|
||||
|
||||
unless student_work.save
|
||||
if result["status"] == 0
|
||||
tmpstatus = 0
|
||||
end
|
||||
|
||||
unless student_work.save
|
||||
resultObj[:status] = 200
|
||||
else
|
||||
else
|
||||
student_work.name = params[:title]
|
||||
student_work.description = params[:src]
|
||||
|
||||
if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d")
|
||||
student_work.late_penalty = @homework.late_penalty
|
||||
student_work.late_penalty = @homework.late_penalty
|
||||
else
|
||||
student_work.late_penalty = 0
|
||||
student_work.late_penalty = 0
|
||||
end
|
||||
|
||||
#每次从数据库取出上次的结果加上本次的结果再存入数据库
|
||||
tEndtime = Time.now
|
||||
tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000+(tEndtime.usec - tStarttime.usec)/1000
|
||||
|
||||
if result["status"].to_i != -2
|
||||
result["results"].first['user_wait'] = tUsedtime
|
||||
|
||||
if result["results"][0]["status"].to_i == 2
|
||||
result["status"] = 2
|
||||
end
|
||||
end
|
||||
|
||||
if result["results"][0]["status"].to_i == 2
|
||||
result["status"] = 2
|
||||
end
|
||||
status = result["status"]
|
||||
if index == 1
|
||||
student_work_test = student_work.student_work_tests.build(status: status,
|
||||
|
@ -166,29 +193,44 @@ class StudentWorkController < ApplicationController
|
|||
|
||||
#超时或编译错误则直接返回了并存入数据库
|
||||
if resultObj[:status] == 2 || resultObj[:status] == -2 || index == @homework.homework_tests.size
|
||||
if status == 0
|
||||
resultObj[:status] = 0
|
||||
end
|
||||
student_work.save!
|
||||
resultObj[:time] = student_work_test.created_at.to_s(:db)
|
||||
resultObj[:index] = student_work.student_work_tests.count
|
||||
if status == 0
|
||||
resultObj[:status] = 0
|
||||
end
|
||||
student_work.save!
|
||||
resultObj[:time] = student_work_test.created_at.strftime(format='%Y-%m-%d %H:%M:%S')
|
||||
resultObj[:index] = student_work.student_work_tests.count
|
||||
end
|
||||
|
||||
#将每次用户等待时间都存起来以便管理界面显示用
|
||||
tEndtime = Time.now
|
||||
tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000+(tEndtime.usec - tStarttime.usec)/1000
|
||||
|
||||
logger.debug "program_test_ex user wait time = #{tUsedtime} 毫秒"
|
||||
|
||||
#渲染返回结果
|
||||
render :json => resultObj
|
||||
time_used = 0
|
||||
if result["status"].to_i != -2
|
||||
#至少一毫秒
|
||||
time_used = result["results"].first['time_used'] == 0 ? 1:result["results"].first['time_used']
|
||||
end
|
||||
#0:答案正确 -3http超时 -2:编译错误 -1:答案错误 2:程序运行超时
|
||||
CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>tmpstatus,:time_used=>time_used,:wait_time=>tUsedtime,:student_work_id=>student_work.id)
|
||||
end
|
||||
end
|
||||
rescue
|
||||
#-5 program_test_ex 函数出错
|
||||
logger.debug "program_test_error 2"
|
||||
resultObj[:status] = -5
|
||||
tmpstatus = -5
|
||||
CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>tmpstatus,:time_used=>0,:wait_time=>0,:student_work_id=>student_work.id)
|
||||
end
|
||||
#渲染返回结果
|
||||
render :json => resultObj
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#找出该作业的所有提交作业
|
||||
def find_all_student_work_by_homeid()
|
||||
all_studentwork = StudentWork.where("homework_common_id =#{@homework.id} and is_test = 0 ")
|
||||
all_studentwork = StudentWork.where("homework_common_id = #{@homework.id} and is_test = 0 ")
|
||||
|
||||
all_studentwork
|
||||
end
|
||||
|
@ -222,13 +264,14 @@ class StudentWorkController < ApplicationController
|
|||
JSON.parse(res.body)
|
||||
end
|
||||
|
||||
#点击代码查重按钮
|
||||
def work_canrepeat
|
||||
@homework_id = params[:homework]
|
||||
@course_id = params[:course_id]
|
||||
|
||||
all_studentwork = find_all_student_work_by_homeid()
|
||||
|
||||
@work_count = all_studentwork.count
|
||||
@work_count = all_studentwork.has_committed.count
|
||||
end
|
||||
|
||||
#代码查重 status: 0完成 -2不需要查重 -1查重失败不支持该语言
|
||||
|
@ -239,7 +282,7 @@ class StudentWorkController < ApplicationController
|
|||
|
||||
@homework = HomeworkCommon.find params[:homework]
|
||||
|
||||
all_studentwork = find_all_student_work_by_homeid()
|
||||
all_studentwork = find_all_student_work_by_homeid().has_committed
|
||||
|
||||
if all_studentwork == nil
|
||||
resultObj[:status] = -2
|
||||
|
@ -263,9 +306,9 @@ class StudentWorkController < ApplicationController
|
|||
|
||||
logger.debug "time3 is #{Time.now.usec} "
|
||||
result['results'].each do |key,value|
|
||||
@student_work = StudentWork.where("id =?", key.to_i).first
|
||||
@student_work.update_column('simi_id', value['simiworkid'].to_i)
|
||||
@student_work.update_column('simi_value', value['simivalue'].to_i)
|
||||
@student_work = StudentWork.where("id =?", key.to_i).first
|
||||
@student_work.update_column('simi_id', value['simiworkid'].to_i)
|
||||
@student_work.update_column('simi_value', value['simivalue'].to_i)
|
||||
# sqlstr = "update student_works set simi_id=#{value['simiworkid']},simi_value=#{value['simivalue']} where id=#{key.to_i} "
|
||||
# dbh.execute(sqlstr)
|
||||
end
|
||||
|
@ -279,13 +322,14 @@ class StudentWorkController < ApplicationController
|
|||
render :json => resultObj
|
||||
end
|
||||
|
||||
#上次代码查重时间
|
||||
def last_codecomparetime
|
||||
resultObj = {status: 0}
|
||||
@homework = HomeworkCommon.find params[:homework]
|
||||
|
||||
#转换一下
|
||||
if @homework.simi_time != nil
|
||||
resultObj[:comparetime] = Time.parse(@homework.simi_time.to_s).strftime("%Y-%m-%d %H:%M")
|
||||
resultObj[:comparetime] = Time.parse(@homework.simi_time.to_s).strftime("%Y-%m-%d %H:%M:%S")
|
||||
else
|
||||
resultObj[:comparetime] = 0
|
||||
end
|
||||
|
@ -330,8 +374,9 @@ class StudentWorkController < ApplicationController
|
|||
end
|
||||
end
|
||||
##################################################################################################################
|
||||
@order,@b_sort,@name,@group = params[:order] || "score",params[:sort] || "desc",params[:name] || "",params[:group]
|
||||
@order,@b_sort,@name,@group = params[:order] || "score",params[:sort] || "desc",params[:name].to_s.strip || "",params[:group]
|
||||
@homework_commons = @course.homework_commons.where("publish_time <= ?",Time.now.strftime("%Y-%m-%d")).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 #是不是匿评
|
||||
@show_all = false
|
||||
|
@ -345,13 +390,13 @@ class StudentWorkController < ApplicationController
|
|||
student_in_group = '(' + group_students.map{|user| user.id}.join(',') + ')'
|
||||
end
|
||||
#开放作品 || 老师 || 超级管理员 || 禁用匿评&&作业截止&&已提交作品 显示所有列表
|
||||
if @homework.is_open == 1 || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.where(:user_id => User.current.id).empty?)
|
||||
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 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.has_committed.where(:user_id => User.current.id).empty?)
|
||||
if @order == 'lastname'
|
||||
@stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) 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
|
||||
@stundet_works = search_homework_member @homework.student_works.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.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) 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
|
||||
@stundet_works = search_homework_member @homework.student_works.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.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name
|
||||
@stundet_works = search_homework_member @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}"),@name
|
||||
end
|
||||
@show_all = true
|
||||
elsif User.current.member_of_course?(@course)
|
||||
|
@ -361,10 +406,10 @@ class StudentWorkController < ApplicationController
|
|||
if pro.nil?
|
||||
@stundet_works = []
|
||||
else
|
||||
@stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").where(:id => pro.student_work_id)
|
||||
@stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => pro.student_work_id)
|
||||
end
|
||||
else
|
||||
@stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").where(:user_id => User.current.id)
|
||||
@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
|
||||
|
@ -375,7 +420,7 @@ class StudentWorkController < ApplicationController
|
|||
my_work = @homework.student_works.where(:id => pro.student_work_id)
|
||||
end
|
||||
else
|
||||
my_work = @homework.student_works.where(:user_id => User.current.id)
|
||||
my_work = @homework.student_works.has_committed.where(:user_id => User.current.id)
|
||||
end
|
||||
@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 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的
|
||||
|
@ -384,20 +429,20 @@ class StudentWorkController < ApplicationController
|
|||
if pro.nil?
|
||||
my_work = []
|
||||
else
|
||||
my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").where(:id => pro.student_work_id)
|
||||
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.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").where(:user_id => User.current.id)
|
||||
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?
|
||||
@stundet_works = []
|
||||
else
|
||||
if @order == 'lastname'
|
||||
@stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) 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
|
||||
@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.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) 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
|
||||
@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.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name
|
||||
@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
|
||||
@show_all = true
|
||||
end
|
||||
|
@ -409,15 +454,15 @@ class StudentWorkController < ApplicationController
|
|||
return
|
||||
end
|
||||
|
||||
@student_work_count = (search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name).count
|
||||
@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 || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.where(:user_id => User.current.id).empty?)
|
||||
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 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.has_committed.where(:user_id => User.current.id).empty?)
|
||||
if @order == 'lastname'
|
||||
@stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins(:user).order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name
|
||||
@stundet_works = search_homework_member @homework.student_works.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.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name
|
||||
@stundet_works = search_homework_member @homework.student_works.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.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").order("#{@order} #{@b_sort}"),@name
|
||||
@stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").order("#{@order} #{@b_sort}"),@name
|
||||
end
|
||||
@show_all = true
|
||||
elsif User.current.member_of_course?(@course)
|
||||
|
@ -427,10 +472,10 @@ class StudentWorkController < ApplicationController
|
|||
if pro.nil?
|
||||
@stundet_works = []
|
||||
else
|
||||
@stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").where(:id => pro.student_work_id)
|
||||
@stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => pro.student_work_id)
|
||||
end
|
||||
else
|
||||
@stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").where(:user_id => User.current.id)
|
||||
@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
|
||||
|
@ -441,7 +486,7 @@ class StudentWorkController < ApplicationController
|
|||
my_work = @homework.student_works.where(:id => pro.student_work_id)
|
||||
end
|
||||
else
|
||||
my_work = @homework.student_works.where(:user_id => User.current.id)
|
||||
my_work = @homework.student_works.has_committed.where(:user_id => User.current.id)
|
||||
end
|
||||
@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 #学生 && 关闭匿评 未提交作品之前列表为空,提交了作品看到所有的
|
||||
|
@ -450,20 +495,20 @@ class StudentWorkController < ApplicationController
|
|||
if pro.nil?
|
||||
my_work = []
|
||||
else
|
||||
my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").where(:id => pro.student_work_id)
|
||||
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.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").where(:user_id => User.current.id)
|
||||
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?
|
||||
@stundet_works = []
|
||||
else
|
||||
if @order == 'lastname'
|
||||
@stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins(:user).order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name
|
||||
@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.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name
|
||||
@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.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").order("#{@order} #{@b_sort}"),@name
|
||||
@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
|
||||
@show_all = true
|
||||
end
|
||||
|
@ -474,11 +519,11 @@ 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
|
||||
|
||||
@student_work_count = (search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").order("#{@order} #{@b_sort}"),@name).count
|
||||
end
|
||||
|
||||
@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]
|
||||
respond_to do |format|
|
||||
|
@ -502,10 +547,10 @@ class StudentWorkController < ApplicationController
|
|||
return
|
||||
end
|
||||
@user = User.current
|
||||
@student_work = @homework.student_works.where("user_id = ?",User.current.id).first
|
||||
if @student_work.nil?
|
||||
#@student_work = @homework.student_works.where("user_id = ?",User.current.id).first
|
||||
#if @student_work.nil?
|
||||
@student_work = StudentWork.new
|
||||
end
|
||||
#end
|
||||
respond_to do |format|
|
||||
format.html{ render :layout => "new_base_user"}
|
||||
end
|
||||
|
@ -515,7 +560,7 @@ class StudentWorkController < ApplicationController
|
|||
# 提交作品前先判断是否已经提交
|
||||
@has_commit = false;
|
||||
if hsd_committed_work?(User.current.id, @homework.id)
|
||||
@work = StudentWork.where("user_id =? and homework_common_id =?", User.current.id, @homework.id).first
|
||||
@work = StudentWork.where("user_id =? and homework_common_id =? and work_status != 0", User.current.id, @homework.id).first
|
||||
@has_commit = true;
|
||||
#flash[:notice] = l(:notice_successful_create)
|
||||
#redirect_to edit_student_work_url(params[:student_work])
|
||||
|
@ -527,6 +572,7 @@ class StudentWorkController < ApplicationController
|
|||
if params[:student_work]
|
||||
@submit_result = true
|
||||
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.description = params[:student_work][:description]
|
||||
|
@ -541,8 +587,10 @@ class StudentWorkController < ApplicationController
|
|||
#提交作品时,计算是否迟交
|
||||
if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d")
|
||||
student_work.late_penalty = @homework.late_penalty
|
||||
student_work.work_status = 2
|
||||
else
|
||||
student_work.late_penalty = 0
|
||||
student_work.work_status = 1
|
||||
end
|
||||
if student_work.save
|
||||
if @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1
|
||||
|
@ -574,7 +622,7 @@ class StudentWorkController < ApplicationController
|
|||
stu_project.save
|
||||
end
|
||||
end
|
||||
@homework.update_attributes(:updated_at => Time.now)
|
||||
@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)
|
||||
|
@ -628,7 +676,7 @@ class StudentWorkController < ApplicationController
|
|||
if @homework.homework_detail_group.base_on_project == 1
|
||||
stu_project.project_id = @student_work_project.project_id
|
||||
else @homework.homework_detail_group.base_on_project == 0
|
||||
stu_project.project_id = -1
|
||||
stu_project.project_id = -1
|
||||
end
|
||||
stu_project.user_id = members[i].to_i
|
||||
stu_project.is_leader = 0
|
||||
|
@ -736,49 +784,67 @@ class StudentWorkController < ApplicationController
|
|||
#老师、教辅可以随时评分,学生只能在匿评作业的匿评阶段进行评分
|
||||
render_403 and return unless @is_teacher || @homework.homework_detail_manual.comment_status == 2
|
||||
@score = student_work_score @work,User.current
|
||||
if @score
|
||||
@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]
|
||||
if User.current.admin?
|
||||
@score.reviewer_role = 1
|
||||
else
|
||||
role = User.current.members.where("course_id = ?",@course.id).first.roles.first.name
|
||||
@score.reviewer_role = get_role_by_name(role)
|
||||
end
|
||||
@is_new = false
|
||||
#@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]
|
||||
#if User.current.admin?
|
||||
# @score.reviewer_role = 1
|
||||
#else
|
||||
# role = User.current.members.where("course_id = ?",@course.id).first.roles.first.name
|
||||
# @score.reviewer_role = get_role_by_name(role)
|
||||
#end
|
||||
#@is_new = false
|
||||
@is_last_a = @work.student_works_scores.empty?
|
||||
@new_score = StudentWorksScore.new
|
||||
if @score && params[:score]
|
||||
@new_score.score = params[:score].to_i == -1 ? @score.score : params[:score]
|
||||
elsif @score.nil? && params[:score]
|
||||
@new_score.score = params[:score].to_i == -1 ? nil : params[:score]
|
||||
end
|
||||
@new_score.comment = params[:new_form][:user_message] if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != ""
|
||||
@new_score.user_id = User.current.id
|
||||
@new_score.student_work_id = @work.id
|
||||
if @is_teacher && @work.work_status == 0
|
||||
@work.update_column('work_status', 1)
|
||||
end
|
||||
if User.current.admin?
|
||||
@new_score.reviewer_role = 1
|
||||
else
|
||||
@is_last_a = @work.student_works_scores.empty?
|
||||
@score = StudentWorksScore.new
|
||||
@score.score = params[:score] if params[:score]
|
||||
@score.comment = params[:new_form][:user_message] if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != ""
|
||||
@score.user_id = User.current.id
|
||||
@score.student_work_id = @work.id
|
||||
if User.current.admin?
|
||||
@score.reviewer_role = 1
|
||||
role = User.current.members.where("course_id = ?",@course.id).first.roles.first.name
|
||||
@new_score.reviewer_role = get_role_by_name(role)
|
||||
end
|
||||
if @score
|
||||
if @is_teacher
|
||||
@is_new = true
|
||||
@is_last_a = false
|
||||
else
|
||||
role = User.current.members.where("course_id = ?",@course.id).first.roles.first.name
|
||||
@score.reviewer_role = get_role_by_name(role)
|
||||
@is_new = false
|
||||
end
|
||||
else
|
||||
@is_new = true
|
||||
end
|
||||
|
||||
@score.save_attachments(params[:attachments])
|
||||
render_attachment_warning_if_needed(@score)
|
||||
@new_score.save_attachments(params[:attachments])
|
||||
render_attachment_warning_if_needed(@new_score)
|
||||
|
||||
if @score.save
|
||||
case @score.reviewer_role
|
||||
if @new_score.save
|
||||
case @new_score.reviewer_role
|
||||
when 1 #教师评分:最后一个教师评分为最终评分
|
||||
@work.teacher_score = @score.score
|
||||
@work.teacher_score = @new_score.score
|
||||
when 2 #教辅评分 教辅评分显示平均分
|
||||
@work.teaching_asistant_score = @work.student_works_scores.where(:reviewer_role => 2).average(:score).try(:round, 2).to_f
|
||||
#@work.teaching_asistant_score = @work.student_works_scores.where(:reviewer_role => 2).average(:score).try(:round, 2).to_f
|
||||
ts_score = StudentWorksScore.find_by_sql("SELECT AVG(score) AS score FROM (SELECT * FROM (SELECT * FROM student_works_scores WHERE student_work_id = #{@work.id} AND reviewer_role = 2 AND score IS NOT NULL ORDER BY created_at DESC) AS t GROUP BY user_id) AS a")
|
||||
@work.teaching_asistant_score = ts_score.first.score.nil? ? nil : ts_score.first.score.try(:round, 2).to_f
|
||||
when 3 #学生评分 学生评分显示平均分
|
||||
@work.student_score = @work.student_works_scores.where(:reviewer_role => 3).average(:score).try(:round, 2).to_f
|
||||
#@work.student_score = @work.student_works_scores.where(:reviewer_role => 3).average(:score).try(:round, 2).to_f
|
||||
stu_score = StudentWorksScore.find_by_sql("SELECT AVG(score) AS score FROM (SELECT * FROM (SELECT * FROM student_works_scores WHERE student_work_id = #{@work.id} AND reviewer_role = 3 ORDER BY created_at DESC) AS t GROUP BY user_id) AS a")
|
||||
@work.student_score = stu_score.first.score.try(:round, 2).to_f
|
||||
end
|
||||
@homework.update_attributes(:updated_at => Time.now)
|
||||
@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)
|
||||
if @work.save
|
||||
@work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => @work.id).first
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
|
@ -811,6 +877,14 @@ class StudentWorkController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
#提交未评分的评语
|
||||
def add_comments_to_work
|
||||
@work = StudentWork.find params[:id]
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
#为作品点赞
|
||||
def praise_student_work
|
||||
pt = PraiseTread.new
|
||||
|
@ -895,11 +969,9 @@ class StudentWorkController < ApplicationController
|
|||
student_work.late_penalty = @homework.late_penalty
|
||||
student_work.save
|
||||
end
|
||||
|
||||
@homework.save
|
||||
end
|
||||
|
||||
unless homework_detail_manual.absence_penalty.to_s == params[:absence_penalty].to_s
|
||||
if params[:absence_penalty] && homework_detail_manual.absence_penalty.to_s != params[:absence_penalty].to_s
|
||||
homework_detail_manual.absence_penalty = params[:absence_penalty]
|
||||
if homework_detail_manual.comment_status == 3 #当前作业处于匿评结束状态,修改缺评扣分才会修改每个作品应扣分的值
|
||||
work_ids = "(" + @homework.student_works.map(&:id).join(",") + ")"
|
||||
|
@ -917,9 +989,8 @@ class StudentWorkController < ApplicationController
|
|||
if homework_detail_manual.ta_proportion.to_s != params[:ta_proportion].to_s || @homework.teacher_priority.to_s != teacher_priority.to_s || (homework_detail_programing && homework_detail_programing.ta_proportion.to_s != params[:sy_proportion].to_s)
|
||||
homework_detail_manual.ta_proportion = params[:ta_proportion]
|
||||
homework_detail_programing.ta_proportion = params[:sy_proportion] if homework_detail_programing
|
||||
@homework.teacher_priority = teacher_priority
|
||||
@homework.update_column('teacher_priority', teacher_priority)
|
||||
|
||||
@homework.save
|
||||
homework_detail_manual.save if homework_detail_manual
|
||||
homework_detail_programing.save if homework_detail_programing
|
||||
|
||||
|
@ -928,6 +999,8 @@ class StudentWorkController < ApplicationController
|
|||
student_work.save
|
||||
end
|
||||
end
|
||||
|
||||
@homework.save
|
||||
if params[:student_path]
|
||||
redirect_to student_work_index_url(:homework => @homework.id)
|
||||
else
|
||||
|
@ -967,6 +1040,10 @@ class StudentWorkController < ApplicationController
|
|||
end
|
||||
attachment = @work.attachments.where("attachtype = 7").first
|
||||
attachment.update_attributes(:description => params[:description])
|
||||
if attachment.attachtype == 7
|
||||
student_work = StudentWork.find attachment.container_id
|
||||
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
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
|
@ -1025,7 +1102,8 @@ class StudentWorkController < ApplicationController
|
|||
all_student_ids = "(" + pro.members.map{|member| member.user_id}.join(",") + ")"
|
||||
end
|
||||
all_students = User.where("id in #{all_student_ids}")
|
||||
@commit_student_ids = @homework.student_work_projects.map{|student| student.user_id}
|
||||
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_work_projects.where("student_work_id != #{student_work_id}").map{|student| student.user_id}
|
||||
@users = searchstudent_by_name all_students,name
|
||||
respond_to do |format|
|
||||
format.js
|
||||
|
@ -1044,6 +1122,20 @@ class StudentWorkController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def get_user_infor
|
||||
req = Hash.new(false)
|
||||
user = User.where("id = #{params[:user_id].to_i}").first
|
||||
if user
|
||||
req[:id] = user.id
|
||||
req[:name] = user.show_name
|
||||
req[:student_id] = user.user_extensions.student_id
|
||||
req[:valid] = true
|
||||
else
|
||||
req[:valid] = false
|
||||
end
|
||||
render :json => req
|
||||
end
|
||||
|
||||
private
|
||||
def searchstudent_by_name users, name
|
||||
mems = []
|
||||
|
@ -1062,7 +1154,7 @@ class StudentWorkController < ApplicationController
|
|||
end
|
||||
|
||||
def hsd_committed_work?(user, homework)
|
||||
sw = StudentWork.where("user_id =? and homework_common_id =?", user, homework).first
|
||||
sw = StudentWork.where("user_id =? and homework_common_id =? and work_status != 0", user, homework).first
|
||||
sw.nil? ? result = false : result = true
|
||||
result
|
||||
end
|
||||
|
@ -1123,43 +1215,100 @@ class StudentWorkController < ApplicationController
|
|||
sheet1 = book.create_worksheet :name => "homework"
|
||||
blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
|
||||
sheet1.row(0).default_format = blue
|
||||
if @homework.homework_type == 1 #匿评作业
|
||||
sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name),
|
||||
l(:excel_t_score),l(:excel_ta_score), l(:excel_n_score),l(:excel_f_score),l(:excel_commit_time)])
|
||||
if @homework.homework_type == 1 #普通作业
|
||||
if @homework.anonymous_comment ==0
|
||||
sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),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
|
||||
sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),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 = 1
|
||||
items.each do |homework|
|
||||
sheet1[count_row,0]=homework.user.id
|
||||
sheet1[count_row,1] = homework.user.lastname.to_s + homework.user.firstname.to_s
|
||||
sheet1[count_row,1] = homework.user.show_name
|
||||
sheet1[count_row,2] = homework.user.login
|
||||
sheet1[count_row,3] = homework.user.user_extensions.student_id
|
||||
sheet1[count_row,4] = homework.user.mail
|
||||
sheet1[count_row,5] = homework.name
|
||||
sheet1[count_row,6] = homework.teacher_score.nil? ? l(:label_without_score) : format("%.2f",homework.teacher_score)
|
||||
sheet1[count_row,7] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : format("%.2f",homework.teaching_asistant_score)
|
||||
sheet1[count_row,8] = homework.student_score.nil? ? l(:label_without_score) : format("%.2f",homework.student_score)
|
||||
sheet1[count_row,9] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : format("%.2f",homework.score) : l(:label_without_score)
|
||||
sheet1[count_row,10] = format_time(homework.created_at)
|
||||
sheet1[count_row,6] = strip_html homework.description if !homework.description.nil?
|
||||
sheet1[count_row,7] = homework.teacher_score.nil? ? l(:label_without_score) : homework.teacher_score.round(2)
|
||||
sheet1[count_row,8] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : homework.teaching_asistant_score.round(2)
|
||||
if @homework.anonymous_comment ==0
|
||||
sheet1[count_row,9] = homework.student_score.nil? ? l(:label_without_score) : homework.student_score.round(2)
|
||||
sheet1[count_row,10] = (@homework.teacher_priority == 1 && !homework.teacher_score.nil?) ? 0 : homework.absence_penalty
|
||||
sheet1[count_row,11] = (@homework.teacher_priority == 1 && !homework.teacher_score.nil?) ? 0 : homework.late_penalty
|
||||
sheet1[count_row,12] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score)
|
||||
sheet1[count_row,13] = format_time(homework.created_at)
|
||||
else
|
||||
sheet1[count_row,9] = (@homework.teacher_priority == 1 && !homework.teacher_score.nil?) ? 0 : homework.late_penalty
|
||||
sheet1[count_row,10] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score)
|
||||
sheet1[count_row,11] = format_time(homework.created_at)
|
||||
end
|
||||
count_row += 1
|
||||
end
|
||||
elsif @homework.homework_type == 2 #编程作业
|
||||
sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_name),
|
||||
l(:excel_t_score),l(:excel_ta_score), l(:excel_s_score),l(:excel_n_score),l(:excel_f_score),l(:excel_commit_time)])
|
||||
if @homework.anonymous_comment ==0
|
||||
sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),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
|
||||
sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),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 = 1
|
||||
items.each do |homework|
|
||||
sheet1[count_row,0]=homework.user.id
|
||||
sheet1[count_row,1] = homework.user.lastname.to_s + homework.user.firstname.to_s
|
||||
sheet1[count_row,1] = homework.user.show_name
|
||||
sheet1[count_row,2] = homework.user.login
|
||||
sheet1[count_row,3] = homework.user.user_extensions.student_id
|
||||
sheet1[count_row,4] = homework.user.mail
|
||||
sheet1[count_row,5] = homework.name
|
||||
sheet1[count_row,6] = homework.teacher_score.nil? ? l(:label_without_score) : format("%.2f",homework.teacher_score)
|
||||
sheet1[count_row,7] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : format("%.2f",homework.teaching_asistant_score)
|
||||
sheet1[count_row,8] = homework.system_score.nil? ? l(:label_without_score) : format("%.2f",homework.system_score)
|
||||
sheet1[count_row,9] = homework.student_score.nil? ? l(:label_without_score) : format("%.2f",homework.student_score)
|
||||
sheet1[count_row,10] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : format("%.2f",homework.score) : l(:label_without_score)
|
||||
sheet1[count_row,11] = format_time(homework.created_at)
|
||||
sheet1[count_row,6] = homework.description
|
||||
sheet1[count_row,7] = homework.teacher_score.nil? ? l(:label_without_score) : homework.teacher_score.round(2)
|
||||
sheet1[count_row,8] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : homework.teaching_asistant_score.round(2)
|
||||
sheet1[count_row,9] = homework.system_score.nil? ? l(:label_without_score) : homework.system_score.round(2)
|
||||
if @homework.anonymous_comment ==0
|
||||
sheet1[count_row,10] = homework.student_score.nil? ? l(:label_without_score) : homework.student_score.round(2)
|
||||
sheet1[count_row,11] = (@homework.teacher_priority == 1 && !homework.teacher_score.nil?) ? 0 : homework.absence_penalty
|
||||
sheet1[count_row,12] = (@homework.teacher_priority == 1 && !homework.teacher_score.nil?) ? 0 : homework.late_penalty
|
||||
sheet1[count_row,13] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score)
|
||||
sheet1[count_row,14] = format_time(homework.created_at)
|
||||
else
|
||||
sheet1[count_row,10] = (@homework.teacher_priority == 1 && !homework.teacher_score.nil?) ? 0 : homework.late_penalty
|
||||
sheet1[count_row,11] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score)
|
||||
sheet1[count_row,12] = format_time(homework.created_at)
|
||||
end
|
||||
count_row += 1
|
||||
end
|
||||
elsif @homework.homework_type == 3 #分组作业
|
||||
if @homework.anonymous_comment ==0
|
||||
sheet1.row(0).concat([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
|
||||
sheet1.row(0).concat([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 = 1
|
||||
items.each do |homework|
|
||||
sheet1[count_row,0] = get_group_member_names homework
|
||||
sheet1[count_row,1] = homework.name
|
||||
sheet1[count_row,2] = (homework.project_id == 0 || homework.project_id.nil?) ? l(:excel_no_project) : homework.project.name
|
||||
sheet1[count_row,3] = strip_html homework.description
|
||||
sheet1[count_row,4] = homework.teacher_score.nil? ? l(:label_without_score) : homework.teacher_score.round(2)
|
||||
sheet1[count_row,5] = homework.teaching_asistant_score.nil? ? l(:label_without_score) : homework.teaching_asistant_score.round(2)
|
||||
if @homework.anonymous_comment ==0
|
||||
sheet1[count_row,6] = homework.student_score.nil? ? l(:label_without_score) : homework.student_score.round(2)
|
||||
sheet1[count_row,7] = (@homework.teacher_priority == 1 && !homework.teacher_score.nil?) ? 0 : homework.absence_penalty
|
||||
sheet1[count_row,8] = (@homework.teacher_priority == 1 && !homework.teacher_score.nil?) ? 0 : homework.late_penalty
|
||||
sheet1[count_row,9] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score)
|
||||
sheet1[count_row,10] = format_time(homework.created_at)
|
||||
else
|
||||
sheet1[count_row,6] = (@homework.teacher_priority == 1 && !homework.teacher_score.nil?) ? 0 : homework.late_penalty
|
||||
sheet1[count_row,7] = homework.respond_to?("score") ? homework.score.nil? ? l(:label_without_score) : homework.score.round(2) : l(:label_without_score)
|
||||
sheet1[count_row,8] = format_time(homework.created_at)
|
||||
end
|
||||
count_row += 1
|
||||
end
|
||||
end
|
||||
book.write xls_report
|
||||
xls_report.string
|
||||
|
@ -1220,11 +1369,11 @@ class StudentWorkController < ApplicationController
|
|||
student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id).first
|
||||
if student_work.nil?
|
||||
@homework.student_works.build(
|
||||
name: params[:title],
|
||||
description: params[:src],
|
||||
user_id: User.current.id,
|
||||
is_test: is_test
|
||||
)
|
||||
name: params[:title],
|
||||
description: params[:src],
|
||||
user_id: User.current.id,
|
||||
is_test: is_test
|
||||
)
|
||||
unless @homework.save
|
||||
logger.debug @homework.errors.full_messages
|
||||
else
|
||||
|
@ -1245,7 +1394,7 @@ class StudentWorkController < ApplicationController
|
|||
src:src,
|
||||
language:@homework.homework_detail_programing.language,
|
||||
factor: factor
|
||||
}
|
||||
}
|
||||
uri = URI(url)
|
||||
body = solutions.to_json
|
||||
res = Net::HTTP.new(uri.host, uri.port).start do |client|
|
||||
|
@ -1276,7 +1425,6 @@ class StudentWorkController < ApplicationController
|
|||
request["Content-Type"] = "application/json"
|
||||
client.request(request)
|
||||
end
|
||||
|
||||
JSON.parse(res.body)
|
||||
end
|
||||
|
||||
|
@ -1287,6 +1435,7 @@ class StudentWorkController < ApplicationController
|
|||
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
|
||||
else
|
||||
if student_work.teaching_asistant_score.nil?
|
||||
student_work.final_score = student_work.student_score
|
||||
|
@ -1299,6 +1448,12 @@ class StudentWorkController < ApplicationController
|
|||
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.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?
|
||||
|
@ -1312,11 +1467,18 @@ class StudentWorkController < ApplicationController
|
|||
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.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
|
||||
else
|
||||
if student_work.teaching_asistant_score.nil? #教辅未评分
|
||||
if student_work.student_score.nil?
|
||||
|
@ -1345,6 +1507,12 @@ class StudentWorkController < ApplicationController
|
|||
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.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? #教辅未评分
|
||||
|
@ -1374,6 +1542,12 @@ class StudentWorkController < ApplicationController
|
|||
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.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score
|
||||
else
|
||||
student_work.work_score = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,218 @@
|
|||
class SubDocumentCommentsController < ApplicationController
|
||||
before_filter :find_subdomain_and_subfield, :only => [:new, :create, :show, :index, :destroy, :edit]
|
||||
before_filter :find_subfield_content, :only => [:show, :index]
|
||||
before_filter :authorize_allowed, :only => [:create, :add_reply]
|
||||
helper :attachments,:organizations
|
||||
layout 'base_org_custom'
|
||||
|
||||
def new
|
||||
@sub_document_comment = SubDocumentComment.new
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@sub_document_comment = SubDocumentComment.new(:sub_domain_id => params[:sub_domain_id], :creator_id => User.current.id, :org_subfield_id => params[:org_subfield_id])
|
||||
@sub_document_comment.title = params[:sub_document_comment][:title]
|
||||
@sub_document_comment.content = params[:sub_document_comment][:content]
|
||||
# @sub_document_comment.save_attachments(params[:attachments])
|
||||
if params[:field_id]
|
||||
@sub_document_comment.org_subfield_id = params[:field_id].to_i
|
||||
end
|
||||
if @sub_document_comment.save
|
||||
flash.keep[:notice] = l(:notice_successful_create)
|
||||
redirect_to org_subfield_sub_domain_sub_document_comments_path(:org_subfield_id => @org_subfield.id, :sub_domain_id => @subdomain.id)
|
||||
# EditorOfDocument.create(:editor_id => User.current.id, :org_document_comment_id => @sub_document_comment.id, :created_at => @sub_document_comment.updated_at)
|
||||
# if params[:field_id]
|
||||
# @org_subfield = OrgSubfield.find(params[:field_id])
|
||||
# if @org_subfield.subfield_subdomain_dir.nil?
|
||||
# redirect_to organization_path(@organization, :org_subfield_id => params[:field_id])
|
||||
# else
|
||||
# redirect_to show_org_subfield_organization_path(:id => @organization.id, :sub_dir_name => @org_subfield.subfield_subdomain_dir.name)
|
||||
# end
|
||||
# else
|
||||
# redirect_to organization_org_document_comments_path(@organization)
|
||||
# end
|
||||
else
|
||||
redirect_to new_org_document_comment_path(:organization_id => @organization.id)
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
|
||||
@document = SubDocumentComment.find(params[:id])
|
||||
respond_to do |format|
|
||||
format.html {render :layout => @organization.switch_type ? 'base_org_custom' : 'base_org'}
|
||||
end
|
||||
else
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
||||
def index
|
||||
if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
|
||||
@documents = @subdomain.sub_document_comments.where("parent_id is null").order("created_at desc")
|
||||
@is_remote = true
|
||||
@limit = 20
|
||||
@atta_count = @documents.count
|
||||
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
|
||||
@offset ||= @atta_pages.offset
|
||||
@documents = paginateHelper @documents,20
|
||||
respond_to do |format|
|
||||
format.html {render :layout => @organization.switch_type ? 'base_org_custom' : 'base_org'}
|
||||
end
|
||||
else
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@sub_document = SubDocumentComment.find(params[:id])
|
||||
@sub_document.update_attributes(:title => params[:sub_document_comment][:title], :content => params[:sub_document_comment][:content])
|
||||
@organization = OrgSubfield.find(params[:org_subfield_id]).organization
|
||||
# Attachment.attach_files(@org_document, params[:attachments])
|
||||
# @org_document.save_attachments(params[:attachments])
|
||||
if @sub_document.parent.nil?
|
||||
act = OrgActivity.where("org_act_type='SubDocumentComment' and org_act_id =?", @sub_document.id).first
|
||||
act.update_attributes(:updated_at => @sub_document.updated_at)
|
||||
# EditorOfDocument.create(:editor_id => User.current.id, :org_document_comment_id => @org_document.id, :created_at => Time.now)
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
if params[:flag].to_i == 0
|
||||
|
||||
# render :action => 'index', :layout => @organization.switch_type ? 'base_sub_domain' : 'base_org'
|
||||
redirect_to org_subfield_sub_domain_sub_document_comments_path(:org_subfield_id => params[:org_subfield_id], :sub_domain_id => params[:sub_domain_id])
|
||||
# render :layout => @organization.switch_type ? 'base_sub_domain' : 'base_org'
|
||||
# redirect_to organization_path(@organization)
|
||||
else
|
||||
redirect_to org_subfield_sub_domain_sub_document_comment_path(:org_subfield_id => params[:org_subfield_id], :sub_domain_id => params[:sub_domain_id])
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@sub_document = SubDocumentComment.find(params[:id])
|
||||
@flag = params[:flag]
|
||||
render :layout => @organization.switch_type ? 'base_sub_domain' : 'base_org'
|
||||
end
|
||||
|
||||
def add_reply
|
||||
@document = SubDocumentComment.find(params[:id]).root
|
||||
@subdomain = @document.sub_domain
|
||||
@org_subfield = @subdomain.org_subfield
|
||||
@organization = @org_subfield.organization
|
||||
@act = OrgActivity.find(params[:id])
|
||||
@comment = SubDocumentComment.new(:sub_domain_id => @document.sub_domain, :creator_id => User.current.id, :reply_id => params[:id])
|
||||
@comment.content = params[:sub_content]
|
||||
@document.children << @comment
|
||||
@document.save
|
||||
end
|
||||
|
||||
def add_reply_in_doc
|
||||
@document = SubDocumentComment.find(params[:id]).root
|
||||
@subdomain = @document.sub_domain
|
||||
@org_subfield = @subdomain.org_subfield
|
||||
@organization = @org_subfield.organization
|
||||
@comment = SubDocumentComment.new(:sub_domain_id => @document.sub_domain_id, :creator_id => User.current.id, :reply_id => params[:id])
|
||||
@comment.content = params[:flag] ? params[:sub_content] : params[:org_comment][:sub_content]
|
||||
@document.children << @comment
|
||||
@document.save
|
||||
respond_to do |format|
|
||||
format.html {redirect_to org_subfield_sub_domain_sub_document_comment_path(:id => @document.id, :org_subfield_id => @org_subfield.id, :sub_domain_id => @subdomain.id)}
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@sub_document_comment = SubDocumentComment.find(params[:id])
|
||||
@sub_document_comment.destroy
|
||||
@sub_domain = @sub_document_comment.sub_domain
|
||||
@org_subfield = @sub_domain.org_subfield
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
respond_to do |format|
|
||||
# format.html{
|
||||
# redirect_to org_subfield_sub_domain_sub_document_comments_path(:id => params[:sub_domain_id], :org_subfield_id => params[:org_subfield_id])
|
||||
# }
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def delete_reply
|
||||
@sub_document_comment = OrgDocumentComment.find(params[:id])
|
||||
@document = @sub_document_comment.root
|
||||
org = @sub_document_comment.organization
|
||||
@sub_document_comment.destroy
|
||||
respond_to do |format|
|
||||
format.html {redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id)}
|
||||
end
|
||||
end
|
||||
def quote
|
||||
@org_comment = OrgDocumentComment.find(params[:id])
|
||||
@subject = @org_comment.content
|
||||
@subject = "RE: #{@subject}" unless @subject.starts_with?('RE:')
|
||||
|
||||
@content = "> #{ll(Setting.default_language, :text_user_wrote, User.find(@org_comment.creator_id).realname)}\n> "
|
||||
@temp = OrgDocumentComment.new
|
||||
#@course_id = params[:course_id]
|
||||
@temp.content = "<blockquote>#{ll(Setting.default_language, :text_user_wrote, User.find(@org_comment.creator_id).realname)} <br/>#{@org_comment.content.html_safe}</blockquote>".html_safe
|
||||
respond_to do | format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def reply
|
||||
@document = OrgDocumentComment.find(params[:id]).root
|
||||
@quote = params[:quote][:quote]
|
||||
@org_document = OrgDocumentComment.new(:creator_id => User.current.id, :reply_id => params[:id])
|
||||
|
||||
# params[:blog_comment][:sticky] = params[:blog_comment][:sticky] || 0
|
||||
# params[:blog_comment][:locked] = params[:blog_comment][:locked] || 0
|
||||
@org_document.title = params[:org_document_comment][:title]
|
||||
@org_document.content = params[:org_document_comment][:content]
|
||||
@org_document.content = @quote + @org_document.content
|
||||
#@org_document.title = "RE: #{@article.title}" unless params[:blog_comment][:title]
|
||||
@document.children << @org_document
|
||||
# @user_activity_id = params[:user_activity_id]
|
||||
# user_activity = UserActivity.where("act_type='BlogComment' and act_id =#{@article.id}").first
|
||||
# if user_activity
|
||||
# user_activity.updated_at = Time.now
|
||||
# user_activity.save
|
||||
# end
|
||||
# attachments = Attachment.attach_files(@org_document, params[:attachments])
|
||||
# render_attachment_warning_if_needed(@org_document)
|
||||
#@article.save
|
||||
# redirect_to user_blogs_path(:user_id=>params[:user_id])
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
# if params[:course_id] #如果呆了course_id过来了,那么这是要跳到课程大纲去的
|
||||
# redirect_to syllabus_course_path(:id=>params[:course_id])
|
||||
# else
|
||||
redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id)
|
||||
# end
|
||||
|
||||
}
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_subdomain_and_subfield
|
||||
@subdomain = SubDomain.find(params[:sub_domain_id])
|
||||
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
|
||||
@organization = @org_subfield.organization
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
# source_subdomain_subfield not found
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_subfield_content
|
||||
@subfield_content = @organization.org_subfields.order("priority")
|
||||
end
|
||||
|
||||
def authorize_allowed
|
||||
unless User.current.logged?
|
||||
redirect_to signin_url
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,66 @@
|
|||
class SubDomainsController < ApplicationController
|
||||
layout 'base_org'
|
||||
before_filter :find_org_subfield_and_subdomain, :only => [:show, :index, :domain_update_priority, :destroy, :update, :hide_sub_domain, :show_sub_domain]
|
||||
|
||||
def new
|
||||
@subdomain = SubDomain.new
|
||||
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
|
||||
@organization = @org_subfield.organization
|
||||
end
|
||||
|
||||
def create
|
||||
if SubDomain.where("org_subfield_id=#{params[:org_subfield_id]} and name=?",params[:name]).count == 0
|
||||
@res = true
|
||||
@subfield = OrgSubfield.find(params[:org_subfield_id])
|
||||
@organization = @subfield.organization
|
||||
@subdomain = SubDomain.create(:name => params[:name], :org_subfield_id => params[:org_subfield_id], :priority => @subfield.sub_domains.blank? ? 1 : @subfield.sub_domains.order("priority").last.priority + 1)
|
||||
@subdomain.update_column(:field_type, params[:field_type])
|
||||
else
|
||||
@res = false
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@subdomain.update_column(:name, params[:name])
|
||||
end
|
||||
|
||||
def domain_update_priority
|
||||
@subdomain.update_attribute(:priority, params[:priority].to_i)
|
||||
end
|
||||
|
||||
def destroy
|
||||
@subdomain.destroy
|
||||
end
|
||||
|
||||
def show
|
||||
render_404
|
||||
# @subfield_content = @organization.org_subfields.order("priority")
|
||||
# render layout: @organization.switch_type ? 'base_sub_domain' : 'base_org'
|
||||
end
|
||||
|
||||
def index
|
||||
|
||||
end
|
||||
|
||||
def hide_sub_domain
|
||||
@subdomain.update_attribute(:hide, 1)
|
||||
end
|
||||
|
||||
def show_sub_domain
|
||||
@subdomain.update_attribute(:hide, 0)
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def find_org_subfield_and_subdomain
|
||||
@subfield = OrgSubfield.find(params[:org_subfield_id])
|
||||
@subdomain = SubDomain.find(params[:id])
|
||||
@organization = @subfield.organization
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
# source_subdomain not found
|
||||
render_404
|
||||
end
|
||||
end
|
|
@ -0,0 +1,182 @@
|
|||
# encoding: utf-8
|
||||
class SyllabusesController < ApplicationController
|
||||
include ApplicationHelper
|
||||
helper :attachments
|
||||
include AttachmentsHelper
|
||||
include CoursesHelper
|
||||
|
||||
before_filter :is_logged, :only => [:index, :show, :edit, :new, :update, :destroy, :delete_syllabus]
|
||||
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]
|
||||
def index
|
||||
user = User.current
|
||||
@syllabuses = user.syllabuses
|
||||
end
|
||||
|
||||
def show
|
||||
#@courses = @syllabus.courses
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html{render :layout => 'base_syllabus'}
|
||||
format.api
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@syllabus = Syllabus.new
|
||||
render :layout => 'new_base'
|
||||
end
|
||||
|
||||
def create
|
||||
if User.current.user_extensions.identity
|
||||
@syllabus = Syllabus.new
|
||||
@syllabus.title = params[:title]
|
||||
@syllabus.eng_name = params[:eng_name]
|
||||
@syllabus.user_id = User.current.id
|
||||
@syllabus.description = Message.where("id = 19412").first.nil? ? '' : Message.where("id = 19412").first.content
|
||||
if @syllabus && @syllabus.save
|
||||
respond_to do |format|
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
format.html {redirect_to syllabus_path(@syllabus)}
|
||||
format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'syllabuses', :action => 'show', :id => @syllabus.id) }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
flash[:notice] = l(:notice_create_failed)
|
||||
format.html { redirect_to new_syllabus_path } #Added by young
|
||||
format.api { render_validation_errors(@syllabus) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
respond_to do |format|
|
||||
format.html{render :layout => 'base_syllabus'}
|
||||
end
|
||||
end
|
||||
|
||||
def delete_syllabus
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@syllabus.description = params[:syllabus][:description]
|
||||
@syllabus.des_status = 1
|
||||
@syllabus.save_attachments(params[:attachments])
|
||||
if @syllabus.save
|
||||
if params[:asset_id]
|
||||
ids = params[:asset_id].split(',')
|
||||
update_kindeditor_assets_owner ids,@syllabus.id,OwnerTypeHelper::SYLLABUS
|
||||
end
|
||||
redirect_to syllabus_path(@syllabus)
|
||||
else
|
||||
redirect_to syllabus_path(@syllabus)
|
||||
end
|
||||
end
|
||||
|
||||
#删除课程大纲的描述
|
||||
def delete_des
|
||||
if @syllabus
|
||||
@syllabus.description = Message.where("id = 19412").first.nil? ? '' : Message.where("id = 19412").first.content
|
||||
@syllabus.des_status = 0
|
||||
@syllabus.attachments.destroy_all
|
||||
if @syllabus.save
|
||||
redirect_to syllabus_path(@syllabus)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @syllabus && @syllabus.courses.empty?
|
||||
@syllabus.destroy
|
||||
redirect_to user_courselist_user_path(User.current.id)
|
||||
end
|
||||
end
|
||||
|
||||
#班级列表
|
||||
def syllabus_courselist
|
||||
@order, @c_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1
|
||||
|
||||
#确定 sort_type
|
||||
if @order.to_i == @type.to_i
|
||||
@c_sort = @c_sort.to_i == 1 ? 2 : 1 #1升序 2降序
|
||||
else
|
||||
@c_sort = 2
|
||||
end
|
||||
|
||||
sort_name = "updated_on"
|
||||
sort_type = @c_sort == 1 ? "asc" : "desc"
|
||||
|
||||
@courses = User.current.courses.visible.where("is_delete =? and syllabus_id =?", 0, @syllabus.id).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS #{sort_name}").order("#{sort_name} #{sort_type}")
|
||||
|
||||
#根据 作业+资源数排序
|
||||
if @order.to_i == 2
|
||||
@type = 2
|
||||
@courses.each do |course|
|
||||
course[:infocount] = (User.current.admin? || User.current.allowed_to?(:as_teacher,course)) ? (course.homework_commons.count + visable_attachemnts_incourse(course).count) : (course.homework_commons.where("publish_time <= '#{Date.today}'").count + visable_attachemnts_incourse(course).count)
|
||||
if course[:infocount] < 0
|
||||
course[:infocount] = 0
|
||||
end
|
||||
end
|
||||
@c_sort == 1 ? (@courses = @courses.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@courses = @courses.sort{|x,y| y[:infocount] <=> x[:infocount]})
|
||||
@courses = sortby_time_countcommon_nosticky @courses,sort_name
|
||||
else
|
||||
@type = 1
|
||||
end
|
||||
|
||||
#分页
|
||||
@limit = 10
|
||||
@is_remote = true
|
||||
@atta_count = @courses.count
|
||||
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
|
||||
@offset ||= @atta_pages.offset
|
||||
@courses = paginateHelper @courses,@limit
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html{render :layout => 'base_syllabus'}
|
||||
end
|
||||
end
|
||||
|
||||
#修改课程名称
|
||||
def edit_syllabus_title
|
||||
if @syllabus && params[:title] != ""
|
||||
@syllabus.update_column("title",params[:title])
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
#修改英文名称
|
||||
def edit_syllabus_eng_name
|
||||
if @syllabus
|
||||
@syllabus.update_column("eng_name",params[:eng_name])
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
#编辑属性
|
||||
def update_base_info
|
||||
if @syllabus
|
||||
@syllabus.update_attributes(:credit => params[:credit], :hours => params[:hours], :theory_hours => params[:theory_hours], :practice_hours => params[:practice_hours], :applicable_major => params[:applicable_major], :pre_course => params[:pre_course])
|
||||
@syllabus.update_attributes(:syllabus_type => params[:syllabus_type])
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_syllabus
|
||||
@syllabus = Syllabus.find params[:id]
|
||||
end
|
||||
|
||||
def is_logged
|
||||
redirect_to signin_path unless User.current.logged?
|
||||
end
|
||||
end
|
|
@ -13,6 +13,7 @@ class TagsController < ApplicationController
|
|||
include ForumsHelper
|
||||
include AttachmentsHelper
|
||||
include ContestsHelper
|
||||
include SyllabusesHelper
|
||||
include ActsAsTaggableOn::TagsHelper
|
||||
include TagsHelper
|
||||
include FilesHelper
|
||||
|
@ -529,6 +530,8 @@ class TagsController < ApplicationController
|
|||
@obj = Course.find_by_id(@obj_id)
|
||||
when '10'
|
||||
@obj = Attachment.find_by_id(@obj_id)
|
||||
when '11'
|
||||
@obj = Syllabus.find_by_id(@obj_id)
|
||||
else
|
||||
@obj = nil
|
||||
end
|
||||
|
@ -619,6 +622,9 @@ class TagsController < ApplicationController
|
|||
when '9' then
|
||||
@obj = Course.find_by_id(obj_id)
|
||||
@obj_pages, @courses_results, @results_count = for_pagination(get_courses_by_tag(selected_tags))
|
||||
when '11' then
|
||||
@obj = Syllabus.find_by_id(obj_id)
|
||||
@obj_pages, @syllabuses_results, @results_count = for_pagination(get_syllabuses_by_tag(selected_tags))
|
||||
else
|
||||
@obj = nil
|
||||
end
|
||||
|
@ -684,6 +690,8 @@ class TagsController < ApplicationController
|
|||
return 'Course'
|
||||
when '10'
|
||||
return 'Attachment'
|
||||
when '11'
|
||||
return 'Syllabus'
|
||||
else
|
||||
render_error :message => e.message
|
||||
return
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,327 @@
|
|||
#coding=utf-8
|
||||
class WechatsController < ActionController::Base
|
||||
wechat_responder
|
||||
|
||||
include ApplicationHelper
|
||||
ROOT_URL = ENV["wechat_url"] || "#{Setting.protocol}://#{Setting.host_name}"
|
||||
#ROOT_URL = "http://www.trustie.net"
|
||||
# default text responder when no other match
|
||||
on :text do |request, content|
|
||||
#邀请码
|
||||
if join_request(request)
|
||||
sendBindClass(request, {invite_code: content})
|
||||
else
|
||||
request.reply.text '您的意见已收到,感谢您的反馈!'
|
||||
end
|
||||
end
|
||||
|
||||
# When receive 'help', will trigger this responder
|
||||
on :text, with: 'help' do |request|
|
||||
request.reply.text 'help content'
|
||||
end
|
||||
|
||||
# When receive '<n>news', will match and will got count as <n> as parameter
|
||||
on :text, with: /^(\d+) news$/ do |request, count|
|
||||
# Wechat article can only contain max 10 items, large than 10 will dropped.
|
||||
news = (1..count.to_i).each_with_object([]) { |n, memo| memo << { title: 'News title', content: "No. #{n} news content" } }
|
||||
request.reply.news(news) do |article, n, index| # article is return object
|
||||
article.item title: "#{index} #{n[:title]}", description: n[:content], pic_url: 'http://www.baidu.com/img/bdlogo.gif', url: 'http://www.baidu.com/'
|
||||
end
|
||||
end
|
||||
|
||||
on :event, with: 'subscribe' do |request|
|
||||
default_msg(request)
|
||||
end
|
||||
|
||||
# When unsubscribe user scan qrcode qrscene_xxxxxx to subscribe in public account
|
||||
# notice user will subscribe public account at same time, so wechat won't trigger subscribe event any more
|
||||
on :scan, with: 'qrscene_xxxxxx' do |request, ticket|
|
||||
request.reply.text "Unsubscribe user #{request[:FromUserName]} Ticket #{ticket}"
|
||||
end
|
||||
|
||||
# When subscribe user scan scene_id in public account
|
||||
on :scan, with: 'scene_id' do |request, ticket|
|
||||
sendBindClass(request, {ticket: ticket})
|
||||
end
|
||||
|
||||
# When no any on :scan responder can match subscribe user scaned scene_id
|
||||
on :event, with: 'scan' do |request|
|
||||
if request[:EventKey].present?
|
||||
sendBindClass(request, {ticket: request[:Ticket]})
|
||||
end
|
||||
end
|
||||
|
||||
# When enterprise user press menu BINDING_QR_CODE and success to scan bar code
|
||||
on :scan, with: 'BINDING_QR_CODE' do |request, scan_result, scan_type|
|
||||
request.reply.text "User #{request[:FromUserName]} ScanResult #{scan_result} ScanType #{scan_type}"
|
||||
end
|
||||
|
||||
# Except QR code, wechat can also scan CODE_39 bar code in enterprise account
|
||||
on :scan, with: 'BINDING_BARCODE' do |message, scan_result|
|
||||
if scan_result.start_with? 'CODE_39,'
|
||||
message.reply.text "User: #{message[:FromUserName]} scan barcode, result is #{scan_result.split(',')[1]}"
|
||||
end
|
||||
end
|
||||
|
||||
# When user click the menu button
|
||||
on :click, with: 'BOOK_LUNCH' do |request, key|
|
||||
request.reply.text "User: #{request[:FromUserName]} click #{key}"
|
||||
end
|
||||
|
||||
on :click, with: 'DEV' do |request, key|
|
||||
request.reply.text "此功能正在开发中,很快就会上线,谢谢!"
|
||||
end
|
||||
# When user view URL in the menu button
|
||||
on :view, with: 'http://wechat.somewhere.com/view_url' do |request, view|
|
||||
request.reply.text "#{request[:FromUserName]} view #{view}"
|
||||
end
|
||||
|
||||
# When user sent the imsage
|
||||
on :image do |request|
|
||||
request.reply.image(request[:MediaId]) # Echo the sent image to user
|
||||
end
|
||||
|
||||
# When user sent the voice
|
||||
on :voice do |request|
|
||||
request.reply.voice(request[:MediaId]) # Echo the sent voice to user
|
||||
end
|
||||
|
||||
# When user sent the video
|
||||
on :video do |request|
|
||||
nickname = wechat.user(request[:FromUserName])['nickname'] # Call wechat api to get sender nickname
|
||||
request.reply.video(request[:MediaId], title: 'Echo', description: "Got #{nickname} sent video") # Echo the sent video to user
|
||||
end
|
||||
|
||||
# When user sent location
|
||||
on :location do |request|
|
||||
request.reply.text("Latitude: #{message[:Latitude]} Longitude: #{message[:Longitude]} Precision: #{message[:Precision]}")
|
||||
end
|
||||
|
||||
on :event, with: 'unsubscribe' do |request|
|
||||
request.reply.success # user can not receive this message
|
||||
end
|
||||
|
||||
# When user enter the app / agent app
|
||||
on :event, with: 'enter_agent' do |request|
|
||||
request.reply.text "#{request[:FromUserName]} enter agent app now"
|
||||
end
|
||||
|
||||
# When batch job create/update user (incremental) finished.
|
||||
on :batch_job, with: 'sync_user' do |request, batch_job|
|
||||
request.reply.text "sync_user job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}"
|
||||
end
|
||||
|
||||
# When batch job replace user (full sync) finished.
|
||||
on :batch_job, with: 'replace_user' do |request, batch_job|
|
||||
request.reply.text "replace_user job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}"
|
||||
end
|
||||
|
||||
# When batch job invent user finished.
|
||||
on :batch_job, with: 'invite_user' do |request, batch_job|
|
||||
request.reply.text "invite_user job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}"
|
||||
end
|
||||
|
||||
# When batch job replace department (full sync) finished.
|
||||
on :batch_job, with: 'replace_party' do |request, batch_job|
|
||||
request.reply.text "replace_party job #{batch_job[:JobId]} finished, return code #{batch_job[:ErrCode]}, return message #{batch_job[:ErrMsg]}"
|
||||
end
|
||||
|
||||
# Any not match above will fail to below
|
||||
on :fallback, respond: 'fallback message'
|
||||
|
||||
on :click, with: 'FEEDBACK' do |request, key|
|
||||
request.reply.text "如有反馈问题,请直接切换至输入框,发微信给我们即可"
|
||||
end
|
||||
|
||||
on :click, with: 'MY_NEWS' do |request, key|
|
||||
default_msg(request)
|
||||
end
|
||||
|
||||
on :click, with: 'JOIN_CLASS' do |request, key|
|
||||
uw = user_binded?(request[:FromUserName])
|
||||
unless uw
|
||||
sendBind(request)
|
||||
else
|
||||
request.reply.text "请直接回复5位班级邀请码\n(不区分大小写):"
|
||||
end
|
||||
end
|
||||
|
||||
def join_request(request)
|
||||
openid = request[:FromUserName]
|
||||
wl = WechatLog.where("openid = '#{openid}' and request_raw like '%\"Event\":\"click\"%'").order('id desc').first
|
||||
wl && JSON(wl.request_raw)["EventKey"] == 'JOIN_CLASS'
|
||||
end
|
||||
|
||||
def sendBindClass(request, params)
|
||||
begin
|
||||
uw = user_binded?(request[:FromUserName])
|
||||
if !uw
|
||||
return sendBind(request)
|
||||
else
|
||||
return join_class(params, uw.user, request)
|
||||
end
|
||||
rescue => e
|
||||
logger.error e.inspect
|
||||
logger.error e.backtrace.join("\n")
|
||||
return request.reply.text e
|
||||
end
|
||||
end
|
||||
|
||||
def default_msg(request)
|
||||
uw = user_binded?(request[:FromUserName])
|
||||
if uw && uw.user
|
||||
request.reply.text "欢迎回来, #{uw.user.show_name}"
|
||||
else
|
||||
sendBind(request)
|
||||
end
|
||||
end
|
||||
|
||||
def sendBind(request)
|
||||
news = (1..1).each_with_object([]) { |n, memo| memo << { title: '绑定登录', content: "欢迎使用Trustie创新实践服务平台!
|
||||
在这里您可以随时了解您的课程和项目动态,随时点赞和回复。
|
||||
我们将会与微信不断结合,为您提供更有价值的服务。
|
||||
|
||||
您还未绑定确实的用户,请先绑定,谢谢!" } }
|
||||
request.reply.news(news) do |article, n, index| # article is return object
|
||||
url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{ROOT_URL+'/wechat/user_activities'}&response_type=code&scope=snsapi_base&state=login#wechat_redirect"
|
||||
pic_url = "#{ROOT_URL}/images/weixin_pic.jpg"
|
||||
article.item title: "#{n[:title]}",
|
||||
description: n[:content],
|
||||
pic_url: pic_url,
|
||||
url: url
|
||||
end
|
||||
end
|
||||
|
||||
def join_class(params, user, request)
|
||||
course = nil
|
||||
course = Course.where(qrcode: params[:ticket]).first if params[:ticket]
|
||||
course = Course.where(invite_code: params[:invite_code]).first if params[:invite_code]
|
||||
raise "班级不存在,请确认您的邀请码是否输入正确,谢谢!" unless course
|
||||
|
||||
cs = CoursesService.new
|
||||
status = cs.join_course({invite_code: course.invite_code}, user)
|
||||
logger.info status
|
||||
if status[:state] != 0
|
||||
raise CoursesService::JoinCourseError.message(status[:state])
|
||||
end
|
||||
|
||||
news = (1..1).each_with_object([]) { |n, memo| memo << { title: '恭喜您成功加入班级,开始学习吧!',
|
||||
content: "课程名称: #{course.name}\n班级名称: #{course.name}\n任课老师: #{course.teacher.show_name}\n进入班级,和小伙伴愉快的学习吧!"} }
|
||||
return request.reply.news(news) do |article, n, index| # article is return object
|
||||
url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{ROOT_URL+'/wechat/user_activities?id='+course.id.to_s}&response_type=code&scope=snsapi_base&state=myclass#wechat_redirect"
|
||||
pic_url = "#{ROOT_URL}/images/wechat/class.jpg"
|
||||
article.item title: "#{n[:title]}",
|
||||
description: n[:content],
|
||||
pic_url: pic_url,
|
||||
url: url
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
### controller method
|
||||
module Controllers
|
||||
def get_bind
|
||||
begin
|
||||
code = params[:code] || session[:wechat_code]
|
||||
openid = get_openid_from_code(code)
|
||||
|
||||
raise "无法获取到微信openid" unless openid
|
||||
|
||||
uw = UserWechat.where(openid: openid).first
|
||||
raise "还未绑定trustie帐户" unless uw
|
||||
logger.debug "get_bind ============= #{uw}"
|
||||
|
||||
user = uw.user
|
||||
::ApiKey.delete_all(user_id: user.id)
|
||||
key = ::ApiKey.create!(user_id: user.id)
|
||||
|
||||
render :json =>{status: 0, token: key.access_token}
|
||||
rescue Exception=>e
|
||||
render :json => {status: -1, message: e.message}
|
||||
end
|
||||
end
|
||||
|
||||
def bind
|
||||
begin
|
||||
|
||||
code = params[:code] || session[:wechat_code]
|
||||
openid = get_openid_from_code(code)
|
||||
|
||||
raise "无法获取到openid,请在微信中打开本页面" unless openid
|
||||
raise "此微信号已绑定用户,不能重复绑定" if user_binded?(openid)
|
||||
|
||||
user, last_login_on = User.try_to_login(params[:username], params[:password])
|
||||
raise "用户名或密码错误,请重新输入" unless user
|
||||
#补全用户信息
|
||||
|
||||
raise "此用户已经绑定过公众号,请换一个帐户试试" if user.user_wechat
|
||||
|
||||
UserWechat.create!(
|
||||
openid: openid,
|
||||
user: user
|
||||
)
|
||||
ws = WechatService.new
|
||||
ws.binding_succ_notice(user.id, "您已成功绑定Trustie平台", user.login, format_time(Time.now))
|
||||
render :json => {status:0, msg: "绑定成功"}
|
||||
rescue Exception=>e
|
||||
render :json => {status: -1, msg: e.message}
|
||||
end
|
||||
end
|
||||
|
||||
def login
|
||||
session[:wechat_code] = params[:code] if params[:code]
|
||||
openid = get_openid_from_code(params[:code])
|
||||
@wechat_user = user_binded?(openid)
|
||||
|
||||
render 'wechats/login', layout: 'base_wechat'
|
||||
end
|
||||
|
||||
def user_activities
|
||||
session[:wechat_code] = params[:code] if params[:code]
|
||||
@path = '/'+(params[:state] || '')
|
||||
open_id = get_openid_from_code(params[:code]) rescue
|
||||
unless open_id
|
||||
render 'wechats/open_wechat', layout: nil and return
|
||||
end
|
||||
if params[:state] == 'myclass'
|
||||
@course_id = params[:id];
|
||||
end
|
||||
|
||||
session[:wechat_openid] = open_id
|
||||
if params[:code]
|
||||
redirect_to "/wechat/user_activities##{@path}?id=#{params[:id]}" and return
|
||||
end
|
||||
render 'wechats/user_activities', layout: nil
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def get_openid_from_code(code)
|
||||
return 'oCnvgvz8R7QheXE-R9Kkr39j8Ndg' if code =='only-for-test'
|
||||
openid = session[:wechat_openid]
|
||||
|
||||
unless openid
|
||||
if code
|
||||
openid = wechat.web_access_token(code)["openid"]
|
||||
end
|
||||
end
|
||||
|
||||
if openid
|
||||
session[:wechat_openid] = openid
|
||||
end
|
||||
|
||||
return openid
|
||||
end
|
||||
|
||||
def user_binded?(openid)
|
||||
uw = UserWechat.where(openid: openid).first
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
include Controllers
|
||||
|
||||
end
|
|
@ -54,15 +54,16 @@ class WordsController < ApplicationController
|
|||
:reply_id => reply_user_id,
|
||||
:notes => content,
|
||||
:is_readed => false}
|
||||
@jfm = add_reply_adapter options
|
||||
@activity = params[:activity_id].nil? ? JournalsForMessage.find(parent_id) : JournalsForMessage.find(params[:activity_id].to_i)
|
||||
@jfm = add_reply_adapter(@activity, options)
|
||||
@save_succ = true if @jfm.errors.empty?
|
||||
if @save_succ
|
||||
update_course_activity('JournalsForMessage',parent_id)
|
||||
update_user_activity('JournalsForMessage',parent_id)
|
||||
update_forge_activity('JournalsForMessage',parent_id)
|
||||
update_org_activity('JournalsForMessage',parent_id)
|
||||
update_principal_activity('JournalsForMessage',parent_id)
|
||||
(JournalsForMessage.find parent_id).update_attribute(:updated_on,Time.now)
|
||||
update_course_activity('JournalsForMessage',@activity.id)
|
||||
update_user_activity('JournalsForMessage',@activity.id)
|
||||
update_forge_activity('JournalsForMessage',@activity.id)
|
||||
update_org_activity('JournalsForMessage',@activity.id)
|
||||
update_principal_activity('JournalsForMessage',@activity.id)
|
||||
@activity.update_attribute(:updated_on,Time.now)
|
||||
end
|
||||
respond_to do |format|
|
||||
# format.html {
|
||||
|
@ -76,8 +77,6 @@ class WordsController < ApplicationController
|
|||
format.js {
|
||||
#@reply_type = params[:reply_type]
|
||||
@user_activity_id = params[:user_activity_id]
|
||||
@activity = JournalsForMessage.find(parent_id)
|
||||
@is_activity = params[:is_activity] if params[:is_activity]
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -92,13 +91,14 @@ class WordsController < ApplicationController
|
|||
elsif @journal_destroyed.jour_type == "Course"
|
||||
@course = Course.find @journal_destroyed.jour_id
|
||||
@jours_count = @course.journals_for_messages.where('m_parent_id IS NULL').count
|
||||
@user_activity_id = params[:user_activity_id] if params[:user_activity_id]
|
||||
@activity = JournalsForMessage.where("id = #{params[:activity_id].to_i}").first if params[:activity_id]
|
||||
elsif @journal_destroyed.jour_type == "Principal"
|
||||
@user = User.find(@journal_destroyed.jour_id)
|
||||
@jours_count = @user.journals_for_messages.where('m_parent_id IS NULL').count
|
||||
@is_user = true
|
||||
@user_activity_id = params[:user_activity_id] if params[:user_activity_id]
|
||||
@is_activity = params[:is_activity].to_i if params[:is_activity]
|
||||
@activity = @journal_destroyed.parent if @journal_destroyed.parent
|
||||
@activity = JournalsForMessage.where("id = #{params[:activity_id].to_i}").first if params[:activity_id]
|
||||
unless @activity
|
||||
redirect_to feedback_path(@user)
|
||||
return
|
||||
|
@ -106,7 +106,7 @@ class WordsController < ApplicationController
|
|||
elsif @journal_destroyed.jour_type == 'HomeworkCommon'
|
||||
@homework = HomeworkCommon.find @journal_destroyed.jour_id
|
||||
if params[:user_activity_id]
|
||||
@user_activity_id = params[:user_activity_id]
|
||||
@user_activity_id = params[:user_activity_id].to_i
|
||||
else
|
||||
@user_activity_id = -1
|
||||
end
|
||||
|
@ -264,6 +264,28 @@ class WordsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
#课程大纲的回复
|
||||
def leave_syllabus_message
|
||||
if User.current.logged?
|
||||
@user = User.current
|
||||
@syllabus = Syllabus.find(params[:id]);
|
||||
if params[:comment].size>0 && User.current.logged? && @user
|
||||
feedback = Syllabus.add_syllabus_jour(@user, params[:comment], params[:id])
|
||||
if (feedback.errors.empty?)
|
||||
if params[:asset_id]
|
||||
ids = params[:asset_id].split(',')
|
||||
update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE
|
||||
end
|
||||
redirect_to syllabus_path(@syllabus)
|
||||
else
|
||||
flash[:error] = feedback.errors.full_messages[0]
|
||||
end
|
||||
end
|
||||
else
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
||||
#作业的回复
|
||||
def leave_homework_message
|
||||
if User.current.logged?
|
||||
|
@ -276,7 +298,7 @@ class WordsController < ApplicationController
|
|||
ids = params[:asset_id].split(',')
|
||||
update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE
|
||||
end
|
||||
@homework_common.update_attributes(:updated_at => Time.now)
|
||||
@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)
|
||||
|
@ -296,6 +318,40 @@ class WordsController < ApplicationController
|
|||
render_403
|
||||
end
|
||||
end
|
||||
|
||||
#作业的二级回复
|
||||
def reply_to_homework
|
||||
if User.current.logged?
|
||||
@user = User.current
|
||||
reply = JournalsForMessage.find params[:id].to_i
|
||||
@homework_common = 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}
|
||||
feedback = HomeworkCommon.add_homework_jour(@user, params[:reply_message], reply.jour_id, options)
|
||||
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)
|
||||
respond_to do |format|
|
||||
format.js{
|
||||
@user_activity_id = params[:user_activity_id].to_i
|
||||
@is_in_course = params[:is_in_course].to_i
|
||||
@course_activity = params[:course_activity].to_i
|
||||
}
|
||||
end
|
||||
else
|
||||
flash[:error] = feedback.errors.full_messages[0]
|
||||
end
|
||||
end
|
||||
else
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
||||
def add_brief_introdution
|
||||
user = User.current
|
||||
|
@ -303,6 +359,27 @@ class WordsController < ApplicationController
|
|||
UserExtensions.introduction(user, message)
|
||||
redirect_to user_url(user.id)
|
||||
end
|
||||
|
||||
#邮箱激活问题留言 留言成功给出提示框
|
||||
def leave_email_activation_message
|
||||
status = 1 #成功
|
||||
me = User.find(params[:user])
|
||||
if me
|
||||
#课程使者id=1
|
||||
@user = User.find(1)
|
||||
if params[:text].size>0 && @user
|
||||
# @user.add_jour(me, params[:text])
|
||||
#私信
|
||||
message = "<span style='color:red;'>【未收到激活邮件的用户反馈,用户邮箱:"+me.mail+"】</span><br>"+params[:text]
|
||||
@user.journals_for_messages << JournalsForMessage.new(:user_id => me.id, :notes => message, :reply_id => 0, :status => true, :is_readed => false, :private => 1)
|
||||
else
|
||||
status = 0
|
||||
end
|
||||
render :json => status
|
||||
else
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
@ -340,28 +417,44 @@ class WordsController < ApplicationController
|
|||
obj
|
||||
end
|
||||
|
||||
def add_reply_adapter options
|
||||
def add_reply_adapter obj, options
|
||||
#modify by nwb
|
||||
#添加对课程留言的支持
|
||||
#留言回复应该不关系其所属的Class,而关心的是其所属的父留言
|
||||
obj = obj_distinguish_url_origin || User.find_by_id(2)
|
||||
if obj.kind_of? User
|
||||
obj.add_jour(nil, nil, nil, options)
|
||||
elsif obj.kind_of? Project
|
||||
Project.add_new_jour(nil, nil, obj.id, options)
|
||||
elsif obj.kind_of? Course
|
||||
Course.add_new_jour(nil, nil, obj.id, options)
|
||||
elsif obj.kind_of? Bid
|
||||
obj.add_jour(nil, nil, nil, options)
|
||||
elsif obj.kind_of? Contest
|
||||
obj.add_jour(nil, nil, obj.id, options) #new added
|
||||
elsif obj.kind_of? Softapplication
|
||||
obj.add_jour(nil, nil, obj.id, options) #new added
|
||||
elsif obj.kind_of? HomeworkAttach
|
||||
obj.add_jour(nil, nil, obj.id, options) #new added
|
||||
else
|
||||
raise "create reply obj unknow type.#{obj.class}"
|
||||
case obj.jour_type
|
||||
when 'Principal'
|
||||
obj.jour.add_jour(nil, nil, nil, options)
|
||||
when 'Project'
|
||||
Project.add_new_jour(nil, nil, obj.jour_id, options)
|
||||
when 'Course'
|
||||
Course.add_new_jour(nil, nil, obj.jour_id, options)
|
||||
when 'Bid'
|
||||
obj.jour.add_jour(nil, nil, nil, options)
|
||||
when 'Contest'
|
||||
obj.jour.add_jour(nil, nil, obj.jour_id, options)
|
||||
when 'Softapplication'
|
||||
obj.jour.add_jour(nil, nil, obj.jour_id, options)
|
||||
when 'HomeworkAttach'
|
||||
obj.jour.add_jour(nil, nil, obj.jour_id, options)
|
||||
end
|
||||
# obj = obj_distinguish_url_origin || User.find_by_id(2)
|
||||
# if obj.kind_of? User
|
||||
# obj.add_jour(nil, nil, nil, options)
|
||||
# elsif obj.kind_of? Project
|
||||
# Project.add_new_jour(nil, nil, obj.id, options)
|
||||
# elsif obj.kind_of? Course
|
||||
# Course.add_new_jour(nil, nil, obj.id, options)
|
||||
# elsif obj.kind_of? Bid
|
||||
# obj.add_jour(nil, nil, nil, options)
|
||||
# elsif obj.kind_of? Contest
|
||||
# obj.add_jour(nil, nil, obj.id, options) #new added
|
||||
# elsif obj.kind_of? Softapplication
|
||||
# obj.add_jour(nil, nil, obj.id, options) #new added
|
||||
# elsif obj.kind_of? HomeworkAttach
|
||||
# obj.add_jour(nil, nil, obj.id, options) #new added
|
||||
# else
|
||||
# raise "create reply obj unknow type.#{obj.class}"
|
||||
# end
|
||||
end
|
||||
#######end of message
|
||||
end
|
||||
|
|
|
@ -10,14 +10,14 @@ class ZipdownController < ApplicationController
|
|||
#勿删 before_filter :authorize, :only => [:assort,:download_user_homework]
|
||||
SAVE_FOLDER = "#{Rails.root}/files"
|
||||
OUTPUT_FOLDER = "#{Rails.root}/files/archiveZip"
|
||||
MAX_PATH = 50
|
||||
|
||||
#统一下载功能
|
||||
def download
|
||||
if User.current.logged?
|
||||
begin
|
||||
if params[:base64file]
|
||||
file = Base64.decode64(params[:base64file])
|
||||
file = file.sub('*', '+')
|
||||
file = decode64(params[:base64file])
|
||||
send_file "#{OUTPUT_FOLDER}/#{file}", :filename => filename_for_content_disposition(file), :type => detect_content_type(file)
|
||||
else
|
||||
send_file "#{OUTPUT_FOLDER}/#{params[:file]}", :filename => filename_for_content_disposition(params[:filename]), :type => detect_content_type(params[:file])
|
||||
|
@ -125,7 +125,11 @@ class ZipdownController < ApplicationController
|
|||
end
|
||||
|
||||
def encode64(str)
|
||||
Base64.encode64(str).sub('+', '*')
|
||||
Base64.urlsafe_encode64(str)
|
||||
end
|
||||
|
||||
def decode64(str)
|
||||
Base64.urlsafe_decode64(str)
|
||||
end
|
||||
|
||||
def zip_homework_common homework_common
|
||||
|
@ -242,6 +246,12 @@ class ZipdownController < ApplicationController
|
|||
|
||||
def zipping(zip_name_refer, files_paths, output_path, is_attachment=false, not_exist_file=[])
|
||||
rename_zipfile = zip_name_refer ||= "#{Time.now.to_i.to_s}.zip"
|
||||
# 文件名过长
|
||||
|
||||
if rename_zipfile.size > MAX_PATH
|
||||
rename_zipfile = rename_zipfile[0,rename_zipfile.size-4][0,MAX_PATH-4] + rename_zipfile[-4,4]
|
||||
end
|
||||
|
||||
zipfile_name = "#{output_path}/#{rename_zipfile}"
|
||||
|
||||
Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name))
|
||||
|
|
|
@ -27,6 +27,10 @@ module ApiHelper
|
|||
location
|
||||
end
|
||||
|
||||
def get_user_realname user
|
||||
name = user.lastname + user.firstname
|
||||
name.empty? || name.nil? || name == " " ? user.login : name
|
||||
end
|
||||
|
||||
def get_assigned_homeworks(homeworks, n, index)
|
||||
homeworks += homeworks
|
||||
|
@ -178,7 +182,7 @@ module ApiHelper
|
|||
timeIntoFormat = 0
|
||||
updateAtValue = ""
|
||||
if timePassed < 0
|
||||
updateAtValue = "时间有问题"
|
||||
updateAtValue = "刚刚"
|
||||
elsif timePassed < ONE_MINUTE
|
||||
updateAtValue = "1分钟前"
|
||||
elsif timePassed < ONE_HOUR
|
||||
|
@ -201,5 +205,310 @@ module ApiHelper
|
|||
|
||||
end
|
||||
|
||||
#日期转换为时间
|
||||
def convert_to_time date, num
|
||||
if num == 0
|
||||
date = date.to_s + " 00:00"
|
||||
elsif num == 1
|
||||
date = date.to_s + " 23:59"
|
||||
end
|
||||
return date
|
||||
end
|
||||
|
||||
#获取用户
|
||||
def get_user user_id
|
||||
user = User.find user_id
|
||||
user
|
||||
end
|
||||
|
||||
#获取项目
|
||||
def get_project project_id
|
||||
project = Project.find project_id
|
||||
project
|
||||
end
|
||||
|
||||
#获取课程
|
||||
def get_course course_id
|
||||
course = Course.find course_id
|
||||
course
|
||||
end
|
||||
|
||||
#获取点赞数
|
||||
def get_activity_praise_num(object)
|
||||
obj_type = object.class
|
||||
obj_id = object.id
|
||||
record = PraiseTreadCache.find_by_object_id_and_object_type(obj_id,obj_type)
|
||||
if record
|
||||
return ((record.praise_num.nil? ? 0 : record.praise_num.to_i)-(record.tread_num.nil? ? 0 : record.tread_num.to_i))
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
#获取缺陷的优先级
|
||||
def get_issue_priority_api value
|
||||
issuetype = ""
|
||||
if value == 4
|
||||
issuetype = "紧急"
|
||||
elsif value == 2
|
||||
issuetype = "正常"
|
||||
elsif value == 3
|
||||
issuetype = "高"
|
||||
elsif value == 1
|
||||
issuetype = "低"
|
||||
else
|
||||
issuetype = "立刻"
|
||||
end
|
||||
end
|
||||
|
||||
def jdetails_to_strings(details, no_html=false, options={})
|
||||
options[:only_path] = (options[:only_path] == false ? false : true)
|
||||
options[:token] = options[:token] if options[:token]
|
||||
strings = []
|
||||
values_by_field = {}
|
||||
details.each do |detail|
|
||||
|
||||
if detail.property == 'cf'
|
||||
field_id = detail.prop_key
|
||||
field = CustomField.find_by_id(field_id)
|
||||
if field && field.multiple?
|
||||
values_by_field[field_id] ||= {:added => [], :deleted => []}
|
||||
if detail.old_value
|
||||
values_by_field[field_id][:deleted] << detail.old_value
|
||||
end
|
||||
if detail.value
|
||||
values_by_field[field_id][:added] << detail.value
|
||||
end
|
||||
next
|
||||
end
|
||||
end
|
||||
strings << jshow_detail(detail, no_html, options)
|
||||
|
||||
end
|
||||
values_by_field.each do |field_id, changes|
|
||||
detail = JournalDetail.new(:property => 'cf', :prop_key => field_id)
|
||||
if changes[:added].any?
|
||||
detail.value = changes[:added]
|
||||
strings << jshow_detail(detail, no_html, options)
|
||||
elsif changes[:deleted].any?
|
||||
detail.old_value = changes[:deleted]
|
||||
strings << jshow_detail(detail, no_html, options)
|
||||
end
|
||||
end
|
||||
strings
|
||||
end
|
||||
|
||||
# Returns the textual representation of a single journal detail
|
||||
def jshow_detail(detail, no_html=false, options={})
|
||||
multiple = false
|
||||
case detail.property
|
||||
when 'attr'
|
||||
field = detail.prop_key.to_s.gsub(/\_id$/, "")
|
||||
label = l(("field_" + field).to_sym)
|
||||
case detail.prop_key
|
||||
when 'due_date', 'start_date'
|
||||
value = format_date(detail.value.to_date) if detail.value
|
||||
old_value = format_date(detail.old_value.to_date) if detail.old_value
|
||||
|
||||
when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
|
||||
'priority_id', 'category_id', 'fixed_version_id'
|
||||
value = find_name_by_reflection(field, detail.value)
|
||||
old_value = find_name_by_reflection(field, detail.old_value)
|
||||
|
||||
when 'estimated_hours'
|
||||
value = "%0.02f" % detail.value.to_f unless detail.value.blank?
|
||||
old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
|
||||
|
||||
when 'parent_id'
|
||||
label = l(:field_parent_issue)
|
||||
value = "##{detail.value}" unless detail.value.blank?
|
||||
old_value = "##{detail.old_value}" unless detail.old_value.blank?
|
||||
|
||||
when 'is_private'
|
||||
value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
|
||||
old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
|
||||
end
|
||||
when 'cf'
|
||||
custom_field = CustomField.find_by_id(detail.prop_key)
|
||||
if custom_field
|
||||
multiple = custom_field.multiple?
|
||||
label = custom_field.name
|
||||
value = format_value(detail.value, custom_field.field_format) if detail.value
|
||||
old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value
|
||||
end
|
||||
when 'attachment'
|
||||
label = l(:label_attachment)
|
||||
end
|
||||
call_hook(:helper_issues_show_detail_after_setting,
|
||||
{:detail => detail, :label => label, :value => value, :old_value => old_value })
|
||||
|
||||
label ||= detail.prop_key
|
||||
value ||= detail.value
|
||||
old_value ||= detail.old_value
|
||||
|
||||
unless no_html
|
||||
label = content_tag('strong', label)
|
||||
old_value = content_tag("i", old_value) if detail.old_value
|
||||
old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank?
|
||||
if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key)
|
||||
# Link to the attachment if it has not been removed
|
||||
if options[:token].nil?
|
||||
value = atta.filename
|
||||
else
|
||||
value = atta.filename
|
||||
end
|
||||
# 放大镜搜索功能
|
||||
# if options[:only_path] != false && atta.is_text?
|
||||
# value += link_to(
|
||||
# image_tag('magnifier.png'),
|
||||
# :controller => 'attachments', :action => 'show',
|
||||
# :id => atta, :filename => atta.filename
|
||||
# )
|
||||
# end
|
||||
else
|
||||
value = content_tag("i", value) if value
|
||||
end
|
||||
end
|
||||
# 缺陷更新结果在消息中显示样式
|
||||
if no_html == "message"
|
||||
label = content_tag(:span, label, :class => "issue_update_message")
|
||||
old_value = content_tag("span", old_value) if detail.old_value
|
||||
old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank?
|
||||
if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key)
|
||||
# Link to the attachment if it has not been removed
|
||||
if options[:token].nil?
|
||||
value = atta.filename
|
||||
else
|
||||
value = atta.filename
|
||||
end
|
||||
else
|
||||
value = content_tag(:span, value, :class => "issue_update_message_value") if value
|
||||
end
|
||||
end
|
||||
|
||||
if detail.property == 'attr' && detail.prop_key == 'description'
|
||||
s = l(:text_journal_changed_no_detail, :label => label)
|
||||
unless no_html
|
||||
diff_link = link_to l(:label_diff),
|
||||
{:controller => 'journals', :action => 'diff', :id => detail.journal_id,
|
||||
:detail_id => detail.id, :only_path => options[:only_path]},
|
||||
:title => l(:label_view_diff)
|
||||
s << " (#{ diff_link })"
|
||||
end
|
||||
s.html_safe
|
||||
elsif detail.value.present?
|
||||
case detail.property
|
||||
when 'attr', 'cf'
|
||||
if detail.old_value.present?
|
||||
l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
|
||||
elsif multiple
|
||||
l(:text_journal_added, :label => label, :value => value).html_safe
|
||||
else
|
||||
l(:text_journal_set_to, :label => label, :value => value).html_safe
|
||||
end
|
||||
when 'attachment'
|
||||
l(:text_journal_added, :label => label, :value => value).html_safe
|
||||
end
|
||||
else
|
||||
l(:text_journal_deleted, :label => label, :old => old_value).html_safe
|
||||
end
|
||||
end
|
||||
|
||||
#课程动态的更新
|
||||
def update_course_activity_api type, id
|
||||
course_activity = CourseActivity.where("course_act_type=? and course_act_id =?", type.to_s, id.to_i).first
|
||||
if course_activity
|
||||
course_activity.updated_at = Time.now
|
||||
course_activity.save
|
||||
end
|
||||
end
|
||||
#首页动态更新
|
||||
def update_user_activity_api type, id
|
||||
user_activity = UserActivity.where("act_type=? and act_id =?", type.to_s, id.to_i).first
|
||||
if user_activity
|
||||
user_activity.updated_at = Time.now
|
||||
user_activity.save
|
||||
end
|
||||
end
|
||||
#项目动态更新
|
||||
def update_forge_activity_api type, id
|
||||
forge_activity = ForgeActivity.where("forge_act_type=? and forge_act_id=?", type.to_s, id.to_i).first
|
||||
if forge_activity
|
||||
forge_activity.updated_at = Time.now
|
||||
forge_activity.save
|
||||
end
|
||||
end
|
||||
#组织动态更新
|
||||
def update_org_activity_api type , id
|
||||
org_activity = OrgActivity.where("org_act_type=? and org_act_id =?", type.to_s, id.to_i).first
|
||||
if org_activity
|
||||
org_activity.updated_at = Time.now
|
||||
org_activity.save
|
||||
end
|
||||
end
|
||||
#个人动态更新
|
||||
def update_principal_activity_api type, id
|
||||
principal_activity = PrincipalActivity.where("principal_act_type=? and principal_act_id =?", type.to_s, id.to_i).first
|
||||
if principal_activity
|
||||
principal_activity.updated_at = Time.now
|
||||
principal_activity.save
|
||||
end
|
||||
end
|
||||
|
||||
#赞/取消赞
|
||||
def praise_or_cancel(type,id,user,flag)
|
||||
unless id.nil? and type.nil?
|
||||
#首先创建或更新praise_tread 表
|
||||
pt = PraiseTread.new
|
||||
pt.user_id = user.id
|
||||
pt.praise_tread_object_id = id.to_i
|
||||
pt.praise_tread_object_type = type
|
||||
pt.praise_or_tread = flag
|
||||
pt.save
|
||||
# end
|
||||
|
||||
#再创建或更新praise_tread_cache表
|
||||
#@ptc = PraiseTreadCache.find_by_object_id_and_object_type(id,type)
|
||||
ptc = PraiseTreadCache.where("object_id = ? and object_type = ?",id.to_i,type).first
|
||||
ptc = ptc.nil? ? PraiseTreadCache.new : ptc
|
||||
ptc.object_id = id.to_i
|
||||
ptc.object_type = type
|
||||
ptc.save
|
||||
ptc.praise_plus(flag,1)
|
||||
end
|
||||
end
|
||||
|
||||
def praise_plus(flag,num)
|
||||
case flag
|
||||
when 1
|
||||
self.update_attribute(:praise_num, self.praise_num.to_i + num)
|
||||
end
|
||||
end
|
||||
|
||||
def praise_minus(num)
|
||||
self.update_attribute(:praise_num, self.praise_num.to_i - num)
|
||||
end
|
||||
|
||||
|
||||
class Errors
|
||||
def self.define_error(arr)
|
||||
@errors = {}
|
||||
arr.each_with_index { |item, index|
|
||||
if index %2 == 1
|
||||
@errors[arr[index-1]] = item
|
||||
end
|
||||
}
|
||||
if arr.count % 2== 1
|
||||
@default_error = arr.last
|
||||
else
|
||||
@default_error = "未知错误"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def self.message(msg_id)
|
||||
@errors[msg_id] || @default_error
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -33,10 +33,45 @@ module ApplicationHelper
|
|||
extend Forwardable
|
||||
def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter
|
||||
|
||||
|
||||
# def user_blogs_path(resource,parameters={})
|
||||
# super
|
||||
# end
|
||||
|
||||
|
||||
def update_visiti_count container
|
||||
container.update_column(:visits, container.visits + 1)
|
||||
end
|
||||
|
||||
def if_hidden_subdomain field
|
||||
domains = field.sub_domains.select{|domain| domain.hide.to_i == 0}
|
||||
result = domains.length > 0 ? true : false
|
||||
return result
|
||||
end
|
||||
|
||||
# 判断某个资源是否可以申请
|
||||
def attach_show_allow attach_id
|
||||
attachment = Attachment.find(attach_id)
|
||||
case attachment.container_type
|
||||
when "Project"
|
||||
User.current.member_of?(attachment.container) ? true : false
|
||||
when "Course"
|
||||
User.current.member_of_course?(attachment.container) ? true : false
|
||||
when "OrgSubfield"
|
||||
User.current.member_of_org?(attachment.container.organization) ? true : false
|
||||
when "Principal"
|
||||
User.current.id == attachment.author_id ? true : false
|
||||
end
|
||||
end
|
||||
|
||||
# 判断某个私有资源是否可以发送下载权限
|
||||
# 结果为true不能下载,false可以下载
|
||||
def private_attachment_allow attachment_id
|
||||
attach = Attachment.find(attachment_id)
|
||||
# 条件取否,result结果为true则不能下载
|
||||
result = attach.is_public == 0 && attach.author != User.current && !attach.get_apply_resource_status(attach.id, User.current.id) && !attach_show_allow(attach)
|
||||
end
|
||||
|
||||
# Time 2015-03-24 15:27:29
|
||||
# Author lizanle
|
||||
# Description 从硬盘上删除对应的资源文件
|
||||
|
@ -76,11 +111,13 @@ module ApplicationHelper
|
|||
|
||||
# 获取组织成员中文名字
|
||||
def get_org_member_role_name member
|
||||
case member.roles[0].name
|
||||
when 'orgManager'
|
||||
'管理人员'
|
||||
when 'orgMember'
|
||||
'组织成员'
|
||||
unless member.roles[0].nil?
|
||||
case member.roles[0].name
|
||||
when 'orgManager'
|
||||
'管理人员'
|
||||
when 'orgMember'
|
||||
'组织成员'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -120,60 +157,53 @@ module ApplicationHelper
|
|||
case type
|
||||
when "HomeworkCommon"
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0,
|
||||
:news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :homework_journal_num => 1)
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :homework_journal_num => 1)
|
||||
else
|
||||
score = course_contributor_score.homework_journal_num + 1
|
||||
course_contributor_score.update_attributes(:homework_journal_num => score)
|
||||
score = course_contributor_score.homework_journal_num.to_i + 1
|
||||
course_contributor_score.update_column(:homework_journal_num, score)
|
||||
end
|
||||
# 课程留言
|
||||
when "Course"
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0,
|
||||
:news_reply_num => 0, :resource_num => 0, :journal_num => 1, :journal_reply_num => 0)
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :journal_num => 1)
|
||||
else
|
||||
score = course_contributor_score.journal_num + 1
|
||||
course_contributor_score.update_attributes(:journal_num => score)
|
||||
score = course_contributor_score.journal_num.to_i + 1
|
||||
course_contributor_score.update_column(:journal_num, score)
|
||||
end
|
||||
when "Message"
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 1, :message_reply_num => 0,
|
||||
:news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0)
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 1)
|
||||
else
|
||||
score = course_contributor_score.message_num + 1
|
||||
course_contributor_score.update_attributes(:message_num => score)
|
||||
score = course_contributor_score.message_num.to_i + 1
|
||||
course_contributor_score.update_column(:message_num, score)
|
||||
end
|
||||
when "MessageReply"
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 1,
|
||||
:news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0)
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_reply_num => 1)
|
||||
else
|
||||
score = course_contributor_score.message_reply_num + 1
|
||||
course_contributor_score.update_attributes(:message_reply_num => score)
|
||||
score = course_contributor_score.message_reply_num.to_i + 1
|
||||
course_contributor_score.update_column(:message_reply_num, score)
|
||||
end
|
||||
when "NewReply"
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0,
|
||||
:news_reply_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0)
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :news_reply_num => 1)
|
||||
else
|
||||
score = course_contributor_score.news_reply_num + 1
|
||||
course_contributor_score.update_attributes(:news_reply_num => score)
|
||||
score = course_contributor_score.news_reply_num.to_i + 1
|
||||
course_contributor_score.update_column(:news_reply_num, score)
|
||||
end
|
||||
when "News"
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0,
|
||||
:news_reply_num => 0, :news_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0)
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :news_num => 1)
|
||||
else
|
||||
score = course_contributor_score.news_num + 1
|
||||
course_contributor_score.update_attributes(:news_num => score)
|
||||
score = course_contributor_score.news_num.to_i + 1
|
||||
course_contributor_score.update_column(:news_num, score)
|
||||
end
|
||||
when "Attachment"
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0,
|
||||
:news_reply_num => 0, :news_num => 0, :resource_num => 1, :journal_num => 0, :journal_reply_num => 0)
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :resource_num => 1)
|
||||
else
|
||||
score = course_contributor_score.resource_num + 1
|
||||
course_contributor_score.update_attributes(:resource_num => score)
|
||||
score = course_contributor_score.resource_num.to_i + 1
|
||||
course_contributor_score.update_column(:resource_num, score)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -184,39 +214,39 @@ module ApplicationHelper
|
|||
case type
|
||||
when "HomeworkCommon"
|
||||
unless course_contributor_score.nil?
|
||||
score = course_contributor_score.homework_journal_num - 1
|
||||
course_contributor_score.update_attribute(:homework_journal_num, score < 0 ? 0 : score)
|
||||
score = course_contributor_score.homework_journal_num.to_i - 1
|
||||
course_contributor_score.update_column(:homework_journal_num, score < 0 ? 0 : score)
|
||||
end
|
||||
# 课程留言
|
||||
when "Course"
|
||||
unless course_contributor_score.nil?
|
||||
score = course_contributor_score.journal_num - 1
|
||||
course_contributor_score.update_attribute(:journal_num, score < 0 ? 0 : score)
|
||||
score = course_contributor_score.journal_num.to_i - 1
|
||||
course_contributor_score.update_column(:journal_num, score < 0 ? 0 : score)
|
||||
end
|
||||
when "Message"
|
||||
unless course_contributor_score.nil?
|
||||
score = course_contributor_score.message_num - 1
|
||||
course_contributor_score.update_attribute(:message_num, score < 0 ? 0 : score)
|
||||
score = course_contributor_score.message_num.to_i - 1
|
||||
course_contributor_score.update_column(:message_num, score < 0 ? 0 : score)
|
||||
end
|
||||
when "MessageReply"
|
||||
unless course_contributor_score.nil?
|
||||
score = course_contributor_score.message_reply_num - 1
|
||||
course_contributor_score.update_attribute(:message_reply_num, score < 0 ? 0 : score)
|
||||
score = course_contributor_score.message_reply_num.to_i - 1
|
||||
course_contributor_score.update_column(:message_reply_num, score < 0 ? 0 : score)
|
||||
end
|
||||
when "NewReply"
|
||||
unless course_contributor_score.nil?
|
||||
score = course_contributor_score.news_reply_num - 1
|
||||
course_contributor_score.update_attribute(:news_reply_num, score < 0 ? 0 : score)
|
||||
score = course_contributor_score.news_reply_num.to_i - 1
|
||||
course_contributor_score.update_column(:news_reply_num, score < 0 ? 0 : score)
|
||||
end
|
||||
when "News"
|
||||
unless course_contributor_score.nil?
|
||||
score = course_contributor_score.news_num - 1
|
||||
course_contributor_score.update_attribute(:news_num, score < 0 ? 0 : score)
|
||||
score = course_contributor_score.news_num.to_i - 1
|
||||
course_contributor_score.update_column(:news_num, score < 0 ? 0 : score)
|
||||
end
|
||||
when "Attachment"
|
||||
unless course_contributor_score.nil?
|
||||
score = course_contributor_score.resource_num - 1
|
||||
course_contributor_score.update_attribute(:resource_num, score < 0 ? 0 : score)
|
||||
score = course_contributor_score.resource_num.to_i - 1
|
||||
course_contributor_score.update_column(:resource_num, score < 0 ? 0 : score)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -773,22 +803,22 @@ module ApplicationHelper
|
|||
end
|
||||
|
||||
# 获取Gitlab版本库提交总数
|
||||
def commit_count(project)
|
||||
def commit_count(project, branch)
|
||||
g = Gitlab.client
|
||||
#add by hx
|
||||
if g.commits(project.gpid , :page=>200).count > 0
|
||||
if g.commits(project.gpid, :ref_name => @rev , :page=>200).count > 0
|
||||
count = 4020
|
||||
elsif g.commits(project.gpid , :page=>25).count==0
|
||||
elsif g.commits(project.gpid , :page=>25, :ref_name => branch).count==0
|
||||
count = count_commits(project.gpid , 0 , 25)
|
||||
elsif g.commits(project.gpid , :page=>50).count ==0
|
||||
elsif g.commits(project.gpid , :page=>50, :ref_name => branch).count ==0
|
||||
count = count_commits(project.gpid , 25 , 50)+ 25 * 20
|
||||
elsif g.commits(project.gpid , :page=>75).count ==0
|
||||
elsif g.commits(project.gpid , :page=>75, :ref_name => branch).count ==0
|
||||
count = count_commits(project.gpid , 50 , 75)+ 50 * 20
|
||||
elsif g.commits(project.gpid , :page=>100).count== 0
|
||||
elsif g.commits(project.gpid , :page=>100, :ref_name => branch).count== 0
|
||||
count = count_commits(project.gpid , 75 , 100) + 75 * 20
|
||||
elsif g.commits(project.gpid , :page=>125).count==0
|
||||
elsif g.commits(project.gpid , :page=>125, :ref_name => branch).count==0
|
||||
count = count_commits(project.gpid , 100 , 125) + 100 * 20
|
||||
elsif g.commits(project.gpid , :page=>150).count==0
|
||||
elsif g.commits(project.gpid , :page=>150, :ref_name => branch).count==0
|
||||
count = count_commits(project.gpid , 125 , 150) + 125 * 20
|
||||
else
|
||||
count = count_commits(project.gpid , 150 ,200) + 150 * 20
|
||||
|
@ -802,7 +832,7 @@ module ApplicationHelper
|
|||
if $g.commits(project_id,:page => page).count == 0
|
||||
break
|
||||
else
|
||||
count = count + $g.commits(project_id,:page => page).count
|
||||
count = count + $g.commits(project_id, :ref_name => @rev, :page => page).count
|
||||
end
|
||||
end
|
||||
return count
|
||||
|
@ -1049,8 +1079,10 @@ module ApplicationHelper
|
|||
title << @organization.name
|
||||
elsif @user
|
||||
title << @user.try(:realname)
|
||||
elsif @syllabus
|
||||
title << @syllabus.title
|
||||
else
|
||||
title << User.current.try(:realname)
|
||||
title << (User.current.id == 2 ? "未登录" : User.current.try(:realname))
|
||||
end
|
||||
if first_page.nil? || first_page.web_title.nil?
|
||||
title << Setting.app_title unless Setting.app_title == title.last
|
||||
|
@ -2067,12 +2099,12 @@ module ApplicationHelper
|
|||
def attachment_history_candown attachment_history
|
||||
if attachment_history.container_type == "Course"
|
||||
course = Course.find(attachment_history.container_id)
|
||||
candown = User.current.member_of?(course) || (course.is_public && attachment_history.is_public == 1)
|
||||
candown = User.current.member_of_course?(course) || (course.is_public && attachment_history.is_public == 1)
|
||||
elsif attachment_history.container_type == "Project"
|
||||
project = Project.find(attachment_history.container_id)
|
||||
candown = User.current.member_of?(project) || (project.is_public && attachment_history.is_public == 1)
|
||||
elsif attachment_history.container_type == "OrgSubfield"
|
||||
org = OrgSubfield.find(attachment_history.container_id)
|
||||
org = OrgSubfield.find(attachment_history.container_id).organization
|
||||
candown = User.current.member_of_org?(org) || (org.organization.is_public && attachment_history.is_public == 1 && (User.current.logged? || org.organization.allow_guest_download?))
|
||||
end
|
||||
end
|
||||
|
@ -2087,20 +2119,20 @@ module ApplicationHelper
|
|||
candown= User.current.member_of?(project) || (project.is_public && attachment.is_public == 1)
|
||||
elsif attachment.container.is_a?(Project)
|
||||
project = attachment.container
|
||||
candown= User.current.member_of?(project) || (project.is_public && attachment.is_public == 1)
|
||||
candown = User.current.member_of?(project) || (attachment.is_public == 1) || attachment.get_status_by_attach(User.current.id) == 2
|
||||
elsif (attachment.container.has_attribute?(:board) || attachment.container.has_attribute?(:board_id)) && attachment.container.board &&
|
||||
attachment.container.board.project
|
||||
project = attachment.container.board.project
|
||||
candown = User.current.member_of?(project) || (project.is_public && attachment.is_public == 1)
|
||||
elsif (attachment.container.has_attribute?(:course) ||attachment.container.has_attribute?(:course_id) ) && attachment.container.course
|
||||
course = attachment.container.course
|
||||
candown = User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1)
|
||||
candown = User.current.member_of_course?(course) || (attachment.is_public == 1) || attachment.get_status_by_attach(User.current.id) == 2
|
||||
elsif attachment.container.is_a?(Course)
|
||||
course = attachment.container
|
||||
candown= User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1)
|
||||
candown= User.current.member_of_course?(course) || (attachment.is_public == 1) || attachment.get_status_by_attach(User.current.id) == 2
|
||||
elsif attachment.container.is_a?(OrgSubfield)
|
||||
org = attachment.container.organization
|
||||
candown = User.current.member_of_org?(org) || (org.is_public && attachment.is_public == 1)
|
||||
candown = User.current.member_of_org?(org) || (attachment.is_public == 1) || attachment.get_status_by_attach(User.current.id) == 2
|
||||
elsif attachment.container.is_a?(OrgDocumentComment)
|
||||
org = attachment.container.organization
|
||||
candown = User.current.member_of_org?(org) || (org.is_public && attachment.is_public == 1)
|
||||
|
@ -2599,7 +2631,7 @@ module ApplicationHelper
|
|||
def homework_anonymous_comment (homework, is_in_course, user_activity_id = -1, course_activity = -1)
|
||||
if homework.homework_detail_manual.comment_status == 0 ||Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d")
|
||||
link = link_to "启动匿评","javascript:void(0)", :class => "postOptionLink", :title => "作业截止日期之前不可以启动匿评"
|
||||
elsif homework.student_works.count >= 2 && homework.homework_detail_manual#作业份数大于2
|
||||
elsif homework.student_works.has_committed.count >= 2 && homework.homework_detail_manual#作业份数大于2
|
||||
case homework.homework_detail_manual.comment_status
|
||||
when 1
|
||||
link = link_to '启动匿评', Setting.protocol + "://" + Setting.host_name + "/homework_common/" + homework.id.to_s + "/alert_anonymous_comment?is_in_course=" + is_in_course.to_s + "&user_activity_id=" + user_activity_id.to_s + "&course_activity=" + course_activity.to_s, id: "#{homework.id}_start_anonymous_comment", remote: true, disable_with: '加载中...',:class => 'postOptionLink'
|
||||
|
@ -2649,40 +2681,41 @@ module ApplicationHelper
|
|||
|
||||
#根据传入作业确定显示为编辑作品还是新建作品,或者显示作品数量
|
||||
def user_for_homework_common homework,is_teacher
|
||||
count = homework.student_works.has_committed.count
|
||||
if User.current.member_of_course?(homework.course)
|
||||
if is_teacher #老师显示作品数量
|
||||
link_to "作品(#{homework.student_works.count})", student_work_index_url_in_org(homework.id), :class => "c_blue"
|
||||
link_to "作品(#{count})", student_work_index_url_in_org(homework.id), :class => "c_blue"
|
||||
else #学生显示提交作品、修改作品等按钮
|
||||
work = cur_user_works_for_homework homework
|
||||
project = cur_user_projects_for_homework homework
|
||||
if work.nil? && Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d")
|
||||
if homework.homework_type ==3 && project.nil? && homework.homework_detail_group.base_on_project == 1
|
||||
link_to "提交作品(#{homework.student_works.count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再提交作品'
|
||||
link_to "提交作品(#{count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再提交作品'
|
||||
else
|
||||
link_to "提交作品(#{homework.student_works.count})", new_student_work_url_without_domain(homework.id),:class => 'c_blue'
|
||||
link_to "提交作品(#{count})", new_student_work_url_without_domain(homework.id),:class => 'c_blue'
|
||||
end
|
||||
elsif work.nil? && Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d")
|
||||
if homework.homework_type ==3 && project.nil? && homework.homework_detail_group.base_on_project == 1
|
||||
link_to "补交作品(#{homework.student_works.count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再补交作品'
|
||||
link_to "补交作品(#{count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再补交作品'
|
||||
else
|
||||
link_to "补交作品(#{homework.student_works.count})", new_student_work_url_without_domain(homework.id),:class => 'c_red'
|
||||
link_to "补交作品(#{count})", new_student_work_url_without_domain(homework.id),:class => 'c_red'
|
||||
end
|
||||
else
|
||||
if homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 2 #匿评作业,且作业状态不是在开启匿评之前
|
||||
link_to "作品匿评", student_work_index_url_in_org(homework.id), :class => 'c_blue', :title => "开启匿评后不可修改作品"
|
||||
elsif homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 3
|
||||
link_to "查看作品(#{homework.student_works.count})",student_work_index_url_in_org(homework.id), :class => 'c_blue', :title => "匿评已结束"
|
||||
link_to "查看作品(#{count})",student_work_index_url_in_org(homework.id), :class => 'c_blue', :title => "匿评已结束"
|
||||
elsif homework.homework_type == 2 && Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d")#编程作业不能修改作品
|
||||
link_to "修改作品(#{homework.student_works.count})", new_student_work_url_without_domain(homework.id),:class => 'c_blue'
|
||||
link_to "修改作品(#{count})", new_student_work_url_without_domain(homework.id),:class => 'c_blue'
|
||||
elsif Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") && work.user_id == User.current.id
|
||||
link_to "修改作品(#{homework.student_works.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'
|
||||
else
|
||||
link_to "查看作品(#{homework.student_works.count})", student_work_index_url_in_org(homework.id), :class => 'c_blue', :title => "作业截止后不可修改作品"
|
||||
link_to "查看作品(#{count})", student_work_index_url_in_org(homework.id), :class => 'c_blue', :title => "作业截止后不可修改作品"
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
link_to "作品(#{homework.student_works.count})",student_work_index_url_in_org(homework.id),:class => "c_blue"
|
||||
link_to "作品(#{count})",student_work_index_url_in_org(homework.id),:class => "c_blue"
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -2720,7 +2753,7 @@ module ApplicationHelper
|
|||
|
||||
#获取当前用户在指定作业下提交的作业的集合
|
||||
def cur_user_works_for_homework homework
|
||||
work = homework.student_works.where("user_id = ?",User.current).first
|
||||
work = homework.student_works.where("user_id = ? && work_status != 0",User.current).first
|
||||
if homework.homework_type == 3
|
||||
pro = homework.student_work_projects.where("user_id = #{User.current.id}").first
|
||||
if pro.nil? || pro.student_work_id == "" || pro.student_work_id.nil?
|
||||
|
@ -2960,6 +2993,14 @@ int main(int argc, char** argv){
|
|||
return sort_projects
|
||||
end
|
||||
end
|
||||
|
||||
def project_sort_first projects
|
||||
unless projects.empty?
|
||||
project_ids = '('+projects.map{|pro|pro.project_id}.join(',')+')'
|
||||
sort_projects = ForgeActivity.find_by_sql("SELECT updated_at,user_id, project_id FROM forge_activities WHERE project_id IN #{project_ids} ORDER BY updated_at DESC limit 1")
|
||||
return sort_projects
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def user_url_in_org(user_id)
|
||||
|
@ -2990,8 +3031,14 @@ def homework_common_index_url_in_org(course_id)
|
|||
Setting.protocol + "://" + Setting.host_name + "/homework_common?course=" + course_id.to_s
|
||||
end
|
||||
|
||||
def student_work_index_url_in_org(homework_id)
|
||||
Setting.protocol + "://" + Setting.host_name + "/student_work?homework=" + homework_id.to_s
|
||||
def student_work_index_url_in_org(homework_id, is_focus = '', show_work_id = '')
|
||||
if is_focus != ''
|
||||
Setting.protocol + "://" + Setting.host_name + "/student_work?homework=" + homework_id.to_s + "&is_focus=" + is_focus.to_s
|
||||
elsif show_work_id != ''
|
||||
Setting.protocol + "://" + Setting.host_name + "/student_work?homework=" + homework_id.to_s + "&show_work_id=" + show_work_id.to_s
|
||||
else
|
||||
Setting.protocol + "://" + Setting.host_name + "/student_work?homework=" + homework_id.to_s
|
||||
end
|
||||
end
|
||||
|
||||
def course_url_in_org(course_id)
|
||||
|
@ -3059,12 +3106,238 @@ def named_attachment_url_without_domain(id, filename, option={})
|
|||
attachment_id = (Attachment === id ? id.id : id)
|
||||
Setting.protocol + "://" + Setting.host_name + "/attachments/" + attachment_id.to_s + "/" + filename
|
||||
end
|
||||
|
||||
#判断是否为默认的组织栏目
|
||||
def is_default_field? field
|
||||
(field.name == 'activity' || field.name == 'course' || field.name == 'project') && field.field_type == 'default'
|
||||
(field.name == 'activity' || field.name == 'course' || field.name == 'project' ) && field.field_type == 'default'
|
||||
end
|
||||
|
||||
def host_with_protocol
|
||||
return Setting.protocol + "://" + Setting.host_name
|
||||
end
|
||||
|
||||
def secdomain_with_protocol secdomain
|
||||
return Setting.protocol + "://" + secdomain + ".trustie.net"
|
||||
end
|
||||
|
||||
|
||||
#获取回复的所有父节点
|
||||
def get_reply_parents parents_rely, comment
|
||||
unless comment.parent.nil?
|
||||
parents_rely << comment.parent
|
||||
get_reply_parents parents_rely, comment.parent
|
||||
end
|
||||
parents_rely
|
||||
end
|
||||
|
||||
#获取回复的所有父节点(不包括根节点)
|
||||
def get_reply_parents_no_root parents_rely, comment
|
||||
if !comment.parent.nil? && !comment.parent.parent.nil?
|
||||
parents_rely << comment.parent
|
||||
get_reply_parents_no_root parents_rely, comment.parent
|
||||
end
|
||||
parents_rely
|
||||
end
|
||||
|
||||
#获取所有子节点
|
||||
def get_all_children result, jour
|
||||
if (jour.kind_of? JournalsForMessage) || (jour.kind_of? Message)
|
||||
jour.children.each do |jour_child|
|
||||
result << jour_child
|
||||
get_all_children result, jour_child
|
||||
end
|
||||
end
|
||||
result.sort! { |a,b| b.created_on <=> a.created_on }
|
||||
end
|
||||
|
||||
#将有置顶属性的提到数组前面
|
||||
def sort_by_sticky topics
|
||||
tmpTopics = []
|
||||
tmpIndex = 0
|
||||
topics.each do |topic|
|
||||
if topic.sticky == 1
|
||||
tmpTopics[tmpIndex] = topic
|
||||
tmpIndex = tmpIndex + 1
|
||||
end
|
||||
end
|
||||
|
||||
topics.each do |topic|
|
||||
if topic.sticky == 0
|
||||
tmpTopics[tmpIndex] = topic
|
||||
tmpIndex = tmpIndex + 1
|
||||
end
|
||||
end
|
||||
return tmpTopics
|
||||
end
|
||||
|
||||
#按人气排序的时候 相同的人气必须按某种时间顺序排序 有置顶属性
|
||||
def sortby_time_countcommon_hassticky topics,sortstr
|
||||
tmpTopics = []
|
||||
tmpTopics = topics
|
||||
tStart = -1
|
||||
tEnd = -1
|
||||
|
||||
tmpTopics_1 = []
|
||||
tmpIndex = 0
|
||||
|
||||
tmpTopics.each_with_index do |topic,index|
|
||||
if topic.sticky == 0
|
||||
if tStart == -1
|
||||
if (index != tmpTopics.count-1) && (topic[:infocount] == tmpTopics[index+1][:infocount])
|
||||
tStart = index
|
||||
end
|
||||
else
|
||||
if ((topic[:infocount] == tmpTopics[index-1][:infocount]) && ((index != tmpTopics.count-1) && (topic[:infocount] == tmpTopics[index+1][:infocount])))
|
||||
tEnd = index
|
||||
else
|
||||
if (topic[:infocount] == tmpTopics[index-1][:infocount])
|
||||
tEnd = index
|
||||
end
|
||||
if tEnd > tStart
|
||||
for i in tStart..tEnd
|
||||
tmpTopics_1[tmpIndex] = tmpTopics[i]
|
||||
tmpIndex = tmpIndex + 1
|
||||
end
|
||||
|
||||
if sortstr == "created_at"
|
||||
tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:created_at].to_i <=> x[:created_at].to_i }
|
||||
elsif sortstr == "created_on"
|
||||
tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:created_on].to_i <=> x[:created_on].to_i }
|
||||
elsif sortstr == "updated_at"
|
||||
tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:updated_at].to_i <=> x[:updated_at].to_i }
|
||||
elsif sortstr == "updated_on"
|
||||
tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:updated_on].to_i <=> x[:updated_on].to_i }
|
||||
end
|
||||
|
||||
tmpIndex = 0
|
||||
for i in tStart..tEnd
|
||||
tmpTopics[i] = tmpTopics_1[tmpIndex]
|
||||
tmpIndex = tmpIndex + 1
|
||||
end
|
||||
end
|
||||
tStart = -1
|
||||
tEnd = -1
|
||||
tmpTopics_1 = []
|
||||
tmpIndex = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return tmpTopics
|
||||
end
|
||||
|
||||
#按人气排序的时候 相同的人气必须按某种时间顺序排序 无置顶属性
|
||||
def sortby_time_countcommon_nosticky topics,sortstr
|
||||
tmpTopics = []
|
||||
tmpTopics = topics
|
||||
tStart = -1
|
||||
tEnd = -1
|
||||
|
||||
tmpTopics_1 = []
|
||||
tmpIndex = 0
|
||||
|
||||
tmpTopics.each_with_index do |topic,index|
|
||||
if tStart == -1
|
||||
if (index != tmpTopics.count-1) && (topic[:infocount] == tmpTopics[index+1][:infocount])
|
||||
tStart = index
|
||||
end
|
||||
else
|
||||
if ((topic[:infocount] == tmpTopics[index-1][:infocount]) && ((index != tmpTopics.count-1) && (topic[:infocount] == tmpTopics[index+1][:infocount])))
|
||||
tEnd = index
|
||||
else
|
||||
if (topic[:infocount] == tmpTopics[index-1][:infocount])
|
||||
tEnd = index
|
||||
end
|
||||
if tEnd > tStart
|
||||
for i in tStart..tEnd
|
||||
tmpTopics_1[tmpIndex] = tmpTopics[i]
|
||||
tmpIndex = tmpIndex + 1
|
||||
end
|
||||
|
||||
if sortstr == "created_at"
|
||||
tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:created_at].to_i <=> x[:created_at].to_i }
|
||||
elsif sortstr == "created_on"
|
||||
tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:created_on].to_i <=> x[:created_on].to_i }
|
||||
elsif sortstr == "updated_at"
|
||||
tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:updated_at].to_i <=> x[:updated_at].to_i }
|
||||
elsif sortstr == "updated_on"
|
||||
tmpTopics_1 = tmpTopics_1.sort{|x,y| y[:updated_on].to_i <=> x[:updated_on].to_i }
|
||||
end
|
||||
|
||||
tmpIndex = 0
|
||||
for i in tStart..tEnd
|
||||
tmpTopics[i] = tmpTopics_1[tmpIndex]
|
||||
tmpIndex = tmpIndex + 1
|
||||
end
|
||||
end
|
||||
tStart = -1
|
||||
tEnd = -1
|
||||
tmpTopics_1 = []
|
||||
tmpIndex = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
return tmpTopics
|
||||
end
|
||||
|
||||
def strip_html(text,len=0,endss="...")
|
||||
ss = ""
|
||||
if !text.nil? && text.length>0
|
||||
ss=text.gsub(/<\/?.*?>/, '').strip
|
||||
ss = ss.gsub(/ /, ' ')
|
||||
|
||||
if len > 0 && ss.length > len
|
||||
ss = ss[0, len] + endss
|
||||
elsif len > 0 && ss.length <= len
|
||||
ss = ss
|
||||
#ss = truncate(ss, :length => len)
|
||||
end
|
||||
end
|
||||
return ss
|
||||
end
|
||||
|
||||
def get_hw_index(hw,is_teacher)
|
||||
if is_teacher
|
||||
homeworks = hw.course.homework_commons.order("created_at asc")
|
||||
else
|
||||
homeworks = hw.course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at asc")
|
||||
end
|
||||
hw_ids = homeworks.map{|hw| hw.id} if !homeworks.empty?
|
||||
index = hw_ids.index(hw.id)
|
||||
return index
|
||||
end
|
||||
|
||||
def get_group_member_names work
|
||||
result = ""
|
||||
unless work.nil?
|
||||
work.student_work_projects.each do |member|
|
||||
user = User.where(:id => member.user_id).first
|
||||
unless user.nil?
|
||||
if result != ""
|
||||
result += "、#{user.show_name}"
|
||||
else
|
||||
result += user.show_name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
def course_syllabus_option user = User.current
|
||||
syllabuses = user.syllabuses
|
||||
type = []
|
||||
option1 = []
|
||||
option1 << "请选择课程"
|
||||
option1 << 0
|
||||
type << option1
|
||||
unless syllabuses.empty?
|
||||
syllabuses.each do |syllabus|
|
||||
option = []
|
||||
option << syllabus.title
|
||||
option << syllabus.id
|
||||
type << option
|
||||
end
|
||||
end
|
||||
type
|
||||
end
|
||||
|
|
|
@ -44,9 +44,9 @@ module CoursesHelper
|
|||
def visible_excellent_course obj
|
||||
# if course.is_pu
|
||||
end
|
||||
|
||||
|
||||
# 返回x项目成员数量,即roles表中定义的所有成员
|
||||
def projectCount project
|
||||
def projectCount project
|
||||
#searchCountByRoles project, AllPeople
|
||||
project.members.count
|
||||
end
|
||||
|
@ -147,10 +147,10 @@ module CoursesHelper
|
|||
|
||||
# 返回学生数量,即roles表中定义的Reporter
|
||||
#def studentCount project
|
||||
# searchStudent(project).count
|
||||
# or
|
||||
# searchStudent(project).count
|
||||
# end
|
||||
# searchStudent(project).count
|
||||
# or
|
||||
# searchStudent(project).count
|
||||
# end
|
||||
|
||||
# 判断用户是否是课程的管理员
|
||||
# add by nwb
|
||||
|
@ -225,11 +225,11 @@ module CoursesHelper
|
|||
#end
|
||||
|
||||
# 注意:此方法有问题,速度慢且结果不准
|
||||
# alias studentCountOrigin studentCount
|
||||
# alias studentCountOrigin studentCount
|
||||
#def studentCount course
|
||||
# count = studentCountOrigin course
|
||||
#garble count
|
||||
# end
|
||||
# count = studentCountOrigin course
|
||||
#garble count
|
||||
# end
|
||||
|
||||
#获取课程所有成员
|
||||
def course_all_member course
|
||||
|
@ -265,7 +265,7 @@ module CoursesHelper
|
|||
def garble count
|
||||
count = count.round( 1-count.to_s.size ).to_i
|
||||
return count.to_s if count.to_s.size.eql?(1)
|
||||
count.to_s << '+'
|
||||
count.to_s << '+'
|
||||
end
|
||||
|
||||
# =====================================================================================
|
||||
|
@ -274,7 +274,7 @@ module CoursesHelper
|
|||
#searchPeopleByRoles(project, TeacherRoles)
|
||||
members = []
|
||||
project.members.includes(:user).each do |m|
|
||||
members << m if m && m.user && m.user.allowed_to?(:as_teacher,project)
|
||||
members << m if m && m.user && m.user.allowed_to?(:as_teacher,project)
|
||||
end
|
||||
members
|
||||
end
|
||||
|
@ -304,8 +304,8 @@ module CoursesHelper
|
|||
members
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def searchStudent_by_name project, name
|
||||
#searchPeopleByRoles(project, StudentRoles)
|
||||
members = []
|
||||
|
@ -324,29 +324,29 @@ module CoursesHelper
|
|||
mems = []
|
||||
if name != ""
|
||||
name = name.to_s.downcase
|
||||
members.each do |m|
|
||||
members.each do |m|
|
||||
username = m.user[:lastname].to_s.downcase + m.user[:firstname].to_s.downcase
|
||||
if(m.user[:login].to_s.downcase.include?(name) || m.user.user_extensions[:student_id].to_s.downcase.include?(name) || username.include?(name))
|
||||
mems << m
|
||||
end
|
||||
end
|
||||
else
|
||||
mems = members
|
||||
end
|
||||
mems = members
|
||||
end
|
||||
mems
|
||||
end
|
||||
def searchgroupmember_by_name members, name, group
|
||||
#searchPeopleByRoles(project, StudentRoles)
|
||||
mems = []
|
||||
if name != ""
|
||||
members.each do |m|
|
||||
if m.course_group_id == group.id
|
||||
username = m.user[:lastname].to_s + m.user[:firstname].to_s
|
||||
if(m.user[:login].to_s.include?(name) || m.user.user_extensions[:student_id].to_s.include?(name) || username.include?(name))
|
||||
mems << m
|
||||
members.each do |m|
|
||||
if m.course_group_id == group.id
|
||||
username = m.user[:lastname].to_s + m.user[:firstname].to_s
|
||||
if(m.user[:login].to_s.include?(name) || m.user.user_extensions[:student_id].to_s.include?(name) || username.include?(name))
|
||||
mems << m
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
mems = members
|
||||
end
|
||||
|
@ -458,7 +458,7 @@ module CoursesHelper
|
|||
content = content_tag('ul', content)
|
||||
content_tag('div', content, :class => "tabs")
|
||||
end
|
||||
|
||||
|
||||
def findCourseTime project
|
||||
str = ""
|
||||
begin
|
||||
|
@ -671,6 +671,22 @@ module CoursesHelper
|
|||
is_current_term || is_next_term
|
||||
end
|
||||
|
||||
#课程大纲下拉框
|
||||
def syllabus_option
|
||||
type = []
|
||||
option1 = []
|
||||
option1 << "请选择课程"
|
||||
option1 << 0
|
||||
type << option1
|
||||
Syllabus.all.each do |syllabus|
|
||||
option = []
|
||||
option << syllabus.title
|
||||
option << syllabus.id
|
||||
type << option
|
||||
end
|
||||
type
|
||||
end
|
||||
|
||||
#获取课程动态
|
||||
def get_course_activity courses, activities
|
||||
@course_ids=activities.keys()
|
||||
|
@ -683,9 +699,9 @@ module CoursesHelper
|
|||
#file_count
|
||||
Attachment.where(container_id: @course_ids, container_type: Course).where("created_on>?", date_from).each do |attachment|
|
||||
if attachment.is_public? || User.current.member_of_course?(@course) || User.current.admin?
|
||||
activities[attachment.container_id]+=1
|
||||
activities[attachment.container_id]+=1
|
||||
else
|
||||
activities[attachment.container_id]
|
||||
activities[attachment.container_id]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -704,8 +720,8 @@ module CoursesHelper
|
|||
#news
|
||||
News.where(course_id: @course_ids).where("created_on>?",date_from).each do |news|
|
||||
if news.author.member_of_course?(@course)
|
||||
activities[news.course_id]+=1
|
||||
end
|
||||
activities[news.course_id]+=1
|
||||
end
|
||||
end
|
||||
|
||||
#homework_count
|
||||
|
@ -756,12 +772,12 @@ module CoursesHelper
|
|||
url = joined ? join_path(:object_id => course.id) : try_join_path(:object_id => course.id)
|
||||
method = joined ? 'delete' : 'post'
|
||||
if joined
|
||||
link = link_to(text, url, :remote => true, :method => method, :class => "pr_join_a", :id => "#{course.id}", :confirm => l(:text_are_you_sure_out))
|
||||
link = link_to(text, url, :remote => true, :method => method, :class => "Blue-btn", :style => "margin_left: 0px;", :id => "#{course.id}", :confirm => l(:text_are_you_sure_out))
|
||||
else
|
||||
link = link_to(text, url, :remote => true, :method => method, :id => "#{course.id}", :class => "pr_join_a")
|
||||
link = link_to(text, url, :remote => true, :method => method, :id => "#{course.id}", :class => "Blue-btn", :style => "margin_left: 0px;")
|
||||
end
|
||||
else
|
||||
link = "<span class='pr_join_span mr5' >#{l(:label_course_join_student)}</span>"
|
||||
link = "<span class='pr_join_span mr5' >#{l(:label_course_join_student)}</span>"
|
||||
end
|
||||
link.html_safe
|
||||
end
|
||||
|
@ -777,6 +793,15 @@ module CoursesHelper
|
|||
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 <= '#{Date.today}'").count
|
||||
end
|
||||
homework_num
|
||||
end
|
||||
|
||||
def zh_course_role role
|
||||
if role == "TeachingAsistant"
|
||||
result = l(:label_TA)
|
||||
|
@ -850,7 +875,7 @@ module CoursesHelper
|
|||
# 学生按作业总分排序,取前8个
|
||||
def hero_homework_score(course, score_sort_by)
|
||||
sql_select = "SELECT members.*,(
|
||||
SELECT SUM(IF(student_works.final_score IS NULL,NULL,IF(student_works.final_score =0,0,IF((student_works.final_score - student_works.absence_penalty - student_works.late_penalty) < 0 , 0, student_works.final_score - student_works.absence_penalty - student_works.late_penalty))))
|
||||
SELECT SUM(work_score)
|
||||
FROM student_works,homework_commons
|
||||
WHERE student_works.homework_common_id = homework_commons.id
|
||||
AND homework_commons.course_id = #{course.id}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
module IssuesHelper
|
||||
include ApplicationHelper
|
||||
|
||||
include TagsHelper
|
||||
def issue_list(issues, &block)
|
||||
ancestors = []
|
||||
issues.each do |issue|
|
||||
|
|
|
@ -23,7 +23,7 @@ module OrganizationsHelper
|
|||
when 'activity' then
|
||||
return '动态'
|
||||
when 'course' then
|
||||
return '课程'
|
||||
return '班级'
|
||||
when 'project' then
|
||||
return '项目'
|
||||
end
|
||||
|
@ -42,11 +42,15 @@ module OrganizationsHelper
|
|||
Attachment.find_by_sql("SELECT * FROM `attachments` where container_id =#{field_id} and container_type = 'OrgSubfield' and is_public =1 order by created_on limit 6;")
|
||||
end
|
||||
|
||||
# 获取两种类型的隐藏状态,数量大于0说明是可见
|
||||
def double_field_show org
|
||||
OrgSubfield.find_by_sql("SELECT * FROM `org_subfields` where organization_id = #{org.id} and (field_type = 'Compstu' or field_type = 'Comptec') and hide = 0;").count
|
||||
end
|
||||
|
||||
def get_attach_org2(field)
|
||||
org_attachments = field.attachments
|
||||
attachments = User.current.admin? ? org_attachments : visable_attachemnts(org_attachments)
|
||||
return attachments.sort_by{|x| x.created_on}.reverse.first(6)
|
||||
# Attachment.find_by_sql("SELECT * FROM `attachments` where container_id =#{field_id} and container_type = 'OrgSubfield' and is_public =1 order by created_on limit 6;")
|
||||
attachments = User.current.admin? ? org_attachments.first(5) : visable_attachemnts(org_attachments).first(5)
|
||||
attachments.sort_by{|x| x.created_on}.reverse
|
||||
end
|
||||
|
||||
# 从内容中获取路径
|
||||
|
@ -59,18 +63,266 @@ module OrganizationsHelper
|
|||
end
|
||||
end
|
||||
|
||||
def org_user_by_type obj
|
||||
case obj.act_type
|
||||
when "Message"
|
||||
obj.act.author
|
||||
when "News"
|
||||
obj.act.author
|
||||
when "HomeworkCommon"
|
||||
obj.act.user
|
||||
when "Issue"
|
||||
obj.act.author
|
||||
end
|
||||
end
|
||||
|
||||
def org_title_by_type obj
|
||||
case obj.act_type
|
||||
when "Message"
|
||||
obj.act.parent_id.nil? ? obj.act.subject : obj.act.parent.subject
|
||||
when "News"
|
||||
obj.act.title
|
||||
when "HomeworkCommon"
|
||||
obj.act.name
|
||||
when "Issue"
|
||||
obj.act.subject
|
||||
end
|
||||
end
|
||||
|
||||
def org_content_by_type obj
|
||||
case obj.act_type
|
||||
when "Message"
|
||||
obj.act.parent_id.nil? ? obj.act.content : obj.act.parent.content
|
||||
when "News"
|
||||
obj.act.description
|
||||
when "HomeworkCommon"
|
||||
obj.act.description
|
||||
when "Issue"
|
||||
obj.act.description
|
||||
end
|
||||
end
|
||||
|
||||
def org_time_by_type obj
|
||||
case obj.act_type
|
||||
when "Message"
|
||||
obj.act.created_on
|
||||
when "News"
|
||||
obj.act.created_on
|
||||
when "HomeworkCommon"
|
||||
obj.act.created_at
|
||||
when "Issue"
|
||||
obj.act.created_on
|
||||
end
|
||||
end
|
||||
|
||||
def org_reply_count_type obj
|
||||
case obj.act_type
|
||||
when "HomeworkCommon"
|
||||
obj.act.journals_for_messages.count
|
||||
when "Issue"
|
||||
obj.act.journals.count
|
||||
when "Message"
|
||||
obj.act.children.count
|
||||
when "News"
|
||||
obj.act.comments_count
|
||||
end
|
||||
end
|
||||
|
||||
# 组织的栏目类型标题
|
||||
def subfield_title_type obj
|
||||
case obj.org_act_type
|
||||
when "OrgDocumentComment"
|
||||
obj.org_act.title
|
||||
when "Message"
|
||||
obj.org_act.parent_id.nil? ? obj.org_act.subject : obj.org_act.parent.subject
|
||||
when "News"
|
||||
obj.org_act.title
|
||||
when "Issue"
|
||||
obj.org_act.subject
|
||||
end
|
||||
end
|
||||
|
||||
# 组织的栏目类型时间
|
||||
def subfield_time_type obj
|
||||
case obj.org_act_type
|
||||
when "OrgDocumentComment"
|
||||
obj.org_act.updated_at
|
||||
when "Message"
|
||||
obj.org_act.updated_on
|
||||
when "News"
|
||||
obj.org_act.created_on
|
||||
end
|
||||
end
|
||||
|
||||
def subfield_reply_count_type obj
|
||||
case obj.org_act_type
|
||||
when "OrgDocumentComment"
|
||||
obj.org_act.children.count
|
||||
when "Message"
|
||||
obj.org_act.children.count
|
||||
when "News"
|
||||
obj.org_act.comments_count
|
||||
end
|
||||
end
|
||||
|
||||
#排列下拉框
|
||||
def subfield_status_option
|
||||
type = []
|
||||
option1 = []
|
||||
option1 << "列表"
|
||||
option1 << "左一"
|
||||
option1 << "1"
|
||||
type << option1
|
||||
option2 = []
|
||||
option2 << "图片"
|
||||
option2 << "0"
|
||||
option2 << "左二"
|
||||
option2 << "2"
|
||||
type << option2
|
||||
option3 = []
|
||||
option3 << "左三"
|
||||
option3 << "3"
|
||||
type << option3
|
||||
type
|
||||
end
|
||||
|
||||
# 课程和项目不参与某些模块的排列
|
||||
def subfield_status_option_default
|
||||
type = []
|
||||
option1 = []
|
||||
option1 << "左一"
|
||||
option1 << "1"
|
||||
type << option1
|
||||
option2 = []
|
||||
option2 << "左二"
|
||||
option2 << "2"
|
||||
type << option2
|
||||
option3 = []
|
||||
option3 << "左三"
|
||||
option3 << "2"
|
||||
type << option3
|
||||
option4 = []
|
||||
option4 << "右一"
|
||||
option4 << "3"
|
||||
type << option4
|
||||
option5 = []
|
||||
option5 << "右二"
|
||||
option5 << "5"
|
||||
type << option5
|
||||
type
|
||||
end
|
||||
|
||||
def subfield_list_type subfield
|
||||
case subfield.to_i
|
||||
when 1
|
||||
resulet = "左一"
|
||||
when 2
|
||||
resulet = "左二"
|
||||
when 3
|
||||
resulet = "左二"
|
||||
when 4
|
||||
resulet = "右一"
|
||||
when 5
|
||||
resulet = "右二"
|
||||
when 6
|
||||
resulet = "右三"
|
||||
end
|
||||
end
|
||||
|
||||
# 系统栏目只有管理员才能看到
|
||||
def subfield_to_addmin?(org)
|
||||
# if User.current.admin?
|
||||
@organization.org_subfields.order("priority")
|
||||
# else
|
||||
# @organization.org_subfields.select { |os| (os.field_type != "Comptec" && os.field_type != "Compstu" && os.field_type != "Comppro" && os.field_type != "Compcou" && os.field_type != "Compact") }.sort_by {|os| os.priority}
|
||||
# end
|
||||
end
|
||||
|
||||
def get_subfield_acts field
|
||||
unless field.nil?
|
||||
org_subfield = OrgSubfield.find(field.id)
|
||||
org_subfield_ids = org_subfield.org_document_comments.map(&:id) << 0
|
||||
org_acts = OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{org_subfield.id})").order('updated_at desc')
|
||||
end
|
||||
end
|
||||
|
||||
def allow_to_create?(org, type)
|
||||
!org_subfield_had_created?(org, type) && User.current.admin?
|
||||
end
|
||||
|
||||
def org_subfield_had_created?(org, type)
|
||||
sub_field = org.org_subfields.select{|subfield| subfield.field_type == type}
|
||||
result = sub_field.length > 0 ? true : false
|
||||
end
|
||||
|
||||
def org_subfield_type(field)
|
||||
case field.field_type
|
||||
when "Post"
|
||||
result = "帖子"
|
||||
when "Resource"
|
||||
result = "资源"
|
||||
when "Compstu"
|
||||
result = "学生"
|
||||
when "Comptec"
|
||||
result = "教师"
|
||||
when "Complex"
|
||||
result = "综合"
|
||||
when "Compcou"
|
||||
result = "课程"
|
||||
when "Comppro"
|
||||
result = "项目"
|
||||
when "Compact"
|
||||
result = "动态"
|
||||
end
|
||||
end
|
||||
|
||||
# 获取最新动态
|
||||
# def get_latest_acts
|
||||
# acts = UserActivity.find_by_sql("SELECT * FROM `user_activities` where act_type in ('HomeworkCommon', 'news', 'message', 'Issue') and (container_type = 'Course' or container_type = 'Project') order by created_at limit 10;")
|
||||
# end
|
||||
|
||||
def org_teacher_resource_count user
|
||||
results = Attachment.find_by_sql("SELECT * FROM attachments where author_id = #{user.id};").count
|
||||
end
|
||||
|
||||
def org_teacher_course_count user
|
||||
results = Course.find_by_sql("select * from courses where courses.tea_id = #{user.id}").count
|
||||
end
|
||||
|
||||
def org_student_course_count user
|
||||
course_ids = user.courses.map { |c| c.is_delete == 0 && c.id}
|
||||
results = Member.find_by_sql("select id from courses where courses.tea_id = #{user.id}").count
|
||||
end
|
||||
|
||||
def excellent_teachers
|
||||
User.find_by_sql("select u.*, ue.technical_title, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count
|
||||
from users u, user_extensions ue where u.id = ue.user_id and ue.identity=0 and u.excellent_teacher =1 order by course_count desc").first(5)
|
||||
end
|
||||
|
||||
def excellent_students
|
||||
User.find_by_sql("select u.*, ue.technical_title, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count
|
||||
from users u, user_extensions ue where u.id = ue.user_id and ue.identity = 1 and u.excellent_student = 1 order by course_count desc").first(5)
|
||||
end
|
||||
|
||||
def excellent_teachers_hide? org
|
||||
org.org_subfields.where(:field_type => "Comptec").first.hide
|
||||
end
|
||||
|
||||
def excellent_students_hide? org
|
||||
org.org_subfields.where(:field_type => "Compstu").first.hide
|
||||
end
|
||||
|
||||
#当前学期(2015春季学期)
|
||||
def current_time_and_term course
|
||||
str = ""
|
||||
term = cur_course_term
|
||||
if (course.time == course.end_time && course.term == course.end_term) || (course.end_term.nil? && course.end_time.nil?) || course.time > Time.now.year
|
||||
str = course.time.to_s + course.term.to_s
|
||||
elsif course.time == Time.now.year && set_term_value(cur_course_term) <= set_term_value(course.term)
|
||||
str = course.time.to_s + course.term.to_s
|
||||
elsif course.end_time < Time.now.year || (course.end_time == Time.now.year && set_term_value(cur_course_term) >= set_term_value(course.term))
|
||||
str = course.end_time.to_s + course.end_term.to_s
|
||||
else
|
||||
str = Time.now.year.to_s + cur_course_term.to_s
|
||||
end
|
||||
str
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -7,5 +7,6 @@ module OwnerTypeHelper
|
|||
BID = 6
|
||||
JOURNALSFORMESSAGE = 7
|
||||
HOMEWORKCOMMON = 8
|
||||
BLOGCOMMENT=9
|
||||
BLOGCOMMENT = 9
|
||||
SYLLABUS = 10
|
||||
end
|
|
@ -0,0 +1,97 @@
|
|||
# encoding: utf-8
|
||||
module QualityAnalysisHelper
|
||||
|
||||
def sqale_rating_status val
|
||||
arr = []
|
||||
if val <= 5
|
||||
arr << "很好"
|
||||
arr << "b_green2"
|
||||
elsif val. > 5 && val <= 10
|
||||
arr << "较好"
|
||||
arr << "b_slow_yellow"
|
||||
elsif val > 10 && val <= 20
|
||||
arr << "中等"
|
||||
arr << "b_yellow"
|
||||
elsif val > 20 && val <= 50
|
||||
arr << "较差"
|
||||
arr << "b_slow_red"
|
||||
elsif val > 20
|
||||
arr << "很差"
|
||||
arr << "b_red"
|
||||
end
|
||||
end
|
||||
|
||||
def complexity_status val
|
||||
arr = []
|
||||
if val <= 10
|
||||
arr << "良好"
|
||||
arr << "b_green2"
|
||||
elsif val > 10 && val <= 15
|
||||
arr << "较高"
|
||||
arr << "b_yellow"
|
||||
elsif val > 15
|
||||
arr << "很高"
|
||||
arr << "b_red"
|
||||
end
|
||||
end
|
||||
|
||||
def duplicated_lines_density_status val
|
||||
arr = []
|
||||
if val <= 30
|
||||
arr << "良好"
|
||||
arr << "b_green2"
|
||||
elsif val > 30 && val <= 50
|
||||
arr << "较高"
|
||||
arr << "b_yellow"
|
||||
elsif val > 50
|
||||
arr << "很高"
|
||||
arr << "b_red"
|
||||
end
|
||||
end
|
||||
|
||||
def comment_lines_density_status val
|
||||
arr = []
|
||||
if val <= 20
|
||||
arr << "较低"
|
||||
arr << "b_yellow"
|
||||
elsif val > 20 && val <= 50
|
||||
arr << "正常"
|
||||
arr << "b_green2"
|
||||
elsif val > 50
|
||||
arr << "较高"
|
||||
arr << "b_red"
|
||||
end
|
||||
end
|
||||
|
||||
def score_sqale_rating val
|
||||
if val >= 0 && val <= 5
|
||||
"5"
|
||||
elsif val > 5 && val <= 10
|
||||
"4"
|
||||
elsif val > 10 && val <= 20
|
||||
"3"
|
||||
elsif val > 20 && val <= 50
|
||||
"2"
|
||||
elsif val > 50
|
||||
"1"
|
||||
end
|
||||
end
|
||||
|
||||
def lines_scale val
|
||||
if val.to_i < 5000
|
||||
"小型"
|
||||
elsif val.to_i >5000 && val.to_i < 50000
|
||||
"中型"
|
||||
else
|
||||
"大型"
|
||||
end
|
||||
end
|
||||
|
||||
#统计答题百分比,统计结果保留两位小数
|
||||
def statistics_result_percentage(e, t)
|
||||
e = e.to_f
|
||||
t = t.to_f
|
||||
t == 0 ? 0 : format("%.2f", e*100/t)
|
||||
end
|
||||
|
||||
end
|
|
@ -41,6 +41,28 @@ module RepositoriesHelper
|
|||
identifiers.include?(iden) ? false :true
|
||||
end
|
||||
|
||||
def quality_analysis login, rep_id
|
||||
long_rep_id = "#{login}:#{rep_id}"
|
||||
QualityAnalysis.where(:sonar_name => long_rep_id).first
|
||||
end
|
||||
|
||||
# 获取文件目录的最新动态
|
||||
def get_trees_last_changes(project_id, rev, ent_name)
|
||||
g = Gitlab.client
|
||||
begin
|
||||
tree_changes = g.rep_last_changes(project_id, :rev => rev, :path => ent_name)
|
||||
tree_changes
|
||||
rescue
|
||||
logger.error("faile to get tress activities!")
|
||||
end
|
||||
end
|
||||
|
||||
def translate_time time
|
||||
case time
|
||||
when time.include("")
|
||||
end
|
||||
end
|
||||
|
||||
# 获取diff内容行号
|
||||
def diff_line_num content
|
||||
content.scan(/@@ -(\d+),\d+ \+\d+,\d+ @@/).first.join("").to_i
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
module ShieldWechatMessagesHelper
|
||||
end
|
|
@ -23,7 +23,7 @@ module StudentWorkHelper
|
|||
|
||||
#获取指定用户对某一作业的评分结果
|
||||
def student_work_score work,user
|
||||
StudentWorksScore.where(:user_id => user.id,:student_work_id => work.id).first
|
||||
StudentWorksScore.where(:user_id => user.id,:student_work_id => work.id).last
|
||||
end
|
||||
|
||||
#获取指定评分的角色
|
||||
|
@ -52,6 +52,19 @@ module StudentWorkHelper
|
|||
result
|
||||
end
|
||||
|
||||
def get_status status
|
||||
str = ""
|
||||
case status
|
||||
when 0
|
||||
str = "未提交"
|
||||
when 1
|
||||
str = "已提交"
|
||||
when 2
|
||||
str = "迟交"
|
||||
end
|
||||
str
|
||||
end
|
||||
|
||||
#获取赞的总数
|
||||
def praise_homework_count obj_id
|
||||
PraiseTread.where("praise_tread_object_id = #{obj_id} AND praise_tread_object_type = 'StudentWork'").count
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
module SubDocumentCommentsHelper
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
module SubDomainsHelper
|
||||
include OrganizationsHelper
|
||||
|
||||
|
||||
end
|
|
@ -0,0 +1,72 @@
|
|||
# encoding: utf-8
|
||||
module SyllabusesHelper
|
||||
def get_syllabuses_by_tag(tag_name)
|
||||
Syllabus.tagged_with(tag_name).order('updated_at desc')
|
||||
end
|
||||
|
||||
def teacher_count syllabus
|
||||
count = 0
|
||||
courses = syllabus.courses
|
||||
unless courses.empty?
|
||||
courses.each do |c|
|
||||
count += TeacherAndAssistantCount c
|
||||
end
|
||||
end
|
||||
count
|
||||
end
|
||||
|
||||
def student_count syllabus
|
||||
count = 0
|
||||
courses = syllabus.courses
|
||||
unless courses.empty?
|
||||
courses.each do |c|
|
||||
count += studentCount c
|
||||
end
|
||||
end
|
||||
count
|
||||
end
|
||||
|
||||
def file_count syllabus
|
||||
count = 0
|
||||
courses = syllabus.courses
|
||||
unless courses.empty?
|
||||
courses.each do |c|
|
||||
count += visable_attachemnts_incourse(c).count
|
||||
end
|
||||
end
|
||||
count
|
||||
end
|
||||
|
||||
#课程性质下拉框
|
||||
def syllabus_type
|
||||
type = []
|
||||
option1 = []
|
||||
option2 = []
|
||||
option3 = []
|
||||
option4 = []
|
||||
option5 = []
|
||||
option6 = []
|
||||
|
||||
option1 << "请选择"
|
||||
option1 << 0
|
||||
option2 << "公共必修课"
|
||||
option2 << 1
|
||||
option3 << "学科必修课"
|
||||
option3 << 2
|
||||
option4 << "专业选修课"
|
||||
option4 << 3
|
||||
option5 << "实践必修课"
|
||||
option5 << 4
|
||||
option6 << "实践选修课"
|
||||
option6 << 5
|
||||
|
||||
type << option1
|
||||
type << option2
|
||||
type << option3
|
||||
type << option4
|
||||
type << option5
|
||||
type << option6
|
||||
|
||||
type
|
||||
end
|
||||
end
|
|
@ -23,6 +23,8 @@ module TagsHelper
|
|||
@obj= Course.find_by_id(obj_id)
|
||||
when '10'
|
||||
@obj = Attachment.find_by_id(obj_id)
|
||||
when '11'
|
||||
@obj = Syllabus.find_by_id(obj_id)
|
||||
else
|
||||
raise Exception, '[TagsHelper] ===> tag type unknow.'
|
||||
end
|
||||
|
|
|
@ -32,7 +32,7 @@ module UsersHelper
|
|||
def get_resource_type type
|
||||
case type
|
||||
when 'Course'
|
||||
'课程资源'
|
||||
'班级资源'
|
||||
when 'Project'
|
||||
'项目资源'
|
||||
when 'Issue'
|
||||
|
@ -122,11 +122,11 @@ module UsersHelper
|
|||
when 'homework'
|
||||
'作业消息'
|
||||
when 'course_message'
|
||||
'课程讨论'
|
||||
'班级讨论'
|
||||
when 'course_news'
|
||||
'课程通知'
|
||||
'班级通知'
|
||||
when 'poll'
|
||||
'课程问卷'
|
||||
'班级问卷'
|
||||
when 'issue'
|
||||
'项目任务'
|
||||
when 'forge_message'
|
||||
|
@ -147,7 +147,9 @@ module UsersHelper
|
|||
|
||||
# 统计未读消息数
|
||||
def unviewed_message(user)
|
||||
course_count = CourseMessage.where("user_id =? and viewed =?", user, 0).count
|
||||
courses = user.courses.where("is_delete = 1")
|
||||
course_ids = courses.empty? ? "(-1)" : "(" + courses.map{|course| course.id}.join(",") + ")"
|
||||
course_count = CourseMessage.where("user_id =? and viewed =? and course_id not in #{course_ids}", user, 0).count
|
||||
forge_count = ForgeMessage.where("user_id =? and viewed =?", user, 0).count
|
||||
org_count = OrgMessage.where("user_id =? and viewed =?", user, 0).count
|
||||
user_feedback_count = UserFeedbackMessage.where("user_id =? and viewed =?", user, 0).count
|
||||
|
@ -386,6 +388,21 @@ module UsersHelper
|
|||
return result
|
||||
end
|
||||
|
||||
|
||||
#获取指定用户的课程大纲
|
||||
def user_syllabus(user)
|
||||
results = []
|
||||
courses = user_courses_list(user)
|
||||
|
||||
other = Syllabus.new(title: '未命名课程')
|
||||
|
||||
courses.each do |c|
|
||||
other << c unless c.syllabus
|
||||
end
|
||||
|
||||
user.syllabuses.to_a << other
|
||||
end
|
||||
|
||||
#获取用户参与的公开的课程列表
|
||||
def user_public_course_list user
|
||||
membership = user.coursememberships.all#@user.coursememberships.all(:conditions => Course.visible_condition(User.current))
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
class ApplyAddSchools < ActiveRecord::Base
|
||||
attr_accessible :address, :city, :name, :province, :remarks, :school_id, :status
|
||||
belongs_to :school
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
class ApplyHomework < ActiveRecord::Base
|
||||
#status:1. 等待回复 2.审核通过 3.已拒绝
|
||||
belongs_to :user
|
||||
belongs_to :homework_common
|
||||
attr_accessible :status, :user_id, :homework_common_id
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
class ApplyResource < ActiveRecord::Base
|
||||
# status:1. 等待回复 2.审核通过 3.已拒绝
|
||||
attr_accessible :attachment_id, :status, :user_id, :container_type, :container_id, :apply_user_id, :content
|
||||
belongs_to :user
|
||||
belongs_to :attachment
|
||||
has_many :course_messages, :class_name => 'CourseMessage', :as => :course_message, :dependent => :destroy
|
||||
after_create :act_as_apply_resource_message
|
||||
|
||||
def act_as_apply_resource_message
|
||||
self.course_messages << CourseMessage.new(:user_id => self.apply_user_id, :course_id => -1, :viewed => false, :status => 0, )
|
||||
# REDO:发送邮件
|
||||
# Mailer.run.apply_for_resource_request(self.container_id, User.current)
|
||||
end
|
||||
|
||||
def find_attachment attachment_id
|
||||
Attachment.find(attachment_id)
|
||||
end
|
||||
|
||||
end
|
|
@ -24,6 +24,7 @@ class Attachment < ActiveRecord::Base
|
|||
belongs_to :course, foreign_key: 'container_id', conditions: "attachments.container_type = 'Course'"
|
||||
belongs_to :org_subfield, foreign_key: 'container_id', conditions: "attachements.container_type = 'OrgSubfield'"
|
||||
belongs_to :organization, foreign_key: 'container_id', conditions: "attachements.container_type = 'Organization'"
|
||||
belongs_to :syllabus, foreign_key: 'container_id', conditions: "attachements.container_type = 'Syllabus'"
|
||||
belongs_to :softapplication, foreign_key: 'container_id', conditions: "attachments.container_type = 'Softapplication'"
|
||||
belongs_to :author, :class_name => "User", :foreign_key => "author_id"
|
||||
belongs_to :attachmentstype, :foreign_key => "attachtype",:primary_key => "id"
|
||||
|
@ -35,6 +36,7 @@ class Attachment < ActiveRecord::Base
|
|||
# end
|
||||
include UserScoreHelper
|
||||
has_many :attachment_histories
|
||||
has_many :apply_resources, :dependent => :destroy
|
||||
|
||||
validates :filename, presence: true, length: {maximum: 254}
|
||||
validates :author, presence: true
|
||||
|
@ -139,6 +141,12 @@ class Attachment < ActiveRecord::Base
|
|||
}
|
||||
)
|
||||
end
|
||||
|
||||
def get_apply_resource_status attachment_id, author_id
|
||||
status = ApplyResource.where("attachment_id =? and user_id =?", attachment_id, author_id).first.try(:status)
|
||||
status == 2
|
||||
end
|
||||
|
||||
# add by nwb
|
||||
# 公开的项目id列表
|
||||
def self.public_project_id
|
||||
|
@ -301,7 +309,7 @@ class Attachment < ActiveRecord::Base
|
|||
nil
|
||||
end
|
||||
|
||||
def filename=(arg)
|
||||
def filename=(arg)
|
||||
write_attribute :filename, sanitize_filename(arg.to_s)
|
||||
filename
|
||||
end
|
||||
|
@ -536,6 +544,11 @@ class Attachment < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
# 获取资源申请状态
|
||||
def get_status_by_attach user_id
|
||||
ApplyResource.where("user_id =? and attachment_id =?", user_id, self.id).first.try(:status)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Physically deletes the file from the file system
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue