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

api
= 11 years ago
parent f9aa145c2b
commit 428d1b6415

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

@ -1,142 +1,158 @@
class UsersService class UsersService
include ApplicationHelper include ApplicationHelper
include AccountHelper include AccountHelper
include AvatarHelper include AvatarHelper
#将用户注册的功能函数写这里 include CoursesHelper
#参数约定 #将用户注册的功能函数写这里
#成功返回注册后的User实例失败直接抛异常 #参数约定
#成功返回注册后的User实例失败直接抛异常
def register(params)
@user = User.new def register(params)
@user.admin = false @user = User.new
@user.register @user.admin = false
@user.login = params[:login] @user.register
@user.mail = params[:mail] @user.login = params[:login]
password = params[:password] @user.mail = params[:mail]
password_confirmation = params[:password_confirmation] password = params[:password]
should_confirmation_password = params[:should_confirmation_password] password_confirmation = params[:password_confirmation]
if !password.blank? && !password_confirmation.blank? && should_confirmation_password should_confirmation_password = params[:should_confirmation_password]
@user.password, @user.password_confirmation = password, password_confirmation if !password.blank? && !password_confirmation.blank? && should_confirmation_password
elsif !password.blank? && !should_confirmation_password @user.password, @user.password_confirmation = password, password_confirmation
@user.password = password elsif !password.blank? && !should_confirmation_password
else @user.password = password
@user.password = "" else
end @user.password = ""
case Setting.self_registration end
when '1' case Setting.self_registration
@user = email_activation_register(@user) when '1'
when '3' @user = email_activation_register(@user)
@user = automatically_register(@user) when '3'
else @user = automatically_register(@user)
@user = administrator_manually__register(@user) else
end @user = administrator_manually__register(@user)
if @user.id != nil end
ue = @user.user_extensions ||= UserExtensions.new if @user.id != nil
ue.user_id = @user.id ue = @user.user_extensions ||= UserExtensions.new
ue.save ue.user_id = @user.id
end ue.save
@user end
end @user
end
#显示用户
#id用户id #显示用户
def show_user(params) #id用户id
@user = User.find(params[:id]) def show_user(params)
img_url = url_to_avatar(@user) @user = User.find(params[:id])
gender = @user.user_extensions.gender.nil? ? 0 : @user.user_extensions.gender img_url = url_to_avatar(@user)
work_unit = "" gender = @user.user_extensions.gender.nil? ? 0 : @user.user_extensions.gender
if @user.user_extensions.identity == 0 || @user.user_extensions.identity == 1 work_unit = ""
work_unit = @user.user_extensions.school.name unless @user.user_extensions.school.nil? if @user.user_extensions.identity == 0 || @user.user_extensions.identity == 1
elsif @user.user_extensions.identity == 3 work_unit = @user.user_extensions.school.name unless @user.user_extensions.school.nil?
work_unit = @user.user_extensions.occupation elsif @user.user_extensions.identity == 3
elsif @user.user_extensions.identity == 2 work_unit = @user.user_extensions.occupation
work_unit = @user.firstname elsif @user.user_extensions.identity == 2
end work_unit = @user.firstname
location = "" end
location << (@user.user_extensions.location || '') location = ""
location << (@user.user_extensions.location_city || '') location << (@user.user_extensions.location || '')
{:id => @user.id, :img_url => img_url, :nickname => @user.login, :gender => gender, :work_unit => work_unit, :mail => @user.mail, :location => location, :brief_introduction => @user.user_extensions.brief_introduction} location << (@user.user_extensions.location_city || '')
end {:id => @user.id, :img_url => img_url, :nickname => @user.login, :gender => gender, :work_unit => work_unit, :mail => @user.mail, :location => location, :brief_introduction => @user.user_extensions.brief_introduction}
end
#编辑用户
#gender 1female 0male 其他male #编辑用户
def edit_user params #gender 1female 0male 其他male
@user = User.find(params[:id]) def edit_user params
fileio = params[:file] @user = User.find(params[:id])
fileio = params[:file]
@se = @user.extensions
if @user.user_extensions.identity == 0 || @user.user_extensions.identity == 1 @se = @user.extensions
@se.school_id = params[:occupation] if @user.user_extensions.identity == 0 || @user.user_extensions.identity == 1
elsif @user.user_extensions.identity == 3 @se.school_id = params[:occupation]
@se.occupation = params[:occupation] elsif @user.user_extensions.identity == 3
elsif @user.user_extensions.identity == 2 @se.occupation = params[:occupation]
@user.firstname = params[:occupation] elsif @user.user_extensions.identity == 2
end @user.firstname = params[:occupation]
@se.brief_introduction = params[:brief_introduction] end
@se.gender = params[:gender] @se.brief_introduction = params[:brief_introduction]
@se.location = params[:province] if params[:province] @se.gender = params[:gender]
@se.location_city = params[:city] if params[:city] @se.location = params[:province] if params[:province]
raise @se.errors.full_message unless @se.save @se.location_city = params[:city] if params[:city]
unless fileio.nil? raise @se.errors.full_message unless @se.save
file = fileio[:tempfile] unless fileio.nil?
diskfile=disk_filename(@user.class.to_s, @user.id) file = fileio[:tempfile]
@image_file = fileio[:name] diskfile=disk_filename(@user.class.to_s, @user.id)
@urlfile='/' << File.join("images", "avatars", avatar_directory(@user.class.to_s), avatar_filename(@user.id, @image_file)) @image_file = fileio[:name]
@urlfile='/' << File.join("images", "avatars", avatar_directory(@user.class.to_s), avatar_filename(@user.id, @image_file))
path = File.dirname(diskfile)
unless File.directory?(path) path = File.dirname(diskfile)
FileUtils.mkdir_p(path) unless File.directory?(path)
end FileUtils.mkdir_p(path)
File.rename(file.path, @urlfile) end
begin File.rename(file.path, @urlfile)
f = Magick::ImageList.new(diskfile) begin
# gif格式不再做大小处理 f = Magick::ImageList.new(diskfile)
if f.format != 'GIF' # gif格式不再做大小处理
width = 300.0 if f.format != 'GIF'
proportion = (width/f[0].columns) width = 300.0
height = (f[0].rows*proportion) proportion = (width/f[0].columns)
f.resize_to_fill!(width, height) height = (f[0].rows*proportion)
f.write(diskfile) f.resize_to_fill!(width, height)
end f.write(diskfile)
end
rescue Exception => e
logger.error "[Error] avatar : users_service#edit_user ===> #{e}" rescue Exception => e
end logger.error "[Error] avatar : users_service#edit_user ===> #{e}"
end end
@se end
end @se
end
#关注列表
def user_watcher params #关注列表
@user = User.find(params[:id]) def user_watcher params
User.watched_by(@user.id) @user = User.find(params[:id])
end User.watched_by(@user.id)
end
#修改密码
def change_password params #用户课程列表
@current_user = User.find(params[:current_user_id]) def user_courses_list params
if @current_user.check_password?(params[:password]) if !User.current.admin? && !@user.active?
@current_user.password, @current_user.password_confirmation = params[:new_password], params[:new_password_confirmation] raise '404'
@current_user.save return
#raise @current_user.errors.full_message end
#return @current_user if User.current == @user || User.current.admin?
membership = @user.coursememberships.all
else else
raise 'wrong password' membership = @user.coursememberships.all(:conditions => Course.visible_condition(User.current))
end end
@current_user membership.sort! {|older, newer| newer.created_on <=> older.created_on }
end membership
end
#搜索用户
def search_user params #修改密码
@status = params[:status] || 1 def change_password params
has = { @current_user = User.find(params[:current_user_id])
"show_changesets" => true if @current_user.check_password?(params[:password])
} @current_user.password, @current_user.password_confirmation = params[:new_password], params[:new_password_confirmation]
scope = User.logged.status(@status) @current_user.save
@search_by = params[:search_by] ? params[:search_by][:id] : 0 #raise @current_user.errors.full_message
scope = scope.like(params[:name],@search_by) if params[:name].present? #return @current_user
scope
end else
raise 'wrong password'
end end
@current_user
end
#搜索用户
def search_user params
@status = params[:status] || 1
has = {
"show_changesets" => true
}
scope = User.logged.status(@status)
@search_by = params[:search_by] ? params[:search_by][:id] : 0
scope = scope.like(params[:name],@search_by) if params[:name].present?
scope
end
end

Loading…
Cancel
Save