2015-08-19 12:04:06 +08:00
#encoding: utf-8
2014-09-15 10:58:14 +08:00
# Redmine - project management software
# Copyright (C) 2006-2013 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2015-08-19 12:04:06 +08:00
2014-09-15 10:58:14 +08:00
class UsersController < ApplicationController
2015-01-17 14:19:54 +08:00
2014-09-15 10:58:14 +08:00
layout :setting_layout
#Added by young
2015-02-11 20:23:50 +08:00
before_filter :auth_login1 , :only = > [ :show , :user_activities , :user_newfeedback ]
2015-03-09 17:28:17 +08:00
before_filter :logged_user_by_apptoken , :only = > [ :show , :user_newfeedback ]
2014-09-15 10:58:14 +08:00
menu_item :activity
menu_item :user_information , :only = > :info
menu_item :user_course , :only = > :user_courses
menu_item :user_homework , :only = > :user_homeworks
menu_item :user_project , :only = > [ :user_projects , :watch_projects ]
2015-07-14 15:16:15 +08:00
menu_item :requirement_focus , :only = > :watch_contests
2014-09-15 10:58:14 +08:00
menu_item :user_newfeedback , :only = > :user_newfeedback
2015-08-13 22:33:08 +08:00
menu_item :user_messages , :only = > :user_messages
2015-07-14 15:16:15 +08:00
2015-01-17 11:18:24 +08:00
#
2014-09-15 10:58:14 +08:00
before_filter :can_show_course , :only = > [ :user_courses , :user_homeworks ]
2015-07-14 15:16:15 +08:00
before_filter :find_user , :only = > [ :user_fanslist , :user_watchlist , :show , :edit , :update , :destroy , :edit_membership , :user_courses ,
2015-09-01 16:37:43 +08:00
:user_homeworks , :destroy_membership , :user_activities , :user_projects , :user_newfeedback , :user_comments ,
:watch_contests , :info , :watch_projects , :show_score , :topic_score_index , :project_score_index ,
:activity_score_index , :influence_score_index , :score_index , :show_new_score , :topic_new_score_index , :project_new_score_index ,
:activity_new_score_index , :influence_new_score_index , :score_new_index , :user_projects_index , :user_resource ,
:user_courses4show , :user_projects4show , :user_course_activities , :user_project_activities , :user_feedback4show , :user_visitorlist , :user_messages , :edit_brief_introduction ,
2015-09-17 16:07:41 +08:00
:user_import_homeworks , :user_search_homeworks , :user_import_resource , :user_system_messages ]
2014-09-15 10:58:14 +08:00
before_filter :auth_user_extension , only : :show
2015-01-12 17:34:26 +08:00
#before_filter :rest_user_score, only: :show
2014-10-17 15:02:09 +08:00
#before_filter :select_entry, only: :user_projects
2014-09-15 10:58:14 +08:00
accept_api_auth :index , :show , :create , :update , :destroy , :tag_save , :tag_saveEx
2015-07-14 15:16:15 +08:00
2014-09-15 10:58:14 +08:00
#william
before_filter :require_login , :only = > [ :tag_save , :tag_saveEx ]
#before_filter :refresh_changests, :only =>[:user_activities,:user_courses,:user_projects,:user_newfeedback]
2015-07-14 15:16:15 +08:00
#visitor
before_filter :recorded_visitor , :only = > [ :show , :user_fanslist , :user_watchlist , :user_visitorlist ]
2014-09-15 10:58:14 +08:00
helper :sort
include SortHelper
helper :custom_fields
include CustomFieldsHelper
include AvatarHelper
include WordsHelper
include GitlabHelper
include UserScoreHelper
2015-08-26 17:58:48 +08:00
include PollHelper
2014-09-15 10:58:14 +08:00
helper :user_score
2015-08-25 15:08:35 +08:00
helper :journals
2014-09-15 10:58:14 +08:00
# added by liuping 关注
helper :watchers
helper :activities
### added by william
include ActsAsTaggableOn :: TagsHelper
# fq
helper :words
2015-07-09 15:27:49 +08:00
helper :project_score
2015-07-17 15:07:01 +08:00
helper :issues
2015-07-09 15:27:49 +08:00
include UsersHelper
2014-09-15 10:58:14 +08:00
def refresh_changests
if ! ( @user . nil? ) && ! ( @user . memberships . nil? )
@user . memberships . each do | member |
unless member . project . nil?
member . project . repository . fetch_changesets if Setting . autofetch_changesets?
end
end
end
end
2015-08-13 22:33:08 +08:00
# 用户消息
2015-08-19 11:06:39 +08:00
# 说明: homework 发布作业; message: 讨论区; news: 新闻; poll: 问卷; works_reviewers: 作品评阅; works_reply:作品回复
2015-08-20 17:20:38 +08:00
# issue: 问题; journal: 缺陷状态更新; forum: 公共贴吧: user_feedback: 用户留言; new_reply:新闻回复( comment)
2015-08-13 22:33:08 +08:00
def user_messages
2015-09-19 12:58:45 +08:00
if ! User . current . logged?
2015-09-06 16:50:03 +08:00
redirect_to signin_url
2015-08-15 16:11:40 +08:00
return
2015-09-19 12:58:45 +08:00
elsif @user != User . current && ! User . current . admin?
return render_403
2015-08-15 16:11:40 +08:00
end
2015-09-21 15:08:40 +08:00
# 初始化/更新 点击按钮时间
# 24小时内显示系统消息
update_onclick_time
# 全部设为已读
2015-09-06 16:50:03 +08:00
if params [ :viewed ] == " all "
2015-09-21 15:17:10 +08:00
update_message_viewed ( @user )
2015-09-06 16:50:03 +08:00
end
2015-08-28 15:51:42 +08:00
# @new_message_count = forge_querys.count + forum_querys.count + course_querys.count + user_querys.count
2015-08-18 10:31:40 +08:00
case params [ :type ]
when nil
2015-08-25 11:10:08 +08:00
@message_alls = [ ]
2015-10-09 10:57:53 +08:00
messages = MessageAll . where ( " (user_id =? and message_type !=?) or message_type =? " , @user , " SystemMessage " , " SystemMessage " ) . order ( " created_at desc " )
2015-08-25 11:10:08 +08:00
messages . each do | message_all |
@message_alls << message_all . message
end
2015-09-07 16:08:04 +08:00
when 'unviewed'
@message_alls = [ ]
messages = MessageAll . where ( " user_id =? " , @user ) . order ( " created_at desc " )
messages . each do | message_all |
# 在点击或者刷新消息列表后未读的消息存放在数组
2015-10-12 15:08:01 +08:00
if message_all . message_type != " SystemMessage " && ! message_all . message . nil? && message_all . message . viewed == 0
2015-09-07 16:08:04 +08:00
@message_alls << message_all . message
end
end
2015-10-09 15:50:40 +08:00
#课程相关消息
2015-08-18 10:31:40 +08:00
when 'homework'
2015-09-25 16:30:00 +08:00
@message_alls = CourseMessage . where ( " course_message_type in ('HomeworkCommon','StudentWorksScore','JournalsForMessage') and user_id =? " , @user ) . order ( " created_at desc " )
2015-08-18 16:53:26 +08:00
when 'course_message'
2015-08-25 11:10:08 +08:00
@message_alls = CourseMessage . where ( " course_message_type =? and user_id =? " , " Message " , @user ) . order ( " created_at desc " )
2015-08-18 16:53:26 +08:00
when 'course_news'
2015-09-01 17:37:43 +08:00
# 课程通知包含发布的通知和回复的通知
@message_alls = CourseMessage . where ( " course_message_type =? or course_message_type =? " , " News " , " Comment " ) . where ( " user_id =? " , @user ) . order ( " created_at desc " )
2015-10-09 15:50:40 +08:00
when 'poll'
@message_alls = CourseMessage . where ( " course_message_type =? and user_id =? " , " Poll " , @user ) . order ( " created_at desc " )
#项目相关消息
2015-08-18 10:31:40 +08:00
when 'issue'
2015-09-01 17:37:43 +08:00
@message_alls = ForgeMessage . where ( " forge_message_type =? or forge_message_type =? " , " Issue " , " Journal " ) . where ( " user_id=? " , @user ) . order ( " created_at desc " )
2015-10-09 15:50:40 +08:00
when 'forge_message'
@message_alls = ForgeMessage . where ( " forge_message_type =? and user_id =? " , " Message " , @user ) . order ( " created_at desc " )
when 'forge_news'
@message_alls = ForgeMessage . where ( " forge_message_type in (?,?) and user_id =? " , " News " , " Comment " , @user ) . order ( " created_at desc " )
when 'apply'
@message_alls = ForgeMessage . where ( " forge_message_type in ('ProjectInvite', 'AppliedProject') and user_id =? " , @user ) . order ( " created_at desc " )
#贴吧消息
2015-08-19 11:06:39 +08:00
when 'forum'
2015-08-25 11:10:08 +08:00
@message_alls = MemoMessage . where ( " memo_type =? and user_id =? " , " Memo " , @user ) . order ( " created_at desc " )
2015-10-09 15:50:40 +08:00
#用户留言
2015-08-20 12:44:32 +08:00
when 'user_feedback'
2015-08-25 11:10:08 +08:00
@message_alls = UserFeedbackMessage . where ( " journals_for_message_type =? and user_id =? " , " JournalsForMessage " , @user ) . order ( " created_at desc " )
2015-08-19 15:03:04 +08:00
else
render_404
return
2015-08-18 10:31:40 +08:00
end
2015-08-28 09:55:23 +08:00
@message_alls = paginateHelper @message_alls , 25
2015-08-18 10:31:40 +08:00
respond_to do | format |
2015-08-24 11:37:50 +08:00
format . html { render :layout = > 'new_base_user' }
2015-08-15 02:11:18 +08:00
end
2015-08-13 22:33:08 +08:00
end
2015-09-21 15:08:40 +08:00
# 初始化/更新 点击按钮时间
def update_onclick_time
# 记录当前点击按钮的时间
# 考虑到用户未退出刷新消息页面
message_time = OnclickTime . where ( " user_id =? " , User . current ) . first
if message_time . nil?
message_new_time = OnclickTime . new
message_new_time . user_id = User . current . id
message_new_time . onclick_time = Time . now
message_new_time . save
else
message_time . update_attributes ( :onclick_time = > Time . now )
end
end
2015-09-21 15:17:10 +08:00
# 消息设置为已读
def update_message_viewed ( user )
course_querys = CourseMessage . where ( " user_id =? and viewed =? " , user , 0 )
forge_querys = ForgeMessage . where ( " user_id =? and viewed =? " , user , 0 )
user_querys = UserFeedbackMessage . where ( " user_id =? and viewed =? " , user , 0 )
forum_querys = MemoMessage . where ( " user_id =? and viewed =? " , user , 0 )
if User . current . id == @user . id
course_querys . update_all ( :viewed = > true )
forge_querys . update_all ( :viewed = > true )
user_querys . update_all ( :viewed = > true )
forum_querys . update_all ( :viewed = > true )
end
end
2015-09-17 14:41:03 +08:00
# 系统消息
2015-09-17 16:07:41 +08:00
def user_system_messages
2015-09-17 14:41:03 +08:00
@sytem_messages = SystemMessage . order ( " created_at desc " ) . all
2015-09-19 11:16:59 +08:00
@sytem_messages = paginateHelper @sytem_messages , 10
2015-09-17 14:41:03 +08:00
respond_to do | format |
format . html { render :layout = > 'new_base_user' }
end
end
2014-10-17 15:02:09 +08:00
def user_projects_index
if User . current . admin?
memberships = @user . memberships . all ( conditions : " projects.project_type = #{ Project :: ProjectType_project } " ) . first
else
cond = Project . visible_condition ( User . current ) + " AND projects.project_type <> 1 "
memberships = @user . memberships . all ( :conditions = > cond ) . first
end
watch_projects = Project . joins ( :watchers ) . where ( " project_type <>? and watchable_type = ? and `watchers`.user_id = ? " , '1' , 'Project' , @user . id ) . first
if memberships . nil? && watch_projects
redirect_to ( :watch_projects_user ) and return
else
redirect_to ( :user_projects_user ) and return
end
end
2014-09-15 10:58:14 +08:00
#added by young
def user_projects
unless User . current . admin?
if ! @user . active? #|| (@user != User.current && @memberships.empty? && events.empty?)
render_404
2015-07-09 15:27:49 +08:00
return
2014-09-15 10:58:14 +08:00
end
end
2015-08-13 11:10:09 +08:00
projects = @user . projects . visible . select ( " projects.*,(SELECT MAX(created_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a " ) . order ( " a desc " )
2015-07-09 15:27:49 +08:00
if ( params [ :status ] == '1' )
2015-07-29 15:55:23 +08:00
projects = projects . where ( " projects.user_id = ? " , @user . id )
2015-07-09 15:27:49 +08:00
elsif ( params [ :status ] == '2' )
2015-07-29 15:55:23 +08:00
projects = projects . where ( " projects.user_id <> ? " , @user . id )
2015-07-09 15:27:49 +08:00
end
2015-07-28 15:56:06 +08:00
@list = paginateHelper projects , 10
@params = params [ :status ]
2014-09-15 10:58:14 +08:00
respond_to do | format |
2015-07-09 15:27:49 +08:00
format . html { render :layout = > 'base_users_new' }
2014-09-15 10:58:14 +08:00
format . api
end
end
# added by bai
def show_score
end
def show_new_score
2015-01-09 12:29:49 +08:00
render :layout = > 'users_base'
2014-09-15 10:58:14 +08:00
end
# end
2015-09-01 16:37:43 +08:00
##added by fq
2014-09-15 10:58:14 +08:00
def watch_bids
2015-06-05 11:17:00 +08:00
# cond = 'bids.reward_type <> 1'
# @bids = Bid.watched_by(@user).where('reward_type = ?', 1) # added by huang
# @offset, @limit = api_offset_and_limit({:limit => 10})
# @bid_count = @bids.count
# @bid_pages = Paginator.new @bid_count, @limit, params['page']
# @offset ||= @bid_pages.reverse_offset
# unless @offset == 0
# @bid = @bids.offset(@offset).limit(@limit).all.reverse
# else
# limit = @bid_count % @limit
# @bid = @bids.offset(@offset).limit(limit).all.reverse
# end
#
# respond_to do |format|
# format.html {
# render :layout => 'base_users'
# }
# format.api
# end
2014-09-15 10:58:14 +08:00
end
2015-07-14 15:16:15 +08:00
2014-09-15 10:58:14 +08:00
#new add by linchun
2015-07-14 15:16:15 +08:00
def watch_contests
@bids = Contest . watched_by ( @user )
2014-09-15 10:58:14 +08:00
@offset , @limit = api_offset_and_limit ( { :limit = > 10 } )
@contest_count = @contests . count
@contest_pages = Paginator . new @contest_count , @limit , params [ 'page' ]
2015-07-14 15:16:15 +08:00
@offset || = @contest_pages . reverse_offset
2014-09-15 10:58:14 +08:00
unless @offset == 0
@contest = @contests . offset ( @offset ) . limit ( @limit ) . all . reverse
else
limit = @bid_count % @limit
@contest = @contests . offset ( @offset ) . limit ( limit ) . all . reverse
end
2015-07-14 15:16:15 +08:00
2014-09-15 10:58:14 +08:00
respond_to do | format |
format . html {
render :layout = > 'base_users'
}
format . api
end
end
# added by fq
def user_activities
2014-10-15 09:54:54 +08:00
redirect_to user_url ( @user , type : params [ :type ] , page : params [ :page ] )
2014-09-15 10:58:14 +08:00
return
# useless abort.
@watcher = User . watched_by_id ( @user )
events = [ ]
for user in @watcher
events << Redmine :: Activity :: Fetcher . new ( User . current , :author = > @user ) . events ( nil , nil , :limit = > 30 )
end
2015-01-10 10:37:32 +08:00
2014-09-15 10:58:14 +08:00
@events_by_day = events . group_by ( & :event_date )
unless User . current . admin?
if ! @user . active? || ( @user != User . current && @memberships . empty? && events . empty? )
render_404
2015-09-01 16:37:43 +08:00
return
2014-09-15 10:58:14 +08:00
end
end
respond_to do | format |
format . html
format . api
end
end
# end
2015-07-14 15:16:15 +08:00
2015-08-24 18:15:46 +08:00
#用户作业列表
2015-07-14 15:16:15 +08:00
def user_homeworks
2015-09-06 16:49:29 +08:00
if User . current == @user
@page = params [ :page ] ? params [ :page ] . to_i + 1 : 0
2015-09-08 08:45:29 +08:00
user_course_ids = @user . courses . empty? ? " (-1) " :" ( " + @user . courses . visible . map { | course | course . id } . join ( " , " ) + " ) "
2015-09-06 16:49:29 +08:00
@homework_commons = HomeworkCommon . where ( " course_id in #{ user_course_ids } " ) . order ( " created_at desc " ) . limit ( 10 ) . offset ( @page * 10 )
2015-09-08 16:36:50 +08:00
@is_teacher = User . current . user_extensions && User . current . user_extensions . identity == 0 && User . current . allowed_to? ( :add_course , nil , :global = > true )
2015-09-29 10:20:13 +08:00
@is_in_course = params [ :is_in_course ] . to_i || 0
2015-09-06 16:49:29 +08:00
respond_to do | format |
format . js
format . html { render :layout = > 'new_base_user' }
end
else
render_403
2015-08-27 16:03:41 +08:00
end
2015-08-26 15:04:44 +08:00
end
2015-08-27 16:03:41 +08:00
#导入作业
def user_import_homeworks
2015-09-29 18:02:11 +08:00
@select_course = params [ :select_course ] ? 1 : 0
2015-08-27 16:03:41 +08:00
@user_homeworks = HomeworkCommon . where ( :user_id = > @user . id ) . order ( " created_at desc " )
respond_to do | format |
format . js
end
2015-07-14 15:16:15 +08:00
end
2015-08-28 10:00:48 +08:00
#用户主页过滤作业
def user_search_homeworks
@user_homeworks = HomeworkCommon . where ( " user_id = ' #{ @user . id } ' and lower(name) like '% #{ params [ :name ] . to_s . downcase } %' " ) . order ( " created_at desc " )
respond_to do | format |
format . js
end
end
2015-08-28 11:32:57 +08:00
#导入作业,确定按钮
def user_select_homework
homework = HomeworkCommon . find_by_id params [ :checkMenu ]
2015-09-11 16:22:35 +08:00
homework_detail_programing = homework . homework_detail_programing
2015-08-28 11:32:57 +08:00
@homework = HomeworkCommon . new
2015-09-29 18:02:11 +08:00
@select_course = params [ :select_course ] || 0
2015-08-28 11:32:57 +08:00
if homework
@homework . name = homework . name
@homework . description = homework . description
@homework . end_time = homework . end_time
2015-09-11 16:22:35 +08:00
@homework . homework_type = homework . homework_type
2015-08-28 11:32:57 +08:00
@homework . course_id = homework . course_id
homework . attachments . each do | attachment |
att = attachment . copy
att . container_id = nil
att . container_type = nil
att . copy_from = attachment . id
att . save
@homework . attachments << att
end
2015-09-11 16:22:35 +08:00
if homework_detail_programing
@homework . homework_detail_programing = HomeworkDetailPrograming . new
@homework_detail_programing = @homework . homework_detail_programing
@homework_detail_programing . ta_proportion = homework_detail_programing . ta_proportion
@homework_detail_programing . language = homework_detail_programing . language
homework . homework_tests . each_with_index do | homework_test |
@homework . homework_tests << HomeworkTest . new (
input : homework_test . input ,
output : homework_test . output
)
end
end
2015-08-28 11:32:57 +08:00
end
respond_to do | format |
format . js
end
end
2015-09-01 16:18:03 +08:00
def new_user_commit_homework
2015-09-06 16:49:29 +08:00
if User . current . logged?
@user = User . current
@homework = HomeworkCommon . find ( params [ :homework_id ] )
@is_test = params [ :is_test ] == 'true'
2015-09-10 11:34:10 +08:00
@student_work = StudentWork . where ( homework_common_id : @homework . id , user_id : User . current . id ) . first
2015-09-06 16:49:29 +08:00
if @student_work . nil?
@student_work = StudentWork . new
end
respond_to do | format |
format . js
format . html { render :layout = > 'new_base_user' }
end
else
render_403
2015-09-01 16:18:03 +08:00
end
end
2015-09-10 17:11:16 +08:00
#修改编程作业
def edit_user_commit_homework
if User . current . logged?
respond_to do | format |
format . js
format . html { render :layout = > 'new_base_user' }
2015-09-06 16:49:29 +08:00
end
else
render_403
2015-09-01 16:18:03 +08:00
end
end
def user_commit_homework
2015-09-09 00:43:54 +08:00
homework = HomeworkCommon . find ( params [ :homework ] )
2015-09-10 11:34:10 +08:00
student_work = StudentWork . where ( homework_common_id : homework . id , user_id : User . current . id ) . first
2015-09-09 00:43:54 +08:00
if student_work
2015-09-16 10:26:13 +08:00
#提交作品时,计算是否迟交
if Time . parse ( homework . end_time . to_s ) . strftime ( " %Y-%m-%d " ) < Time . parse ( Time . now . to_s ) . strftime ( " %Y-%m-%d " )
student_work . late_penalty = 1
else
student_work . late_penalty = 0
end
2015-09-09 00:43:54 +08:00
student_work . save
flash [ :notice ] = l ( :notice_successful_create )
redirect_to student_work_index_url ( :homework = > params [ :homework ] )
else
render_403
end
2015-09-01 16:18:03 +08:00
end
2015-08-26 17:29:47 +08:00
def user_new_homework
2015-09-06 16:49:29 +08:00
if User . current . logged?
if params [ :homework_common ]
homework = HomeworkCommon . new
homework . name = params [ :homework_common ] [ :name ]
homework . description = params [ :homework_common ] [ :description ]
homework . end_time = params [ :homework_common ] [ :end_time ] || Time . now
homework . publish_time = Time . now
homework . homework_type = params [ :homework_type ] . to_i || 1
2015-09-17 10:21:01 +08:00
homework . late_penalty = 10
2015-09-17 10:24:37 +08:00
homework . teacher_priority = 1
2015-09-06 16:49:29 +08:00
homework . user_id = User . current . id
homework . course_id = params [ :course_id ]
homework . save_attachments ( params [ :attachments ] )
render_attachment_warning_if_needed ( homework )
2015-09-11 10:19:45 +08:00
homework_detail_manual = HomeworkDetailManual . new
2015-09-18 11:14:59 +08:00
homework_detail_manual . ta_proportion = homework . homework_type == 1 ? 0 . 6 : 0 . 3
2015-09-11 10:19:45 +08:00
homework_detail_manual . comment_status = 1
2015-09-21 17:11:45 +08:00
homework_detail_manual . evaluation_start = params [ :evaluation_start ] . blank? ? homework . end_time + 7 : params [ :evaluation_start ]
homework_detail_manual . evaluation_end = params [ :evaluation_end ] . blank? ? homework_detail_manual . evaluation_start + 7 : params [ :evaluation_end ]
2015-09-11 10:19:45 +08:00
homework_detail_manual . evaluation_num = params [ :evaluation_num ] || 3
2015-09-17 10:21:01 +08:00
homework_detail_manual . absence_penalty = 5
2015-09-11 10:19:45 +08:00
homework . homework_detail_manual = homework_detail_manual
#编程作业相关属性
if homework . homework_type == 2
2015-09-06 16:49:29 +08:00
homework_detail_programing = HomeworkDetailPrograming . new
homework . homework_detail_programing = homework_detail_programing
2015-09-17 10:21:01 +08:00
homework_detail_programing . ta_proportion = 0 . 5
2015-09-07 23:47:14 +08:00
homework_detail_programing . language = params [ :language_type ] . to_i
2015-09-06 16:49:29 +08:00
inputs = params [ :program ] [ :input ]
if Array === inputs
inputs . each_with_index do | val , i |
homework . homework_tests << HomeworkTest . new (
input : val ,
output : params [ :program ] [ :output ] [ i ]
)
end
2015-09-01 16:18:03 +08:00
end
2015-09-06 16:49:29 +08:00
2015-09-01 16:18:03 +08:00
end
2015-08-26 17:29:47 +08:00
2015-09-06 16:49:29 +08:00
if homework . save
homework_detail_manual . save if homework_detail_manual
homework_detail_programing . save if homework_detail_programing
2015-09-28 17:27:01 +08:00
if params [ :is_in_course ] == " 1 "
redirect_to homework_common_index_path ( :course = > homework . course_id )
else
redirect_to user_homeworks_user_path ( User . current . id )
end
2015-09-06 16:49:29 +08:00
end
2015-08-26 17:29:47 +08:00
end
2015-09-06 16:49:29 +08:00
else
render_403
2015-08-26 17:29:47 +08:00
end
end
2015-08-28 16:47:43 +08:00
#用户从资源库导入资源到作业
def user_import_resource
2015-09-01 11:29:43 +08:00
@user = User . current
user_course_ids = @user . courses . map { | c | c . id } #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
2015-08-28 16:47:43 +08:00
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and container_type in('Project','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 ( ',' ) } )) " ) . order ( " created_on desc " )
2015-09-01 11:29:43 +08:00
@type = params [ :type ]
@homework_id = params [ :homework_id ]
@limit = 7
@is_remote = true
@atta_count = @attachments . count
@atta_pages = Paginator . new @atta_count , @limit , params [ 'page' ] || 1
@offset || = @atta_pages . offset
2015-10-12 15:51:47 +08:00
@seleted_resources = session [ :seleted_resource_ids ] . nil? ? [ ] : session [ :seleted_resource_ids ]
2015-09-01 11:29:43 +08:00
#@curse_attachments_all = @all_attachments[@offset, @limit]
@attachments = paginateHelper @attachments , 7
2015-08-28 16:47:43 +08:00
respond_to do | format |
format . js
end
end
2015-09-01 11:29:43 +08:00
#引入资源列表根据类型过滤
def user_resource_type
if User . current . id . to_i != params [ :id ] . to_i
render_403
return
end
2015-09-01 16:37:43 +08:00
if ( params [ :type ] . blank? || params [ :type ] == " 1 " ) #全部
user_course_ids = User . current . courses . map { | c | c . id } #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and container_type in('Project','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 ( ',' ) } )) " ) . order ( " created_on desc " )
2015-09-01 11:29:43 +08:00
elsif params [ :type ] == " 2 " #课程资源
2015-09-01 16:37:43 +08:00
user_course_ids = User . current . courses . map { | c | c . id }
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and container_type = 'Course') or (container_type = 'Course' and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } )) " ) . order ( " created_on desc " )
2015-09-01 11:29:43 +08:00
elsif params [ :type ] == " 3 " #项目资源
2015-09-01 16:37:43 +08:00
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type = 'Project' " ) . order ( " created_on desc " )
2015-09-01 11:29:43 +08:00
elsif params [ :type ] == " 4 " #附件
2015-09-01 16:37:43 +08:00
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon') " ) . order ( " created_on desc " )
2015-09-01 11:29:43 +08:00
elsif params [ :type ] == " 5 " #用户资源
2015-09-01 16:37:43 +08:00
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type = 'Principal' " ) . order ( " created_on desc " )
2015-09-01 11:29:43 +08:00
end
@type = params [ :type ]
@limit = 7
@is_remote = true
@atta_count = @attachments . count
@atta_pages = Paginator . new @atta_count , @limit , params [ 'page' ] || 1
@offset || = @atta_pages . offset
2015-10-12 15:51:47 +08:00
@seleted_resources = session [ :seleted_resource_ids ] . nil? ? [ ] : session [ :seleted_resource_ids ]
2015-09-01 11:29:43 +08:00
#@curse_attachments_all = @all_attachments[@offset, @limit]
@attachments = paginateHelper @attachments , 7
respond_to do | format |
format . js
end
end
#引入资源列表根据关键词过滤
def user_ref_resource_search
search = params [ :search ] . to_s . strip . downcase
2015-09-01 16:37:43 +08:00
if ( params [ :type ] . blank? || params [ :type ] == " 1 " ) #全部
user_course_ids = User . current . courses . map { | c | c . id } #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 取交集并查询
@attachments = Attachment . where ( " ((author_id = #{ params [ :id ] } and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
" or (container_type = 'Course' and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } ))) and (filename like '% #{ search } %') " ) . order ( " created_on desc " )
2015-09-01 11:29:43 +08:00
elsif params [ :type ] == " 2 " #课程资源
2015-09-01 16:37:43 +08:00
user_course_ids = User . current . courses . map { | c | c . id }
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and container_type = 'Course') or (container_type = 'Course' and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } )) and (filename like '% #{ search } %') " ) . order ( " created_on desc " )
2015-09-01 11:29:43 +08:00
elsif params [ :type ] == " 3 " #项目资源
2015-09-01 16:37:43 +08:00
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type = 'Project' and (filename like '% #{ search } %') " ) . order ( " created_on desc " )
2015-09-01 11:29:43 +08:00
elsif params [ :type ] == " 4 " #附件
2015-09-01 16:37:43 +08:00
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like '% #{ search } %') " ) . order ( " created_on desc " )
2015-09-01 11:29:43 +08:00
elsif params [ :type ] == " 5 " #用户资源
2015-09-01 16:37:43 +08:00
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type = 'Principal' and (filename like '% #{ search } %') " ) . order ( " created_on desc " )
2015-09-01 11:29:43 +08:00
end
@type = params [ :type ]
@limit = 7
@is_remote = true
@atta_count = @attachments . count
@atta_pages = Paginator . new @atta_count , @limit , params [ 'page' ] || 1
@offset || = @atta_pages . offset
2015-10-12 15:51:47 +08:00
@seleted_resources = session [ :seleted_resource_ids ] . nil? ? [ ] : session [ :seleted_resource_ids ]
2015-09-01 11:29:43 +08:00
#@curse_attachments_all = @all_attachments[@offset, @limit]
@attachments = paginateHelper @attachments , 7
respond_to do | format |
format . js
end
end
#将资源批量引入
def import_resources_to_homework
@attachments = [ ]
2015-10-12 15:51:47 +08:00
unless session [ :seleted_resource_ids ] . nil? || session [ :seleted_resource_ids ] . blank?
session [ :seleted_resource_ids ] . each do | id |
2015-09-01 16:37:43 +08:00
atta = Attachment . find ( id )
att_copy = atta . copy
att_copy . container_id = nil
att_copy . container_type = nil
2015-09-06 15:41:43 +08:00
att_copy . author_id = User . current . id
2015-09-01 16:37:43 +08:00
att_copy . copy_from = atta . id
att_copy . save
@attachments << att_copy
2015-09-01 11:29:43 +08:00
end
2015-09-01 16:37:43 +08:00
end
2015-10-12 15:51:47 +08:00
session [ :seleted_resource_ids ] = [ ] #保存后清空
2015-08-28 16:47:43 +08:00
respond_to do | format |
format . js
end
end
2015-10-12 15:51:47 +08:00
# ajax 用session保存选择的资源id
def store_selected_resource
session [ :seleted_resource_ids ] = [ ] if session [ :seleted_resource_ids ] . nil?
if params [ :save ] == 'y'
session [ :seleted_resource_ids ] << params [ :res_id ]
else
session [ :seleted_resource_ids ] . delete ( params [ :res_id ] )
end
render :nothing = > true
end
2015-07-14 15:16:15 +08:00
2014-09-15 10:58:14 +08:00
include CoursesHelper
2015-07-09 15:27:49 +08:00
def user_courses
2014-09-15 10:58:14 +08:00
unless User . current . admin?
2015-07-28 15:56:06 +08:00
if ! @user . active?
2014-09-15 10:58:14 +08:00
render_404
2015-07-09 15:27:49 +08:00
return
2014-09-15 10:58:14 +08:00
end
end
2015-08-13 11:10:09 +08:00
courses = @user . courses . visible . select ( " courses.*,(SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a " ) . order ( " a desc " )
2015-07-09 15:27:49 +08:00
if ( params [ :status ] == '1' )
2015-07-28 15:56:06 +08:00
courses = courses . where ( " endup_time >= ? or endup_time is null or endup_time='' " , Time . now )
2015-07-09 15:27:49 +08:00
elsif ( params [ :status ] == '2' )
2015-07-28 15:56:06 +08:00
courses = courses . where ( " endup_time < ? " , Time . now )
2015-07-09 15:27:49 +08:00
end
2015-07-28 15:56:06 +08:00
@list = paginateHelper courses , 10
@params = params [ :status ]
2015-07-09 15:27:49 +08:00
render :layout = > 'base_users_new'
2014-09-15 10:58:14 +08:00
end
# modified by fq
def user_newfeedback
2015-09-06 16:50:03 +08:00
unless User . current . logged?
redirect_to signin_url
return
end
2015-09-18 14:04:02 +08:00
# 自己访问自己的页面才更新消息状态
if User . current == @user
journals_messages = UserFeedbackMessage . where ( " user_id =? and journals_for_message_type =? and viewed =? " , User . current . id , " JournalsForMessage " , 0 )
journals_messages . each do | journals_message |
journals_message . update_attributes ( :viewed = > true )
2015-09-02 11:50:58 +08:00
end
end
# end
2015-07-29 15:55:23 +08:00
jours = @user . journals_for_messages . where ( 'm_parent_id IS NULL' ) . order ( 'created_on DESC' )
2015-08-10 16:12:13 +08:00
if User . current == @user
jours . update_all ( :is_readed = > true , :status = > false )
jours . each do | journal |
fetch_user_leaveWord_reply ( journal ) . update_all ( :is_readed = > true , :status = > false )
end
2014-09-15 10:58:14 +08:00
end
2015-07-29 15:55:23 +08:00
@jour = paginateHelper jours , 10
2014-09-15 10:58:14 +08:00
@state = false
2015-08-26 15:49:05 +08:00
render :layout = > 'new_base_user'
2014-09-15 10:58:14 +08:00
end
def user_comments
end
#end
def index
2015-07-14 15:16:15 +08:00
2014-09-15 10:58:14 +08:00
@status = params [ :status ] || 1
sort_init 'login' , 'asc'
sort_update %w( login firstname lastname mail admin created_on last_login_on )
case params [ :format ]
2015-09-01 16:37:43 +08:00
when 'xml' , 'json'
@offset , @limit = api_offset_and_limit ( { :limit = > 15 } )
else
@limit = 15
2014-09-15 10:58:14 +08:00
end
# retrieve all users
# 先内连一下statuses 保证排序之后数量一致
scope = User . visible .
2015-09-01 16:37:43 +08:00
joins ( " INNER JOIN user_statuses ON users.id = user_statuses.user_id " )
2015-07-14 15:16:15 +08:00
2014-09-15 10:58:14 +08:00
# unknow
scope = scope . in_group ( params [ :group_id ] ) if params [ :group_id ] . present?
# pagination
@user_count = scope . count
@user_pages = Paginator . new @user_count , @limit , params [ 'page' ]
# users classify
case params [ :user_sort_type ]
2015-09-01 16:37:43 +08:00
when '0'
# 创建时间排序
@s_type = 0
@users = scope . reorder ( 'users.created_on DESC' )
when '1'
# 活跃度排序, 就是所谓的得分情况
@s_type = 1
@users = scope .
joins ( " LEFT JOIN option_numbers ON users.id = option_numbers.user_id and option_numbers.score_type = 1 " ) .
reorder ( 'option_numbers.total_score DESC' )
when '2'
# 粉丝数排序
@s_type = 2
@users = scope .
#joins("INNER JOIN user_statuses ON users.id = user_statuses.user_id").
reorder ( 'user_statuses.watchers_count DESC' )
2014-09-15 10:58:14 +08:00
2015-09-01 16:37:43 +08:00
else
# 默认活跃度排序
@s_type = 1
@users = scope .
joins ( " LEFT JOIN option_numbers ON users.id = option_numbers.user_id and option_numbers.score_type = 1 " ) .
reorder ( 'option_numbers.total_score DESC' )
2014-09-15 10:58:14 +08:00
end
# limit and offset
@users = @users . limit ( @user_pages . per_page ) . offset ( @user_pages . offset )
2015-07-14 15:16:15 +08:00
2014-09-15 10:58:14 +08:00
@user_base_tag = params [ :id ] ? 'base_users' :'users_base'
respond_to do | format |
format . html {
@groups = Group . all . sort
2015-01-27 15:11:24 +08:00
User . current . admin? ? ( render :layout = > @user_base_tag ) : ( render_404 )
2014-09-15 10:58:14 +08:00
}
format . api
end
end
2015-07-14 15:16:15 +08:00
2014-09-15 10:58:14 +08:00
def search
sort_init 'login' , 'asc'
sort_update %w( login firstname lastname mail admin created_on last_login_on )
2014-10-15 09:54:54 +08:00
( redirect_to user_url , :notice = > l ( :label_sumbit_empty ) ; return ) if params [ :name ] . blank?
2015-09-01 16:37:43 +08:00
case params [ :format ]
2014-12-10 20:27:41 +08:00
when 'xml' , 'json'
@offset , @limit = api_offset_and_limit ( { :limit = > 15 } )
else
@limit = 15 #per_page_option
2015-09-01 16:37:43 +08:00
end
#
#@status = params[:status] || 1
#has = {
# "show_changesets" => true
#}
# scope = User.logged.status(@status)
# @search_by = params[:search_by] ? params[:search_by][:id] : 0
# scope = scope.like(params[:name],@search_by) if params[:name].present?
2015-05-18 16:41:04 +08:00
@search_by = params [ :search_by ] ? params [ :search_by ] : 0
2014-12-10 20:27:41 +08:00
us = UsersService . new
scope = us . search_user params
@user_count = scope . count
@user_pages = Paginator . new @user_count , @limit , params [ 'page' ]
@user_base_tag = params [ :id ] ? 'base_users' :'users_base'
@offset || = @user_pages . reverse_offset
unless @offset == 0
@users = scope . offset ( @offset ) . limit ( @limit ) . all . reverse
2014-09-15 10:58:14 +08:00
else
2014-12-10 20:27:41 +08:00
limit = @user_count % @limit
if limit == 0
limit = @limit
end
@users = scope . offset ( @offset ) . limit ( limit ) . all . reverse
2014-09-15 10:58:14 +08:00
end
2015-08-25 18:59:45 +08:00
@name = params [ :name ]
@type = 'users'
2014-09-15 10:58:14 +08:00
respond_to do | format |
format . html {
@groups = Group . all . sort
render :layout = > @user_base_tag
}
format . api
end
end
2015-07-09 15:27:49 +08:00
2015-08-24 14:44:22 +08:00
#显示更多用户课程
2015-07-09 15:27:49 +08:00
def user_courses4show
2015-08-24 14:44:22 +08:00
@page = params [ :page ] . to_i + 1
@courses = @user . courses . visible . select ( " courses.*,(SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a " ) . order ( " a desc " ) . limit ( 5 ) . offset ( @page * 5 )
2015-09-01 16:37:43 +08:00
end
2015-07-09 15:27:49 +08:00
2015-08-24 14:44:22 +08:00
#显示更多用户项目
def user_projects4show
2015-08-24 14:53:35 +08:00
@page = params [ :page ] . to_i + 1
@projects = @user . projects . visible . select ( " projects.*,(SELECT MAX(created_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a " ) . order ( " a desc " ) . limit ( 5 ) . offset ( @page * 5 )
2015-09-01 16:37:43 +08:00
end
2015-07-09 15:27:49 +08:00
def user_course_activities
lastid = nil
if params [ :lastid ] != nil && ! params [ :lastid ] . empty?
lastid = params [ :lastid ] ;
end
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
2015-07-17 15:07:01 +08:00
query = Activity . joins ( " join courses c on c.id= #{ Activity . table_name } .activity_container_id and #{ Activity . table_name } .activity_container_type='Course' " )
query = query . where ( " #{ Activity . table_name } .user_id in (?) " , user_ids )
if User . current != @user #看别人
if @user . user_extensions! = nil && @user . user_extensions . identity == 0 #看老师
query = query . joins ( " join members m on c.id=m.course_id and m.user_id = #{ @user . id } " )
query = query . joins ( " join member_roles r on m.id = r.member_id " )
query = query . where ( " r.role_id in(3,7,9) " )
end
query = query . where ( " c.is_public=1 " )
end
2015-07-16 10:26:09 +08:00
if ( lastid != nil )
2015-07-17 15:07:01 +08:00
query = query . where ( " #{ Activity . table_name } .id < ? " , lastid )
2015-07-09 15:27:49 +08:00
end
2015-07-17 15:07:01 +08:00
query = query . order ( " #{ Activity . table_name } .id desc " )
@list = query_activities ( query )
2015-07-16 10:26:09 +08:00
2015-07-09 15:27:49 +08:00
render :layout = > nil
end
def user_project_activities
lastid = nil
if params [ :lastid ] != nil && ! params [ :lastid ] . empty?
lastid = params [ :lastid ] ;
end
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
2015-07-17 15:07:01 +08:00
query = Activity . joins ( " join projects c on c.id= #{ Activity . table_name } .activity_container_id and #{ Activity . table_name } .activity_container_type='Project' " )
query = query . where ( user_id : user_ids )
if User . current != @user #看别人
query = query . where ( " c.is_public=1 " )
end
2015-07-16 10:26:09 +08:00
if ( lastid != nil )
2015-07-17 15:07:01 +08:00
query = query . where ( " #{ Activity . table_name } .id < ? " , lastid )
2015-07-09 15:27:49 +08:00
end
2015-07-17 15:07:01 +08:00
query = query . order ( " #{ Activity . table_name } .id desc " )
2015-07-28 16:04:40 +08:00
@list = query_activities ( query )
2015-07-16 10:26:09 +08:00
2015-07-09 15:27:49 +08:00
render :action = > 'user_course_activities' , :layout = > nil
end
def user_feedback4show
query = @user . journals_for_messages
if params [ :lastid ] != nil && ! params [ :lastid ] . empty?
query = query . where ( " #{ JournalsForMessage . table_name } .id < ? " , params [ :lastid ] )
end
2015-07-10 14:17:19 +08:00
logger . info ( 'xxoo' )
2015-07-09 15:27:49 +08:00
@list = query . order ( " #{ JournalsForMessage . table_name } .id desc " ) . limit ( 3 ) . all
2015-07-10 14:17:19 +08:00
logger . info ( 'aavv' )
render :layout = > nil , :locals = > { :feed_list = > @list }
2015-07-09 15:27:49 +08:00
end
2014-09-15 10:58:14 +08:00
def show
2015-08-25 20:08:52 +08:00
@page = params [ :page ] ? params [ :page ] . to_i + 1 : 0
user_project_ids = @user . projects . visible . empty? ? " (-1) " : " ( " + @user . projects . visible . map { | project | project . id } . join ( " , " ) + " ) "
user_course_ids = @user . courses . visible . empty? ? " (-1) " : " ( " + @user . courses . visible . map { | course | course . id } . join ( " , " ) + " ) "
2015-09-06 15:31:26 +08:00
course_types = " ('Message','News','HomeworkCommon','Poll') "
2015-08-26 15:24:57 +08:00
project_types = " ('Message','Issue') "
2015-10-14 11:38:16 +08:00
principal_types = " JournalsForMessage "
2015-08-29 16:39:37 +08:00
if params [ :type ] . present?
case params [ :type ]
2015-08-25 19:24:23 +08:00
when " course_homework "
2015-09-17 15:50:33 +08:00
@user_activities = UserActivity . where ( " container_type = 'Course' and container_id in #{ user_course_ids } and act_type = 'HomeworkCommon' " ) . order ( 'updated_at desc' ) . limit ( 10 ) . offset ( @page * 10 )
2015-08-25 19:24:23 +08:00
when " course_news "
2015-09-17 15:50:33 +08:00
@user_activities = UserActivity . where ( " container_type = 'Course' and container_id in #{ user_course_ids } and act_type = 'News' " ) . order ( 'updated_at desc' ) . limit ( 10 ) . offset ( @page * 10 )
2015-08-25 19:24:23 +08:00
when " course_message "
2015-09-17 15:50:33 +08:00
@user_activities = UserActivity . where ( " container_type = 'Course' and container_id in #{ user_course_ids } and act_type = 'Message' " ) . order ( 'updated_at desc' ) . limit ( 10 ) . offset ( @page * 10 )
2015-08-26 15:24:57 +08:00
when " course_poll "
2015-09-17 15:50:33 +08:00
@user_activities = UserActivity . where ( " container_type = 'Course' and container_id in #{ user_course_ids } and act_type = 'Poll' " ) . order ( 'updated_at desc' ) . limit ( 10 ) . offset ( @page * 10 )
2015-08-25 19:24:23 +08:00
when " project_issue "
2015-09-17 15:50:33 +08:00
@user_activities = UserActivity . where ( " container_type = 'Project' and container_id in #{ user_project_ids } and act_type = 'Issue' " ) . order ( 'updated_at desc' ) . limit ( 10 ) . offset ( @page * 10 )
2015-08-25 19:24:23 +08:00
when " project_message "
2015-09-17 15:50:33 +08:00
@user_activities = UserActivity . where ( " container_type = 'Project' and container_id in #{ user_project_ids } and act_type = 'Message' " ) . order ( 'updated_at desc' ) . limit ( 10 ) . offset ( @page * 10 )
2015-10-14 11:38:16 +08:00
when " user_journals "
@user_activities = UserActivity . where ( " container_type = 'Principal' and act_type= 'JournalsForMessage' and container_id = #{ @user . id } " ) . order ( 'updated_at desc' ) . limit ( 10 ) . offset ( @page * 10 )
2015-09-07 15:01:08 +08:00
when " current_user "
2015-09-17 15:50:33 +08:00
@user_activities = UserActivity . where ( " user_id = #{ @user . id } and ((container_type = 'Project' and container_id in #{ user_project_ids } and act_type in #{ project_types } ) or (container_type = 'Course' and container_id in #{ user_course_ids } and act_type in #{ course_types } )) " ) . order ( 'updated_at desc' ) . limit ( 10 ) . offset ( @page * 10 )
2015-08-26 15:24:57 +08:00
else
2015-10-14 11:38:16 +08:00
@user_activities = UserActivity . where ( " (container_type = 'Project' and container_id in #{ user_project_ids } and act_type in #{ project_types } ) or (container_type = 'Course' and container_id in #{ user_course_ids } and act_type in #{ course_types } ) or (container_type = 'Principal' and act_type= ' #{ principal_types } ' and container_id = #{ @user . id } ) " ) . order ( 'updated_at desc' ) . limit ( 10 ) . offset ( @page * 10 )
2015-09-01 16:37:43 +08:00
end
2015-08-25 19:24:23 +08:00
else
2015-10-14 11:38:16 +08:00
@user_activities = UserActivity . where ( " (container_type = 'Project' and container_id in #{ user_project_ids } and act_type in #{ project_types } ) or (container_type = 'Course' and container_id in #{ user_course_ids } and act_type in #{ course_types } )or (container_type = 'Principal' and act_type= ' #{ principal_types } ' and container_id = #{ @user . id } ) " ) . order ( 'updated_at desc' ) . limit ( 10 ) . offset ( @page * 10 )
2015-08-25 19:24:23 +08:00
end
2015-08-25 16:01:31 +08:00
# @user_activities = paginateHelper @user_activities,500
2015-08-29 16:39:37 +08:00
@type = params [ :type ]
2015-08-25 20:08:52 +08:00
respond_to do | format |
format . js
format . html { render :layout = > 'new_base_user' }
end
2015-07-09 15:27:49 +08:00
end
def show_old
2014-09-15 10:58:14 +08:00
pre_count = 10 #limit
2015-03-04 15:32:00 +08:00
# Time 2015-02-04 11:46:34
# Author lizanle
# Description type 1 :所有动态包括我关注的人 type 2:我的动态 type 3:关于我的回复
2014-09-15 10:58:14 +08:00
case params [ :type ]
2015-09-01 16:37:43 +08:00
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
2015-04-10 16:27:26 +08:00
end
2015-09-01 16:37:43 +08:00
when " 2 "
message = [ ]
if @user == User . current
message = JournalsForMessage . reference_message ( @user . id )
message += Journal . reference_message ( @user . id )
2015-07-14 15:16:15 +08:00
end
2015-09-01 16:37:43 +08:00
@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
2015-07-14 15:16:15 +08:00
end
2015-09-01 16:37:43 +08:00
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 }
2015-04-10 16:27:26 +08:00
2015-09-01 16:37:43 +08:00
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 }
2015-07-14 15:16:15 +08:00
2015-09-01 16:37:43 +08:00
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 }
2015-04-10 16:27:26 +08:00
2015-09-01 16:37:43 +08:00
logger . debug " filter ids #{ ids } "
2015-04-10 16:27:26 +08:00
2015-09-01 16:37:43 +08:00
activity = activity . where ( 'act_id not in (?)' , ids . flatten ) . order ( 'id desc' ) unless ids . flatten . empty?
end
2015-04-10 10:37:39 +08:00
2015-09-01 16:37:43 +08:00
# 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))))))
# }
#
2015-07-14 15:16:15 +08:00
2015-09-01 16:37:43 +08:00
@activity_count = activity . count
@activity_pages = Paginator . new @activity_count , pre_count , params [ 'page' ]
@activity = activity . slice ( @activity_pages . offset , @activity_pages . per_page )
@state = 0
2014-09-15 10:58:14 +08:00
end
2015-07-14 15:16:15 +08:00
2014-09-15 10:58:14 +08:00
if params [ :user ] . present?
2015-07-14 15:16:15 +08:00
2014-09-15 10:58:14 +08:00
user_temp = User . find_by_sql ( " select id from users where concat(lastname,firstname) like '% #{ params [ :user ] } %' or lastname like '% #{ params [ :user ] } %' " )
2015-07-14 15:16:15 +08:00
2014-09-15 10:58:14 +08:00
if user_temp . size > 1
2015-07-14 15:16:15 +08:00
activity = Activity . where ( 'user_id in (?)' , user_temp ) . where ( 'user_id in (?)' , watcher ) . order ( 'id desc' )
2014-09-15 10:58:14 +08:00
elsif user_temp . size == 1
2015-07-14 15:16:15 +08:00
activity = Activity . where ( 'user_id = ?' , user_temp ) . where ( 'user_id in (?)' , watcher ) . order ( 'id desc' )
2014-09-15 10:58:14 +08:00
else
activity = Activity . where ( " 1 = 0 " )
end
@offset , @limit = api_offset_and_limit ( { :limit = > 10 } )
2015-07-14 15:16:15 +08:00
@activity_count = activity . count
2014-09-15 10:58:14 +08:00
@activity_pages = Paginator . new @activity_count , @limit , params [ 'page' ]
@offset || = @activity_pages . offset
2015-07-14 15:16:15 +08:00
@activity = activity . offset ( @offset ) . limit ( @limit )
2014-09-15 10:58:14 +08:00
@state = 0
end
2015-07-14 15:16:15 +08:00
2014-09-15 10:58:14 +08:00
#Modified by nie
unless User . current . admin?
if ! @user . active? #|| (@user != User.current && @memberships.empty? && events.empty?)
# redirect_to home_path
render_404
2015-09-01 16:37:43 +08:00
return
2014-09-15 10:58:14 +08:00
end
end
respond_to do | format |
format . html
format . api
end
end
##end fq
#### added by fq
def info
message = [ ]
2015-07-14 15:16:15 +08:00
if @user == User . current
2014-09-15 10:58:14 +08:00
message = JournalsForMessage . reference_message ( @user . id )
2015-07-14 15:16:15 +08:00
message += Journal . reference_message ( @user . id )
2014-09-15 10:58:14 +08:00
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
2015-07-14 15:16:15 +08:00
2014-09-15 10:58:14 +08:00
messages = message . sort { | x , y | y . created_on < = > x . created_on }
2015-07-14 15:16:15 +08:00
2014-09-15 10:58:14 +08:00
@message = messages [ @offset , @limit ]
unless User . current . admin?
if ! @user . active?
render_404
2015-09-01 16:37:43 +08:00
return
2014-09-15 10:58:14 +08:00
end
end
respond_to do | format |
format . html
format . api
end
end
#### end
2015-07-14 15:16:15 +08:00
2014-09-15 10:58:14 +08:00
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 ] : [ ] )
2015-03-31 11:42:36 +08:00
Mailer . run . account_information ( @user , params [ :user ] [ :password ] ) if params [ :send_information ]
2014-09-15 10:58:14 +08:00
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 ]
2014-10-15 09:54:54 +08:00
redirect_to new_user_url
2014-09-15 10:58:14 +08:00
else
2014-10-15 09:54:54 +08:00
redirect_to edit_user_url ( @user )
2014-09-15 10:58:14 +08:00
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 ,
2015-09-01 16:37:43 +08:00
:gender = > 0 ,
2014-09-15 10:58:14 +08:00
:user_id = > @user . id )
ue . save
end
end
def edit
@auth_sources = AuthSource . all
@membership || = Member . new
end
2015-07-14 15:16:15 +08:00
2014-09-15 10:58:14 +08:00
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
2015-03-31 11:42:36 +08:00
Mailer . run . account_activated ( @user )
2014-09-15 10:58:14 +08:00
elsif @user . active? && params [ :send_information ] && ! params [ :user ] [ :password ] . blank? && @user . auth_source_id . nil?
2015-03-31 11:42:36 +08:00
Mailer . run . account_information ( @user , params [ :user ] [ :password ] )
2014-09-15 10:58:14 +08:00
end
respond_to do | format |
format . html {
flash [ :notice ] = l ( :notice_successful_update )
2014-10-15 09:54:54 +08:00
redirect_to_referer_or edit_user_url ( @user )
2014-09-15 10:58:14 +08:00
}
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
2015-08-15 17:06:41 +08:00
# 上传用户资源
def user_resource_create
@user = User . find ( params [ :id ] )
#@user.save_attachments(params[:attachments],User.current)
# Container_type为Principal
2015-09-01 16:37:43 +08:00
Attachment . attach_filesex ( @user , params [ :attachments ] , params [ :attachment_type ] )
if ( params [ :type ] . blank? || params [ :type ] == " 1 " ) #全部
2015-08-21 14:00:24 +08:00
if User . current . id . to_i == params [ :id ] . to_i
user_course_ids = User . current . courses . map { | c | c . id } #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
2015-08-21 17:13:42 +08:00
" or (container_type = 'Course' and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } )) " ) . order ( " created_on desc " )
2015-08-21 14:00:24 +08:00
else
user_course_ids = User . find ( params [ :id ] ) . courses . visible . map { | c | c . id } #Ta的资源库的话, 应该是他上传的公开资源 加上 他加入的所有我可见课程里的公开资源
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and is_public = 1 " +
" and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
2015-08-21 17:13:42 +08:00
" or (container_type = 'Course' and is_public = 1 and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } )) " ) . order ( " created_on desc " )
2015-08-21 14:00:24 +08:00
end
elsif params [ :type ] == " 2 " #课程资源
if User . current . id . to_i == params [ :id ] . to_i
2015-08-21 17:13:42 +08:00
user_course_ids = User . current . courses . map { | c | c . id }
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and container_type = 'Course') or (container_type = 'Course' and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } )) " ) . order ( " created_on desc " )
2015-08-21 14:00:24 +08:00
else
user_course_ids = User . find ( params [ :id ] ) . courses . visible . map { | c | c . id } #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and is_public = 1 and container_type = 'Course') " +
2015-08-21 17:13:42 +08:00
" or (container_type = 'Course' and is_public = 1 and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } )) " ) . order ( " created_on desc " )
2015-08-21 14:00:24 +08:00
end
elsif params [ :type ] == " 3 " #项目资源
if User . current . id . to_i == params [ :id ] . to_i
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type = 'Project' " ) . order ( " created_on desc " )
else
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and is_public = 1 and container_type = 'Project' " ) . order ( " created_on desc " )
end
elsif params [ :type ] == " 4 " #附件
if User . current . id . to_i == params [ :id ] . to_i
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon') " ) . order ( " created_on desc " )
else
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and is_public = 1 and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon') " ) . order ( " created_on desc " )
end
2015-08-29 12:32:00 +08:00
elsif params [ :type ] == " 5 " #附件
if User . current . id . to_i == params [ :id ] . to_i
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type ='Principal' " ) . order ( " created_on desc " )
else
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and is_public = 1 and container_type ='Principal' " ) . order ( " created_on desc " )
end
2015-08-21 14:00:24 +08:00
end
@type = params [ :type ] || 1
2015-08-28 10:47:50 +08:00
@limit = 25
2015-08-21 14:00:24 +08:00
@is_remote = true
2015-08-24 10:31:25 +08:00
@atta_count = @attachments . count
@atta_pages = Paginator . new @atta_count , @limit , params [ 'page' ] || 1
@offset || = @atta_pages . offset
2015-08-21 14:00:24 +08:00
#@curse_attachments_all = @all_attachments[@offset, @limit]
2015-08-28 10:47:50 +08:00
@attachments = paginateHelper @attachments , 25
2015-08-15 17:06:41 +08:00
respond_to do | format |
format . js
end
end
2015-08-21 10:14:04 +08:00
# 删除用户资源,分为批量删除 和 单个删除,只能删除自己上传的资源
2015-08-15 17:06:41 +08:00
def user_resource_delete
2015-08-20 14:01:33 +08:00
if params [ :resource_id ] . present?
2015-09-01 16:37:43 +08:00
Attachment . where ( " author_id = #{ User . current . id } " ) . delete ( params [ :resource_id ] )
2015-08-20 14:01:33 +08:00
elsif params [ :checkbox1 ] . present?
2015-09-01 16:37:43 +08:00
params [ :checkbox1 ] . each do | id |
Attachment . where ( " author_id = #{ User . current . id } " ) . delete ( id )
2015-08-20 14:01:33 +08:00
end
end
2015-09-01 16:37:43 +08:00
if ( params [ :type ] . blank? || params [ :type ] == " 1 " ) #全部
2015-08-21 10:14:04 +08:00
if User . current . id . to_i == params [ :id ] . to_i
user_course_ids = User . current . courses . map { | c | c . id } #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
2015-08-21 17:13:42 +08:00
" or (container_type = 'Course' and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } )) " ) . order ( " created_on desc " )
2015-08-21 10:14:04 +08:00
else
user_course_ids = User . find ( params [ :id ] ) . courses . visible . map { | c | c . id } #Ta的资源库的话, 应该是他上传的公开资源 加上 他加入的所有我可见课程里的公开资源
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and is_public = 1 " +
" and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
2015-08-21 17:13:42 +08:00
" or (container_type = 'Course' and is_public = 1 and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } )) " ) . order ( " created_on desc " )
2015-08-21 10:14:04 +08:00
end
elsif params [ :type ] == " 2 " #课程资源
if User . current . id . to_i == params [ :id ] . to_i
2015-08-21 16:36:42 +08:00
user_course_ids = User . current . courses . map { | c | c . id }
2015-08-21 17:13:42 +08:00
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and container_type = 'Course') or (container_type = 'Course' and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } )) " ) . order ( " created_on desc " )
2015-08-21 10:14:04 +08:00
else
user_course_ids = User . find ( params [ :id ] ) . courses . visible . map { | c | c . id } #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and is_public = 1 and container_type = 'Course') " +
2015-08-21 17:13:42 +08:00
" or (container_type = 'Course' and is_public = 1 and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } )) " ) . order ( " created_on desc " )
2015-08-21 10:14:04 +08:00
end
elsif params [ :type ] == " 3 " #项目资源
if User . current . id . to_i == params [ :id ] . to_i
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type = 'Project' " ) . order ( " created_on desc " )
else
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and is_public = 1 and container_type = 'Project' " ) . order ( " created_on desc " )
end
elsif params [ :type ] == " 4 " #附件
if User . current . id . to_i == params [ :id ] . to_i
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon') " ) . order ( " created_on desc " )
else
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and is_public = 1 and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon') " ) . order ( " created_on desc " )
end
2015-08-29 12:32:00 +08:00
elsif params [ :type ] == " 5 " #用户资源
if User . current . id . to_i == params [ :id ] . to_i
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type ='Principal' " ) . order ( " created_on desc " )
else
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and is_public = 1 and container_type ='Principal' " ) . order ( " created_on desc " )
end
2015-08-21 10:14:04 +08:00
end
@type = params [ :type ]
2015-08-28 10:47:50 +08:00
@limit = 25
2015-08-21 10:14:04 +08:00
@is_remote = true
2015-08-24 10:31:25 +08:00
@atta_count = @attachments . count
@atta_pages = Paginator . new @atta_count , @limit , params [ 'page' ] || 1
@offset || = @atta_pages . offset
2015-08-21 10:14:04 +08:00
#@curse_attachments_all = @all_attachments[@offset, @limit]
2015-08-28 10:47:50 +08:00
@attachments = paginateHelper @attachments , 25
2015-09-01 16:37:43 +08:00
respond_to do | format |
format . js
end
2015-08-15 17:06:41 +08:00
end
2015-08-18 09:31:03 +08:00
#根据id或者名称搜索教师或者助教为当前用户的课程
def search_user_course
@user = User . current
if ! params [ :search ] . nil?
2015-09-01 16:37:43 +08:00
@course = @user . courses . where ( " #{ Course . table_name } .id = #{ params [ :search ] . to_i } or #{ Course . table_name } .name like '% #{ params [ :search . to_s ] } %' " )
. select { | course | @user . allowed_to? ( :as_teacher , course ) }
2015-08-18 09:31:03 +08:00
else
@course = @user . courses
. select { | course | @user . allowed_to? ( :as_teacher , course ) }
end
2015-08-20 16:05:58 +08:00
#这里仅仅是传递需要发送的资源id
2015-08-18 09:31:03 +08:00
@send_id = params [ :send_id ]
2015-08-20 16:05:58 +08:00
@send_ids = params [ :checkbox1 ] || params [ :send_ids ]
2015-08-18 09:31:03 +08:00
respond_to do | format |
format . js
end
end
2015-08-20 10:14:26 +08:00
# 根据id或者名称搜索当前用户所在的项目
def search_user_project
@user = User . current
if ! params [ :search ] . nil?
@projects = @user . projects . where ( " #{ Project . table_name } .id = #{ params [ :search ] . to_i } or #{ Project . table_name } .name like '% #{ params [ :search . to_s ] } %' " )
else
@projects = @user . projects
end
2015-08-20 16:05:58 +08:00
#这里仅仅是传递需要发送的资源id
2015-08-20 10:14:26 +08:00
@send_id = params [ :send_id ]
2015-08-20 16:05:58 +08:00
@send_ids = params [ :checkbox1 ] || params [ :send_ids ] #搜索的时候 和 直接 用表格提交的时候的send_ids
2015-08-20 10:14:26 +08:00
respond_to do | format |
format . js
end
end
2015-08-20 16:05:58 +08:00
# 将资源发送到对应的课程,分为发送单个,或者批量发送
2015-08-18 09:31:03 +08:00
def add_exist_file_to_course
2015-08-27 11:02:20 +08:00
@flag = true
2015-09-01 16:37:43 +08:00
if params [ :send_id ] . present?
2015-08-20 16:05:58 +08:00
send_id = params [ :send_id ]
ori = Attachment . find_by_id ( send_id )
course_ids = params [ :course_ids ]
2015-08-27 11:02:20 +08:00
if course_ids . nil?
@flag = false
end
2015-09-01 16:37:43 +08:00
unless course_ids . nil?
course_ids . each do | id |
next if ori . blank?
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
if attach_copied_obj . attachtype == nil
attach_copied_obj . attachtype = 4
end
attach_copied_obj . save
@save_message = attach_copied_obj . errors . full_messages
2015-08-20 16:05:58 +08:00
end
2015-09-01 16:37:43 +08:00
end
2015-08-20 16:05:58 +08:00
elsif params [ :send_ids ] . present?
send_ids = params [ :send_ids ] . split ( " " )
2015-08-27 11:02:20 +08:00
course_ids = params [ :course_ids ]
if course_ids . nil?
@flag = false
end
2015-08-20 16:05:58 +08:00
send_ids . each do | send_id |
2015-08-18 09:31:03 +08:00
ori = Attachment . find_by_id ( send_id )
2015-08-27 11:02:20 +08:00
2015-08-20 16:05:58 +08:00
unless course_ids . nil?
course_ids . each do | id |
next if ori . blank?
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
if attach_copied_obj . attachtype == nil
attach_copied_obj . attachtype = 4
end
attach_copied_obj . save
@save_message = attach_copied_obj . errors . full_messages
end
2015-08-18 09:31:03 +08:00
end
2015-08-20 16:05:58 +08:00
end
2015-08-27 11:02:20 +08:00
else
2015-09-01 16:37:43 +08:00
@flag = false
2015-08-18 09:31:03 +08:00
end
2015-09-01 16:37:43 +08:00
user_course_ids = User . current . courses . map { | c | c . id } #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and container_type in('Project','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 ( ',' ) } )) " ) . order ( " created_on desc " )
@type = params [ :type ]
@limit = 25
@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
2015-08-18 09:31:03 +08:00
respond_to do | format |
format . js
end
end
2015-08-20 10:14:26 +08:00
# 添加资源到对应的项目
def add_exist_file_to_project
2015-08-27 11:02:20 +08:00
@flag = true
2015-08-20 16:05:58 +08:00
if params [ :send_id ] . present?
send_id = params [ :send_id ]
project_ids = params [ :projects_ids ]
2015-08-27 11:02:20 +08:00
if project_ids . nil?
@flag = false
end
2015-08-20 16:05:58 +08:00
ori = Attachment . find_by_id ( send_id )
unless project_ids . nil?
project_ids . each do | project_id |
next if ori . blank?
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
if attach_copied_obj . attachtype == nil
attach_copied_obj . attachtype = 1
end
attach_copied_obj . save
2015-08-20 10:14:26 +08:00
end
end
2015-08-20 16:05:58 +08:00
elsif params [ :send_ids ] . present?
send_ids = params [ :send_ids ] . split ( " " )
2015-08-27 11:02:20 +08:00
project_ids = params [ :projects_ids ]
if project_ids . nil?
@flag = false
end
2015-08-20 16:05:58 +08:00
send_ids . each do | send_id |
2015-08-27 11:02:20 +08:00
2015-08-20 16:05:58 +08:00
ori = Attachment . find_by_id ( send_id )
unless project_ids . nil?
project_ids . each do | project_id |
next if ori . blank?
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
if attach_copied_obj . attachtype == nil
attach_copied_obj . attachtype = 1
end
attach_copied_obj . save
end
end
end
else
2015-08-27 11:02:20 +08:00
@flag = true
2015-08-20 10:14:26 +08:00
end
2015-09-01 16:37:43 +08:00
user_course_ids = User . current . courses . map { | c | c . id } #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and container_type in('Project','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 ( ',' ) } )) " ) . order ( " created_on desc " )
@type = params [ :type ]
@limit = 25
@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
2015-08-20 10:14:26 +08:00
respond_to do | format |
format . js
end
end
2015-08-18 09:31:03 +08:00
# 资源预览
def resource_preview
2015-09-01 16:37:43 +08:00
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
2015-08-18 09:31:03 +08:00
end
2015-08-18 11:53:54 +08:00
# 重命名资源
def rename_resource
2015-08-20 17:38:30 +08:00
@attachment = Attachment . find ( params [ :res_id ] ) if params [ :res_id ] . present?
2015-08-18 11:53:54 +08:00
if @attachment != nil
@attachment . filename = params [ :res_name ]
@flag = @attachment . save
end
# respond_to do |format|
# format.js
# end
if @flag
2015-08-18 17:26:39 +08:00
render :text = > download_named_attachment_path ( @attachment . id , @attachment . filename )
2015-08-18 11:53:54 +08:00
else
render :text = > 'fail'
end
end
2014-09-15 10:58:14 +08:00
def destroy
@user . destroy
respond_to do | format |
format . html { redirect_back_or_default ( admin_users_path ) }
format . api { render_api_ok }
end
end
def edit_membership
@membership = Member . edit_membership ( params [ :membership_id ] , params [ :membership ] , @user )
@membership . save
respond_to do | format |
2014-10-15 09:54:54 +08:00
format . html { redirect_to edit_user_url ( @user , :tab = > 'memberships' ) }
2014-09-15 10:58:14 +08:00
format . js
end
end
def destroy_membership
@membership = Member . find ( params [ :membership_id ] )
if @membership . deletable?
2015-09-01 16:37:43 +08:00
@membership . destroy
2014-09-15 10:58:14 +08:00
end
respond_to do | format |
2014-10-15 09:54:54 +08:00
format . html { redirect_to edit_user_url ( @user , :tab = > 'memberships' ) }
2014-09-15 10:58:14 +08:00
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 ]
case @obj_flag
2015-09-01 16:37:43 +08:00
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
2014-09-15 10:58:14 +08:00
end
unless @obj . nil?
@obj . tag_list . add ( @tags . split ( " , " ) )
else
2015-09-01 16:37:43 +08:00
return
2014-09-15 10:58:14 +08:00
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
2015-06-05 11:17:00 +08:00
# @obj = Bid.find_by_id(@obj_id)
2014-09-15 10:58:14 +08:00
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
###add by huang
2015-07-09 15:27:49 +08:00
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 ( ) ;
2015-08-26 11:41:32 +08:00
@action = 'watch'
render :template = > 'users/user_fanslist' , :layout = > 'new_base_user'
2014-09-15 10:58:14 +08:00
end
###add by huang
2015-07-09 15:27:49 +08:00
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'
2015-08-26 11:41:32 +08:00
render :layout = > 'new_base_user'
2014-09-15 10:58:14 +08:00
end
2015-07-14 15:16:15 +08:00
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
2014-09-15 10:58:14 +08:00
#william
def update_extensions ( user_extensions )
user_extensions = params [ :user_extensions ]
unless user_extensions . nil?
2015-09-01 16:37:43 +08:00
user_extensions = UserExtensions . find_by_id ( user_extensions . user_id )
2015-07-14 15:16:15 +08:00
2015-09-01 16:37:43 +08:00
# user_extensions.
2014-09-15 10:58:14 +08:00
end
end
def update_score
@user = User . find ( params [ :id ] )
end
2015-08-21 16:29:25 +08:00
#修改个人简介
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
2015-08-15 17:06:41 +08:00
# 资源库 分为全部 课程资源 项目资源 附件
def user_resource
#确定container_type
# @user = User.find(params[:id])
2015-08-21 10:44:09 +08:00
# 别人的资源库是没有权限去看的
if User . current . id . to_i != params [ :id ] . to_i
render_403
return
end
2015-09-01 16:37:43 +08:00
if ( params [ :type ] . blank? || params [ :type ] == " 1 " ) #全部
2015-08-18 16:57:41 +08:00
if User . current . id . to_i == params [ :id ] . to_i
2015-08-21 10:02:26 +08:00
user_course_ids = User . current . courses . map { | c | c . id } #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
2015-08-21 17:05:54 +08:00
" or (container_type = 'Course' and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } )) " ) . order ( " created_on desc " )
2015-08-15 17:06:41 +08:00
else
2015-08-21 10:02:26 +08:00
user_course_ids = User . find ( params [ :id ] ) . courses . visible . map { | c | c . id } #Ta的资源库的话, 应该是他上传的公开资源 加上 他加入的所有我可见课程里的公开资源
2015-08-19 12:04:06 +08:00
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and is_public = 1 " +
" and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
2015-08-21 17:05:54 +08:00
" or (container_type = 'Course' and is_public = 1 and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } )) " ) . order ( " created_on desc " )
2015-08-15 17:06:41 +08:00
end
elsif params [ :type ] == " 2 " #课程资源
2015-08-18 16:57:41 +08:00
if User . current . id . to_i == params [ :id ] . to_i
2015-08-21 16:36:42 +08:00
user_course_ids = User . current . courses . map { | c | c . id }
2015-08-21 17:05:54 +08:00
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and container_type = 'Course') or (container_type = 'Course' and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } )) " ) . order ( " created_on desc " )
2015-08-15 17:06:41 +08:00
else
2015-08-19 12:04:06 +08:00
user_course_ids = User . find ( params [ :id ] ) . courses . visible . map { | c | c . id } #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and is_public = 1 and container_type = 'Course') " +
2015-08-21 17:05:54 +08:00
" or (container_type = 'Course' and is_public = 1 and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } )) " ) . order ( " created_on desc " )
2015-08-15 17:06:41 +08:00
end
elsif params [ :type ] == " 3 " #项目资源
2015-08-18 16:57:41 +08:00
if User . current . id . to_i == params [ :id ] . to_i
2015-08-15 17:06:41 +08:00
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type = 'Project' " ) . order ( " created_on desc " )
else
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and is_public = 1 and container_type = 'Project' " ) . order ( " created_on desc " )
end
elsif params [ :type ] == " 4 " #附件
2015-08-18 16:57:41 +08:00
if User . current . id . to_i == params [ :id ] . to_i
2015-08-20 17:38:30 +08:00
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon') " ) . order ( " created_on desc " )
2015-08-15 17:06:41 +08:00
else
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and is_public = 1 and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon') " ) . order ( " created_on desc " )
end
2015-08-29 12:32:00 +08:00
elsif params [ :type ] == " 5 " #用户资源
if User . current . id . to_i == params [ :id ] . to_i
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type = 'Principal' " ) . order ( " created_on desc " )
else
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and is_public = 1 and container_type = 'Principal' " ) . order ( " created_on desc " )
end
2015-08-15 17:06:41 +08:00
end
@type = params [ :type ]
2015-08-28 10:47:50 +08:00
@limit = 25
2015-08-20 17:38:30 +08:00
@is_remote = true
2015-08-24 10:31:25 +08:00
@atta_count = @attachments . count
@atta_pages = Paginator . new @atta_count , @limit , params [ 'page' ] || 1
@offset || = @atta_pages . offset
2015-08-20 17:00:54 +08:00
#@curse_attachments_all = @all_attachments[@offset, @limit]
2015-08-28 10:47:50 +08:00
@attachments = paginateHelper @attachments , 25
2015-08-15 17:06:41 +08:00
respond_to do | format |
format . js
2015-08-24 13:54:15 +08:00
format . html { render :layout = > 'new_base_user' }
2015-08-15 17:06:41 +08:00
end
end
# 根据资源关键字进行搜索
def resource_search
search = params [ :search ] . to_s . strip . downcase
2015-08-18 15:25:36 +08:00
if ( params [ :type ] . nil? || params [ :type ] == " 1 " ) #全部
2015-08-19 09:20:39 +08:00
if User . current . id . to_i == params [ :id ] . to_i
2015-08-21 10:02:26 +08:00
user_course_ids = User . current . courses . map { | c | c . id } #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源 取交集并查询
@attachments = Attachment . where ( " ((author_id = #{ params [ :id ] } and container_type in('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
2015-08-21 17:05:54 +08:00
" or (container_type = 'Course' and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } ))) and (filename like '% #{ search } %') " ) . order ( " created_on desc " )
2015-08-18 15:25:36 +08:00
else
2015-08-19 12:04:06 +08:00
user_course_ids = User . find ( params [ :id ] ) . courses . visible . map { | c | c . id } #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中
@attachments = Attachment . where ( " ((author_id = #{ params [ :id ] } and is_public = 1 and container_type in " +
2015-09-01 16:37:43 +08:00
" ('Project','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) " +
" or (container_type = 'Course' and is_public = 1 and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } )) ) " +
" and (filename like '% #{ search } %') " ) . order ( " created_on desc " )
2015-08-18 15:25:36 +08:00
end
elsif params [ :type ] == " 2 " #课程资源
2015-08-19 09:20:39 +08:00
if User . current . id . to_i == params [ :id ] . to_i
2015-08-21 16:36:42 +08:00
user_course_ids = User . current . courses . map { | c | c . id }
2015-08-21 21:29:33 +08:00
@attachments = Attachment . where ( " (author_id = #{ params [ :id ] } and container_type = 'Course') or (container_type = 'Course' and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } )) and (filename like '% #{ search } %') " ) . order ( " created_on desc " )
2015-08-18 15:25:36 +08:00
else
2015-08-19 12:04:06 +08:00
user_course_ids = User . find ( params [ :id ] ) . courses . visible . map { | c | c . id } #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中
@attachments = Attachment . where ( " ((author_id = #{ params [ :id ] } and is_public = 1 and container_type = 'Course') " +
2015-09-01 16:37:43 +08:00
" or (container_type = 'Course' and is_public = 1 and container_id in ( #{ user_course_ids . empty? ? '0' : user_course_ids . join ( ',' ) } )) ) " +
2015-08-19 12:04:06 +08:00
" and (filename like '% #{ search } %') " ) . order ( " created_on desc " )
2015-08-18 15:25:36 +08:00
end
elsif params [ :type ] == " 3 " #项目资源
2015-08-19 09:20:39 +08:00
if User . current . id . to_i == params [ :id ] . to_i
2015-08-18 15:25:36 +08:00
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type = 'Project' and (filename like '% #{ search } %') " ) . order ( " created_on desc " )
else
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and is_public = 1 and container_type = 'Project' and (filename like '% #{ search } %') " ) . order ( " created_on desc " )
end
elsif params [ :type ] == " 4 " #附件
2015-08-19 09:20:39 +08:00
if User . current . id . to_i == params [ :id ] . to_i
2015-08-18 15:25:36 +08:00
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type in('Project','Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like '% #{ search } %') " ) . order ( " created_on desc " )
else
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and is_public = 1 and container_type in('Issue','Document','Message','News','StudentWorkScore','HomewCommon') and (filename like '% #{ search } %') " ) . order ( " created_on desc " )
end
2015-08-29 12:32:00 +08:00
elsif params [ :type ] == " 5 " #用户资源
if User . current . id . to_i == params [ :id ] . to_i
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and container_type = 'Principal' and (filename like '% #{ search } %') " ) . order ( " created_on desc " )
else
@attachments = Attachment . where ( " author_id = #{ params [ :id ] } and is_public = 1 and container_type = 'Principal' and (filename like '% #{ search } %') " ) . order ( " created_on desc " )
end
2015-08-15 17:06:41 +08:00
end
2015-08-18 15:25:36 +08:00
@type = params [ :type ]
2015-08-28 10:47:50 +08:00
@limit = 25
2015-08-20 17:38:30 +08:00
@is_remote = true
2015-08-24 10:31:25 +08:00
@atta_count = @attachments . count
@atta_pages = Paginator . new @atta_count , @limit , params [ 'page' ] || 1
@offset || = @atta_pages . offset
2015-08-20 17:00:54 +08:00
#@curse_attachments_all = @all_attachments[@offset, @limit]
2015-08-28 10:47:50 +08:00
@attachments = paginateHelper @attachments , 25
2015-08-15 17:06:41 +08:00
respond_to do | format |
format . js
end
end
2014-09-15 10:58:14 +08:00
private
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
2015-08-15 17:06:41 +08:00
def setting_layout ( default_base = 'base_users_new' )
2014-09-15 10:58:14 +08:00
User . current . admin? ? default_base : default_base
end
# 必填自己的工作单位,其实就是学校
def auth_user_extension
2015-07-14 15:16:15 +08:00
if @user == User . current && @user . user_extensions . nil?
2014-09-15 10:58:14 +08:00
flash [ :error ] = l ( :error_complete_occupation )
2014-10-15 09:54:54 +08:00
redirect_to my_account_url
2014-09-15 10:58:14 +08:00
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
2014-10-16 11:09:45 +08:00
@first_page = FirstPage . find_by_page_type ( 'project' )
2014-09-15 10:58:14 +08:00
if @first_page . show_course == 2
render_404
end
end
2015-07-14 15:16:15 +08:00
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
2015-08-15 17:06:41 +08:00
2014-09-15 10:58:14 +08:00
end