Merge branch 'develop' into cxt_course

This commit is contained in:
cxt 2016-12-27 14:20:37 +08:00
commit f1a4cac61c
342 changed files with 8600 additions and 4939 deletions

View File

@ -75,6 +75,7 @@ group :development, :test do
gem "test-unit", "~>3.0"
end
gem 'rspec-rails', '~> 3.0'
gem 'factory_girl_rails'
end
# Gems used only for assets and not required

View File

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

View File

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

View File

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

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

View File

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

View File

@ -0,0 +1,3 @@
// Place all the styles related to the contest_members controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -0,0 +1,3 @@
// Place all the styles related to the contestant_works controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -1,4 +0,0 @@
/*
Place all the styles related to the matching controller here.
They will automatically be included in application.css.
*/

View File

@ -0,0 +1,3 @@
// Place all the styles related to the contests controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -0,0 +1,3 @@
// Place all the styles related to the works controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -430,6 +430,8 @@ class ApplicationController < ActionController::Base
@course = Course.find(params[:course_id])
elsif params[:org_subfield_id]
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
elsif params[:contest_id]
@contest = Contest.find(params[:contest_id])
end
rescue ActiveRecord::RecordNotFound
render_404

View File

@ -695,7 +695,7 @@ class AttachmentsController < ApplicationController
@attachment.container.board.course)
@course = @attachment.container.board.course
else
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'
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' || @attachment.container_type == 'Work'|| @attachment.container_type == 'ContestantWork'|| @attachment.container_type == 'Contest'
@project = @attachment.project
end
end

View File

@ -21,13 +21,14 @@ class CommentsController < ApplicationController
model_object News
before_filter :find_model_object, :except => [:reply, :quote]
before_filter :find_project_from_association, :except => [:reply, :quote]
before_filter :authorize
before_filter :authorize, :except => [:destroy]
def create
raise Unauthorized unless @news.commentable?
if !@news.org_subfield_id.nil?
@org_subfield = OrgSubfield.find(@news.org_subfield_id)
end
@contest = Contest.find(@news.contest_id) if @news.contest_id
@comment = Comment.new
#@project ? @comment.comments = params[:comment][:comments] : @comment.comments = params[:comment]
if params[:user_activity_id]

View File

@ -0,0 +1,151 @@
#encoding=utf-8
class ContestMembersController < ApplicationController
helper :users
helper :contest_members
helper :contests
before_filter :find_contest_member, :only => [:update, :destroy]
def create
@contest = Contest.find(params[:contest])
if params[:membership] && @contest
@create_member_error_messages = "角色不能留空" unless params[:membership][:role_ids]
@create_member_error_messages = "用户不能留空" unless params[:membership][:user_ids]
members = []
if params[:membership][:user_ids] && params[:membership][:role_ids]
attrs = params[:membership].dup
user_ids = attrs.delete(:user_ids)
role_ids = params[:membership][:role_ids]
user_ids.each do |user_id|
member = ContestMember.new(:user_id => user_id)
members << member
contest_member_roles = member.contest_member_roles
if role_ids.include?('14') && role_ids.include?('13')
contest_member_roles << ContestMemberRole.new(:role_id => 13)
contest_member_roles << ContestMemberRole.new(:role_id => 14, :is_current => 0)
else
contest_member_roles << ContestMemberRole.new(:role_id => role_ids[0].to_i)
end
if role_ids.include?('15')
ContestantForContest.create(:student_id => user_id, :contest_id => @contest.id)
end
#给新成员和老师发送加入课程的消息发送者id放在CourseMessage的course_message_id字段中
#course_message_type设置为JoinCourse
#status = 0 表示给学生发status = 1表示给老师发
course_join = ContestMessage.new(:user_id =>user_id, :contest_message_id=>User.current.id,:contest_id => @contest.id,:contest_message_type=>"JoinContest", :content => role_ids, :viewed => false, :status => 0)
course_join.save
ContestMessage.create(:user_id => User.current.id, :contest_message_id => user_id, :contest_message_id => @contest.id, :contest_message_type => "JoinContest",:content => role_ids, :viewed => false, :status => 1)
end
end
@contest.contest_members << members
members = @contest.member_principals.includes(:roles, :principal).all.sort
end
@roles = Role.where("id in (13, 14, 15)")
respond_to do |format|
format.html { redirect_to_settings_in_courses }
format.js { @members = members;}
format.api {
@member = members.first
if @member.valid?
render :action => 'show', :status => :created, :location => membership_url(@member)
else
render_validation_errors(@member)
end
}
end
end
def show
end
def contest_member_autocomplete
@contest = Contest.find(params[:contest])
@flag = params[:flag] || false
respond_to do |format|
format.js
end
end
def update
if params[:membership]
new_role_ids = params[:membership][:role_ids]
if new_role_ids.size != 0 && new_role_ids != @contest_member.contest_member_roles.map{|ro| ro.role_id.to_s}
destroy_member_roles = @contest_member.contest_member_roles
if destroy_member_roles.any?
destroy_member_roles.each(&:destroy)
end
contest_member_roles = @contest_member.contest_member_roles
if new_role_ids.include?('14') && new_role_ids.include?('13')
contest_member_roles << ContestMemberRole.new(:role_id => 13)
contest_member_roles << ContestMemberRole.new(:role_id => 14, :is_current => 0)
else
contest_member_roles << ContestMemberRole.new(:role_id => new_role_ids[0].to_i)
end
joined = ContestantForContest.where('student_id = ? and contest_id = ?', @contest_member.user_id, @contest.id)
joined.each do |join|
join.destroy
end
if new_role_ids.include?('15')
ContestantForContest.create(:student_id => @contest_member.user_id, :contest_id => @contest.id)
end
end
@contest_member.save
@members = @contest.member_principals.includes(:roles, :principal).all.sort
@roles = Role.where("id in (13, 14, 15)")
@member = @contest.contest_members.new
end
saved = @member.save
respond_to do |format|
format.html { redirect_to settings_contest_path(@contest) }
format.js
format.api {
if saved
render_api_ok
else
render_validation_errors(@member)
end
}
end
end
def destroy
if request.delete? && @contest_member.deletable?
@contest_member.destroy
joined = ContestantForContest.where('student_id = ? and contest_id = ?', @contest_member.user_id, @contest.id)
joined.each do |join|
join.destroy
end
@roles = Role.where("id in (13, 14, 15)")
@members = @contest.member_principals.includes(:roles, :principal).all.sort
#移出课程发送消息
ContestMessage.create(:user_id => @contest_member.user_id, :contest_id => @contest.id, :contest_message_type => "RemoveFromContest", :viewed => false, :contest_message_id => User.current.id)
end
respond_to do |format|
format.html { redirect_to settings_contest_path(@contest) }
format.js
format.api {
if @contest_member.destroyed?
render_api_ok
else
head :unprocessable_entity
end
}
end
end
private
def find_contest_member
@contest_member = ContestMember.find params[:id]
@contest = @contest_member.contest
end
end

View File

@ -1,6 +0,0 @@
class ContestNotificationController < ApplicationController
layout 'contest_base'
def show
@notification = ContestNotification.find(params[:id])
end
end

View File

@ -0,0 +1,408 @@
#encoding: utf-8
class ContestantWorksController < ApplicationController
layout "base_contests"
include ContestantWorksHelper
include ApplicationHelper
require 'bigdecimal'
require "base64"
before_filter :find_contestwork, :only => [:new, :index, :create, :new_student_work_project,:student_work_project,:cancel_relate_project,
:delete_work,:search_contest_students,:work_canrepeat,:add_group_member,:change_project]
before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work,:retry_work,:revise_attachment]
before_filter :member_of_contest, :only => [:new, :create, :show]
before_filter :author_of_work, :only => [:edit, :update, :destroy]
before_filter :admin_of_contest, :only => []
before_filter :is_logged, :only => [:index]
def new
#更新消息
noEvaluation = @contestwork.contest_messages.where("user_id =? and viewed =?", User.current.id, 0)
noEvaluation.update_all(:viewed => true)
@user = User.current
@student_work = ContestantWork.new
respond_to do |format|
format.html{ render :layout => "base_contests"}
end
end
def index
# 作业消息状态更新?
work_messages = ContestMessage.where(:user_id => User.current.id, :viewed => 0, :contest_message_id => @contestwork.id, :contest_message_type => "Work")
work_messages.update_all(:viewed => true)
studentwork_messages = ContestMessage.where(:user_id => User.current.id, :viewed => 0, :contest_id => @contestwork.contest, :contest_message_type => "ContestantWork")
studentwork_messages.update_all(:viewed => true)
# 作品打分消息状态更新
#studentworks_scores = ContestMessage.where("user_id =? and contest_id =? and contest_message_type =? and viewed =?", User.current.id, @contestwork.contest, "StudentWorksScore", 0)
#studentworks_scores.update_all(:viewed => true)
# 作品评论消息状态更新
#journals_for_teacher = ContestMessage.where("user_id =? and contest_id =? and contest_message_type =? and viewed =?", User.current.id, @contestwork.contest, "JournalsForMessage", 0)
#journals_for_teacher.update_all(:viewed => true)
##################################################################################################################
@order,@b_sort,@name,@group = params[:order] || "score",params[:sort] || "desc",params[:name].to_s.strip || "",params[:group]
@homework_commons = @contest.works.where("publish_time <= ?",Time.now.strftime("%Y-%m-%d")).order("created_at desc")
@all_homework_commons = @contest.works.order("created_at desc")
@is_teacher = User.current.admin_of_contest?(@contest) || User.current.admin?
@is_judge = User.current.judge_of_contest?(@contest)
@show_all = false
if @is_teacher || @is_judge
# if @order == 'lastname'
# @stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").joins(:user).order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name
# elsif @order == 'student_id'
# @stundet_works = search_homework_member @homework.student_works.no_copy.select("student_works.*,student_works.work_score as score").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name
# else
@stundet_works = @contestwork.contestant_works.no_copy.select("contestant_works.*,contestant_works.work_score as score").includes(:user => {:user_extensions => []}, :project => {}, :contestant_work_scores => {}).order("#{@order} #{@b_sort}")
#end
@show_all = true
elsif User.current.member_of_contest?(@contest)
if @contestwork.work_type == 3
pro = @contestwork.contestant_work_projects.where(:user_id => User.current.id).first
if pro.nil?
@stundet_works = []
else
@stundet_works = @contestwork.contestant_works.select("contestant_works.*,contestant_works.work_score as score").where(:id => pro.contestant_work_id)
end
else
@stundet_works = @contestwork.contestant_works.select("contestant_works.*,contestant_works.work_score as score").where(:user_id => User.current.id)
end
else
render_403
return
end
@student_work_count = @contestwork.contestant_works.has_committed.select("contestant_works.*,contestant_works.work_score as score").order("#{@order} #{@b_sort}").count
@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]
@left_nav_type = 3
@tab = params[:tab].to_i
respond_to do |format|
format.js
format.html
# format.xls {
# filename = "#{@contest.user.lastname.to_s + @contest.user.firstname}_#{@contest.name}_#{@contestwork.name}#{l(:excel_homework_list)}.xls"
# send_data(homework_to_xls(@stundet_works), :type => "text/excel;charset=utf-8; header=present",
# :filename => filename_for_content_disposition(filename))
# }
end
end
def show
#@score = student_work_score @work,User.current
@is_teacher = User.current.admin_of_contest?(@contest) || User.current.judge_of_contest?(@contest) || User.current.admin?
# if @homework.homework_detail_manual.comment_status == 2 && !@is_teacher && @work.user != User.current
# @student_work_scores = @work.student_works_scores.where("user_id = #{User.current.id} and reviewer_role = 3").order("updated_at desc")
# else
# @student_work_scores = student_work_score_record(@work)
# end
respond_to do |format|
format.js
end
end
def create
# 提交作品前先判断是否已经提交
@has_commit = false;
if hsd_committed_work?(User.current.id, @contestwork.id)
@work = ContestantWork.where("user_id =? and work_id =?", User.current.id, @contestwork.id).first
@has_commit = true;
#flash[:notice] = l(:notice_successful_create)
#redirect_to edit_student_work_url(params[:student_work])
respond_to do |format|
format.js
end
return
end
if params[:student_work]
@submit_result = true
student_work = ContestantWork.find(params[:student_work_id]) if params[:student_work_id]
student_work ||= ContestantWork.new
student_work.name = params[:student_work][:name] == "#{@contestwork.name}的作品提交(可修改)" ? "#{@contestwork.name}的作品提交" : params[:student_work][:name]
student_work.description = params[:student_work][:description]
student_work.work_id = @contestwork.id
student_work.user_id = User.current.id
student_work.commit_time = Time.now
student_work.save_attachments(params[:attachments])
render_attachment_warning_if_needed(student_work)
if @contestwork.work_type == 3 && @contestwork.work_detail_group.base_on_project
@student_work_project = @contestwork.contestant_work_projects.where("user_id = #{User.current.id}").first
student_work.project_id = @student_work_project.project_id
end
#提交作品时,计算是否迟交
student_work.work_status = Time.parse(@contestwork.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") ? 2 : 1
if student_work.save
if @contestwork.work_type == 3
if @contestwork.work_detail_group.base_on_project
@student_work_project.contestant_work_id = student_work.id
@student_work_project.save
else
stu_project = ContestantWorkProject.new(:work_id => @contestwork.id, :contestant_work_id => student_work.id, :project_id => student_work.project_id, :user_id => student_work.user_id, :is_leader => 1, :contest_id => @contestwork.contest_id)
stu_project.save
end
members = params[:group_member_ids].split(',')
for i in 1 .. members.count-1
stu_work = ContestantWork.new(:name => student_work.name, :description => student_work.description,:user_id =>members[i].to_i, :work_id => @contestwork.id, :project_id => student_work.project_id, :work_status => 3, :commit_time => student_work.commit_time)
if stu_work.save
stu_project = ContestantWorkProject.new(:work_id => @contestwork.id, :contestant_work_id => student_work.id, :project_id => stu_work.project_id == 0 ? -1 : stu_work.project_id, :user_id => members[i].to_i, :is_leader => 0, :contest_id => @contestwork.contest_id)
stu_project.save
end
end
end
@contestwork.update_column(:updated_at, Time.now)
update_contest_activity(@contestwork.class,@contestwork.id)
update_user_activity(@contestwork.class,@contestwork.id)
contest_message = ContestMessage.new(:user_id =>User.current.id,:content=>"new",:contest_message_id=>student_work.id,:contest_id => @contest.id,:contest_message_type=>"ContestantWork", :status => 9) #作品提交记录
contest_message.save
@student_work = ContestantWork.where(work_id: @contestwork.id, user_id: User.current.id).first
respond_to do |format|
format.js
end
return
end
end
@submit_result = false
respond_to do |format|
format.js
end
end
def edit
@user = User.current
if Time.parse(@contestwork.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") #编程作业不能修改作业|| 截止日期已到不能修改作业
render_403
else
respond_to do |format|
format.html{ render :layout => "base_contests"}
end
end
end
def update
if params[:student_work]
@submit_result = true
@work.name = params[:student_work][:name]
@work.description = params[:student_work][:description]
@work.save_attachments(params[:attachments])
render_attachment_warning_if_needed(@work)
if @work.save
#如果学生作品被打分后修改,应该给老师提示
#send_message_to_teacher(@work)
if @contestwork.work_type == 3
@student_work_project = @contestwork.contestant_work_projects.where("user_id=?",User.current.id).first
student_work_projects = @contestwork.contestant_work_projects.where("contestant_work_id=? and is_leader =?",@work.id,0)
user_ids = student_work_projects.empty? ? "(-1)" : "(" + student_work_projects.map{|stu|stu.user_id}.join(",") + ")"
student_works = @contestwork.contestant_works.where("user_id in #{user_ids}")
student_works.delete_all
student_work_projects.delete_all
members = params[:group_member_ids].split(',')
for i in 1 .. members.count-1
stu_work = ContestantWork.new(:name => @work.name, :description => @work.description,:user_id=> members[i].to_i, :work_id => @contestwork.id, :project_id => @work.project_id, :work_status => 3, :commit_time => @work.commit_time)
if stu_work.save
stu_project = ContestantWorkProject.new(:work_id => @contestwork.id, :contestant_work_id => @work.id, :project_id => stu_work.project_id == 0 ? -1 : stu_work.project_id, :user_id => members[i].to_i, :is_leader => 0, :contest_id => @contestwork.contest_id)
stu_project.save
end
end
end
contest_message = ContestMessage.new(:user_id =>User.current.id,:content=>"edit",:contest_message_id=>@work.id,:contest_id => @contest.id,:contest_message_type=>"ContestantWork", :status => 9) #作品提交记录
contest_message.save
@student_work = @work
respond_to do |format|
format.js
end
return
end
end
=begin
respond_to do |format|
format.html{redirect_to edit_student_work_url(@work)}
end
=end
@submit_result = false
respond_to do |format|
format.js
end
end
def destroy
if @contestwork.work_type == 3
pros = @work.contestant_work_projects.where("is_leader = 0")
user_ids = pros.empty? ? "(-1)" : "(" + pros.map{|stu|stu.user_id}.join(",") + ")"
student_works = @contestwork.contestant_works.where("user_id in #{user_ids}")
student_works.delete_all
pros.delete_all
project = @work.contestant_work_projects.where("is_leader = 1").first
if @contestwork.work_detail_group.base_on_project
project.update_attributes(:contestant_work_id => nil)
else
project.destroy
end
end
@work.destroy
@work.attachments.destroy_all
#@work.student_works_scores.destroy_all
@work.contest_messages.destroy_all
#@work.student_work_tests.destroy_all
respond_to do |format|
format.html {
redirect_to contestant_works_path(:work => @contestwork.id)
}
end
end
def delete_work
@work = ContestantWork.where("user_id =? and work_id =?", User.current.id, @contestwork.id).first
if @work
@work.destroy
if @contestwork.work_type == 3 && @contestwork.work_detail_group.base_on_project
pros = @work.contestant_work_projects.where("is_leader = 0")
pros.each do |pro|
pro.destroy
end
project = @work.contestant_work_projects.where("is_leader = 1").first
project.update_attributes(:contestant_work_id => nil)
elsif @contestwork.work_type == 3 && !@contestwork.work_detail_group.base_on_project
@work.contestant_work_projects.each do |pro2|
pro2.destroy
end
end
end
redirect_to works_path(:contest => @contestwork.contest_id)
end
def retry_work
if @contestwork.work_type == 3
pros = @work.contestant_work_projects.where("is_leader = 0")
user_ids = pros.empty? ? "(-1)" : "(" + pros.map{|stu|stu.user_id}.join(",") + ")"
student_works = @contestwork.contestant_works.where("user_id in #{user_ids}")
student_works.delete_all
pros.delete_all
project = @work.contestant_work_projects.where("is_leader = 1").first
if @contestwork.work_detail_group.base_on_project
project.update_attributes(:contestant_work_id => nil)
else
project.destroy
end
end
@work.destroy
@work.attachments.destroy_all
@work.contest_messages.destroy_all
@student_work = ContestantWork.new
respond_to do |format|
format.js
end
end
#查找竞赛中的参赛者
def search_contest_students
name = ""
unless params[:name].nil?
name = params[:name]
end
if !@contestwork.work_detail_group.base_on_project
all_student_ids = "(" + @contestwork.contest.contestants.map{|student| student.student_id}.join(",") + ")"
else
pro = Project.find @contestwork.contestant_work_projects.where("user_id=?",User.current.id).first.project_id
all_student_ids = "(" + pro.members.map{|member| member.user_id}.join(",") + ")"
end
all_students = User.where("id in #{all_student_ids}")
student_work_id = @contestwork.contestant_work_projects.where("user_id=? and contestant_work_id is not null",User.current.id).first.nil? ? -1 : @contestwork.contestant_work_projects.where("user_id=?",User.current.id).first.contestant_work_id
@commit_student_ids = @contestwork.contestant_works.where("id != #{student_work_id}").map{|student| student.user_id}
@users = searchstudent_by_name all_students,name
respond_to do |format|
format.js
end
end
def new_student_work_project
@user_activity_id = params[:user_activity_id].to_i
@hw_status = params[:hw_status].to_i
respond_to do |format|
format.js
end
end
#创建作业的关联项目
def student_work_project
@project = ContestantWorkProject.new
@project.work_id = @contestwork.id
@project.project_id = params[:projectName].to_i
@project.user_id = User.current.id
@project.is_leader = 1
@project.contest_id = @contestwork.contest_id
if @project.save
@user_activity_id = params[:user_activity_id].to_i
@hw_status = params[:hw_status].to_i
@is_teacher = User.current.admin_of_contest?(@contestwork.contest) || User.current.admin?
respond_to do |format|
format.js
end
end
end
# 取消关联项目
def cancel_relate_project
relate_pro = ContestantWorkProject.where("user_id = #{User.current.id} and work_id = #{@contestwork.id}").first
if relate_pro.destroy
@user_activity_id = params[:user_activity_id].to_i
@hw_status = params[:hw_status].to_i
@is_teacher = User.current.admin_of_contest?(@contestwork.contest) || User.current.admin?
respond_to do |format|
format.js
end
end
end
private
def hsd_committed_work?(user, homework)
sw = ContestantWork.where("user_id =? and work_id =?", user, homework).first
sw.nil? ? result = false : result = true
result
end
#获取题目
def find_contestwork
@contestwork = Work.find params[:work]
@contest = @contestwork.contest
rescue
render_404
end
#获取作品
def find_work
@work = ContestantWork.find params[:id]
@contestwork = @work.work
@contest = @contestwork.contest
rescue
render_404
end
#是不是当前竞赛的成员
#当前竞赛成员才可以看到作品列表
def member_of_contest
render_403 unless User.current.member_of_contest?(@contest) || User.current.admin?
end
#判断是不是当前作品的提交者
#提交者 && (非匿评作业 || 未开启匿评) 可以编辑作品
def author_of_work
render_403 unless User.current.admin? || User.current.id == @work.user_id
end
def admin_of_contest
render_403 unless User.current.admin_of_contest?(@contest) || User.current.admin?
end
def is_logged
redirect_to signin_path unless User.current.logged?
end
end

View File

@ -1,187 +0,0 @@
class ContestnotificationsController < ApplicationController
# GET /contestnotifications
# GET /contestnotifications.json
layout 'base_newcontest'
default_search_scope :contestnotifications
model_object Contestnotification
# before_filter :find_model_object, :except => [:new, :create, :index]
# before_filter :find_contest_from_association, :except => [:new, :create, :index]
before_filter :find_contest_by_contest_id, :only => [:new, :create]
before_filter :find_contest
before_filter :find_author
# before_filter :authorize, :except => [:index]
before_filter :find_optional_contest, :only => [:index]
accept_rss_auth :index
accept_api_auth :index
before_filter :access_edit_destroy, only: [:edit ,:update, :destroy]
def find_author
@user = @contest.author
render_404 if @user.nil?
end
def find_contest
@contest = Contest.find(params[:contest_id])
render_404 if @contest.nil?
end
def index
# @contestnotifications = Contestnotification.all
#
# respond_to do |format|
# format.html # index.html.erb
# format.json { render json: @contestnotifications }
# end
### begin ###
case params[:format]
when 'xml', 'json'
@offset, @limit = api_offset_and_limit
else
@limit = 10
end
scope = @contest ? @contest.contestnotifications.visible : Contestnotifications.visible
@contestnotifications_count = scope.count
@contestnotifications_pages = Paginator.new @contestnotifications_count, @limit, params['page']
@offset ||= @contestnotifications_pages.offset
@contestnotificationss = scope.all(:include => [:author, :contest],
:order => "#{Contestnotification.table_name}.created_at DESC",
:offset => @offset,
:limit => @limit)
respond_to do |format|
format.html {
@contestnotification = Contestnotification.new # for adding news inline
render :layout => 'base_newcontest'
}
format.api
format.atom { render_feed(@contestnotificationss, :title => (@contest ? @contest.name : Setting.app_title) + ": #{l(:label_contest_notification)}") }
end
### end ###
end
# GET /contestnotifications/1
# GET /contestnotifications/1.json
def show
@contestnotification = Contestnotification.find(params[:id])
#
# respond_to do |format|
# format.html # show.html.erb
# format.json { render json: @contestnotification }
# end
@notificationcomments = @contestnotification.notificationcomments
@notificationcomments.reverse! if User.current.wants_notificationcomments_in_reverse_order?
render :layout => 'base_newcontest'
end
# GET /contestnotifications/new
# GET /contestnotifications/new.json
def new
# @contestnotification = Contestnotification.new
#
# respond_to do |format|
# format.html # new.html.erb
# format.json { render json: @contestnotification }
# end
@contestnotification = Contestnotification.new(:contest => @contest, :author => User.current)
render :layout => 'base_newcontest'
end
# GET /contestnotifications/1/edit
def edit
@contestnotification = Contestnotification.find(params[:id])
end
# POST /contestnotifications
# POST /contestnotifications.json
def create
# @contestnotification = Contestnotification.new(params[:contestnotification])
#
# respond_to do |format|
# if @contestnotification.save
# format.html { redirect_to @contestnotification, notice: 'Contestnotification was successfully created.' }
# format.json { render json: @contestnotification, status: :created, location: @contestnotification }
# else
# format.html { render action: "new" }
# format.json { render json: @contestnotification.errors, status: :unprocessable_entity }
# end
# end
@contestnotification = Contestnotification.new(:contest => @contest, :author => User.current)
@contestnotification.safe_attributes = params[:contestnotification]
@contestnotification.save_attachments(params[:attachments])
if @contestnotification.save
render_attachment_warning_if_needed(@contestnotification)
flash[:notice] = l(:notice_successful_create)
redirect_to contest_contestnotifications_url(@contest)
else
layout_file = 'base_newcontest'
render :action => 'new', :layout => layout_file
end
end
# PUT /contestnotifications/1
# PUT /contestnotifications/1.json
def update
# @contestnotification = Contestnotification.find(params[:id])
#
# respond_to do |format|
# if @contestnotification.update_attributes(params[:contestnotification])
# format.html { redirect_to @contestnotification, notice: 'Contestnotification was successfully updated.' }
# format.json { head :no_content }
# else
# format.html { render action: "edit" }
# format.json { render json: @contestnotification.errors, status: :unprocessable_entity }
# end
# end
@contestnotification = Contestnotification.find(params[:id])
@contestnotification.safe_attributes = params[:contestnotification]
@contestnotification.save_attachments(params[:attachments])
if @contestnotification.save
render_attachment_warning_if_needed(@contestnotification)
flash[:notice] = l(:notice_successful_update)
redirect_to contest_contestnotification_url(@contestnotification.contest, @contestnotification)
else
render :action => 'edit'
end
end
# DELETE /contestnotifications/1
# DELETE /contestnotifications/1.json
def destroy
# @contestnotification = Contestnotification.find(params[:id])
# @contestnotification.destroy
#
# respond_to do |format|
# format.html { redirect_to contestnotifications_url }
# format.json { head :no_content }
# end
@contestnotification = Contestnotification.find(params[:id])
@contestnotification.destroy
redirect_to contest_contestnotifications_url(@contest)
end
private
def find_optional_contest
return true unless params[:id]
@contest = Contest.find(params[:id])
# authorize
rescue ActiveRecord::RecordNotFound
render_404
end
def access_edit_destroy
if (User.current.admin? && User.current.logged? )||(User.current == @contest.author && User.current.logged?)
return true
else
render_403
end
end
end

View File

@ -1,736 +1,260 @@
# fq
# class BidsController < ApplicationController
class ContestsController < ApplicationController
layout "contest_base"
menu_item :respond
menu_item :project, :only => :show_project
menu_item :application, :only => :show_softapplication
menu_item :attendingcontests, :only => :show_attendingcontest
menu_item :contestnotifications, :only => :index
before_filter :can_show_contest, :except => [] # modified by alan
# modified by longjun
before_filter :find_contest, :only => [
:show_contest, :show_project, :show_softapplication,
:show_attendingcontest, :index, :set_reward_project,
:set_reward_softapplication, :create, :destroy, :more,
:back, :add, :add_softapplication, :new,:show_results,
:set_reward, :show_contest_project, :show_contest_user, :watcherlist,
:join_in_contest, :unjoin_in_contest, :new_join, :settings
]
# end longjun
# added by fq
before_filter :require_login, :only => [:join_in_contest, :unjoin_in_contest]
# end
before_filter :require_login,:only => [:set_reward, :destroy, :add, :new ]
helper :watchers
helper :attachments
helper :projects
helper :words
include AttachmentsHelper
include ApplicationHelper
def index
render_404 unless params[:name]
# @contests = Contest.visible
# @contests ||= []
@offset, @limit = api_offset_and_limit(:limit => 10)
#@contests = Contest.visible
#@contests = @contests.like(params[:name]) if params[:name].present?
@is_search = params[:name] ? true:false
@contests = Contest.visible.where("name like '%#{params[:name]}%'")
if params[:contests_search]
(redirect_to contests_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
end
@contest_count = @contests.count
@contest_pages = Paginator.new @contest_count, @limit, params['page']
@offset ||= @contest_pages.reverse_offset
if params[:contest_sort_type].present?
case params[:contest_sort_type]
when '0'
# modified by longjun
# never use unless and else, 将下面重复操作模块化放在private下
# unless @offset == 0
# if @offset != 0
# @contests = @contests.reorder('contests.commit').offset(@offset).limit(@limit).all.reverse
# else
# limit = @contest_count % @limit
# limit = @limit if limit == 0
# @contests = @contests.reorder('contests.commit').offset(@offset).limit(limit).all.reverse
@contests = index_page_sort(@offset, @limit, @contest_count, @contests, 'contests.commit')
# end
@s_state = 0
when '1'
@contests = index_page_sort(@offset, @limit, @contest_count, @contests, 'contests.created_on')
@s_state = 1
# modified by longjun
# 目前只有 0 1 两个sort_type
# when '2'
else
# end longjun
@contests = index_page_sort(@offset, @limit, @contest_count, @contests, '')
@s_state = 0
end
else
# modified by longjun
# never use unless and else
# unless @offset == 0
if @offset != 0
@contests = @contests.reorder('contests.created_on').offset(@offset).limit(@limit).all.reverse
else
limit = @contest_count % @limit
limit = @limit if limit == 0
@contests = @contests.reorder('contests.created_on').offset(@offset).limit(limit).all.reverse
end
@s_state = 1
end
end
def search
redirect_to action: 'index',name:params[:name]
end
def homework
@offset, @limit = api_offset_and_limit({:limit => 10})
@bids = @course.homeworks.order('deadline DESC')
@bids = @bids.like(params[:name]) if params[:name].present?
@bid_count = @bids.count
@bid_pages = Paginator.new @bid_count, @limit, params['page']
@offset ||= @bid_pages.reverse_offset
# modified by longjun
# never use unless and else
# unless @offset == 0
if @offset != 0
@bids = @bids.offset(@offset).limit(@limit).all.reverse
else
limit = @bid_count % @limit
@bids = @bids.offset(@offset).limit(limit).all.reverse
end
render :layout => 'base_courses'
end
def show_contest
@user = @contest.author
@jours = @contest.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
#@limit = 10
#@feedback_count = @jours.count
#@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
#@offset ||= @feedback_pages.offset
#@jour = @jours[@offset, @limit]
@jour = paginateHelper @jours,10
@state = false
respond_to do |format|
format.html {
render :layout => 'base_newcontest'
}
format.api
end
end
def join_in_contest
if params[:contest_password] == @contest.password
JoinInCompetition.create(:user_id => User.current.id, :competition_id => @contest.id)
@state = 0
else
@state = 1
end
respond_to do |format|
format.js { render :partial => 'set_join', :locals => {:user => User.current, :object_id => params[:id]} }
end
end
def unjoin_in_contest
joined = JoinInCompetition.where('competition_id = ? and user_id = ?', @contest.id, User.current.id)
joined.each do |join|
join.delete
end
respond_to do |format|
format.js { render :partial => 'set_join', :locals => {:user => User.current, :object_id => params[:id]} }
end
end
def show_participator
render :layout => 'base_newcontest'
end
def settings
if @contest.author.id == User.current.id
@contest = Contest.find(params[:id])
render :layout => 'base_newcontest'
else
render_403 :message => :notice_not_contest_setting_authorized
end
end
# Added by Longjun
def destroy_contest
@contest = Contest.find(params[:id])
if @contest.author_id == User.current.id || User.current.admin?
@contest.destroy
redirect_to welcome_contest_url
else
render_403 :message => :notice_not_contest_delete_authorized
end
end
# end
def show_contest_project
contests = Contest.where('parent_id = ?', @contest.id)
@projects = []
# Modified by longjun
# 用 arr.each 替换 for [ according to the style guide ]
# for contest in contests
# @projects += contest.contesting_projects
# end
contests.each do |contest|
@projects += contest.contesting_projects
end
# end
respond_to do |format|
format.html {
render :layout => 'base_newcontest'
}
format.api
end
end
def show_contest_softapplication
contests = Contest.where('parent_id = ?', @contest.id)
@softapplications = []
# Modified by Longjun
# for contest in contests
# @softapplications += contest.contesting_softapplications
contests.each do |contest|
@softapplications += contest.contesting_softapplications
end
# end
respond_to do |format|
format.html {
render :layout => 'base_newcontest'
}
format.api
end
end
def show_contest_user
contests = Contest.find(:all)
@users = []
# Modified by Longjun
# for contest in contests
# for project in contest.projects
# @users += project.users
# end
contests.each do |contest|
contest.projects.each do |project|
@users += project.users
end
end
# end
respond_to do |format|
format.html {
render :layout => 'base_newcontest'
}
format.api
end
end
#显示参赛的项目
def show_project
@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
@option = []
# @contesting_project_count = @contesting_project_all.count
# @contesting_project_pages = Paginator.new @contesting_project_count, per_page_option, params['page']
@membership.each do |membership|
# Modified by Longjun
# 将两个判断语句合并
# unless membership.project.project_type==1
# if User.current.allowed_to?(:quote_project, membership.project)
# @option << membership.project
# end
# end
if membership.project.project_type != 1 && User.current.allowed_to?(:quote_project, membership.project)
@option << membership.project
end
# end
end
@user = @contest.author
@contesting_project = @contest.contesting_projects.all
if params[:student_id].present?
@temp = []
@contesting_project.each do |pro|
if pro.project && pro.project.project_status
if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id
@temp << pro
end
end
@temp
end
@contesting_project = @temp
else
@temp = []
@contesting_project.each do |pro|
# modified by longjun
# if pro.project && pro.project.project_status
# @temp << pro
# end
@temp << pro if pro.project && pro.project.project_status
# end longjun
@temp
end
if @temp.size > 0
@contesting_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade}
end
end
@contesting_project = paginateHelper(@contesting_project)
respond_to do |format|
format.html {
render :layout => 'base_newcontest'
}
format.api
end
end
############
##显示参赛的应用
def show_softapplication
# @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
# @option = []
# @user = @contest.user
@softapplication = Softapplication.all
@contesting_softapplication = @contest.contesting_softapplications
@contesting_softapplication = paginateHelper(@contesting_softapplication, 10)
# @temp = []
# @softapplicationt.each do |pro|
# if pro.project && pro.project.project_status
# @temp << pro
# end
# @temp
# if @temp.size > 0
# @contesting_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade}
# end
# end
# respond_to do |format|
# format.html {
# render :layout => 'base_newcontest'
# }
# format.api
# end
##########################
@contest = Contest.find_by_id(params[:id])
respond_to do |format|
format.html {
render :layout => 'base_newcontest'
}
format.api
end
end
###我要参赛
def show_attendingcontest
##取出参赛项目--项目列表
@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
@option = []
# @contesting_project_count = @contesting_project_all.count
# @contesting_project_pages = Paginator.new @contesting_project_count, per_page_option, params['page']
@membership.each do |membership|
unless membership.project.project_type==1
#拥有编辑项目权限的可将该项目参赛
if User.current.allowed_to?(:quote_project, membership.project)
@option << membership.project
end
end
end
@user = @contest.author
@contesting_project = @contest.contesting_projects.all
if params[:student_id].present?
@temp = []
@contesting_project.each do |pro|
if pro.project && pro.project.project_status
if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id
@temp << pro
end
end
@temp
end
@contesting_project = @temp
else
@temp = []
@contesting_project.each do |pro|
# modified by longjun
# if pro.project && pro.project.project_status
# @temp << pro
# end
@temp << pro if pro.project && pro.project.project_status
# end longjun
@temp
end
if @temp.size > 0
@contesting_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade}
end
end
# 取出参赛应用 --应用列表
@softapplication = Softapplication.all
@contesting_softapplication = @contest.contesting_softapplications.
joins("LEFT JOIN softapplications ON contesting_softapplications.softapplication_id=softapplications.id").
joins("LEFT JOIN (
SELECT * FROM seems_rateable_cached_ratings
WHERE cacheable_type='Softapplication' AND DIMENSION = 'quality') AS cached
ON cached.cacheable_id=softapplications.id").
order("cached.avg").reverse_order
@contesting_softapplication = paginateHelper @contesting_softapplication, 10
#引用base_newcontest整体样式
@contest = Contest.find_by_id(params[:id])
respond_to do |format|
format.html {
render :layout => 'base_newcontest'
}
format.api
end
end
###end
def show_notification
@contest = Contest.find_by_id(params[:id])
respond_to do |format|
format.html {
render :layout => 'base_newcontest'
}
format.api
end
end
def set_reward_project
@c_p = nil
@contesting_project_id = nil
if params[:set_reward_project][:reward]&&((User.current.id==@contest.author_id)||User.current.admin)
# @bid_id = params[:id]
@contesting_project_id = params[:set_reward_project][:c_id]
@c_p = ContestingProject.find_by_id(@contesting_project_id)
# 把字段存进表中
@c_p.update_reward(params[:set_reward_project][:reward].to_s)
end
respond_to do |format|
format.js
end
end
def set_reward_softapplication
@c_sa = nil
@contesting_softapplication_id = nil
if params[:set_reward_softapplication][:reward]&&((User.current.id==@contest.author_id)||User.current.admin)
# @bid_id = params[:id]
@contesting_softapplication_id = params[:set_reward_softapplication][:c_id]
@c_sa = ContestingSoftapplication.find_by_id(@contesting_softapplication_id)
# 把字段存进表中
@c_sa.update_reward(params[:set_reward_softapplication][:reward].to_s)
end
respond_to do |format|
format.js
end
end
###添加已创建的参赛项目
def add
project = Project.find(params[:contest])
contest_message = params[:contest_for_save][:contest_message]
if ContestingProject.where("project_id = ? and contest_id = ?", project.id, @contest.id).size == 0
# modified by longjun, create 写错了
# if ContestingProject.cerate_contesting(@contest.id, project.id, contest_message)
if ContestingProject.create_contesting(@contest.id, project.id, contest_message)
# end longjun
flash.now[:notice] = l(:label_bidding_contest_succeed)
end
else
flash.now[:error] = l(:label_bidding_fail)
end
@contesting_project = paginateHelper @contest.contesting_projects
respond_to do |format|
format.html { redirect_to :back }
format.js
end
end
###添加已发布的参赛应用
def add_softapplication
softapplication = Softapplication.find(params[:contest])
contest_message = params[:contest_for_save][:contest_message]
if ContestingSoftapplication.where("softapplication_id = ? and contest_id = ?", softapplication.id, @contest.id).size == 0
if ContestingSoftapplication.create_softapplication_contesting(@contest.id, softapplication.id, contest_message)
flash.now[:notice] = l(:label_release_add_contest_succeed)
end
else
flash.now[:error] = l(:label_add_contest_succeed_fail)
end
@contesting_softapplication = paginateHelper @contest.contesting_softapplications
respond_to do |format|
format.html { redirect_to :back }
format.js
end
end
## 新建留言
def create
if params[:contest_message][:message].size>0
if params[:reference_content]
message = params[:contest_message][:message] + "\n" + params[:reference_content]
else
message = params[:contest_message][:message]
end
refer_user_id = params[:contest_message][:reference_user_id].to_i
@contest.add_jour(User.current, message, refer_user_id)
end
@user = @contest.author
@jours = @contest.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
@limit = 10
@feedback_count = @jours.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
@offset ||= @feedback_pages.offset
@jour = @jours[@offset, @limit]
@contest.set_commit(@feedback_count)
respond_to do |format|
format.js
end
end
##删除留言
def destroy
@user = @contest.author
if User.current.admin? || User.current.id == @user.id
JournalsForMessage.delete_message(params[:object_id])
end
@jours = @contest.journals_for_messages.reverse
@limit = 10
@feedback_count = @jours.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
@offset ||= @feedback_pages.offset
@jour = @jours[@offset, @limit]
@contest.set_commit(@feedback_count)
respond_to do |format|
format.js
end
end
##引用留言
def new
@jour = JournalsForMessage.find(params[:journal_id]) if params[:journal_id]
if @jour
user = @jour.user
text = @jour.notes
else
user = @contest.author
text = @contest.description
end
text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
@content = "> #{ll(User.current.language, :text_user_wrote, user)}\n> "
@content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
@id = user.id
rescue ActiveRecord::RecordNotFound
render_404
end
##新建竞赛
def new_contest
@contest = Contest.new
@contest.safe_attributes = params[:contest]
end
##提交创建的竞赛
def create_contest
@contest = Contest.new
@contest.name = params[:contest][:name]
@contest.description = params[:contest][:description]
@contest.budget = params[:contest][:budget]
@contest.deadline = params[:contest][:deadline]
@contest.password = params[:contest][:password]
@contest.author_id = User.current.id
@contest.commit = 0
if @contest.save
unless @contest.watched_by?(User.current)
if @contest.add_watcher(User.current)
flash[:notice] = l(:label_contesting_created_succeed)
end
end
redirect_to show_contest_contest_url(@contest)
else
@contest.safe_attributes = params[:contest]
render :action => 'new_contest'
end
end
##更新竞赛配置信息
def update_contest
@contest = Contest.find(params[:id])
@contest.name = params[:contest][:name]
@contest.description = params[:contest][:description]
@contest.budget = params[:contest][:budget]
@contest.deadline = params[:contest][:deadline]
@contest.password = params[:contest][:password]
@contest.author_id = User.current.id
@contest.commit = 0
if @contest.save
unless @contest.watched_by?(User.current)
if @contest.add_watcher(User.current)
flash[:notice] = l(:label_contesting_updated_succeed)
end
end
redirect_to show_contest_contest_url(@contest)
else
@contest.safe_attributes = params[:contest]
render :action => 'new_contest'
end
end
def more
@jour = @contest.journals_for_messages
@jour.each_with_index {|j,i| j.indice = i+1}
@state = true
respond_to do |format|
format.html { redirect_to :back }
format.js
#format.api { render_api_ok }
end
end
def back
@jour = @contest.journals_for_messages
@jour.each_with_index {|j,i| j.indice = i+1}
@state = false
respond_to do |format|
format.html { redirect_to :back }
format.js
#format.api { render_api_ok }
end
end
def set_reward
@b_p = nil
@contesting_project_id = nil
if params[:set_reward][:reward]&&((User.current.id==@contest.author_id)||User.current.admin)
# @contest_id = params[:id]
@contesting_project_id = params[:set_reward][:b_id] #[:b_id]???
@b_p = ContestingProject.find_by_id(@contesting_project_id)
# 把字段存进表中
@b_p.update_reward(params[:set_reward][:reward].to_s)
end
respond_to do |format|
format.js
end
end
def watcherlist
render :layout => 'base_newcontest'
end
private
def find_contest
if params[:id]
@contest = Contest.find(params[:id])
@user = @contest.author
end
rescue
render_404
end
#验证是否显示竞赛
def can_show_contest
@first_page = FirstPage.find_by_page_type('project')
if @first_page.show_contest == 2
render_404
end
end
# added by longjun
# 将index页面中分页排序的方法抽离出来
def index_page_sort(offset, limit, contest_count, contests, contest_sort_by)
# modified by longjun
# never use unless and else
# unless @offset == 0
if offset != 0
contests = contests.reorder(contest_sort_by).offset(offset).limit(limit).all.reverse
else
limit = contest_count % limit
limit = limit if limit == 0
contests = contests.reorder(contest_sort_by).offset(offset).limit(limit).all.reverse
end
contests
end
end
#encoding=utf-8
class ContestsController < ApplicationController
include ContestsHelper
helper :contest_members
before_filter :find_contest, :only => [:show, :settings, :update, :contest_activities, :search_member, :private_or_public, :switch_role]
before_filter :is_logged, :only => [:index, :new, :create]
before_filter :is_admin?, :only => [:settings]
before_filter :is_member?, :only => [:show, :contest_activities]
layout "base_contests"
def show
@left_nav_type = 1
respond_to do |format|
format.js
format.html
end
end
def contest_activities
#更新创建课程消息状态
contest_request_messages = ContestMessage.where(:user_id => User.current.id, :contest_id => @contest.id, :contest_message_type => "ContestRequestDealResult", :viewed => false)
contest_request_messages.update_all(:viewed => true)
contest_activities = @contest.contest_activities
@page = params[:page] ? params[:page].to_i + 1 : 0
if params[:type].present?
case params[:type]
when "work"
@contest_activities = contest_activities.where("contest_act_type = 'Work'").order('updated_at desc')
when "news"
@contest_activities = contest_activities.where("contest_act_type = 'News'").order('updated_at desc')
when "message"
@contest_activities = contest_activities.where("contest_act_type = 'Message'").order('updated_at desc')
when "poll"
@contest_activities = contest_activities.where("contest_act_type = 'Poll'").order('updated_at desc')
when "attachment"
@contest_activities = contest_activities.where("contest_act_type = 'Attachment'").order('updated_at desc')
when "journalsForMessage"
@contest_activities = contest_activities.where("contest_act_type = 'JournalsForMessage'").order('updated_at desc')
when "news"
@contest_activities = contest_activities.where("contest_act_type = 'News'").order('updated_at desc')
else
@contest_activities = contest_activities.order('updated_at desc')
end
else
@contest_activities = contest_activities.order('updated_at desc')
end
@contest_activities_count = @contest_activities.count
@contest_activities = @contest_activities.limit(10).offset(@page * 10)
@type = params[:type]
@left_nav_type = 2
respond_to do |format|
format.js
format.html
format.api
end
end
def new
if User.current.login?
@contest = Contest.new
render :layout => 'new_base'
else
redirect_to signin_url
end
end
def create
@contest = Contest.new
@contest.name = params[:contest][:name]
params[:contest][:is_public] ? @contest.is_public = 1 : @contest.is_public = 0
@contest.user_id = User.current.id
if @contest && @contest.save
#unless User.current.admin?
member = ContestMember.new(:user_id => User.current.id)
@contest.contest_members << member
ContestMemberRole.create(:contest_member_id => member.id, :role_id => 13)
@contest.contest_acts << ContestActivity.new(:user_id => @contest.user_id,:contest_id => @contest.id)
respond_to do |format|
format.html {redirect_to contest_url(@contest)}
end
end
end
def update
@contest.name = params[:contest][:name]
@contest.description = params[:contest][:description]
# @project.organization_id = params[:organization_id]
params[:contest][:is_public] == "on" ? @contest.is_public = 1 : @contest.is_public = 0
@contest.save_attachments(params[:attachments])
begin
if @contest.save
respond_to do |format|
format.html{redirect_to contest_path(@contest)}
end
end
rescue Exception => e
@message = e.message
end
end
def private_or_public
@contest.update_attributes(:is_public => !@contest.is_public)
respond_to do |format|
format.js
end
end
#设置竞赛公开或私有
def set_contest_attribute
contest_id = params[:contest].to_i
@contest = Contest.find(contest_id)
@user = User.find(params[:user_id])
@contest.is_public? ? @contest.update_attribute(:is_public, false) : @contest.update_attribute(:is_public, true)
respond_to do |format|
format.js
end
end
def settings
if params[:tab] && params[:tab] == 'boards'
@tab = 2
else
@tab = 0
end
@member ||= @contest.contest_members.new
@roles = Role.where("id in (13, 14, 15)")
@members = @contest.member_principals.includes(:roles, :principal).all.sort
end
def join_contest
end
def join_contest_multi_role
if User.current.logged?
cs = ContestsService.new
@user = User.current
join = cs.join_contest_roles params,@user
@state = join[:state]
@contest = join[:contest]
else
@state = 5 #未登录
end
@object_id = @contest.id if @contest
respond_to do |format|
format.js
end
end
#处理加入竞赛成为管理员、评委、参赛者的请求
#status 1 同意 2 拒绝
def dealwith_apply_request
@msg = AppliedMessage.find(params[:msg_id])
#AppliedMessage role 13 管理员 14 评委 15 参赛者
applied_contest = @msg.applied
apply_user = User.find(applied_contest.user_id)
ids = applied_contest.role.split(",") # [@msg.content] msg content保存的是申请的职位角色
integer_ids = []
ids.each do |role_id|
integer_ids << role_id.to_i
end
case params[:agree]
when 'Y'
member = ContestMember.new(:user_id => apply_user.id)
Contest.find(applied_contest.contest_id).contest_members << member
contest_member_roles = member.contest_member_roles
if integer_ids.include?(14) && integer_ids.include?(13)
contest_member_roles << ContestMemberRole.new(:role_id => 13)
contest_member_roles << ContestMemberRole.new(:role_id => 14, :is_current => 0)
else
contest_member_roles << ContestMemberRole.new(:role_id => integer_ids[0])
end
ContestMessage.create(:user_id => apply_user.id, :contest_id => applied_contest.contest_id, :viewed => false,:contest_message_id=>User.current.id,:content=>applied_contest.role,:contest_message_type=>'ContestRequestDealResult',:status=>1)
applied_contest.applied_messages.update_all(:status => 1, :viewed => 1)
@msg.update_attributes(:status => 1, :viewed => 1)
applied_contest.update_attributes(:status => 1)
if integer_ids.include?(15)
ContestantForContest.create(:student_id => apply_user.id, :contest_id =>applied_contest.contest_id)
end
when 'N'
ContestMessage.create(:user_id => apply_user.id, :contest_id => applied_contest.contest_id, :viewed => false,:contest_message_id=>User.current.id,:content=>applied_contest.role,:contest_message_type=>'ContestRequestDealResult',:status=>2)
applied_contest.applied_messages.update_all(:status => 2, :viewed => 1)
@msg.update_attributes(:status => 2, :viewed => 1)
applied_contest.update_attributes(:status => 2)
end
respond_to do |format|
format.js
end
end
def switch_role
members = @contest.contest_members.where("user_id = #{params[:user_id]}")
unless members.blank?
curr_role = ContestMemberRole.find_by_contest_member_id_and_role_id(members.first.id, params[:curr_role])
tar_role = ContestMemberRole.find_by_contest_member_id_and_role_id(members.first.id, params[:tar_role])
unless (curr_role.nil? || tar_role.nil?)
curr_role.update_column('is_current', 0)
tar_role.update_column('is_current', 1)
end
end
redirect_to contest_path(@contest)
end
def search_member
if User.current.admin_of_contest?(@contest) || User.current.admin?
q = "#{params[:name].strip}"
@roles = Role.givable.all[11..13]
if q.nil? || q == ""
@members = @contest.member_principals.includes(:roles, :principal).all.sort
else
@members = searchmember_by_name(@contest.member_principals.includes(:roles, :principal).all.sort,q)
end
else
render_403
end
end
private
def find_contest
if params[:id].to_i < 780
render_403
return
end
@contest = Contest.find(params[:id])
rescue ActiveRecord::RecordNotFound
render_404
end
def is_logged
redirect_to signin_path unless User.current.logged?
end
def is_admin?
unless User.current.admin_of_contest?(@contest) || User.current.admin?
render_403
return
end
end
def is_member?
if User.current.member_of_contest?(@contest) || User.current.admin? || @contest.is_public
else
render_403
return
end
end
end

View File

@ -109,9 +109,9 @@ class DocumentsController < ApplicationController
attachments = Attachment.attach_files(@document, params[:attachments])
render_attachment_warning_if_needed(@document)
if attachments.present? && attachments[:files].present? && Setting.notified_events.include?('document_added')
Mailer.run.attachments_added(attachments[:files])
end
# if attachments.present? && attachments[:files].present? && Setting.notified_events.include?('document_added')
# # Mailer.run.attachments_added(attachments[:files])
# end
redirect_to document_url(@document)
end

View File

@ -524,7 +524,7 @@ class FilesController < ApplicationController
attachments = Attachment.attach_filesex(@project, params[:attachments], params[:attachment_type])
if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
# 发送邮件
Mailer.run.attachments_added(attachments[:files])
# Mailer.run.attachments_added(attachments[:files])
# 生成动态
attachments[:files].each do |file|
ForgeActivity.create(:user_id => User.current.id, :project_id => @project.id, :forge_act_id => file.id, :forge_act_type => "Attachment")
@ -581,9 +581,9 @@ class FilesController < ApplicationController
end
attachments = Attachment.attach_filesex(@course, params[:attachments], params[:attachment_type])
if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
Mailer.run.attachments_added(attachments[:files])
end
# if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
# # Mailer.run.attachments_added(attachments[:files])
# end
if !attachments.empty? && attachments[:files]
attachments[:files].each do |attachment|
if params[:publish_time]

View File

@ -73,7 +73,7 @@ class HomeworkCommonController < ApplicationController
end
else
respond_to do |format|
format.html{render :layout => 'new_base_user'}
format.html{render :layout => 'base_course_community'}
end
end
end
@ -284,7 +284,7 @@ class HomeworkCommonController < ApplicationController
@statue = 1
# 匿评开启消息邮件通知
send_message_anonymous_comment(@homework, m_status = 2)
Mailer.send_mail_anonymous_comment_open(@homework).deliver
# Mailer.send_mail_anonymous_comment_open(@homework).deliver
else
@statue = 2
@ -326,7 +326,7 @@ class HomeworkCommonController < ApplicationController
# 匿评关闭消息邮件通知
send_message_anonymous_comment(@homework, m_status = 3)
Mailer.send_mail_anonymous_comment_close(@homework).deliver
# Mailer.send_mail_anonymous_comment_close(@homework).deliver
@user_activity_id = params[:user_activity_id].to_i
@hw_status = params[:hw_status].to_i
@is_teacher = User.current.admin? || User.current.allowed_to?(:as_teacher, @course)

View File

@ -1,3 +1,4 @@
#coding=utf-8
# Redmine - project management software
# Copyright (C) 2006-2013 Jean-Philippe Lang
#
@ -261,6 +262,7 @@ class IssuesController < ApplicationController
retrieve_previous_and_next_issue_ids
render :template => 'issues/show', :layout => @project_base_tag#by young
}
format.js
format.api
format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
format.pdf {
@ -585,12 +587,15 @@ class IssuesController < ApplicationController
update_forge_activity(@issue.class,@issue.id)
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
@user_activity_id = params[:user_activity_id]
if params[:issue_id]
@issue_id = params[:issue_id]
end
@priorities = IssuePriority.active
respond_to do |format|
format.js
# Issue详情单独处理
if params[:is_issue_show]
format.js{redirect_to issue_path(@issue)}
else
format.js
end
end
end
end
@ -642,7 +647,11 @@ class IssuesController < ApplicationController
update_user_activity(@issue.class,@issue.id)
update_forge_activity(@issue.class,@issue.id)
respond_to do |format|
format.js
if params[:is_issue_show]
format.js{redirect_to issue_path(@issue)}
else
format.js
end
end
end
end
@ -654,28 +663,81 @@ class IssuesController < ApplicationController
# 非动态页面直接刷新,动态页面手动刷新
def delete_journal
@is_project = params[:is_project]
@issue = Issue.find(params[:id])
begin
forge_acts = ForgeMessage.where(:forge_message_type => "Journal", :forge_message_id => params[:journal_id])
forge_acts.destroy_all unless forge_acts.empty?
at_message = AtMessage.where(:at_message_type => "Journal", :at_message_id => params[:journal_id])
at_message.destroy_all unless at_message.empty?
Journal.delete(params[:journal_id])
rescue Exception => e
puts e
end
@user_activity_id = params[:user_activity_id]
respond_to do |format|
if @user_activity_id
format.js
else
format.html{ redirect_to issue_url(@issue)}
end
@issue = Issue.find(params[:id])
begin
forge_acts = ForgeMessage.where(:forge_message_type => "Journal", :forge_message_id => params[:journal_id])
forge_acts.destroy_all unless forge_acts.empty?
at_message = AtMessage.where(:at_message_type => "Journal", :at_message_id => params[:journal_id])
at_message.destroy_all unless at_message.empty?
Journal.delete(params[:journal_id])
rescue Exception => e
puts e
end
@user_activity_id = params[:user_activity_id]
respond_to do |format|
if @user_activity_id
format.js
else
format.js{ redirect_to issue_url(@issue)}
end
end
end
def statistics
@project = Project.find(params[:id])
params[:author_id].to_i != 0 ? (@author = User.find(params[:author_id].to_i).show_name) : @author = 0
case params[:tracker_id].to_i
when 1
@tracker = "缺陷"
when 2
@tracker = "功能"
when 3
@tracker = "支持"
when 4
@tracker = "任务"
when 5
@tracker = "周报"
when 0
@tracker = 0
end
params[:subject].blank? ? @search = 0 : @search = params[:subject]
params[:assigned_to_id].to_i != 0 ? (@assigned = User.find(params[:assigned_to_id].to_i).show_name) : @assigned = 0
params[:fixed_version_id].to_i != 0 ? (@version = Version.find(params[:fixed_version_id].to_i).name) : @version = 0
params[:done_ratio].to_i != -1 ? (@done = params[:done_ratio].to_i) : @done = -1
case params[:priority_id].to_i
when 1
@prior = ""
when 2
@prior = "正常"
when 3
@prior = ""
when 4
@prior = "紧急"
when 5
@prior = "立刻"
when 0
@prior = 0
end
case params[:status_id].to_i
when 1
@status = "新增"
when 2
@status = "正在解决"
when 3
@status = "已解决"
when 4
@status = "反馈"
when 5
@status = "关闭"
when 6
@status = "拒绝"
when 0
@status = 0
end
params[:issue_create_date_start].blank? ? @start_time = 0 : @start_time = params[:issue_create_date_start]
params[:issue_create_date_end].blank? ? @end_time = 0 : @end_time = params[:issue_create_date_end]
@filter_condition = true
@filter_condition = false if (@author == 0 && @tracker == 0 && @search == 0 && @assigned == 0 && @version == 0 && @done == -1 && @prior ==0 && @status == 0 && @start_time ==0 && @end_time)
if @project.nil?
render_404
end

View File

@ -57,10 +57,10 @@ class MembersController < ApplicationController
@applied_message = AppliedMessage.find(params[:applied_message_id])
applied_project = @applied_message.applied
user = User.find(@applied_message.applied_user_id)
project = Project.find(applied_project.project_id)
if user.member_of?(project)
@flash_message = "您已经是项目成员了"
@applied_message.update_attribute(:status, 2)
project = Project.find(applied_project.project_id) if !applied_project.nil?
if user.member_of?(project)|| AppliedMessage.where(:applied_id => @applied_message.applied_id, :status => 1).count == 0
@flash_message = "该申请已被其他管理员处理"
# @applied_message.update_attribute(:status, 2)
else
ap_role = applied_project.try(:role)
if ap_role
@ -104,24 +104,30 @@ class MembersController < ApplicationController
@applied_message = AppliedMessage.find(params[:applied_message_id])
# @applied_message.update_attribute(:status, 3)
applied_project = @applied_message.applied
project = Project.find(@applied_message.project_id)
# 发送消息给被拒者,user_id对应的收到信息的用户
AppliedMessage.create(:user_id => @applied_message.applied_user_id, :applied_type => "AppliedProject", :applied_id => applied_project.id ,:status => 4,
project = Project.find(@applied_message.project_id) if !applied_project.nil?
user = User.find(@applied_message.applied_user_id)
if user.member_of?(project) || AppliedMessage.where(:applied_id => @applied_message.applied_id, :status => 1).count == 0
@flash_message = "该申请已被其他管理员处理"
# @applied_message.update_attribute(:status, 2)
else
# 发送消息给被拒者,user_id对应的收到信息的用户
AppliedMessage.create(:user_id => @applied_message.applied_user_id, :applied_type => "AppliedProject", :applied_id => applied_project.id ,:status => 4,
:viewed => false, :applied_user_id => @applied_message.user_id, :role => applied_project.role, :project_id => applied_project.project_id)
# 拒绝功后所有管理员收到的消息状态都要更新
applied_messages = AppliedMessage.where(:applied_id => @applied_message.applied_id, :project_id => @applied_message.project_id, :status => 1,
# 拒绝功后所有管理员收到的消息状态都要更新
applied_messages = AppliedMessage.where(:applied_id => @applied_message.applied_id, :project_id => @applied_message.project_id, :status => 1,
:applied_type => "AppliedProject")
applied_messages.update_all(:status => 5, :viewed => true)
@applied_message = AppliedMessage.find(params[:applied_message_id])
# AppliedMessage.create(:user_id => @applied_message.user_id, :applied_type => "AppliedProject", :applied_id => applied_project.id ,:status => 5,
# :viewed => true, :applied_user_id => @applied_message.applied_user_id, :role => applied_project.role, :project_id => applied_project.project_id)
ps = ProjectsService.new
user = User.find(@applied_message.applied_user_id)
ap_role = applied_project.try(:role)
ps.send_wechat_join_project_notice user,project,ap_role,1
applied_messages.update_all(:status => 5, :viewed => true)
@applied_message = AppliedMessage.find(params[:applied_message_id])
# AppliedMessage.create(:user_id => @applied_message.user_id, :applied_type => "AppliedProject", :applied_id => applied_project.id ,:status => 5,
# :viewed => true, :applied_user_id => @applied_message.applied_user_id, :role => applied_project.role, :project_id => applied_project.project_id)
ps = ProjectsService.new
user = User.find(@applied_message.applied_user_id)
ap_role = applied_project.try(:role)
ps.send_wechat_join_project_notice user,project,ap_role,1
applied_project.delete
applied_project.delete
end
end
def create
@ -151,23 +157,33 @@ class MembersController < ApplicationController
project_info = []
if params[:membership]
if params[:membership][:user_ids]
attrs = params[:membership].dup
user_ids = attrs.delete(:user_ids)
user_ids.each do |user_id|
members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id)
user_grades << UserGrade.new(:user_id => user_id, :project_id => @project.id)
ActiveRecord::Base.transaction do
begin
attrs = params[:membership].dup
user_ids = attrs.delete(:user_ids)
user_ids.each do |user_id|
members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id)
user_grades << UserGrade.new(:user_id => user_id, :project_id => @project.id)
#给新成员发送加入项目的消息发送者id放在ForgeMessage的forge_message_id字段中
#forge_message_type设置为JoinProject
forge_join = ForgeMessage.new(:user_id =>user_id, :forge_message_id=>User.current.id,:project_id => @project.id,:forge_message_type=>"JoinProject", :viewed => false)
forge_join.save
## added by nie
if (params[:membership][:role_ids])
role = Role.find(params[:membership][:role_ids][0])
project_info << ProjectInfo.new(:user_id => user_id, :project_id => @project.id) if role.allowed_to?(:is_manager)
# ProjectInfo.create(:name => "test", :user_id => 123)
#给新成员发送加入项目的消息发送者id放在ForgeMessage的forge_message_id字段中
#forge_message_type设置为JoinProject
forge_join = ForgeMessage.new(:user_id =>user_id, :forge_message_id=>User.current.id,:project_id => @project.id,:forge_message_type=>"JoinProject", :viewed => false)
forge_join.save
## added by nie
if (params[:membership][:role_ids])
role = Role.find(params[:membership][:role_ids][0])
project_info << ProjectInfo.new(:user_id => user_id, :project_id => @project.id) if role.allowed_to?(:is_manager)
# ProjectInfo.create(:name => "test", :user_id => 123)
end
## end
end
rescue Gitlab::Error::Forbidden => e
@message = l(:label_pull_request_forbidden)
rescue Gitlab::Error::BadRequest => e
@message = "添加成员失败,可能是你添加的用户名中含有非法字符"
rescue Exception => e
puts e
end
## end
end
else
members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id])
@ -291,26 +307,29 @@ class MembersController < ApplicationController
#增加对课程成员修改的支持
if @project
if params[:membership]
@member.role_ids = params[:membership][:role_ids]
#added by nie
if (params[:membership][:role_ids])
role = Role.find(params[:membership][:role_ids][0])
if role.allowed_to?(:is_manager)
@projectInfo = ProjectInfo.new(:user_id => @member.user_id, :project_id => @project.id)
@projectInfo.save
else
user_admin = ProjectInfo.where("user_id = ? and project_id = ?", @member.user_id, @project.id)
if user_admin.size > 0
user_admin.each do |user|
user.destroy
ActiveRecord::Base.transaction do
begin
@member.role_ids = params[:membership][:role_ids]
if (params[:membership][:role_ids])
role = Role.find(params[:membership][:role_ids][0])
if role.allowed_to?(:is_manager)
@projectInfo = ProjectInfo.new(:user_id => @member.user_id, :project_id => @project.id)
@projectInfo.save
else
user_admin = ProjectInfo.where("user_id = ? and project_id = ?", @member.user_id, @project.id)
if user_admin.size > 0
user_admin.each do |user|
user.destroy
end
end
end
end
@member.save!
rescue Exception => e
puts e
end
end
end
saved = @member.save
respond_to do |format|
format.html { redirect_to_settings_in_projects }
format.js
@ -379,27 +398,33 @@ class MembersController < ApplicationController
#课程成员删除修改
if @project
if request.delete? && @member.deletable?
@member.destroy
# end
user_admin = ProjectInfo.where("user_id = ? and project_id = ?", @member.user_id, @project.id)
if user_admin.size > 0
user_admin.each do |user|
user.destroy
ActiveRecord::Base.transaction do
begin
@member.destroy
# end
user_admin = ProjectInfo.where("user_id = ? and project_id = ?", @member.user_id, @project.id)
if user_admin.size > 0
user_admin.each do |user|
user.destroy
end
end
user_grade = UserGrade.where("user_id = ? and project_id = ?", @member.user_id, @project.id)
if user_grade.size > 0
user_grade.each do |grade|
grade.destroy
end
end
# 移出的时候删除申请消息,不需要删除消息,所以不必要关联删除
applied_projects = AppliedProject.where(:project_id => @project.id, :user_id => @member.user_id).first
unless applied_projects.nil?
applied_projects.delete
end
#移出项目发送消息
ForgeMessage.create(:user_id => @member.user_id, :project_id => @project.id, :forge_message_type => "RemoveFromProject", :viewed => false, :forge_message_id => User.current.id)
rescue Exception => e
puts e
end
end
user_grade = UserGrade.where("user_id = ? and project_id = ?", @member.user_id, @project.id)
if user_grade.size > 0
user_grade.each do |grade|
grade.destroy
end
end
# 移出的时候删除申请消息,不需要删除消息,所以不必要关联删除
applied_projects = AppliedProject.where(:project_id => @project.id, :user_id => @member.user_id).first
unless applied_projects.nil?
applied_projects.delete
end
#移出项目发送消息
ForgeMessage.create(:user_id => @member.user_id, :project_id => @project.id, :forge_message_type => "RemoveFromProject", :viewed => false, :forge_message_id => User.current.id)
end
respond_to do |format|
format.html { redirect_to_settings_in_projects }

View File

@ -154,22 +154,14 @@ class MyController < ApplicationController
diskfile1 = diskfile + 'temp'
begin
if request.post?
# 修改邮箱的时候同步修改到gitlab
if @user.mail != params[:user][:mail]
g = Gitlab.client
begin
g.edit_user(@user.gid, :email => params[:user][:mail])
rescue
logger.error "sync user's email of gitlab failed!"
end
end
changed_login = (@user.login != params[:login])
changed_mail = (@user.mail != params[:user][:mail])
@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]
@user.login = params[:login].strip
unless @user.user_extensions.nil?
# 如果用户是从业者将单位名称保存至学校id字段
if @user.user_extensions.identity == 3
@ -195,6 +187,21 @@ class MyController < ApplicationController
@se.description = params[:description]
if @user.save && @se.save
# 修改邮箱的时候同步修改到gitlab
if changed_mail || changed_login
g = Gitlab.client
s = Trustie::Gitlab::Sync.new
begin
gid = @user.gid
if gid.nil?
gid = s.sync_user(@user).id
end
g.edit_user(gid, :email => params[:user][:mail], :username => @user.login)
rescue Exception => e
puts e
end
end
# 头像保存
FileUtils.mv diskfile1, diskfile, force: true if File.exist? diskfile1
@user.pref.save

View File

@ -42,6 +42,8 @@ class NewsController < ApplicationController
@limit = 10
end
@contest = Contest.find(params[:contest_id]) if params[:contest_id]
# modify by nwb
if params[:course_id] && @course==nil
@course = Course.find(params[:course_id])
@ -69,6 +71,84 @@ class NewsController < ApplicationController
format.api
format.atom { render_feed(@newss, :title => (@project ? @project.name : Setting.app_title) + ": #{l(:label_news_plural)}") }
end
elsif @contest
if (User.current.admin? || @contest.is_public || (!@contest.is_public && User.current.member_of_contest?(@contest)))
@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 = @contest.news if @contest
# @newss = scope.all(:include => [:author, :contest], :order => "#{News.table_name}.created_on DESC")
#
# @page = params[:page] ? params[:page].to_i + 1 : 0
news_page = 0 #@page *10
# @news_count = @newss.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 #{sort_type}").offset(news_page).includes(:author,:course).all()
else
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,:contest).all()
end
scope_order.each do |topic|
topic[:updated_at] = topic.contest_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
@is_new = params[:is_new]
#@newss = paginateHelper scope_order,10
@left_nav_type = 5
respond_to do |format|
format.html {
@news = News.new
render :layout => 'base_contests'
}
format.js
format.api
end
else
render_403
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
@ -190,6 +270,15 @@ class NewsController < ApplicationController
format.html {render :layout => 'base_courses'}
end
end
elsif @news.contest_id
@contest = Contest.find(@news.contest_id)
if @contest
@left_nav_type = 4
respond_to do |format|
format.js
format.html {render :layout => 'base_contests'}
end
end
elsif @project
respond_to do |format|
format.js
@ -255,6 +344,22 @@ class NewsController < ApplicationController
#layout_file = 'base_courses'
#render :action => 'new', :layout => layout_file
end
elsif @contest
@news = News.new(:contest => @contest, :author => User.current)
#render :layout => 'base_courses'
@news.safe_attributes = params[:news]
@news.save_attachments(params[:attachments])
if @news.save
if params[:asset_id]
ids = params[:asset_id].split(',')
update_kindeditor_assets_owner ids,@news.id,OwnerTypeHelper::NEWS
end
render_attachment_warning_if_needed(@news)
else
end
respond_to do |format|
format.html{redirect_to contest_news_index_path(@contest)}
end
end
end
@ -310,10 +415,15 @@ class NewsController < ApplicationController
if @news.org_subfield_id
@org_subfield = OrgSubfield.find(@news.org_subfield_id)
@organization = @org_subfield.organization
elsif @news.contest_id
@contest = Contest.find(@news.contest_id)
end
if @course
@left_nav_type = 4
render :layout => "base_courses"
elsif @contest
@left_nav_type = 4
render :layout => "base_contests"
elsif @org_subfield
render :layout => 'base_org'
end
@ -335,6 +445,8 @@ class NewsController < ApplicationController
def destroy
if @news.org_subfield_id
@org_subfield = OrgSubfield.find(@news.org_subfield_id)
elsif @news.contest_id
@contest = Contest.find(@news.contest_id)
end
@news.destroy
# modify by nwb
@ -342,6 +454,8 @@ class NewsController < ApplicationController
redirect_to project_news_index_url(@project)
elsif @course
redirect_to course_news_index_url(@course)
elsif @contest
redirect_to contest_news_index_url(@contest)
elsif @org_subfield
redirect_to organization_path(@org_subfield.organization, :org_subfield_id => @org_subfield.id)
end

View File

@ -133,6 +133,8 @@ class PraiseTreadController < ApplicationController
@obj = Contest.find_by_id(id)
when 'Syllabus'
@obj = Syllabus.find_by_id(id)
when 'Work'
@obj = Work.find_by_id(id)
else
@obj = nil
end

View File

@ -432,7 +432,7 @@ class ProjectsController < ApplicationController
# 如果已经邀请过该用户,则不重复发送
if InviteList.where("project_id =? and mail =?", @project.id, params[:mail].to_s).first.nil?
email = params[:mail]
Mailer.request_member_to_project(email, @project, User.current).deliver
# Mailer.request_member_to_project(email, @project, User.current).deliver
flash[:notice] = l(:notice_email_sent, :value => email)
else
flash[:error] = l(:notice_email_invited)
@ -445,7 +445,7 @@ class ProjectsController < ApplicationController
first_name = params[:first_name]
last_name = params[:last_name]
gender = params[:gender]
Mailer.send_invite_in_project(email, @project, User.current, first_name, last_name, gender).deliver
# Mailer.send_invite_in_project(email, @project, User.current, first_name, last_name, gender).deliver
@is_zhuce = false
flash[:notice] = l(:notice_email_sent, :value => email)
end
@ -458,13 +458,13 @@ class ProjectsController < ApplicationController
invite_list = InviteList.where("project_id =? and mail =?", @project.id, params[:mail].to_s).first
if invite_list.nil?
email = params[:mail]
Mailer.request_member_to_project(email, @project, User.current).deliver
# Mailer.request_member_to_project(email, @project, User.current).deliver
flash[:notice] = l(:notice_email_sent, :value => email)
else
# 已经发送过了则隔3小时才能再次发送
if Time.now - invite_list.created_at > 10800
email = params[:mail]
Mailer.request_member_to_project(email, @project, User.current).deliver
# Mailer.request_member_to_project(email, @project, User.current).deliver
flash[:notice] = l(:notice_email_sent, :value => email)
else
flash[:error] = l(:notice_email_invited)

View File

@ -35,7 +35,7 @@ class RepositoriesController < ApplicationController
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, :project_archive, :export_rep_static]
before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo, :to_gitlab, :forked, :export_rep_static]
# 连接gitlab
# before_filter :connect_gitlab, :only => [:quality_analysis, :commit_diff]
@ -121,9 +121,15 @@ class RepositoriesController < ApplicationController
# 一键ZIP下载
def project_archive
g = Gitlab.client
g.get()
# g.project_archive(params[:gpid].to_i, params[:rev])
token = Gitlab.private_token
token = aes_encrypt(token, "abcd")
# g = Gitlab.client
# g.project_archive(@project.gpid, @rev)
# 'git archive --format zip --output /path/to/file.zip master' # 将 master 以zip格式打包到指定文件
#
# zip_path = Gitlab.endpoint.to_s + "/projects/" + @project.gpid.to_s + "/repository/archive?&private_token=" + Gitlab.private_token
# f = open(zip_path).read
# send_file "/path/to/file.zip"
end
# 判断用户是否已经fork过该项目
@ -265,12 +271,23 @@ update
@repository.type = 'Repository::Gitlab'
@repository.identifier = @repository.identifier.downcase
@repository.url = @repository.identifier
if request.post? && @repository.save
s = Trustie::Gitlab::Sync.new
s.create_project(@project, @repository)
redirect_to(:controller => 'repositories', :action => 'show', :id => @project, :repository_id => gitlab_repository(@project).try(:identifier))
else
redirect_to settings_project_url(@project, :tab => 'repositories',:repository_error_message=>@repository.errors.full_messages)
ActiveRecord::Base.transaction do
begin
if request.post? && @repository.save
s = Trustie::Gitlab::Sync.new
s.create_project(@project, @repository)
raise "sync failed" if @project.gpid.blank?
redirect_to(:controller => 'repositories', :action => 'show', :id => @project, :repository_id => gitlab_repository(@project).try(:identifier))
else
redirect_to settings_project_url(@project, :tab => 'repositories',:repository_error_message=>@repository.errors.full_messages)
end
rescue Gitlab::Error::Forbidden => e
@message = l(:label_pull_request_forbidden)
rescue Gitlab::Error::NotFound => e
@message = l(:label_pull_request_notfound)
rescue Exception => e
puts e
end
end
end
end
@ -398,8 +415,12 @@ update
@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_token = Gitlab.private_token
# token值加密解密
token = aes_encrypt("priEn3UwXfJs3Pmy", gitlab_token)
# token值解密
# gitlab_token = aes_dicrypt("priEn3UwXfJs3Pmy", token)
@zip_path = Gitlab.endpoint.to_s + "/projects/" + @project.gpid.to_s + "/repository/archive?&private_token=" + token
end
@creator = @project.owner.to_s

View File

@ -11,6 +11,8 @@ class ShieldActivitiesController < ApplicationController
ShieldActivity.create(:container_type => 'User', :container_id => params[:user_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i)
elsif params[:course_id]
ShieldActivity.create(:container_type => 'User', :container_id => params[:user_id].to_i, :shield_type => 'Course', :shield_id => params[:course_id].to_i)
elsif params[:contest_id]
ShieldActivity.create(:container_type => 'User', :container_id => params[:user_id].to_i, :shield_type => 'Contest', :shield_id => params[:contest_id].to_i)
end
end
end
@ -37,6 +39,10 @@ class ShieldActivitiesController < ApplicationController
ShieldActivity.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
elsif params[:contest_id]
ShieldActivity.where(:container_type => 'User', :container_id => params[:user_id].to_i, :shield_type => 'Contest', :shield_id => params[:contest_id].to_i).each do |act|
act.destroy
end
end
end
end

View File

@ -1344,22 +1344,6 @@ class StudentWorkController < ApplicationController
end
private
def searchstudent_by_name users, name
mems = []
if name != ""
name = name.to_s.downcase
users.each do |m|
username = m.lastname.to_s.downcase + m.firstname.to_s.downcase
if(m.login.to_s.downcase.include?(name) || m.user_extensions[:student_id].to_s.downcase.include?(name) || username.include?(name))
mems << m
end
end
else
mems = users
end
mems
end
def hsd_committed_work?(user, homework)
sw = StudentWork.where("user_id =? and homework_common_id =? and work_status != 0", user, homework).first
sw.nil? ? result = false : result = true

View File

@ -39,10 +39,10 @@ class UsersController < ApplicationController
:unfinished_poll_list, :user_homeworks,:student_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments,
:anonymous_evaluation_list,:unfinished_test_list, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index,
:unapproval_applied_list, :activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index,
:activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index,:user_resource,
:user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction,
:activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index,:user_resource,:user_contestlist,
:user_courses4show,:user_projects4show,:user_contests4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction,
:user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course,:user_courselist,:user_projectlist,:sort_syllabus_list,
:sort_project_list,:my_homeworks,:manage_or_receive_homeworks,:search_m_r_homeworks, :cancel_or_collect,:expand_courses,:homepage, :user_issues, :course_community, :project_community]
:sort_project_list,:my_homeworks,:manage_or_receive_homeworks,:search_m_r_homeworks, :cancel_or_collect,:expand_courses,:homepage, :user_issues, :course_community, :project_community, :contest_community]
before_filter :auth_user_extension, only: :show
#before_filter :rest_user_score, only: :show
#before_filter :select_entry, only: :user_projects
@ -177,9 +177,9 @@ class UsersController < ApplicationController
@is_project = params[:is_project]
case params[:type]
when 'HomeworkCommon'
when 'HomeworkCommon', 'Work'
@reply = JournalsForMessage.find params[:reply_id]
@type = 'HomeworkCommon'
@type = params[:type]
if params[:user_activity_id]
@user_activity_id = params[:user_activity_id]
else
@ -243,6 +243,8 @@ class UsersController < ApplicationController
if @type == 'JournalsForMessage'
if reply.jour_type == "HomeworkCommon"
@type = "HomeworkCommon"
elsif reply.jour_type == "Work"
@type = "Work"
elsif reply.jour_type == "Syllabus"
@type = "Syllabus"
end
@ -255,6 +257,12 @@ class UsersController < ApplicationController
comment = HomeworkCommon.add_homework_jour(User.current, params[:reply_message], reply.jour_id, reply.root_id, options)
@root.update_column('updated_at', Time.now)
@is_teacher = User.current.allowed_to?(:as_teacher, @root.course) || User.current.admin?
when 'Work'
@root = Work.find reply.jour_id
options = {:notes => params[:reply_message], :reply_id => reply.user_id,:user_id => User.current.id,:m_parent_id => params[:reply_id].to_i,:m_reply_id => params[:reply_id].to_i, :root_id => reply.root_id}
comment = Work.add_work_jour(User.current, params[:reply_message], reply.jour_id, reply.root_id, options)
@root.update_column('updated_at', Time.now)
@is_teacher = User.current.admin_of_contest?(@root.contest) || User.current.admin?
when 'JournalsForMessage'
options = {:user_id => User.current.id,
:status => true,
@ -768,7 +776,7 @@ class UsersController < ApplicationController
ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", User.current.id, params[:homework_id].to_i)
if ah.empty?
ApplyHomework.create(:user_id => params[:id].to_i, :homework_common_id => params[:homework_id].to_i, :status => 1)
Mailer.run.apply_for_homework_request(homework, User.current)
# Mailer.run.apply_for_homework_request(homework, User.current)
CourseMessage.create(:user_id => homework.user_id, :course_id => homework.course.id, :viewed => false,:course_message_id=>params[:homework_id].to_i,:course_message_type=>'HomeworkCommon',:status=>5,:apply_user_id=>params[:id].to_i,:content=>params[:content])
@state = 2
@ah = ApplyHomework.where("user_id = ? and homework_common_id = ?", params[:id].to_i, params[:homework_id].to_i).first
@ -1641,6 +1649,13 @@ class UsersController < ApplicationController
@all_count = @user.favorite_projects.visible.count
end
# 竞赛社区左侧列表展开
def user_contests4show
@page = params[:page].to_i + 1
@courses = @user.favorite_contests.visible.where("is_delete =?", 0).select("contests.*,(SELECT MAX(updated_at) FROM `contest_activities` WHERE contest_activities.contest_id = contests.id) AS a").order("a desc").limit(10).offset(@page * 10)
@all_count = @user.favorite_contests.visible.where("is_delete =?", 0).count
end
def user_course_activities
lastid = nil
if params[:lastid]!=nil && !params[:lastid].empty?
@ -1834,7 +1849,7 @@ class UsersController < ApplicationController
end
@message_count = @message_alls.count
@message_alls = paginateHelper @message_alls, 20
@unsolved_issues_count = Issue.where(:assigned_to_id => @user.id, :status_id => [1, 2, 4, 6]).includes(:author, :project).order("updated_on desc").count
@unsolved_issues_count = Issue.where(:assigned_to_id => @user.id, :status_id => [1, 2, 4, 6]).includes(:author, :project).count
# 用户待完成的作业
my_course_ids = StudentsForCourse.includes(:course).where("student_id = #{@user.id} and courses.is_delete = 0").blank? ? "(-1)" : "(" + StudentsForCourse.includes(:course).where("student_id = #{@user.id} and courses.is_delete = 0").map{|sc| sc.course_id}.join(",") + ")"
homeworks = HomeworkCommon.where("course_id in #{my_course_ids} and publish_time <= '#{Date.today}'")
@ -1873,7 +1888,7 @@ class UsersController < ApplicationController
@applied_message_alls << mess
end
elsif (message_all.message_type == "AppliedMessage" )
if (mess.applied_type == "StudentWorksScoresAppeal" && mess.status == 0) || (mess.applied_type == "AppliedProject" && mess.status == 1) || ( mess.applied_type == "ApplyAddSchools" && ApplyAddSchools.where(:school_id => mess.applied_id, :status => 0).count != 0 )
if (mess.applied_type == "AppliedContest" && mess.status == 0) || (mess.applied_type == "StudentWorksScoresAppeal" && mess.status == 0) || (mess.applied_type == "AppliedProject" && mess.status == 1) || ( mess.applied_type == "ApplyAddSchools" && ApplyAddSchools.where(:school_id => mess.applied_id, :status => 0).count != 0 )
@applied_message_alls << mess
end
elsif message_all.message_type == "CourseMessage"
@ -2059,11 +2074,11 @@ class UsersController < ApplicationController
anonymous_evaluation_ids = student_work_scores.blank? ? "(-1)" : "(" + student_work_scores.map{|st| st.student_work_id}.join(",") + ")"
unfinished_evaluations = @user.student_works_evaluation_distributions.where("student_work_id not in #{anonymous_evaluation_ids}")
unfinished_evaluations_work_ids = unfinished_evaluations.blank? ? "(-1)" : "(" + unfinished_evaluations.map{|st| st.student_work_id}.join(",") + ")"
@anonymous_evaluation_count = StudentWork.where("student_works.id in #{unfinished_evaluations_work_ids} and homework_common_id in #{homework_ids}").count
homework_ids = StudentWork.where("id in #{unfinished_evaluations_work_ids} and homework_common_id in #{homework_ids}").blank? ? "(-1)" : "(" + StudentWork.where("id in #{unfinished_evaluations_work_ids} and homework_common_id in #{homework_ids}").map{|st| st.homework_common_id}.join(",") + ")"
@anonymous_evaluation = HomeworkCommon.where("homework_commons.id in #{homework_ids}")
@anonymous_evaluation_count = @anonymous_evaluation.count
@limit = 20
@anonymous_evaluation_pages = Paginator.new @anonymous_evaluation_count, @limit, params['page'] || 1
@anonymous_evaluation_pages = Paginator.new @anonymous_evaluation.count, @limit, params['page'] || 1
@offset ||= @anonymous_evaluation_pages.offset
@anonymous_evaluation = paginateHelper @anonymous_evaluation, @limit
respond_to do |format|
@ -2084,7 +2099,7 @@ class UsersController < ApplicationController
@message_alls << mess
end
elsif (message_all.message_type == "AppliedMessage" )
if (mess.applied_type == "StudentWorksScoresAppeal" && mess.status == 0) || (mess.applied_type == "AppliedProject" && mess.status == 1) || ( mess.applied_type == "ApplyAddSchools" && ApplyAddSchools.where(:school_id => mess.applied_id, :status => 0).count != 0 )
if (mess.applied_type == "AppliedContest" && mess.status == 0) || (mess.applied_type == "StudentWorksScoresAppeal" && mess.status == 0) || (mess.applied_type == "AppliedProject" && mess.status == 1) || ( mess.applied_type == "ApplyAddSchools" && ApplyAddSchools.where(:school_id => mess.applied_id, :status => 0).count != 0 )
@message_alls << mess
end
elsif message_all.message_type == "CourseMessage"
@ -2109,6 +2124,7 @@ class UsersController < ApplicationController
# 课程社区
def course_community
@course_community = "课程"
if params[:course_id] != nil
join_course_messages = CourseMessage.where("course_id =? and course_message_type =? and user_id =? and course_message_id =? and viewed =?",
params[:course_id], 'JoinCourseRequest', User.current.id, @user.id, false)
@ -2117,7 +2133,7 @@ class UsersController < ApplicationController
shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id)
@page = params[:page] ? params[:page].to_i + 1 : 0
user_course_ids = (@user.favorite_courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.favorite_courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")"
course_types = "('Message','News','HomeworkCommon','Poll','Course','JournalsForMessage')"
course_types = "('Message','News','HomeworkCommon','Poll','Course','JournalsForMessage','Attachment')"
principal_types = "JournalsForMessage"
container_type = ''
act_type = ''
@ -2133,6 +2149,9 @@ class UsersController < ApplicationController
when "course_message"
container_type = 'Course'
act_type = 'Message'
when "course_resource"
container_type = 'Course'
act_type = "Attachment"
when "course_poll"
container_type = 'Course'
act_type = 'Poll'
@ -2176,6 +2195,7 @@ class UsersController < ApplicationController
def project_community
# 看别人的主页显示动态
#更新用户申请成为课程老师或教辅消息的状态
@project_community = "项目"
shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Project'").map(&:shield_id)
@page = params[:page] ? params[:page].to_i + 1 : 0
user_project_ids = (@user.favorite_projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.favorite_projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")"
@ -2224,6 +2244,62 @@ class UsersController < ApplicationController
end
end
# 竞赛社区
def contest_community
@contest_community = "竞赛"
shield_contest_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Contest'").map(&:shield_id)
@page = params[:page] ? params[:page].to_i + 1 : 0
user_contest_ids = (@user.favorite_contests.visible.where("is_delete = 0").map{|contest| contest.id}-shield_contest_ids).empty? ? "(-1)" : "(" + (@user.favorite_contests.visible.map{|contest| contest.id}-shield_contest_ids).join(",") + ")"
contest_types = "('Message','News','Work','Contest','JournalsForMessage')"
container_type = ''
act_type = ''
if params[:type].present?
case params[:type]
when "contest_work"
container_type = 'Contest'
act_type = 'Work'
when "contest_news"
container_type = 'Contest'
act_type = 'News'
when "contest_message"
container_type = 'Contest'
act_type = 'Message'
when "contest_journals"
container_type = 'Contest'
act_type = 'JournalsForMessage'
when "current_user"
container_type = 'Principal'
act_type = 'Principal'
when "all"
container_type = 'all'
act_type = 'all'
end
end
if container_type != '' && container_type != 'all'
if container_type == 'Contest'
sql = "container_type = '#{container_type}' and container_id in #{user_contest_ids} and act_type = '#{act_type}'"
elsif container_type == 'Principal' && act_type == 'Principal'
sql = "user_id = #{@user.id} and (container_type = 'Contest' and container_id in #{user_contest_ids} and act_type in #{contest_types})"
end
if User.current != @user
sql += " and user_id = #{@user.id}"
end
else
sql = "(container_type = 'Contest' and container_id in #{user_contest_ids} and act_type in #{contest_types})"
if container_type != 'all' && User.current != @user
sql = "user_id = #{@user.id} and(" + sql + ")"
end
end
@user_activities_count = UserActivity.where("#{sql}").order('updated_at desc').count
@user_activities = UserActivity.where("#{sql}").order('updated_at desc').limit(10).offset(@page * 10)
@type = params[:type]
respond_to do |format|
format.js
format.html {render :layout => 'base_contest_community'}
end
end
def show_old
pre_count = 10 #limit
# Time 2015-02-04 11:46:34
@ -3979,7 +4055,7 @@ class UsersController < ApplicationController
end
end
#收藏班级/项目
#收藏班级/项目/竞赛
def cancel_or_collect
if params[:project]
@project = Project.find params[:project]
@ -3987,20 +4063,39 @@ class UsersController < ApplicationController
elsif params[:course]
@course = Course.find params[:course]
member = Member.where("user_id = #{@user.id} and course_id = #{@course.id}")
elsif params[:contest]
@contest = Contest.find params[:contest]
member = ContestMember.where("user_id = #{@user.id} and contest_id = #{@contest.id}")
end
unless member.empty?
member.first.update_attribute(:is_collect, member.first.is_collect == 0 ? 1 : 0)
member.first.update_attribute(:is_collect, member.first.is_collect == false ? 1 : 0)
end
if @project
@projects = @user.favorite_projects.visible.select("projects.*, (SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(10)
elsif @course
@courses = @user.favorite_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(10)
elsif @contest
@contests = @user.favorite_contests.visible.where("is_delete =?", 0).select("contests.*,(SELECT MAX(updated_at) FROM `contest_activities` WHERE contest_activities.contest_id = contests.id) AS a").order("a desc").limit(10)
end
respond_to do |format|
format.js
end
end
# 用户竞赛列表
def user_contestlist
# 我创建的竞赛
@my_contests = @user.contests.where(:user_id => @user.id).order("created_at desc")
@my_contests_count = @my_contests.count
# 我参与的竞赛
my_all_contests = @user.contest_members.where(:user_id => @user.id).blank? ? "(-1)" : "(" + @user.contest_members.where(:user_id => @user.id).map{ |cm| cm.contest_id }.join(",") + ")"
@my_joined_contests = Contest.where("id in #{my_all_contests} and user_id != #{@user.id}").order("created_at desc")
@my_joined_contests_count = @my_joined_contests.count
respond_to do |format|
format.html {render :layout => 'base_contest_community'}
end
end
def user_projectlist
@order, @c_sort, @type, @list_type = 1, 2, 1, 1
#limit = 5
@ -4107,6 +4202,12 @@ class UsersController < ApplicationController
@journals = obj.journals_for_messages.reorder("created_on desc")
@is_teacher = User.current.allowed_to?(:as_teacher,obj.course)
@user_activity_id = params[:user_activity_id].to_i if params[:user_activity_id]
when 'Work'
obj = Work.where('id = ?', params[:id].to_i).first
@type = 'Work'
@journals = obj.journals_for_messages.reorder("created_on desc")
@is_teacher = User.current.admin_of_contest?(obj.contest)
@user_activity_id = params[:user_activity_id].to_i if params[:user_activity_id]
end
end
@journals = get_no_children_comments_all @journals

View File

@ -118,6 +118,15 @@ class WordsController < ApplicationController
end
@hw_status = params[:hw_status].to_i if
@is_teacher = User.current.allowed_to?(:as_teacher, @homework.course) || User.current.admin?
elsif @journal_destroyed.jour_type == 'Work'
@work = Work.find @journal_destroyed.jour_id
if params[:user_activity_id]
@user_activity_id = params[:user_activity_id].to_i
else
@user_activity_id = -1
end
@hw_status = params[:hw_status].to_i if
@is_teacher = User.current.admin_of_contest?(@work.contest) || User.current.admin?
elsif @journal_destroyed.jour_type == 'Syllabus'
@syllabus = Syllabus.find @journal_destroyed.jour_id
@count = @syllabus.journals_for_messages.count
@ -362,6 +371,70 @@ class WordsController < ApplicationController
end
end
#题目的回复
def leave_contest_work_message
if User.current.logged?
@user = User.current
@contestwork = Work.find(params[:id])
if params[:homework_message].size>0 && User.current.logged? && @user
feedback = Work.add_work_jour(@user, params[:homework_message], params[:id], @contestwork.id)
if (feedback.errors.empty?)
if params[:asset_id]
ids = params[:asset_id].split(',')
update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE
end
@contestwork.update_column('updated_at', Time.now)
update_contest_activity(@contestwork.class,@contestwork.id)
update_user_activity(@contestwork.class,@contestwork.id)
respond_to do |format|
format.js{
@user_activity_id = params[:user_activity_id].to_i
@hw_status = params[:hw_status].to_i if params[:hw_status]
@is_teacher = User.current.admin_of_contest?(@contestwork.contest) || User.current.admin?
}
end
else
flash[:error] = feedback.errors.full_messages[0]
end
end
else
render_403
end
end
#题目的二级回复
def reply_to_contest_work
if User.current.logged?
@user = User.current
reply = JournalsForMessage.find params[:id].to_i
@contestwork = Work.find reply.jour_id
if params[:reply_message].size>0 && User.current.logged? && @user
options = {:notes => params[:reply_message], :reply_id => reply.user_id,:user_id => @user.id,:m_parent_id => params[:id].to_i,:m_reply_id => params[:id].to_i, :root_id => reply.root_id}
feedback = Work.add_work_jour(@user, params[:reply_message], reply.jour_id, reply.root_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
@contestwork.update_column('updated_at', Time.now)
update_contest_activity(@contestwork.class,@contestwork.id)
update_user_activity(@contestwork.class,@contestwork.id)
respond_to do |format|
format.js{
@user_activity_id = params[:user_activity_id].to_i
@hw_status = params[:hw_status].to_i if params[:hw_status]
@is_teacher = User.current.admin_of_contest?(@contestwork.contest) || User.current.admin?
}
end
else
flash[:error] = feedback.errors.full_messages[0]
end
end
else
render_403
end
end
#课程大纲的二级回复
def reply_to_syllabus
if User.current.logged?

View File

@ -0,0 +1,223 @@
class WorksController < ApplicationController
layout "base_contests"
before_filter :find_contest, :only => [:index,:new,:create]
before_filter :find_contestwork, :only => [:edit,:update,:destroy,:score_rule_set,:alert_open_student_works,:open_student_works,:set_score_open,:alert_score_open_modal]
before_filter :admin_of_contest, :only => [:new, :create, :edit, :update, :destroy,:score_rule_set,:alert_open_student_works,:open_student_works]
before_filter :member_of_contest, :only => [:index]
def index
search = "%#{params[:search].to_s.strip.downcase}%"
@new_homework = Work.new
@new_homework.contest = @contest
@page = params[:page] ? params[:page].to_i + 1 : 0
@is_teacher = User.current.logged? && (User.current.admin? || User.current.admin_of_contest?(@contest))
if @is_teacher
@homework_commons = @contest.works.where("name like '%#{search}%'").order("created_at desc")
else
@homework_commons = @contest.works.where("name like '%#{search}%' and publish_time <= '#{Date.today}'").order("created_at desc")
end
@is_new = params[:is_new]
@homeworks = paginateHelper @homework_commons,10
#设置at已读
ids = @homeworks.inject([]) do |ids, homework|
jids = homework.journals_for_messages.map(&:id)
jids ? ids + jids : ids
# homework.delay.set_jour_viewed
end
unless ids.empty?
User.current.at_messages.where(viewed: false,
at_message_type: 'JournalsForMessage',
at_message_id: ids).update_all(viewed: true)
end
@left_nav_type = 3
respond_to do |format|
format.js
format.html
end
end
def show
end
def new
end
def create
if User.current.logged?
if params[:homework_common]
homework = Work.new
homework.name = params[:homework_common][:name]
homework.description = params[:homework_common][:description]
homework.end_time = params[:homework_common][:end_time] || Date.today
if params[:homework_common][:publish_time] == ""
homework.publish_time = Date.today
else
homework.publish_time = params[:homework_common][:publish_time]
end
homework.work_type = params[:homework_type].to_i || 1
#homework.late_penalty = 0
#homework.teacher_priority = 1
homework.user_id = User.current.id
homework.contest_id = @contest.id
homework.save_attachments(params[:attachments])
render_attachment_warning_if_needed(homework)
homework.work_status = homework.publish_time > Date.today ? 0 : 1
#分组作业
if homework.work_type == 3
homework_detail_group = WorkDetailGroup.new
homework.work_detail_group = homework_detail_group
homework_detail_group.min_num = params[:min_num].to_i
homework_detail_group.max_num = params[:max_num].to_i
homework_detail_group.base_on_project = params[:base_on_project].to_i
end
if homework.save
homework_detail_group.save if homework_detail_group
redirect_to works_path(:contest => @contest.id)
end
end
else
render_403
end
end
def update
if params[:homework_common]
@contestwork.name = params[:homework_common][:name]
@contestwork.description = params[:homework_common][:description]
if params[:homework_common][:publish_time] == ""
@contestwork.publish_time = Date.today
else
@contestwork.publish_time = params[:homework_common][:publish_time]
end
param_end_time = Time.parse(params[:homework_common][:end_time]).strftime("%Y-%m-%d")
homework_end_time = Time.parse(@contestwork.end_time.to_s).strftime("%Y-%m-%d")
if homework_end_time != param_end_time
if homework_end_time > param_end_time
@contestwork.contestant_works.each do |st|
if param_end_time < Time.parse(st.commit_time.to_s).strftime("%Y-%m-%d")
st.work_status = 2
st.save
end
end
else
@contestwork.contestant_works.where("work_status = 2").each do |st|
if param_end_time >= Time.parse(st.commit_time.to_s).strftime("%Y-%m-%d")
st.work_status = 1
st.save
end
end
end
end
@contestwork.end_time = params[:homework_common][:end_time] || Time.now
if params[:homework_type] && params[:homework_type].to_i != @contestwork.work_type
if @contestwork.work_type == 3
@contestwork.work_detail_group.destroy if @contestwork.work_detail_group
end
end
@contestwork.work_type = params[:homework_type].to_i || @contestwork.work_type
#status = false
if @contestwork.publish_time <= Date.today && @contestwork.work_status == 0
@contestwork.work_status = 1
#status = true
end
@contestwork.save_attachments(params[:attachments])
render_attachment_warning_if_needed(@contestwork)
#分组作业
if @contestwork.work_type == 3
@contestwork.work_detail_group ||= WorkDetailGroup.new
@homework_detail_group = @contestwork.work_detail_group
@homework_detail_group.min_num = params[:min_num].to_i if params[:min_num]
@homework_detail_group.max_num = params[:max_num].to_i if params[:max_num]
@homework_detail_group.base_on_project = params[:base_on_project] ? 1 : 0
end
if @contestwork.save
@homework_detail_group.save if @homework_detail_group
@hw_status = params[:hw_status].to_i
if @hw_status == 1
redirect_to user_contest_community_path(User.current.id)
elsif @hw_status == 2
redirect_to contest_path(@contest.id)
elsif @hw_status == 5
redirect_to contestant_works_path(:work => @contestwork.id)
else
redirect_to works_path(:contest => @contest.id)
end
end
end
end
def edit
@user = User.current
@hw_status = params[:hw_status].to_i
@homework = @contestwork
if @hw_status != 1
@left_nav_type = 3
respond_to do |format|
format.html{render :layout => 'base_contests'}
end
else
respond_to do |format|
format.html{render :layout => 'base_contest_community'}
end
end
end
def destroy
if @contestwork.destroy
respond_to do |format|
format.html {
@hw_status = params[:hw_status].to_i
if @hw_status == 1
redirect_to user_contest_community_path(User.current.id)
elsif @hw_status == 2
redirect_to contest_path(@contest.id)
else
redirect_to works_path(:contest => @contest.id)
end
}
end
end
end
private
#获取竞赛
def find_contest
@contest = Contest.find params[:contest]
rescue
render_404
end
#获取题目
def find_contestwork
@contestwork = Work.find params[:id]
@work_detail_group = @contestwork.work_detail_group
@contest = @contestwork.contest
rescue
render_404
end
#是不是管理员
def admin_of_contest
render_403 unless User.current.admin_of_contest?(@contest) || User.current.admin?
end
#当前用户是不是竞赛的成员
def member_of_contest
render_403 unless @contest.is_public==1 || User.current.member_of_contest?(@contest) || User.current.admin?
end
end

View File

@ -52,6 +52,17 @@ class ZipdownController < ApplicationController
else
zipfile = {:message => "no file"}
end
elsif params[:obj_class] == "Work"
homework = Work.find params[:obj_id]
render_403 if User.current.admin_of_contest?(homework.contest)
file_count = 0
homework.contestant_works.map { |work| file_count += work.attachments.count}
if file_count > 0
zipfile = zip_homework_common homework
else
zipfile = {:message => "no file"}
end
else
logger.error "[ZipDown#assort] ===> #{params[:obj_class]} unKown !!"
end
@ -159,6 +170,33 @@ class ZipdownController < ApplicationController
}]
end
def zip_contest_work homework_common
bid_homework_path = []
digests = []
homework_common.contestant_works.each do |work|
unless work.attachments.empty?
out_file = zip_student_work_by_user(work)
bid_homework_path << out_file.file_path
digests << out_file.file_digest
end
end
homework_id = homework_common.id
user_id = homework_common.user_id
out_file = find_or_pack(homework_id, user_id, digests.sort){
zipping("#{Time.now.to_i}_#{homework_common.name}.zip",
bid_homework_path, OUTPUT_FOLDER)
}
[{files:[out_file.file_path], count: 1, index: 1,
real_file: out_file.file_path,
file: File.basename(out_file.file_path),
base64file: encode64(File.basename(out_file.file_path)),
size:(out_file.pack_size / 1024.0 / 1024.0).round(2)
}]
end
def zip_homework_by_user(homework_attach)
homeworks_attach_path = []
not_exist_file = []
@ -216,6 +254,39 @@ class ZipdownController < ApplicationController
end
def zip_student_work_by_user(work)
homeworks_attach_path = []
not_exist_file = []
# 需要将所有homework.attachments遍历加入zip
digests = []
work.attachments.each do |attach|
if File.exist?(attach.diskfile)
homeworks_attach_path << attach.diskfile
digests << attach.digest
else
not_exist_file << attach.filename
digests << 'not_exist_file'
end
end
#单个文件的话,不需要压缩,只改名
out_file = nil
if homeworks_attach_path.size == 1
out_file = find_or_pack(work.homework_common_id, work.user_id, digests.sort){
des_path = "#{OUTPUT_FOLDER}/#{make_zip_name(work)}_#{File.basename(homeworks_attach_path.first)}"
FileUtils.cp homeworks_attach_path.first, des_path
des_path
}
else
out_file = find_or_pack(work.homework_common_id, work.user_id, digests.sort){
zipping("#{make_zip_name(work)}.zip",
homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file)
}
end
out_file
end
def find_or_pack(homework_id, user_id, digests)
raise "please given a pack block" unless block_given?

View File

@ -37,6 +37,37 @@ module ApplicationHelper
# super
# end
# 获取竞赛的管理人员
def contest_managers contest
contest.contest_members.select{|cm| cm.roles.to_s.include?("ContestManager")}
end
# 获取竞赛的评委人员
def contest_judges contest
contest.contest_members.select{|cm| cm.roles.to_s.include?("Judge")}
end
# 获取竞赛的参赛人员
def contest_contestants contest
contest.contest_members.select{|cm| cm.roles.to_s.include?("Contestant")}
end
# 字符串加密
def aes_encrypt(key, encrypted_string)
aes = OpenSSL::Cipher::Cipher.new("AES-128-ECB")
aes.encrypt
aes.key = key
txt = aes.update(encrypted_string) << aes.final
txt.unpack('H*')[0].upcase
end
# 字符串解密
def aes_dicrypt(key, dicrypted_string)
aes = OpenSSL::Cipher::Cipher.new("AES-128-ECB")
aes.decrypt
aes.key = key
aes.update([dicrypted_string].pack('H*')) << aes.final
end
# 获取多种类型的user用户名
def user_message_username user
user.try(:show_name)
@ -1286,10 +1317,20 @@ module ApplicationHelper
title << @project.name
elsif @course
title << @course.name
elsif @contest
title << @contest.name
elsif @organization
title << @organization.name
elsif @user
title << @user.try(:realname)
if !@project_community.blank?
title << @project_community
elsif !@course_community.blank?
title << @course_community
elsif !@contest_community.blank?
title << @contest_community
else
title << @user.try(:realname)
end
elsif @syllabus
title << @syllabus.title
else
@ -1903,7 +1944,7 @@ module ApplicationHelper
objects = objects.map {|o| o.is_a?(String) ? instance_variable_get("@#{o}") : o}.compact
errors = objects.map {|o| o.errors.full_messages}.flatten
if errors.any?
html << "<div id='errorExplanation'><ul>\n"
html << "<div id='errorExplanation'><ul class='pt10'>\n"
errors.each do |error|
###by xianbo
if(error!=l(:label_repository_path_not_null))
@ -2405,6 +2446,12 @@ module ApplicationHelper
candown = true
elsif attachment.container.class.to_s=="StudentWork"
candown = true
elsif attachment.container.class.to_s=="Contest"
candown = true
elsif attachment.container.class.to_s=="Work"
candown = true
elsif attachment.container.class.to_s=="ContestantWork"
candown = true
elsif attachment.container.class.to_s=="BlogComment" #博客资源允许下载
candown = true
elsif attachment.container.class.to_s=="Memo" #论坛资源允许下载
@ -2826,9 +2873,16 @@ module ApplicationHelper
end
technical_title
end
# 用户竞赛总数
def user_contest_count
count = @user.favorite_contests.visible.where("is_delete =?", 0).count
return count
end
# 用户项目总数
def user_project_count
@my_projects = @user.projects.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS updatetime").order("updatetime DESC")
@my_projects = @user.projects.visible.where("status != 9")
@my_project_total = @my_projects.count
end
@ -3024,6 +3078,40 @@ module ApplicationHelper
end
end
#根据传入作业确定显示为编辑作品还是新建作品,或者显示作品数量
def user_for_contest_work homework,is_contestant,work
count = homework.contestant_works.has_committed.count
if User.current.member_of_contest?(homework.contest)
if !is_contestant #老师显示作品数量
link_to "作品(#{count})", contestant_works_path(:work =>homework.id, :tab => 2), :class => "c_blue"
else #学生显示提交作品、修改作品等按钮
work = cur_user_works_for_work homework
project = cur_user_projects_for_work homework
if work.nil? && Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d")
if homework.work_type ==3 && project.nil? && homework.work_detail_group.base_on_project
link_to "提交作品(#{count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再提交作品'
else
link_to "提交作品(#{count})", new_contestant_work_path(:work => 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.work_type ==3 && project.nil? && homework.work_detail_group.base_on_project
link_to "补交作品(#{count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再补交作品'
else
link_to "补交作品(#{count})", new_contestant_work_path(:work => homework.id),:class => 'c_red'
end
else
if 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 "修改作品(#{count})", edit_contestant_work_path(work.id),:class => 'c_blue'
else
link_to "查看作品(#{count})", contestant_works_path(:work =>homework.id, :tab => 2), :class => 'c_blue', :title => "不可修改作品"
end
end
end
else
link_to "作品(#{count})",contestant_works_path(:work =>homework.id, :tab => 2),:class => "c_blue"
end
end
#根据传入作业确定显示为提交作品、补交作品、查看作品等
def student_for_homework_common homework
if User.current.allowed_to?(:as_teacher, homework.course)
@ -3108,6 +3196,24 @@ module ApplicationHelper
homework.student_work_projects.where("user_id = ?",User.current).first
end
#获取当前用户在指定题目下提交的作业的集合
def cur_user_works_for_work homework
work = homework.contestant_works.where("user_id = ? && work_status != 0",User.current).first
if homework.work_type == 3
pro = homework.contestant_work_projects.where("user_id = #{User.current.id}").first
if pro.nil? || pro.contestant_work_id == "" || pro.contestant_work_id.nil?
work = nil
else
work = ContestantWork.find pro.contestant_work_id
end
end
work
end
#获取当前用户在指定题目下关联的项目的集合
def cur_user_projects_for_work work
work.contestant_work_projects.where("user_id = ?",User.current).first
end
#获取当前作业的提交截止时间/互评截止时间
def cur_homework_end_time homework
str = ""
@ -3294,6 +3400,14 @@ int main(int argc, char** argv){
ss.html_safe
end
#竞赛动态的更新
def update_contest_activity type, id
contest_activity = ContestActivity.where("contest_act_type=? and contest_act_id =?", type.to_s, id).first
if contest_activity
contest_activity.updated_at = Time.now
contest_activity.save
end
end
#课程动态的更新
def update_course_activity type, id
course_activity = CourseActivity.where("course_act_type=? and course_act_id =?", type.to_s, id).first
@ -3392,6 +3506,17 @@ def student_work_index_url_in_org(homework_id, tab = 1, is_focus = '', show_work
end
end
def contestant_work_index_url_in_org(work_id, tab = 1, is_focus = '', show_work_id = '')
if is_focus != ''
Setting.protocol + "://" + Setting.host_name + "/contestant_work?work=" + work_id.to_s + "&tab=" + tab.to_s + "&is_focus=" + is_focus.to_s
elsif show_work_id != ''
Setting.protocol + "://" + Setting.host_name + "/contestant_work?work=" + work_id.to_s + "&tab=" + tab.to_s + "&show_work_id=" + show_work_id.to_s
else
Setting.protocol + "://" + Setting.host_name + "/contestant_work?work=" + work_id.to_s + "&tab=" + tab.to_s
end
end
def course_url_in_org(course_id)
Setting.protocol + "://" + Setting.host_name + "/courses/" + course_id.to_s
end
@ -3475,7 +3600,7 @@ end
def get_reply_by_type type, reply_id
reply = nil
case type
when 'HomeworkCommon'
when 'HomeworkCommon', 'Work'
reply = JournalsForMessage.find reply_id
when 'JournalsForMessage'
reply = JournalsForMessage.find reply_id
@ -3750,6 +3875,17 @@ def message_content content
content
end
def get_work_index(hw,is_teacher)
if is_teacher
works = hw.contest.works.order("created_at asc")
else
works = hw.contest.works.where("publish_time <= '#{Date.today}'").order("created_at asc")
end
hw_ids = works.map{|hw| hw.id} if !works.empty?
index = hw_ids.index(hw.id)
return index
end
def get_hw_index(hw,is_teacher)
if is_teacher
homeworks = hw.course.homework_commons.order("created_at asc")
@ -3800,6 +3936,23 @@ def get_hw_status homework_common
str
end
def get_cw_status contest_work
str = ""
if contest_work.work_status == 0 && contest_work.publish_time.nil?
str += '<span class="grey_homework_btn_cir ml5">挂起</span>'
elsif contest_work.work_status == 0
str += '<span class="grey_homework_btn_cir ml5">未发布</span>'
elsif contest_work.work_status == 1
if Time.parse(contest_work.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d")
str += '<span class="green_homework_btn_cir ml5">作品提交中</span>'
else
str += '<span class="red_homework_btn_cir ml5">作品补交中</span>'
end
end
str
end
def get_group_member_names work
result = ""
unless work.nil?
@ -3884,6 +4037,54 @@ def homework_type_option
type
end
# 竞赛题目类型
def work_type_option
type = []
option0 = []
option0 << "请选择竞赛类型"
option0 << 0
option1 = []
option1 << "普通竞赛"
option1 << 1
# option2 = []
# option2 << "编程作业"
# option2 << 2
option3 = []
option3 << "团队竞赛"
option3 << 3
type << option0
type << option1
#type << option2
type << option3
type
end
# 当前用户可见的某竞赛下的作品数
def visable_contest_work contest
if User.current.admin? || User.current.admin_of_contest?(contest)
work_num = contest.works.count
else
work_num = contest.works.where("publish_time <= '#{Date.today}'").count
end
work_num
end
def searchstudent_by_name users, name
mems = []
if name != ""
name = name.to_s.downcase
users.each do |m|
username = m.lastname.to_s.downcase + m.firstname.to_s.downcase
if(m.login.to_s.downcase.include?(name) || m.user_extensions[:student_id].to_s.downcase.include?(name) || username.include?(name))
mems << m
end
end
else
mems = users
end
mems
end
def add_reply_adapter obj, options
#modify by nwb
#添加对课程留言的支持

View File

@ -0,0 +1,17 @@
#encoding=utf-8
module ContestMembersHelper
def find_user_not_in_current_contest_by_name contest
if params[:q] && params[:q].lstrip.rstrip != ""
scope = Principal.active.sorted.not_member_of_contest(contest).like(params[:q])
else
scope = []
end
principals = paginateHelper scope,10
s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :id => 'principals', :class => 'sy_new_tchlist')
links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true){|text, parameters, options|
link_to text, host_with_protocol + "/contest_members/contest_member_autocomplete?" + parameters.merge(:q => params[:q],:flag => true,:contest=> contest, :format => 'js').to_query, :remote => true
}
s + content_tag('ul', links,:class => 'wlist',:style=>'float:left !important', :id => "contest_member_pagination_links" )
end
end

View File

@ -0,0 +1,16 @@
#encoding: utf-8
module ContestantWorksHelper
def get_status status
str = ""
case status
when 0
str = "未提交"
when 1
str = "已提交"
when 2
str = "迟交"
end
str
end
end

View File

@ -1,2 +0,0 @@
module ContestnotificationsHelper
end

View File

@ -1,206 +1,79 @@
#enconding:utf-8
# fq
module ContestsHelper
def render_notes(contest, journal, options={})
content = ''
removable = User.current == journal.user || User.current == contest.author
links = []
if !journal.notes.blank?
links << link_to(image_tag('comment.png'),
{:controller => 'contests', :action => 'new', :id => contest, :journal_id => journal},
:remote => true,
:method => 'post',
:title => l(:button_quote)) if options[:reply_links]
if removable
url = {:controller => 'contests',
:action => 'destroy',
:object_id => journal,
:id => contest}
links << ' '
links << link_to(image_tag('delete.png'), url,
:remote => true, :method => 'delete', :class => "delete", :title => l(:button_delete))
end
# 获取动态列表名称
def get_acts_list_type type
case type
when "work"
l(:label_work_acts)
when "news"
l(:label_news_acts)
when "attachment"
l(:label_attachment_acts)
when "message"
l(:label_message_acts)
when "journalsForMessage"
l(:label_journalsForMessage_acts)
when "poll"
l(:label_poll_acts)
else
l(:label_contest_cats)
end
content << content_tag('div', links.join(' ').html_safe, :class => 'contextual') unless links.empty?
content << textilizable(journal.notes)
css_classes = "wiki"
content_tag('div', content.html_safe, :id => "journal-#{journal.id}-notes", :class => css_classes)
end
def link_to_in_place_notes_editor(text, field_id, url, options={})
onclick = "$.ajax({url: '#{url_for(url)}', type: 'get'}); return false;"
link_to text, '#', options.merge(:onclick => onclick)
# 判断当前用户是否为竞赛管理员
def is_contest_manager?(user_id, contest_id)
@result = false
mem = ContestMember.where("user_id = ? and contest_id = ?",user_id, contest_id)
unless mem.blank?
@result = mem.first.roles.to_s.include?("ContestManager") ? true : false
end
return @result
end
# this method is used to get all projects that tagged one tag
# added by william
def get_contests_by_tag(tag_name)
Contest.tagged_with(tag_name).order('updated_on desc')
# 获取竞赛的管理人员
def contest_managers contest
contest.contest_members.select{|cm| cm.roles.to_s.include?("ContestManager")}
end
#added by huang
def sort_contest_enterprise(state, project_type)
content = ''.html_safe
case state
when 0
content << content_tag('li', link_to(l(:label_sort_by_active), calls_path(:contest_sort_type => '1', :project_type => project_type)))
content << content_tag('li', link_to(l(:label_sort_by_time), calls_path(:contest_sort_type => '0', :project_type => project_type), :class=>"selected"), :class=>"selected")
when 1
content << content_tag('li', link_to(l(:label_sort_by_active), calls_path(:contest_sort_type => '1', :project_type => project_type), :class=>"selected"), :class=>"selected")
content << content_tag('li', link_to(l(:label_sort_by_time), calls_path(:contest_sort_type => '0', :project_type => project_type)))
# 获取竞赛的评委人员
def contest_judges contest
contest.contest_members.select{|cm| cm.roles.to_s.include?("Judge")}
end
# 获取竞赛的参赛人员
def contest_contestants contest
contest.contest_members.select{|cm| cm.roles.to_s.include?("Contestant")}
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
content = content_tag('ul', content)
content_tag('div', content, :class => "tabs_enterprise")
end
#end
#huang
def sort_contest(state)
content = ''.html_safe
case state
when 0
content << content_tag('li', link_to(l(:label_sort_by_time), {controller: 'contests', action: 'index' ,:contest_sort_type => '1'}))
content << content_tag('li', link_to(l(:label_sort_by_active), {controller: 'contests', action: 'index' ,:contest_sort_type => '0'}, :class=>"selected"), :class=>"selected")
when 1
content << content_tag('li', link_to(l(:label_sort_by_time), {controller: 'contests', action: 'index' ,:contest_sort_type => '1'}, :class=>"selected"), :class=>"selected")
content << content_tag('li', link_to(l(:label_sort_by_active), {controller: 'contests', action: 'index' ,:contest_sort_type => '0'}))
else
mems = members
end
content = content_tag('ul', content)
content_tag('div', content, :class => "tabs")
end
#end
# def course_options_for_select(courses)
# # <option value = '0'>#{l(:label_choose_reward)}</option>
# html = ''
# courses.each do |course|
# html << "<option value = #{course.id}>"
# html << course.name
# html << "</option>"
# end
# html.html_safe
# end
# used to get the reward and handle the value which can be used to display in views
# added by william
def get_prize(c_project)
c_project.get_reward
mems
end
def get_prize(c_softapplication)
c_softapplication.get_reward
end
def count_contest_project
contests = Contest.find(:id)
@projects = []
# Modified by longjun
# for contest in contests
contests.each do |contest|
# end longjun
@projects += contest.contesting_projects
def zh_contest_role role
if role == "ContestManager"
result = l(:label_CM)
elsif role == "Judge"
result = l(:label_judge)
elsif role == "Contestant"
result = l(:label_contestant)
elsif role == "Manager"
result = l(:field_admin)
elsif role.include?("ContestManager") && role.include?("Judge")
result = l(:label_CM) + " " + l(:label_judge)
end
@projects.count
result
end
def count_contest_softapplication
contests = Contest.find(:id)
@softapplications = []
# Modified by alan
# for contest in contests
contests.each do |contest|
# end alan
@softapplications += contest.contesting_softapplications
end
@projects.count
end
def count_contest_user
contests = Contest.find(:id)
@users = []
# Modified by alan
# for contest in contests
contests.each do |contest|
contest.projects.each do |project|
@users += project.users
end
end
# end alan
@users.count
end
def count_contest_softapplication_user
contests = Contest.find(:id)
@users = []
# Modified by alan
# for contest in contests
contests.each do |contest|
contest.projects.each do |softapplications|
# for project in contest.softapplications
@users += softapplication.users
end
end
@users.count
end
def im_watching_student_id? contest
people = []
people << contest.author
# case bid.reward_type # 天煞的bid分了三用途里面各种hasmany还不定能用
# when 1
# when 2
# bid.join_in_contests.each do |jic|
# people << jic.user
# end
# when 3
# people += bid.courses.first.users.to_a
# else
# raise 'bids_helper: unknow bid type' # 出了错看这里!不知道的抛异常,省的找不到出错的地方!
# end
contest.join_in_contests.each do |jic|
people << jic.user
end
people.include?(User.current)
end
# def select_option_helper option
# tmp = Hash.new
# tmp={"" => ""}
# option.each do |project|
# tmp[project.name] = project.identifier
# end
# tmp
# end
def select_option_app_helper options
tmp = Hash.new
options.each do |option|
tmp[option.name] = option.id
end
tmp
end
#作品分类下拉框
def work_type_opttion
type = []
#work_types = WorksCategory.all
WorksCategory.all.each do |work_type|
option = []
option << work_type.category
option << work_type.category
type << option
end
type
end
end
end

View File

@ -11,4 +11,5 @@ module OwnerTypeHelper
SYLLABUS = 10
ArticleHomepage = 11
PROJECT = 12
CONTEST = 13
end

View File

@ -63,6 +63,11 @@ module PollHelper
def total_answer id
total = PollVote.find_by_sql("SELECT distinct(user_id) FROM `poll_votes` where poll_question_id = #{id}").count
end
# 获取其它选项的答案
def other_answers poll_question
poll_question.poll_votes.select{|pv| !pv.try(:vote_text).blank?}
end
#页面体型显示
def options_show pq

View File

@ -63,6 +63,14 @@ module UsersHelper
end
# 作业待匿评的次数
def work_anonymous_num homework
# student_work_ids = StudentWork.where(:homework_common_id => homework.id)
# total_eva_count = StudentWorksEvaluationDistribution.where(:student_work_id => student_work_ids).count
# already_eva_count = StudentWorksScore.where("SELECT * FROM (SELECT * FROM student_works_scores WHERE student_work_id in #{student_work_ids} AND reviewer_role = 3 ) AS t GROUP BY user_id")
# unfinished_eva_count = total_eva_count - already_eva_count
end
def get_resource_type type
case type
when 'Course'
@ -136,7 +144,7 @@ module UsersHelper
def applied_project_users applied_message
# case applied_message.status
# when 3,2,1,5,4,7,6
user = User.find(applied_message.applied_user_id).show_name
user = User.find(applied_message.applied_user_id)
# end
end
@ -145,11 +153,11 @@ module UsersHelper
when 4
"被拒绝"
when 5
"已拒绝"
"已拒绝"
when 6
"已通过"
when 7
"已同意"
"已同意"
end
end

View File

@ -0,0 +1,2 @@
module WorksHelper
end

View File

@ -0,0 +1,28 @@
class AppliedContest < ActiveRecord::Base
include ContestsHelper
belongs_to :contest
belongs_to :user
#status :0 新建 1 已批准 2 拒绝
attr_accessible :role, :status, :contest_id, :user_id
has_many :applied_messages, :class_name => 'AppliedMessage', :as => :applied, :dependent => :destroy
after_create :send_appliled_message
# 仅仅给项目管理人员发送消息
def send_appliled_message
case self.role
when '13'
role = 1
when '14'
role = 2
when '15'
role = 3
else
role = 4
end
contest_managers(self.contest).each do |member|
self.applied_messages << AppliedMessage.new(:user_id => member.user_id, :status => 0, :viewed => false, :applied_user_id => self.user_id, :role => role)
end
# end
end
end

View File

@ -64,9 +64,9 @@ class Comment < ActiveRecord::Base
end
def send_mail
if self.commented.is_a?(News) && Setting.notified_events.include?('news_comment_added')
Mailer.run.news_comment_added(self)
end
# if self.commented.is_a?(News) && Setting.notified_events.include?('news_comment_added')
# Mailer.run.news_comment_added(self)
# end
end
after_destroy :delete_kindeditor_assets

View File

@ -1,136 +1,111 @@
class Contest < ActiveRecord::Base
attr_accessible :author_id, :budget, :commit, :deadline, :description, :name, :password
include Redmine::SafeAttributes
belongs_to :author, :class_name => 'User', :foreign_key => :author_id
has_many :contesting_projects, :dependent => :destroy
has_many :projects, :through => :contesting_projects
has_many :contesting_softapplications, :dependent => :destroy
has_many :softapplications, :through => :contesting_softapplications, :dependent => :destroy
has_many :projects_member, :class_name => 'User', :through => :projects
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
has_many :join_in_competitions, foreign_key: 'competition_id', :dependent => :destroy
has_many :join_in_contests, class_name: 'JoinInCompetition', foreign_key: 'competition_id', :dependent => :destroy
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
has_one :praise_tread_cache, as: :object, dependent: :destroy
has_many :contestnotifications, :dependent => :destroy, :include => :author
acts_as_attachable
NAME_LENGTH_LIMIT = 60
DESCRIPTION_LENGTH_LIMIT = 250
validates :name, length: {maximum: NAME_LENGTH_LIMIT}, presence: true
validates :description, length: {maximum: DESCRIPTION_LENGTH_LIMIT}
validates :author_id, presence: true
validates :budget, presence: true
validates :deadline, format: {:with =>/^[1-9][0-9]{3}\-0?[1-9]|1[12]\-0?[1-9]|[12]\d|3[01]$/}
validate :validate_user
after_create :act_as_activity
scope :visible, lambda {|*args|
nil
}
scope :like, lambda {|arg|
if arg.blank?
where(nil)
else
pattern = "%#{arg.to_s.strip.downcase}%"
where("LOWER(id) LIKE :p OR LOWER(name) LIKE :p OR LOWER(description) LIKE :p", :p => pattern)
end
}
acts_as_watchable
acts_as_taggable
acts_as_event :title => Proc.new {|o| "#{l(:label_requirement)} ##{o.id}: #{o.name}" },
:description => :description,
:author => :author,
:url => Proc.new {|o| {:controller => 'contests', :action => 'show_contest', :id => o.id}}
acts_as_activity_provider :find_options => {:include => [:projects, :author]},
:author_key => :author_id
safe_attributes 'name',
'description',
'budget',
'deadline',
'password'
def add_jour(user, notes, reference_user_id = 0, options = {})
if options.count == 0
self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id)
else
jfm = self.journals_for_messages.build(options)
jfm.save
jfm
end
end
# modified by longjun
# 这个函数没有用到
# def self.creat_contests(budget, deadline, name, description=nil)
# self.create(:author_id => User.current.id, :budget => budget,
# :deadline => deadline, :name => name, :description => description, :commit => 0)
# end
# end longjun
def update_contests(budget, deadline, name, description=nil)
if(User.current.id == self.author_id)
self.name = name
self.budget = budget
self.deadline = deadline
self.description = description
self.save
end
end
def delete_contests
unless self.nil?
if User.current.id == self.author_id
self.destroy
end
end
end
# Closes open and locked project versions that are completed
def close_completed_versions_contest
Version.transaction do
versions.where(:status => %w(open locked)).all.each do |version|
if version.completed?
version.update_attribute(:status, 'closed')
end
end
end
end
def set_commit(commit)
self.update_attribute(:commit, commit)
end
private
def validate_user
errors.add :author_id, :invalid if author.nil? || !author.active?
end
def act_as_activity
self.acts << Activity.new(:user_id => self.author_id)
end
def validate_contest_manager(user_id)
unless user_id.nil?
if self.author_id == user_id
return true
else
return false
end
end
end
end
class Contest < ActiveRecord::Base
attr_accessible :description, :invite_code, :invite_code_halt, :is_delete, :is_public, :name, :user_id, :visits
include ContestsHelper
belongs_to :user
has_many :contest_members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}"
has_many :memberships, :class_name => 'ContestMember'
has_many :member_principals, :class_name => 'ContestMember',
:include => :principal,
:conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE})"
has_many :principals, :through => :member_principals, :source => :principal
has_many :users, :through => :members
has_many :contestants, :class_name => 'ContestantForContest', :source => :user
has_many :works
has_many :news, :dependent => :destroy, :include => :author
has_many :contest_acts, :class_name => 'ContestActivity',:as =>:contest_act ,:dependent => :destroy
has_many :contest_activities
has_many :contest_messages, :class_name =>'ContestMessage', :as => :contest_message, :dependent => :destroy
acts_as_attachable
validates_format_of :name,:with =>/^[^ ]+[a-zA-Z0-9_\u4e00-\u9fa5\s\S]*$/
before_destroy :delete_all_members
#after_create :act_as_contest_activity
scope :visible, lambda {|*args| where(Contest.where("is_delete =?", 0).visible_condition(args.shift || User.current, *args)) }
# 删除竞赛所有成员
def delete_all_members
if self.contest_members && self.contest_members.count > 0
me, mr = ContestMember.table_name, ContestMemberRole.table_name
connection.delete("DELETE FROM #{mr} WHERE #{mr}.contest_member_id IN (SELECT #{me}.id FROM #{me} WHERE #{me}.contest_id = #{id})")
ContestMember.delete_all(['contest_id = ?', id])
end
end
def self.visible_condition(user, options={})
allowed_to_condition(user, :view_course, options)
end
def self.allowed_to_condition(user, permission, options={})
perm = Redmine::AccessControl.permission(permission)
base_statement = ("#{Contest.table_name}.is_delete <> 1")
if perm && perm.contest_module
base_statement << " AND #{Contest.table_name}.id IN (SELECT em.contest_id FROM #{EnabledModule.table_name} em WHERE em.name='#{perm.contest_module}')"
end
if options[:contest]
contest_statement = "#{Contest.table_name}.id = #{options[:contest].id}"
contest_statement << " OR (#{Contest.table_name}.lft > #{options[:contest].lft} AND #{Contest.table_name}.rgt < #{options[:contest].rgt})" if options[:with_subcontests]
base_statement = "(#{contest_statement}) AND (#{base_statement})"
end
if user.admin?
base_statement
else
statement_by_role = {}
unless options[:contest_member]
role = user.logged? ? Role.non_member : Role.anonymous
if role.allowed_to?(permission)
statement_by_role[role] = "#{Contest.table_name}.is_public = #{connection.quoted_true}"
end
end
if user.logged?
user.contests_by_role.each do |role, contests|
if role.allowed_to?(permission) && contests.any?
statement_by_role[role] = "#{Contest.table_name}.id IN (#{contests.collect(&:id).join(',')})"
end
end
end
if statement_by_role.empty?
"1=0"
else
if block_given?
statement_by_role.each do |role, statement|
if s = yield(role, user)
statement_by_role[role] = "(#{statement} AND (#{s}))"
end
end
end
"((#{base_statement}) AND (#{statement_by_role.values.join(' OR ')}))"
end
end
end
# 竞赛动态公共表记录
def act_as_contest_activity
self.contest_acts << ContestActivity.new(:user_id => self.user_id,:contest_id => self.id)
end
# 延迟生成邀请码
def invite_code
return generate_invite_code
end
# 生成邀请码
# 如果已有改邀请码,则重新生成
CODES = %W(2 3 4 5 6 7 8 9 A B C D E F G H J K L N M O P Q R S T U V W X Y Z)
def generate_invite_code
code = read_attribute(:invite_code)
if !code || code.size < 4
code = CODES.sample(4).join
return generate_invite_code if Project.where(invite_code: code).present?
update_attribute(:invite_code, code)
end
code
end
end

View File

@ -0,0 +1,37 @@
class ContestActivity < ActiveRecord::Base
attr_accessible :contest_act_id, :contest_act_type, :user_id, :contest_id
belongs_to :user
belongs_to :contest
belongs_to :contest_act ,:polymorphic => true
has_many :user_acts, :class_name => 'UserAcivity',:as =>:act
after_create :add_user_activity
before_destroy :destroy_user_activity
#在个人动态里面增加当前动态
def add_user_activity
user_activity = UserActivity.where("act_type = '#{self.contest_act_type.to_s}' and act_id = '#{self.contest_act_id}'").first
if user_activity
user_activity.save
else
if self.contest_act_type == 'Message' && !self.contest_act.parent_id.nil?
user_activity = UserActivity.where("act_type = 'Message' and act_id = #{self.contest_act.parent.id}").first
user_activity.created_at = self.created_at
user_activity.save
else
user_activity = UserActivity.new
user_activity.act_id = self.contest_act_id
user_activity.act_type = self.contest_act_type
user_activity.container_type = "Contest"
user_activity.container_id = self.contest_id
user_activity.user_id = self.user_id
user_activity.save
end
end
end
def destroy_user_activity
user_activity = UserActivity.where("act_type = '#{self.contest_act_type.to_s}' and act_id = '#{self.contest_act_id}'")
user_activity.destroy_all
end
end

View File

@ -0,0 +1,59 @@
class ContestMember < ActiveRecord::Base
attr_accessible :is_collect, :user_id, :contest_id
belongs_to :user
belongs_to :contest
belongs_to :principal, :foreign_key => 'user_id'
has_many :contest_member_roles, :dependent => :destroy
has_many :roles, :through => :contest_member_roles
validates_presence_of :principal
validates_uniqueness_of :user_id, :scope => [:contest_id]
#validate :validate_role
def deletable?
user != contest.user
end
def role
end
def role=
end
def name
self.user.name
end
# alias :base_role_ids= :role_ids=
# def role_ids=(arg)
# ids = (arg || []).collect(&:to_i) - [0]
#
# new_role_ids = ids - role_ids
# if (new_role_ids.include?(14) || new_role_ids.include?(13)) && role_ids.include?(15)
# contest_member_roles.where("role_id = 15").first.update_column('is_current', 0)
# end
# # Add new roles
# if new_role_ids.include?(14) && new_role_ids.include?(13)
# contest_member_roles << ContestMemberRole.new(:role_id => 14)
# contest_member_roles << ContestMemberRole.new(:role_id => 15, :is_current => 0)
# elsif new_role_ids.include?(13) && new_role_ids.include?(15)
# contest_member_roles << ContestMemberRole.new(:role_id => 13)
# contest_member_roles << ContestMemberRole.new(:role_id => 15, :is_current => 0)
# else
# new_role_ids.each {|id| contest_member_roles << ContestMemberRole.new(:role_id => id) }
# end
# # Remove roles (Rails' #role_ids= will not trigger MemberRole#on_destroy)
# member_roles_to_destroy = contest_member_roles.select {|mr| !ids.include?(mr.role_id)}
# if member_roles_to_destroy.any?
# member_roles_to_destroy.each(&:destroy)
# end
# end
protected
def validate_role
errors.add_on_empty :role if contest_member_roles.empty? && roles.empty?
end
end

View File

@ -0,0 +1,23 @@
class ContestMemberRole < ActiveRecord::Base
attr_accessible :role_id, :contest_member_id, :is_current
belongs_to :contest_member
belongs_to :role
#after_destroy :remove_member_if_empty
validates_presence_of :role
#validate :validate_role_member
def validate_role_member
errors.add :role_id, :invalid if role && !role.member?
end
private
def remove_member_if_empty
if contest_member.roles.empty?
contest_member.destroy
end
end
end

View File

@ -0,0 +1,20 @@
class ContestMessage < ActiveRecord::Base
attr_accessible :content, :contest_message_id, :contest_message_type, :status, :viewed, :user_id, :contest_id
belongs_to :contest_message ,:polymorphic => true
belongs_to :user
belongs_to :contest
has_many :message_alls, :class_name => 'MessageAll',:as =>:message, :dependent => :destroy
validates :user_id, presence: true
validates :contest_id, presence: true
validates :contest_message_id, presence: true
validates :contest_message_type, presence: true
after_create :add_user_message
def add_user_message
if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil? && self.status != 9
self.message_alls << MessageAll.new(:user_id => self.user_id)
end
end
end

View File

@ -1,6 +0,0 @@
class ContestNotification < ActiveRecord::Base
attr_accessible :content, :title
validates :title, length: {maximum: 30}
end

View File

@ -0,0 +1,8 @@
class ContestantForContest < ActiveRecord::Base
belongs_to :contest
attr_accessible :student_id, :contest_id
belongs_to :contestants, :class_name => 'User', :foreign_key => :student_id
validates_presence_of :contest_id, :student_id
validates_uniqueness_of :student_id, :scope => :contest_id
end

View File

@ -0,0 +1,23 @@
class ContestantWork < ActiveRecord::Base
belongs_to :work
belongs_to :user
belongs_to :project
attr_accessible :commit_time, :description, :is_delete, :name, :work_score, :work_status, :work_id, :user_id, :project_id
has_many :contestant_work_projects, :dependent => :destroy
has_many :contestant_work_scores, :dependent => :destroy
has_many :contest_messages, :class_name =>'ContestMessage', :as => :contest_message, :dependent => :destroy
has_many :attachments, :dependent => :destroy
scope :has_committed, lambda{where("work_status != 0 and work_status != 3")}
scope :no_copy, lambda{where("work_status != 3")}
after_create :act_as_message
acts_as_attachable
def act_as_message
if self.work_status != 0 && self.created_at > self.work.end_time + 1
self.contest_messages << ContestMessage.new(:user_id => self.user_id, :contest_id => self.work.contest_id, :viewed => false, :status => false)
end
end
end

View File

@ -0,0 +1,8 @@
class ContestantWorkProject < ActiveRecord::Base
belongs_to :contest
belongs_to :work
belongs_to :contestant_work
belongs_to :project
belongs_to :user
attr_accessible :is_leader, :contest_id, :work_id, :contestant_work_id, :project_id, :user_id
end

View File

@ -0,0 +1,5 @@
class ContestantWorkScore < ActiveRecord::Base
belongs_to :contestant_work
belongs_to :user
attr_accessible :comment, :reviewer_role, :score, :contestant_work_id, :user_id
end

View File

@ -1,53 +0,0 @@
class ContestingProject < ActiveRecord::Base
attr_accessible :contest_id, :description, :project_id, :user_id, :reward
belongs_to :contest
belongs_to :project
belongs_to :user
DESCRIPTION_LENGTH_LIMIT = 500
validates :description, length: {maximum:DESCRIPTION_LENGTH_LIMIT }
validates :user_id, presence: true
validates :contest_id, presence: true, uniqueness: {scope: :project_id}
validates :project_id, presence: true
validate :validate_user
validate :validate_contest
validate :validate_project
def self.create_contesting(contest_id, project_id, description = nil)
self.create(:user_id => User.current.id, :contest_id => contest_id,
:project_id => project_id, :description => description)
end
def update_reward(which)
self.update_attribute(:reward,which)
end
def get_reward
self.reward
end
def cancel_contesting
unless self.nil?
if User.current.id == self.user_id
self.destroy
end
end
end
private
def validate_user
errors.add :user_id, :invalid if user.nil? || !user.active?
end
def validate_contest
errors.add :contest_id, :invalid if contest.nil?
end
def validate_project
errors.add :project_id, :invalid if project.nil?
end
end

View File

@ -1,28 +0,0 @@
class ContestingSoftapplication < ActiveRecord::Base
attr_accessible :contest_id, :description, :softapplication_id, :user_id
belongs_to :contest
belongs_to :softapplication, :dependent => :destroy
belongs_to :user
def self.create_softapplication_contesting(contest_id, softapplication_id, description = nil)
self.create(:user_id => User.current.id, :contest_id => contest_id,
:softapplication_id => softapplication_id, :description => description)
end
def self.create_work_contesting(contest_id, softapplication_id)
self.create(:user_id => User.current.id, :contest_id => contest_id,
:softapplication_id => softapplication_id)
end
def update_reward(which)
self.update_attribute(:reward,which)
end
def get_reward
self.reward
end
end

View File

@ -1,59 +0,0 @@
class Contestnotification < ActiveRecord::Base
#attr_accessible :author_id, :notificationcomments_count, :contest_id, :description, :summary, :title
include Redmine::SafeAttributes
#Contestnotification::Notificationcomment
belongs_to :contest
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
has_many :notificationcomments, as: :notificationcommented, :dependent => :delete_all, :order => "created_at"
# fq
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
validates :title, length: {maximum: 60}, presence: true
validates :description, presence: true
validates :summary, length: {maximum: 255}
acts_as_attachable :delete_permission => :manage_contestnotifications
acts_as_searchable :columns => ['title', 'summary', "#{table_name}.description"], :include => :contest
acts_as_event :url => Proc.new {|o| {:controller => 'contestnotifications', :action => 'show', :id => o.id}}
acts_as_activity_provider :find_options => {:include => [:contest, :author]},
:author_key => :author_id
acts_as_watchable
after_create :add_author_as_watcher
after_create :act_as_activity
scope :visible, lambda {|*args|
nil
#includes(:contest).where(Contest.allowed_to_condition(args.shift || User.current, :view_contestnotifications, *args))
}
safe_attributes 'title', 'summary', 'description'
def visible?(user=User.current)
!user.nil? && user.allowed_to?(:view_contestnotifications, contest)
end
# Returns true if the news can be commented by user
def notificationcommentable?(user=User.current)
user.allowed_to?(:notificationcomment_contestnotifications, contest)
end
def recipients
#contest.users.select {|user| user.notify_about?(self)}.map(&:mail)
end
# returns latest news for contests visible by user
def self.latest(user = User.current, count = 5)
visible(user).includes([:author, :contest]).order("#{Contestnotification.table_name}.created_at DESC").limit(count).all
end
private
def add_author_as_watcher
#Watcher.create(:watchable => self, :user => author)
end
## fq
def act_as_activity
self.acts << Activity.new(:user_id => self.author_id)
end
end

View File

@ -24,7 +24,7 @@ class Document < ActiveRecord::Base
after_save :be_user_score # user_score
after_destroy :down_user_score
acts_as_attachable :delete_permission => :delete_documents
after_create :send_mail
# after_create :send_mail
# 被ForgeActivity虚拟关联
has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy
# end
@ -89,7 +89,7 @@ class Document < ActiveRecord::Base
end
def send_mail
Mailer.run.document_added(self) if Setting.notified_events.include?('document_added')
# Mailer.run.document_added(self) if Setting.notified_events.include?('document_added')
end
end

View File

@ -31,7 +31,7 @@ class HomeworkCommon < ActiveRecord::Base
:description => :description,
:author => :author,
:url => Proc.new {|o| {:controller => 'student_work', :action => 'index', :homework => o.id}}
after_create :act_as_activity, :send_mail,:act_as_course_message
after_create :act_as_activity, :act_as_course_message
after_update :update_activity
after_save :act_as_course_activity
after_destroy :delete_kindeditor_assets
@ -129,9 +129,9 @@ class HomeworkCommon < ActiveRecord::Base
end
def send_mail
if self.homework_detail_manual.comment_status != 0
Mailer.run.homework_added(self)
end
# if self.homework_detail_manual.comment_status != 0
# Mailer.run.homework_added(self)
# end
end
def is_program_homework?

View File

@ -19,10 +19,10 @@ class IssueObserver < ActiveRecord::Observer
def after_create(issue)
# 将跟踪者与本项目的其他成员都设为收件方,并去重,不在进行抄送,
recipients = issue.recipients - issue.watcher_recipients + issue.watcher_recipients
recipients.each do |rec|
Mailer.run.issue_add(issue,rec) if Setting.notified_events.include?('issue_added')
end
# recipients = issue.recipients - issue.watcher_recipients + issue.watcher_recipients
# recipients.each do |rec|
# Mailer.run.issue_add(issue,rec) if Setting.notified_events.include?('issue_added')
# end
end
end

View File

@ -2,36 +2,36 @@ class IssueOverdue < ActiveRecord::Base
#缺陷到期后发送邮件提示
#只监听已经提交的未到期的缺陷,已过期的缺陷默认已经发过邮件通知,不再提醒。
def self.mail_issue
threads = []
issues = Issue.where("done_ratio <> 100 and closed_on is null and due_date is not null")
puts issues
issues.each do |issue|
thread = Thread.new do
while true
cur_issue = Issue.find issue.id
if cur_issue.done_ratio == 100 || cur_issue.closed_on != nil
break
end
if Time.now < Time.parse(cur_issue.due_date.to_s)
#休眠一个小时。。。
puts cur_issue.id.to_s
sleep 5
else
#发邮件
#puts "11" + issue.id.to_s
#Mailer.issue_expire(issue).deliver
recipients = issue.recipients
recipients.each do |rec|
Mailer.issue_edit(issue,rec).deliver
end
break
end
end
end
threads << thread
end
puts threads
return threads
# threads = []
# issues = Issue.where("done_ratio <> 100 and closed_on is null and due_date is not null")
# puts issues
# issues.each do |issue|
# thread = Thread.new do
# while true
# cur_issue = Issue.find issue.id
# if cur_issue.done_ratio == 100 || cur_issue.closed_on != nil
# break
# end
# if Time.now < Time.parse(cur_issue.due_date.to_s)
# #休眠一个小时。。。
# puts cur_issue.id.to_s
# sleep 5
# else
# #发邮件
# #puts "11" + issue.id.to_s
# #Mailer.issue_expire(issue).deliver
# recipients = issue.recipients
# recipients.each do |rec|
#
# Mailer.issue_edit(issue,rec).deliver
# end
# break
# end
# end
# end
# threads << thread
# end
# puts threads
# return threads
end
end

View File

@ -17,18 +17,18 @@
class JournalObserver < ActiveRecord::Observer
def after_create(journal)
if journal.notify? &&
(Setting.notified_events.include?('issue_updated') ||
(Setting.notified_events.include?('issue_note_added') && journal.notes.present?) ||
(Setting.notified_events.include?('issue_status_updated') && journal.new_status.present?) ||
(Setting.notified_events.include?('issue_priority_updated') && journal.new_value_for('priority_id').present?)
)
# 将跟踪者与本项目的其他成员都设为收件方,并去重,不在进行抄送,
recipients = journal.recipients - journal.watcher_recipients + journal.watcher_recipients
recipients.each do |rec|
Mailer.run.issue_edit(journal,rec)
end
end
# if journal.notify? &&
# (Setting.notified_events.include?('issue_updated') ||
# (Setting.notified_events.include?('issue_note_added') && journal.notes.present?) ||
# (Setting.notified_events.include?('issue_status_updated') && journal.new_status.present?) ||
# (Setting.notified_events.include?('issue_priority_updated') && journal.new_value_for('priority_id').present?)
# )
# # 将跟踪者与本项目的其他成员都设为收件方,并去重,不在进行抄送,
# recipients = journal.recipients - journal.watcher_recipients + journal.watcher_recipients
# recipients.each do |rec|
#
# Mailer.run.issue_edit(journal,rec)
# end
# end
end
end

View File

@ -64,8 +64,11 @@ class JournalsForMessage < ActiveRecord::Base
has_many :principal_acts, :class_name => 'PrincipalActivity',:as =>:principal_act ,:dependent => :destroy
# 课程动态
has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy
# 竞赛动态
has_many :contest_acts, :class_name => 'ContestActivity',:as =>:contest_act ,:dependent => :destroy
# 消息关联
has_many :course_messages, :class_name => 'CourseMessage',:as =>:course_message ,:dependent => :destroy
has_many :contest_messages, :class_name =>'ContestMessage', :as => :contest_message, :dependent => :destroy
has_many :user_feedback_messages, :class_name => 'UserFeedbackMessage', :as =>:journals_for_message, :dependent => :destroy
has_many :at_messages, as: :at_message, dependent: :destroy

View File

@ -34,13 +34,13 @@ class Mailer < ActionMailer::Base
@target = cls
end
def method_missing(name, *args, &block)
if Setting.delayjob_enabled? && Object.const_defined?('Delayed')
# with delayed_job
@target.delay.send(name, *args, &block)
else
# if Setting.delayjob_enabled? && Object.const_defined?('Delayed')
# # with delayed_job
# @target.delay.send(name, *args, &block)
# else
# without delayed_job
@target.send(name, *args, &block).deliver
end
# end
end
end
@ -50,59 +50,59 @@ class Mailer < ActionMailer::Base
# 作业匿评开启
def send_mail_anonymous_comment_open(homework_common)
course = homework_common.course
recipients ||= []
course.members.each do |member|
user = User.find(member.user_id)
@subject = "#{l(:mail_homework)}#{homework_common.name} #{l(:mail_anonymous_comment_open)}"
@token = Token.get_token_from_user(user, 'autologin')
@anonymous_comment_close_url = url_for(student_work_index_url(:homework => homework_common.id, :token => @token.value))
@anonymous_comment_close_name = homework_common.name
@author = homework_common.user
#收件人邮箱
recipients << user.mail
end
mail :to => recipients,
:subject => @subject
# course = homework_common.course
# recipients ||= []
# course.members.each do |member|
# user = User.find(member.user_id)
# @subject = "#{l(:mail_homework)}#{homework_common.name} #{l(:mail_anonymous_comment_open)}"
# @token = Token.get_token_from_user(user, 'autologin')
# @anonymous_comment_close_url = url_for(student_work_index_url(:homework => homework_common.id, :token => @token.value))
# @anonymous_comment_close_name = homework_common.name
# @author = homework_common.user
# #收件人邮箱
# recipients << user.mail
# end
# mail :to => recipients,
# :subject => @subject
end
# 作业匿评关闭
def send_mail_anonymous_comment_close(homework_common)
course = homework_common.course
recipients ||= []
course.members.each do |member|
user = User.find(member.user_id)
@subject = "#{l(:mail_homework)}#{homework_common.name} #{l(:mail_anonymous_comment_close)}"
@token = Token.get_token_from_user(user, 'autologin')
@anonymous_comment_close_url = url_for(student_work_index_url(:homework => homework_common.id, :token => @token.value))
@anonymous_comment_close_name = homework_common.name
@author = homework_common.user
#收件人邮箱
recipients << user.mail
end
mail :to => recipients,
:subject => @subject
# course = homework_common.course
# recipients ||= []
# course.members.each do |member|
# user = User.find(member.user_id)
# @subject = "#{l(:mail_homework)}#{homework_common.name} #{l(:mail_anonymous_comment_close)}"
# @token = Token.get_token_from_user(user, 'autologin')
# @anonymous_comment_close_url = url_for(student_work_index_url(:homework => homework_common.id, :token => @token.value))
# @anonymous_comment_close_name = homework_common.name
# @author = homework_common.user
# #收件人邮箱
# recipients << user.mail
# end
# mail :to => recipients,
# :subject => @subject
end
# 匿评失败给老师发送邮件通知
def send_mail_anonymous_comment_fail(homework_common)
course = homework_common.course
recipients ||= []
# 只给该课程的老师发送邮件提醒
course.members.each do |member|
if member.user.allowed_to?(:as_teacher,course)
user = User.find(member.user_id)
@subject = "[#{l(:mail_homework)} #{homework_common.name}] #{l(:mail_anonymous_comment_failed)}"
@token = Token.get_token_from_user(user, 'autologin')
@anonymous_comment_fail_url = url_for(student_work_index_url(:homework => homework_common.id, :token => @token.value))
@anonymous_comment_fail_name = homework_common.name
@author = homework_common.user
#收件人邮箱
recipients << user.mail
end
end
mail :to => recipients,
:subject => @subject
# course = homework_common.course
# recipients ||= []
# # 只给该课程的老师发送邮件提醒
# course.members.each do |member|
# if member.user.allowed_to?(:as_teacher,course)
# user = User.find(member.user_id)
# @subject = "[#{l(:mail_homework)} #{homework_common.name}] #{l(:mail_anonymous_comment_failed)}"
# @token = Token.get_token_from_user(user, 'autologin')
# @anonymous_comment_fail_url = url_for(student_work_index_url(:homework => homework_common.id, :token => @token.value))
# @anonymous_comment_fail_name = homework_common.name
# @author = homework_common.user
# #收件人邮箱
# recipients << user.mail
# end
# end
# mail :to => recipients,
# :subject => @subject
end
# author: alan
@ -146,149 +146,149 @@ class Mailer < ActionMailer::Base
end
# 邀请信息消息 注forge_message_id 为邀请人ID(特殊情况)
def send_message_request_member(user, project)
key = newpass(6).to_s
ForgeMessage.create(:user_id => user.id, :project_id => project.id, :forge_message_type => "ProjectInvite",:forge_message_id => User.current.id, :viewed => false, :secret_key =>key)
end
# def send_message_request_member(user, project)
# key = newpass(6).to_s
# ForgeMessage.create(:user_id => user.id, :project_id => project.id, :forge_message_type => "ProjectInvite",:forge_message_id => User.current.id, :viewed => false, :secret_key =>key)
# end
# author: alan
# 根据用户选择发送个人日报或周报
# 发送内容: 项目【缺陷,讨论区,新闻】,课程【通知,留言,新闻】, 贴吧, 个人留言
def send_for_user_activities(user, date_to, days)
date_from = date_to - days.days
date_from = "#{date_from} 17:59:59"
date_to = "#{date_to} 17:59:59"
# 生成token用于直接点击登录
@user = user
@token = Token.get_token_from_user(user, 'autologin')
# 查询user参加的项目及课程
projects = user.projects
courses = user.courses
project_ids = projects.map{|project| project.id}.join(",")
course_ids = courses.map {|course| course.id}.join(",")
# 查询user的缺陷项目中成员都能收到
sql = "select DISTINCT * from members m, issues i where i.project_id = m.project_id and m.user_id='#{user.id}'
and (i.updated_on between '#{date_from}' and '#{date_to}') order by i.project_id, i.updated_on desc"
@issues = Issue.find_by_sql(sql)
# issue回复
@issues_journals = Journal.find_by_sql("select j.* from journals j, members m, projects p, issues i
where m.user_id = '#{user.id}' and p.id = m.project_id and i.project_id = p.id and j.journalized_id = i.id
and j.journalized_type='Issue' and (j.created_on between '#{date_from}' and '#{date_to}') order by i.project_id, created_on desc")
# @bids 查询课程作业包括老师发布的作业以及user提交作业
# @attachments查询课程课件更新
@attachments ||= []
@bids ||= [] # 老师发布的作业
unless courses.first.nil?
count = courses.count
count = count - 1
for i in 0..count do
bids = courses[i].homework_commons.where("homework_commons.created_at between '#{date_from}' and '#{date_to}'").order("homework_commons.created_at desc")
attachments = courses[i].attachments.where("attachments.created_on between '#{date_from}' and '#{date_to}'")
@bids += bids if bids.count > 0
@attachments += attachments if attachments.count > 0
end
# @bids = @bids.sort_by { |obj| obj.created_at }
end
# 项目附件
@project_attachments = Attachment.find_by_sql("select DISTINCT a.* from members m, attachments a
where a.container_id = m.project_id and m.user_id='#{user.id}' and container_type = 'Project' and (a.created_on between '#{date_from}' and '#{date_to}') order by m.project_id, a.created_on desc")
# user 提交的作业
# @homeworks = HomeworkAttach.where("user_id=#{user.id} and (created_at between '#{date_from}' and '#{date_to}')").order("created_at desc")
# 查询user所在项目添加wiki
@wiki_contents = WikiContent.find_by_sql("select DISTINCT wc.* from wikis w, members m, projects p, wiki_pages wp, wiki_contents wc where
m.user_id = '#{user.id}' and m.project_id = p.id and w.project_id = p.id and w.id = wp.wiki_id and wc.page_id = wp.id and w.project_id>0
and (wc.updated_on between '#{date_from}' and '#{date_to}') order by m.project_id, updated_on desc")
# 查询user在课程中发布的讨论帖子
course_mesages = Message.find_by_sql("select DISTINCT me.* from messages me, boards b, members m where
b.id = me.board_id and b.course_id = m.course_id
and b.course_id is not Null and m.user_id = '#{user.id}'
and (me.created_on between '#{date_from}' and '#{date_to}') order by m.course_id, created_on desc")
# 查询user在项目中发布的讨论帖子
project_messages = Message.find_by_sql("select DISTINCT me.* from messages me, boards b, members m where
b.id = me.board_id and b.project_id = m.project_id
and b.project_id != '-1' and m.user_id = '#{user.id}' and (me.created_on between '#{date_from}' and '#{date_to}') order by m.project_id, created_on desc")
# messages = Message.find_by_sql("select DISTINCT * from messages where author_id = #{user.id} and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc")
@course_messages ||= []
@project_messages ||= []
unless course_mesages.first.nil?
course_mesages.each do |msg|
@course_messages << msg
end
end
unless project_messages.first.nil?
project_messages.each do |msg|
@project_messages << msg
end
end
# wiki
# 查询user在课程中发布的通知和回复通知
@course_news = (course_ids && !course_ids.empty?) ? News.find_by_sql("select DISTINCT n.* from news n
where n.course_id in (#{course_ids})
and (created_on between '#{date_from}' and '#{date_to}') order by n.course_id, created_on desc") : []
@course_news_comments = Comment.find_by_sql("select cm.* from comments cm, members m, courses c, news n
where m.user_id = '#{user.id}' and c.id = m.course_id and n.course_id = c.id and cm.commented_id = n.id
and cm.commented_type ='News' and (cm.created_on between '#{date_from}' and '#{date_to}') order by m.course_id, created_on desc")
# 查询user在项目中添加新闻和回复新闻
@project_news = (project_ids && !project_ids.empty?) ? News.find_by_sql("select DISTINCT n.* from news n where n.project_id in (#{project_ids})
and (created_on between '#{date_from}' and '#{date_to}') order by n.project_id, created_on desc") : []
@project_news_comments = Comment.find_by_sql("select c.* from comments c, members m, projects p, news n
where m.user_id = '#{user.id}' and p.id = m.project_id and n.project_id = p.id and c.commented_id = n.id
and c.commented_type ='News' and (c.created_on between '#{date_from}' and '#{date_to}') order by m.project_id, created_on desc")
# 查询user在课程及个人中留言
@course_journal_messages = JournalsForMessage.find_by_sql("select DISTINCT jfm.* from journals_for_messages jfm, members m, courses c
where m.user_id = '#{user.id}' and c.id = m.course_id and jfm.jour_id = c.id
and jfm.jour_type='Course' and (jfm.created_on between '#{date_from}' and '#{date_to}') order by m.course_id, created_on desc")
@user_journal_messages = user.journals_for_messages.where("jour_type='Principal' and (created_on between '#{date_from}' and '#{date_to}')").order('created_on DESC')
# 查询user在项目中留言用户反馈
@project_journal_messages = JournalsForMessage.find_by_sql("select DISTINCT jfm.* from journals_for_messages jfm, members m, projects p
where m.user_id = '#{user.id}' and p.id = m.project_id and jfm.jour_id = p.id
and jfm.jour_type='Project' and (jfm.created_on between '#{date_from}' and '#{date_to}') order by m.project_id, created_on desc")
# 查询user新建贴吧或发布帖子
@forums = Forum.find_by_sql("select DISTINCT * from forums where creator_id = #{user.id} and (created_at between '#{date_from}' and '#{date_to}') order by created_at desc")
@memos = Memo.find_by_sql("select DISTINCT m.* from memos m, forums f where (m.author_id = #{user.id} or (m.forum_id = f.id and f.creator_id = #{user.id}))
and (m.created_at between '#{date_from}' and '#{date_to}') order by m.created_at desc")
has_content = [@issues,@issues_journals,@course_messages,@project_messages,@course_news,@course_news_comments,@project_news,@project_news_comments,@project_attachments,
@course_journal_messages,@user_journal_messages,@project_journal_messages,@forums,@memos,@attachments,@bids,@wiki_contents].any? {|o| !o.empty?}
total_count = @issues.count + @issues_journals.count + @course_messages.count + @project_messages.count + @course_news.count + @course_news_comments.count + @project_news.count + @project_news_comments.count +
@project_attachments.count + @course_journal_messages.count + @user_journal_messages.count + @project_journal_messages.count + @forums.count + @memos.count + @attachments.count +
@bids.count + @wiki_contents.count
subject = "[ #{user.show_name}#{l(:label_day_mail_first)}#{total_count}#{l(:label_day_mail_last)}]"
@subject = " #{user.show_name}#{l(:label_day_mail_first)}#{total_count}#{l(:label_day_mail_last)}"
mylogger.debug "Sent activity mail : #{user.mail} - #{has_content}"
#有内容才发,没有不发
mail :to => user.mail,:subject => @subject if has_content
# date_from = date_to - days.days
# date_from = "#{date_from} 17:59:59"
# date_to = "#{date_to} 17:59:59"
# # 生成token用于直接点击登录
# @user = user
# @token = Token.get_token_from_user(user, 'autologin')
#
# # 查询user参加的项目及课程
# projects = user.projects
# courses = user.courses
# project_ids = projects.map{|project| project.id}.join(",")
# course_ids = courses.map {|course| course.id}.join(",")
#
# # 查询user的缺陷项目中成员都能收到
# sql = "select DISTINCT * from members m, issues i where i.project_id = m.project_id and m.user_id='#{user.id}'
# and (i.updated_on between '#{date_from}' and '#{date_to}') order by i.project_id, i.updated_on desc"
# @issues = Issue.find_by_sql(sql)
#
# # issue回复
# @issues_journals = Journal.find_by_sql("select j.* from journals j, members m, projects p, issues i
# where m.user_id = '#{user.id}' and p.id = m.project_id and i.project_id = p.id and j.journalized_id = i.id
# and j.journalized_type='Issue' and (j.created_on between '#{date_from}' and '#{date_to}') order by i.project_id, created_on desc")
#
# # @bids 查询课程作业包括老师发布的作业以及user提交作业
# # @attachments查询课程课件更新
# @attachments ||= []
# @bids ||= [] # 老师发布的作业
# unless courses.first.nil?
# count = courses.count
# count = count - 1
# for i in 0..count do
# bids = courses[i].homework_commons.where("homework_commons.created_at between '#{date_from}' and '#{date_to}'").order("homework_commons.created_at desc")
# attachments = courses[i].attachments.where("attachments.created_on between '#{date_from}' and '#{date_to}'")
# @bids += bids if bids.count > 0
# @attachments += attachments if attachments.count > 0
# end
# # @bids = @bids.sort_by { |obj| obj.created_at }
# end
#
# # 项目附件
# @project_attachments = Attachment.find_by_sql("select DISTINCT a.* from members m, attachments a
# where a.container_id = m.project_id and m.user_id='#{user.id}' and container_type = 'Project' and (a.created_on between '#{date_from}' and '#{date_to}') order by m.project_id, a.created_on desc")
#
# # user 提交的作业
# # @homeworks = HomeworkAttach.where("user_id=#{user.id} and (created_at between '#{date_from}' and '#{date_to}')").order("created_at desc")
#
# # 查询user所在项目添加wiki
# @wiki_contents = WikiContent.find_by_sql("select DISTINCT wc.* from wikis w, members m, projects p, wiki_pages wp, wiki_contents wc where
# m.user_id = '#{user.id}' and m.project_id = p.id and w.project_id = p.id and w.id = wp.wiki_id and wc.page_id = wp.id and w.project_id>0
# and (wc.updated_on between '#{date_from}' and '#{date_to}') order by m.project_id, updated_on desc")
#
# # 查询user在课程中发布的讨论帖子
# course_mesages = Message.find_by_sql("select DISTINCT me.* from messages me, boards b, members m where
# b.id = me.board_id and b.course_id = m.course_id
# and b.course_id is not Null and m.user_id = '#{user.id}'
# and (me.created_on between '#{date_from}' and '#{date_to}') order by m.course_id, created_on desc")
#
# # 查询user在项目中发布的讨论帖子
# project_messages = Message.find_by_sql("select DISTINCT me.* from messages me, boards b, members m where
# b.id = me.board_id and b.project_id = m.project_id
# and b.project_id != '-1' and m.user_id = '#{user.id}' and (me.created_on between '#{date_from}' and '#{date_to}') order by m.project_id, created_on desc")
# # messages = Message.find_by_sql("select DISTINCT * from messages where author_id = #{user.id} and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc")
# @course_messages ||= []
# @project_messages ||= []
# unless course_mesages.first.nil?
# course_mesages.each do |msg|
# @course_messages << msg
# end
# end
# unless project_messages.first.nil?
# project_messages.each do |msg|
# @project_messages << msg
# end
# end
# # wiki
#
# # 查询user在课程中发布的通知和回复通知
# @course_news = (course_ids && !course_ids.empty?) ? News.find_by_sql("select DISTINCT n.* from news n
# where n.course_id in (#{course_ids})
# and (created_on between '#{date_from}' and '#{date_to}') order by n.course_id, created_on desc") : []
#
# @course_news_comments = Comment.find_by_sql("select cm.* from comments cm, members m, courses c, news n
# where m.user_id = '#{user.id}' and c.id = m.course_id and n.course_id = c.id and cm.commented_id = n.id
# and cm.commented_type ='News' and (cm.created_on between '#{date_from}' and '#{date_to}') order by m.course_id, created_on desc")
#
# # 查询user在项目中添加新闻和回复新闻
# @project_news = (project_ids && !project_ids.empty?) ? News.find_by_sql("select DISTINCT n.* from news n where n.project_id in (#{project_ids})
# and (created_on between '#{date_from}' and '#{date_to}') order by n.project_id, created_on desc") : []
#
# @project_news_comments = Comment.find_by_sql("select c.* from comments c, members m, projects p, news n
# where m.user_id = '#{user.id}' and p.id = m.project_id and n.project_id = p.id and c.commented_id = n.id
# and c.commented_type ='News' and (c.created_on between '#{date_from}' and '#{date_to}') order by m.project_id, created_on desc")
#
# # 查询user在课程及个人中留言
# @course_journal_messages = JournalsForMessage.find_by_sql("select DISTINCT jfm.* from journals_for_messages jfm, members m, courses c
# where m.user_id = '#{user.id}' and c.id = m.course_id and jfm.jour_id = c.id
# and jfm.jour_type='Course' and (jfm.created_on between '#{date_from}' and '#{date_to}') order by m.course_id, created_on desc")
#
# @user_journal_messages = user.journals_for_messages.where("jour_type='Principal' and (created_on between '#{date_from}' and '#{date_to}')").order('created_on DESC')
#
# # 查询user在项目中留言用户反馈
# @project_journal_messages = JournalsForMessage.find_by_sql("select DISTINCT jfm.* from journals_for_messages jfm, members m, projects p
# where m.user_id = '#{user.id}' and p.id = m.project_id and jfm.jour_id = p.id
# and jfm.jour_type='Project' and (jfm.created_on between '#{date_from}' and '#{date_to}') order by m.project_id, created_on desc")
#
# # 查询user新建贴吧或发布帖子
# @forums = Forum.find_by_sql("select DISTINCT * from forums where creator_id = #{user.id} and (created_at between '#{date_from}' and '#{date_to}') order by created_at desc")
# @memos = Memo.find_by_sql("select DISTINCT m.* from memos m, forums f where (m.author_id = #{user.id} or (m.forum_id = f.id and f.creator_id = #{user.id}))
# and (m.created_at between '#{date_from}' and '#{date_to}') order by m.created_at desc")
#
# has_content = [@issues,@issues_journals,@course_messages,@project_messages,@course_news,@course_news_comments,@project_news,@project_news_comments,@project_attachments,
# @course_journal_messages,@user_journal_messages,@project_journal_messages,@forums,@memos,@attachments,@bids,@wiki_contents].any? {|o| !o.empty?}
# total_count = @issues.count + @issues_journals.count + @course_messages.count + @project_messages.count + @course_news.count + @course_news_comments.count + @project_news.count + @project_news_comments.count +
# @project_attachments.count + @course_journal_messages.count + @user_journal_messages.count + @project_journal_messages.count + @forums.count + @memos.count + @attachments.count +
# @bids.count + @wiki_contents.count
# subject = "[ #{user.show_name}#{l(:label_day_mail_first)}#{total_count}#{l(:label_day_mail_last)}]"
# @subject = " #{user.show_name}#{l(:label_day_mail_first)}#{total_count}#{l(:label_day_mail_last)}"
# mylogger.debug "Sent activity mail : #{user.mail} - #{has_content}"
# #有内容才发,没有不发
# mail :to => user.mail,:subject => @subject if has_content
end
# 作业截止时间邮件提醒
def homework_endtime__added(homework_common, user_id)
user = User.find(user_id)
@subject = "#{l(:mail_homework)}#{homework_common.name} #{l(:mail_homework_endtime)} "
@token = Token.get_token_from_user(user, 'autologin')
@homework_endtime_url = url_for(student_work_index_url(:homework => homework_common.id, :token => @token.value))
@homework_endtime_name = homework_common.name
@author = homework_common.user
#收件人邮箱
recipient = user.mail
mail :to => recipient,
:subject => @subject
# user = User.find(user_id)
# @subject = "#{l(:mail_homework)}#{homework_common.name} #{l(:mail_homework_endtime)} "
# @token = Token.get_token_from_user(user, 'autologin')
# @homework_endtime_url = url_for(student_work_index_url(:homework => homework_common.id, :token => @token.value))
# @homework_endtime_name = homework_common.name
# @author = homework_common.user
# #收件人邮箱
# recipient = user.mail
# mail :to => recipient,
# :subject => @subject
end
# 公共讨论区发帖、回帖添加邮件发送信息
@ -382,20 +382,20 @@ class Mailer < ActionMailer::Base
# issue截止时间提醒
def issue_due_date(issue)
recipients ||= []
if issue.author.id != issue.assigned_to_id
recipients << issue.author.mail
end
# 被指派人邮箱地址加入数组
recipients << issue.assigned_to.mail
# cc = wiki_content.page.wiki.watcher_recipients - recipients
@author = issue.author
@issue_name = issue.subject
@issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id)
@subject = "#{l(:mail_issue)}#{issue.subject} #{l(:mail_issue_due_date)} "
mail :to => recipients,
:subject => @subject
# recipients ||= []
# if issue.author.id != issue.assigned_to_id
# recipients << issue.author.mail
# end
#
# # 被指派人邮箱地址加入数组
# recipients << issue.assigned_to.mail
# # cc = wiki_content.page.wiki.watcher_recipients - recipients
# @author = issue.author
# @issue_name = issue.subject
# @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id)
# @subject = "#{l(:mail_issue)}#{issue.subject} #{l(:mail_issue_due_date)} "
# mail :to => recipients,
# :subject => @subject
end
# Builds a Mail::Message object used to email recipients of the added issue.
@ -404,31 +404,31 @@ class Mailer < ActionMailer::Base
# issue_add(issue) => Mail::Message object
# Mailer.issue_add(issue).deliver => sends an email to issue recipients
def issue_add(issue, recipients)
issue_id = issue.project_index
redmine_headers 'Project' => issue.project.identifier,
'Issue-Id' => issue_id,
'Issue-Author' => issue.author.login
redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
message_id issue
@author = issue.author
@issue = issue
user = User.find_by_mail(recipients)
@user = user
# @token = Token.get_token_from_user(user, 'autologin')
@issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id)
# edit
@issue_author_url = url_for(user_activities_url(@author))
@project_url = url_for(:controller => 'projects', :action => 'show', :id => issue.project_id)
@user_url = url_for(my_account_url(user))
subject = "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] (#{issue.status.name}) #{issue.subject}"
mail :to => recipients,
:subject => subject,
:filter => true
# issue_id = issue.project_index
# redmine_headers 'Project' => issue.project.identifier,
# 'Issue-Id' => issue_id,
# 'Issue-Author' => issue.author.login
# redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
# message_id issue
#
# @author = issue.author
# @issue = issue
# user = User.find_by_mail(recipients)
# @user = user
# # @token = Token.get_token_from_user(user, 'autologin')
# @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id)
#
# # edit
# @issue_author_url = url_for(user_activities_url(@author))
# @project_url = url_for(:controller => 'projects', :action => 'show', :id => issue.project_id)
#
# @user_url = url_for(my_account_url(user))
#
#
# subject = "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] (#{issue.status.name}) #{issue.subject}"
# mail :to => recipients,
# :subject => subject,
# :filter => true
end
# issue.attachments.each do |attach|
# attachments["#{attach.filename}"] = File.read("#{attach.disk_filename}")
@ -445,36 +445,36 @@ class Mailer < ActionMailer::Base
# issue_edit(journal) => Mail::Message object
# Mailer.issue_edit(journal).deliver => sends an email to issue recipients
def issue_edit(journal,recipients)
issue = journal.journalized.reload
issue_id = issue.project_index
redmine_headers 'Project' => issue.project.identifier,
'Issue-Id' => issue_id.to_s,
'Issue-Author' => issue.author.login
redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
message_id journal
references issue
@author = journal.user
user = User.find_by_mail(recipients)
@user = user
# @token = Token.get_token_from_user(user, 'autologin')
# edit
@issue_author_url = url_for(:controller => 'users', :action => 'show', :id => issue.author_id)
@project_url = url_for(:controller => 'projects', :action => 'show', :id => issue.project_id)
@user_url = url_for(my_account_url(user))
@issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id, :anchor => "change-#{journal.id}")
s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] "
s << "(#{issue.status.name}) " if journal.new_value_for('status_id')
s << issue.subject
@issue = issue
@journal = journal
# @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue, :anchor => "change-#{journal.id}")
mail :to => recipients,
:subject => s,
:filter => true
# issue = journal.journalized.reload
# issue_id = issue.project_index
# redmine_headers 'Project' => issue.project.identifier,
# 'Issue-Id' => issue_id.to_s,
# 'Issue-Author' => issue.author.login
# redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
# message_id journal
# references issue
# @author = journal.user
#
# user = User.find_by_mail(recipients)
# @user = user
# # @token = Token.get_token_from_user(user, 'autologin')
#
#
# # edit
# @issue_author_url = url_for(:controller => 'users', :action => 'show', :id => issue.author_id)
# @project_url = url_for(:controller => 'projects', :action => 'show', :id => issue.project_id)
# @user_url = url_for(my_account_url(user))
#
# @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id, :anchor => "change-#{journal.id}")
# s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] "
# s << "(#{issue.status.name}) " if journal.new_value_for('status_id')
# s << issue.subject
# @issue = issue
# @journal = journal
# # @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue, :anchor => "change-#{journal.id}")
# mail :to => recipients,
# :subject => s,
# :filter => true
end
def self.deliver_mailer(to,cc, subject)
@ -510,19 +510,19 @@ class Mailer < ActionMailer::Base
#缺陷到期邮件通知
def issue_expire issue
issue_id = issue.project_index
redmine_headers 'Project' => issue.project.identifier,
'Issue-Id' => issue_id,
'Issue-Author' => issue.author.login
redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
message_id issue
@author = issue.author
@issue = issue
@issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id)
recipients = issue.recipients
s = l(:text_issue_expire,:issue => "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] (#{issue.status.name}) #{issue.subject}")
mail :to => recipients,
:subject => s
# issue_id = issue.project_index
# redmine_headers 'Project' => issue.project.identifier,
# 'Issue-Id' => issue_id,
# 'Issue-Author' => issue.author.login
# redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
# message_id issue
# @author = issue.author
# @issue = issue
# @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id)
# recipients = issue.recipients
# s = l(:text_issue_expire,:issue => "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] (#{issue.status.name}) #{issue.subject}")
# mail :to => recipients,
# :subject => s
#########################################################################################################
#@issues = issues
#s = l(:text_issue_expire,:issue => "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] (#{issue.status.name}) #{issue.subject}")
@ -627,19 +627,19 @@ class Mailer < ActionMailer::Base
# attachments_added(attachments) => Mail::Message object
# Mailer.attachments_added(attachments).deliver => sends an email to the project's recipients
def homework_added(homework_common)
logger.info "homework added"
@homework_common = homework_common
@author = homework_common.user
@homework_common_url = url_for(:controller => "homework_common", :action =>"index", :homework => @homework_common.id)
@homework_author_url = url_for(user_activities_url(@author))
recipients ||= []
#将帖子创建者邮箱地址加入数组
@homework_common.course.members.each do |member|
recipients << member.user.mail
end
mail :to => recipients,
:subject => "[ #{l(:label_user_homework)} : #{homework_common.name} #{l(:label_memo_create_succ)}]",
:filter => true
# logger.info "homework added"
# @homework_common = homework_common
# @author = homework_common.user
# @homework_common_url = url_for(:controller => "homework_common", :action =>"index", :homework => @homework_common.id)
# @homework_author_url = url_for(user_activities_url(@author))
# recipients ||= []
# #将帖子创建者邮箱地址加入数组
# @homework_common.course.members.each do |member|
# recipients << member.user.mail
# end
# mail :to => recipients,
# :subject => "[ #{l(:label_user_homework)} : #{homework_common.name} #{l(:label_memo_create_succ)}]",
# :filter => true
end
# Builds a Mail::Message object used to email recipients of a news' project when a news item is added.
@ -649,28 +649,28 @@ class Mailer < ActionMailer::Base
# Mailer.news_added(news).deliver => sends an email to the news' project recipients
def news_added(news)
if news.project
# redmine_headers 'Project' => news.project.identifier
# @author = news.author
# @issue_author_url = url_for(user_activities_url(@author))
# message_id news
# @news = news
# @news_url = url_for(:controller => 'news', :action => 'show', :id => news)
# mail :to => news.recipients,
# :subject => "[#{news.project.name}] #{l(:label_news)}: #{news.title}",
# :filter => true
elsif news.course
redmine_headers 'Course' => news.course.id
@author = news.author
@issue_author_url = url_for(user_activities_url(@author))
message_id news
@news = news
recipients = news.course.notified_users.select { |user| user.allowed_to?(:view_files, news.course) }.collect { |u| u.mail }
@news_url = url_for(:controller => 'news', :action => 'show', :id => news)
mail :to => recipients,
:subject => "[#{news.course.name}] #{l(:label_news)}: #{news.title}",
:filter => true
end
# if news.project
# # redmine_headers 'Project' => news.project.identifier
# # @author = news.author
# # @issue_author_url = url_for(user_activities_url(@author))
# # message_id news
# # @news = news
# # @news_url = url_for(:controller => 'news', :action => 'show', :id => news)
# # mail :to => news.recipients,
# # :subject => "[#{news.project.name}] #{l(:label_news)}: #{news.title}",
# # :filter => true
# elsif news.course
# redmine_headers 'Course' => news.course.id
# @author = news.author
# @issue_author_url = url_for(user_activities_url(@author))
# message_id news
# @news = news
# recipients = news.course.notified_users.select { |user| user.allowed_to?(:view_files, news.course) }.collect { |u| u.mail }
# @news_url = url_for(:controller => 'news', :action => 'show', :id => news)
# mail :to => recipients,
# :subject => "[#{news.course.name}] #{l(:label_news)}: #{news.title}",
# :filter => true
# end
end
# Builds a Mail::Message object used to email recipients of a news' project when a news comment is added.
@ -679,33 +679,33 @@ class Mailer < ActionMailer::Base
# news_comment_added(comment) => Mail::Message object
# Mailer.news_comment_added(comment) => sends an email to the news' project recipients
def news_comment_added(comment)
news = comment.commented
if news.project
# redmine_headers 'Project' => news.project.identifier
# @author = comment.author
# @issue_author_url = url_for(user_activities_url(@author))
# message_id comment
# @news = news
# @comment = comment
# @news_url = url_for(:controller => 'news', :action => 'show', :id => news)
# mail :to => news.recipients,
# :cc => news.watcher_recipients,
# :subject => "Re: [#{news.project.name}] #{l(:label_news)}: #{news.title}",
# :filter => true
elsif news.course
redmine_headers 'Course' => news.course.id
@author = comment.author
@issue_author_url = url_for(user_activities_url(@author))
message_id comment
@news = news
@comment = comment
@news_url = url_for(:controller => 'news', :action => 'show', :id => news)
recipients = news.course.notified_users.select { |user| user.allowed_to?(:view_files, news.course) }.collect { |u| u.mail }
mail :to => recipients,
:subject => "[#{news.course.name}] #{l(:label_news)}: #{news.title}",
:filter => true
end
# news = comment.commented
# if news.project
# # redmine_headers 'Project' => news.project.identifier
# # @author = comment.author
# # @issue_author_url = url_for(user_activities_url(@author))
# # message_id comment
# # @news = news
# # @comment = comment
# # @news_url = url_for(:controller => 'news', :action => 'show', :id => news)
# # mail :to => news.recipients,
# # :cc => news.watcher_recipients,
# # :subject => "Re: [#{news.project.name}] #{l(:label_news)}: #{news.title}",
# # :filter => true
# elsif news.course
# redmine_headers 'Course' => news.course.id
# @author = comment.author
# @issue_author_url = url_for(user_activities_url(@author))
# message_id comment
# @news = news
# @comment = comment
# @news_url = url_for(:controller => 'news', :action => 'show', :id => news)
# recipients = news.course.notified_users.select { |user| user.allowed_to?(:view_files, news.course) }.collect { |u| u.mail }
#
# mail :to => recipients,
# :subject => "[#{news.course.name}] #{l(:label_news)}: #{news.title}",
# :filter => true
# end
end
# Builds a Mail::Message object used to email the recipients of the specified message that was posted.
@ -850,7 +850,7 @@ class Mailer < ActionMailer::Base
@token = token
@url = url_for(:controller => 'account', :action => 'activate', :token => token.value)
mail :to => token.user.mail,
:subject => l(:mail_subject_register, Setting.app_title)
:subject => l(:mail_subject)
end
def test_email(user)
@ -1032,21 +1032,21 @@ class Mailer < ActionMailer::Base
end
def join_course_request(course, user, role)
@receive = User.find(course.tea_id)
@course = course
@user = user
@role = role
@subject = "#{@user.show_name} #{l(:label_apply_join_course)} #{@course.name} "
mail :to => @receive.mail,
:subject => @subject
# @receive = User.find(course.tea_id)
# @course = course
# @user = user
# @role = role
# @subject = "#{@user.show_name} #{l(:label_apply_join_course)} #{@course.name} "
# mail :to => @receive.mail,
# :subject => @subject
end
def apply_for_homework_request(homework, user)
@receive = User.find(homework.user_id)
@user = user
@subject = "#{@user.show_name} #{l(:label_apply_for_homework)} #{homework.name} "
mail :to => @receive.mail,
:subject => @subject
# @receive = User.find(homework.user_id)
# @user = user
# @subject = "#{@user.show_name} #{l(:label_apply_for_homework)} #{homework.name} "
# mail :to => @receive.mail,
# :subject => @subject
end
private

View File

@ -124,7 +124,7 @@ class Memo < ActiveRecord::Base
end
def send_mail
Mailer.run.forum_message_added(self) if Setting.notified_events.include?('forum_message_added')
# Mailer.run.forum_message_added(self) if Setting.notified_events.include?('forum_message_added')
end
def creator_user
@ -218,9 +218,9 @@ class Memo < ActiveRecord::Base
end
def send_notification
if Setting.notified_events.include?('message_posted')
Mailer.run.message_posted(self)
end
# if Setting.notified_events.include?('message_posted')
# Mailer.run.message_posted(self)
# end
end
def plusParentAndForum

View File

@ -40,11 +40,13 @@ class Message < ActiveRecord::Base
has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy
# 课程动态
has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy
# 竞赛动态
has_many :contest_acts, :class_name => 'ContestActivity',:as =>:contest_act ,:dependent => :destroy
# end
# 课程/项目 消息
has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy
has_many :forge_messages, :class_name => 'ForgeMessage', :as => :forge_message, :dependent => :destroy
has_many :contest_messages, :class_name =>'ContestMessage', :as => :contest_message, :dependent => :destroy
has_many :at_messages, as: :at_message, dependent: :destroy
has_many :ActivityNotifies,:as => :activity, :dependent => :destroy
@ -389,7 +391,7 @@ class Message < ActiveRecord::Base
end
def send_mail
Mailer.run.message_posted(self) if Setting.notified_events.include?('message_posted')
# Mailer.run.message_posted(self) if Setting.notified_events.include?('message_posted')
end
# Time 2015-03-31 09:15:06

View File

@ -25,6 +25,7 @@ class News < ActiveRecord::Base
has_many_kindeditor_assets :assets, :dependent => :destroy
#added by nwb
belongs_to :course,:touch => true
belongs_to :contest,:touch => true
belongs_to :org_subfield, :touch => true
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
has_many :comments, :as => :commented, :dependent => :destroy, :order => "created_on"
@ -34,10 +35,13 @@ class News < ActiveRecord::Base
has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy
# 课程动态
has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy
# 竞赛动态
has_many :contest_acts, :class_name => 'ContestActivity',:as =>:contest_act ,:dependent => :destroy
# end
# 课程/项目消息关联
# 课程/项目/竞赛消息关联
has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy
has_many :forge_messages, :class_name => 'ForgeMessage', :as => :forge_message, :dependent => :destroy
has_many :contest_messages, :class_name =>'ContestMessage', :as => :contest_message, :dependent => :destroy
#end
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
@ -65,7 +69,7 @@ class News < ActiveRecord::Base
:author_key => :author_id
acts_as_watchable
after_create :act_as_course_activity, :add_author_as_watcher, :send_mail, :add_news_count, :act_as_student_score,:delay_news_wechat_send, :delay_news_send
after_create :act_as_course_activity, :add_author_as_watcher, :add_news_count, :act_as_student_score,:delay_news_wechat_send, :delay_news_send
after_update :update_activity
after_destroy :delete_kindeditor_assets, :decrease_news_count, :delete_org_activities, :down_course_score
@ -76,6 +80,10 @@ class News < ActiveRecord::Base
scope :course_visible, lambda {|*args|
includes(:course).where(Course.allowed_to_condition(args.shift || User.current, :view_course_news, *args))
}
scope :contest_visible, lambda {|*args|
includes(:contest).where(Contest.allowed_to_condition(args.shift || User.current, :view_contest_news, *args))
}
safe_attributes 'title', 'summary', 'description', 'sticky'
#动态的更新
@ -157,6 +165,8 @@ class News < ActiveRecord::Base
def act_as_course_activity
if self.course
self.course_acts << CourseActivity.new(:user_id => self.author_id,:course_id => self.course_id)
elsif self.contest
self.contest_acts << ContestActivity.new(:user_id => self.author_id,:contest_id => self.contest_id)
end
end
@ -226,6 +236,23 @@ class News < ActiveRecord::Base
self.delay.contain_news_message(vs)
end
elsif self.contest_id
vs = []
self.contest.contest_members.each do | m|
if m.user_id != self.author_id
vs << {course_message_type:'Contest',course_message_id:self.id, :user_id => m.user_id,
:contest_id => self.contest_id, :viewed => false}
if vs.size >= 30
self.delay.contain_contst_news_message(vs)
vs.clear
end
end
end
unless vs.empty?
self.delay.contain_contst_news_message(vs)
end
end
end
@ -233,6 +260,10 @@ class News < ActiveRecord::Base
CourseMessage.create(vs)
end
def contain_contst_news_message(vs)
ContestMessage.create(vs)
end
# Time 2015-03-31 13:50:54
# Author lizanle
# Description 删除news后删除对应的资源
@ -241,7 +272,7 @@ class News < ActiveRecord::Base
end
def send_mail
Mailer.run.news_added(self) if Setting.notified_events.include?('news_added')
# Mailer.run.news_added(self) if Setting.notified_events.include?('news_added')
end
def delete_org_activities

View File

@ -34,6 +34,10 @@ class Principal < ActiveRecord::Base
has_many :course_groups, :through => :members
has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify
has_many :contest_members, :foreign_key => 'user_id', :dependent => :destroy
has_many :contestmemberships, :class_name => 'ContestMember', :foreign_key => 'user_id', :include => [:contest, :roles], :order => "#{Contest.table_name}.name"
has_many :contests, :through => :contestmemberships
# Groups and active users
scope :active, lambda { where(:status => STATUS_ACTIVE) }
@ -87,6 +91,16 @@ class Principal < ActiveRecord::Base
end
}
scope :not_member_of_contest, lambda {|contests|
contests = [contests] unless contests.is_a?(Array)
if contests.empty?
where("1=0")
else
ids = contests.map(&:id)
where("#{Principal.table_name}.id NOT IN (SELECT DISTINCT user_id FROM #{ContestMember.table_name} WHERE contest_id IN (?))", ids)
end
}
scope :not_member_of_org, lambda {|org|
orgs = [org] unless org.is_a?(Array)
if orgs.empty?
@ -157,6 +171,14 @@ class Principal < ActiveRecord::Base
return projects
end
#收藏的竞赛
def favorite_contests
members = ContestMember.where(:user_id => self.id, :is_collect => true)
contest_ids = members.empty? ? "(-1)" : "(" + members.map{|member| member.contest_id}.join(",") + ")"
contests = Contest.where("id in #{contest_ids}")
return contests
end
protected
# Make sure we don't try to insert NULL values (see #4632)

View File

@ -158,9 +158,9 @@ class RelativeMemo < ActiveRecord::Base
end
def send_notification
if Setting.notified_events.include?('message_posted')
Mailer.run.message_posted(self)
end
# if Setting.notified_events.include?('message_posted')
# Mailer.run.message_posted(self)
# end
end
# def plusParentAndForum

View File

@ -57,6 +57,8 @@ class Role < ActiveRecord::Base
has_many :members, :through => :member_roles
has_many :org_member_roles, :dependent => :destroy
has_many :org_members,:through => :org_member_roles
has_many :contest_member_roles, :dependent => :destroy
has_many :contest_members, :through => :contest_member_roles
acts_as_list
serialize :permissions, ::Role::PermissionsAttributeCoder

View File

@ -130,7 +130,6 @@ class User < Principal
belongs_to :ucourse, :class_name => 'Course', :foreign_key => :id #huang
## added by xianbo for delete
# has_many :biding_projects, :dependent => :destroy
has_many :contesting_projects, :dependent => :destroy
belongs_to :softapplication, :foreign_key => 'id', :dependent => :destroy
##ended by xianbo
@ -138,12 +137,12 @@ class User < Principal
has_many :jours, :class_name => 'JournalsForMessage', :dependent => :destroy
has_many :journals_messages, :class_name => 'JournalsForMessage', :foreign_key => "user_id", :dependent => :destroy
# has_many :bids, :foreign_key => 'author_id', :dependent => :destroy
has_many :contests, :foreign_key => 'author_id', :dependent => :destroy
has_many :softapplications, :foreign_key => 'user_id', :dependent => :destroy
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
has_many :journal_replies, :dependent => :destroy
has_many :activities, :dependent => :destroy
has_many :students_for_courses
has_many :contestant_for_contests
#has_many :courses, :through => :students_for_courses, :source => :project
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
has_many :principal_acts, :class_name => 'PrincipalActivity',:as =>:principal_act ,:dependent => :destroy
@ -151,11 +150,8 @@ class User < Principal
has_many :course_attachments , :class_name => 'Attachment', :foreign_key => 'author_id', :conditions => "container_type = 'Course'"
####
# added by bai
has_many :join_in_contests, :dependent => :destroy
has_many :news, :foreign_key => 'author_id'
has_many :contestnotification, :foreign_key => 'author_id'
has_many :comments, :foreign_key => 'author_id'
has_many :notificationcomments, :foreign_key => 'author_id'
has_many :wiki_contents, :foreign_key => 'author_id'
has_many :journals
has_many :messages, :foreign_key => 'author_id'
@ -501,6 +497,7 @@ class User < Principal
@name = nil
@projects_by_role = nil
@courses_by_role = nil
@contests_by_role = nil
@membership_by_project_id = nil
base_reload(*args)
end
@ -884,6 +881,11 @@ class User < Principal
courses.to_a.include?(course)
end
def member_of_contest?(contest)
contest.contest_members.where(:user_id => self.id).count > 0
#contests.to_a.include?(contest)
end
def member_of_org?(org)
if !self.logged?
return false
@ -912,6 +914,49 @@ class User < Principal
false
end
end
# 判断是否是竞赛的主办人
def admin_of_contest?(contest)
if contest.nil?
return false
end
if ContestMember.where("user_id =? and contest_id =?", self.id, contest.id).count == 0
return false
end
member_role = ContestMember.where("user_id =? and contest_id =?", self.id, contest.id)[0].contest_member_roles.where(:is_current => true)[0]
unless member_role.nil?
member_role.role.name == 'ContestManager' ? true : false
else
false
end
end
# 判断是否是竞赛的评委
def judge_of_contest?(contest)
if ContestMember.where("user_id =? and contest_id =?", self.id, contest.id).count == 0
return false
end
member_role = ContestMember.where("user_id =? and contest_id =?", self.id, contest.id)[0].contest_member_roles.where(:is_current => true)[0]
unless member_role.nil?
member_role.role.name == 'Judge' ? true : false
else
false
end
end
# 判断是否是竞赛的参赛者
def contestant_of_contest?(contest)
if ContestMember.where("user_id =? and contest_id =?", self.id, contest.id).count == 0
return false
end
member_role = ContestMember.where("user_id =? and contest_id =?", self.id, contest.id)[0].contest_member_roles.where(:is_current => true)[0]
unless member_role.nil?
member_role.role.name == 'Contestant' ? true : false
else
false
end
end
def member_of_course_group?(course_group)
course_groups.to_a.include?(course_group)
end
@ -954,6 +999,26 @@ class User < Principal
@courses_by_role
end
# 竞赛的角色权限
def contests_by_role
return @contests_by_role if @contests_by_role
@contests_by_role = Hash.new([])
contestmemberships.each do |membership|
if membership.contest
membership.roles.each do |role|
@contests_by_role[role] = [] unless @contests_by_role.key?(role)
@contests_by_role[role] << membership.contest
end
end
end
@contests_by_role.each do |role, contests|
contests.uniq!
end
@contests_by_role
end
# Returns true if user is arg or belongs to arg
def is_or_belongs_to?(arg)
if arg.is_a?(User)

View File

@ -17,12 +17,12 @@
class WikiContentObserver < ActiveRecord::Observer
def after_create(wiki_content)
Mailer.run.wiki_content_added(wiki_content) if Setting.notified_events.include?('wiki_content_added')
# Mailer.run.wiki_content_added(wiki_content) if Setting.notified_events.include?('wiki_content_added')
end
def after_update(wiki_content)
if wiki_content.text_changed?
Mailer.run.wiki_content_updated(wiki_content) if Setting.notified_events.include?('wiki_content_updated')
end
# if wiki_content.text_changed?
# Mailer.run.wiki_content_updated(wiki_content) if Setting.notified_events.include?('wiki_content_updated')
# end
end
end

71
app/models/work.rb Normal file
View File

@ -0,0 +1,71 @@
class Work < ActiveRecord::Base
belongs_to :user
belongs_to :contest
attr_accessible :description, :end_time, :is_delete, :is_open, :name, :publish_time, :score_open, :work_status, :work_type, :contest_id, :user_id
include ApplicationHelper
has_one :work_detail_group, :dependent => :destroy
has_many :contestant_work_projects, :dependent => :destroy
has_many :contestant_works, :dependent => :destroy, :conditions => "is_delete != 1"
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
has_one :praise_tread_cache, as: :object, dependent: :destroy
# 竞赛动态
has_many :contest_acts, :class_name => 'ContestActivity',:as =>:contest_act ,:dependent => :destroy
# 竞赛消息
has_many :contest_messages, :class_name =>'ContestMessage', :as => :contest_message, :dependent => :destroy
acts_as_attachable
after_create :act_as_contest_message
after_update :update_activity
after_save :act_as_contest_activity
#after_destroy :delete_kindeditor_assets
def is_group_work?
self.work_type == 3 && self.work_detail_group
end
###添加回复
def self.add_work_jour(user, notes, id, root_id, options = {})
homework = Work.find(id)
if options.count == 0
jfm = homework.journals_for_messages.build(:user_id => user.id, :notes => notes, :reply_id => 0, :root_id => root_id)
else
jfm = homework.journals_for_messages.build(options)
end
jfm.save
jfm
end
def act_as_contest_activity
if self.contest
if self.work_status == 0
self.contest_acts.destroy_all
else
if self.contest_acts.size == 0
self.contest_acts << ContestActivity.new(:user_id => self.user_id,:contest_id => self.contest_id)
end
end
end
end
#动态的更新
def update_activity
update_contest_activity(self.class, self.id)
update_user_activity(self.class, self.id)
end
def act_as_contest_message
if self.contest
if self.work_status == 0
self.contest_messages.destroy_all
else
self.contest.contest_members.each do |m|
if m.user_id != self.user_id
self.contest_messages << ContestMessage.new(:user_id => m.user_id, :contest_id => self.contest_id, :viewed => false)
end
end
end
end
end
end

View File

@ -0,0 +1,4 @@
class WorkDetailGroup < ActiveRecord::Base
belongs_to :work
attr_accessible :base_on_project, :max_num, :min_num, :work_id
end

View File

@ -0,0 +1,45 @@
#coding=utf-8
class ContestsService
include ApplicationHelper
include ContestsHelper
include ApiHelper
include ActionView::Helpers::DateHelper
#多个角色加入竞赛
def join_contest_roles params,current_user
contest = Contest.find_by_invite_code(params[:invite_code]) if params[:invite_code]
go_contestgroup_flag = 0
contest_id = 0
@state = 10
if contest
if contest[:is_delete] == 1
@state = 11
elsif contest[:invite_code_halt] == 1
@state = 14
else
if current_user.member_of_contest?(contest) #如果已经是成员
@state = 3
else
if params[:invite_code].present?
role_ids = params[:role]
role_str = role_ids.join(",").to_s
#如果已经发送过消息了,那么就要给个提示
if AppliedContest.where(:contest_id => contest.id, :user_id => current_user.id, :role => role_str, :status => 0).count != 0
@state = 7
else
AppliedContest.create(:contest_id => contest.id, :user_id => current_user.id, :role => role_str, :status => 0)
@state = 6
end
else
@state = 1
end
end
end
else
@state = 4
end
{:state => @state, :contest => contest, :go_contestgroup_flag => go_contestgroup_flag, :contest_id => contest_id}
end
end

View File

@ -658,7 +658,7 @@ class CoursesService
@state = 7
end
else
Mailer.run.join_course_request(course, current_user, params[:role])
# Mailer.run.join_course_request(course, current_user, params[:role])
CourseMessage.create(:user_id => course.tea_id, :course_id => course.id, :viewed => false,:content=> role_str,:course_message_id=>current_user.id,:course_message_type=>'JoinCourseRequest',:status=>0)
#----------------微信通知----------------------

View File

@ -232,25 +232,27 @@ class UsersService
#修改密码
def change_password params
@current_user = User.find(params[:current_user_id])
if @current_user.check_password?(params[:password])
@current_user.password, @current_user.password_confirmation = params[:new_password], params[:new_password_confirmation]
@current_user.save
# 修改密码同步gitlab密码修改
unless @current_user.gid.nil?
begin
g = Gitlab.client
g.edit_user(@current_user.gid, :password => params[:new_password])
rescue Exception => e
logger.error "change users password failed! ===> #{e}"
ActiveRecord::Base.transaction do
@current_user = User.find(params[:current_user_id])
if @current_user.check_password?(params[:password])
@current_user.password, @current_user.password_confirmation = params[:new_password], params[:new_password_confirmation]
@current_user.save
# 修改密码同步gitlab密码修改
unless @current_user.gid.nil?
begin
g = Gitlab.client
g.edit_user(@current_user.gid, :password => params[:new_password])
rescue Exception => e
logger.error "change users password failed! ===> #{e}"
end
end
end
#raise @current_user.errors.full_message
#return @current_user
else
raise l(:notice_account_wrong_password,:locale => 'zh')
else
raise l(:notice_account_wrong_password,:locale => 'zh')
end
@current_user
end
@current_user
end
#搜索用户

View File

@ -10,8 +10,28 @@
</head>
<body>
<% email = @user.mail.split("@")[1] %>
<div style="border: 1px solid #c0c0c0 ; width:850px; margin-top: 10px" >
<script>
var countdown = 60;
function settime(val) {
if (countdown == 0) {
val.removeAttribute("disabled");
$("#btn").removeClass("btn-grey");
val.value="重新获取验证码";
countdown = 60;
} else {
val.setAttribute("disabled", true);
$("#btn").addClass("btn-grey");
val.value="重新发送(" + countdown + ")";
countdown--;
if(countdown >= 0){
setTimeout(function() {
settime(val)
},1000)
}
}
}
</script>
<div style="border: 1px solid #c0c0c0 ; width:100%; margin-top: 10px" >
<h3 style=" padding-bottom: 8px; margin-top:5px; border-bottom: 1px solid #c0c0c0;color:black; ">
<span id = "jihuo" style=" margin-left: 4%;"></span><%= l(:label_email_valid)%></h3>
@ -19,21 +39,16 @@
<div style="margin-left:auto; margin-right:auto">
<center>
<div >
<h4 style="font-size: 18px;margin-top: 10px; padding-bottom: 10px;"><%= l(:notice_email_register_time)%></h4>
<div class="to-email" style="padding-bottom: 8px; font-size: 14px">
<div class="to-email" style="padding-bottom: 8px; font-size: 14px">
<h4 style="font-size: 18px;margin-top: 10px; padding-bottom: 10px;"><%= l(:notice_email_register_time) %></h4>
<div class="to-email mb10" style="padding-bottom: 8px; font-size: 14px">
<div class="to-email" style="padding-bottom:15px; font-size:14px; padding-top:10px;">
<span ><%= l(:notice_email_arrival)%></span>
<a href="#" class="f-blue"><%= @user.mail %></a>
</div>
<p>
<a href="http://mail.<%= email %>" style="background: #15bccf;margin: auto;
color: #fff;
font-size: 13px;
border: none;
padding: 10px 16px;
line-height: 1.33;" target="_blank"><%= l(:label_check_email)%></a>
&nbsp; &nbsp; <%= link_to l(:label_mail_resend), { :controller => 'account', :action => 'resendmail',:user => @user}, :remote => true, :method => 'get' %>
<a href="http://mail.<%= email %>" class="btn btn-blue" target="_blank"><%= l(:label_check_email)%></a>
&nbsp; &nbsp; <%= link_to "<input class='btn btn-blue' type='button' id='btn' value='重新获取验证码' onclick='settime(this)' />".html_safe, { :controller => 'account', :action => 'resendmail', :user => @user}, :remote => true, :method => 'get' %>
<!--<a href="<%#= resendmail_path(@user) %>" data-remote="true"><input class="btn btn-blue" type="button" id="btn" value="重新获取验证码" onclick="settime(this)" /></a>-->
</p>

View File

@ -51,7 +51,7 @@
<%= format_date(course.created_on) %>
</td>
<td style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;" title='<%=course.subject %>'>
<%= link_to(course.subject, course_boards_path(Board.where('id=?',course.board_id).first.course_id)) %>
<%= link_to(course.subject, board_message_path(course.board_id, course), :target => "_blank") %>
</td>
<td class="center">
<%= link_to(course.replies_count, course_boards_path(Board.where('id=?',course.board_id).first.course_id)) %>

View File

@ -3,7 +3,7 @@
</h3>
<%= render 'tab_messages' %>
<h4><%=l(:label_forum) %></h4>
<h4><%= l(:label_forum) %></h4>
<div class="autoscroll">
<table class="list" style="width: 100%;table-layout: fixed">
<thead>
@ -53,7 +53,7 @@
<% if memo.parent_id.nil? || memo.subject.starts_with?('RE:')%>
<%= link_to(memo.subject, forum_memo_path(memo.forum, memo)) %>
<% else %>
<%= link_to("RE:"+memo.subject, forum_memo_path(memo.forum, memo)) %>
<%= link_to("RE:"+memo.subject, forum_memo_path(memo.forum, memo), :target => "_blank") %>
<% end %>
</td>
<td class="center">

View File

@ -51,7 +51,7 @@
<%= format_date(project.created_on) %>
</td>
<td title='<%=project.subject %>' style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;" class="name">
<%= link_to(project.subject, project_boards_path(Board.where('id=?',project.board_id).first.project_id)) %>
<%= link_to(project.subject, board_message_path(project.board_id, project), :target => "_blank") %>
</td>
<td class="center">
<%= link_to(project.replies_count, project_boards_path(Board.where('id=?',project.board_id).first.project_id)) %>

View File

@ -2,6 +2,8 @@
$("#activity_post_reply_<%= @user_activity_id%>").html("<%= escape_javascript(render :partial => 'users/course_news_post_reply', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>");
<% elsif @project %>
$("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'projects/project_news', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>");
<% elsif @contest %>
$("#activity_post_reply_<%= @user_activity_id %>").html("<%= escape_javascript(render :partial => 'users/course_news_post_reply', :locals => {:activity => @news,:user_activity_id => @user_activity_id}) %>");
<% else %>
$("#activity_post_reply_<%= @user_activity_id%>").html("<%= escape_javascript(render :partial => 'organizations/course_news_post_reply', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>");
<% end %>

View File

@ -3,6 +3,8 @@
$("#user_activity_<%= @user_activity_id %>").replaceWith("<%= escape_javascript(render :partial => 'projects/project_news', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>");
<% elsif @news.course_id %>
$("#activity_post_reply_<%= @user_activity_id %>").html("<%= escape_javascript(render :partial => 'users/course_news_post_reply', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>");
<% elsif @news.contest_id %>
$("#activity_post_reply_<%= @user_activity_id %>").html("<%= escape_javascript(render :partial => 'users/course_news_post_reply', :locals => {:activity => @news,:user_activity_id => @user_activity_id}) %>");
<% elsif @news.org_subfield_id %>
$("#user_activity_<%= @user_activity_id %>").replaceWith("<%= escape_javascript(render :partial => 'organizations/org_subfield_news', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>");
<% end %>

View File

@ -3,6 +3,8 @@
$("#user_activity_<%= @user_activity_id %>").replaceWith("<%= escape_javascript(render :partial => 'projects/project_news', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>");
<% elsif @news.course_id %>
$("#activity_post_reply_<%= @user_activity_id %>").html("<%= escape_javascript(render :partial => 'users/course_news_post_reply', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>");
<% elsif @news.contest_id %>
$("#activity_post_reply_<%= @user_activity_id %>").html("<%= escape_javascript(render :partial => 'users/course_news_post_reply', :locals => {:activity => @news,:user_activity_id => @user_activity_id}) %>");
<% elsif @news.org_subfield_id %>
$("#user_activity_<%= @user_activity_id %>").replaceWith("<%= escape_javascript(render :partial => 'organizations/org_subfield_news', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>");
<% end %>

View File

@ -0,0 +1,19 @@
<% if @contest %>
var checked = $("#principals_for_new_member input:checked").size();
if(checked > 0)
{
alert('翻页或搜索后将丢失当前选择的用户数据!');
}
$('#principals_for_new_member').html('<%= escape_javascript(find_user_not_in_current_contest_by_name(@contest)) %>');
<% end %>
var collection = $("#principals_for_new_member").children("#principals").children("label");
collection.css("text-overflow", "ellipsis");
collection.css("white-space", "nowrap");
collection.css("width", "200px");
collection.css("overflow", "hidden");
for(i = 0; i < collection.length; i++) { //增加悬浮显示
var label = collection[i];
var text = $(label).text();
$(label).attr("title", text);
}

View File

@ -0,0 +1,12 @@
<%if @contest%>
<% if @create_member_error_messages%>
alert("<%= @create_member_error_messages%>");
<% else %>
$('#game-setting-content-2').html('<%= escape_javascript(render :partial => 'contests/members') %>');
$("#admin_num").html("<%= contest_managers(@contest).count %>");
$("#judge_num").html("<%= contest_judges(@contest).count %>");
$("#contestant_num").html("<%= contest_contestants(@contest).count %>");
alert("添加成功");
<% end%>
hideOnLoad();
<%end%>

View File

@ -0,0 +1,6 @@
$('#game-setting-content-2').html('<%= escape_javascript(render :partial => 'contests/members') %>');
$("#admin_num").html("<%= contest_managers(@contest).count %>");
$("#judge_num").html("<%= contest_judges(@contest).count %>");
$("#contestant_num").html("<%= contest_contestants(@contest).count %>");
hideOnLoad();

View File

@ -0,0 +1,6 @@
$('#game-setting-content-2').html('<%= escape_javascript(render :partial => 'contests/members') %>');
$("#admin_num").html("<%= contest_managers(@contest).count %>");
$("#judge_num").html("<%= contest_judges(@contest).count %>");
$("#contestant_num").html("<%= contest_contestants(@contest).count %>");
hideOnLoad();

View File

@ -0,0 +1,125 @@
<% if @contestwork.work_detail_group %>
<div id="popbox02">
<div>
<div class="relateText fl">请从<%= @contestwork.work_detail_group.base_on_project ? '项目成员':'竞赛成员' %>中添加小组成员</div>
</div>
<div class="resourcePopupClose"> <a href="javascript:void(0);" class="resourceClose" onclick="clickCanel();"></a></div>
<div class="cl"></div>
<div>
<form class="resourcesSearchBox">
<input type="text" name="serach" placeholder="输入关键字搜索" class="searchResourcePopup" />
</form>
</div>
<ul class="addMemberC fl" id="all_students_list"></ul>
<div class="rightArrow"><img src="/images/course/right-arrow.png" width="16" height="30" /></div>
<ul class="addMemberC fr" id="choose_students_list">
<li id="choose_student_<%=User.current.id %>"><%=User.current.show_name %>
<% unless User.current.user_extensions.student_id == "" %>
(<%=User.current.user_extensions.student_id %>)
<% end %>
</li>
</ul>
<div class="cl"></div>
<div class="courseSendCancel mr15" style="float:right;"><a href="javascript:void(0);" class="sendSourceText" onclick="clickCanel();">取消</a></div>
<div class="courseSendSubmit" style="float:right;"><a href="javascript:void(0);" class="sendSourceText" onclick="clickOK()">确定</a></div>
<div class="cl"></div>
</div>
<script type="text/javascript">
var lastSearchCondition = '';
var count = 0;
function search_stus(e){
if($(e.target).val().trim() == lastSearchCondition && lastSearchCondition != '')
{
return;
}
lastSearchCondition = $(e.target).val().trim();
$.ajax({
url: '<%= url_for(:controller => 'contestant_works', :action => 'search_contest_students') %>'+'?name='+ e.target.value+'&work='+<%=@contestwork.id %>,
type:'get'
});
}
function throttle(method,context,e){
clearTimeout(method.tId);
method.tId=setTimeout(function(){
method.call(context,e);
},500);
}
//查询
$("input[name='serach']").on('input', function (e) {
throttle(search_stus,window,e);
});
function clickOK() {
var str="";
var show = "合作成员:";
var lists = $("#choose_students_list li");
if(lists.length > 0) {
for(var i=0; i<lists.length; i++) {
var id = $(lists[i]).attr("id").replace(/[^0-9]/ig,"");
str += id;
var show_name = $(lists[i]).html();
var index = show_name.indexOf("(");
if (index != -1) {
var name = show_name.substring(0,show_name.indexOf("("));
} else {
var name = show_name;
}
show += name;
if (i == 0) {
show += "(组长)";
}
if (i != lists.length -1) {
str += ",";
show += "、";
}
}
$("#group_member_ids").val(str);
}
hideModal("#popbox02");
$("#group_members_show").show().html(show);
}
function delete_student(id) {
$("#choose_student_"+id).remove();
$("#student_"+id).one("click",function choose_student() {
$("#choose_students_list").append("<li id='choose_student_"+id+"' onclick='delete_student("+id+");'>"+$("#student_"+id).html()+"</li>");
});
}
$(document).ready(function(){
$.ajax({
url: '<%= url_for(:controller => 'contestant_works', :action => 'search_contest_students') %>'+'?work='+<%=@contestwork.id %>,
type:'get'
});
var ids = $("#group_member_ids").val().split(',');
if (ids.length > 1){
for(var i=1; i<ids.length; i++) {
if($("#choose_student_"+ids[i]).length == 0) {
$.get(
'/student_work/get_user_infor',
{
user_id: ids[i]
},
function (data) {
if (data.valid) {
var link = "<li id='choose_student_"+data.id+"' onclick='delete_student("+data.id+");'>"+data.name;
if (data.student_id != "" ) {
link += "("+data.student_id+")";
}
link += "</li>";
$("#choose_students_list").append(link);
}
else
{
}
}
);
}
}
}
});
</script>
<% end %>

View File

@ -0,0 +1,9 @@
<div class="syllabus_courses_box">
<% @stundet_works.each_with_index do |student_work, i| %>
<div class="syllabus_courses_list" id="student_work_<%= student_work.id%>" onclick="show_student_work('<%= contestant_work_path(student_work)%>');" style="cursor: default; background-color:#f6f6f6;">
<%= render :partial => 'contest_evaluation_un_group_work', :locals => {:student_work => student_work} %>
</div>
<div id="about_hwork_<%= student_work.id %>" class="about_hwork"></div>
<% end %>
</div>
<div class="cl"></div>

View File

@ -0,0 +1,65 @@
<div class="sy_courses_open f14 fontGrey3">
<div>
<span class="fl" style="width:280px;">
<span class="hidden fl" style="max-width:220px;"><%= student_work.name %></span>
<span class="fontGrey2 ml5 fl">
<% if student_work.work_status %>
<%= get_status student_work.work_status %>
<% end %>
</span>
</span>
<div class="cl"></div>
<% if @contestwork.work_detail_group.base_on_project %>
<div class="pr">
<span class="fl fontGrey2">关联项目:</span>
<div class="fl projectName">
<% if student_work.project.status != 9 && (student_work.project.is_public || User.current.member_of?(student_work.project) || User.current.admin? || User.current.admin_of_contest?(@contestwork.contest) || User.current.judge_of_contest?(@contestwork.contest)) %>
<%= link_to student_work.project.name, project_path(student_work.project.id), :class => 'link-blue fl hidden', :style => "max-width:550px;", :title => "项目名称", :target => "_blank" %>
<% elsif student_work.project.status != 9 %>
<span class="fontBlue fr hidden" style="max-width:550px;" title="该项目是私有的"><%= student_work.project.name %></span>
<% else %>
<span class="fontGrey2 fr hidden" style="max-width:550px;" title="该项目已删除"><%= student_work.project.name %>(已删除)</span><% end %>
<% project = student_work.project %>
<div class="score-tip none tl f12" style="width:300px; top:-48px; right:-372px;">
<em style="bottom:45px;"></em>
<font style="bottom:45px;"></font>
<p class="fb break_word mw280"><%= project.name %><%= project.status == 9 ? "(已删除)" : ""%></p>
<p class="mb10">
<span class="mr15">创建者:<%= project.creater %></span><span>成员数量:<%= project.members.count %></span></p>
<% project_score = project.project_score %>
<p>项目综合得分:<%= project.status == 9 ? 0 : static_project_score(project_score).to_i %></p>
<% if project.status != 9 %>
<p>= 代码提交得分 + issue得分 + 资源得分 + 帖子得分</p>
<p>= <%= (project_score.changeset_num||0) * 4 %>
+ <%= project_score.issue_num * 4 + project_score.issue_journal_num %> + <%= project_score.attach_num * 5 %>
+ <%= project_score.board_num * 2 + project_score.board_message_num + project_score.news_num %></p>
<% end %>
</div>
</div>
</div>
<% end %>
</div>
<div class="cl"></div>
</div>
<div class="fl sy_p_grey" style="margin-left: 0px;">
<span class="fl" style="width:180px;">提交时间:<%= format_date(student_work.commit_time) %></span>
<span class="fl" style="width:105px; text-align: center">人数:<%=student_work.contestant_work_projects.count %>人</span>
<div class="flex-container fl" style="width:400px;">
<div class="flex-cell">评委评分:--</div>
<div class="flex-cell">最终成绩:--</div>
</div>
</div>
<div class="cl"></div>
<script>
$(".projectName").mouseenter(function () {
$(this).children().next().show();
}).mouseleave(function () {
$(this).children().next().hide();
});
</script>

View File

@ -0,0 +1,42 @@
<table class="hwork-table-wrap" id="homework_table">
<%# if @homework.homework_type == 1 %>
<%#= render :partial => 'evaluation_un_common_title' %>
<%# elsif @homework.homework_type == 2 %>
<%#= render :partial => 'evaluation_un_pro_title' %>
<%# elsif @homework.homework_type == 3 %>
<%#= render :partial => 'evaluation_un_group_title' %>
<%# else %>
<tr class="b_grey hworkH30">
<th class="hworkList40 hworkH30 pl5 pr5">序号</th>
<th class="hworkList50">&nbsp;</th>
<th class="hworkList190 pl5 pr5 hide-text">
姓名
</th>
<th class="hworkList80 pl5 pr5 hide-text">
</th>
<th class="hworkList130">
状态
</th>
<th class="hworkList100">
评委评分
</th>
<th class="hworkList100">
最终成绩
</th>
</tr>
<%# end %>
<% @stundet_works.each_with_index do |student_work, i| %>
<% score_open = true %>
<a name="<%= student_work.id%>"></a>
<%= render :partial => "contest_evaluation_un_work", :locals => {:student_work => student_work, :index => i, :score_open => score_open} %>
<tr>
<td colspan="12">
<div id="about_hwork_<%= student_work.id %>" class="about_hwork">
</div>
</td>
</tr>
<% end %>
</table>

View File

@ -0,0 +1,37 @@
<tr class="hworkListRow" id="student_work_<%= student_work.id%>">
<td class="hworkList40 pl5 pr5" id="work_num_<%=student_work.id %>"><%=index + 1 %></td>
<td class="hworkPortrait pr10 float-none">
<%= link_to(image_tag(url_to_avatar(student_work.user),:width =>"40",:height => "40",:style => "display:block;"),user_path(student_work.user), :target => '_blank') %>
</td>
<td class="hworkStName190 pr10 float-none hidden" title="<%= student_work.user.show_name%>" style="cursor:pointer; text-align: center;">
<%= link_to student_work.user.show_name ,user_path(student_work.user), :target => '_blank' %>
</td>
<td class="hworkList80 student_work_<%= student_work.id%>" onclick="show_student_work('<%= contestant_work_path(student_work)%>');">
</td>
<td class="hworkList130 c_grey student_work_<%= student_work.id%>" onclick="show_student_work('<%= contestant_work_path(student_work)%>');" style="cursor: pointer;">
<% if student_work.work_status%>
<%=get_status student_work.work_status %>
<% end %>
</td>
<td class="hworkList100 <%= score_color nil %>">
--
</td>
<td class="hworkList100 <%= score_color nil %> student_final_scor_info pr">
--
</td>
<td><div style="position:relative;"><div class="hworkTip" style="display: none" id="work_click_<%= student_work.id%>"><em></em><span></span><font class="fontGrey2">点击查看详情</font></div></div></td>
</tr>
<%# end %>
<script type="text/javascript">
$(".student_work_<%= student_work.id%>").mouseenter(function(){
if($("#about_hwork_<%= student_work.id%>").html().trim() == "") {
$("#work_click_<%= student_work.id%>").show();
}
}).mouseleave(function(){
$("#work_click_<%= student_work.id%>").hide();
}).mouse;
</script>

View File

@ -0,0 +1,17 @@
<% attachments.each_with_index do |attachment,i| %>
<div id="attachment_<%= attachment.id%>">
<span class="fl">
<span title="点击可下载">
<%= link_to_short_attachment attachment,:length=> 58, :class => 'hidden link_file_a fl newsBlue mw360', :download => true -%>
</span>
</span>
<% if attachment.id && User.current == attachment.author && (attachment.attachtype == 7 || @contestwork.end_time >= Date.today) %>
<%= link_to('&nbsp;'.html_safe, attachment_path(attachment, :format => 'js'), :method => 'delete', :remote => true, :title => '删除', :class => 'remove-upload fl', :confirm => l(:text_are_you_sure)) %>
<% end %>
<span class="postAttSize">(<%= number_to_human_size attachment.filesize %>)</span>
<span class="author">
<%= format_time(attachment.created_on) %>
</span>
<div class="cl"></div>
</div>
<% end -%>

View File

@ -0,0 +1,56 @@
<div class="mt10">
<span id="attachments_fields" class="attachments_fields">
<% if defined?(container) && container && container.saved_attachments %>
<% container.attachments.each_with_index do |attachment, i| %>
<span id="attachments_p<%= i %>">
<%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename link_file', :readonly=>'readonly')%>
<%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 254, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") %>
<span class="ispublic-label"><%= l(:field_is_public)%>:</span>
<%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false,:class => 'is_public')%>
<%= link_to('&nbsp;'.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') unless attachment.id.nil? %>
<%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %>
</span>
<div class="cl"></div>
<% end %>
<% container.saved_attachments.each_with_index do |attachment, i| %>
<span id="attachments_p<%= i %>">
<%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename readonly', :readonly=>'readonly')%>
<%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 254, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") %>
<span class="ispublic-label"><%= l(:field_is_public)%>:</span>
<%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false,:class => 'is_public')%>
<%= link_to('&nbsp;'.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') unless attachment.id.nil? %>
<%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %>
</span>
<div class="cl"></div>
<% end %>
<% end %>
</span>
<%= file_field_tag 'attachments[dummy][file]',
:id => '_file',
:class => ie8? ? '' : 'file_selector',
:multiple => true,
:onchange => 'addInputFiles(this);',
:style => ie8? ? '' : 'display:none',
:data => {
:max_file_size => Setting.attachment_max_size.to_i.kilobytes,
:max_file_size_message => l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)),
:max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i,
:upload_path => uploads_path(:format => 'js',:project =>nil),
:description_placeholder => l(:label_optional_description),
:field_is_public => l(:field_is_public),
:are_you_sure => l(:text_are_you_sure),
:file_count => l(:label_file_count),
:lebel_file_uploding => l(:lebel_file_uploding),
:delete_all_files => l(:text_are_you_sure_all)
} %>
</div>
<div class="cl"></div>
<div class="mt5 fl">
<!-- , user_import_resource_user_path(User.current.id,:homework_id=>container.id) -->
<a href="javascript:void(0);" id="upload_file_local" class="AnnexBtn fl mt3 mr15" onclick="$('#_file').click();" title="请选择文件上传">上传附件</a>
</div>
<% content_for :header_tags do %>
<%= javascript_include_tag 'attachments' %>
<% end %>

View File

@ -0,0 +1,55 @@
<div class="fl pr" style="padding-bottom:10px; width:720px;">
<span class="c_dark f14 fb fl mr10">
作品
<font class="f12 c_red">
<% if @contestwork.work_type == 3 %>
<% member_count = @contestwork.contestant_works.where("work_status != 0").count %>
(<%= @student_work_count%>组<%=member_count %>人已交)
<% else %>
(<%= @student_work_count%>人已交)
<% end %>
</font>
<%# my_work = @homework.student_works.where("user_id = #{User.current.id}").first %>
<% my_work = cur_user_works_for_work @contestwork %>
<% if !@is_teacher && !@is_judge && my_work.nil? && User.current.member_of_contest?(@contest) %>
<span class="f12 c_red">您尚未提交作品</span>
<% unless @contestwork.work_type == 3 && @contestwork.work_detail_group.base_on_project %>
<%=link_to "提交作品", new_contestant_work_path(:work => @contestwork.id),:class => 'blueCir ml5 f12' %>
<% end %>
<% elsif !@is_teacher && !@is_judge && my_work &&Time.parse(@contestwork.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") && !@stundet_works.empty?%>
<span class="f12 c_red">截止日期已过,已提交且不可修改</span>
<% elsif !@is_teacher && !@is_judge && my_work &&Time.parse(@contestwork.end_time.to_s).strftime("%Y-%m-%d") >= Time.parse(Time.now.to_s).strftime("%Y-%m-%d") && !@stundet_works.empty?%>
<% if @contestwork.work_type == 3 %>
<span class="f12 c_red">组长已提交,组长还可修改</span>
<% else %>
<span class="f12 c_red">您已提交,您还可以修改</span>
<% end %>
<% end %>
</span>
<%# if !@is_teacher && !@is_judge && @contestwork.work_type == 3 && my_work && my_work.user == User.current && Time.parse(@contestwork.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") %>
<!--<div class="mt5 fr">-->
<!--<a href="javascript:void(0);" class="memberBtn fl mt3" title="添加小组成员" onclick="add_or_delete_group_member();">合作成员</a>-->
<!--</div>-->
<%# end %>
</div>
<div class="cl"></div>
<div class="fl">
<% if @contestwork.work_type != 3%>
<%= render :partial => "contest_evaluation_un_title"%>
<% else %>
<%= render :partial => "contest_evaluation_un_group"%>
<% end %>
</div>
<div class="cl"></div>
<script type="text/javascript">
// function add_or_delete_group_member() {
// var html_value = "<%#= escape_javascript(render :partial => 'student_work/add_or_delete_member',:locals => {:homework=>@homework,:edit_mode => true}) %>";
// pop_up_box(html_value, 530);
// }
</script>

View File

@ -0,0 +1,24 @@
<div id="popbox02">
<div class="ni_con">
<div><p align='center' style='margin-top: 35px'>您已提交过作品,请不要重复提交,如果想修改作品请点击编辑。</p></div>
<div class="cl"></div>
<div class="ni_btn mt10">
<a href="javascript:" class="tijiao" onclick="clickOK();" style="margin-bottom: 15px;margin-top:15px;" >
编&nbsp;&nbsp;辑
</a>
<a href="javascript:" class="tijiao" onclick="clickCanel();" style="margin-bottom: 15px;margin-top:15px;" >
取&nbsp;&nbsp;消
</a>
</div>
</div>
</div>
<script type="text/javascript">
function clickOK() {
window.location.href = '<%= edit_contestant_work_path(@work.id)%>';
}
function clickCanel() {
hideModal('#popbox02');
window.location.href = '<%= contestant_works_path(:work => @contestwork.id)%>';
}
</script>

View File

@ -0,0 +1,63 @@
<div id="muban_popup_box" style="width:400px;">
<div class="muban_popup_top">
<h3 class="fl">关联项目</h3>
<a href="javascript:void(0);" class="muban_icons_close fr"></a>
<div class="cl"></div>
</div>
<div class="muban_popup_con clear ml30 mr30 mt10">
<%= form_for('new_form',:url =>{:controller => 'contestant_works',:action => 'student_work_project',:work => @contestwork.id,:user_activity_id=>@user_activity_id,:hw_status =>@hw_status},:method => "post", :remote => true) do |f|%>
<input type="text" name="project" placeholder="输入项目名称进行搜索" class="searchResourcePopup mb10" />
<div class="cl"></div>
<p id="no_search_result" class="c_red f14" style="width:320px;display: none">您当前尚未创建任何项目,请先创建项目再关联。</p>
<ul id="search_project_list" class="maxHeight200"></ul>
<p id="notes" class="c_red"></p>
<a href="javascript:void(0);" class="sy_btn_blue fr" onclick="clickOK();">确定</a>
<a href="javascript:void(0);" class="sy_btn_grey fr mr5" onclick="clickCanel();">取消</a>
<div class="cl"></div>
<% end %>
</div>
</div>
<script type="text/javascript">
var lastSearchCondition = '';
var count = 0;
function search_pros(e){
if($(e.target).val().trim() == lastSearchCondition && lastSearchCondition != '')
{
return;
}
lastSearchCondition = $(e.target).val().trim();
$.ajax({
url: '<%= url_for(:controller => 'student_work', :action => 'search_user_projects') %>'+'?name='+ e.target.value,
type:'get'
});
}
function throttle(method,context,e){
clearTimeout(method.tId);
method.tId=setTimeout(function(){
method.call(context,e);
},500);
}
//查询项目
$("input[name='project']").on('input', function (e) {
throttle(search_pros,window,e);
});
$(document).ready(function(){
$.ajax({
url: '<%= url_for(:controller => 'student_work', :action => 'search_user_projects') %>'+'?first=1',
type:'get'
});
});
function clickOK() {
var radio = $("input[name='projectName']:checked");
if(radio.length < 1) {
$("#notes").html("请先选择一个项目");
return false;
} else {
$("#muban_popup_box").find('form').submit();
}
}
</script>

Some files were not shown because too many files have changed in this diff Show More