个人课程列表、作业详情、作品详情

This commit is contained in:
= 2014-12-17 14:50:57 +08:00
parent f9aa145c2b
commit 428d1b6415
2 changed files with 221 additions and 142 deletions

View File

@ -0,0 +1,63 @@
class HomeworkService
#作业详情(老师才显示启动匿评,学生不显示
#bid.comment_status=0 启动匿评
#bid.comment_status=1 关闭匿评
#many_times 第几次(作业)
#is_teacher 判断是否为该课程老师
def show_homework params
@bid = Bid.find(params[:id])
course = @bid.courses.first
is_teacher = is_course_teacher(User.current,course)
author = @bid.author.firstname + @bid.author.lastname
many_times = course.homeworks.index(@bid) + 1
name = @bid.name
homework_count = @bid.homeworks.count
description = @bid.description
if is_teacher && bid.open_anonymous_evaluation == 1 && bid.homeworks.count >= 2
case bid.comment_status
when 0
alert_anonymous_comment_bid_path(bid)
when 1
alert_anonymous_comment_bid_path(bid)
when 2
raise '匿评结束'
end
end
end
#启动作业匿评
def alert_homework_anonymous_comment params
@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)
end
#匿评作品详情
def anonymous_works_show params
@homework = HomeworkAttach.find(params[:id])
if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first)
end
end
#
end

View File

@ -2,6 +2,7 @@ class UsersService
include ApplicationHelper
include AccountHelper
include AvatarHelper
include CoursesHelper
#将用户注册的功能函数写这里
#参数约定
#成功返回注册后的User实例失败直接抛异常
@ -112,6 +113,21 @@ class UsersService
User.watched_by(@user.id)
end
#用户课程列表
def user_courses_list params
if !User.current.admin? && !@user.active?
raise '404'
return
end
if User.current == @user || User.current.admin?
membership = @user.coursememberships.all
else
membership = @user.coursememberships.all(:conditions => Course.visible_condition(User.current))
end
membership.sort! {|older, newer| newer.created_on <=> older.created_on }
membership
end
#修改密码
def change_password params
@current_user = User.find(params[:current_user_id])