|
|
|
@ -1,9 +1,24 @@
|
|
|
|
|
module AvatarHelper
|
|
|
|
|
|
|
|
|
|
AVATAR_SIZE="50x50"
|
|
|
|
|
|
|
|
|
|
def copy_avatar(des, src)
|
|
|
|
|
src_file = disk_filename(src.class,src.id)
|
|
|
|
|
des_file = disk_filename(des.class,des.id)
|
|
|
|
|
|
|
|
|
|
FileUtils.cp(src_file, des_file) if File.exist?(src_file)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def avatar_image(source)
|
|
|
|
|
File.join(relative_path, avatar_directory(source.class), source.id.to_s)
|
|
|
|
|
def avatar_image(source, copyed=false)
|
|
|
|
|
source_type = source.class
|
|
|
|
|
source_id = source.id
|
|
|
|
|
|
|
|
|
|
course = Course.find(source_id) rescue nil
|
|
|
|
|
if course && copyed
|
|
|
|
|
source_id = course.is_copy
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
File.join(relative_path, avatar_directory(source_type), source_id.to_s)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def relative_path
|
|
|
|
@ -23,7 +38,18 @@ module AvatarHelper
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def disk_filename(source_type,source_id,image_file=nil)
|
|
|
|
|
File.join(storage_path,avatar_directory(source_type),avatar_filename(source_id,image_file))
|
|
|
|
|
File.join(storage_path,avatar_directory(source_type),avatar_filename(source_id,image_file))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def copy_course?(source_type, source_id)
|
|
|
|
|
file= disk_filename(source_type, source_id)
|
|
|
|
|
if source_type == Course && !File.exist?(file)
|
|
|
|
|
course = Course.find(source_id) rescue nil
|
|
|
|
|
if course && course.is_copy>0
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def file_extension(filename=nil)
|
|
|
|
@ -35,7 +61,9 @@ module AvatarHelper
|
|
|
|
|
return File.join(relative_path,'AnonymousUser','0')
|
|
|
|
|
end
|
|
|
|
|
if source.class && source.id && File.exist?(disk_filename(source.class,source.id))
|
|
|
|
|
avatar_image(source)
|
|
|
|
|
avatar_image(source, false)
|
|
|
|
|
elsif copy_course?(source.class, source.id)
|
|
|
|
|
avatar_image(source, true)
|
|
|
|
|
else
|
|
|
|
|
File.join(relative_path,avatar_directory(source.class),'0')
|
|
|
|
|
end
|
|
|
|
|