@ -200,7 +200,7 @@ class BidsController < ApplicationController
flash [ :notice ] = l ( :label_bid_succeed )
end
end
redirect_to respon d_path( @homework )
redirect_to course_for_bi d_path( @homework )
else
@bid . safe_attributes = params [ :bid ]
@courses = [ ]
@ -454,6 +454,7 @@ class BidsController < ApplicationController
# 显示作业课程
# add by nwb
def show_courseEx
if ( User . current . logged? && ( User . current . member_of_course? ( @bid . courses . first ) || User . current . admin? ) )
# flash[:notice] = ""
@membership = User . current . coursememberships . all ( :conditions = > Course . visible_condition ( User . current ) )
@ -489,26 +490,38 @@ class BidsController < ApplicationController
if @bid . homework_type
@homework = HomeworkAttach . new
if @bid . proportion
teacher_proportion = @bid . proportion * 1 . 0 / 100
@is_teacher = is_course_teacher ( User . current , @bid . courses . first )
teachers = " ( "
teacher_members = searchTeacherAndAssistant ( @bid . courses . first )
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
if @is_teacher
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 s_score DESC,created_at ASC) AS table1
WHERE table1 . t_score IS NULL " )
@cur_type = 1
else
teacher_proportion = 1 . 0
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 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
WHERE homework_attaches . bid_id = #{@bid.id} AND homework_evaluations.user_id = #{User.current.id} ORDER BY s_score DESC")
@is_student_batch_homework = true
@cur_type = 4
end
#@homework_list = @bid.homeworks
#增加作业按评分排序,
#@homework_list = @bid.homeworks.eager_load(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC').order("#{HomeworkAttach.table_name}.created_at ASC")
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 = #{@bid.author_id}) AS t_score,
( SELECT AVG ( stars ) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches . id AND rater_id < > #{@bid.author_id}) AS s_score
FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY
( CASE WHEN t_score IS NULL THEN 0 ELSE t_score * #{teacher_proportion} END + CASE WHEN s_score IS NULL THEN 0 ELSE s_score * #{1 - teacher_proportion} END) DESC,created_at ASC")
limit = 10
feedback_count = all_homework_list . count
@feedback_pages = Paginator . new feedback_count , limit , params [ 'page' ]
offset || = @feedback_pages . offset
@homework_list = all_homework_list [ offset , limit ]
@cur_page = params [ :page ] || 1
@homework_list = paginateHelper all_homework_list , 10
@jours_count = @bid . journals_for_messages . where ( 'm_parent_id IS NULL' ) . count
if params [ :student_id ] . present?
@temp = [ ]
@homework_list . each do | pro |
@ -635,13 +648,8 @@ class BidsController < ApplicationController
end
@user = @bid . author
@jours = @bid . 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
@bid . set_commit ( @feedback_count )
respond_to do | format |
format . js
#format.api { render_api_ok }
@ -797,6 +805,7 @@ class BidsController < ApplicationController
@bid . description = params [ :bid ] [ :description ]
@bid . is_evaluation = params [ :bid ] [ :is_evaluation ]
@bid . proportion = params [ :bid ] [ :proportion ]
@bid . evaluation_num = params [ :bid ] [ :evaluation_num ]
@bid . reward_type = 3
# @bid.budget = params[:bid][:budget]
@bid . deadline = params [ :bid ] [ :deadline ]
@ -813,7 +822,7 @@ class BidsController < ApplicationController
flash [ :notice ] = l ( :label_bid_succeed )
end
end
redirect_to respond_url( @bid )
redirect_to course_homework_url( params [ :course_id ] )
else
@bid . safe_attributes = params [ :bid ]
@homework = @bid
@ -852,6 +861,7 @@ class BidsController < ApplicationController
@bid . description = params [ :bid ] [ :description ]
@bid . is_evaluation = params [ :bid ] [ :is_evaluation ]
@bid . proportion = params [ :bid ] [ :proportion ]
@bid . evaluation_num = params [ :bid ] [ :evaluation_num ]
@bid . reward_type = 3
@bid . deadline = params [ :bid ] [ :deadline ]
@bid . budget = 0
@ -991,8 +1001,81 @@ class BidsController < ApplicationController
def manage
end
# 启动匿评
def start_anonymous_comment
@bid = Bid . find ( params [ :id ] )
@course = @bid . courses . first
if ( @bid . comment_status == 0 )
homeworks = @bid . homeworks
if ( homeworks && homeworks . size > = 2 )
homeworks . each_with_index do | homework , index |
user = homework . user
n = @bid . evaluation_num
n = n < homeworks . size ? n : homeworks . size - 1
assigned_homeworks = get_assigned_homeworks ( homeworks , n , index )
assigned_homeworks . each do | h |
@homework_evaluation = HomeworkEvaluation . new ( user_id : user . id , homework_attach_id : h . id )
@homework_evaluation . save
end
end
@bid . update_column ( 'comment_status' , 1 )
@statue = 1
else
@statue = 2
end
else
@statue = 3
end
respond_to do | format |
format . js
end
end
def stop_anonymous_comment
@bid = Bid . find ( params [ :id ] )
@bid . update_column ( 'comment_status' , 2 )
respond_to do | format |
format . js
end
end
def alert_anonymous_comment
@bid = Bid . find params [ :id ]
@course = @bid . courses . first
if @bid . comment_status == 0
@totle_size = searchStudent ( @course ) . size
@cur_size = @bid . homeworks . size
elsif @bid . comment_status == 1
@totle_size = 0
@bid . homeworks . map { | homework | @totle_size += homework . homework_evaluations . count }
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
@cur_size = 0
@bid . homeworks . map { | homework | @cur_size += homework . rates ( :quality ) . where ( " seems_rateable_rates.rater_id not in #{ teachers } " ) . count }
end
@percent = format ( " %.2f " , ( @cur_size . to_f / ( @totle_size == 0 ? 1 : @totle_size ) ) * 100 )
respond_to do | format |
format . js
end
end
private
def get_assigned_homeworks ( homeworks , n , index )
homeworks += homeworks
homeworks [ index + 1 .. index + n ]
end
def find_bid
if params [ :id ]
@ -1026,6 +1109,5 @@ class BidsController < ApplicationController
render_404
end
end
end