diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb
index 279e89f13..686f70a11 100644
--- a/app/controllers/account_controller.rb
+++ b/app/controllers/account_controller.rb
@@ -101,33 +101,12 @@ class AccountController < ApplicationController
# User self-registration
def register
- # @root_path="/home/pdl/redmine-2.3.2-0/apache2/"
-#
- #@cache_identityy = params[:identity]||"" #身份
- @cache_no = params[:no]||"" #学号
- @cache_technical_title = params[:technical_title]||"" #教师职称
- @cache_province = params[:province]||"" #省份
- @cache_city = params[:city]||"" #城市
- @cache_enterprise_name = params[:enterprise_name]||"" #企业
-
- firstname_code = ""
- lastname_code = ""
(redirect_to(home_url); return) unless Setting.self_registration? || session[:auth_source_registration]
if request.get?
session[:auth_source_registration] = nil
@user = User.new(:language => current_language.to_s)
else
user_params = params[:user] || {}
- @user = User.new
- @user.safe_attributes = user_params
- if params[:identity] == "2" # 2 企业
- firstname_code = @user.firstname
- lastname_code = @user.lastname
- @user.firstname = params[:enterprise_name]
- @user.lastname = l(:field_enterprise)
- end
- @user.admin = false
- @user.register
if session[:auth_source_registration]
@user.activate
@user.login = session[:auth_source_registration][:login]
@@ -139,36 +118,7 @@ class AccountController < ApplicationController
redirect_to my_account_path
end
else
- @user.login = params[:user][:login]
- unless user_params[:identity_url].present? && user_params[:password].blank? && user_params[:password_confirmation].blank?
- @user.password, @user.password_confirmation = user_params[:password], user_params[:password_confirmation]
- end
-
-
-
- case Setting.self_registration
- when '1'
- register_by_email_activation(@user)
- when '3'
- register_automatically(@user)
- else
- register_manually_by_administrator(@user)
- end
-
- #added by bai
- if @user.id != nil
- ue = @user.user_extensions ||= UserExtensions.new
- #ue = UserExtensions.create(:identity => params[:identity].to_i,:technical_title => params[:technical_title], :gender => params[:gender].to_i, :user_id => @user.id, :student_id => )
- ue.identity = params[:identity].to_i
- ue.technical_title = params[:technical_title]
- ue.gender = params[:gender].to_i
- ue.user_id = @user.id
- ue.student_id = params[:no]
- ue.location = params[:province] if params[:province] != nil
- ue.location_city = params[:city] if params[:city] != nil
- ue.save
- end
-
+ create_and_save_user params[:user][:login],user_params[:password],user_params[:mail],user_params[:password_confirmation],true
end
end
if params[:identity] == "2"
@@ -177,6 +127,34 @@ class AccountController < ApplicationController
end
end
+ #should_confirmation_password是否验证密码
+ def create_and_save_user login,password,email,password_confirmation,should_confirmation_password
+ @user = User.new
+ @user.admin = false
+ @user.register
+ @user.login = login
+ @user.mail = email
+ if should_confirmation_password && !password.blank? && !password_confirmation.blank?
+ @user.password,@user.password_confirmation = password,password_confirmation
+ elsif !should_confirmation_password && !password.blank?
+ @user.password = password
+ end
+ case Setting.self_registration
+ when '1'
+ register_by_email_activation(@user)
+ when '3'
+ register_automatically(@user)
+ else
+ register_manually_by_administrator(@user)
+ end
+ if @user.id != nil
+ ue = @user.user_extensions ||= UserExtensions.new
+ ue.user_id = @user.id
+ ue.save
+ end
+ @user
+ end
+
# Token based account activation
def activate
(redirect_to(home_url); return) unless Setting.self_registration? && params[:token].present?
diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb
index 31463d691..111ec2cca 100644
--- a/app/controllers/attachments_controller.rb
+++ b/app/controllers/attachments_controller.rb
@@ -25,6 +25,7 @@ class AttachmentsController < ApplicationController
#before_filter :login_without_softapplication, only: [:download]
accept_api_auth :show, :download, :upload
require 'iconv'
+ include AttachmentsHelper
def show
@@ -346,8 +347,18 @@ class AttachmentsController < ApplicationController
def add_exist_file_to_courses
file = Attachment.find(params[:file_id])
courses = params[:courses][:course]
+ @message = ""
courses.each do |course|
c = Course.find(course);
+ if course_contains_attachment?(c,file)
+ if @message && @message == ""
+ @message += l(:label_course_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed)
+ next
+ else
+ @message += " " + l(:label_course_prompt) + c.name + l(:label_contain_resource) + file.filename + l(:label_quote_resource_failed)
+ next
+ end
+ end
attach_copied_obj = file.copy
attach_copied_obj.tag_list.add(file.tag_list) # tag关联
attach_copied_obj.container = c
@@ -360,6 +371,7 @@ class AttachmentsController < ApplicationController
@obj = c
@save_flag = attach_copied_obj.save
@save_message = attach_copied_obj.errors.full_messages
+ update_quotes attach_copied_obj
end
respond_to do |format|
format.js
@@ -372,6 +384,20 @@ class AttachmentsController < ApplicationController
end
end
+ def update_quotes attachment
+ if attachment.copy_from
+ attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.copy_from} or id = #{attachment.copy_from}")
+ else
+ attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.id} or id = #{attachment.copy_from}")
+ end
+ attachment.quotes = get_qute_number attachment
+ attachment.save
+ attachments.each do |att|
+ att.quotes = attachment.quotes
+ att.save
+ end
+ end
+
private
def find_project
@attachment = Attachment.find(params[:id])
diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb
index 627e1945b..af532cd87 100644
--- a/app/controllers/contests_controller.rb
+++ b/app/controllers/contests_controller.rb
@@ -188,10 +188,10 @@ class ContestsController < ApplicationController
# Added by Longjun
def destroy_contest
@contest = Contest.find(params[:id])
- if @contest.author_id == User.current.id
+ if @contest.author_id == User.current.id || User.current.admin?
@contest.destroy
- redirect_to action: 'index'
+ redirect_to welcome_contest_url
else
render_403 :message => :notice_not_contest_delete_authorized
end
diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb
index 12b733669..ccb02d939 100644
--- a/app/controllers/courses_controller.rb
+++ b/app/controllers/courses_controller.rb
@@ -514,7 +514,7 @@ class CoursesController < ApplicationController
end
def homework
- if @course.is_public != 0 || User.current.member_of_course?(@course)
+ if @course.is_public != 0 || User.current.member_of_course?(@course) || User.current.admin?
@offset, @limit = api_offset_and_limit({:limit => 10})
@bids = @course.homeworks.order('deadline DESC')
@bids = @bids.like(params[:name]) if params[:name].present?
diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb
index 251496e30..1ed40f691 100644
--- a/app/controllers/files_controller.rb
+++ b/app/controllers/files_controller.rb
@@ -28,6 +28,7 @@ class FilesController < ApplicationController
include SortHelper
include FilesHelper
helper :project_score
+ include CoursesHelper
def show_attachments obj
@attachments = []
@@ -44,16 +45,28 @@ class FilesController < ApplicationController
end
def search
+ sort = ""
+ @sort = ""
+ @order = ""
+ @is_remote = true
+ if params[:sort]
+ order_by = params[:sort].split(":")
+ @sort = order_by[0]
+ if order_by.count > 1
+ @order = order_by[1]
+ end
+ sort = "#{@sort} #{@order}"
+ end
+
begin
- @is_remote = true
q = "%#{params[:name].strip}%"
#(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
if params[:insite]
- @result = find_public_attache q
- @result = visable_attachemnts @result
+ @result = find_public_attache q,sort
+ @result = visable_attachemnts_insite @result,@course
@searched_attach = paginateHelper @result,10
else
- @result = find_course_attache q,@course
+ @result = find_course_attache q,@course,sort
@result = visable_attachemnts @result
@searched_attach = paginateHelper @result,10
end
@@ -64,17 +77,24 @@ class FilesController < ApplicationController
end
end
- def find_course_attache keywords,course
+ def find_course_attache keywords,course,sort = ""
+ if sort == ""
+ sort = "created_on DESC"
+ end
resultSet = Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' AND filename LIKE :like ", like: "%#{keywords}%").
- reorder("created_on DESC")
+ reorder(sort)
+ #resultSet = Attachment.find_by_sql("SELECT `attachments`.* FROM `attachments` LEFT OUTER JOIN `homework_attaches` ON `attachments`.container_type = 'HomeworkAttach' AND `attachments`.container_id = `homework_attaches`.id LEFT OUTER JOIN `homework_for_courses` ON `homework_attaches`.bid_id = `homework_for_courses`.bid_id LEFT OUTER JOIN `homework_for_courses` AS H_C ON `attachments`.container_type = 'Bid' AND `attachments`.container_id = H_C.bid_id WHERE (`homework_for_courses`.course_id = 117 OR H_C.course_id = 117 OR (`attachments`.container_type = 'Course' AND `attachments`.container_id = 117)) AND `attachments`.filename LIKE '%#{keywords}%'").reorder("created_on DESC")
end
- def find_public_attache keywords
+ def find_public_attache keywords,sort = ""
# StoresController#search 将每条文件都查出来,再次进行判断过滤。---> resultSet.to_a.map
# 此时内容不多速度还可,但文件增长,每条判断多则进行3-4次表连接。
# 现在还木有思路 药丸
- resultSet = Attachment.where("attachments.container_type IS NOT NULL AND filename LIKE :like ", like: "%#{keywords}%").
- reorder("created_on DESC")
+ if sort == ""
+ sort = "created_on DESC"
+ end
+ resultSet = Attachment.where("attachments.container_type IS NOT NULL AND attachments.copy_from IS NULL AND filename LIKE :like ", like: "%#{keywords}%").
+ reorder(sort)
end
def index
@@ -151,6 +171,8 @@ class FilesController < ApplicationController
attribute = "downloads"
when "created_on"
attribute = "created_on"
+ when "quotes"
+ attribute = "quotes"
end
@sort = order_by[0]
@order = order_by[1]
@@ -371,14 +393,14 @@ class FilesController < ApplicationController
end
end
- # show_attachments @containers
- # @attachtype = params[:type].to_i
- # @contenttype = params[:contentType].to_s
- #
- # respond_to do |format|
- # format.js
- # format.html
- # end
+ show_attachments @containers
+ @attachtype = params[:type].to_i
+ @contenttype = params[:contentType].to_s
+
+ respond_to do |format|
+ format.js
+ format.html
+ end
end
end
diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb
index a9adc9ec6..6088e2294 100644
--- a/app/controllers/homework_attach_controller.rb
+++ b/app/controllers/homework_attach_controller.rb
@@ -22,23 +22,10 @@ class HomeworkAttachController < ApplicationController
#获取未批作业列表
def get_not_batch_homework
sort, direction = params[:sort] || "s_socre", params[:direction] || "desc"
- if sort == 't_socre'
- order_by = "t_score #{direction}"
- elsif sort == 's_socre'
- order_by = "s_score #{direction}"
- elsif sort == 'time'
- order_by = "created_at #{direction}"
- end
teachers = find_course_teachers @course
- all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*,
- (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN #{teachers}) AS t_score,
- (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN #{teachers}) AS s_score
- FROM homework_attaches WHERE bid_id = #{@bid.id}
- ORDER BY #{order_by}) AS table1
- WHERE table1.t_score IS NULL")
+ get_not_batch_homework_list sort,direction,teachers, @bid.id
@cur_page = params[:page] || 1
@cur_type = 1
- @homework_list = paginateHelper all_homework_list,10
@direction = direction == 'asc'? 'desc' : 'asc'
respond_to do |format|
format.js
@@ -57,8 +44,8 @@ class HomeworkAttachController < ApplicationController
end
teachers = find_course_teachers @course
all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*,
- (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN #{teachers} and stars IS NOT NULL) AS t_score,
- (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN #{teachers}) AS s_score
+ (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (#{teachers}) and stars IS NOT NULL) AS t_score,
+ (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN (#{teachers})) AS s_score
FROM homework_attaches WHERE bid_id = #{@bid.id}
ORDER BY #{order_by}) AS table1
WHERE table1.t_score IS NOT NULL")
@@ -83,8 +70,8 @@ class HomeworkAttachController < ApplicationController
end
teachers = find_course_teachers @course
all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*,
- (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id in #{teachers}) AS t_score,
- (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id not in #{teachers}) AS s_score
+ (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id in (#{teachers})) AS t_score,
+ (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id not in (#{teachers})) AS s_score
FROM homework_attaches WHERE bid_id = #{@bid.id}
ORDER BY #{order_by}")
@cur_page = params[:page] || 1
@@ -101,8 +88,8 @@ class HomeworkAttachController < ApplicationController
@is_student_batch_homework = true
teachers = find_course_teachers @course
all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*,
- (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN #{teachers}) AS t_score,
- (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN #{teachers}) AS s_score,
+ (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (#{teachers})) AS t_score,
+ (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN (#{teachers})) AS s_score,
(SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{User.current.id}) AS m_score
FROM homework_attaches
INNER JOIN homework_evaluations ON homework_evaluations.homework_attach_id = homework_attaches.id
@@ -120,15 +107,15 @@ class HomeworkAttachController < ApplicationController
@is_my_homework = true
teachers = find_course_teachers @course
all_homework_list = HomeworkAttach.find_by_sql("SELECT homework_attaches.*,
- (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN #{teachers}) AS t_score,
- (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN #{teachers}) AS s_score
+ (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (#{teachers})) AS t_score,
+ (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN (#{teachers})) AS s_score
FROM homework_attaches
WHERE homework_attaches.bid_id = #{@bid.id} AND homework_attaches.user_id = #{User.current.id}")
#如果我没有创建过作业,就检索我是否参与了某个作业
if all_homework_list.empty?
all_homework_list = HomeworkAttach.find_by_sql("SELECT homework_attaches.*,
- (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN #{teachers}) AS t_score,
- (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN #{teachers}) AS s_score
+ (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (#{teachers})) AS t_score,
+ (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN (#{teachers})) AS s_score
FROM homework_attaches
INNER JOIN homework_users ON homework_users.homework_attach_id = homework_attaches.id
WHERE homework_attaches.bid_id = #{@bid.id} AND homework_users.user_id = #{User.current.id}")
@@ -331,18 +318,9 @@ class HomeworkAttachController < ApplicationController
if User.current.admin? || User.current.member_of_course?(course)
name = params[:homework_name]
description = params[:homework_description]
- if params[:homework_attach]
- if params[:homework_attach][:project_id]
- project_id = params[:homework_attach][:project_id]
- else
- project_id = 0
- end
- else
- project_id = 0
- end
@homework.name = name
@homework.description = description
- @homework.project_id = project_id
+ @homework.project_id = params[:project_id] || 0
if params[:attachments]
@homework.save_attachments(params[:attachments])
end
@@ -381,11 +359,11 @@ class HomeworkAttachController < ApplicationController
def show
if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first)
# 打分统计
- stars_reates = @homework. rates(:quality)
+ #stars_reates = @homework. rates(:quality)
#是否已经进行过评价
temp = HomeworkAttach.find_by_sql("SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = #{@homework.id} AND rater_id = #{User.current.id}").first
@m_score = temp.nil? ? 0:temp.stars
- @has_evaluation = stars_reates.where("rater_id = ?",User.current).count > 0
+ @has_evaluation = @homework.has_rated?( User.current,:quality)
#@jours留言 is null条件用以兼容历史数据
@jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC")
@cur_page = params[:cur_page] || 1
@@ -394,30 +372,35 @@ class HomeworkAttachController < ApplicationController
teachers = searchTeacherAndAssistant @course
@comprehensive_evaluation = []
+ #JourForMessage的is_comprehensive_evaluation字段:
+ #1:老师评价
+ #2:学生评价
+ #3 || null:学生留言
teachers.each do|teacher|
temp = @homework.journals_for_messages.where("is_comprehensive_evaluation = 1 and user_id = #{teacher.user_id}").order("created_on DESC").first
@comprehensive_evaluation << temp if temp
end
- annymous_users = @homework.homework_evaluations.map(&:user)
- unless annymous_users.nil? || annymous_users.count == 0
- @anonymous_comments = @homework.journals_for_messages.where("is_comprehensive_evaluation = 2 and user_id in #{convert_array(annymous_users)}").order("created_on DESC")
+ annymous_users = @homework.homework_evaluations.map { |homework_evaluation| homework_evaluation.user.id}.join(',')
+ unless annymous_users.nil? || annymous_users == ""
+ @anonymous_comments = @homework.journals_for_messages.where("is_comprehensive_evaluation = 2 and user_id in (#{annymous_users})").order("created_on DESC")
end
- @totle_score = score_for_homework @homework
- @teaher_score = teacher_score_for_homework @homework
+ #@totle_score = score_for_homework @homework
+ #@teaher_score = teacher_score_for_homework @homework
- is_student = is_cur_course_student @homework.bid.courses.first
- is_teacher = is_course_teacher User.current,@homework.bid.courses.first
+ #is_student = is_cur_course_student @homework.bid.courses.first
+ @is_teacher = is_course_teacher User.current,@homework.bid.courses.first
@is_anonymous_comments = @homework.bid.comment_status == 1 #是否开启了匿评
- if !User.current.member_of_course?(@homework.bid.courses.first)
- @is_comprehensive_evaluation = 3 #留言
- elsif is_student && @is_anonymous_comments && !@has_evaluation#是学生且开启了匿评且未进行评分
- @is_comprehensive_evaluation = 2 #匿评
- elsif is_student && @is_anonymous_comments && @has_evaluation #是学生且开启了匿评,但已评分
- @is_comprehensive_evaluation = 2 #匿评
- elsif is_student && !@is_anonymous_comments #是学生未开启匿评
- @is_comprehensive_evaluation = 3 #留言
- elsif is_teacher
- @is_comprehensive_evaluation = 1 #教师评论
+ #@is_comprehensive_evaluation 1:教师评论,2:学生匿评,3:学生留言
+ if User.current.member_of_course?(@homework.bid.courses.first)
+ if @is_teacher
+ @is_comprehensive_evaluation = 1 #教师评论
+ else
+ if @is_anonymous_comments && !@has_evaluation #是学生且开启了匿评且未进行评分
+ @is_comprehensive_evaluation = 2 #匿评
+ else #是学生未开启匿评或者已经进行评分
+ @is_comprehensive_evaluation = 3 #留言
+ end
+ end
else
@is_comprehensive_evaluation = 3
end
@@ -442,9 +425,9 @@ class HomeworkAttachController < ApplicationController
@jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC")
@jour = paginateHelper @jours,5
elsif @is_comprehensive_evaluation == 2
- annymous_users = @homework.homework_evaluations.map(&:user)
- unless annymous_users.nil? || annymous_users.count == 0
- @anonymous_comments = @homework.journals_for_messages.where("is_comprehensive_evaluation = 2 and user_id in #{convert_array(annymous_users)}").order("created_on DESC")
+ annymous_users = @homework.homework_evaluations.map { |homework_evaluation| homework_evaluation.user.id}.join(',')
+ unless annymous_users.nil? || annymous_users.count == ""
+ @anonymous_comments = @homework.journals_for_messages.where("is_comprehensive_evaluation = 2 and user_id in (#{annymous_users})").order("created_on DESC")
end
elsif @is_comprehensive_evaluation == 1
teachers = searchTeacherAndAssistant @course
@@ -454,9 +437,6 @@ class HomeworkAttachController < ApplicationController
@comprehensive_evaluation << temp if temp
end
end
-
-
-
respond_to do |format|
format.js
end
@@ -465,17 +445,27 @@ class HomeworkAttachController < ApplicationController
#添加留言
def addjours
@homework = HomeworkAttach.find(params[:jour_id])
- @add_jour = @homework.addjours User.current.id, params[:new_form][:user_message],0,params[:is_comprehensive_evaluation]
- if @add_jour.is_comprehensive_evaluation == 3
+ #保存评分
+ @homework.rate(params[:stars_value],User.current.id,:quality) if params[:stars_value] && params[:stars_value] != "0"
+ #保存评论
+ @cur_is_comprehensive_evaluation = params[:is_comprehensive_evaluation]
+ if params[:new_form] && params[:new_form][:user_message] && params[:new_form][:user_message] != "" #有没有留言
+ @homework.addjours User.current.id, params[:new_form][:user_message],0,@cur_is_comprehensive_evaluation
+ end
+
+ @cur_page = params[:cur_page] || 1
+ @cur_type = params[:cur_type] || 5
+ teachers = searchTeacherAndAssistant @homework.bid.courses.first
+ if @cur_is_comprehensive_evaluation == "3"
@jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC")
@jour = paginateHelper @jours,5
- elsif @add_jour.is_comprehensive_evaluation == 2
- annymous_users = @homework.homework_evaluations.map(&:user)
- unless annymous_users.nil? || annymous_users.count == 0
- @anonymous_comments = @homework.journals_for_messages.where("is_comprehensive_evaluation = 2 and user_id in #{convert_array(annymous_users)}").order("created_on DESC")
+ elsif @cur_is_comprehensive_evaluation == "2"
+ annymous_users = @homework.homework_evaluations.map { |homework_evaluation| homework_evaluation.user.id}.join(',')
+ unless annymous_users.nil? || annymous_users == ""
+ @anonymous_comments = @homework.journals_for_messages.where("is_comprehensive_evaluation = 2 and user_id in (#{annymous_users})").order("created_on DESC")
end
- elsif @add_jour.is_comprehensive_evaluation == 1
- teachers = searchTeacherAndAssistant @homework.bid.courses.first
+ @m_score = params[:stars_value].to_i
+ elsif @cur_is_comprehensive_evaluation == "1"
@comprehensive_evaluation = []
teachers.each do|teacher|
temp = @homework.journals_for_messages.where("is_comprehensive_evaluation = 1 and user_id = #{teacher.user_id}").order("created_on DESC").first
@@ -483,35 +473,49 @@ class HomeworkAttachController < ApplicationController
end
end
-
- #@limit = 10
- #@feedback_count = @jours.count
- #@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
- #@offset ||= @feedback_pages.offset
- #@jour = @jours[@offset, @limit]
- #@comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC")
-
- @totle_score = score_for_homework @homework
- @teaher_score = teacher_score_for_homework @homework
- stars_reates = @homework. rates(:quality)
- is_student = is_cur_course_student @homework.bid.courses.first
is_teacher = is_course_teacher User.current,@homework.bid.courses.first
- @has_evaluation = stars_reates.where("rater_id = ?",User.current).count > 0
@is_anonymous_comments = @homework.bid.comment_status == 1 #是否开启了匿评
- if !User.current.member_of_course?(@homework.bid.courses.first)
- @is_comprehensive_evaluation = 3 #留言
- elsif is_student && @is_anonymous_comments && !@has_evaluation#是学生且开启了匿评且未进行评分
- @is_comprehensive_evaluation = 2 #匿评
- elsif is_student && @is_anonymous_comments && @has_evaluation #是学生且开启了匿评,但已评分
- @is_comprehensive_evaluation = 3 #留言
- elsif is_student && !@is_anonymous_comments #是学生未开启匿评
- @is_comprehensive_evaluation = 3 #留言
- elsif is_teacher
- @is_comprehensive_evaluation = 1 #教师评论
+ #@is_comprehensive_evaluation 1:教师评论,2:学生匿评,3:学生留言
+ if User.current.member_of_course?(@homework.bid.courses.first)
+ if is_teacher
+ @is_comprehensive_evaluation = 1 #教师评论
+ else
+ if @is_anonymous_comments && !@has_evaluation #是学生且开启了匿评且未进行评分
+ @is_comprehensive_evaluation = 2 #匿评
+ else #是学生未开启匿评或者已经进行评分
+ @is_comprehensive_evaluation = 3 #留言
+ end
+ end
else
@is_comprehensive_evaluation = 3
end
+ #teachers = find_course_teachers @homework.bid.courses.first
+ teachers_str = teachers.map{|teacher| teacher.user_id}.join(",")
+ if @cur_type == "1" #如果当前是老师未批列表,需要刷新整个作业列表界面
+ @bid = @homework.bid
+ get_not_batch_homework_list "s_socre","desc",teachers_str,@homework.bid_id
+ elsif @cur_type == "2" #老师已批列表
+ @result_homework = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*,
+ (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (#{teachers_str}) and stars IS NOT NULL) AS t_score,
+ (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN (#{teachers_str})) AS s_score
+ FROM homework_attaches WHERE id = #{@homework.id}").first
+ elsif @cur_type == "3" #全部作业列表
+ @result_homework = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*,
+ (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id in (#{teachers_str})) AS t_score,
+ (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id not in (#{teachers_str})) AS s_score
+ FROM homework_attaches WHERE id = #{@homework.id}").first
+ elsif @cur_type == "4" #匿评作业列表
+ @is_student_batch_homework = true
+ @result_homework = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*,
+ (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (#{teachers_str})) AS t_score,
+ (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN (#{teachers_str})) AS s_score,
+ (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{User.current.id}) AS m_score
+ FROM homework_attaches
+ WHERE homework_attaches.id = #{@homework.id}").first
+ else #其他的不用管
+
+ end
respond_to do |format|
format.js
@@ -587,16 +591,7 @@ class HomeworkAttachController < ApplicationController
#获取课程的老师列表
def find_course_teachers course
- teachers = "("
- teacher_members = searchTeacherAndAssistant(course)
- teacher_members.each do |member|
- if member == teacher_members.last
- teachers += member.user_id.to_s + ")"
- else
- teachers += member.user_id.to_s + ","
- end
- end
- teachers
+ searchTeacherAndAssistant(course).map{|teacher| teacher.user_id}.join(",")
end
#获取作业教师评分所占比例
@@ -608,5 +603,22 @@ class HomeworkAttachController < ApplicationController
end
teacher_proportion
end
+
+ def get_not_batch_homework_list sort,direction,teachers,bid_id
+ if sort == 't_socre'
+ order_by = "t_score #{direction}"
+ elsif sort == 's_socre'
+ order_by = "s_score #{direction}"
+ elsif sort == 'time'
+ order_by = "created_at #{direction}"
+ end
+ all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*,
+ (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (#{teachers})) AS t_score,
+ (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN (#{teachers})) AS s_score
+ FROM homework_attaches WHERE bid_id = #{bid_id}
+ ORDER BY #{order_by}) AS table1
+ WHERE table1.t_score IS NULL")
+ @homework_list = paginateHelper all_homework_list,10
+ end
end
diff --git a/app/controllers/school_controller.rb b/app/controllers/school_controller.rb
index a7bf1edb8..008fe00fc 100644
--- a/app/controllers/school_controller.rb
+++ b/app/controllers/school_controller.rb
@@ -58,7 +58,7 @@ class SchoolController < ApplicationController
options_s = ""
school.each do |s|
- options_s << "
#{s.name} "
+ options_s << "#{s.name} "
end
res = Hash.new
@@ -78,7 +78,7 @@ class SchoolController < ApplicationController
@school.each do |s|
#options << "#{s.name} "
- options << "#{s.name} "
+ options << "#{s.name} "
end
@@ -91,7 +91,7 @@ class SchoolController < ApplicationController
options = ""
@school.each do |s|
- options << "#{s.name} "
+ options << "#{s.name} "
end
render :text => options
@@ -105,7 +105,7 @@ class SchoolController < ApplicationController
options = ""
@school.each do |s|
- options << " #{s.name} "
+ options << " #{s.name} "
end
options = "#{l(:label_school_not_fount)}
" if options.blank?
diff --git a/app/controllers/stores_controller.rb b/app/controllers/stores_controller.rb
index a68d12517..b1705c826 100644
--- a/app/controllers/stores_controller.rb
+++ b/app/controllers/stores_controller.rb
@@ -26,19 +26,19 @@ class StoresController < ApplicationController
resultSet = Attachment.where("attachments.container_type IS NOT NULL AND filename LIKE :like ", like: "%#{keywords}%").
reorder("created_on DESC")
- # result = resultSet.to_a.dup
+ result = resultSet.to_a.dup
- # resultSet.to_a.map { |res|
- # if(res.container.nil? ||
- # (res.container.class.to_s=="Project" && res.container.is_public == false) ||
- # (res.container.has_attribute?(:project) && res.container.project.is_public == false) ||
- # (res.container.class.to_s=="HomeworkAttach" && res.container.bid.reward_type == 3) ||
- # false
- # )
- # result.delete(res)
- # end
- # }
- # result
+ resultSet.to_a.map { |res|
+ if(res.container.nil? ||
+ (res.container.class.to_s=="Project" && res.container.is_public == false) ||
+ (res.container.has_attribute?(:project) && res.container.project.is_public == false) ||
+ (res.container.class.to_s=="HomeworkAttach" && res.container.bid.reward_type == 3) ||
+ false
+ ) || (res.container.is_a?(Course) && res.container.is_public == 0)
+ result.delete(res)
+ end
+ }
+ result
end
LIMIT = 12 unless const_defined?(:LIMIT)
diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb
index 4e7768785..89fa0e1dc 100644
--- a/app/controllers/words_controller.rb
+++ b/app/controllers/words_controller.rb
@@ -47,7 +47,6 @@ class WordsController < ApplicationController
# 删除留言功能要调用destroy,也记得在destroy.js中修改
# deny api. api useless
- @show_real_name = params[:show_real_name] || false
parent_id = params[:reference_id]
author_id = User.current.id
reply_user_id = params[:reference_user_id]
diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb
index 6cbe0dd95..cee26ae32 100644
--- a/app/controllers/zipdown_controller.rb
+++ b/app/controllers/zipdown_controller.rb
@@ -44,7 +44,7 @@ class ZipdownController < ApplicationController
if homework != nil
unless homework.attachments.empty?
zipfile = zip_homework_by_user homework
- send_file zipfile, :filename => homework.name+".zip", :type => detect_content_type(zipfile) if(zipfile)
+ send_file zipfile, :filename => homework.user.user_extensions.student_id + "_" + homework.user.lastname + homework.user.firstname + "_" + homework.name+".zip", :type => detect_content_type(zipfile) if(zipfile)
else
render file: 'public/no_file_found.html'
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 9c5d8c9b5..8c2542aa2 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -251,7 +251,7 @@ module ApplicationHelper
end
def toggle_link(name, id, options={})
- onclick = "$('##{id}').toggle(); "
+ onclick = "$('##{id}').slideToggle(); "
onclick << (options[:focus] ? "$('##{options[:focus]}').focus(); " : "this.blur(); ")
onclick << "return false;"
link_to(name, "#", :onclick => onclick)
diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb
index 3c882d393..50dd79a08 100644
--- a/app/helpers/attachments_helper.rb
+++ b/app/helpers/attachments_helper.rb
@@ -67,6 +67,28 @@ module AttachmentsHelper
end
end
+ def course_contains_attachment? course,attachment
+ course.attachments.each do |att|
+ if att.id == attachment.id || (!att.copy_from.nil? && !attachment.copy_from.nil? && att.copy_from == attachment.copy_from) || att.copy_from == attachment.id || att.id == attachment.copy_from
+ return true
+ end
+ end
+ false
+ end
+
+ def get_qute_number attachment
+ if attachment.copy_from
+ result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.copy_from}")
+ else
+ result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.id}")
+ end
+ if result.nil? || result.count <= 0
+ return 0
+ else
+ return result[0].number
+ end
+ end
+
private
def deletable? container, user=User.current
diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb
index 9e18c9f54..ccca6be9d 100644
--- a/app/helpers/courses_helper.rb
+++ b/app/helpers/courses_helper.rb
@@ -471,9 +471,9 @@ module CoursesHelper
end
#课程实践年份下拉框
- def course_time_option
+ def course_time_option year
type = []
- now_year = Time.now.year
+ now_year = year.nil? ? Time.now.year : (Time.now.year <= year ? Time.now.year : year)
for i in (now_year..now_year + 10)
option = []
option << i
@@ -507,6 +507,20 @@ module CoursesHelper
term
end
+ def course_in_current_or_next_term course
+ is_current_term = false
+ is_next_term = false
+ if course.time == Time.now.year && course.term == cur_course_term
+ is_current_term = true
+ end
+ if cur_course_term == "秋季学期" && course.time == (Time.now.year + 1) && course.term == "春季学期"
+ is_next_term = true
+ elsif cur_course_term == "春季学期" && course.time == Time.now.year && course.term == "秋季学期"
+ is_next_term = true
+ end
+ is_current_term || is_next_term
+ end
+
#获取课程动态
def get_course_activity courses, activities
@course_ids=activities.keys()
diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb
index 399b7be1d..5683b9a05 100644
--- a/app/helpers/files_helper.rb
+++ b/app/helpers/files_helper.rb
@@ -47,18 +47,18 @@ module FilesHelper
def courses_check_box_tags(name,courses,current_course,attachment)
s = ''
courses.each do |course|
- if !(attachment.container_type && attachment.container_id == course.id) && is_course_teacher(User.current,course)
- s << "#{ check_box_tag name, course.id, false, :id => nil } #{h course.name} "
+ if !(attachment.container_type && attachment.container_id == course.id) && is_course_teacher(User.current,course) && course_in_current_or_next_term(course)
+ s << "#{ check_box_tag name, course.id, false, :id => nil } #{h course.name} [#{get_course_term course}] "
end
end
s.html_safe
end
- #判断用户是否拥有课程,需用户在该课程中角色为教师
- def has_course? user
+ #判断用户是否拥有除current_course以外的课程,需用户在该课程中角色为教师且该课程属于当前学期或下一学期
+ def has_course? user,current_course
result = false
user.courses.each do |course|
- if is_course_teacher(user,course)
+ if current_course.id != course.id && is_course_teacher(User.current,course) && course_in_current_or_next_term(course)
return true
end
end
@@ -86,17 +86,33 @@ module FilesHelper
def visable_attachemnts attachments
result = []
attachments.each do |attachment|
- if attachment.is_public? || attachment.author_id == User.current.id
+ if attachment.is_public? || (attachment.container_type == "Course" && User.current.member_of_course?(Course.find(attachment.container_id)))|| attachment.author_id == User.current.id
result << attachment
end
end
result
end
- def get_qute_number attachment
- if attachment.copy_from.nil?
- return 0
+ def visable_attachemnts_incourse attachments
+ result = []
+ attachments.each do |attachment|
+ if attachment.is_public? || (attachment.author.member_of_course?(Course.find(attachment.container_id)))|| attachment.author_id == User.current.id
+ result << attachment
+ end
+ end
+ result
+ end
+
+ def visable_attachemnts_insite attachments,course
+ result = []
+ attachments.each do |attachment|
+ if attachment.is_public? || (attachment.container_type == "Course" && attachment.container_id == course.id && User.current.member_of_course?(Course.find(attachment.container_id)))|| attachment.author_id == User.current.id
+ result << attachment
+ end
end
- count = Attachment.find_by_sql("select count(*) from attachments where copy_from = #{attachment.copy_from}")
+ result
end
+
+
+
end
\ No newline at end of file
diff --git a/app/helpers/homework_attach_helper.rb b/app/helpers/homework_attach_helper.rb
index 63332e564..1ab1cb928 100644
--- a/app/helpers/homework_attach_helper.rb
+++ b/app/helpers/homework_attach_helper.rb
@@ -87,8 +87,8 @@ module HomeworkAttachHelper
#获取用户对作业的评分
def get_homework_score user, homework
- seems_rateable_rate = HomeworkAttach.find_by_sql("SELECT * FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = #{homework.id} AND rater_id = #{user.id}")
- seems_rateable_rate.nil? || seems_rateable_rate.count == 0 ? 0:seems_rateable_rate[0].stars
+ temp = HomeworkAttach.find_by_sql("SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = #{homework.id} AND rater_id = #{user.id}").first
+ @m_score = temp.nil? ? 0:temp.stars.to_i
end
def convert_array array
diff --git a/app/models/course.rb b/app/models/course.rb
index 099ae7ae5..ef42d91e8 100644
--- a/app/models/course.rb
+++ b/app/models/course.rb
@@ -7,7 +7,7 @@ class Course < ActiveRecord::Base
STATUS_ARCHIVED = 9
attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period, :open_student
- belongs_to :project, :class_name => 'Course', :foreign_key => :extra, primary_key: :identifier
+ #belongs_to :project, :class_name => 'Course', :foreign_key => :extra, primary_key: :identifier
belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher,该方法通过tea_id来调用User表
belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school,该方法通过school_id来调用School表
has_many :bid
@@ -33,7 +33,7 @@ class Course < ActiveRecord::Base
acts_as_taggable
acts_as_nested_set :order => 'name', :dependent => :destroy
- acts_as_attachable :view_permission => :view_files,
+ acts_as_attachable :view_permission => :view_course_files,
:delete_permission => :manage_files
validates_presence_of :password, :term,:name,:description
diff --git a/app/models/user.rb b/app/models/user.rb
index 29709519d..ef327f47f 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -930,7 +930,7 @@ class User < Principal
def validate_password_length
# Password length validation based on setting
- if !password.nil? && password.size < Setting.password_min_length.to_i
+ if password.nil? || password.size < Setting.password_min_length.to_i
errors.add(:password, :too_short, :count => Setting.password_min_length.to_i)
end
end
diff --git a/app/views/attachments/add_exist_file_to_courses.js.erb b/app/views/attachments/add_exist_file_to_courses.js.erb
index 23761647f..eec1e255a 100644
--- a/app/views/attachments/add_exist_file_to_courses.js.erb
+++ b/app/views/attachments/add_exist_file_to_courses.js.erb
@@ -1,5 +1,7 @@
-<% if !@save_flag%>
+<% if !@save_flag && @save_message %>
$("#error_show").html("<%= @save_message.join(', ') %>");
+<% elsif @message && @message != "" %>
+ $("#error_show").html("<%= @message.html_safe %>");
<% else %>
closeModal();
<% end %>
diff --git a/app/views/bids/_bid_homework_show.html.erb b/app/views/bids/_bid_homework_show.html.erb
index 630d7552c..e7b58fefc 100644
--- a/app/views/bids/_bid_homework_show.html.erb
+++ b/app/views/bids/_bid_homework_show.html.erb
@@ -68,7 +68,7 @@
<% end %>
<% end %>
- <% if (User.current.admin?||User.current.id==bid.author_id) %>
+ <% if (User.current.admin?||User.current.allowed_to?(:as_teacher,@course)) %>
<% if bid.open_anonymous_evaluation == 1 && bid.homeworks.count >= 2%>