From fbc70614edbe5deee28d26069359a8bc4a5979bd Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 13 Jan 2017 16:00:51 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B3=E8=AF=B7=E7=B1=BB=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E5=86=B2=E7=AA=81=E9=97=AE=E9=A2=98=E3=80=81user=20base?= =?UTF-8?q?=E5=87=A0=E4=B8=AA=E5=8F=96=E5=80=BC=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 3735 ++++++++++---------- app/helpers/application_helper.rb | 9 +- app/views/layouts/_logined_header.html.erb | 4 +- app/views/layouts/new_base_user.html.erb | 23 +- app/views/users/_new_user_message.html.erb | 10 +- 5 files changed, 1880 insertions(+), 1901 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 7b72d043c..57e45cd13 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -176,8 +176,8 @@ class UsersController < ApplicationController @issues_filter = Issue.where("author_id =?", @user.id) @issue_open_count = @issues_filter.where(:status_id => [1, 2, 3, 4, 6]).count @issue_close_count = @issues_filter.where(:status_id => 5).count - # @issue_open_count = Issue.where(:author_id => @user.id, :status_id => [1, 2, 3, 4, 6]).count - # @issue_close_count = Issue.where(:author_id => @user.id, :status_id => 5).count + # @issue_open_count = Issue.where(:author_id => @user.id, :status_id => [1, 2, 3, 4, 6]).count + # @issue_close_count = Issue.where(:author_id => @user.id, :status_id => 5).count # 导出excel的issues @excel_issues = @issues @@ -499,7 +499,7 @@ class UsersController < ApplicationController when nil # 系统消息为管理员发送,我的消息中包含有系统消息 @message_alls = [] - messages = MessageAll.where("(user_id =? and message_type !=?) or message_type =?" ,@user.id, "SystemMessage", "SystemMessage").includes(:message).order("created_at desc") + messages = MessageAll.where(:user_id => @user.id).includes(:message).order("created_at desc") messages.each do |message_all| mess = message_all.message unless (message_all.message_type == 'CourseMessage' && mess && mess.course && mess.course.is_delete == 1) @@ -2294,832 +2294,782 @@ class UsersController < ApplicationController if ForgeMessage.where("status in (1,3) and user_id != #{user_id} and pull_request_id = #{mess.forge_message_id}") @message_alls << mess end + end end end end + @message_count = @message_alls.count + @message_alls = paginateHelper @message_alls, 20 + respond_to do |format| + format.js + end end - @message_count = @message_alls.count - @message_alls = paginateHelper @message_alls, 20 - respond_to do |format| - format.js - end -end - # 课程社区 -def course_community - @course_community = "课程" - if params[:course_id] != nil - join_course_messages = CourseMessage.where("course_id =? and course_message_type =? and user_id =? and course_message_id =? and viewed =?", - params[:course_id], 'JoinCourseRequest', User.current.id, @user.id, false) - join_course_messages.update_all(:viewed => true) - end - shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id) - @page = params[:page] ? params[:page].to_i + 1 : 0 - user_course_ids = (@user.favorite_courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.favorite_courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")" - course_types = "('Message','News','HomeworkCommon','Poll','Course','JournalsForMessage','Attachment')" - principal_types = "JournalsForMessage" - container_type = '' - act_type = '' + def course_community + @course_community = "课程" + if params[:course_id] != nil + join_course_messages = CourseMessage.where("course_id =? and course_message_type =? and user_id =? and course_message_id =? and viewed =?", + params[:course_id], 'JoinCourseRequest', User.current.id, @user.id, false) + join_course_messages.update_all(:viewed => true) + end + shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Course'").map(&:shield_id) + @page = params[:page] ? params[:page].to_i + 1 : 0 + user_course_ids = (@user.favorite_courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.favorite_courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")" + course_types = "('Message','News','HomeworkCommon','Poll','Course','JournalsForMessage','Attachment')" + principal_types = "JournalsForMessage" + container_type = '' + act_type = '' - if params[:type].present? - case params[:type] - when "course_homework" - container_type = 'Course' - act_type = 'HomeworkCommon' - when "course_news" - container_type = 'Course' - act_type = 'News' - when "course_message" - container_type = 'Course' - act_type = 'Message' - when "course_resource" - container_type = 'Course' - act_type = "Attachment" - when "course_poll" - container_type = 'Course' - act_type = 'Poll' - when "course_journals" - container_type = 'Course' - act_type = 'JournalsForMessage' - when "current_user" - container_type = 'Principal' - act_type = 'Principal' - when "all" - container_type = 'all' - act_type = 'all' + if params[:type].present? + case params[:type] + when "course_homework" + container_type = 'Course' + act_type = 'HomeworkCommon' + when "course_news" + container_type = 'Course' + act_type = 'News' + when "course_message" + container_type = 'Course' + act_type = 'Message' + when "course_resource" + container_type = 'Course' + act_type = "Attachment" + when "course_poll" + container_type = 'Course' + act_type = 'Poll' + when "course_journals" + container_type = 'Course' + act_type = 'JournalsForMessage' + when "current_user" + container_type = 'Principal' + act_type = 'Principal' + when "all" + container_type = 'all' + act_type = 'all' + end + end + if container_type != '' && container_type != 'all' + if container_type == 'Course' + sql = "container_type = '#{container_type}' and container_id in #{user_course_ids} and act_type = '#{act_type}'" + elsif container_type == 'Principal' && act_type == 'Principal' + sql = "user_id = #{@user.id} and (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})" + end + if User.current != @user + sql += " and user_id = #{@user.id}" + end + else + sql = "(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}) " + if container_type != 'all' && User.current != @user + sql = "user_id = #{@user.id} and(" + sql + ")" + end + end + @user_activities_count = UserActivity.where("#{sql}").order('updated_at desc').count + @user_activities = UserActivity.where("#{sql}").order('updated_at desc').limit(10).offset(@page * 10) + @type = params[:type] + respond_to do |format| + format.js + format.html {render :layout => 'base_course_community'} end end - if container_type != '' && container_type != 'all' - if container_type == 'Course' - sql = "container_type = '#{container_type}' and container_id in #{user_course_ids} and act_type = '#{act_type}'" - elsif container_type == 'Principal' && act_type == 'Principal' - sql = "user_id = #{@user.id} and (container_type = 'Course' and container_id in #{user_course_ids} and act_type in #{course_types})" - end - if User.current != @user - sql += " and user_id = #{@user.id}" - end - else - sql = "(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}) " - if container_type != 'all' && User.current != @user - sql = "user_id = #{@user.id} and(" + sql + ")" - end - end - @user_activities_count = UserActivity.where("#{sql}").order('updated_at desc').count - @user_activities = UserActivity.where("#{sql}").order('updated_at desc').limit(10).offset(@page * 10) - @type = params[:type] - respond_to do |format| - format.js - format.html {render :layout => 'base_course_community'} - end -end # 项目社区 -def project_community - # 看别人的主页显示动态 - #更新用户申请成为课程老师或教辅消息的状态 - @project_community = "项目" - shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Project'").map(&:shield_id) - @page = params[:page] ? params[:page].to_i + 1 : 0 - user_project_ids = (@user.favorite_projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.favorite_projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")" - project_types = "('Message','Issue','Project')" - principal_types = "JournalsForMessage" - container_type = '' - act_type = '' - if params[:type].present? - case params[:type] - when "project_issue" - container_type = 'Project' - act_type = 'Issue' - when "project_message" - container_type = 'Project' - act_type = 'Message' - when "current_user" - container_type = 'Principal' - act_type = 'Principal' - when "all" - container_type = 'all' - act_type = 'all' + def project_community + # 看别人的主页显示动态 + #更新用户申请成为课程老师或教辅消息的状态 + @project_community = "项目" + shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Project'").map(&:shield_id) + @page = params[:page] ? params[:page].to_i + 1 : 0 + user_project_ids = (@user.favorite_projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.favorite_projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")" + project_types = "('Message','Issue','Project')" + principal_types = "JournalsForMessage" + container_type = '' + act_type = '' + if params[:type].present? + case params[:type] + when "project_issue" + container_type = 'Project' + act_type = 'Issue' + when "project_message" + container_type = 'Project' + act_type = 'Message' + when "current_user" + container_type = 'Principal' + act_type = 'Principal' + when "all" + container_type = 'all' + act_type = 'all' + end + end + if container_type != '' && container_type != 'all' + if container_type == 'Project' + sql = "container_type = '#{container_type}' and container_id in #{user_project_ids} and act_type = '#{act_type}'" + elsif container_type == 'Principal' && act_type == 'Principal' + sql = "user_id = #{@user.id} and ((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}))" + end + if User.current != @user + sql += " and user_id = #{@user.id}" + end + else + sql = "(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + + "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " + if container_type != 'all' && User.current != @user + sql = "user_id = #{@user.id} and(" + sql + ")" + end + end + @user_activities_count = UserActivity.where("#{sql}").order('updated_at desc').count + @user_activities = UserActivity.where("#{sql}").order('updated_at desc').limit(10).offset(@page * 10) + @type = params[:type] + respond_to do |format| + format.js + format.html {render :layout => 'base_project_community'} end end - if container_type != '' && container_type != 'all' - if container_type == 'Project' - sql = "container_type = '#{container_type}' and container_id in #{user_project_ids} and act_type = '#{act_type}'" - elsif container_type == 'Principal' && act_type == 'Principal' - sql = "user_id = #{@user.id} and ((container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types}))" - end - if User.current != @user - sql += " and user_id = #{@user.id}" - end - else - sql = "(container_type = 'Project' and container_id in #{user_project_ids} and act_type in #{project_types})" + - "or (container_type = 'Principal' and act_type= '#{principal_types}' and container_id = #{@user.id}) " - if container_type != 'all' && User.current != @user - sql = "user_id = #{@user.id} and(" + sql + ")" - end - end - @user_activities_count = UserActivity.where("#{sql}").order('updated_at desc').count - @user_activities = UserActivity.where("#{sql}").order('updated_at desc').limit(10).offset(@page * 10) - @type = params[:type] - respond_to do |format| - format.js - format.html {render :layout => 'base_project_community'} - end -end # 竞赛社区 -def contest_community - @contest_community = "竞赛" - shield_contest_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Contest'").map(&:shield_id) - @page = params[:page] ? params[:page].to_i + 1 : 0 - user_contest_ids = (@user.favorite_contests.visible.where("is_delete = 0").map{|contest| contest.id}-shield_contest_ids).empty? ? "(-1)" : "(" + (@user.favorite_contests.visible.map{|contest| contest.id}-shield_contest_ids).join(",") + ")" - contest_types = "('Message','News','Work','Contest','JournalsForMessage')" - container_type = '' - act_type = '' + def contest_community + @contest_community = "竞赛" + shield_contest_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Contest'").map(&:shield_id) + @page = params[:page] ? params[:page].to_i + 1 : 0 + user_contest_ids = (@user.favorite_contests.visible.where("is_delete = 0").map{|contest| contest.id}-shield_contest_ids).empty? ? "(-1)" : "(" + (@user.favorite_contests.visible.map{|contest| contest.id}-shield_contest_ids).join(",") + ")" + contest_types = "('Message','News','Work','Contest','JournalsForMessage')" + container_type = '' + act_type = '' - if params[:type].present? + if params[:type].present? + case params[:type] + when "contest_work" + container_type = 'Contest' + act_type = 'Work' + when "contest_news" + container_type = 'Contest' + act_type = 'News' + when "contest_message" + container_type = 'Contest' + act_type = 'Message' + when "contest_journals" + container_type = 'Contest' + act_type = 'JournalsForMessage' + when "current_user" + container_type = 'Principal' + act_type = 'Principal' + when "all" + container_type = 'all' + act_type = 'all' + end + end + if container_type != '' && container_type != 'all' + if container_type == 'Contest' + sql = "container_type = '#{container_type}' and container_id in #{user_contest_ids} and act_type = '#{act_type}'" + elsif container_type == 'Principal' && act_type == 'Principal' + sql = "user_id = #{@user.id} and (container_type = 'Contest' and container_id in #{user_contest_ids} and act_type in #{contest_types})" + end + if User.current != @user + sql += " and user_id = #{@user.id}" + end + else + sql = "(container_type = 'Contest' and container_id in #{user_contest_ids} and act_type in #{contest_types})" + if container_type != 'all' && User.current != @user + sql = "user_id = #{@user.id} and(" + sql + ")" + end + end + @user_activities_count = UserActivity.where("#{sql}").order('updated_at desc').count + @user_activities = UserActivity.where("#{sql}").order('updated_at desc').limit(10).offset(@page * 10) + @type = params[:type] + respond_to do |format| + format.js + format.html {render :layout => 'base_contest_community'} + end + end + + def show_old + pre_count = 10 #limit + # Time 2015-02-04 11:46:34 + # Author lizanle + # Description type 1 :所有动态包括我关注的人 type 2:我的动态 type 3:关于我的回复 case params[:type] - when "contest_work" - container_type = 'Contest' - act_type = 'Work' - when "contest_news" - container_type = 'Contest' - act_type = 'News' - when "contest_message" - container_type = 'Contest' - act_type = 'Message' - when "contest_journals" - container_type = 'Contest' - act_type = 'JournalsForMessage' - when "current_user" - container_type = 'Principal' - act_type = 'Principal' - when "all" - container_type = 'all' - act_type = 'all' - end - end - if container_type != '' && container_type != 'all' - if container_type == 'Contest' - sql = "container_type = '#{container_type}' and container_id in #{user_contest_ids} and act_type = '#{act_type}'" - elsif container_type == 'Principal' && act_type == 'Principal' - sql = "user_id = #{@user.id} and (container_type = 'Contest' and container_id in #{user_contest_ids} and act_type in #{contest_types})" - end - if User.current != @user - sql += " and user_id = #{@user.id}" - end - else - sql = "(container_type = 'Contest' and container_id in #{user_contest_ids} and act_type in #{contest_types})" - if container_type != 'all' && User.current != @user - sql = "user_id = #{@user.id} and(" + sql + ")" - end - end - @user_activities_count = UserActivity.where("#{sql}").order('updated_at desc').count - @user_activities = UserActivity.where("#{sql}").order('updated_at desc').limit(10).offset(@page * 10) - @type = params[:type] - respond_to do |format| - format.js - format.html {render :layout => 'base_contest_community'} - end -end + when "1" + if @user == User.current + activity = Activity.where('user_id = ?', User.current.id).order('id desc') + @activity_count = activity.count + @activity_pages = Paginator.new @activity_count, pre_count, params['page'] + @activity = activity.offset(@activity_pages.offset).limit(@activity_pages.per_page).all + @state = 1 + end + when "2" + message = [] + if @user == User.current + message = JournalsForMessage.reference_message(@user.id) + message += Journal.reference_message(@user.id) + end + @activity_count = message.size + @info_pages = Paginator.new @activity_count, pre_count, params['page'] + messages = message.sort {|x,y| y.created_on <=> x.created_on } + @message = messages[@info_pages.offset, @info_pages.per_page] + @state = 2 + else + # Time 2015-02-04 10:50:49 + # Author lizanle + # Description 所有动态 + where_condition = nil; + # where_condition = "act_type <> 'JournalsForMessage'" + user_ids = [] + if @user == User.current + watcher = User.watched_by(@user) + watcher.push(User.current) + user_ids = watcher.map{|x| x.id} + else + user_ids << @user.id + end + activity = Activity.where(where_condition).where(user_id: user_ids).order('id desc') + + permission = !User.current.admin? + if permission + #Issue + act_ids = activity.where(act_type: 'Issue').select('act_id').map{|x| x.act_id} + project_ids = Issue.where(id: act_ids).select('distinct project_id').map{|x| x.project_id} + p_ids = [] + Project.where(id: project_ids).each do |x| + p_ids << x.id unless x.visible?(User.current) + end + ids = [] + ids << Issue.where(id: act_ids, project_id: p_ids).map{|x| x.id} + + #HomeworkCommon + act_ids = activity.where(act_type: 'HomeworkCommon').select('act_id').map{|x| x.act_id} + course_ids = HomeworkCommon.where(id: act_ids).select('distinct course_id').map{|x| x.course_id} + c_ids = [] + Course.where(id: course_ids).each do |x| + c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x) + end + ids << HomeworkCommon.where(id: act_ids, course_id: c_ids).map{|x| x.id} + + #Journal + act_ids = activity.where(act_type: 'Journal').select('act_id').map{|x| x.act_id} + project_ids = Journal.where(id:act_ids, journalized_type: 'Project').select('distinct journalized_id').map{|x| x.journalized_id} + p_ids = [] + Project.where(id: project_ids).each do |x| + p_ids << x.id unless x.visible?(User.current) + end + ids << Journal.where(id: act_ids, journalized_id: p_ids, journalized_type: 'Project').map{|x| x.id} + + #News + act_ids = activity.where(act_type: 'News').select('act_id').map{|x| x.act_id} + project_ids = News.where(id: act_ids).select('distinct project_id').map{|x| x.project_id} + p_ids = [] + Project.where(id: project_ids).each do |x| + p_ids << x.id unless x.visible?(User.current) + end + ids << News.where(id: act_ids, project_id: p_ids).map{|x| x.id} + + project_ids = News.where(id: act_ids).select('distinct course_id').map{|x| x.course_id} + c_ids = [] + Course.where(id: project_ids).each do |x| + c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x) + end + ids << News.where(id: act_ids, course_id: p_ids).map{|x| x.id} + + #Message + act_ids = activity.where(act_type: 'Message').select('act_id').map{|x| x.act_id} + board_ids = Message.where(id: act_ids).select('distinct board_id').map{|x| x.board_id} + project_ids = Board.where(id: board_ids).select('distinct project_id').map{|x| x.project_id} + p_ids = [] + Project.where(id: project_ids).each do |x| + p_ids << x.id unless x.visible?(User.current) + end + ids << Message.where(id: act_ids, board_id: p_ids).map{|x| x.id} + + project_ids = Board.where(id: board_ids).select('distinct course_id').map{|x| x.course_id} + c_ids = [] + Course.where(id: project_ids).each do |x| + c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x) + end + ids << Message.where(id: act_ids, board_id: c_ids).map{|x| x.id} + + logger.debug "filter ids #{ids}" + + activity = activity.where('act_id not in (?)', ids.flatten ).order('id desc') unless ids.flatten.empty? + end + + # activity = activity.reject { |e| + # e.act.nil? || + # (!User.current.admin? && !e.act.nil? + # (((e.act_type == "Issue") && !e.act.project.visible?(User.current)) || + # (e.act_type == "Bid" && !e.act.courses.first.nil? && e.act.courses.first.is_public == 0 && !User.current.member_of_course?(e.act.courses.first)) || + # (e.act_type == "Journal" && e.act.respond_to?("Project") && !e.act.project.visible?(User.current)) || + # (e.act_type == "News" && ((!e.act.project.nil? && !e.act.project.visible?(User.current)) || (!e.act.course.nil? && e.act.course.is_public == 0 && !User.current.member_of_course?(e.act.course)))) || + # (e.act_type == "Message" && !e.act.board.nil? && ((!e.act.board.project.nil? && !e.act.board.project.visible?(User.current)) || (!e.act.board.course.nil? && e.act.board.course.is_public == 0 && !User.current.member_of_course?(e.act.board.course)))))) + # } + # -def show_old - pre_count = 10 #limit - # Time 2015-02-04 11:46:34 - # Author lizanle - # Description type 1 :所有动态包括我关注的人 type 2:我的动态 type 3:关于我的回复 - case params[:type] - when "1" - if @user == User.current - activity = Activity.where('user_id = ?', User.current.id).order('id desc') @activity_count = activity.count @activity_pages = Paginator.new @activity_count, pre_count, params['page'] - @activity = activity.offset(@activity_pages.offset).limit(@activity_pages.per_page).all - @state = 1 - end - when "2" - message = [] - if @user == User.current - message = JournalsForMessage.reference_message(@user.id) - message += Journal.reference_message(@user.id) - end - @activity_count = message.size - @info_pages = Paginator.new @activity_count, pre_count, params['page'] - messages = message.sort {|x,y| y.created_on <=> x.created_on } - @message = messages[@info_pages.offset, @info_pages.per_page] - @state = 2 - else - # Time 2015-02-04 10:50:49 - # Author lizanle - # Description 所有动态 - where_condition = nil; - # where_condition = "act_type <> 'JournalsForMessage'" - user_ids = [] - if @user == User.current - watcher = User.watched_by(@user) - watcher.push(User.current) - user_ids = watcher.map{|x| x.id} + @activity = activity.slice(@activity_pages.offset,@activity_pages.per_page) + @state = 0 + end + + if params[:user].present? + + user_temp = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{params[:user]}%' or lastname like '%#{params[:user]}%'") + + if user_temp.size > 1 + activity = Activity.where('user_id in (?)', user_temp).where('user_id in (?)', watcher).order('id desc') + elsif user_temp.size == 1 + activity = Activity.where('user_id = ?', user_temp).where('user_id in (?)', watcher).order('id desc') else - user_ids << @user.id + activity = Activity.where("1 = 0") end - activity = Activity.where(where_condition).where(user_id: user_ids).order('id desc') - - permission = !User.current.admin? - if permission - #Issue - act_ids = activity.where(act_type: 'Issue').select('act_id').map{|x| x.act_id} - project_ids = Issue.where(id: act_ids).select('distinct project_id').map{|x| x.project_id} - p_ids = [] - Project.where(id: project_ids).each do |x| - p_ids << x.id unless x.visible?(User.current) - end - ids = [] - ids << Issue.where(id: act_ids, project_id: p_ids).map{|x| x.id} - - #HomeworkCommon - act_ids = activity.where(act_type: 'HomeworkCommon').select('act_id').map{|x| x.act_id} - course_ids = HomeworkCommon.where(id: act_ids).select('distinct course_id').map{|x| x.course_id} - c_ids = [] - Course.where(id: course_ids).each do |x| - c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x) - end - ids << HomeworkCommon.where(id: act_ids, course_id: c_ids).map{|x| x.id} - - #Journal - act_ids = activity.where(act_type: 'Journal').select('act_id').map{|x| x.act_id} - project_ids = Journal.where(id:act_ids, journalized_type: 'Project').select('distinct journalized_id').map{|x| x.journalized_id} - p_ids = [] - Project.where(id: project_ids).each do |x| - p_ids << x.id unless x.visible?(User.current) - end - ids << Journal.where(id: act_ids, journalized_id: p_ids, journalized_type: 'Project').map{|x| x.id} - - #News - act_ids = activity.where(act_type: 'News').select('act_id').map{|x| x.act_id} - project_ids = News.where(id: act_ids).select('distinct project_id').map{|x| x.project_id} - p_ids = [] - Project.where(id: project_ids).each do |x| - p_ids << x.id unless x.visible?(User.current) - end - ids << News.where(id: act_ids, project_id: p_ids).map{|x| x.id} - - project_ids = News.where(id: act_ids).select('distinct course_id').map{|x| x.course_id} - c_ids = [] - Course.where(id: project_ids).each do |x| - c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x) - end - ids << News.where(id: act_ids, course_id: p_ids).map{|x| x.id} - - #Message - act_ids = activity.where(act_type: 'Message').select('act_id').map{|x| x.act_id} - board_ids = Message.where(id: act_ids).select('distinct board_id').map{|x| x.board_id} - project_ids = Board.where(id: board_ids).select('distinct project_id').map{|x| x.project_id} - p_ids = [] - Project.where(id: project_ids).each do |x| - p_ids << x.id unless x.visible?(User.current) - end - ids << Message.where(id: act_ids, board_id: p_ids).map{|x| x.id} - - project_ids = Board.where(id: board_ids).select('distinct course_id').map{|x| x.course_id} - c_ids = [] - Course.where(id: project_ids).each do |x| - c_ids << x.id unless x.is_public !=0 && User.current.member_of_course?(x) - end - ids << Message.where(id: act_ids, board_id: c_ids).map{|x| x.id} - - logger.debug "filter ids #{ids}" - - activity = activity.where('act_id not in (?)', ids.flatten ).order('id desc') unless ids.flatten.empty? - end - - # activity = activity.reject { |e| - # e.act.nil? || - # (!User.current.admin? && !e.act.nil? - # (((e.act_type == "Issue") && !e.act.project.visible?(User.current)) || - # (e.act_type == "Bid" && !e.act.courses.first.nil? && e.act.courses.first.is_public == 0 && !User.current.member_of_course?(e.act.courses.first)) || - # (e.act_type == "Journal" && e.act.respond_to?("Project") && !e.act.project.visible?(User.current)) || - # (e.act_type == "News" && ((!e.act.project.nil? && !e.act.project.visible?(User.current)) || (!e.act.course.nil? && e.act.course.is_public == 0 && !User.current.member_of_course?(e.act.course)))) || - # (e.act_type == "Message" && !e.act.board.nil? && ((!e.act.board.project.nil? && !e.act.board.project.visible?(User.current)) || (!e.act.board.course.nil? && e.act.board.course.is_public == 0 && !User.current.member_of_course?(e.act.board.course)))))) - # } - # - + @offset, @limit = api_offset_and_limit({:limit => 10}) @activity_count = activity.count - @activity_pages = Paginator.new @activity_count, pre_count, params['page'] - @activity = activity.slice(@activity_pages.offset,@activity_pages.per_page) + @activity_pages = Paginator.new @activity_count, @limit, params['page'] + @offset ||= @activity_pages.offset + @activity = activity.offset(@offset).limit(@limit) @state = 0 - end - - if params[:user].present? - - user_temp = User.find_by_sql("select id from users where concat(lastname,firstname) like '%#{params[:user]}%' or lastname like '%#{params[:user]}%'") - - if user_temp.size > 1 - activity = Activity.where('user_id in (?)', user_temp).where('user_id in (?)', watcher).order('id desc') - elsif user_temp.size == 1 - activity = Activity.where('user_id = ?', user_temp).where('user_id in (?)', watcher).order('id desc') - else - activity = Activity.where("1 = 0") end - @offset, @limit = api_offset_and_limit({:limit => 10}) - @activity_count = activity.count - @activity_pages = Paginator.new @activity_count, @limit, params['page'] - @offset ||= @activity_pages.offset - @activity = activity.offset(@offset).limit(@limit) - @state = 0 - end -#Modified by nie - unless User.current.admin? - if !@user.active? #|| (@user != User.current && @memberships.empty? && events.empty?) - # redirect_to home_path - render_404 - return + #Modified by nie + unless User.current.admin? + if !@user.active? #|| (@user != User.current && @memberships.empty? && events.empty?) + # redirect_to home_path + render_404 + return + end + end + + respond_to do |format| + format.html + format.api end end - respond_to do |format| - format.html - format.api - end -end - ##end fq #### added by fq -def info + def info - message = [] - if @user == User.current - message = JournalsForMessage.reference_message(@user.id) - message += Journal.reference_message(@user.id) - end - @offset, @limit = api_offset_and_limit({:limit => 10}) - @info_count = message.size - @info_pages = Paginator.new @info_count, @limit, params['page'] - @offset ||= @info_pages.offset + message = [] + if @user == User.current + message = JournalsForMessage.reference_message(@user.id) + message += Journal.reference_message(@user.id) + end + @offset, @limit = api_offset_and_limit({:limit => 10}) + @info_count = message.size + @info_pages = Paginator.new @info_count, @limit, params['page'] + @offset ||= @info_pages.offset - messages = message.sort {|x,y| y.created_on <=> x.created_on } + messages = message.sort {|x,y| y.created_on <=> x.created_on } - @message = messages[@offset, @limit] + @message = messages[@offset, @limit] - unless User.current.admin? - if !@user.active? - render_404 - return + unless User.current.admin? + if !@user.active? + render_404 + return + end + end + + respond_to do |format| + format.html + format.api end end - - respond_to do |format| - format.html - format.api - end -end #### end -def new - @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option) - @auth_sources = AuthSource.all - render :layout => "users_base" -end - -def create - @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option) - @user.safe_attributes = params[:user] - @user.admin = params[:user][:admin] || false - @user.login = params[:user][:login] - @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] unless @user.auth_source_id - - if @user.save - @user.pref.attributes = params[:pref] - @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') - @user.pref.save - @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) - - Mailer.run.account_information(@user, params[:user][:password]) if params[:send_information] - - respond_to do |format| - format.html { - flash[:notice] = l(:notice_user_successful_create, :id => view_context.link_to(@user.login, user_path(@user))) - if params[:continue] - redirect_to new_user_url - else - redirect_to edit_user_url(@user) - end - } - format.api { render :action => 'show', :status => :created, :location => user_url(@user) } - end - else + def new + @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option) @auth_sources = AuthSource.all - # Clear password input - @user.password = @user.password_confirmation = nil + render :layout => "users_base" + end - respond_to do |format| - format.html { render :action => 'new',:layout => "users_base" } - format.api { render_validation_errors(@user) } + def create + @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option) + @user.safe_attributes = params[:user] + @user.admin = params[:user][:admin] || false + @user.login = params[:user][:login] + @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] unless @user.auth_source_id + + if @user.save + @user.pref.attributes = params[:pref] + @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') + @user.pref.save + @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) + + Mailer.run.account_information(@user, params[:user][:password]) if params[:send_information] + + respond_to do |format| + format.html { + flash[:notice] = l(:notice_user_successful_create, :id => view_context.link_to(@user.login, user_path(@user))) + if params[:continue] + redirect_to new_user_url + else + redirect_to edit_user_url(@user) + end + } + format.api { render :action => 'show', :status => :created, :location => user_url(@user) } + end + else + @auth_sources = AuthSource.all + # Clear password input + @user.password = @user.password_confirmation = nil + + respond_to do |format| + format.html { render :action => 'new',:layout => "users_base" } + format.api { render_validation_errors(@user) } + end + end + + unless @user.id.nil? + #后台注册的用户默认权限为男性开发员 + ue = UserExtensions.create(:identity => 3, + :gender => 0, + :user_id => @user.id) + ue.save end end - unless @user.id.nil? - #后台注册的用户默认权限为男性开发员 - ue = UserExtensions.create(:identity => 3, - :gender => 0, - :user_id => @user.id) - ue.save - end -end - -def edit - @auth_sources = AuthSource.all - @membership ||= Member.new -end - -def watch_projects - @watch_projects = Project.joins(:watchers).where("project_type <>? and watchable_type = ? and `watchers`.user_id = ?", '1','Project', @user.id) - @state = 1 - respond_to do |format| - format.html { - render :layout => 'base_users' - } - format.api - end -end - -def update - @user.admin = params[:user][:admin] if params[:user][:admin] - @user.login = params[:user][:login] if params[:user][:login] - if params[:user][:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?) - @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] - end - @user.safe_attributes = params[:user] - # Was the account actived ? (do it before User#save clears the change) - was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE]) - # TODO: Similar to My#account - @user.pref.attributes = params[:pref] - @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') - - if @user.save - @user.pref.save - @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) - - if was_activated - Mailer.run.account_activated(@user) - elsif @user.active? && params[:send_information] && !params[:user][:password].blank? && @user.auth_source_id.nil? - Mailer.run.account_information(@user, params[:user][:password]) - end - - respond_to do |format| - format.html { - flash[:notice] = l(:notice_successful_update) - redirect_to_referer_or edit_user_url(@user) - } - format.api { render_api_ok } - end - else + def edit @auth_sources = AuthSource.all @membership ||= Member.new - # Clear password input - @user.password = @user.password_confirmation = nil + end + def watch_projects + @watch_projects = Project.joins(:watchers).where("project_type <>? and watchable_type = ? and `watchers`.user_id = ?", '1','Project', @user.id) + @state = 1 respond_to do |format| - format.html { render :action => :edit } - format.api { render_validation_errors(@user) } + format.html { + render :layout => 'base_users' + } + format.api + end + end + + def update + @user.admin = params[:user][:admin] if params[:user][:admin] + @user.login = params[:user][:login] if params[:user][:login] + if params[:user][:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?) + @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] + end + @user.safe_attributes = params[:user] + # Was the account actived ? (do it before User#save clears the change) + was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE]) + # TODO: Similar to My#account + @user.pref.attributes = params[:pref] + @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') + + if @user.save + @user.pref.save + @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) + + if was_activated + Mailer.run.account_activated(@user) + elsif @user.active? && params[:send_information] && !params[:user][:password].blank? && @user.auth_source_id.nil? + Mailer.run.account_information(@user, params[:user][:password]) + end + + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_update) + redirect_to_referer_or edit_user_url(@user) + } + format.api { render_api_ok } + end + else + @auth_sources = AuthSource.all + @membership ||= Member.new + # Clear password input + @user.password = @user.password_confirmation = nil + + respond_to do |format| + format.html { render :action => :edit } + format.api { render_validation_errors(@user) } + end end end -end # 上传用户资源 -def user_resource_create - user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} - user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } - # user_org_ids = User.current.organizations.map {|o| o.id} - @user = User.current - # 保存文件 - attach = Attachment.attach_filesex_public(@user, params[:attachments], params[:attachment_type], is_public = true) - @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" - @score = @b_sort == "desc" ? "asc" : "desc" - # user_org_ids = User.current.organizations.map {|o| o.id} - if(params[:type].blank? || params[:type] == "1") # 我的资源 - # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 - if params[:status] == "2" - @attachments = get_course_resources(@user.id, user_course_ids, @order, @score) - elsif params[:status] == "3" - @attachments = get_project_resources(@user.id, user_project_ids, @order, @score) - elsif params[:status] == "4" - @attachments = get_attch_resources(@user.id, @order, @score) - elsif params[:status] == "5" - @attachments = get_principal_resources(@user.id, @order, @score) - else - # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(@user.id, user_course_ids, user_project_ids, @order, @score) + def user_resource_create + user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} + user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } + # user_org_ids = User.current.organizations.map {|o| o.id} + @user = User.current + # 保存文件 + attach = Attachment.attach_filesex_public(@user, params[:attachments], params[:attachment_type], is_public = true) + @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + @score = @b_sort == "desc" ? "asc" : "desc" + # user_org_ids = User.current.organizations.map {|o| o.id} + if(params[:type].blank? || params[:type] == "1") # 我的资源 + # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 + if params[:status] == "2" + @attachments = get_course_resources(@user.id, user_course_ids, @order, @score) + elsif params[:status] == "3" + @attachments = get_project_resources(@user.id, user_project_ids, @order, @score) + elsif params[:status] == "4" + @attachments = get_attch_resources(@user.id, @order, @score) + elsif params[:status] == "5" + @attachments = get_principal_resources(@user.id, @order, @score) + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_my_resources(@user.id, user_course_ids, user_project_ids, @order, @score) + end + elsif params[:type] == "6" # 公共资源 + if params[:status] == "2" + @attachments = get_course_resources_public( user_course_ids, @order, @score) + elsif params[:status] == "3" + @attachments = get_project_resources_public(user_project_ids, @order, @score) + elsif params[:status] == "4" + @attachments = get_attch_resources_public(@order, @score) + elsif params[:status] == "5" + @attachments = get_principal_resources_public(@order, @score) + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) + end end - elsif params[:type] == "6" # 公共资源 - if params[:status] == "2" - @attachments = get_course_resources_public( user_course_ids, @order, @score) - elsif params[:status] == "3" - @attachments = get_project_resources_public(user_project_ids, @order, @score) - elsif params[:status] == "4" - @attachments = get_attch_resources_public(@order, @score) - elsif params[:status] == "5" - @attachments = get_principal_resources_public(@order, @score) - else - # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) - end - end - @status = params[:status] - @type = params[:type] - @path = user_resource_user_path(User.current, :type => @type) - @limit = 25 - @is_remote = true - @atta_count = @attachments.count - @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 - @offset ||= @atta_pages.offset - #@curse_attachments_all = @all_attachments[@offset, @limit] - @attachments = paginateHelper @attachments,25 - respond_to do |format| - format.js + @status = params[:status] + @type = params[:type] + @path = user_resource_user_path(User.current, :type => @type) + @limit = 25 + @is_remote = true + @atta_count = @attachments.count + @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + @offset ||= @atta_pages.offset + #@curse_attachments_all = @all_attachments[@offset, @limit] + @attachments = paginateHelper @attachments,25 + respond_to do |format| + format.js + end end -end # 删除用户资源,分为批量删除 和 单个删除,只能删除自己上传的资源 -def user_resource_delete - if params[:resource_id].present? - Attachment.where("author_id =? and id =?", User.current.id, params[:resource_id]).first.destroy - elsif params[:checkbox1].present? - params[:checkbox1].each do |id| - Attachment.where("author_id =? and id =?", User.current.id, id).first.destroy + def user_resource_delete + if params[:resource_id].present? + Attachment.where("author_id =? and id =?", User.current.id, params[:resource_id]).first.destroy + elsif params[:checkbox1].present? + params[:checkbox1].each do |id| + Attachment.where("author_id =? and id =?", User.current.id, id).first.destroy + end + end + @user = User.current + @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + @score = @b_sort == "desc" ? "asc" : "desc" + 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].blank? || params[:type] == "1") # 我的资源 + # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 + if params[:status] == "2" + @attachments = get_course_resources(@user.id, user_course_ids, @order, @score) + elsif params[:status] == "3" + @attachments = get_project_resources(@user.id, user_project_ids, @order, @score) + elsif params[:status] == "4" + @attachments = get_attch_resources(@user.id, @order, @score) + elsif params[:status] == "5" + @attachments = get_principal_resources(@user.id, @order, @score) + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_my_resources(@user.id, user_course_ids, user_project_ids, @order, @score) + end + elsif params[:type] == "6" # 公共资源 + if params[:status] == "2" + @attachments = get_course_resources_public( user_course_ids, @order, @score) + elsif params[:status] == "3" + @attachments = get_project_resources_public(user_project_ids, @order, @score) + elsif params[:status] == "4" + @attachments = get_attch_resources_public(@order, @score) + elsif params[:status] == "5" + @attachments = get_principal_resources_public(@order, @score) + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) + end + end + @status = params[:status] + @type = params[:type] + @path = user_resource_user_path(User.current, :type => @type) + @limit = 25 + @is_remote = true + @atta_count = @attachments.count + @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + @offset ||= @atta_pages.offset + #@curse_attachments_all = @all_attachments[@offset, @limit] + @attachments = paginateHelper @attachments,25 + respond_to do |format| + format.js end end - @user = User.current - @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" - @score = @b_sort == "desc" ? "asc" : "desc" - 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].blank? || params[:type] == "1") # 我的资源 - # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 - if params[:status] == "2" - @attachments = get_course_resources(@user.id, user_course_ids, @order, @score) - elsif params[:status] == "3" - @attachments = get_project_resources(@user.id, user_project_ids, @order, @score) - elsif params[:status] == "4" - @attachments = get_attch_resources(@user.id, @order, @score) - elsif params[:status] == "5" - @attachments = get_principal_resources(@user.id, @order, @score) - else - # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(@user.id, user_course_ids, user_project_ids, @order, @score) - end - elsif params[:type] == "6" # 公共资源 - if params[:status] == "2" - @attachments = get_course_resources_public( user_course_ids, @order, @score) - elsif params[:status] == "3" - @attachments = get_project_resources_public(user_project_ids, @order, @score) - elsif params[:status] == "4" - @attachments = get_attch_resources_public(@order, @score) - elsif params[:status] == "5" - @attachments = get_principal_resources_public(@order, @score) - else - # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) - end - end - @status = params[:status] - @type = params[:type] - @path = user_resource_user_path(User.current, :type => @type) - @limit = 25 - @is_remote = true - @atta_count = @attachments.count - @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 - @offset ||= @atta_pages.offset - #@curse_attachments_all = @all_attachments[@offset, @limit] - @attachments = paginateHelper @attachments,25 - respond_to do |format| - format.js - end -end #根据id或者名称搜索教师或者助教为当前用户的课程 -def search_user_course - @user = User.current - if !params[:search].nil? - search = "%#{params[:search].to_s.strip.downcase}%" - @course = @user.courses.not_deleted.where(" #{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p",:p=>search) - else - @course = @user.courses.not_deleted + def search_user_course + @user = User.current + if !params[:search].nil? + search = "%#{params[:search].to_s.strip.downcase}%" + @course = @user.courses.not_deleted.where(" #{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p",:p=>search) + else + @course = @user.courses.not_deleted + end + @search = params[:search] + @type = params[:type] + #这里仅仅是传递需要发送的资源id + @send_id = params[:send_id] + @send_ids = params[:checkbox1] || params[:send_ids] + @hidden_unproject = hidden_unproject_infos + respond_to do |format| + format.js + end end - @search = params[:search] - @type = params[:type] - #这里仅仅是传递需要发送的资源id - @send_id = params[:send_id] - @send_ids = params[:checkbox1] || params[:send_ids] - @hidden_unproject = hidden_unproject_infos - respond_to do |format| - format.js - end -end # 根据id或者名称搜索当前用户所在的项目 -def search_user_project - @user = User.current - if !params[:search].nil? - search = "%#{params[:search].to_s.strip.downcase}%" - @projects = @user.projects.visible.where(" #{Project.table_name}.id = #{params[:search].to_i } or #{Project.table_name}.name like :p",:p=>search) - else - @projects = @user.projects.visible + def search_user_project + @user = User.current + if !params[:search].nil? + search = "%#{params[:search].to_s.strip.downcase}%" + @projects = @user.projects.visible.where(" #{Project.table_name}.id = #{params[:search].to_i } or #{Project.table_name}.name like :p",:p=>search) + else + @projects = @user.projects.visible + end + @search = params[:search] + @type = params[:type] + #这里仅仅是传递需要发送的资源id + @send_id = params[:send_id] + @send_ids = params[:checkbox1] || params[:send_ids] #搜索的时候 和 直接 用表格提交的时候的send_ids + @hidden_unproject = hidden_unproject_infos + respond_to do |format| + format.js + end end - @search = params[:search] - @type = params[:type] - #这里仅仅是传递需要发送的资源id - @send_id = params[:send_id] - @send_ids = params[:checkbox1] || params[:send_ids] #搜索的时候 和 直接 用表格提交的时候的send_ids - @hidden_unproject = hidden_unproject_infos - respond_to do |format| - format.js - end -end # 将资源发送到对应的课程,分为发送单个,或者批量发送 -def add_exist_file_to_course - @flag = true - if params[:send_id].present? - rs = ResourcesService.new - @ori, @flag, @save_message = rs.send_resource_to_course(User.current, params) - elsif params[:send_ids].present? - send_ids = params[:send_ids].split(",") - course_ids = params[:course_ids] - if course_ids.nil? - @flag = false - end - send_ids.each do |send_id| - quotes = 0 - @ori = Attachment.find_by_id(send_id) - unless course_ids.nil? - course_ids.each do |id| - quotes = 0 - next if @ori.blank? - @exist = false - Course.find(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 + def add_exist_file_to_course + @flag = true + if params[:send_id].present? + rs = ResourcesService.new + @ori, @flag, @save_message = rs.send_resource_to_course(User.current, params) + elsif params[:send_ids].present? + send_ids = params[:send_ids].split(",") + course_ids = params[:course_ids] + if course_ids.nil? + @flag = false + end + send_ids.each do |send_id| + quotes = 0 + @ori = Attachment.find_by_id(send_id) + unless course_ids.nil? + course_ids.each do |id| + quotes = 0 + next if @ori.blank? + @exist = false + Course.find(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 = Course.find(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 = 4 + end + if attach_copied_obj.save + # 更新引用次数 + quotes = @ori.quotes.to_i + 1 + @ori.update_attribute(:quotes, quotes) unless @ori.nil? + @ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) + end + @save_message = attach_copied_obj.errors.full_messages end - next if @exist - attach_copied_obj = @ori.copy - attach_copied_obj.tag_list.add(@ori.tag_list) # tag关联 - attach_copied_obj.container = Course.find(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 = 4 - end - if attach_copied_obj.save - # 更新引用次数 - quotes = @ori.quotes.to_i + 1 - @ori.update_attribute(:quotes, quotes) unless @ori.nil? - @ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) - end - @save_message = attach_copied_obj.errors.full_messages end end - end - else - @flag = false - end - @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" - @score = @b_sort == "desc" ? "asc" : "desc" - user_project_ids = User.current.projects.map {|p| p.id} - user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 - if(params[:type] == "1") # 我的资源 - # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 - if params[:status] == "2" - @attachments = get_course_resources(User.current.id, user_course_ids, @order, @score) - elsif params[:status] == "3" - @attachments = get_project_resources(User.current.id, user_project_ids, @order, @score) - elsif params[:status] == "4" - @attachments = get_attch_resources(User.current.id, @order, @score) - elsif params[:status] == "5" - @attachments = get_principal_resources(User.current.id, @order, @score) else - # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score) + @flag = false end - elsif (params[:type].blank? || params[:type] == "6") # 公共资源 - if params[:status] == "2" - @attachments = get_course_resources_public( user_course_ids, @order, @score) - elsif params[:status] == "3" - @attachments = get_project_resources_public(user_project_ids, @order, @score) - elsif params[:status] == "4" - @attachments = get_attch_resources_public(@order, @score) - elsif params[:status] == "5" - @attachments = get_principal_resources_public(@order, @score) - else - # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) + @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + @score = @b_sort == "desc" ? "asc" : "desc" + user_project_ids = User.current.projects.map {|p| p.id} + user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 + if(params[:type] == "1") # 我的资源 + # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 + if params[:status] == "2" + @attachments = get_course_resources(User.current.id, user_course_ids, @order, @score) + elsif params[:status] == "3" + @attachments = get_project_resources(User.current.id, user_project_ids, @order, @score) + elsif params[:status] == "4" + @attachments = get_attch_resources(User.current.id, @order, @score) + elsif params[:status] == "5" + @attachments = get_principal_resources(User.current.id, @order, @score) + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score) + end + elsif (params[:type].blank? || params[:type] == "6") # 公共资源 + if params[:status] == "2" + @attachments = get_course_resources_public( user_course_ids, @order, @score) + elsif params[:status] == "3" + @attachments = get_project_resources_public(user_project_ids, @order, @score) + elsif params[:status] == "4" + @attachments = get_attch_resources_public(@order, @score) + elsif params[:status] == "5" + @attachments = get_principal_resources_public(@order, @score) + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) + end + # elsif params[:type] == "2" + # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} + # if params[:status] == "2" + # resource_type = "'Course'" + # elsif params[:status] == "3" + # resource_type = "'Project'" + # elsif params[:status] == "5" + # resource_type = "'Principal'" + # else + # resource_type = "'Project','OrgSubfield','Principal','Course'" + # end + # @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score) + end + @type = params[:type] + @limit = 25 + @path = user_resource_user_path(User.current, :type => @type) + @user = User.current + @is_remote = true + @atta_count = @attachments.count + @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + @offset ||= @atta_pages.offset + #@curse_attachments_all = @all_attachments[@offset, @limit] + @attachments = paginateHelper @attachments,25 + respond_to do |format| + format.js end - # elsif params[:type] == "2" - # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} - # if params[:status] == "2" - # resource_type = "'Course'" - # elsif params[:status] == "3" - # resource_type = "'Project'" - # elsif params[:status] == "5" - # resource_type = "'Principal'" - # else - # resource_type = "'Project','OrgSubfield','Principal','Course'" - # end - # @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score) end - @type = params[:type] - @limit = 25 - @path = user_resource_user_path(User.current, :type => @type) - @user = User.current - @is_remote = true - @atta_count = @attachments.count - @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 - @offset ||= @atta_pages.offset - #@curse_attachments_all = @all_attachments[@offset, @limit] - @attachments = paginateHelper @attachments,25 - respond_to do |format| - format.js - end -end # 添加资源到对应的项目 -def add_exist_file_to_project - @flag = true - # 发送单个资源 - if params[:send_id].present? - send_id = params[:send_id] - project_ids = params[:projects_ids] - if project_ids.nil? - @flag = false - end - ori = Attachment.find_by_id(send_id) - unless project_ids.nil? - project_ids.each do |project_id| - next if ori.blank? - @exist = false - # 如果对象中包含该资源 - Project.find(project_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 = Project.find(project_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 - # 更新引用次数 - quotes = ori.quotes.to_i + 1 - ori.update_attribute(:quotes, quotes) unless ori.nil? - ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) - # 项目中添加动态 - ForgeActivity.create(:user_id => User.current.id, :project_id => project_id, :forge_act_id => attach_copied_obj.id, :forge_act_type => "Attachment" ) - end - unless Project.find(project_id).project_score.nil? - Project.find(project_id).project_score.update_attribute(:attach_num, - Project.find(project_id).project_score.attach_num + 1) - end + def add_exist_file_to_project + @flag = true + # 发送单个资源 + if params[:send_id].present? + send_id = params[:send_id] + project_ids = params[:projects_ids] + if project_ids.nil? + @flag = false end - @ori = ori - end - # 发送多个资源 - elsif params[:send_ids].present? - send_ids = params[:send_ids].split(",") - project_ids = params[:projects_ids] - if project_ids.nil? - @flag = false - end - send_ids.each do |send_id| - quotes = 0 ori = Attachment.find_by_id(send_id) unless project_ids.nil? project_ids.each do |project_id| - quotes = 0 next if ori.blank? @exist = false - Project.find(project_id).attachments.each do |att| #如果课程中包含该资源 + # 如果对象中包含该资源 + Project.find(project_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 @@ -3147,124 +3097,134 @@ def add_exist_file_to_project ForgeActivity.create(:user_id => User.current.id, :project_id => project_id, :forge_act_id => attach_copied_obj.id, :forge_act_type => "Attachment" ) end unless Project.find(project_id).project_score.nil? - Project.find(project_id).project_score.update_attribute(:attach_num, Project.find(project_id).project_score.attach_num + 1) + Project.find(project_id).project_score.update_attribute(:attach_num, + Project.find(project_id).project_score.attach_num + 1) + end + end + @ori = ori + end + # 发送多个资源 + elsif params[:send_ids].present? + send_ids = params[:send_ids].split(",") + project_ids = params[:projects_ids] + if project_ids.nil? + @flag = false + end + send_ids.each do |send_id| + quotes = 0 + ori = Attachment.find_by_id(send_id) + unless project_ids.nil? + project_ids.each do |project_id| + quotes = 0 + next if ori.blank? + @exist = false + Project.find(project_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 = Project.find(project_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 + # 更新引用次数 + quotes = ori.quotes.to_i + 1 + ori.update_attribute(:quotes, quotes) unless ori.nil? + ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) + # 项目中添加动态 + ForgeActivity.create(:user_id => User.current.id, :project_id => project_id, :forge_act_id => attach_copied_obj.id, :forge_act_type => "Attachment" ) + end + unless Project.find(project_id).project_score.nil? + Project.find(project_id).project_score.update_attribute(:attach_num, Project.find(project_id).project_score.attach_num + 1) + end end end end - end - else - @flag=true - end - @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" - @score = @b_sort == "desc" ? "asc" : "desc" - user_project_ids = User.current.projects.map {|p| p.id} - user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 - if(params[:type] == "1") # 我的资源 - # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 - if params[:status] == "2" - @attachments = get_course_resources(User.current.id, user_course_ids, @order, @score) - elsif params[:status] == "3" - @attachments = get_project_resources(User.current.id, user_project_ids, @order, @score) - elsif params[:status] == "4" - @attachments = get_attch_resources(User.current.id, @order, @score) - elsif params[:status] == "5" - @attachments = get_principal_resources(User.current.id, @order, @score) else - # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score) + @flag=true end - elsif (params[:type].blank? || params[:type] == "6") # 公共资源 - if params[:status] == "2" - @attachments = get_course_resources_public( user_course_ids, @order, @score) - elsif params[:status] == "3" - @attachments = get_project_resources_public(user_project_ids, @order, @score) - elsif params[:status] == "4" - @attachments = get_attch_resources_public(@order, @score) - elsif params[:status] == "5" - @attachments = get_principal_resources_public(@order, @score) - else - # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) + @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + @score = @b_sort == "desc" ? "asc" : "desc" + user_project_ids = User.current.projects.map {|p| p.id} + user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 + if(params[:type] == "1") # 我的资源 + # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 + if params[:status] == "2" + @attachments = get_course_resources(User.current.id, user_course_ids, @order, @score) + elsif params[:status] == "3" + @attachments = get_project_resources(User.current.id, user_project_ids, @order, @score) + elsif params[:status] == "4" + @attachments = get_attch_resources(User.current.id, @order, @score) + elsif params[:status] == "5" + @attachments = get_principal_resources(User.current.id, @order, @score) + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score) + end + elsif (params[:type].blank? || params[:type] == "6") # 公共资源 + if params[:status] == "2" + @attachments = get_course_resources_public( user_course_ids, @order, @score) + elsif params[:status] == "3" + @attachments = get_project_resources_public(user_project_ids, @order, @score) + elsif params[:status] == "4" + @attachments = get_attch_resources_public(@order, @score) + elsif params[:status] == "5" + @attachments = get_principal_resources_public(@order, @score) + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) + end + # elsif params[:type] == "2" + # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} + # if params[:status] == "2" + # resource_type = "'Course'" + # elsif params[:status] == "3" + # resource_type = "'Project'" + # elsif params[:status] == "5" + # resource_type = "'Principal'" + # else + # resource_type = "'Project','OrgSubfield','Principal','Course'" + # end + # @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score) + end + @status = params[:status] + @type = params[:type] + @limit = 25 + @path = user_resource_user_path(User.current, :type => @type) + @user = User.current + @is_remote = true + @atta_count = @attachments.count + @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + @offset ||= @atta_pages.offset + #@curse_attachments_all = @all_attachments[@offset, @limit] + @attachments = paginateHelper @attachments,25 + respond_to do |format| + format.js end - # elsif params[:type] == "2" - # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} - # if params[:status] == "2" - # resource_type = "'Course'" - # elsif params[:status] == "3" - # resource_type = "'Project'" - # elsif params[:status] == "5" - # resource_type = "'Principal'" - # else - # resource_type = "'Project','OrgSubfield','Principal','Course'" - # end - # @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score) end - @status = params[:status] - @type = params[:type] - @limit = 25 - @path = user_resource_user_path(User.current, :type => @type) - @user = User.current - @is_remote = true - @atta_count = @attachments.count - @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 - @offset ||= @atta_pages.offset - #@curse_attachments_all = @all_attachments[@offset, @limit] - @attachments = paginateHelper @attachments,25 - respond_to do |format| - format.js - end -end -def add_exist_file_to_org - @flag = true - if params[:send_id].present? - send_id = params[:send_id] - subfield_id = params[:subfield] - if subfield_id.nil? - @flag = false - 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 + def add_exist_file_to_org + @flag = true + if params[:send_id].present? + send_id = params[:send_id] + subfield_id = params[:subfield] + if subfield_id.nil? + @flag = false 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 - # 更新引用次数 - quotes = ori.quotes.to_i + 1 - ori.update_attribute(:quotes, quotes) unless ori.nil? - ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) - end - end - end - @ori = ori - elsif params[:send_ids].present? - send_ids = params[:send_ids].split(",") - subfield_id = params[:subfield] - if subfield_id.nil? - @flag = false - end - send_ids.each do |send_id| - quotes = 0 ori = Attachment.find_by_id(send_id) unless subfield_id.nil? - next if ori.blank? + 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 @@ -3274,436 +3234,475 @@ def add_exist_file_to_org 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 + 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 + # 更新引用次数 + quotes = ori.quotes.to_i + 1 + ori.update_attribute(:quotes, quotes) unless ori.nil? + ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) + end end - if attach_copied_obj.save - # 更新引用次数 - quotes = ori.quotes.to_i + 1 - ori.update_attribute(:quotes, quotes) unless ori.nil? - ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) + end + @ori = ori + elsif params[:send_ids].present? + send_ids = params[:send_ids].split(",") + subfield_id = params[:subfield] + if subfield_id.nil? + @flag = false + end + send_ids.each do |send_id| + quotes = 0 + 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 + # 更新引用次数 + quotes = ori.quotes.to_i + 1 + ori.update_attribute(:quotes, quotes) unless ori.nil? + 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 + @flag=true + end + @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + @score = @b_sort == "desc" ? "asc" : "desc" + user_project_ids = User.current.projects.map {|p| p.id} + user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 + if(params[:type] == "1") # 我的资源 + # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 + if params[:status] == "2" + @attachments = get_course_resources(User.current.id, user_course_ids, @order, @score) + elsif params[:status] == "3" + @attachments = get_project_resources(User.current.id, user_project_ids, @order, @score) + elsif params[:status] == "4" + @attachments = get_attch_resources(User.current.id, @order, @score) + elsif params[:status] == "5" + @attachments = get_principal_resources(User.current.id, @order, @score) + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score) + end + elsif (params[:type].blank? || params[:type] == "6") # 公共资源 + if params[:status] == "2" + @attachments = get_course_resources_public( user_course_ids, @order, @score) + elsif params[:status] == "3" + @attachments = get_project_resources_public(user_project_ids, @order, @score) + elsif params[:status] == "4" + @attachments = get_attch_resources_public(@order, @score) + elsif params[:status] == "5" + @attachments = get_principal_resources_public(@order, @score) + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) + end + # elsif params[:type] == "2" + # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} + # if params[:status] == "2" + # resource_type = "'Course'" + # elsif params[:status] == "3" + # resource_type = "'Project'" + # elsif params[:status] == "5" + # resource_type = "'Principal'" + # else + # resource_type = "'Project','OrgSubfield','Principal','Course'" + # end + # @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score) + end + @type = params[:type] + @limit = 25 + @path = user_resource_user_path(User.current, :type => @type) + @user = User.current + @is_remote = true + @atta_count = @attachments.count + @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + @offset ||= @atta_pages.offset + #@curse_attachments_all = @all_attachments[@offset, @limit] + @attachments = paginateHelper @attachments,25 + respond_to do |format| + format.js + end + end + + def share_news_to_course + news = News.find(params[:send_id]) + course_ids = params[:course_ids] + course_ids.each do |course_id| + if Course.find(course_id).news.map(&:id).exclude?(news.id) + course_news = News.create(:course_id => course_id.to_i, :title => news.title, :summary => news.summary, :description => news.description,:author_id => User.current.id, :created_on => Time.now,:project_id => -1) + #record forward to table forwards if new record is valid + if course_news.valid? + news.forwards << Forward.new(:to_type => course_news.class.name, :to_id => course_news.id) + 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) end end end - else - @flag=true end - @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" - @score = @b_sort == "desc" ? "asc" : "desc" - user_project_ids = User.current.projects.map {|p| p.id} - user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 - if(params[:type] == "1") # 我的资源 - # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 - if params[:status] == "2" - @attachments = get_course_resources(User.current.id, user_course_ids, @order, @score) - elsif params[:status] == "3" - @attachments = get_project_resources(User.current.id, user_project_ids, @order, @score) - elsif params[:status] == "4" - @attachments = get_attch_resources(User.current.id, @order, @score) - elsif params[:status] == "5" - @attachments = get_principal_resources(User.current.id, @order, @score) - else - # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score) - end - elsif (params[:type].blank? || params[:type] == "6") # 公共资源 - if params[:status] == "2" - @attachments = get_course_resources_public( user_course_ids, @order, @score) - elsif params[:status] == "3" - @attachments = get_project_resources_public(user_project_ids, @order, @score) - elsif params[:status] == "4" - @attachments = get_attch_resources_public(@order, @score) - elsif params[:status] == "5" - @attachments = get_principal_resources_public(@order, @score) - else - # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) - end - # elsif params[:type] == "2" - # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} - # if params[:status] == "2" - # resource_type = "'Course'" - # elsif params[:status] == "3" - # resource_type = "'Project'" - # elsif params[:status] == "5" - # resource_type = "'Principal'" - # else - # resource_type = "'Project','OrgSubfield','Principal','Course'" - # end - # @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score) - end - @type = params[:type] - @limit = 25 - @path = user_resource_user_path(User.current, :type => @type) - @user = User.current - @is_remote = true - @atta_count = @attachments.count - @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 - @offset ||= @atta_pages.offset - #@curse_attachments_all = @all_attachments[@offset, @limit] - @attachments = paginateHelper @attachments,25 - respond_to do |format| - format.js - end -end -def share_news_to_course - news = News.find(params[:send_id]) - course_ids = params[:course_ids] - course_ids.each do |course_id| - if Course.find(course_id).news.map(&:id).exclude?(news.id) - course_news = News.create(:course_id => course_id.to_i, :title => news.title, :summary => news.summary, :description => news.description,:author_id => User.current.id, :created_on => Time.now,:project_id => -1) - #record forward to table forwards if new record is valid - if course_news.valid? - news.forwards << Forward.new(:to_type => course_news.class.name, :to_id => course_news.id) - 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) + def share_news_to_project + news = News.find(params[:send_id]) + project_ids = params[:project_ids] + project_ids.each do |project_id| + project = Project.find(project_id) + if project.news.map(&:id).exclude?(news.id) + # message = Message.create(:board_id => project.boards.first.id, :subject => news.title, :content => news.description, :author_id => User.current.id) + message = News.create(:project_id => project.id, :title => news.title, :summary => news.summary, :description => news.description, :author_id => User.current.id, :created_on => Time.now ) + # record forward to table forwards if new record is valid + if message.valid? + news.forwards << Forward.new(:to_type => message.class.name, :to_id => message.id) + 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) + end end end end -end -def share_news_to_project - news = News.find(params[:send_id]) - project_ids = params[:project_ids] - project_ids.each do |project_id| - project = Project.find(project_id) - if project.news.map(&:id).exclude?(news.id) - # message = Message.create(:board_id => project.boards.first.id, :subject => news.title, :content => news.description, :author_id => User.current.id) - message = News.create(:project_id => project.id, :title => news.title, :summary => news.summary, :description => news.description, :author_id => User.current.id, :created_on => Time.now ) - # record forward to table forwards if new record is valid - if message.valid? - news.forwards << Forward.new(:to_type => message.class.name, :to_id => message.id) - 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) + def share_news_to_org + news = News.find(params[:send_id]) + field_id = params[:subfield] + org_news = News.create(:org_subfield_id => field_id.to_i, :title => news.title, :summary => news.summary, :description => news.description,:author_id => User.current.id, :created_on => Time.now,:project_id => -1) + # record forward to table forwards if new record is valid + if org_news.valid? + news.forwards << Forward.new(:to_type => org_news.class.name, :to_id => org_news.id) + 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) + 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 + + def share_message_to_course + @message = Message.find(params[:send_id]) + course_ids = params[:course_ids] + course_ids.each do |course_id| + course = Course.find(course_id) + if course.news.map(&:id).exclude?(@message.id) + message = Message.create(:board_id => course.boards.first.id, :subject => @message.subject, :content => @message.content, :author_id => User.current.id) + # record forward to table forwards if new record is valid + if message.valid? + @message.forwards << Forward.new(:to_type => message.class.name, :to_id => message.id) + end + @message.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) + end end end end -end -def share_news_to_org - news = News.find(params[:send_id]) - field_id = params[:subfield] - org_news = News.create(:org_subfield_id => field_id.to_i, :title => news.title, :summary => news.summary, :description => news.description,:author_id => User.current.id, :created_on => Time.now,:project_id => -1) - # record forward to table forwards if new record is valid - if org_news.valid? - news.forwards << Forward.new(:to_type => org_news.class.name, :to_id => org_news.id) - 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) - 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 - -def share_message_to_course - @message = Message.find(params[:send_id]) - course_ids = params[:course_ids] - course_ids.each do |course_id| - course = Course.find(course_id) - if course.news.map(&:id).exclude?(@message.id) - message = Message.create(:board_id => course.boards.first.id, :subject => @message.subject, :content => @message.content, :author_id => User.current.id) - # record forward to table forwards if new record is valid - if message.valid? - @message.forwards << Forward.new(:to_type => message.class.name, :to_id => message.id) - end - @message.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) + def share_message_to_project + @message = Message.find(params[:send_id]) + project_ids = params[:project_ids] + project_ids.each do |project_id| + project = Project.find(project_id) + if project.news.map(&:id).exclude?(@message.id) + message = Message.create(:board_id => project.boards.first.id, :subject => @message.subject, :content => @message.content, :author_id => User.current.id) + # record forward to table forwards if new record is valid + if message.valid? + @message.forwards << Forward.new(:to_type => message.class.name, :to_id => message.id) + end + @message.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) + end end end end -end -def share_message_to_project - @message = Message.find(params[:send_id]) - project_ids = params[:project_ids] - project_ids.each do |project_id| - project = Project.find(project_id) - if project.news.map(&:id).exclude?(@message.id) - message = Message.create(:board_id => project.boards.first.id, :subject => @message.subject, :content => @message.content, :author_id => User.current.id) - # record forward to table forwards if new record is valid - if message.valid? - @message.forwards << Forward.new(:to_type => message.class.name, :to_id => message.id) - end - @message.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) - end + def share_message_to_org + field_id = params[:subfield] + @message = Message.find(params[:send_id]) + @message.quotes = @message.quotes.nil? ? 1 : (@message.quotes + 1) + @message.save + board = OrgSubfield.find(field_id).boards.first + mes = Message.create(:board_id => board.id, :subject => @message.subject, :content => @message.content, :author_id => User.current.id) + # record forward to table forwards if new record is valid + if mes.valid? + @message.forwards << Forward.new(:to_type => mes.class.name, :to_id => mes.id) end + @message.attachments.each do |attach| + mes.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) + end + OrgActivity.create(:container_type => 'OrgSubfield', :container_id => field_id.to_i, :org_act_type=>'Message', :org_act_id => mes.id, :user_id => User.current.id) end -end -def share_message_to_org - field_id = params[:subfield] - @message = Message.find(params[:send_id]) - @message.quotes = @message.quotes.nil? ? 1 : (@message.quotes + 1) - @message.save - board = OrgSubfield.find(field_id).boards.first - mes = Message.create(:board_id => board.id, :subject => @message.subject, :content => @message.content, :author_id => User.current.id) - # record forward to table forwards if new record is valid - if mes.valid? - @message.forwards << Forward.new(:to_type => mes.class.name, :to_id => mes.id) + def change_org_subfield + end - @message.attachments.each do |attach| - mes.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) - end - OrgActivity.create(:container_type => 'OrgSubfield', :container_id => field_id.to_i, :org_act_type=>'Message', :org_act_id => mes.id, :user_id => User.current.id) -end - -def change_org_subfield - -end # 资源预览 -def resource_preview - preview_id = params[:resource_id] - @file = Attachment.find(preview_id) - @preview_able = false; - if %w(pdf pptx doc docx xls xlsx).any?{|x| @file.filename.downcase.end_with?(x)} - @preview_able = true; + def resource_preview + preview_id = params[:resource_id] + @file = Attachment.find(preview_id) + @preview_able = false; + if %w(pdf pptx doc docx xls xlsx).any?{|x| @file.filename.downcase.end_with?(x)} + @preview_able = true; + end + respond_to do |format| + format.js + end end - respond_to do |format| - format.js - end -end # 重命名资源 -def rename_resource - @attachment = Attachment.find(params[:res_id]) if params[:res_id].present? - if @attachment != nil - @attachment.filename = params[:res_name] - @flag = @attachment.save + def rename_resource + @attachment = Attachment.find(params[:res_id]) if params[:res_id].present? + if @attachment != nil + @attachment.filename = params[:res_name] + @flag = @attachment.save + end + # respond_to do |format| + # format.js + # end + if @flag + render :text=> download_named_attachment_path(@attachment.id, @attachment.filename) + else + render :text=>'fail' + end end - # respond_to do |format| - # format.js - # end - if @flag - render :text=> download_named_attachment_path(@attachment.id, @attachment.filename) - else - render :text=>'fail' - end -end -def destroy - @user.destroy - respond_to do |format| - format.html { redirect_back_or_default(admin_users_path) } - format.api { render_api_ok } + def destroy + @user.destroy + respond_to do |format| + format.html { redirect_back_or_default(admin_users_path) } + format.api { render_api_ok } + end end -end -def edit_membership - @membership = Member.edit_membership(params[:membership_id], params[:membership], @user) - @membership.save - respond_to do |format| - format.html { redirect_to edit_user_url(@user, :tab => 'memberships') } - format.js + def edit_membership + @membership = Member.edit_membership(params[:membership_id], params[:membership], @user) + @membership.save + respond_to do |format| + format.html { redirect_to edit_user_url(@user, :tab => 'memberships') } + format.js + end end -end -def destroy_membership - @membership = Member.find(params[:membership_id]) - if @membership.deletable? - @membership.destroy + def destroy_membership + @membership = Member.find(params[:membership_id]) + if @membership.deletable? + @membership.destroy + end + respond_to do |format| + format.html { redirect_to edit_user_url(@user, :tab => 'memberships') } + format.js + end end - respond_to do |format| - format.html { redirect_to edit_user_url(@user, :tab => 'memberships') } - format.js - end -end ################# added by william -def tag_save - @tags = params[:tag_for_save][:name] - @obj_id = params[:tag_for_save][:object_id] - @obj_flag = params[:tag_for_save][:object_flag] + def tag_save + @tags = params[:tag_for_save][:name] + @obj_id = params[:tag_for_save][:object_id] + @obj_flag = params[:tag_for_save][:object_flag] - case @obj_flag - when '1' then - @obj = User.find_by_id(@obj_id) - when '2' then - @obj = Project.find_by_id(@obj_id) - when '3' then - @obj = Issue.find_by_id(@obj_id) - when '4' then - # @obj = Bid.find_by_id(@obj_id) - when '5' then - @obj = Forum.find_by_id(@obj_id) - when '6' - @obj = Attachment.find_by_id(@obj_id) - when '7' then - @obj = Contest.find_by_id(@obj_id) - when '8' - @obj = OpenSourceProject.find_by_id(@obj_id) - when '9' - @obj = Course.find_by_id(@obj_id) + case @obj_flag + when '1' then + @obj = User.find_by_id(@obj_id) + when '2' then + @obj = Project.find_by_id(@obj_id) + when '3' then + @obj = Issue.find_by_id(@obj_id) + when '4' then + # @obj = Bid.find_by_id(@obj_id) + when '5' then + @obj = Forum.find_by_id(@obj_id) + when '6' + @obj = Attachment.find_by_id(@obj_id) + when '7' then + @obj = Contest.find_by_id(@obj_id) + when '8' + @obj = OpenSourceProject.find_by_id(@obj_id) + when '9' + @obj = Course.find_by_id(@obj_id) + else + @obj = nil + end + unless @obj.nil? + @obj.tag_list.add(@tags.split(",")) else - @obj = nil - end - unless @obj.nil? - @obj.tag_list.add(@tags.split(",")) - else - return - end - if @obj.save - logger.debug "#{__FILE__}:#{__LINE__} ===> #{@obj.to_json}" - else - logger.error "#{__FILE__}:#{__LINE__} ===> #{@obj.errors.try(:full_messages)}" - end - respond_to do |format| - format.js - format.html - end -end - -def tag_saveEx - @tags = params[:tag_name] - @obj_id = params[:obj_id] - @obj_flag = params[:obj_flag] - - case @obj_flag - when '1' then - @obj = User.find_by_id(@obj_id) - when '2' then - @obj = Project.find_by_id(@obj_id) - when '3' then - @obj = Issue.find_by_id(@obj_id) - when '4' then - # @obj = Bid.find_by_id(@obj_id) - when '5' then - @obj = Forum.find_by_id(@obj_id) - when '6' - @obj = Attachment.find_by_id(@obj_id) - when '7' then - @obj = Contest.find_by_id(@obj_id) - when '8' - @obj = OpenSourceProject.find_by_id(@obj_id) - when '9' - @obj = Course.find_by_id(@obj_id) + return + end + if @obj.save + logger.debug "#{__FILE__}:#{__LINE__} ===> #{@obj.to_json}" else - @obj = nil + logger.error "#{__FILE__}:#{__LINE__} ===> #{@obj.errors.try(:full_messages)}" + end + respond_to do |format| + format.js + format.html + end end - unless @obj.nil? - @obj.tag_list.add(@tags.split(",")) - else - return + + def tag_saveEx + @tags = params[:tag_name] + @obj_id = params[:obj_id] + @obj_flag = params[:obj_flag] + + case @obj_flag + when '1' then + @obj = User.find_by_id(@obj_id) + when '2' then + @obj = Project.find_by_id(@obj_id) + when '3' then + @obj = Issue.find_by_id(@obj_id) + when '4' then + # @obj = Bid.find_by_id(@obj_id) + when '5' then + @obj = Forum.find_by_id(@obj_id) + when '6' + @obj = Attachment.find_by_id(@obj_id) + when '7' then + @obj = Contest.find_by_id(@obj_id) + when '8' + @obj = OpenSourceProject.find_by_id(@obj_id) + when '9' + @obj = Course.find_by_id(@obj_id) + else + @obj = nil + end + unless @obj.nil? + @obj.tag_list.add(@tags.split(",")) + else + return + end + if @obj.save + ## 执行成功的操作。 + else + #捕获异常 + end + respond_to do |format| + format.js + format.html + end end - if @obj.save - ## 执行成功的操作。 - else - #捕获异常 - end - respond_to do |format| - format.js - format.html - end -end ###add by huang -def user_watchlist - limit = 10; - query = User.watched_by(@user.id); - @obj_count = query.count(); - @obj_pages = Paginator.new @obj_count,limit,params['page'] - @list = query.order("#{Watcher.table_name}.id desc").limit(limit).offset(@obj_pages.offset).all(); - @action = 'watch' - render :template=>'users/user_fanslist',:layout=>'new_base_user' -end + def user_watchlist + limit = 10; + query = User.watched_by(@user.id); + @obj_count = query.count(); + @obj_pages = Paginator.new @obj_count,limit,params['page'] + @list = query.order("#{Watcher.table_name}.id desc").limit(limit).offset(@obj_pages.offset).all(); + @action = 'watch' + render :template=>'users/user_fanslist',:layout=>'new_base_user' + end ###add by huang -def user_fanslist - limit = 10; - query = @user.watcher_users; - @obj_count = query.count(); - @obj_pages = Paginator.new @obj_count,limit,params['page'] - @list = query.order("#{Watcher.table_name}.id desc").limit(limit).offset(@obj_pages.offset).all(); - @action = 'fans' - render :layout=>'new_base_user' -end -def user_visitorlist - limit = 10; - #query = @user.watcher_users; - query = User.joins("join visitors v on #{User.table_name}.id=v.user_id") - query = query.where("v.master_id=?",@user.id) - @obj_count = query.count(); - @obj_pages = Paginator.new @obj_count,limit,params['page'] - @list = query.order("v.updated_on desc").limit(limit).offset(@obj_pages.offset).all(); - @action = 'visitor' - render :template=>'users/user_fanslist',:layout=>'base_users_new' -end + def user_fanslist + limit = 10; + query = @user.watcher_users; + @obj_count = query.count(); + @obj_pages = Paginator.new @obj_count,limit,params['page'] + @list = query.order("#{Watcher.table_name}.id desc").limit(limit).offset(@obj_pages.offset).all(); + @action = 'fans' + render :layout=>'new_base_user' + end + def user_visitorlist + limit = 10; + #query = @user.watcher_users; + query = User.joins("join visitors v on #{User.table_name}.id=v.user_id") + query = query.where("v.master_id=?",@user.id) + @obj_count = query.count(); + @obj_pages = Paginator.new @obj_count,limit,params['page'] + @list = query.order("v.updated_on desc").limit(limit).offset(@obj_pages.offset).all(); + @action = 'visitor' + render :template=>'users/user_fanslist',:layout=>'base_users_new' + end #william -def update_extensions(user_extensions) - user_extensions = params[:user_extensions] - unless user_extensions.nil? - user_extensions = UserExtensions.find_by_id(user_extensions.user_id) + def update_extensions(user_extensions) + user_extensions = params[:user_extensions] + unless user_extensions.nil? + user_extensions = UserExtensions.find_by_id(user_extensions.user_id) - # user_extensions. + # user_extensions. + end end -end -def update_score - @user = User.find(params[:id]) -end + def update_score + @user = User.find(params[:id]) + end #修改个人简介 -def edit_brief_introduction - if @user && @user.extensions - @user.extensions.update_column("brief_introduction",params[:brief_introduction]) + def edit_brief_introduction + if @user && @user.extensions + @user.extensions.update_column("brief_introduction",params[:brief_introduction]) + end + respond_to do |format| + format.js + end end - respond_to do |format| - format.js - end -end # 获取公共资源 -def get_public_resources user_course_ids, user_project_ids, order, score - attachments = Attachment.where("(is_publish = 1 and is_public = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) ").order("#{order.nil? ? 'created_on' : order} #{score}") -end + def get_public_resources user_course_ids, user_project_ids, order, score + attachments = Attachment.where("(is_publish = 1 and is_public = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course')) ").order("#{order.nil? ? 'created_on' : order} #{score}") + end # 获取公共资源搜索 -def get_public_resources_search user_course_ids, user_project_ids, order, score, search - attachments = Attachment.where("is_publish = 1 and is_public = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course') and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") -end + def get_public_resources_search user_course_ids, user_project_ids, order, score, search + attachments = Attachment.where("is_publish = 1 and is_public = 1 and container_id is not null and container_type in('Project','OrgSubfield','Principal','Course') and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") + end # 获取我的资源 -def get_my_resources author_id, user_course_ids, user_project_ids, order, score - attachments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('OrgSubfield','Principal','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("#{order.nil? ? 'created_on' : order} #{score}") -end + def get_my_resources author_id, user_course_ids, user_project_ids, order, score + attachments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type in('OrgSubfield','Principal','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("#{order.nil? ? 'created_on' : order} #{score}") + end # 获取我的资源查询结果 -def get_my_resources_search (author_id, user_course_ids, user_project_ids, order, score, search) - @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("#{order.nil? ? 'created_on' : order} #{score}") -end + def get_my_resources_search (author_id, user_course_ids, user_project_ids, order, score, search) + @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("#{order.nil? ? 'created_on' : order} #{score}") + end # 获取我的课程资源 -def get_course_resources author_id, user_course_ids, order, score - attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and container_type = 'Course')"+ - "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) + def get_course_resources author_id, user_course_ids, order, score + attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) and container_type = '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)" ).order("#{order.nil? ? 'created_on' : order} #{score}") -end + end # # 获取我的私有资源分享结果 # def get_my_private_resources apply_ids, resource_type, order, score @@ -3716,475 +3715,428 @@ end # end # 获取我的课程资源中搜索结果 -def get_course_resources_search author_id, user_course_ids, order, score, search - attchments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Course')"+ - "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}) + def get_course_resources_search author_id, user_course_ids, order, score, search + attchments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = '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)) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") -end + end # 获取公共资源中课程资源 -def get_course_resources_public user_course_ids, order, score - attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1 and is_public =1)").order("#{order.nil? ? 'created_on' : order} #{score}") -end + def get_course_resources_public user_course_ids, order, score + attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1 and is_public =1)").order("#{order.nil? ? 'created_on' : order} #{score}") + end # 获取公共资源中课程资源搜索结果 -def get_course_resources_public_search user_course_ids, order, score, search - attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1 and is_public =1) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") -end + def get_course_resources_public_search user_course_ids, order, score, search + attchments = Attachment.where("(container_type = 'Course'and container_id is not null and is_publish = 1 and is_public =1) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") + end # 获取我的项目资源 -def get_project_resources author_id, user_project_ids, order, score - attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Project') "+ - "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) + def get_project_resources author_id, user_project_ids, order, score + attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Project') "+ + "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("#{order.nil? ? 'created_on' : order} #{score}") -end + end # 获取我的项目资源搜索 -def get_project_resources_search author_id, user_project_ids, order, score, search - attchments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Project') "+ - "or (container_type = 'Project' and container_id in (#{user_project_ids.empty? ? '0': user_project_ids.join(',')}) + def get_project_resources_search author_id, user_project_ids, order, score, search + attchments = Attachment.where("((author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Project') "+ + "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("#{order.nil? ? 'created_on' : order} #{score}") -end + end # 获取公共资源的项目资源 -def get_project_resources_public user_project_ids, order, score - attchments = Attachment.where("container_type = 'Project' and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}") -end + def get_project_resources_public user_project_ids, order, score + attchments = Attachment.where("container_type = 'Project' and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}") + end # 获取公共资源的项目资源搜索 -def get_project_resources_public_search user_project_ids, order, score, search - attchments = Attachment.where("(container_type = 'Project' and container_id is not null and is_public =1) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") -end + def get_project_resources_public_search user_project_ids, order, score, search + attchments = Attachment.where("(container_type = 'Project' and container_id is not null and is_public =1) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") + end # 获取我上传的附件 -def get_attch_resources author_id, order, score - attchments = 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', + def get_attch_resources author_id, order, score + attchments = 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'))").order("#{order.nil? ? 'created_on' : order} #{score}") -end + end # 获取我上传的附件搜索结果 -def get_attch_resources_search author_id, order, score, search - attchments = 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', + def get_attch_resources_search author_id, order, score, search + attchments = 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')) and (filename like :p)", :p => search ).order("#{order.nil? ? 'created_on' : order} #{score}") -end + end # 获取公共资源中我上传的附件 -def get_attch_resources_public order, score - attchments = Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal') + def get_attch_resources_public order, score + attchments = Attachment.where("container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal') and container_id is not null and is_public =1").order("#{order.nil? ? 'created_on' : order} #{score}") -end + end # 获取公共资源中我上传的附件 -def get_attch_resources_public_search order, score, search - attchments = Attachment.where("(container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal') + def get_attch_resources_public_search order, score, search + attchments = Attachment.where("(container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon','OrgSubfield','Principal') and container_id is not null and is_public =1) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") -end + end # 获取我的用户类型资源 -def get_principal_resources author_id, order, score - attchments = Attachment.where("author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Principal'").order("#{order.nil? ? 'created_on' : order} #{score}") -end + def get_principal_resources author_id, order, score + attchments = Attachment.where("author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Principal'").order("#{order.nil? ? 'created_on' : order} #{score}") + end # 获取我的用户类型资源搜索 -def get_principal_resources_search author_id, order, score, search - attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Principal') and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") -end + def get_principal_resources_search author_id, order, score, search + attchments = Attachment.where("(author_id = #{author_id} and is_publish = 1 and container_id is not null and container_type = 'Principal') and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") + end # 获取我的用户类型资源 -def get_principal_resources_public order, score - attchments = Attachment.where("container_type = 'Principal' and is_public =1 and container_id is not null").order("#{order.nil? ? 'created_on' : order} #{score}") -end + def get_principal_resources_public order, score + attchments = Attachment.where("container_type = 'Principal' and is_public =1 and container_id is not null").order("#{order.nil? ? 'created_on' : order} #{score}") + end # 获取我的用户类型资源 -def get_principal_resources_public_search order, score, search - attchments = Attachment.where("(container_type = 'Principal'and container_id is not null and is_public =1) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") -end + def get_principal_resources_public_search order, score, search + attchments = Attachment.where("(container_type = 'Principal'and container_id is not null and is_public =1) and (filename like :p)", :p => search).order("#{order.nil? ? 'created_on' : order} #{score}") + end # 资源库 分为全部 课程资源 项目资源 附件 -def user_resource - # 别人的资源库是没有权限去看的 - if User.current.id.to_i != @user.id.to_i - render_403 - return - end - @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" - @score = @b_sort == "desc" ? "asc" : "desc" - user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} - user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } - # user_org_ids = User.current.organizations.map {|o| o.id} - if(params[:type].blank? || params[:type] == "1") # 我的资源 - # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 - if params[:status] == "2" - @attachments = get_course_resources(User.current.id, user_course_ids, @order, @score) - elsif params[:status] == "3" - @attachments = get_project_resources(User.current.id, user_project_ids, @order, @score) - elsif params[:status] == "4" - @attachments = get_attch_resources(User.current.id, @order, @score) - elsif params[:status] == "5" - @attachments = get_principal_resources(User.current.id, @order, @score) - else - # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score) + def user_resource + # 别人的资源库是没有权限去看的 + if User.current.id.to_i != @user.id.to_i + render_403 + return end - elsif (params[:type] == "6") # 公共资源 - if params[:status] == "2" - @attachments = get_course_resources_public( user_course_ids, @order, @score) - elsif params[:status] == "3" - @attachments = get_project_resources_public(user_project_ids, @order, @score) - elsif params[:status] == "4" - @attachments = get_attch_resources_public(@order, @score) - elsif params[:status] == "5" - @attachments = get_principal_resources_public(@order, @score) - else - # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) - end - # elsif params[:type] == "2" # 私有资源 - # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} - # if params[:status] == "2" - # resource_type = "'Course'" - # elsif params[:status] == "3" - # resource_type = "'Project'" - # elsif params[:status] == "5" - # resource_type = "'Principal'" - # else - # resource_type = "'Project','OrgSubfield','Principal','Course'" - # end - # @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score) - end - @status = params[:status] - @type = params[:type] - @limit = 25 - @is_remote = true - @atta_count = @attachments.count - @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 - @offset ||= @atta_pages.offset - #@curse_attachments_all = @all_attachments[@offset, @limit] - @attachments = paginateHelper @attachments,25 - respond_to do |format| - format.js - format.html {render :layout => 'new_base'} - end -end - -# 导入资源 -def import_resources - @resource_id = params[:project_id].nil? ? (params[:course_id].nil? ? params[:subfield_file_id] : params[:course_id]) : params[:project_id] - @resource_type = params[:project_id].nil? ? (params[:course_id].nil? ? "SubfieldFile" : "Course") : "Project" - @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" - @score = @b_sort == "desc" ? "asc" : "desc" - user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} - user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } # user_org_ids = User.current.organizations.map {|o| o.id} - if(params[:type].blank? || params[:type] == "1") # 我的资源 - # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 - @attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score) - elsif params[:type] == "6" # 公共资源 - # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) - end - @status = params[:status] - @type = params[:type] - @limit = 10 - @is_remote = true - @atta_count = @attachments.count - @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 - @offset ||= @atta_pages.offset - #@curse_attachments_all = @all_attachments[@offset, @limit] - @attachments = paginateHelper @attachments,10 - respond_to do |format| - format.js - format.html {render :layout => 'new_base'} - end -end - -def import_resources_search - @resource_id = params[:mul_id] - @resource_type = params[:mul_type] - @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" - @score = @b_sort == "desc" ? "asc" : "desc" - @user = User.current - @switch_search = params[:name].nil? ? " " : params[:name] - search = "%#{@switch_search.strip.downcase}%" - # 别人的资源库是没有权限去看的 - if(params[:type].blank? || params[:type] == "1") # 我的资源 - # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 + @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + @score = @b_sort == "desc" ? "asc" : "desc" user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } # user_org_ids = User.current.organizations.map {|o| o.id} - @attachments = get_my_resources_search(User.current.id, user_course_ids, user_project_ids, @order, @score, search) - elsif params[:type] == "6" # 公共资源 - # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_public_resources_search(user_course_ids, user_project_ids, @order, @score, search) - end - @type = params[:type] - @limit = 10 - @is_remote = true - @atta_count = @attachments.count - @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 - @offset ||= @atta_pages.offset - #@curse_attachments_all = @all_attachments[@offset, @limit] - @attachments = paginateHelper @attachments, 10 - respond_to do |format| - format.js - # format.html {render :layout => 'new_base'} - end -end - -# 内容导入到对象中 -def import_into_container - send_ids = params[:checkbox1] - # mul_id为当前课程id、项目id、组织id的多种形态 - mul_id = params[:mul_id] - if params[:mul_type] == "Course" - mul_container = Course.find(mul_id) - elsif params[:mul_type] == "Project" - mul_container = Project.find(mul_id) - elsif params[:mul_type] == "SubfieldFile" - mul_container = OrgSubfield.find(mul_id) - end - unless params[:checkbox1].blank? - send_ids.each do |send_id| - ori = Attachment.find_by_id(send_id) - # 如果该附件已经存课程中,则只更新附件创建时间 - mul_container.attachments.each do |att| - @exist = false - 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(params[:type].blank? || params[:type] == "1") # 我的资源 + # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 + if params[:status] == "2" + @attachments = get_course_resources(User.current.id, user_course_ids, @order, @score) + elsif params[:status] == "3" + @attachments = get_project_resources(User.current.id, user_project_ids, @order, @score) + elsif params[:status] == "4" + @attachments = get_attch_resources(User.current.id, @order, @score) + elsif params[:status] == "5" + @attachments = get_principal_resources(User.current.id, @order, @score) + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score) end - next if @exist - attach_copied_obj = ori.copy - attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 - attach_copied_obj.container = mul_container - 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 = 4 + elsif (params[:type] == "6") # 公共资源 + if params[:status] == "2" + @attachments = get_course_resources_public( user_course_ids, @order, @score) + elsif params[:status] == "3" + @attachments = get_project_resources_public(user_project_ids, @order, @score) + elsif params[:status] == "4" + @attachments = get_attch_resources_public(@order, @score) + elsif params[:status] == "5" + @attachments = get_principal_resources_public(@order, @score) + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) end - attach_copied_obj.save - # 附件保存成功后更新项目和课程的统计数 - if params[:mul_type] == "Project" - mul_container.project_score.update_attribute(:attach_num, mul_container.project_score.attach_num + 1) unless mul_container.project_score.nil? - end - @save_message = attach_copied_obj.errors.full_messages + # elsif params[:type] == "2" # 私有资源 + # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} + # if params[:status] == "2" + # resource_type = "'Course'" + # elsif params[:status] == "3" + # resource_type = "'Project'" + # elsif params[:status] == "5" + # resource_type = "'Principal'" + # else + # resource_type = "'Project','OrgSubfield','Principal','Course'" + # end + # @attachments = get_my_private_resources(apply_ids, resource_type, @order, @score) + end + @status = params[:status] + @type = params[:type] + @limit = 25 + @is_remote = true + @atta_count = @attachments.count + @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + @offset ||= @atta_pages.offset + #@curse_attachments_all = @all_attachments[@offset, @limit] + @attachments = paginateHelper @attachments,25 + respond_to do |format| + format.js + format.html {render :layout => 'new_base'} end end - respond_to do |format| - format.html { - if params[:mul_type] == "Course" - redirect_to course_files_url(mul_container) unless mul_container.nil? - elsif params[:mul_type] == "Project" - redirect_to project_files_url(mul_container) unless mul_container.nil? - elsif params[:mul_type] == "SubfieldFile" - redirect_to org_subfield_files_url(mul_container) unless mul_container.nil? - end - } - end -end -# 根据资源关键字进行搜索 -def resource_search - @order, @b_sort = params[:order] || "created_on", params[:sort] || "desc" - @score = @b_sort == "desc" ? "asc" : "desc" - @user = User.current - @switch_search = params[:search].nil? ? " " : params[:search] - search = "%#{@switch_search.strip.downcase}%" - user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} - user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } - if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') # 全部 - if params[:status] == "2" - @attachments = get_course_resources_search(User.current.id, user_course_ids, @order, @score, search) - elsif params[:status] == "3" - @attachments = get_project_resources_search(User.current.id, user_project_ids, @order, @score, search) - elsif params[:status] == "4" - @attachments = get_attch_resources_search(User.current.id, @order, @score, search) - elsif params[:status] == "5" - @attachments = get_principal_resources_search(User.current.id, @order, @score, search) - else +# 导入资源 + def import_resources + @resource_id = params[:project_id].nil? ? (params[:course_id].nil? ? params[:subfield_file_id] : params[:course_id]) : params[:project_id] + @resource_type = params[:project_id].nil? ? (params[:course_id].nil? ? "SubfieldFile" : "Course") : "Project" + @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + @score = @b_sort == "desc" ? "asc" : "desc" + user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} + user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } # user_org_ids = User.current.organizations.map {|o| o.id} + if(params[:type].blank? || params[:type] == "1") # 我的资源 + # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 + @attachments = get_my_resources(User.current.id, user_course_ids, user_project_ids, @order, @score) + elsif params[:type] == "6" # 公共资源 # 公共资源库:所有公开资源或者我上传的私有资源 - @attachments = get_my_resources_search(User.current.id, user_course_ids, user_project_ids, @order, @score, search) + @attachments = get_public_resources(user_course_ids, user_project_ids, params[:order], @score) end - elsif params[:type] == "6" # 公共资源 - if params[:status] == "2" - @attachments = get_course_resources_public_search(user_course_ids, @order, @score, search) - elsif params[:status] == "3" - @attachments = get_project_resources_public_search(user_project_ids, @order, @score, search) - elsif params[:status] == "4" - @attachments = get_attch_resources_public_search(@order, @score, search) - elsif params[:status] == "5" - @attachments = get_principal_resources_public_search(@order, @score, search) - else + @status = params[:status] + @type = params[:type] + @limit = 10 + @is_remote = true + @atta_count = @attachments.count + @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + @offset ||= @atta_pages.offset + #@curse_attachments_all = @all_attachments[@offset, @limit] + @attachments = paginateHelper @attachments,10 + respond_to do |format| + format.js + format.html {render :layout => 'new_base'} + end + end + + def import_resources_search + @resource_id = params[:mul_id] + @resource_type = params[:mul_type] + @order, @b_sort = params[:order] || "created_on", params[:sort] || "asc" + @score = @b_sort == "desc" ? "asc" : "desc" + @user = User.current + @switch_search = params[:name].nil? ? " " : params[:name] + search = "%#{@switch_search.strip.downcase}%" + # 别人的资源库是没有权限去看的 + if(params[:type].blank? || params[:type] == "1") # 我的资源 + # 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源 + user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} + user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } + # user_org_ids = User.current.organizations.map {|o| o.id} + @attachments = get_my_resources_search(User.current.id, user_course_ids, user_project_ids, @order, @score, search) + elsif params[:type] == "6" # 公共资源 # 公共资源库:所有公开资源或者我上传的私有资源 @attachments = get_public_resources_search(user_course_ids, user_project_ids, @order, @score, search) end - # elsif params[:type] == "2" # 私有资源 - # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} - # if params[:status] == "2" - # resource_type = "'Course'" - # elsif params[:status] == "3" - # resource_type = "'Project'" - # elsif params[:status] == "5" - # resource_type = "'Principal'" - # else - # resource_type = "'Project','OrgSubfield','Principal','Course'" - # end - # @attachments = get_my_private_resources_search(apply_ids, resource_type, @order, @score, search) - # @attachments - end - @status = params[:status] - @type = params[:type] - @limit = 25 - @is_remote = true - @atta_count = @attachments.count - @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 - @offset ||= @atta_pages.offset - #@curse_attachments_all = @all_attachments[@offset, @limit] - @attachments = paginateHelper @attachments,25 - respond_to do |format| - format.js - end -end - -def user_organizations - @user = User.current - @orgs = @user.organizations - respond_to do |format| - format.html {render :layout => 'static_base'} - end -end - -def search_user_orgs - name="" - if !params[:search_orgs].nil? - name = params[:search_orgs].strip - end - name = "%"+name+"%" - @orgs = User.current.organizations.where("name like ?", name) - @user = User.current - @type = params[:type] - respond_to do |format| - format.html {render :layout => 'static_base'} - format.js - end -end - -def search_user_org - @user = User.current - if !params[:search].nil? #发送到有栏目类型为资源的组织中 - search = "%#{params[:search].to_s.strip.downcase}%" - if params[:send_type].present? and (params[:send_type] == 'news' or params[:send_type] == 'message') - @orgs = @user.organizations.where("name like ?", search).select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Post'").count > 0} - else - @orgs = @user.organizations.where("name like ?", search).select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Resource'").count > 0} - end - else - if params[:send_type].present? and (params[:send_type] == 'news' or params[:send_type] == 'message') - @orgs = @user.organizations.select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Post'").count > 0} - else - @orgs = @user.organizations.select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Resource'").count > 0} + @type = params[:type] + @limit = 10 + @is_remote = true + @atta_count = @attachments.count + @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + @offset ||= @atta_pages.offset + #@curse_attachments_all = @all_attachments[@offset, @limit] + @attachments = paginateHelper @attachments, 10 + respond_to do |format| + format.js + # format.html {render :layout => 'new_base'} end end - @type = params[:type] - @search = params[:search] - #这里仅仅是传递需要发送的资源id - @send_id = params[:send_id] - @send_ids = params[:checkbox1] || params[:send_ids] - @hidden_unproject = hidden_unproject_infos - respond_to do |format| - format.js - end -end -def user_courselist - @order, @c_sort, @type, @list_type = 1, 2, 1, 1 - - @my_syllabuses = @user.syllabuses - - if @user == User.current - archive_ids = Course.where("tea_id = #{@user.id} and is_delete = 1 and syllabus_id is NOT NULL").blank? ? "(-1)" : "(" + Course.where("tea_id = #{@user.id} and is_delete = 1 and syllabus_id is NOT NULL").map{|course| course.syllabus_id}.join(",") + ")" - @archive_syllabuses = Syllabus.where("id in #{archive_ids}") +# 内容导入到对象中 + def import_into_container + send_ids = params[:checkbox1] + # mul_id为当前课程id、项目id、组织id的多种形态 + mul_id = params[:mul_id] + if params[:mul_type] == "Course" + mul_container = Course.find(mul_id) + elsif params[:mul_type] == "Project" + mul_container = Project.find(mul_id) + elsif params[:mul_type] == "SubfieldFile" + mul_container = OrgSubfield.find(mul_id) + end + unless params[:checkbox1].blank? + send_ids.each do |send_id| + ori = Attachment.find_by_id(send_id) + # 如果该附件已经存课程中,则只更新附件创建时间 + mul_container.attachments.each do |att| + @exist = false + 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 = mul_container + 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 = 4 + end + attach_copied_obj.save + # 附件保存成功后更新项目和课程的统计数 + if params[:mul_type] == "Project" + mul_container.project_score.update_attribute(:attach_num, mul_container.project_score.attach_num + 1) unless mul_container.project_score.nil? + end + @save_message = attach_copied_obj.errors.full_messages + end + end + respond_to do |format| + format.html { + if params[:mul_type] == "Course" + redirect_to course_files_url(mul_container) unless mul_container.nil? + elsif params[:mul_type] == "Project" + redirect_to project_files_url(mul_container) unless mul_container.nil? + elsif params[:mul_type] == "SubfieldFile" + redirect_to org_subfield_files_url(mul_container) unless mul_container.nil? + end + } + end end - sy_courses = @user.courses.visible.not_deleted - syllabus_ids = sy_courses.empty? ? '(-1)' : "(" + sy_courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")" - syllabus_members = SyllabusMember.where("user_id = #{@user.id}") - syllabus_member_ids = syllabus_members.empty? ? "(-1)" : "(" + syllabus_members.map{|syl_mem| syl_mem.syllabus_id}.join(',') + ")" - @join_syllabuses = Syllabus.where("(id in #{syllabus_ids} or id in #{syllabus_member_ids}) and user_id != #{@user.id}") - - @my_syllabuses = syllabus_course_list_sort @my_syllabuses - @join_syllabuses = syllabus_course_list_sort @join_syllabuses - @my_syllabuses = @my_syllabuses.sort{|x,y| y[:last_update] <=> x[:last_update]} - @join_syllabuses = @join_syllabuses.sort{|x,y| y[:last_update] <=> x[:last_update]} - @is_course = 1 - - #分页 - # @limit = 10 - # @is_remote = true - # @atta_count = @syllabus.count - # @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 - # @offset ||= @atta_pages.offset - # @syllabus = paginateHelper @syllabus,@limit - - respond_to do |format| - format.html {render :layout => 'base_course_community'} +# 根据资源关键字进行搜索 + def resource_search + @order, @b_sort = params[:order] || "created_on", params[:sort] || "desc" + @score = @b_sort == "desc" ? "asc" : "desc" + @user = User.current + @switch_search = params[:search].nil? ? " " : params[:search] + search = "%#{@switch_search.strip.downcase}%" + user_course_ids = User.current.courses.map { |c| c.is_delete == 0 && c.id} + user_project_ids = User.current.projects.map {|p| p.status != 9 && p.id } + if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') # 全部 + if params[:status] == "2" + @attachments = get_course_resources_search(User.current.id, user_course_ids, @order, @score, search) + elsif params[:status] == "3" + @attachments = get_project_resources_search(User.current.id, user_project_ids, @order, @score, search) + elsif params[:status] == "4" + @attachments = get_attch_resources_search(User.current.id, @order, @score, search) + elsif params[:status] == "5" + @attachments = get_principal_resources_search(User.current.id, @order, @score, search) + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_my_resources_search(User.current.id, user_course_ids, user_project_ids, @order, @score, search) + end + elsif params[:type] == "6" # 公共资源 + if params[:status] == "2" + @attachments = get_course_resources_public_search(user_course_ids, @order, @score, search) + elsif params[:status] == "3" + @attachments = get_project_resources_public_search(user_project_ids, @order, @score, search) + elsif params[:status] == "4" + @attachments = get_attch_resources_public_search(@order, @score, search) + elsif params[:status] == "5" + @attachments = get_principal_resources_public_search(@order, @score, search) + else + # 公共资源库:所有公开资源或者我上传的私有资源 + @attachments = get_public_resources_search(user_course_ids, user_project_ids, @order, @score, search) + end + # elsif params[:type] == "2" # 私有资源 + # apply_ids = ApplyResource.where("user_id =? and status =?", params[:id], 2).map { |ar| ar.attachment_id} + # if params[:status] == "2" + # resource_type = "'Course'" + # elsif params[:status] == "3" + # resource_type = "'Project'" + # elsif params[:status] == "5" + # resource_type = "'Principal'" + # else + # resource_type = "'Project','OrgSubfield','Principal','Course'" + # end + # @attachments = get_my_private_resources_search(apply_ids, resource_type, @order, @score, search) + # @attachments + end + @status = params[:status] + @type = params[:type] + @limit = 25 + @is_remote = true + @atta_count = @attachments.count + @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + @offset ||= @atta_pages.offset + #@curse_attachments_all = @all_attachments[@offset, @limit] + @attachments = paginateHelper @attachments,25 + respond_to do |format| + format.js + end + end + + def user_organizations + @user = User.current + @orgs = @user.organizations + respond_to do |format| + format.html {render :layout => 'static_base'} + end + end + + def search_user_orgs + name="" + if !params[:search_orgs].nil? + name = params[:search_orgs].strip + end + name = "%"+name+"%" + @orgs = User.current.organizations.where("name like ?", name) + @user = User.current + @type = params[:type] + respond_to do |format| + format.html {render :layout => 'static_base'} + format.js + end + end + + def search_user_org + @user = User.current + if !params[:search].nil? #发送到有栏目类型为资源的组织中 + search = "%#{params[:search].to_s.strip.downcase}%" + if params[:send_type].present? and (params[:send_type] == 'news' or params[:send_type] == 'message') + @orgs = @user.organizations.where("name like ?", search).select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Post'").count > 0} + else + @orgs = @user.organizations.where("name like ?", search).select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Resource'").count > 0} + end + else + if params[:send_type].present? and (params[:send_type] == 'news' or params[:send_type] == 'message') + @orgs = @user.organizations.select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Post'").count > 0} + else + @orgs = @user.organizations.select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Resource'").count > 0} + end + end + @type = params[:type] + @search = params[:search] + #这里仅仅是传递需要发送的资源id + @send_id = params[:send_id] + @send_ids = params[:checkbox1] || params[:send_ids] + @hidden_unproject = hidden_unproject_infos + respond_to do |format| + format.js + end + end + + def user_courselist + @order, @c_sort, @type, @list_type = 1, 2, 1, 1 + + @my_syllabuses = @user.syllabuses + + if @user == User.current + archive_ids = Course.where("tea_id = #{@user.id} and is_delete = 1 and syllabus_id is NOT NULL").blank? ? "(-1)" : "(" + Course.where("tea_id = #{@user.id} and is_delete = 1 and syllabus_id is NOT NULL").map{|course| course.syllabus_id}.join(",") + ")" + @archive_syllabuses = Syllabus.where("id in #{archive_ids}") + end + + sy_courses = @user.courses.visible.not_deleted + syllabus_ids = sy_courses.empty? ? '(-1)' : "(" + sy_courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")" + syllabus_members = SyllabusMember.where("user_id = #{@user.id}") + syllabus_member_ids = syllabus_members.empty? ? "(-1)" : "(" + syllabus_members.map{|syl_mem| syl_mem.syllabus_id}.join(',') + ")" + @join_syllabuses = Syllabus.where("(id in #{syllabus_ids} or id in #{syllabus_member_ids}) and user_id != #{@user.id}") + + @my_syllabuses = syllabus_course_list_sort @my_syllabuses + @join_syllabuses = syllabus_course_list_sort @join_syllabuses + @my_syllabuses = @my_syllabuses.sort{|x,y| y[:last_update] <=> x[:last_update]} + @join_syllabuses = @join_syllabuses.sort{|x,y| y[:last_update] <=> x[:last_update]} + @is_course = 1 + + #分页 + # @limit = 10 + # @is_remote = true + # @atta_count = @syllabus.count + # @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + # @offset ||= @atta_pages.offset + # @syllabus = paginateHelper @syllabus,@limit + + respond_to do |format| + format.html {render :layout => 'base_course_community'} + end end -end #课程列表的排序 -def sort_syllabus_list - @order, @c_sort, @type, @list_type = params[:order] || 1, params[:sort] || 1, params[:type] || 1, params[:list_type] || 1 - - #确定 sort_type - if @order.to_i == @type.to_i - @c_sort = @c_sort.to_i == 1 ? 2 : 1 #1升序 2降序 - else - @c_sort = 2 - end - - sort_name = "updated_at" - - if @list_type.to_i == 1 - @syllabuses = @user.syllabuses.order("updated_at desc") - else - sy_courses = @user.courses.visible.where("is_delete =? and tea_id != ?", 0, @user.id) - syllabus_ids = sy_courses.empty? ? '(-1)' : "(" + sy_courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")" - @syllabuses = Syllabus.where("id in #{syllabus_ids} and user_id != #{@user.id}").order("updated_at desc") - end - - if @order.to_i == 1 #根据 班级更新时间排序 - @syllabuses = syllabus_course_list_sort @syllabuses - @c_sort == 1 ? (@syllabuses = @syllabuses.sort{|x,y| x[:last_update] <=> y[:last_update] }) : (@syllabuses = @syllabuses.sort{|x,y| y[:last_update] <=> x[:last_update]}) - @type = 1 - elsif @order.to_i == 2 #根据 作业+资源数排序 - @type = 2 - @syllabuses.each do |syllabus| - count = 0 - courses = syllabus.courses.not_deleted - courses.each do |c| - count += (User.current.admin? || User.current.allowed_to?(:as_teacher,c)) ? (c.homework_commons.count + visable_attachemnts_incourse(c).count) : (c.homework_commons.where("publish_time <= '#{Date.today}'").count + visable_attachemnts_incourse(c).count) - end - syllabus[:infocount] = count - end - @c_sort == 1 ? (@syllabuses = @syllabuses.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@syllabuses = @syllabuses.sort{|x,y| y[:infocount] <=> x[:infocount]}) - @syllabuses = sortby_time_countcommon_nosticky @syllabuses,sort_name - else - @type = 1 - end - - respond_to do |format| - format.js - end -end - -#归档班级列表 -def user_archive_courses - if User.current.logged? - @order, @c_sort, @type = params[:order] || 1, params[:sort] || 1, params[:type] || 1 + def sort_syllabus_list + @order, @c_sort, @type, @list_type = params[:order] || 1, params[:sort] || 1, params[:type] || 1, params[:list_type] || 1 #确定 sort_type if @order.to_i == @type.to_i @@ -4193,18 +4145,23 @@ def user_archive_courses @c_sort = 2 end - @user = User.current sort_name = "updated_at" - archive_ids = Course.where("tea_id = #{@user.id} and is_delete = 1 and syllabus_id is NOT NULL").blank? ? "(-1)" : "(" + Course.where("tea_id = #{@user.id} and is_delete = 1 and syllabus_id is NOT NULL").map{|course| course.syllabus_id}.join(",") + ")" - @archive_syllabuses = Syllabus.where("id in #{archive_ids}") + + if @list_type.to_i == 1 + @syllabuses = @user.syllabuses.order("updated_at desc") + else + sy_courses = @user.courses.visible.where("is_delete =? and tea_id != ?", 0, @user.id) + syllabus_ids = sy_courses.empty? ? '(-1)' : "(" + sy_courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")" + @syllabuses = Syllabus.where("id in #{syllabus_ids} and user_id != #{@user.id}").order("updated_at desc") + end if @order.to_i == 1 #根据 班级更新时间排序 - @archive_syllabuses = syllabus_course_list_sort @archive_syllabuses - @c_sort == 1 ? (@archive_syllabuses = @archive_syllabuses.sort{|x,y| x[:last_update] <=> y[:last_update] }) : (@archive_syllabuses = @archive_syllabuses.sort{|x,y| y[:last_update] <=> x[:last_update]}) + @syllabuses = syllabus_course_list_sort @syllabuses + @c_sort == 1 ? (@syllabuses = @syllabuses.sort{|x,y| x[:last_update] <=> y[:last_update] }) : (@syllabuses = @syllabuses.sort{|x,y| y[:last_update] <=> x[:last_update]}) @type = 1 elsif @order.to_i == 2 #根据 作业+资源数排序 @type = 2 - @archive_syllabuses.each do |syllabus| + @syllabuses.each do |syllabus| count = 0 courses = syllabus.courses.not_deleted courses.each do |c| @@ -4212,268 +4169,310 @@ def user_archive_courses end syllabus[:infocount] = count end - @c_sort == 1 ? (@archive_syllabuses = @archive_syllabuses.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@archive_syllabuses = @archive_syllabuses.sort{|x,y| y[:infocount] <=> x[:infocount]}) - @archive_syllabuses = sortby_time_countcommon_nosticky @archive_syllabuses,sort_name + @c_sort == 1 ? (@syllabuses = @syllabuses.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@syllabuses = @syllabuses.sort{|x,y| y[:infocount] <=> x[:infocount]}) + @syllabuses = sortby_time_countcommon_nosticky @syllabuses,sort_name else @type = 1 end - respond_to do |format| - format.js - format.html {render :layout => 'base_course_community'} - end - end -end -#展开课程下的班级 -def expand_courses - @syllabus = Syllabus.where("id = #{params[:syllabus_id]}").first - unless @syllabus.nil? - if params[:is_delete] && params[:is_delete] == '1' - @courses = @syllabus.courses.where("is_delete = 1").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc") - else - @courses = @syllabus.courses.not_deleted.select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc") - end respond_to do |format| format.js end end -end -#收藏班级/项目/竞赛 -def cancel_or_collect - if params[:project] - @project = Project.find params[:project] - member = Member.where("user_id = #{@user.id} and project_id = #{@project.id}") - elsif params[:course] - @course = Course.find params[:course] - member = Member.where("user_id = #{@user.id} and course_id = #{@course.id}") - elsif params[:contest] - @contest = Contest.find params[:contest] - member = ContestMember.where("user_id = #{@user.id} and contest_id = #{@contest.id}") - end - if !member.empty? && params[:contest] - member.first.update_attribute(:is_collect, member.first.is_collect == false ? 1 : 0) - elsif !member.empty? - member.first.update_attribute(:is_collect, member.first.is_collect == 0 ? 1 : 0) - end - if @project - @projects = @user.favorite_projects.visible.select("projects.*, (SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(10) - elsif @course - @courses = @user.favorite_courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(10) - elsif @contest - @contests = @user.favorite_contests.visible.where("is_delete =?", 0).select("contests.*,(SELECT MAX(updated_at) FROM `contest_activities` WHERE contest_activities.contest_id = contests.id) AS a").order("a desc").limit(10) - end - respond_to do |format| - format.js - end -end + # 归档班级列表 + def user_archive_courses + if User.current.logged? + @order, @c_sort, @type = params[:order] || 1, params[:sort] || 1, params[:type] || 1 -# 用户竞赛列表 -def user_contestlist - # 我创建的竞赛 - @contest_community = "竞赛" - @my_contests = @user.contests.where(:user_id => @user.id).order("created_at desc") - @my_contests_count = @my_contests.count - # 我参与的竞赛 - my_all_contests = @user.contest_members.where(:user_id => @user.id).blank? ? "(-1)" : "(" + @user.contest_members.where(:user_id => @user.id).map{ |cm| cm.contest_id }.join(",") + ")" - @my_joined_contests = Contest.where("id in #{my_all_contests} and user_id != #{@user.id}").order("created_at desc") - @my_joined_contests_count = @my_joined_contests.count - respond_to do |format| - format.html {render :layout => 'base_contest_community'} - end -end + #确定 sort_type + if @order.to_i == @type.to_i + @c_sort = @c_sort.to_i == 1 ? 2 : 1 #1升序 2降序 + else + @c_sort = 2 + end -def user_projectlist - @order, @c_sort, @type, @list_type = 1, 2, 1, 1 - #limit = 5 + @user = User.current + sort_name = "updated_at" + archive_ids = Course.where("tea_id = #{@user.id} and is_delete = 1 and syllabus_id is NOT NULL").blank? ? "(-1)" : "(" + Course.where("tea_id = #{@user.id} and is_delete = 1 and syllabus_id is NOT NULL").map{|course| course.syllabus_id}.join(",") + ")" + @archive_syllabuses = Syllabus.where("id in #{archive_ids}") - # 用户的所有项目 - # @my_projects = @user.projects.visible.where("projects.user_id = #{@user.id}").select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS updatetime").order("updatetime DESC") - @my_projects = @user.projects.where("projects.user_id = #{@user.id}").select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS updatetime").order("updatetime DESC") - @my_projects_count = @my_projects.count - - #@my_joined_projects = @user.projects.visible.where("projects.user_id != #{@user.id}").select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS updatetime").order("updatetime DESC") - @my_joined_projects = @user.projects.where("projects.user_id != #{@user.id}").select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS updatetime").order("updatetime DESC") - @my_joined_projects_count = @my_joined_projects.count - - respond_to do |format| - format.html {render :layout => 'base_project_community'} - end -end - -def sort_project_list - @order, @c_sort, @type, @list_type = params[:order] || 1, params[:sort] || 1, params[:type] || 1, params[:list_type] || 1 - #limit = 5 - - #确定 sort_type - if @order.to_i == @type.to_i - @c_sort = @c_sort.to_i == 1 ? 2 : 1 #1升序 2降序 - else - @c_sort = 2 - end - - sort_name = "updatetime" - sort_type = @c_sort == 1 ? "asc" : "desc" - - #@projects = @user.projects.visible.order("#{sort_name} #{sort_type}") - if @list_type.to_i == 1 - @projects = @user.projects.visible.where("projects.user_id = #{@user.id}").select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS #{sort_name}").order("#{sort_name} #{sort_type}") - else - @projects = @user.projects.visible.where("projects.user_id != #{@user.id}").select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS #{sort_name}").order("#{sort_name} #{sort_type}") - end - @projects_count = @projects.count - - #根据 问题+资源数排序 @project.project_score.issue_num @project.project_score.attach_num - if @order.to_i == 2 - @type = 2 - @projects.each do |project| - project[:infocount] = project.project_score.issue_num+project.project_score.attach_num - if project[:infocount] < 0 - project[:infocount] = 0 + if @order.to_i == 1 #根据 班级更新时间排序 + @archive_syllabuses = syllabus_course_list_sort @archive_syllabuses + @c_sort == 1 ? (@archive_syllabuses = @archive_syllabuses.sort{|x,y| x[:last_update] <=> y[:last_update] }) : (@archive_syllabuses = @archive_syllabuses.sort{|x,y| y[:last_update] <=> x[:last_update]}) + @type = 1 + elsif @order.to_i == 2 #根据 作业+资源数排序 + @type = 2 + @archive_syllabuses.each do |syllabus| + count = 0 + courses = syllabus.courses.not_deleted + courses.each do |c| + count += (User.current.admin? || User.current.allowed_to?(:as_teacher,c)) ? (c.homework_commons.count + visable_attachemnts_incourse(c).count) : (c.homework_commons.where("publish_time <= '#{Date.today}'").count + visable_attachemnts_incourse(c).count) + end + syllabus[:infocount] = count + end + @c_sort == 1 ? (@archive_syllabuses = @archive_syllabuses.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@archive_syllabuses = @archive_syllabuses.sort{|x,y| y[:infocount] <=> x[:infocount]}) + @archive_syllabuses = sortby_time_countcommon_nosticky @archive_syllabuses,sort_name + else + @type = 1 + end + respond_to do |format| + format.js + format.html {render :layout => 'base_course_community'} end end - @c_sort == 1 ? (@projects = @projects.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@projects = @projects.sort{|x,y| y[:infocount] <=> x[:infocount] }) - @projects = sortby_time_countcommon_nosticky @projects,sort_name - else - @type = 1 end - respond_to do |format| - format.js - end -end - -def all_journals - if params[:type].present? - case params[:type] - when 'OrgDocumentComment' - @user_activity_id = params[:div_id].to_i if params[:div_id] - @type = 'OrgDocumentComment' - @journals = OrgDocumentComment.where("root_id = #{params[:id].to_i}").reorder("created_at desc") - when 'Message','is_project_message' - @type = 'Message' - @user_activity_id = params[:div_id].to_i if params[:div_id] - @journals = Message.where("root_id = #{params[:id].to_i}").reorder("created_on desc") - when 'News' - obj = News.where('id = ?', params[:id].to_i).first - @journals = obj.comments.reorder("created_on desc") - @type = 'News' - @user_activity_id = params[:div_id].to_i if params[:div_id] - when 'Syllabus' - obj = Syllabus.where('id = ?', params[:id].to_i).first - @journals = obj.journals_for_messages.reorder("created_on desc") - @type = 'Syllabus' - @user_activity_id = params[:div_id].to_i if params[:div_id] - when 'JournalsForMessage' - @journals = JournalsForMessage.where("root_id = #{params[:id].to_i}").reorder("created_on desc") - @type = 'JournalsForMessage' - @user_activity_id = params[:div_id].to_i if params[:div_id] - when 'Issue' - obj = Issue.where('id = ?', params[:id].to_i).first - @journals = obj.journals.reorder("created_on desc") - @type = 'Issue' - @user_activity_id = params[:div_id].to_i if params[:div_id] - when 'is_project_issue' - @activity = Issue.where('id = ?', params[:id].to_i).first - @journals = @activity.journals.reorder("created_on desc") - @user_activity_id = params[:div_id].to_i if params[:div_id] - @user_activity = ForgeActivity.where(params[:div_id].to_i).first if params[:div_id] - when 'BlogComment' - obj = BlogComment.where('id = ?', params[:id].to_i).first - @user_activity_id = params[:div_id].to_i if params[:div_id] - @type = 'BlogComment' - @journals = BlogComment.where("root_id = #{params[:id].to_i}").reorder("created_on desc") - when 'HomeworkCommon' - obj = HomeworkCommon.where('id = ?', params[:id].to_i).first - @type = 'HomeworkCommon' - @journals = obj.journals_for_messages.reorder("created_on desc") - @is_teacher = User.current.allowed_to?(:as_teacher,obj.course) - @user_activity_id = params[:user_activity_id].to_i if params[:user_activity_id] - when 'Work' - obj = Work.where('id = ?', params[:id].to_i).first - @type = 'Work' - @journals = obj.journals_for_messages.reorder("created_on desc") - @is_teacher = User.current.admin_of_contest?(obj.contest) - @user_activity_id = params[:user_activity_id].to_i if params[:user_activity_id] + # 展开课程下的班级 + def expand_courses + @syllabus = Syllabus.where("id = #{params[:syllabus_id]}").first + unless @syllabus.nil? + if params[:is_delete] && params[:is_delete] == '1' + @courses = @syllabus.courses.where("is_delete = 1").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc") + else + @courses = @syllabus.courses.not_deleted.select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc") + end + respond_to do |format| + format.js + end end end - @journals = get_no_children_comments_all @journals -end -def homepage - @article = @user.base_homepage - respond_to do |format| - format.html {render :layout => 'clear_base'} + # 收藏班级/项目/竞赛 + def cancel_or_collect + if params[:project] + @project = Project.find params[:project] + member = Member.where("user_id = #{@user.id} and project_id = #{@project.id}") + elsif params[:course] + @course = Course.find params[:course] + member = Member.where("user_id = #{@user.id} and course_id = #{@course.id}") + elsif params[:contest] + @contest = Contest.find params[:contest] + member = ContestMember.where("user_id = #{@user.id} and contest_id = #{@contest.id}") + end + if !member.empty? && params[:contest] + member.first.update_attribute(:is_collect, member.first.is_collect == false ? 1 : 0) + elsif !member.empty? + member.first.update_attribute(:is_collect, member.first.is_collect == 0 ? 1 : 0) + end + if @project + @projects = @user.favorite_projects.visible.select("projects.*, (SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(10) + elsif @course + @courses = @user.favorite_courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(10) + elsif @contest + @contests = @user.favorite_contests.visible.where("is_delete =?", 0).select("contests.*,(SELECT MAX(updated_at) FROM `contest_activities` WHERE contest_activities.contest_id = contests.id) AS a").order("a desc").limit(10) + end + respond_to do |format| + format.js + end end -end -private -def show_system_message -# 系统消息总显示在最前面,显示周期30天 + # 用户竞赛列表 + def user_contestlist + # 我创建的竞赛 + @contest_community = "竞赛" + @my_contests = @user.contests.where(:user_id => @user.id).order("created_at desc") + @my_contests_count = @my_contests.count + # 我参与的竞赛 + my_all_contests = @user.contest_members.where(:user_id => @user.id).blank? ? "(-1)" : "(" + @user.contest_members.where(:user_id => @user.id).map{ |cm| cm.contest_id }.join(",") + ")" + @my_joined_contests = Contest.where("id in #{my_all_contests} and user_id != #{@user.id}").order("created_at desc") + @my_joined_contests_count = @my_joined_contests.count + respond_to do |format| + format.html {render :layout => 'base_contest_community'} + end + end + + def user_projectlist + @order, @c_sort, @type, @list_type = 1, 2, 1, 1 + #limit = 5 + + # 用户的所有项目 + # @my_projects = @user.projects.visible.where("projects.user_id = #{@user.id}").select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS updatetime").order("updatetime DESC") + @my_projects = @user.projects.where("projects.user_id = #{@user.id}").select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS updatetime").order("updatetime DESC") + @my_projects_count = @my_projects.count + + #@my_joined_projects = @user.projects.visible.where("projects.user_id != #{@user.id}").select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS updatetime").order("updatetime DESC") + @my_joined_projects = @user.projects.where("projects.user_id != #{@user.id}").select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS updatetime").order("updatetime DESC") + @my_joined_projects_count = @my_joined_projects.count + + respond_to do |format| + format.html {render :layout => 'base_project_community'} + end + end + + def sort_project_list + @order, @c_sort, @type, @list_type = params[:order] || 1, params[:sort] || 1, params[:type] || 1, params[:list_type] || 1 + #limit = 5 + + #确定 sort_type + if @order.to_i == @type.to_i + @c_sort = @c_sort.to_i == 1 ? 2 : 1 #1升序 2降序 + else + @c_sort = 2 + end + + sort_name = "updatetime" + sort_type = @c_sort == 1 ? "asc" : "desc" + + #@projects = @user.projects.visible.order("#{sort_name} #{sort_type}") + if @list_type.to_i == 1 + @projects = @user.projects.visible.where("projects.user_id = #{@user.id}").select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS #{sort_name}").order("#{sort_name} #{sort_type}") + else + @projects = @user.projects.visible.where("projects.user_id != #{@user.id}").select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS #{sort_name}").order("#{sort_name} #{sort_type}") + end + @projects_count = @projects.count + + #根据 问题+资源数排序 @project.project_score.issue_num @project.project_score.attach_num + if @order.to_i == 2 + @type = 2 + @projects.each do |project| + project[:infocount] = project.project_score.issue_num+project.project_score.attach_num + if project[:infocount] < 0 + project[:infocount] = 0 + end + end + @c_sort == 1 ? (@projects = @projects.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@projects = @projects.sort{|x,y| y[:infocount] <=> x[:infocount] }) + @projects = sortby_time_countcommon_nosticky @projects,sort_name + else + @type = 1 + end + + respond_to do |format| + format.js + end + end + + def all_journals + if params[:type].present? + case params[:type] + when 'OrgDocumentComment' + @user_activity_id = params[:div_id].to_i if params[:div_id] + @type = 'OrgDocumentComment' + @journals = OrgDocumentComment.where("root_id = #{params[:id].to_i}").reorder("created_at desc") + when 'Message','is_project_message' + @type = 'Message' + @user_activity_id = params[:div_id].to_i if params[:div_id] + @journals = Message.where("root_id = #{params[:id].to_i}").reorder("created_on desc") + when 'News' + obj = News.where('id = ?', params[:id].to_i).first + @journals = obj.comments.reorder("created_on desc") + @type = 'News' + @user_activity_id = params[:div_id].to_i if params[:div_id] + when 'Syllabus' + obj = Syllabus.where('id = ?', params[:id].to_i).first + @journals = obj.journals_for_messages.reorder("created_on desc") + @type = 'Syllabus' + @user_activity_id = params[:div_id].to_i if params[:div_id] + when 'JournalsForMessage' + @journals = JournalsForMessage.where("root_id = #{params[:id].to_i}").reorder("created_on desc") + @type = 'JournalsForMessage' + @user_activity_id = params[:div_id].to_i if params[:div_id] + when 'Issue' + obj = Issue.where('id = ?', params[:id].to_i).first + @journals = obj.journals.reorder("created_on desc") + @type = 'Issue' + @user_activity_id = params[:div_id].to_i if params[:div_id] + when 'is_project_issue' + @activity = Issue.where('id = ?', params[:id].to_i).first + @journals = @activity.journals.reorder("created_on desc") + @user_activity_id = params[:div_id].to_i if params[:div_id] + @user_activity = ForgeActivity.where(params[:div_id].to_i).first if params[:div_id] + when 'BlogComment' + obj = BlogComment.where('id = ?', params[:id].to_i).first + @user_activity_id = params[:div_id].to_i if params[:div_id] + @type = 'BlogComment' + @journals = BlogComment.where("root_id = #{params[:id].to_i}").reorder("created_on desc") + when 'HomeworkCommon' + obj = HomeworkCommon.where('id = ?', params[:id].to_i).first + @type = 'HomeworkCommon' + @journals = obj.journals_for_messages.reorder("created_on desc") + @is_teacher = User.current.allowed_to?(:as_teacher,obj.course) + @user_activity_id = params[:user_activity_id].to_i if params[:user_activity_id] + when 'Work' + obj = Work.where('id = ?', params[:id].to_i).first + @type = 'Work' + @journals = obj.journals_for_messages.reorder("created_on desc") + @is_teacher = User.current.admin_of_contest?(obj.contest) + @user_activity_id = params[:user_activity_id].to_i if params[:user_activity_id] + end + end + @journals = get_no_children_comments_all @journals + end + + def homepage + @article = @user.base_homepage + respond_to do |format| + format.html {render :layout => 'clear_base'} + end + end + + private + def show_system_message + # 系统消息总显示在最前面,显示周期30天 @system_messages = SystemMessage.where("created_at > ?", Time.now - 86400 * 30) -end - -def find_user - if params[:id] == 'current' - require_login || return - @user = User.current - else - @user = User.find(params[:id]) end -rescue ActiveRecord::RecordNotFound - render_404 -end -def setting_layout(default_base='base_users_new') - User.current.admin? ? default_base : default_base -end - -# 必填自己的工作单位,其实就是学校 -def auth_user_extension - if @user == User.current && @user.user_extensions.nil? - flash[:error] = l(:error_complete_occupation) - redirect_to my_account_url - end -end - -#重置用户得分 -def rest_user_score - memo_num(@user) - messges_for_issue_num(@user) - issues_status_num(@user) - replay_for_memo_num(@user) - tread_num(@user) - praise_num(@user) - changeset_num(@user) - document_num(@user) - attachment_num(@user) - issue_done_ratio_num(@user) - post_issue_num(@user) -end - -#验证是否显示课程 -def can_show_course - @first_page = FirstPage.find_by_page_type('project') - if @first_page.show_course == 2 + def find_user + if params[:id] == 'current' + require_login || return + @user = User.current + else + @user = User.find(params[:id]) + end + rescue ActiveRecord::RecordNotFound render_404 end -end -def recorded_visitor - if(User.current.logged? && User.current != @user) - #impl = Visitor.where('user_id=? and master_id=?',User.current.id,@user.id).find; - # impl = Visitor.find_by_sql('user_id=? and master_id=?',[User.current.id,@user.id]); - impl = Visitor.find_by_user_id_and_master_id(User.current.id,@user.id); - if(impl.nil?) - impl = Visitor.new - impl.user_id = User.current.id - impl.master_id = @user.id - else - impl.updated_on = Time.now - end - impl.save + def setting_layout(default_base='base_users_new') + User.current.admin? ? default_base : default_base + end + + # 必填自己的工作单位,其实就是学校 + def auth_user_extension + if @user == User.current && @user.user_extensions.nil? + flash[:error] = l(:error_complete_occupation) + redirect_to my_account_url + end + end + + #重置用户得分 + def rest_user_score + memo_num(@user) + messges_for_issue_num(@user) + issues_status_num(@user) + replay_for_memo_num(@user) + tread_num(@user) + praise_num(@user) + changeset_num(@user) + document_num(@user) + attachment_num(@user) + issue_done_ratio_num(@user) + post_issue_num(@user) + end + + #验证是否显示课程 + def can_show_course + @first_page = FirstPage.find_by_page_type('project') + if @first_page.show_course == 2 + render_404 + end + end + + def recorded_visitor + if(User.current.logged? && User.current != @user) + #impl = Visitor.where('user_id=? and master_id=?',User.current.id,@user.id).find; + # impl = Visitor.find_by_sql('user_id=? and master_id=?',[User.current.id,@user.id]); + impl = Visitor.find_by_user_id_and_master_id(User.current.id,@user.id); + if(impl.nil?) + impl = Visitor.new + impl.user_id = User.current.id + impl.master_id = @user.id + else + impl.updated_on = Time.now + end + impl.save + end end -end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8ea4c4e7c..21a3dfff8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2906,8 +2906,7 @@ module ApplicationHelper # 用户竞赛总数 def user_contest_count - count = @user.favorite_contests.visible.where("is_delete =?", 0).count - return count + @user.favorite_contests.visible.where("is_delete =?", 0).count end # 用户项目总数 @@ -2946,14 +2945,12 @@ module ApplicationHelper # 用户发布的issue数 def issues_author_is_self_count - @issues = Issue.where( :author_id => @user.id ) - @issues_author_is_self_count = @issues.count + Issue.where(:author_id => @user.id).count end # 用户收到的issue数 def issues_assigned_is_self_count - @issues = Issue.where( :assigned_to_id => @user.id ) - @issues_assigned_is_self_count = @issues.count + Issue.where( :assigned_to_id => @user.id ).count end def get_user_roll user diff --git a/app/views/layouts/_logined_header.html.erb b/app/views/layouts/_logined_header.html.erb index 293bb9131..fe5a0001f 100644 --- a/app/views/layouts/_logined_header.html.erb +++ b/app/views/layouts/_logined_header.html.erb @@ -94,10 +94,10 @@