diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 1c24d3395..10fec7c1b 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -106,7 +106,7 @@ class UsersController < ApplicationController
redirect_to signin_url
return
elsif @user != User.current && !User.current.admin?
- return render_403
+ return render_403
end
# 初始化/更新 点击按钮时间
# 24小时内显示系统消息
@@ -570,7 +570,7 @@ class UsersController < ApplicationController
student_work.save
flash[:notice] = l(:notice_successful_create)
redirect_to student_work_index_url(:homework => params[:homework])
- else
+ else
render_403
end
end
@@ -775,7 +775,7 @@ class UsersController < ApplicationController
def store_selected_resource
session[:seleted_resource_ids] = [] if session[:seleted_resource_ids].nil?
if params[:save] == 'y'
- session[:seleted_resource_ids] << params[:res_id]
+ session[:seleted_resource_ids] << params[:res_id]
else
session[:seleted_resource_ids].delete( params[:res_id])
end
@@ -1081,12 +1081,12 @@ class UsersController < ApplicationController
else
blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")"
@user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" +
- "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+
+ "or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+
"or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " +
- "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10)
+ "or (container_type = 'Blog' and act_type= 'BlogComment' and container_id in #{blog_ids})").order('updated_at desc').limit(10).offset(@page * 10)
end
else
- # @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10)
+ # @user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}) or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id})").order('updated_at desc').limit(10).offset(@page * 10)
blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")"
@user_activities = UserActivity.where("(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" +
"or (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types}) "+
@@ -1733,30 +1733,30 @@ class UsersController < ApplicationController
end
ori = Attachment.find_by_id(send_id)
unless subfield_id.nil?
- attach_copied_obj = ori.copy
- @exist = false
- OrgSubfield.find(subfield_id).attachments.each do |att| #如果课程中包含该资源
- if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from
- att.created_on = Time.now
- att.save
- @exist = true
- break
- end
+ attach_copied_obj = ori.copy
+ @exist = false
+ OrgSubfield.find(subfield_id).attachments.each do |att| #如果课程中包含该资源
+ if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from
+ att.created_on = Time.now
+ att.save
+ @exist = true
+ break
end
- if @exist == false #如果不存在该资源
- attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
- attach_copied_obj.container = OrgSubfield.find(subfield_id)
- attach_copied_obj.created_on = Time.now
- attach_copied_obj.author_id = User.current.id
- attach_copied_obj.is_public = 0
- attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from
- if attach_copied_obj.attachtype == nil
- attach_copied_obj.attachtype = 1
- end
- if attach_copied_obj.save
- ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
- end
+ end
+ if @exist == false #如果不存在该资源
+ attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
+ attach_copied_obj.container = OrgSubfield.find(subfield_id)
+ attach_copied_obj.created_on = Time.now
+ attach_copied_obj.author_id = User.current.id
+ attach_copied_obj.is_public = 0
+ attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from
+ if attach_copied_obj.attachtype == nil
+ attach_copied_obj.attachtype = 1
end
+ if attach_copied_obj.save
+ ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
+ end
+ end
end
elsif params[:send_ids].present?
send_ids = params[:send_ids].split(" ")
@@ -1768,30 +1768,30 @@ class UsersController < ApplicationController
ori = Attachment.find_by_id(send_id)
unless subfield_id.nil?
- next if ori.blank?
- @exist = false
- OrgSubfield.find(subfield_id).attachments.each do |att| #如果课程中包含该资源
- if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from
- att.created_on = Time.now
- att.save
- @exist = true
- break
- end
- end
- next if @exist
- attach_copied_obj = ori.copy
- attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
- attach_copied_obj.container = OrgSubfield.find(subfield_id)
- attach_copied_obj.created_on = Time.now
- attach_copied_obj.author_id = User.current.id
- attach_copied_obj.is_public = 0
- attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from
- if attach_copied_obj.attachtype == nil
- attach_copied_obj.attachtype = 1
- end
- if attach_copied_obj.save
- ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
+ next if ori.blank?
+ @exist = false
+ OrgSubfield.find(subfield_id).attachments.each do |att| #如果课程中包含该资源
+ if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from
+ att.created_on = Time.now
+ att.save
+ @exist = true
+ break
end
+ end
+ next if @exist
+ attach_copied_obj = ori.copy
+ attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
+ attach_copied_obj.container = OrgSubfield.find(subfield_id)
+ attach_copied_obj.created_on = Time.now
+ attach_copied_obj.author_id = User.current.id
+ attach_copied_obj.is_public = 0
+ attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from #发送要添加copy_from
+ if attach_copied_obj.attachtype == nil
+ attach_copied_obj.attachtype = 1
+ end
+ if attach_copied_obj.save
+ ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
+ end
end
end
else
@@ -1826,8 +1826,8 @@ class UsersController < ApplicationController
end
news.attachments.each do |attach|
course_news.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
- :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
- :is_public => attach.is_public, :quotes => 0)
+ :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
+ :is_public => attach.is_public, :quotes => 0)
end
end
end
@@ -1846,8 +1846,8 @@ class UsersController < ApplicationController
end
news.attachments.each do |attach|
message.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
- :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
- :is_public => attach.is_public, :quotes => 0)
+ :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
+ :is_public => attach.is_public, :quotes => 0)
end
end
end
@@ -1863,8 +1863,8 @@ class UsersController < ApplicationController
end
news.attachments.each do |attach|
org_news.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
- :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
- :is_public => attach.is_public, :quotes => 0)
+ :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
+ :is_public => attach.is_public, :quotes => 0)
end
OrgActivity.create(:container_type => 'OrgSubfield', :container_id => field_id.to_i, :org_act_type=>'News', :org_act_id => org_news.id, :user_id => User.current.id)
end
@@ -2135,15 +2135,15 @@ class UsersController < ApplicationController
# 获取公共资源
def get_public_resources user_course_ids, user_project_ids
attachments = Attachment.where("(is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) "+
- "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" +
- "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)" ).order("created_on desc")
+ "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" +
+ "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)" ).order("created_on desc")
end
# 获取我的资源
def get_my_resources author_id, user_course_ids, user_project_ids
attachments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
- "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" +
- "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)" ).order("created_on desc")
+ "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" +
+ "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)" ).order("created_on desc")
end
# 获取我的课程资源
@@ -2261,12 +2261,12 @@ class UsersController < ApplicationController
ori = Attachment.find_by_id(send_id)
# 如果该附件已经存课程中,则只更新附件创建时间
mul_container.attachments.each do |att|
- if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from
- att.created_on = Time.now
- att.save
- @exist = true
- break
- end
+ if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from
+ att.created_on = Time.now
+ att.save
+ @exist = true
+ break
+ end
end
next if @exist
attach_copied_obj = ori.copy
@@ -2296,54 +2296,21 @@ class UsersController < ApplicationController
end
end
- # 公共资源搜索结果
- def get_resource_search_public user_course_ids, user_project_ids
- @attachments = Attachment.where("((is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) "+
- "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" +
- "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)" ,:p => search).order("created_on desc")
-
- # @attachments = Attachment.where("((is_public =1 and is_publish = 1 and container_id is not null)" +
- # "or (author_id = #{params[:id]} and is_publish = 0)) and (filename like :p) ", :p => search).order("created_on desc")
- end
-
- # 我的资源 搜索结果
- def get_resource_search_my author_id, user_course_ids, user_project_ids
- @attachments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
- "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and is_publish = 1 and container_id is not null)" +
- "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) and is_publish = 1 and container_id is not null)) and (filename like :p)" ,:p => search).order("created_on desc")
-
- # @attachments = Attachment.where("((author_id = #{params[:id]} and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
- # " or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))) and (filename like :p) ",:p=>search).order("created_on desc")
- end
-
- # 课程搜索结果
- def get_resource_search_course author_id
- @attachments = Attachment.where("(author_id = #{author_id} and container_type = 'Course') or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) and (filename like :p) ",:p=>search).order("created_on desc")
- end
-
- # 项目资源搜索结果
- def get_resource_search_project author_id
- @attachments = Attachment.where("author_id = #{author_id} and container_type = 'Project' and (filename like :p)",:p=>search).order("created_on desc")
- end
-
- # 附件
- def get_resource_search_attach author_id
- @attachments = Attachment.where("author_id = #{author_id} and container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like :p)",:p=>search).order("created_on desc")
- end
-
- # 个人
- def get_resource_search_principal author_id
- @attachments = Attachment.where("author_id = #{author_id} and container_type = 'Principal' and (filename like :p)",:p=>search).order("created_on desc")
- end
-
# 根据资源关键字进行搜索
def resource_search
search = "%#{params[:search].strip.downcase}%"
- user_course_ids = User.current.courses.map { |c| c.id}
- user_project_ids = User.current.projects.map {|p| p.id}
- # user_org_ids = User.current.organizations.map {|o| o.id}
if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') #全部
- @attachments = get_resource_search_my(params[:id], user_course_ids, user_project_ids)
+ if User.current.id.to_i == params[:id].to_i
+ user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 取交集并查询
+ @attachments = Attachment.where("((author_id = #{params[:id]} and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
+ " or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))) and (filename like :p) ",:p=>search).order("created_on desc")
+ else
+ user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中
+ @attachments = Attachment.where("((author_id = #{params[:id]} and is_public = 1 and container_type in" +
+ " ('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon'))"+
+ " or (container_type = 'Course' and is_public = 1 and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')})) )" +
+ " and (filename like :p) ",:p=>search).order("created_on desc")
+ end
elsif params[:type] == "2" #课程资源
if User.current.id.to_i == params[:id].to_i
user_course_ids = User.current.courses.map { |c| c.id}
@@ -2374,7 +2341,8 @@ class UsersController < ApplicationController
end
elsif params[:type] == "6" #全部资源
# 公共资源库:所有公开资源或者我上传的私有资源
- @attachments = get_resource_search_public(params[:id], user_course_ids, user_project_ids)
+ @attachments = Attachment.where("((is_public =1 and is_publish = 1 and container_id is not null)" +
+ "or (author_id = #{params[:id]} and is_publish = 0)) and (filename like :p) ", :p => search).order("created_on desc")
end
@type = params[:type]
@limit = 25
diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb
index 8dfda10bd..fa59fbed9 100644
--- a/app/views/layouts/base_courses.html.erb
+++ b/app/views/layouts/base_courses.html.erb
@@ -162,6 +162,9 @@
<% unless contributor_score.journal_num == 0 %>
课程留言:<%= contributor_score.journal_num %>
<% end %>
+ <% unless contributor_score.homework_journal_num == 0 %>
+ 作业留言:<%= contributor_score.homework_journal_num %>
+ <% end %>
<% unless contributor_score.news_reply_num == 0 %>
课程通知:<%= contributor_score.news_reply_num %>
<% end %>