This commit is contained in:
z9hang 2014-12-29 17:45:05 +08:00
commit 058d19f8d5
15 changed files with 293 additions and 131 deletions

View File

@ -759,6 +759,18 @@ class ApplicationController < ActionController::Base
end
end
def paginateHelper_for_members obj, pre_size=10
@obj_count = StudentsForCourse.find_by_sql("select count(id) as mem_count from students_for_courses where course_id = #{@course.id}")[0][:mem_count].to_s.to_i
@obj_pages = Paginator.new @obj_count, pre_size, params['page']
if obj.kind_of? ActiveRecord::Base or obj.kind_of? ActiveRecord::Relation
obj.limit(@obj_pages.per_page).offset(0)
elsif obj.kind_of? Array
obj[0, @obj_pages.per_page]
else
logger.error "[ApplicationController] Error : application_controller#paginateHelper ===> unknow category: #{obj.class}"
raise RuntimeError, 'unknow type, Please input you type into this helper.'
end
end
#查找首页相关信息
def find_first_page

View File

@ -492,27 +492,18 @@ class BidsController < ApplicationController
if @bid.homework_type
@homework = HomeworkAttach.new
@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
all_homework_list = HomeworkAttach.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 is_teacher_score = 1) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) 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
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
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 is_teacher_score = 1) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) 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} AND is_teacher_score = #{@is_teacher ? 1 : 0}) 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")
@ -1056,17 +1047,8 @@ class BidsController < ApplicationController
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}
@bid.homeworks.map { |homework| @cur_size += homework.rates(:quality).where("seems_rateable_rates.rater_id is_teacher_score = 0").count}
end
@percent = format("%.2f",(@cur_size.to_f / ( @totle_size == 0 ? 1 : @totle_size)) * 100)
respond_to do |format|

View File

@ -23,7 +23,7 @@ class CoursesController < ApplicationController
before_filter :require_login, :only => [:join, :unjoin]
#before_filter :allow_join, :only => [:join]
@@result = nil
def join
if User.current.logged?
course = Course.find_by_id params[:object_id]
@ -213,10 +213,11 @@ class CoursesController < ApplicationController
q = "#{params[:name].strip}"
#(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
if params[:incourse]
@results = searchmember_by_name(student_homework_score, q)
@results = searchmember_by_name(student_homework_score(0,0,0), q)
elsif params[:ingroup]
@group = CourseGroup.find(params[:search_group_id])
@results =searchgroupmember_by_name(student_homework_score, @group, q)
@results = searchmember_by_name(student_homework_score(@group.id,0,0), q)
end
@is_remote = true
@result_count = @results.count
@ -285,9 +286,9 @@ class CoursesController < ApplicationController
member.course_group_id = group.id
member.save
@group = group
@members = student_homework_score
@course_groups = @course.course_groups
@membercount = @members.count
search_group_members group
end
def unjoin_group
@ -298,8 +299,7 @@ class CoursesController < ApplicationController
member.save
@group = group
@course_groups = @course.course_groups
@members = student_homework_score
@membercount = @members.count
search_group_members group
end
def searchgroupmembers
@ -309,15 +309,19 @@ class CoursesController < ApplicationController
@is_remote = true
if params[:group_id] && params[:group_id] != "0"
@group = CourseGroup.find(params[:group_id])
@results = student_homework_score.find_all {|mem| mem.course_group_id == @group.id}
@results = student_homework_score(@group.id,0, 0)
@results = paginateHelper @results, 10
else
@results = student_homework_score
page_from = params[:page].nil? ? 0 : (params[:page].to_i - 1)
@results = student_homework_score(0,page_from, 10)
@results = paginateHelper_for_members @results, 10
end
@members = searchStudent(@course)
@membercount = @members.count
@results = paginateHelper @results
end
@ -325,31 +329,36 @@ class CoursesController < ApplicationController
## 有角色参数的才是课程,没有的就是项目
if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course)))
@render_file = 'member_list'
@teachers= searchTeacherAndAssistant(@course)
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
@role = params[:role]
@is_remote = false
@role = params[:role].nil? ? '2':params[:role]
@is_remote = true
@course_groups = @course.course_groups if @course.course_groups
@show_serch = params[:role] == '2'
case params[:role]
case @role
when '1'
@subPage_title = l :label_teacher_list
@members = @teachers
@members = searchTeacherAndAssistant(@course)
@members = paginateHelper @members, 10
when '2'
@subPage_title = l :label_student_list
@members = student_homework_score
page = params[:page].nil? ? 0 : (params['page'].to_i - 1)
@members = student_homework_score(0,page, 10)
# @member_scores = @@member_scores
# @members = searchStudent_sort(@course, 'desc', @@member_scores)
@membercount = @members.count
@members = paginateHelper_for_members @members, 10
end
respond_to do |format|
if params[:page]
format.js
else
@subPage_title = ''
@members = @course.member_principals.includes(:roles, :principal).all.sort
format.html {render :layout => 'base_courses'}
end
end
@members = paginateHelper @members
render :layout => 'base_courses'
# render :layout => 'base_courses'
else
render_403
end
@ -378,19 +387,11 @@ class CoursesController < ApplicationController
respond_to do |format|
format.html {render :layout => 'course_base'}
format.js
end
end
#判断指定用户是否为课程教师
def isCourseTeacher(id)
result = false
if @teachers.find_by_user_id(id) != nil
result = true
end
result
end
def handle_course courses, activities
course_activity_count_array=activities.values()
@ -881,11 +882,13 @@ class CoursesController < ApplicationController
end
end
def student_homework_score
def student_homework_score(groupid,start_from, nums)
#teachers = find_course_teachers(@course)
start_from = start_from * nums
sql = ActiveRecord::Base.connection()
homework_scores = Member.find_by_sql("call member_score(#{@course.id},#{groupid},#{start_from},#{nums})")
homework_scores = Member.find_by_sql("call member_score(#{@course.id})")
sql.close()
homework_scores
end
@ -901,10 +904,10 @@ class CoursesController < ApplicationController
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
@is_remote = true
@members = searchStudent(@course)
@membercount = @members.count
@results = student_homework_score.find_all {|mem| mem.course_group_id == group.id}
@@result = @results
@results = paginateHelper @results
page_from = params[:page].nil? ? 0 : (params[:page].to_i - 1)
@results = student_homework_score(group.id,0,0)
@results = paginateHelper @results, 10
end
end

View File

@ -22,8 +22,7 @@ class HomeworkAttachController < ApplicationController
#获取未批作业列表
def get_not_batch_homework
sort, direction = params[:sort] || "s_socre", params[:direction] || "desc"
teachers = find_course_teachers @course
get_not_batch_homework_list sort,direction,teachers, @bid.id
get_not_batch_homework_list sort,direction, @bid.id
@cur_page = params[:page] || 1
@cur_type = 1
@direction = direction == 'asc'? 'desc' : 'asc'
@ -42,10 +41,9 @@ class HomeworkAttachController < ApplicationController
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}) 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 is_teacher_score = 1 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 is_teacher_score = 0) AS s_score
FROM homework_attaches WHERE bid_id = #{@bid.id}
ORDER BY #{order_by}) AS table1
WHERE table1.t_score IS NOT NULL")
@ -90,10 +88,9 @@ class HomeworkAttachController < ApplicationController
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 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 is_teacher_score = 1) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score
FROM homework_attaches WHERE bid_id = #{@bid.id}
ORDER BY #{order_by}")
@cur_page = params[:page] || 1
@ -108,11 +105,10 @@ class HomeworkAttachController < ApplicationController
#获取学生匿评列表
def get_student_batch_homework
@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 stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{User.current.id}) AS m_score
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) 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} AND is_teacher_score = 0) 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 m_score DESC")
@ -127,17 +123,16 @@ class HomeworkAttachController < ApplicationController
#获取我的作业
def get_my_homework
@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 is_teacher_score = 1) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) 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 is_teacher_score = 1) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) 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}")
@ -380,12 +375,11 @@ class HomeworkAttachController < ApplicationController
# 作业打分列表
@stars_reates = @homework.rates(:quality)
#我的评分
@has_evaluation = @stars_reates.where("rater_id = #{User.current.id}").first
@m_score = @has_evaluation.nil? ? 0 : @has_evaluation.stars
teachers = find_course_teachers(@course)
@teacher_stars = @stars_reates.where("rater_id in (#{teachers})") #老师评分列表
@student_stars = @stars_reates.where("rater_id not in (#{teachers})") #学生评分列表
@is_teacher = is_course_teacher User.current,@course
@has_evaluation = @stars_reates.where("rater_id = #{User.current.id} and is_teacher_score=#{@is_teacher ? 1 : 0}").first
@m_score = @has_evaluation.nil? ? 0 : @has_evaluation.stars
@teacher_stars = @stars_reates.where("is_teacher_score = 1") #老师评分列表
@student_stars = @stars_reates.where("is_teacher_score = 0") #学生评分列表
@is_anonymous_comments = @bid.comment_status == 1 && !@homework.users.include?(User.current) && @homework.user != User.current && !@is_teacher #判断是不是匿评(开启匿评,当前用户不是作业的创建者或者参与者,不是老师)
jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC")#jours留言 is null条件用以兼容历史数据
@jour = paginateHelper jours,5 #留言
@ -407,10 +401,9 @@ class HomeworkAttachController < ApplicationController
@journal_destroyed = JournalsForMessage.find(params[:object_id])
if @journal_destroyed.is_comprehensive_evaluation == 3 && @journal_destroyed.destroy
render_403 unless User.current == @journal_destroyed.user || User.current.admin?
teachers = find_course_teachers(@homework.bid.courses.first)
@stars_reates = @homework.rates(:quality)
@teacher_stars = @stars_reates.where("rater_id in (#{teachers})") #老师评分列表
@student_stars = @stars_reates.where("rater_id not in (#{teachers})") #学生评分列表
@teacher_stars = @stars_reates.where("is_teacher_score = 1)") #老师评分列表
@student_stars = @stars_reates.where("is_teacher_score = 0") #学生评分列表
jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC")#jours留言 is null条件用以兼容历史数据
@jour = paginateHelper jours,5 #留言
else
@ -447,41 +440,48 @@ class HomeworkAttachController < ApplicationController
@is_teacher,@is_anonymous_comments,@m_score = params[:is_teacher]=="true",params[:is_anonymous_comments]=="true",params[:stars_value]
@cur_page,@cur_type = params[:cur_page] || 1,params[:cur_type] || 5
@homework = HomeworkAttach.find(params[:homework_id])
#保存评分
@homework.rate(@m_score.to_i,User.current.id,:quality) if @m_score
is_teacher = @is_teacher ? 1 : 0
#保存评分@homework.rate(@m_score.to_i,User.current.id,:quality, (@is_teacher ? 1 : 0))
if @m_score
rate = @homework.rates(:quality).where(:rater_id => User.current.id, :is_teacher_score => is_teacher).first
if rate
rate.stars = @m_score
rate.save!
else
@homework.rates(:quality).new(:stars => @m_score, :rater_id => User.current.id, :is_teacher_score => is_teacher).save!
end
end
#保存评论
@is_comprehensive_evaluation = @is_teacher ? 1 : (@is_anonymous_comments ? 2 : 3) #判断当前评论是老师评论?匿评?留言
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,@is_comprehensive_evaluation
end
teachers = find_course_teachers(@homework.bid.courses.first)
@stars_reates = @homework.rates(:quality)
@teacher_stars = @stars_reates.where("rater_id in (#{teachers})") #老师评分列表
@student_stars = @stars_reates.where("rater_id not in (#{teachers})") #学生评分列表
@teacher_stars = @stars_reates.where("is_teacher_score = 1") #老师评分列表
@student_stars = @stars_reates.where("is_teacher_score = 0") #学生评分列表
jours = @homework.journals_for_messages.where("is_comprehensive_evaluation = 3 or is_comprehensive_evaluation is null").order("created_on DESC")#jours留言 is null条件用以兼容历史数据
@jour = paginateHelper jours,5 #留言
if @cur_type == "1" #如果当前是老师未批列表,需要刷新整个作业列表界面
@bid = @homework.bid
get_not_batch_homework_list "s_socre","desc",teachers,@homework.bid_id
get_not_batch_homework_list "s_socre","desc",@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}) 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
@result_homework = 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 is_teacher_score = 1 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 is_teacher_score = 0) 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})) 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
@result_homework = 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 is_teacher_score = 1) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) 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})) 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
@result_homework = 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 is_teacher_score = 1) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) 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} AND is_teacher_score = #{is_teacher}) AS m_score
FROM homework_attaches
WHERE homework_attaches.id = #{@homework.id}").first
else #其他的不用管
@ -574,7 +574,7 @@ class HomeworkAttachController < ApplicationController
teacher_proportion
end
def get_not_batch_homework_list sort,direction,teachers,bid_id
def get_not_batch_homework_list sort,direction,bid_id
if sort == 't_socre'
order_by = "t_score #{direction}"
elsif sort == 's_socre'
@ -583,8 +583,8 @@ class HomeworkAttachController < ApplicationController
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
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1) AS t_score,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score
FROM homework_attaches WHERE bid_id = #{bid_id}
ORDER BY #{order_by}) AS table1
WHERE table1.t_score IS NULL")

View File

@ -0,0 +1,3 @@
class SeemsRateableRates < ActiveRecord::Base
attr_accessible :rater_id, :rateable_id, :rateable_type, :stars, :dimension, :is_teacher_score
end

View File

@ -13,7 +13,7 @@
a{ text-decoration:none; }
a:hover{ }
.alert_box {width:488px;height:550px;position:fixed;z-index:1002;left:50%;top:40%;margin:-215px 0 0 -300px; background:#fff; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px; box-shadow:0px 0px 8px #194a81; padding:5px; overflow:auto; }
#popbox{width:488px;height:308px;}
.alert .C{width:476px;height:296px;position:absolute;left:5px;top:5px; }
.C_top{ margin-top:20px; width:368px; height:100px; background:#e9e9e9; padding:0px 60px; }
@ -21,7 +21,7 @@
.C_top p{ color:#a9aaaa; line-height:22px;}
.C_form{ margin:20px 0 0 60px;}
.C_form ul li{ font-size:14px; color:#3f3a39; line-height:30px; }
.C_form ul li input{ margin-left:30px; border:0px; border:1px solid #e1e1e1; color:#898989; padding-left:5px; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px; }
.C_form ul li input{ margin-left:20px; border:0px; border:1px solid #e1e1e1; color:#898989; padding-left:5px; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px; padding: 0 !important; }
.C_form ul li.mB5{ color:#898989; font-size:12px; padding-left:90px;}
.width190{ width:190px; height:26px; border-color:#e1e1e1;}
.C_form a{ font-size:12px; color:#15bccf; float:left; display:block; height:40px; width:200px; margin-top:25px;}
@ -35,6 +35,11 @@
hideModal(obj);
$("#new-watcher-form").submit();
}
function hidden_join_course_form()
{
hideModal($("#popbox"));
}
</script>
</head>
@ -55,6 +60,7 @@
<li>
<span class="tips">课&nbsp;程&nbsp;ID</span>
<input class=" width190" name="object_id" id="object_id" type="text" value="" >
<input type="text" style="display: none"/>
</li>
<li class="mB5">课程ID是所在课程网址中显示的序号</li>
<li>
@ -62,8 +68,12 @@
<input class=" width190" type="password" name="course_password" id="course_password" value="" >
</li>
<li>
<a href="#" class="btn" style="margin-left: 50px;" onclick="submit_form(this);"><%= l(:label_new_join) %></a>
<a href="#" class="btn" style="margin-left: 20px;" onclick="hideModal(this);"><%= l(:button_cancel)%></a>
<a href="#" class="btn" style="margin-left: 50px;" onclick="submit_form(this);">
<%= l(:label_new_join) %>
</a>
<a href="#" class="btn" style="margin-left: 20px;" onclick="hideModal(this);">
<%= l(:button_cancel)%>
</a>
</li>
</ul>
<% end%>

View File

@ -1,3 +1,9 @@
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'join_private_course') %>');
showModal('ajax-modal', '510px');
$('#ajax-modal').css('height','330px');
$('#ajax-modal').css('height','330px');
$('#ajax-modal').siblings().remove();
$('#ajax-modal').before("<span style='float: right;cursor:pointer;padding-left: 513px;'>" +
"<a href='#' onclick='hidden_join_course_form();'><img src='/images/bid/close.png' width='26px' height='26px' /></a></span>");
$('#ajax-modal').parent().removeClass("alert_praise");
$('#ajax-modal').parent().css("top","").css("left","");
$('#ajax-modal').parent().addClass("alert_box");

View File

@ -0,0 +1 @@
$("#member_content").html("<%= escape_javascript( render :partial => @render_file, :locals => {:members => @members})%>");

View File

@ -35,7 +35,7 @@
<tr>
<td colspan="2" width="580px">
<p class="info-break">
<%= h(truncate(strip_tags(e.event_description).gsub(/&nbsp;/, ' '), length: 30, omission: '...')) %>
<%= e.event_description %>
</p>
</td>
</tr>

View File

@ -55,13 +55,19 @@
<% end %>
</span>
<% unless @course_page.nil? %>
<span class="font_welcome_trustie"><%= @course_page.title %> </span>
<span class="font_welcome_trustie">
<%= @course_page.title %>
</span>
<% if @school_id.nil? and (User.current.user_extensions.nil? || User.current.user_extensions.school.nil?) %>
<span class="font_welcome_tdescription">, <%= @course_page.description %></span>
<span class="font_welcome_tdescription">,
<%= @course_page.description %>
</span>
<% else %>
<% if @school_id == "0" %>
<span class="font_welcome_tdescription">, <%= @course_page.description %></span>
<span class="font_welcome_tdescription">,
<%= @course_page.description %>
</span>
<% end %>
<% end %>
<% end %>
@ -77,7 +83,11 @@
<div id="J_Slide" class="d-p-index-box d-p-index-hot">
<h3><strong><%= l(:lable_hot_course)%></strong></h3>
<h3>
<strong>
<%= l(:lable_hot_course)%>
</strong>
</h3>
<% month_now = Time.now.strftime("%m").to_i %>
<% year_now = Time.new.strftime("%Y") %>
@ -86,7 +96,9 @@
<% @school_id.nil? ? cur_school_course = [] : cur_school_course = find_miracle_course(10,7,@school_id, year_now, course_term) %>
<% if cur_school_course.count == 0 %>
<span><%= render :partial => 'more_course', :locals => {:school_id => nil}%></span>
<span>
<%= render :partial => 'more_course', :locals => {:school_id => nil}%>
</span>
<div class="d-p-projectlist-box">
<ul class="d-p-projectlist">
<% if User.current.logged? %>

View File

@ -0,0 +1,5 @@
class AddColumToSeemsRateableRates < ActiveRecord::Migration
def change
add_column :seems_rateable_rates, :is_teacher_score, :integer, default: 0
end
end

View File

@ -0,0 +1,27 @@
class ChangeSeemsRateableRates < ActiveRecord::Migration
def up
Course.all.each do |course|
teachers = []
course.members.each do |m|
teachers << m.user_id if m && m.user && m.user.allowed_to?(:as_teacher,course)
end
course.homeworks.each do |bid|
bid.homeworks.each do |homework|
SeemsRateableRates.where("rateable_type = 'HomeworkAttach' and rateable_id = #{homework.id}").each do |rate|
if teachers.include?(rate.rater_id)
rate.is_teacher_score = 1
rate.save
end
end
end
end
end
end
def down
SeemsRateableRates.where("is_teacher_score = 1").each do |rate|
rate.is_teacher_score = 0
rate.save
end
end
end

View File

@ -0,0 +1,100 @@
class ProMemberScore < ActiveRecord::Migration
def up
sql_delete = ("DROP PROCEDURE IF EXISTS `member_score`;")
sql = ("
CREATE PROCEDURE `member_score`(IN courseid INT, IN groupid INT,IN start_from INT, IN nums INT)
BEGIN
CREATE TEMPORARY TABLE IF NOT EXISTS course_teachers (
id INT
);
TRUNCATE TABLE course_teachers;
CREATE TEMPORARY TABLE IF NOT EXISTS mems (
id INT ,
user_id INT,
course_id INT,
created_on DATETIME,
course_group_id INT,
score FLOAT DEFAULT 0
);
TRUNCATE TABLE mems;
CREATE TEMPORARY TABLE IF NOT EXISTS mem_home (
id INT,
user_id INT,
course_id INT,
created_on DATETIME,
course_group_id INT,
home_id INT,
score FLOAT DEFAULT 0
);
TRUNCATE TABLE mem_home;
CREATE TEMPORARY TABLE IF NOT EXISTS t_scores (
home_id INT,
score FLOAT
);
TRUNCATE TABLE t_scores;
CREATE TEMPORARY TABLE IF NOT EXISTS s_scores (
home_id INT,
score FLOAT
);
TRUNCATE TABLE s_scores;
CREATE TEMPORARY TABLE IF NOT EXISTS scores (
user_id INT,
score FLOAT
);
TRUNCATE TABLE scores;
INSERT INTO course_teachers (SELECT members.user_id FROM members WHERE members.user_id NOT IN (SELECT student_id FROM students_for_courses WHERE course_id = courseid));
INSERT INTO mems (id, user_id, course_id, created_on, course_group_id)
(SELECT members.id, members.user_id, members.course_id, members.created_on, members.course_group_id
FROM members WHERE course_id = courseid AND members.user_id NOT IN (SELECT id FROM course_teachers));
INSERT INTO mem_home (id, user_id, course_id, created_on, course_group_id,home_id)
(SELECT members.id, members.user_id, members.course_id, members.created_on, members.course_group_id, homework_attaches.id
FROM members, homework_attaches WHERE course_id = courseid
AND members.user_id = homework_attaches.user_id AND members.user_id NOT IN (SELECT id FROM course_teachers)
AND homework_attaches.bid_id IN (SELECT bid_id FROM homework_for_courses WHERE course_id = courseid ));
INSERT INTO t_scores (home_id, score) (SELECT rateable_id,AVG(seems_rateable_rates.stars)
FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id IN (SELECT mem_home.home_id FROM mem_home)
AND rater_id IN (SELECT id FROM course_teachers)
GROUP BY rateable_id);
INSERT INTO s_scores (home_id, score) (SELECT rateable_id,AVG(seems_rateable_rates.stars)
FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id IN (SELECT mem_home.home_id FROM mem_home)
AND rater_id NOT IN (SELECT id FROM course_teachers)
GROUP BY rateable_id) ;
UPDATE mem_home, t_scores SET mem_home.score = t_scores.score WHERE mem_home.home_id = t_scores.home_id ;
UPDATE mem_home, s_scores SET mem_home.score = s_scores.score WHERE mem_home.home_id = s_scores.home_id AND mem_home.score = 0;
INSERT INTO scores (user_id, score) (SELECT user_id, SUM(score) FROM mem_home GROUP BY user_id);
UPDATE mems, scores SET mems.score = scores.score WHERE mems.user_id = scores.user_id;
IF nums <> 0 THEN
SELECT * FROM mems ORDER BY score DESC LIMIT start_from, nums;
ELSE
SELECT * FROM mems WHERE course_group_id = groupid ORDER BY score DESC;
END IF;
END;
")
execute(sql_delete)
execute(sql)
end
def down
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20141226074532) do
ActiveRecord::Schema.define(:version => 20141229025925) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -977,13 +977,14 @@ ActiveRecord::Schema.define(:version => 20141226074532) do
end
create_table "seems_rateable_rates", :force => true do |t|
t.integer "rater_id", :limit => 8
t.integer "rater_id", :limit => 8
t.integer "rateable_id"
t.string "rateable_type"
t.float "stars", :null => false
t.float "stars", :null => false
t.string "dimension"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "is_teacher_score", :default => 0
end
create_table "settings", :force => true do |t|

View File

@ -37,9 +37,9 @@ module SeemsRateable
def update_users_rating(stars, user_id, dimension=nil)
obj = rates(dimension).where(:rater_id => user_id).first
#current_record = average(dimension)
#current_record.avg = (current_record.avg*current_record.cnt - obj.stars + stars) / (current_record.cnt)
#current_record.save!
current_record = average(dimension)
current_record.avg = (current_record.avg*current_record.cnt - obj.stars + stars) / (current_record.cnt)
current_record.save!
obj.stars = stars
obj.save!
end