diff --git a/app/assets/javascripts/shield_activities.js.coffee b/app/assets/javascripts/shield_activities.js.coffee
new file mode 100644
index 000000000..761567942
--- /dev/null
+++ b/app/assets/javascripts/shield_activities.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
diff --git a/app/assets/stylesheets/shield_activities.css.scss b/app/assets/stylesheets/shield_activities.css.scss
new file mode 100644
index 000000000..9ac6bff3e
--- /dev/null
+++ b/app/assets/stylesheets/shield_activities.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the shield_activities controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/controllers/at_controller.rb b/app/controllers/at_controller.rb
index 8c551d0df..9e7309646 100644
--- a/app/controllers/at_controller.rb
+++ b/app/controllers/at_controller.rb
@@ -7,10 +7,14 @@ class AtController < ApplicationController
@logger = Logger.new(Rails.root.join('log', 'at.log').to_s)
users = find_at_users(params[:type], params[:id])
@users = users
- @users = users.uniq { |u| u.id }.delete_if { |u| u.id == User.current.id } if users
+ @users = users.uniq { |u| u.id }.delete_if { |u| u.id == User.current.id }.sort{|x,y| to_pinyin(x.show_name) <=> to_pinyin(y.show_name)} if users
end
private
+ def to_pinyin(s)
+ Pinyin.t(s).downcase
+ end
+
def find_at_users(type, id)
@logger.info("#{type}, #{id}")
case type
diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb
index 664dc4cf5..fd43977ee 100644
--- a/app/controllers/attachments_controller.rb
+++ b/app/controllers/attachments_controller.rb
@@ -185,7 +185,6 @@ class AttachmentsController < ApplicationController
end
@attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16)
saved = @attachment.save
-
respond_to do |format|
format.js
format.api {
@@ -198,12 +197,43 @@ class AttachmentsController < ApplicationController
end
end
+ def upload_attachment_version
+ @flag = false
+ Attachment.transaction do
+ @old_attachment = Attachment.find params[:old_attachment_id]
+ #取出当前上传的文件
+ @attachment = Attachment.find(params[:attachments ].first[1][:attachment_id])
+ #将需要修改的记录保存到历史记录
+ @history = AttachmentHistory.new
+ @history.attributes = @old_attachment.attributes.dup.except("id")
+ @history.attachment_id = params[:old_attachment_id]
+ #需要更新版本号,需要拿到原来该文件最大的历史版本号
+ @old_history = @old_attachment.attachment_histories.reorder('version desc').first
+ @history.version = @old_history.nil? ? 1 : @old_history.version + 1
+ @history.save #历史记录保存完毕
+ #将最新保存的记录 数据替换到 需要修改的文件记录
+ @old_attachment.attributes = @attachment.attributes.dup.except("id","container_id","container_type","is_public")
+ @old_attachment.save
+ #删除当前记录
+ @attachment.delete
+ @flag = true
+ end
+
+ respond_to do |format|
+ format.js
+ end
+ end
+
def destroy
if @attachment.container.respond_to?(:init_journal)
@attachment.container.init_journal(User.current)
end
if @attachment.container
- @attachment.container.attachments.delete(@attachment)
+ if @attachment.container_type == "Issue"
+ @attachment.destroy
+ else
+ @attachment.container.attachments.delete(@attachment)
+ end
else
@attachment.destroy
end
@@ -242,6 +272,8 @@ class AttachmentsController < ApplicationController
format.html { redirect_to_referer_or mobile_version_path }
elsif !@attachment.container.nil? && @attachment.container.is_a?(OrgSubfield)
format.html {redirect_to_referer_or org_subfield_files_path(@attachment.container)}
+ elsif !@attachment.container.nil? && @attachment.container.is_a?(OrgDocumentComment)
+ format.html {redirect_to_referer_or org_document_comment_path(@attachment.container)}
else
if @project.nil?
format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) }
@@ -253,7 +285,7 @@ class AttachmentsController < ApplicationController
format.js
end
end
-
+
def delete_homework
@bid = @attachment.container.bid
# Make sure association callbacks are called
@@ -316,13 +348,13 @@ class AttachmentsController < ApplicationController
end
respond_to do |format|
- format.js
+ format.js
end
rescue NoMethodError
@save_flag = false
@save_message = [] << l(:error_attachment_empty)
respond_to do |format|
- format.js
+ format.js
end
end
@@ -492,6 +524,15 @@ class AttachmentsController < ApplicationController
end
end
+ #找到文件的所有的历史版本
+ def attachment_versions
+ @attachment = Attachment.find(params[:id])
+ @attachment_histories = @attachment.attachment_histories
+ respond_to do |format|
+ format.js
+ end
+ end
+
private
def find_project
@attachment = Attachment.find(params[:id])
diff --git a/app/controllers/avatar_controller.rb b/app/controllers/avatar_controller.rb
index a7c0e7b95..b5c174b0c 100644
--- a/app/controllers/avatar_controller.rb
+++ b/app/controllers/avatar_controller.rb
@@ -10,7 +10,7 @@ class AvatarController < ApplicationController
unless request.content_type == 'application/octet-stream'
@source_type = params[:source_type]
@source_id = params[:source_id]
- @temp_file = params[:avatar][:image]
+ @temp_file = params[:avatar][:image]
@image_file = @temp_file.original_filename
else
unless request.raw_post.nil?
@@ -23,7 +23,7 @@ class AvatarController < ApplicationController
#image_file.force_encoding("UTF-8") if filename.respond_to?(:force_encoding)
else
@image_file=params[:filename]
- end
+ end
@temp_file = StringIO.new(@temp_file)
end
end
diff --git a/app/controllers/blog_comments_controller.rb b/app/controllers/blog_comments_controller.rb
index 7c09e2cdf..ae6aff794 100644
--- a/app/controllers/blog_comments_controller.rb
+++ b/app/controllers/blog_comments_controller.rb
@@ -52,7 +52,11 @@ class BlogCommentsController < ApplicationController
render_attachment_warning_if_needed(@article)
else
end
- redirect_to user_blog_blog_comment_path(:user_id=>params[:user_id],:blog_id=>params[:blog_id],:id=>params[:id])
+ if params[:is_homepage]
+ redirect_to user_blogs_path(params[:user_id])
+ else
+ redirect_to user_blog_blog_comment_path(:user_id=>params[:user_id],:blog_id=>params[:blog_id],:id=>params[:id])
+ end
end
def destroy
@article = BlogComment.find(params[:id])
diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb
index 07bf60464..0202224ed 100644
--- a/app/controllers/blogs_controller.rb
+++ b/app/controllers/blogs_controller.rb
@@ -1,5 +1,5 @@
class BlogsController < ApplicationController
- before_filter :find_blog,:except => [:index,:create,:new]
+ before_filter :find_blog,:except => [:index,:create,:new,:set_homepage, :cancel_homepage]
before_filter :find_user
def index
@articls = @user.blog.articles
@@ -26,6 +26,18 @@ class BlogsController < ApplicationController
def edit
end
+
+ def set_homepage
+ @blog = Blog.find(params[:id])
+ @blog.update_attribute(:homepage_id, params[:article_id])
+ redirect_to user_blogs_path(params[:user_id])
+ end
+
+ def cancel_homepage
+ @blog = Blog.find(params[:id])
+ @blog.update_attribute(:homepage_id, nil)
+ redirect_to user_blogs_path(params[:user_id])
+ end
private
def find_blog
if params[:blog_id]
diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb
index 0c3236d4e..c8518e8a3 100644
--- a/app/controllers/boards_controller.rb
+++ b/app/controllers/boards_controller.rb
@@ -18,8 +18,8 @@
class BoardsController < ApplicationController
layout 'base_projects'#by young
default_search_scope :messages
- before_filter :find_project_by_project_id, :find_board_if_available
- before_filter :authorize, :except => [:new, :show, :create, :index]
+ before_filter :find_project_by_project_id, :find_board_if_available, :except => [:join_to_org_subfields]
+ before_filter :authorize, :except => [:new, :show, :create, :index, :join_to_org_subfields]
accept_rss_auth :index, :show
@@ -79,13 +79,12 @@ class BoardsController < ApplicationController
end
end
end
-
+ # 更新@消息为已读
@project.boards.each do |board|
board.messages.each do |m|
User.current.at_messages.unviewed('Message', m.id).each {|x| x.viewed!}
end
end
-
elsif @course
query_course_messages = @board.messages
query_course_messages.each do |query_course_message|
@@ -106,43 +105,19 @@ class BoardsController < ApplicationController
@is_new = params[:is_new]
@topic_count = @board ? @board.topics.count : 0
if @project
- @topic_pages = Paginator.new @topic_count, per_page_option, params['page']
- #现在发布帖子的时候置顶功能已经没有了。所以取消这个置顶排序 #{Message.table_name}.sticky DESC,
- @topics = @board.topics.
- reorder("#{Message.table_name}.created_on desc").
- includes(:last_reply).
- limit(@topic_pages.per_page).
- offset(@topic_pages.offset).
-
- preload(:author, {:last_reply => :author}).
- all
+ if @board
+ limit = 10;
+ @topic_count = @board.topics.count();
+ @topic_pages = (params[:page] ? params[:page].to_i + 1 : 0) *10
+ @topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) desc").
+ limit(limit).offset(@topic_pages).includes(:last_reply).
+ preload(:author, {:last_reply => :author}).all();
+ else
+ @topics = [];
+ end
elsif @course
- #
- # board_topics = @board ? @board.topics.reorder("#{Message.table_name}.sticky DESC, #{Message.table_name}.created_on desc").
- # includes(:last_reply).
- # # limit(@topic_pages.per_page).
- # # offset(@topic_pages.offset).
- #
- # preload(:author, {:last_reply => :author}).
- # all : []
- # @topics = paginateHelper board_topics,10
if (@board)
limit = 10;
- #pageno = params[:page];
- #if(pageno == nil || pageno=='')
- # dw_topic = nil;
- # if( params[:parent_id]!=nil && params[:parent_id]!='' )
- # dw_topic = @board.topics.where(id:params[:parent_id]).first();
- # end
- # if( dw_topic != nil )
- # dw_count = @board.topics.where('(sticky>?) or (sticky=? and created_on>?)',dw_topic.sticky,dw_topic.sticky,dw_topic.created_on).count();
- # dw_count = dw_count+1;
- # pageno = dw_count%10==0 ? (dw_count/limit) : (dw_count/limit+1)
- # end
- #end
- #if(pageno == nil || pageno=='')
- # pageno=1;
- #end
@topic_count = @board.topics.count();
@topic_pages = (params[:page] ? params[:page].to_i + 1 : 0) *10
@topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) desc").
@@ -225,6 +200,16 @@ class BoardsController < ApplicationController
redirect_to_settings_in_projects
end
+ def join_to_org_subfields
+ if params[:id]
+ @board = Board.find(params[:id])
+ @org_subfield_ids = params[:org_subfield_ids]
+ @org_subfield_ids.each do |id|
+ OrgSubfieldBoard.create(:org_subfield_id => id.to_i, :board_id => params[:id].to_i)
+ end
+ end
+ end
+
private
def redirect_to_settings_in_projects
redirect_to settings_project_url(@project, :tab => 'boards')
diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb
index 11a788590..c8dcf0b8e 100644
--- a/app/controllers/comments_controller.rb
+++ b/app/controllers/comments_controller.rb
@@ -54,16 +54,9 @@ class CommentsController < ApplicationController
# end
# # ������ض�̬�ļ�¼add end
#flash[:notice] = l(:label_comment_added)
- course_activity = CourseActivity.where("course_act_type='News' and course_act_id =#{@news.id}").first
- if course_activity
- course_activity.updated_at = Time.now
- course_activity.save
- end
- user_activity = UserActivity.where("act_type='News' and act_id =#{@news.id}").first
- if user_activity
- user_activity.updated_at = Time.now
- user_activity.save
- end
+ update_course_activity(@news.class,@news.id)
+ update_user_activity(@news.class,@news.id)
+ update_org_activity(@news.class,@news.id)
end
if params[:user_activity_id]
diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb
index 8bd91b089..279975c77 100644
--- a/app/controllers/courses_controller.rb
+++ b/app/controllers/courses_controller.rb
@@ -1,3 +1,4 @@
+#encoding: utf-8
class CoursesController < ApplicationController
# layout 'base_courses'
include CoursesHelper
@@ -38,15 +39,17 @@ class CoursesController < ApplicationController
end
limit = 15
course_org_ids = OrgCourse.find_by_sql("select distinct organization_id from org_courses where course_id = #{params[:id]}").map(&:organization_id)
- if course_org_ids.empty?
- @orgs_not_in_course = Organization.where("(is_public or creator_id =?) and name like ?",User.current.id, condition).page((params[:page].to_i || 1)).per(limit)
- @org_count = Organization.where("is_public = 1 or creator_id =?", User.current.id).where("name like ?", condition).count
- else
- course_org_ids = "(" + course_org_ids.join(',') + ")"
- @orgs_not_in_course = Organization.where("id not in #{course_org_ids} and (is_public = 1 or creator_id =?) and name like ?", User.current.id, condition).page((params[:page].to_i || 1)).per(limit)
- @org_count = Organization.where("id not in #{course_org_ids} and (is_public = 1 or creator_id =?)", User.current.id).where("name like ?", condition).count
- end
- # @course_count = Project.course_entities.visible.like(params[:name]).page(params[:page]).count
+ #@orgs_not_in_course = User.current.organizations.where("organizations.id not in (#{course_org_ids.join(',')}) and organizations.name like ?", condition).page(params[:page].to_i || 1).per(limit)
+ #@org_count = User.current.organizations.where("organizations.id not in (#{course_org_ids.join(',')}) and organizations.name like ?", condition).count
+ if course_org_ids.empty?
+ @orgs_not_in_course = User.current.organizations.where("name like ?",condition).page((params[:page].to_i || 1)).per(limit)
+ @org_count = @orgs_not_in_course.count
+ else
+ course_org_ids = "(" + course_org_ids.join(',') + ")"
+ @orgs_not_in_course = User.current.organizations.where("organizations.id not in #{course_org_ids} and organizations.name like ?", condition).page((params[:page].to_i || 1)).per(limit)
+ @org_count = @orgs_not_in_course.empty? ? 0 : @orgs_not_in_course.count
+ end
+ @course_count = Project.course_entities.visible.like(params[:name]).page(params[:page]).count
@orgs_page = Paginator.new @org_count, limit,params[:page]
@hint_flag = params[:hint_flag]
#render :json => {:orgs => @orgs_not_in_course, :count => @org_count}.to_json
@@ -399,6 +402,25 @@ class CoursesController < ApplicationController
end
+ def private_or_public
+ if @course.is_public == 0
+ @course.update_attributes(:is_public => 1)
+ else
+ @course.update_attributes(:is_public => 0)
+ end
+ if @course.is_public == 0
+ course_status = CourseStatus.find_by_course_id(@course.id)
+ course_status.destroy if course_status
+ elsif @course.is_public == 1
+ course_status = CourseStatus.find_by_course_id(@course.id)
+ course_status.destroy if course_status
+ course_status = CourseStatus.create(:course_id => @course.id, :grade => 0)
+ end
+ respond_to do |format|
+ format.js
+ end
+ end
+
def search_member
if User.current.allowed_to?(:as_teacher,@course) || User.current.admin
q = "#{params[:name].strip}"
@@ -417,6 +439,73 @@ class CoursesController < ApplicationController
def create
cs = CoursesService.new
@course = cs.create_course(params,User.current)[:course]
+ if params[:copy_course]
+ copy_course = Course.find params[:copy_course].to_i
+ @course.update_attributes(:open_student => copy_course.open_student, :publish_resource => copy_course.publish_resource)
+ if params[:checkAll]
+ attachments = copy_course.attachments
+ attachments.each do |attachment|
+ attach_copied_obj = attachment.copy
+ attach_copied_obj.tag_list.add(attachment.tag_list) # tag关联
+ attach_copied_obj.container = @course
+ attach_copied_obj.created_on = Time.now
+ attach_copied_obj.author_id = User.current.id
+ attach_copied_obj.copy_from = attachment.copy_from.nil? ? attachment.id : attachment.copy_from
+ if attach_copied_obj.attachtype == nil
+ attach_copied_obj.attachtype = 4
+ end
+ attach_copied_obj.save
+ update_quotes attach_copied_obj
+ end
+ elsif params[:course_attachment_type]
+ copy_attachments = []
+ params[:course_attachment_type].each do |type|
+ case type
+ when "1"
+ tag_name = l(:label_courseware)
+ when "2"
+ tag_name = l(:label_software)
+ when "3"
+ tag_name = l(:label_media)
+ when "4"
+ tag_name = l(:label_code)
+ when "6"
+ tag_name = "论文"
+ else
+ tag_name = ""
+ end
+ if tag_name == ""
+ tag_attachments = copy_course.attachments.select{|attachment|
+ !attachment.tag_list.include?('课件') &&
+ !attachment.tag_list.include?('软件') &&
+ !attachment.tag_list.include?('媒体') &&
+ !attachment.tag_list.include?('代码') &&
+ !attachment.tag_list.include?('论文') }
+ else
+ tag_attachments = copy_course.attachments.select{|attachment| attachment.tag_list.include?(tag_name)}
+ end
+ tag_attachments.each do |attach|
+ next if copy_attachments.include?(attach)
+ copy_attachments << attach
+ end
+ end
+ unless copy_attachments.blank?
+ copy_attachments.each do |c_attach|
+ attach_copied_obj = c_attach.copy
+ attach_copied_obj.tag_list.add(c_attach.tag_list) # tag关联
+ attach_copied_obj.container = @course
+ attach_copied_obj.created_on = Time.now
+ attach_copied_obj.author_id = User.current.id
+ attach_copied_obj.copy_from = c_attach.copy_from.nil? ? c_attach.id : c_attach.copy_from
+ if attach_copied_obj.attachtype == nil
+ attach_copied_obj.attachtype = 4
+ end
+ attach_copied_obj.save
+ update_quotes attach_copied_obj
+ end
+ end
+ end
+ end
if @course
respond_to do |format|
flash[:notice] = l(:notice_successful_create)
@@ -732,6 +821,11 @@ class CoursesController < ApplicationController
#param id:已有课程ID
def copy_course
if @course
+ @new_course = Course.new
+ respond_to do |format|
+ format.js
+ end
+=begin
@new_course = Course.new @course.attributes
@new_course.tea_id = User.current.id
@new_course.created_at = DateTime.now
@@ -750,6 +844,7 @@ class CoursesController < ApplicationController
@new_course.course_infos << course
redirect_to settings_course_url @new_course
end
+=end
else
render_404
end
@@ -810,6 +905,33 @@ class CoursesController < ApplicationController
end
private
+ def update_quotes attachment
+ if attachment.copy_from
+ attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.copy_from} or id = #{attachment.copy_from}")
+ else
+ attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.id} or id = #{attachment.copy_from}")
+ end
+ attachment.quotes = get_qute_number attachment
+ attachment.save
+ attachments.each do |att|
+ att.quotes = attachment.quotes
+ att.save
+ end
+ end
+
+ def get_qute_number attachment
+ if attachment.copy_from
+ result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.copy_from}")
+ else
+ result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.id}")
+ end
+ if result.nil? || result.count <= 0
+ return 0
+ else
+ return result[0].number
+ end
+ end
+
def allow_join course
if course_endTime_timeout? course
respond_to do |format|
diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb
index 25b5dacec..b1e5456c5 100644
--- a/app/controllers/exercise_controller.rb
+++ b/app/controllers/exercise_controller.rb
@@ -1,681 +1,709 @@
-class ExerciseController < ApplicationController
- layout "base_courses"
-
- before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit, :update, :show, :destroy,
- :commit_exercise, :commit_answer,:publish_exercise,:republish_exercise,
- :show_student_result,:student_exercise_list]
- before_filter :find_course, :only => [:index,:new,:create]
- include ExerciseHelper
-
- def index
- publish_exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now)
- publish_exercises.each do |exercise|
- exercise.update_column('exercise_status', 2)
- course = exercise.course
- course.members.each do |m|
- exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2)
- end
- end
-
- if @course.is_public == 0 && !(User.current.member_of_course?(@course)||User.current.admin?)
- render_403
- return
- end
- remove_invalid_exercise(@course)
- @is_teacher = User.current.allowed_to?(:as_teacher,@course)
- if @is_teacher || User.current.admin?
- exercises = @course.exercises.order("created_at asc")
- else
- exercises = @course.exercises.where("exercise_status <> 1").order("created_at asc")
- end
- @exercises = paginateHelper exercises,20 #分页
- respond_to do |format|
- format.html
- end
- end
-
- def show
- publish_exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now)
- publish_exercises.each do |exercise|
- exercise.update_column('exercise_status', 2)
- course = exercise.course
- course.members.each do |m|
- exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2)
- end
- end
-
- unless User.current.member_of_course?(@course) || User.current.admin?
- render_403
- return
- end
- @exercise = Exercise.find params[:id]
- @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
- exercise_end = @exercise.end_time > Time.now
- if @exercise.time == -1
- @can_edit_excercise = exercise_end
- else
- @can_edit_excercise = !has_commit_exercise?(@exercise.id,User.current.id)&& exercise_end
- end
- unless @is_teacher
- @exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first
- if @exercise_user.nil?
- eu = ExerciseUser.create(:user_id => User.current.id, :exercise_id => @exercise.id, :start_at => Time.now, :status => false)
- @exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first
- end
- score = calculate_student_score(@exercise, User.current)
- @exercise_user.update_attributes(:score => score)
- end
- # @percent = get_percent(@exercise,User.current)
- @exercise_questions = @exercise.exercise_questions
- respond_to do |format|
- format.html {render :layout => 'base_courses'}
- end
- #end
- end
-
- def new
- option = {
- :exercise_name => "",
- :course_id => @course.id,
- :exercise_status => 1,
- :user_id => User.current.id,
- :time => "",
- :end_time => "",
- :publish_time => "",
- :exercise_description => "",
- :show_result => 1
- }
- @exercise = Exercise.create option
- if @exercise
- redirect_to edit_exercise_url @exercise.id
- end
- end
-
- def create
- if params[:exercise]
- exercise = Exercise.find(params[:exercise_id]) if params[:exercise_id]
- exercise ||= Exercise.new
- exercise.exercise_name = params[:exercise][:exercise_name]
- exercise.exercise_description = params[:exercise][:exercise_description]
- exercise.end_time = Time.at(params[:exercise][:end_time].to_time.to_i + 16*60*60 -1)
- exercise.publish_time = params[:exercise][:publish_time]
- exercise.user_id = User.current.id
- exercise.time = params[:exercise][:time]
- exercise.course_id = params[:course_id]
- exercise.exercise_status = 1
- if exercise.save
- @exercise = exercise
- respond_to do |format|
- format.js
- end
- end
- end
- end
-
- def edit
- respond_to do |format|
- format.html{render :layout => 'base_courses'}
- end
- end
-
- def update
- @exercise.exercise_name = params[:exercise][:exercise_name]
- @exercise.exercise_description = params[:exercise][:exercise_description]
- @exercise.time = params[:exercise][:time].blank? ? -1 : params[:exercise][:time]
- @exercise.end_time = Time.at(params[:exercise][:end_time].to_time.to_i + 16*60*60 -1)
- @exercise.publish_time = params[:exercise][:publish_time]
- @exercise.show_result = params[:exercise][:show_result].blank? ? 1 : params[:exercise][:show_result]
- if @exercise.save
- respond_to do |format|
- format.js
- end
- else
- render_404
- end
- end
-
- def destroy
- @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
- if @exercise && @exercise.destroy
- if @is_teacher
- exercises = Exercise.where("course_id =?", @course.id)
- else
- exercises = Exercise.where("course_id =? and exercise_status =?", @course.id, 2)
- end
- @exercises = paginateHelper exercises,20 #分页
- respond_to do |format|
- format.js
- end
- end
- end
-
- # 统计结果
- def statistics_result
- @exercise = Exercise.find(params[:id])
- exercise_questions = @exercise.exercise_questions
- @exercise_questions = paginateHelper exercise_questions, 5
- respond_to do |format|
- format.html{render :layout => 'base_courses'}
- end
- end
-
- # 添加题目
- # question_type 1:单选 2:多选 3:填空题
- def create_exercise_question
- question_title = params[:question_title].nil? || params[:question_title].empty? ? l(:label_enter_single_title) : params[:question_title]
- option = {
- :question_title => question_title,
- :question_type => params[:question_type] || 1,
- :question_number => params[:question_type] == "1"? @exercise.exercise_questions.where("question_type = 1").count + 1 :
- (params[:question_type] == "2" ? (@exercise.exercise_questions.where("question_type = 2").count + 1) :
- @exercise.exercise_questions.where("question_type = 3").count + 1),
- :question_score => params[:question_score]
- }
- @exercise_questions = @exercise.exercise_questions.new option
- # params[:question_answer] 题目选项
- if params[:question_answer]
- for i in 1..params[:question_answer].count
- answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1]
- question_option = {
- :choice_position => i,
- :choice_text => answer
- }
- @exercise_questions.exercise_choices.new question_option
- end
- end
- # 如果是插入的话,那么从插入的这个id以后的question_num都将要+1
- if params[:quest_id]
- @is_insert = true
- if @exercise_questions.question_type == 1
- ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 1).update_all(" question_number = question_number + 1")
- #@exercise.exercise_questions.where("question_number > #{params[:quest_num].to_i} and question_type == 1").update_all(" question_number = question_number + 1")
- elsif @exercise_questions.question_type == 2
- ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 2).update_all(" question_number = question_number + 1")
- else
- ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 3).update_all(" question_number = question_number + 1")
- end
- # @exercise_question_num = params[:quest_num].to_i
- @exercise_questions.question_number = params[:quest_num].to_i + 1
- end
- if @exercise_questions.save
- # params[:exercise_choice] 标准答案参数
- # 问答题标准答案有三个,单独处理
- if @exercise_questions.question_type == 3
- for i in 1..params[:exercise_choice].count
- standart_answer = ExerciseStandardAnswer.new
- standart_answer.exercise_question_id = @exercise_questions.id
- standart_answer.answer_text = params[:exercise_choice].values[i-1]
- standart_answer.save
- end
- else
- standart_answer = ExerciseStandardAnswer.new
- standart_answer.exercise_question_id = @exercise_questions.id
- if @exercise_questions.question_type == 1
- standart_answer.exercise_choice_id = sigle_selection_standard_answer(params[:exercise_choice])
- else
- standart_answer.exercise_choice_id = multiselect_standard_answer(params[:exercise_choice])
- end
- standart_answer.save
- end
- respond_to do |format|
- format.js
- end
- end
-
- end
-
- # 修改题目
- # params[:exercise_question] The id of exercise_question
- # params[:question_answer] eg:A、B、C选项
- def update_exercise_question
- @exercise_question = ExerciseQuestion.find params[:exercise_question]
- @exercise_question.question_title = params[:question_title].nil? || params[:question_title].empty? ? l(:label_enter_single_title) : params[:question_title]
- @exercise_question.question_score = params[:question_score]
- # 处理选项:如果选了某个选项,那么则要删除之前的选项
- if params[:question_answer]
- @exercise_question.exercise_choices.each do |answer|
- answer.destroy unless params[:question_answer].keys.include? answer.id.to_s
- end
- for i in 1..params[:question_answer].count
- question = @exercise_question.exercise_choices.find_by_id params[:question_answer].keys[i-1]
- answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1]
- if question
- question.choice_position = i
- question.choice_text = answer
- question.save
- else
- question_option = {
- :choice_position => i,
- :choice_text => answer
- }
- @exercise_question.exercise_choices.new question_option
- end
- end
- end
- # 更新标准答案
- if params[:exercise_choice]
- if @exercise_question.question_type == 3
- # 删除不合理的选项
- @exercise_question.exercise_standard_answers.each do |answer|
- answer.destroy unless params[:exercise_choice].keys.include? answer.id.to_s
- end
- for i in 1..params[:exercise_choice].count
- # 找到对应的标准答案
- question_standart = @exercise_question.exercise_standard_answers.find_by_id params[:exercise_choice].keys[i-1]
- # 标准答案值
- answer_standart = (params[:exercise_choice].values[i-1].nil? || params[:exercise_choice].values[i-1].empty?) ? l(:label_new_answer) : params[:exercise_choice].values[i-1]
- if question_standart
- question_standart.answer_text = answer_standart
- question_standart.save
- else
- standart_answer_option = {
- :answer_text => answer_standart
- }
- @exercise_question.exercise_standard_answers.new standart_answer_option
- end
- end
- else
- answer_standart = @exercise_question.exercise_standard_answers.first
- answer_standart.exercise_choice_id = @exercise_question.question_type == 1 ? sigle_selection_standard_answer(params[:exercise_choice]) : multiselect_standard_answer(params[:exercise_choice])
- answer_standart.save
- end
- @exercise_question.save
- respond_to do |format|
- format.js
- end
- end
- end
-
- # 删除题目
- def delete_exercise_question
- @exercise_question = ExerciseQuestion.find params[:exercise_question]
- @exercise = @exercise_question.exercise
-
- if @exercise_question.question_type == 1
- ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 1).update_all(" question_number = question_number - 1")
- #@exercise.exercise_questions.where("question_number > #{params[:quest_num].to_i} and question_type == 1").update_all(" question_number = question_number + 1")
- elsif @exercise_question.question_type == 2
- ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 2).update_all(" question_number = question_number - 1")
- else
- ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 3).update_all(" question_number = question_number - 1")
- end
- # @exercise_question_num = params[:quest_num].to_i
- # @exercise_questions.question_number = params[:quest_num].to_i - 1
- #
- # exercise_questions = @exercise.exercise_questions.where("question_number > #{@exercise_question.question_number}")
- # exercise_questions.each do |question|
- # question.question_number -= 1
- # question.save
- # end
- if @exercise_question && @exercise_question.destroy
- respond_to do |format|
- format.js
- end
- end
- end
-
- # 发布试卷
- def publish_exercise
- @is_teacher = User.current.allowed_to?(:as_teacher,@course)
- @index = params[:index]
- @exercise.exercise_status = 2
- @exercise.publish_time = Time.now
- if @exercise.save
- @exercise.course.members.each do |m|
- @exercise.course_messages << CourseMessage.create(:user_id =>m.user_id, :course_id => @exercise.course.id, :viewed => false,:status=>2)
- end
- #redirect_to exercise_index_url(:course_id=> @course.id)
- respond_to do |format|
- format.js
- end
- end
- end
-
- # 重新发布试卷
- # 重新发布的时候会删除所有的答题
- def republish_exercise
- @is_teacher = User.current.allowed_to?(:as_teacher,@course)
- @index = params[:index]
- @exercise.exercise_questions.each do |exercise_question|
- exercise_question.exercise_answers.destroy_all
- end
- @exercise.course_messages.destroy_all
- @exercise.exercise_users.destroy_all
- @exercise.exercise_status = 1
- @exercise.publish_time = nil
- @exercise.save
- respond_to do |format|
- format.js
- end
- end
-
- def student_exercise_list
-=begin
- if @exercise.end_time <= Time.now
- @course.student.each do |student|
- if ExerciseUser.where("user_id = ? && exercise_id = ?",student.student_id,@exercise.id).empty?
- ExerciseUser.create(:user_id => student.student_id, :exercise_id => @exercise.id, :start_at => @exercise.end_time, :status => true,:score=>0)
- end
-
- s_score = calculate_student_score(@exercise, student.student)
- exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", student.student_id, @exercise.id).first
- exercise_user.update_attributes(:score => s_score)
- end
- end
-=end
- @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
- @all_exercises = @course.exercises.where("exercise_status > 1").order("created_at desc")
- @exercise_count = @exercise.exercise_users.where('score is not NULL').count
- if @is_teacher || (!@exercise.exercise_users.where(:user_id => User.current.id).empty? && @exercise.end_time <= Time.now)
- @exercise_users_list = @exercise.exercise_users.where('score is not NULL')
- @show_all = true;
- elsif !@exercise.exercise_users.where(:user_id => User.current.id).empty? && @exercise.end_time > Time.now
- @exercise_users_list = @exercise.exercise_users.where("user_id = ? and score is not NULL",User.current.id)
- else
- @exercise_users_list = []
- end
- respond_to do |format|
- format.html
- end
- end
-
- # 学生提交答卷,选中答案的过程中提交
- def commit_answer
- eq = ExerciseQuestion.find(params[:exercise_question_id])
- # 已提交过的且是限时的则不允许答题
- if (has_commit_exercise?(@exercise.id,User.current.id) && (!User.current.admin?) && @exercise.time != -1) || @exercise.end_time < Time.now
- render :json => {:text => "failure"}
- return
- end
- if eq.question_type == 1
- # 单选题
- ea = ExerciseAnswer.find_by_exercise_question_id_and_user_id(params[:exercise_question_id],User.current.id)
- if ea.nil?
- # 尚未答该题,添加答案
- ea = ExerciseAnswer.new
- ea.user_id = User.current.id
- ea.exercise_question_id = params[:exercise_question_id]
- end
- #修改该题对应答案
- ea.exercise_choice_id = params[:exercise_choice_id]
- if ea.save
- # 保存成功返回成功信息及当前以答题百分比
- uncomplete_question = get_uncomplete_question(@exercise, User.current)
- if uncomplete_question.count < 1
- complete = 1;
- else
- complete = 0;
- end
- @percent = get_percent(@exercise,User.current)
- render :json => {:text => "ok" ,:complete => complete,:percent => format("%.2f" ,@percent)}
- else
- #返回失败信息
- render :json => {:text => "failure"}
- end
- elsif eq.question_type == 2
- #多选题
- ea = ExerciseAnswer.find_by_exercise_choice_id_and_user_id(params[:exercise_choice_id],User.current.id)
- if ea.nil?
- #尚未答该题,添加答案
- ea = ExerciseAnswer.new
- ea.user_id = User.current.id
- ea.exercise_question_id = params[:exercise_question_id]
- ea.exercise_choice_id = params[:exercise_choice_id]
- if ea.save
- uncomplete_question = get_uncomplete_question(@exercise, User.current)
- if uncomplete_question.count < 1
- complete = 1;
- else
- complete = 0;
- end
- @percent = get_percent(@exercise,User.current)
- render :json => {:text => "ok",:complete => complete,:percent => format("%.2f" ,@percent)}
- else
- render :json => {:text => "failure"}
- end
- else
- #pv不为空,则当前选项之前已被选择,再次点击则是不再选择该项,故删除该答案
- if ea.delete
- @percent = get_percent(@exercise, User.current)
- render :json => {:text => "false" ,:percent => format("%.2f" , @percent)}
- else
- render :json => {:text => "failure"}
- end
- end
- elsif eq.question_type == 3
- #单行文本,多行文本题
- ea = ExerciseAnswer.find_by_exercise_question_id_and_user_id(params[:exercise_question_id], User.current.id)
- if ea.nil?
- # ea为空之前尚未答题,添加答案
- if params[:answer_text].nil? || params[:answer_text].blank?
- #用户提交空答案,视作不作答
- @percent = get_percent(@exercise,User.current)
- render :json => {:text => ea.answer_text,:percent => format("%.2f", @percent)}
- else
- #添加答案
- ea = ExerciseAnswer.new
- ea.user_id = User.current.id
- ea.exercise_question_id = params[:exercise_question_id]
- ea.answer_text = params[:answer_text]
- if ea.save
- uncomplete_question = get_uncomplete_question(@exercise, User.current)
- if uncomplete_question.count < 1
- complete = 1;
- else
- complete = 0;
- end
- @percent = get_percent(@exercise,User.current)
- render :json => {:text => ea.answer_text,:complete => complete,:percent => format("%.2f",@percent)}
- else
- render :json => {:text => "failure"}
- end
- end
- else
- # ea不为空说明用户之前已作答
- if params[:answer_text].nil? || params[:answer_text].blank?
- # 用户提交空答案,视为删除答案
- if ea.delete
- @percent = get_percent(@exercise,User.current)
- render :json => {:text => ea.answer_text,:percent => format("%.2f", @percent)}
- else
- render :json => {:text => "failure"}
- end
- else
- #用户修改答案
- ea.answer_text = params[:answer_text]
- if ea.save
- @percent = get_percent(@exercise,User.current)
- render :json => {:text => pv.vote_text,:percent => format("%.2f", @percent)}
- else
- render :json => {:text => "failure"}
- end
- end
- end
-
- else
- render :json => {:text => "failure"}
- end
- end
-
- # 提交问卷
- def commit_exercise
- # 老师不需要提交
- if User.current.allowed_to?(:as_teacher,@course)
- if @exercise.publish_time.nil?
- @exercise.update_attributes(:show_result => params[:show_result])
- @exercise.update_attributes(:exercise_status => 2)
- @exercise.update_attributes(:publish_time => Time.now)
- course = @exercise.course
- course.members.each do |m|
- @exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2)
- end
- redirect_to exercise_url(@exercise)
- return
- elsif @exercise.publish_time > Time.now
- @exercise.update_attributes(:show_result => params[:show_result])
- redirect_to exercise_url(@exercise)
- return
- end
- @exercise.update_attributes(:show_result => params[:show_result])
- redirect_to exercise_url(@exercise)
- # REDO: 提示提交成功
- else
- # 更新提交状态
- cur_exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", User.current, @exercise.id).first
- cur_exercise_user.update_attributes(:status => 1)
- # 答题过程中需要统计完成量
- @uncomplete_question = get_uncomplete_question(@exercise, User.current)
- # 获取改学生的考试得分
- @score = calculate_student_score(@exercise, User.current)
- # @score = 100
- if @uncomplete_question.count < 1
- # 查看是否有已提交记录
- cur_exercise_user.score = @score
- if cur_exercise_user.save
- #redirect_to poll_index_path(:polls_group_id => @course.id,:polls_type => 'Course')
- @status = 0 #提交成功
- else
- @status = 2 #未知错误
- end
- else
- @status = 1 #有未做得必答题
- end
- @save = params[:save].to_i if params[:save]
- respond_to do |format|
- format.js
- end
- end
- end
-
- #查看学生的答卷情况
- def show_student_result
- @user = User.find params[:user_id]
- @can_edit_excercise = false
- @exercise_questions = @exercise.exercise_questions
- score = calculate_student_score(@exercise, @user)
- eu = get_exercise_user(@exercise.id, @user.id)
- eu.update_attributes(:score => score)
- @exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", @user.id, @exercise.id).first
- respond_to do |format|
- format.html {render :layout => 'base_courses'}
- end
- end
-
- # 计算学生得分
- def calculate_student_score(exercise, user)
- score = 0
- score1 = 0
- score2 = 0
- score3 = 0
- exercise_qustions = exercise.exercise_questions
- exercise_qustions.each do |question|
- answer = get_user_answer(question, user)
- standard_answer = get_user_standard_answer(question, user)
- unless answer.empty?
- # 问答题有多个答案
- if question.question_type == 3 && !standard_answer.empty?
- if standard_answer.include?(answer.first.answer_text)
- score1 = score1+ question.question_score unless question.question_score.nil?
- end
- elsif question.question_type == 1 && !standard_answer.nil?
- if answer.first.exercise_choice.choice_position == standard_answer.exercise_choice_id
- score2 = score2 + question.question_score unless question.question_score.nil?
- end
- elsif question.question_type == 2 && !standard_answer.nil?
- arr = get_mulscore(question, user)
- if arr.to_i == standard_answer.exercise_choice_id
- score3 = score3 + question.question_score unless question.question_score.nil?
- end
- # ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id)
- # arr = []
- # ecs.each do |ec|
- # arr << ec.exercise_choice.choice_position
- # end
- # arr.sort
- # arr = arr.join("")
- # if arr.to_i == standard_answer.exercise_choice_id
- # score3 = score + question.question_score unless question.question_score.nil?
- # end
- end
- end
- end
- score = score1 + score2 + score3
- end
-
- private
-
- # ExerciseUser记录用户是否已提交问卷有对应的记录则已提交,没有则新建一个
- def get_exercise_user exercise_id,user_id
- eu = ExerciseUser.find_by_exercise_id_and_user_id(exercise_id,user_id)
- if eu.nil?
- eu = ExerciseUser.new
- end
- eu
- end
-
- # 获取当前学生回答问题的答案
- def get_user_answer(question,user)
- # user_answer = ExerciseAnswer.where("user_id=? and exercise_question_id=?", user.id, question.id).first
- user_answer = question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id}")
- user_answer
- end
-
- # 获取问题的标准答案
- def get_user_standard_answer(question,user)
- if question.question_type == 3
- standard_answer =[]
- question.exercise_standard_answers.each do |answer|
- standard_answer << answer.answer_text
- end
- else
- standard_answer = question.exercise_standard_answers.first
- end
- standard_answer
- end
- # 是否完成了答题
- def get_complete_question(exercise,user)
- questions = exercise.exercise_questions
- complete_question = []
- questions.each do |question|
- answers = get_user_answer(question,user)
- if !(answers.nil? || answers.count < 1)
- complete_question << question
- end
- end
- complete_question
- end
-
- # 获取答题百分比
- def get_percent exercise,user
- complete_count = get_complete_question(exercise,user).count
- if exercise.exercise_questions.count == 0
- return 0
- else
- return (complete_count.to_f / exercise.exercise_questions.count.to_f)*100
- end
- end
-
- def remove_invalid_exercise(course)
- exercises = course.exercises.where("exercise_name=?","")
- unless exercises.empty?
- exercises.each do |exercise|
- if exercise.exercise_questions.empty?
- exercise.destroy
- end
- end
- end
- end
-
- def find_exercise_and_course
- @exercise = Exercise.find params[:id]
- @course = Course.find @exercise.course_id
- rescue Exception => e
- render_404
- end
-
- def find_course
- @course = Course.find params[:course_id]
- rescue Exception => e
- render_404
- end
+class ExerciseController < ApplicationController
+ layout "base_courses"
+
+ before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit, :update, :show, :destroy,
+ :commit_exercise, :commit_answer,:publish_exercise,:republish_exercise,
+ :show_student_result,:student_exercise_list]
+ before_filter :find_course, :only => [:index,:new,:create]
+ include ExerciseHelper
+
+ def index
+ publish_exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now)
+ publish_exercises.each do |exercise|
+ exercise.update_column('exercise_status', 2)
+ course = exercise.course
+ course.members.each do |m|
+ exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2)
+ end
+ end
+
+ if @course.is_public == 0 && !(User.current.member_of_course?(@course)||User.current.admin?)
+ render_403
+ return
+ end
+ remove_invalid_exercise(@course)
+ @is_teacher = User.current.allowed_to?(:as_teacher,@course)
+ if @is_teacher || User.current.admin?
+ exercises = @course.exercises.order("created_at asc")
+ else
+ exercises = @course.exercises.where("exercise_status <> 1").order("created_at asc")
+ end
+ @exercises = paginateHelper exercises,20 #分页
+ respond_to do |format|
+ format.html
+ end
+ end
+
+ def show
+ publish_exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now)
+ publish_exercises.each do |exercise|
+ exercise.update_column('exercise_status', 2)
+ course = exercise.course
+ course.members.each do |m|
+ exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2)
+ end
+ end
+
+ unless User.current.member_of_course?(@course) || User.current.admin?
+ render_403
+ return
+ end
+ @exercise = Exercise.find params[:id]
+ @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
+ exercise_end = @exercise.end_time > Time.now
+ if @exercise.time == -1
+ @can_edit_excercise = exercise_end
+ else
+ @can_edit_excercise = !has_commit_exercise?(@exercise.id,User.current.id)&& exercise_end
+ end
+ unless @is_teacher
+ @exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first
+ if @exercise_user.nil?
+ eu = ExerciseUser.create(:user_id => User.current.id, :exercise_id => @exercise.id, :start_at => Time.now, :status => false)
+ @exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first
+ end
+ score = calculate_student_score(@exercise, User.current)
+ @exercise_user.update_attributes(:score => score)
+ end
+ # @percent = get_percent(@exercise,User.current)
+ @exercise_questions = @exercise.exercise_questions
+ respond_to do |format|
+ format.html {render :layout => 'base_courses'}
+ end
+ #end
+ end
+
+ def new
+ option = {
+ :exercise_name => "",
+ :course_id => @course.id,
+ :exercise_status => 1,
+ :user_id => User.current.id,
+ :time => "",
+ :end_time => "",
+ :publish_time => "",
+ :exercise_description => "",
+ :show_result => 1
+ }
+ @exercise = Exercise.create option
+ if @exercise
+ redirect_to edit_exercise_url @exercise.id
+ end
+ end
+
+ def create
+ if params[:exercise]
+ exercise = Exercise.find(params[:exercise_id]) if params[:exercise_id]
+ exercise ||= Exercise.new
+ exercise.exercise_name = params[:exercise][:exercise_name]
+ exercise.exercise_description = params[:exercise][:exercise_description]
+ exercise.end_time = Time.at(params[:exercise][:end_time].to_time.to_i + 16*60*60 -1)
+ exercise.publish_time = params[:exercise][:publish_time]
+ exercise.user_id = User.current.id
+ exercise.time = params[:exercise][:time]
+ exercise.course_id = params[:course_id]
+ exercise.exercise_status = 1
+ if exercise.save
+ @exercise = exercise
+ respond_to do |format|
+ format.js
+ end
+ end
+ end
+ end
+
+ def edit
+ respond_to do |format|
+ format.html{render :layout => 'base_courses'}
+ end
+ end
+
+ def update
+ @exercise.exercise_name = params[:exercise][:exercise_name]
+ @exercise.exercise_description = params[:exercise][:exercise_description]
+ @exercise.time = params[:exercise][:time].blank? ? -1 : params[:exercise][:time]
+ @exercise.end_time = Time.at(params[:exercise][:end_time].to_time.to_i + 16*60*60 -1)
+ @exercise.publish_time = params[:exercise][:publish_time]
+ @exercise.show_result = params[:exercise][:show_result].blank? ? 1 : params[:exercise][:show_result]
+ if @exercise.save
+ respond_to do |format|
+ format.js
+ end
+ else
+ render_404
+ end
+ end
+
+ def destroy
+ @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
+ if @exercise && @exercise.destroy
+ if @is_teacher
+ exercises = Exercise.where("course_id =?", @course.id)
+ else
+ exercises = Exercise.where("course_id =? and exercise_status =?", @course.id, 2)
+ end
+ @exercises = paginateHelper exercises,20 #分页
+ respond_to do |format|
+ format.js
+ end
+ end
+ end
+
+ # 统计结果
+ def statistics_result
+ @exercise = Exercise.find(params[:id])
+ exercise_questions = @exercise.exercise_questions
+ @exercise_questions = paginateHelper exercise_questions, 5
+ respond_to do |format|
+ format.html{render :layout => 'base_courses'}
+ end
+ end
+
+ # 添加题目
+ # question_type 1:单选 2:多选 3:填空题
+ def create_exercise_question
+ question_title = params[:question_title].nil? || params[:question_title].empty? ? l(:label_enter_single_title) : params[:question_title]
+ option = {
+ :question_title => question_title,
+ :question_type => params[:question_type] || 1,
+ :question_number => params[:question_type] == "1"? @exercise.exercise_questions.where("question_type = 1").count + 1 :
+ (params[:question_type] == "2" ? (@exercise.exercise_questions.where("question_type = 2").count + 1) :
+ @exercise.exercise_questions.where("question_type = 3").count + 1),
+ :question_score => params[:question_score]
+ }
+ @exercise_questions = @exercise.exercise_questions.new option
+ # params[:question_answer] 题目选项
+ if params[:question_answer]
+ for i in 1..params[:question_answer].count
+ answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1]
+ question_option = {
+ :choice_position => i,
+ :choice_text => answer
+ }
+ @exercise_questions.exercise_choices.new question_option
+ end
+ end
+ # 如果是插入的话,那么从插入的这个id以后的question_num都将要+1
+ if params[:quest_id]
+ @is_insert = true
+ if @exercise_questions.question_type == 1
+ ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 1).update_all(" question_number = question_number + 1")
+ #@exercise.exercise_questions.where("question_number > #{params[:quest_num].to_i} and question_type == 1").update_all(" question_number = question_number + 1")
+ elsif @exercise_questions.question_type == 2
+ ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 2).update_all(" question_number = question_number + 1")
+ else
+ ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 3).update_all(" question_number = question_number + 1")
+ end
+ # @exercise_question_num = params[:quest_num].to_i
+ @exercise_questions.question_number = params[:quest_num].to_i + 1
+ end
+ if @exercise_questions.save
+ # params[:exercise_choice] 标准答案参数
+ # 问答题标准答案有三个,单独处理
+ if @exercise_questions.question_type == 3
+ for i in 1..params[:exercise_choice].count
+ standart_answer = ExerciseStandardAnswer.new
+ standart_answer.exercise_question_id = @exercise_questions.id
+ standart_answer.answer_text = params[:exercise_choice].values[i-1]
+ standart_answer.save
+ end
+ else
+ standart_answer = ExerciseStandardAnswer.new
+ standart_answer.exercise_question_id = @exercise_questions.id
+ if @exercise_questions.question_type == 1
+ standart_answer.exercise_choice_id = sigle_selection_standard_answer(params[:exercise_choice])
+ else
+ standart_answer.exercise_choice_id = multiselect_standard_answer(params[:exercise_choice])
+ end
+ standart_answer.save
+ end
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ end
+
+ # 修改题目
+ # params[:exercise_question] The id of exercise_question
+ # params[:question_answer] eg:A、B、C选项
+ def update_exercise_question
+ @exercise_question = ExerciseQuestion.find params[:exercise_question]
+ @exercise_question.question_title = params[:question_title].nil? || params[:question_title].empty? ? l(:label_enter_single_title) : params[:question_title]
+ @exercise_question.question_score = params[:question_score]
+ # 处理选项:如果选了某个选项,那么则要删除之前的选项
+ if params[:question_answer]
+ @exercise_question.exercise_choices.each do |answer|
+ answer.destroy unless params[:question_answer].keys.include? answer.id.to_s
+ end
+ for i in 1..params[:question_answer].count
+ question = @exercise_question.exercise_choices.find_by_id params[:question_answer].keys[i-1]
+ answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1]
+ if question
+ question.choice_position = i
+ question.choice_text = answer
+ question.save
+ else
+ question_option = {
+ :choice_position => i,
+ :choice_text => answer
+ }
+ @exercise_question.exercise_choices.new question_option
+ end
+ end
+ end
+ # 更新标准答案
+ if params[:exercise_choice]
+ if @exercise_question.question_type == 3
+ # 删除不合理的选项
+ @exercise_question.exercise_standard_answers.each do |answer|
+ answer.destroy unless params[:exercise_choice].keys.include? answer.id.to_s
+ end
+ for i in 1..params[:exercise_choice].count
+ # 找到对应的标准答案
+ question_standart = @exercise_question.exercise_standard_answers.find_by_id params[:exercise_choice].keys[i-1]
+ # 标准答案值
+ answer_standart = (params[:exercise_choice].values[i-1].nil? || params[:exercise_choice].values[i-1].empty?) ? l(:label_new_answer) : params[:exercise_choice].values[i-1]
+ if question_standart
+ question_standart.answer_text = answer_standart
+ question_standart.save
+ else
+ standart_answer_option = {
+ :answer_text => answer_standart
+ }
+ @exercise_question.exercise_standard_answers.new standart_answer_option
+ end
+ end
+ else
+ answer_standart = @exercise_question.exercise_standard_answers.first
+ answer_standart.exercise_choice_id = @exercise_question.question_type == 1 ? sigle_selection_standard_answer(params[:exercise_choice]) : multiselect_standard_answer(params[:exercise_choice])
+ answer_standart.save
+ end
+ @exercise_question.save
+ respond_to do |format|
+ format.js
+ end
+ end
+ end
+
+ # 删除题目
+ def delete_exercise_question
+ @exercise_question = ExerciseQuestion.find params[:exercise_question]
+ @exercise = @exercise_question.exercise
+
+ if @exercise_question.question_type == 1
+ ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 1).update_all(" question_number = question_number - 1")
+ #@exercise.exercise_questions.where("question_number > #{params[:quest_num].to_i} and question_type == 1").update_all(" question_number = question_number + 1")
+ elsif @exercise_question.question_type == 2
+ ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 2).update_all(" question_number = question_number - 1")
+ else
+ ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 3).update_all(" question_number = question_number - 1")
+ end
+ # @exercise_question_num = params[:quest_num].to_i
+ # @exercise_questions.question_number = params[:quest_num].to_i - 1
+ #
+ # exercise_questions = @exercise.exercise_questions.where("question_number > #{@exercise_question.question_number}")
+ # exercise_questions.each do |question|
+ # question.question_number -= 1
+ # question.save
+ # end
+ if @exercise_question && @exercise_question.destroy
+ respond_to do |format|
+ format.js
+ end
+ end
+ end
+
+ # 发布试卷
+ def publish_exercise
+ @is_teacher = User.current.allowed_to?(:as_teacher,@course)
+ @index = params[:index]
+ @exercise.exercise_status = 2
+ @exercise.publish_time = Time.now
+ if @exercise.save
+ @exercise.course.members.each do |m|
+ @exercise.course_messages << CourseMessage.create(:user_id =>m.user_id, :course_id => @exercise.course.id, :viewed => false,:status=>2)
+ end
+ #redirect_to exercise_index_url(:course_id=> @course.id)
+ respond_to do |format|
+ format.js
+ end
+ end
+ end
+
+ # 重新发布试卷
+ # 重新发布的时候会删除所有的答题
+ def republish_exercise
+ @is_teacher = User.current.allowed_to?(:as_teacher,@course)
+ @index = params[:index]
+ @exercise.exercise_questions.each do |exercise_question|
+ exercise_question.exercise_answers.destroy_all
+ end
+ @exercise.course_messages.destroy_all
+ @exercise.exercise_users.destroy_all
+ @exercise.exercise_status = 1
+ @exercise.publish_time = nil
+ @exercise.save
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def student_exercise_list
+=begin
+ if @exercise.end_time <= Time.now
+ @course.student.each do |student|
+ if ExerciseUser.where("user_id = ? && exercise_id = ?",student.student_id,@exercise.id).empty?
+ ExerciseUser.create(:user_id => student.student_id, :exercise_id => @exercise.id, :start_at => @exercise.end_time, :status => true,:score=>0)
+ end
+
+ s_score = calculate_student_score(@exercise, student.student)
+ exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", student.student_id, @exercise.id).first
+ exercise_user.update_attributes(:score => s_score)
+ end
+ end
+=end
+ @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
+ @all_exercises = @course.exercises.where("exercise_status > 1").order("created_at desc")
+ @exercise_count = @exercise.exercise_users.where('score is not NULL').count
+ if @is_teacher || (!@exercise.exercise_users.where(:user_id => User.current.id).empty? && @exercise.end_time <= Time.now)
+ @exercise_users_list = @exercise.exercise_users.where('score is not NULL')
+ @show_all = true;
+ elsif !@exercise.exercise_users.where(:user_id => User.current.id).empty? && @exercise.end_time > Time.now
+ @exercise_users_list = @exercise.exercise_users.where("user_id = ? and score is not NULL",User.current.id)
+ else
+ @exercise_users_list = []
+ end
+ respond_to do |format|
+ format.html
+ format.xls {
+ filename = "#{@course.teacher.lastname.to_s + @course.teacher.firstname}_#{@course.name}_#{@course.time.to_s + @course.term}_#{@exercise.exercise_name}#{l(:excel_exercise_list)}.xls"
+ send_data(exercise_to_xls(@exercise_users_list), :type => "text/excel;charset=utf-8; header=present",
+ :filename => filename_for_content_disposition(filename))
+ }
+ end
+ end
+
+ # 学生提交答卷,选中答案的过程中提交
+ def commit_answer
+ eq = ExerciseQuestion.find(params[:exercise_question_id])
+ # 已提交过的且是限时的则不允许答题
+ if (has_commit_exercise?(@exercise.id,User.current.id) && (!User.current.admin?) && @exercise.time != -1) || @exercise.end_time < Time.now
+ render :json => {:text => "failure"}
+ return
+ end
+ if eq.question_type == 1
+ # 单选题
+ ea = ExerciseAnswer.find_by_exercise_question_id_and_user_id(params[:exercise_question_id],User.current.id)
+ if ea.nil?
+ # 尚未答该题,添加答案
+ ea = ExerciseAnswer.new
+ ea.user_id = User.current.id
+ ea.exercise_question_id = params[:exercise_question_id]
+ end
+ #修改该题对应答案
+ ea.exercise_choice_id = params[:exercise_choice_id]
+ if ea.save
+ # 保存成功返回成功信息及当前以答题百分比
+ uncomplete_question = get_uncomplete_question(@exercise, User.current)
+ if uncomplete_question.count < 1
+ complete = 1;
+ else
+ complete = 0;
+ end
+ @percent = get_percent(@exercise,User.current)
+ render :json => {:text => "ok" ,:complete => complete,:percent => format("%.2f" ,@percent)}
+ else
+ #返回失败信息
+ render :json => {:text => "failure"}
+ end
+ elsif eq.question_type == 2
+ #多选题
+ ea = ExerciseAnswer.find_by_exercise_choice_id_and_user_id(params[:exercise_choice_id],User.current.id)
+ if ea.nil?
+ #尚未答该题,添加答案
+ ea = ExerciseAnswer.new
+ ea.user_id = User.current.id
+ ea.exercise_question_id = params[:exercise_question_id]
+ ea.exercise_choice_id = params[:exercise_choice_id]
+ if ea.save
+ uncomplete_question = get_uncomplete_question(@exercise, User.current)
+ if uncomplete_question.count < 1
+ complete = 1;
+ else
+ complete = 0;
+ end
+ @percent = get_percent(@exercise,User.current)
+ render :json => {:text => "ok",:complete => complete,:percent => format("%.2f" ,@percent)}
+ else
+ render :json => {:text => "failure"}
+ end
+ else
+ #pv不为空,则当前选项之前已被选择,再次点击则是不再选择该项,故删除该答案
+ if ea.delete
+ @percent = get_percent(@exercise, User.current)
+ render :json => {:text => "false" ,:percent => format("%.2f" , @percent)}
+ else
+ render :json => {:text => "failure"}
+ end
+ end
+ elsif eq.question_type == 3
+ #单行文本,多行文本题
+ ea = ExerciseAnswer.find_by_exercise_question_id_and_user_id(params[:exercise_question_id], User.current.id)
+ if ea.nil?
+ # ea为空之前尚未答题,添加答案
+ if params[:answer_text].nil? || params[:answer_text].blank?
+ #用户提交空答案,视作不作答
+ @percent = get_percent(@exercise,User.current)
+ render :json => {:text => "",:percent => format("%.2f", @percent)}
+ else
+ #添加答案
+ ea = ExerciseAnswer.new
+ ea.user_id = User.current.id
+ ea.exercise_question_id = params[:exercise_question_id]
+ ea.answer_text = params[:answer_text]
+ if ea.save
+ uncomplete_question = get_uncomplete_question(@exercise, User.current)
+ if uncomplete_question.count < 1
+ complete = 1;
+ else
+ complete = 0;
+ end
+ @percent = get_percent(@exercise,User.current)
+ render :json => {:text => ea.answer_text,:complete => complete,:percent => format("%.2f",@percent)}
+ else
+ render :json => {:text => "failure"}
+ end
+ end
+ else
+ # ea不为空说明用户之前已作答
+ if params[:answer_text].nil? || params[:answer_text].blank?
+ # 用户提交空答案,视为删除答案
+ if ea.delete
+ @percent = get_percent(@exercise,User.current)
+ render :json => {:text => "",:percent => format("%.2f", @percent)}
+ else
+ render :json => {:text => "failure"}
+ end
+ else
+ #用户修改答案
+ ea.answer_text = params[:answer_text]
+ if ea.save
+ @percent = get_percent(@exercise,User.current)
+ render :json => {:text => ea.answer_text,:percent => format("%.2f", @percent)}
+ else
+ render :json => {:text => "failure"}
+ end
+ end
+ end
+
+ else
+ render :json => {:text => "failure"}
+ end
+ end
+
+ # 提交问卷
+ def commit_exercise
+ # 老师不需要提交
+ if User.current.allowed_to?(:as_teacher,@course)
+ if @exercise.publish_time.nil?
+ @exercise.update_attributes(:show_result => params[:show_result])
+ @exercise.update_attributes(:exercise_status => 2)
+ @exercise.update_attributes(:publish_time => Time.now)
+ course = @exercise.course
+ course.members.each do |m|
+ @exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2)
+ end
+ redirect_to exercise_url(@exercise)
+ return
+ elsif @exercise.publish_time > Time.now
+ @exercise.update_attributes(:show_result => params[:show_result])
+ redirect_to exercise_url(@exercise)
+ return
+ end
+ @exercise.update_attributes(:show_result => params[:show_result])
+ redirect_to exercise_url(@exercise)
+ # REDO: 提示提交成功
+ else
+ # 更新提交状态
+ cur_exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", User.current, @exercise.id).first
+ cur_exercise_user.update_attributes(:status => 1)
+ # 答题过程中需要统计完成量
+ @uncomplete_question = get_uncomplete_question(@exercise, User.current)
+ # 获取改学生的考试得分
+ @score = calculate_student_score(@exercise, User.current)
+ # @score = 100
+ if @uncomplete_question.count < 1
+ # 查看是否有已提交记录
+ cur_exercise_user.score = @score
+ if cur_exercise_user.save
+ #redirect_to poll_index_path(:polls_group_id => @course.id,:polls_type => 'Course')
+ @status = 0 #提交成功
+ else
+ @status = 2 #未知错误
+ end
+ else
+ @status = 1 #有未做得必答题
+ end
+ @save = params[:save].to_i if params[:save]
+ respond_to do |format|
+ format.js
+ end
+ end
+ end
+
+ #查看学生的答卷情况
+ def show_student_result
+ @user = User.find params[:user_id]
+ @can_edit_excercise = false
+ @exercise_questions = @exercise.exercise_questions
+ score = calculate_student_score(@exercise, @user)
+ eu = get_exercise_user(@exercise.id, @user.id)
+ eu.update_attributes(:score => score)
+ @exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", @user.id, @exercise.id).first
+ respond_to do |format|
+ format.html {render :layout => 'base_courses'}
+ end
+ end
+
+ # 计算学生得分
+ def calculate_student_score(exercise, user)
+ score = 0
+ score1 = 0
+ score2 = 0
+ score3 = 0
+ exercise_qustions = exercise.exercise_questions
+ exercise_qustions.each do |question|
+ answer = get_user_answer(question, user)
+ standard_answer = get_user_standard_answer(question, user)
+ unless answer.empty?
+ # 问答题有多个答案
+ if question.question_type == 3 && !standard_answer.empty?
+ if standard_answer.include?(answer.first.answer_text)
+ score1 = score1+ question.question_score unless question.question_score.nil?
+ end
+ elsif question.question_type == 1 && !standard_answer.nil?
+ if answer.first.exercise_choice.choice_position == standard_answer.exercise_choice_id
+ score2 = score2 + question.question_score unless question.question_score.nil?
+ end
+ elsif question.question_type == 2 && !standard_answer.nil?
+ arr = get_mulscore(question, user)
+ if arr.to_i == standard_answer.exercise_choice_id
+ score3 = score3 + question.question_score unless question.question_score.nil?
+ end
+ # ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id)
+ # arr = []
+ # ecs.each do |ec|
+ # arr << ec.exercise_choice.choice_position
+ # end
+ # arr.sort
+ # arr = arr.join("")
+ # if arr.to_i == standard_answer.exercise_choice_id
+ # score3 = score + question.question_score unless question.question_score.nil?
+ # end
+ end
+ end
+ end
+ score = score1 + score2 + score3
+ end
+
+ private
+ #测验列表转换为excel
+ def exercise_to_xls items
+ xls_report = StringIO.new
+ book = Spreadsheet::Workbook.new
+ sheet1 = book.create_worksheet :name => "exercise"
+ blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
+ sheet1.row(0).default_format = blue
+ sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_class),l(:excel_f_score),l(:excel_commit_time)])
+ count_row = 1
+ items.each do |exercise|
+ sheet1[count_row,0]=exercise.user.id
+ sheet1[count_row,1] = exercise.user.lastname.to_s + exercise.user.firstname.to_s
+ sheet1[count_row,2] = exercise.user.login
+ sheet1[count_row,3] = exercise.user.user_extensions.student_id
+ sheet1[count_row,4] = exercise.user.mail
+ sheet1[count_row,5] = ""
+ sheet1[count_row,6] = exercise.score
+ sheet1[count_row,7] = format_time(exercise.created_at)
+ count_row += 1
+ end
+ book.write xls_report
+ xls_report.string
+ end
+
+ # ExerciseUser记录用户是否已提交问卷有对应的记录则已提交,没有则新建一个
+ def get_exercise_user exercise_id,user_id
+ eu = ExerciseUser.find_by_exercise_id_and_user_id(exercise_id,user_id)
+ if eu.nil?
+ eu = ExerciseUser.new
+ end
+ eu
+ end
+
+ # 获取当前学生回答问题的答案
+ def get_user_answer(question,user)
+ # user_answer = ExerciseAnswer.where("user_id=? and exercise_question_id=?", user.id, question.id).first
+ user_answer = question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id}")
+ user_answer
+ end
+
+ # 获取问题的标准答案
+ def get_user_standard_answer(question,user)
+ if question.question_type == 3
+ standard_answer =[]
+ question.exercise_standard_answers.each do |answer|
+ standard_answer << answer.answer_text
+ end
+ else
+ standard_answer = question.exercise_standard_answers.first
+ end
+ standard_answer
+ end
+ # 是否完成了答题
+ def get_complete_question(exercise,user)
+ questions = exercise.exercise_questions
+ complete_question = []
+ questions.each do |question|
+ answers = get_user_answer(question,user)
+ if !(answers.nil? || answers.count < 1)
+ complete_question << question
+ end
+ end
+ complete_question
+ end
+
+ # 获取答题百分比
+ def get_percent exercise,user
+ complete_count = get_complete_question(exercise,user).count
+ if exercise.exercise_questions.count == 0
+ return 0
+ else
+ return (complete_count.to_f / exercise.exercise_questions.count.to_f)*100
+ end
+ end
+
+ def remove_invalid_exercise(course)
+ exercises = course.exercises.where("exercise_name=?","")
+ unless exercises.empty?
+ exercises.each do |exercise|
+ if exercise.exercise_questions.empty?
+ exercise.destroy
+ end
+ end
+ end
+ end
+
+ def find_exercise_and_course
+ @exercise = Exercise.find params[:id]
+ @course = Course.find @exercise.course_id
+ rescue Exception => e
+ render_404
+ end
+
+ def find_course
+ @course = Course.find params[:course_id]
+ rescue Exception => e
+ render_404
+ end
end
\ No newline at end of file
diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb
index 121cd3a42..70a0b76b8 100644
--- a/app/controllers/files_controller.rb
+++ b/app/controllers/files_controller.rb
@@ -24,7 +24,10 @@ class FilesController < ApplicationController
before_filter :auth_login1, :only => [:index]
before_filter :logged_user_by_apptoken,:only => [:index]
before_filter :find_project_by_project_id#, :except => [:getattachtype]
- before_filter :authorize, :except => [:create,:getattachtype,:quote_resource_show,:search,:searchone4reload,:search_project,:quote_resource_show_project,:search_tag_attachment,:subfield_upload_file,:search_org_subfield_tag_attachment,:search_tag_attachment,:quote_resource_show_org_subfield,:find_org_subfield_attache,:search_files_in_subfield]
+ before_filter :authorize, :except => [:create,:getattachtype,:quote_resource_show,:search,:searchone4reload,:search_project,:quote_resource_show_project,
+ :search_tag_attachment,:subfield_upload_file,:search_org_subfield_tag_attachment,
+ :search_tag_attachment,:quote_resource_show_org_subfield,:find_org_subfield_attache,
+ :search_files_in_subfield,:upload_files_menu]
helper :sort
include SortHelper
@@ -99,6 +102,7 @@ class FilesController < ApplicationController
@sort = ""
@order = ""
@is_remote = true
+ @q = params[:name].strip
if params[:sort]
order_by = params[:sort].split(":")
@sort = order_by[0]
@@ -107,24 +111,25 @@ class FilesController < ApplicationController
end
sort = "#{@sort} #{@order}"
end
+ # show_attachments [@course]
begin
q = "%#{params[:name].strip}%"
#(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
if params[:insite]
if q == "%%"
- @result = []
- @searched_attach = paginateHelper @result,10
+ @project_attachment_result = []
+ @searched_attach = paginateHelper @project_attachment_result, 10
else
- @result = find_public_attache q,sort
- @result = visable_attachemnts_insite @result,@project
- @searched_attach = paginateHelper @result,10
+ @project_attachment_result = find_public_attache q,sort
+ @project_attachment_result = visable_attachemnts_insite @project_attachment_result, @project
+ @searched_attach = paginateHelper @project_attachment_result, 10
end
else
- @result = find_project_attache q,@project,sort
- @result = visable_attachemnts @result
- @searched_attach = paginateHelper @result,10
+ @project_attachment_result = find_project_attache q, @project,sort
+ @project_attachment_result = visable_attachemnts @project_attachment_result
+ @searched_attach = paginateHelper @project_attachment_result,10
+ @tag_list = get_project_tag_list @project
end
-
#rescue Exception => e
# #render 'stores'
# redirect_to search_course_files_url
@@ -200,23 +205,10 @@ class FilesController < ApplicationController
if sort == ""
sort = "created_on DESC"
end
- ids = ""
- len = 0
- count = project.versions.count
- project.versions.each do |version|
- len = len + 1
- if len != count
- ids += version.id.to_s + ','
- else
- ids += version.id.to_s
- end
- end
- if ids.blank?
- resultSet = Attachment.where("attachments.container_type = 'Project' And attachments.container_id = '#{project.id}' AND filename LIKE :like ", like: "%#{keywords}%").
- reorder(sort)
+ if keywords != "%%"
+ resultSet = Attachment.where("attachments.container_type = 'Project' And attachments.container_id = '#{project.id}' AND filename LIKE :like ", like: "%#{keywords}%").reorder(sort)
else
- resultSet = Attachment.where("((attachments.container_type = 'Project' And attachments.container_id = '#{project.id}') OR (container_type = 'Version' AND container_id IN (#{ids}))) AND filename LIKE :like ", like: "%#{keywords}%").
- reorder(sort)
+ resultSet = Attachment.where("attachments.container_type = 'Project' And attachments.container_id = '#{project.id}' "). reorder(sort)
end
end
@@ -238,12 +230,11 @@ class FilesController < ApplicationController
@order = ""
@is_remote = false
if params[:project_id]
+ @page = params[:page] ? params[:page].to_i + 1 : 2
@container_type = 0
-
if params[:sort]
params[:sort].split(",").each do |sort_type|
order_by = sort_type.split(":")
-
case order_by[0]
when "filename"
attribute = "filename"
@@ -281,25 +272,19 @@ class FilesController < ApplicationController
else
sort = "#{Attachment.table_name}.created_on desc"
end
+ # @containers = [ Project.includes(:attachments).find(@project.id)]
+ # @containers += @project.versions.includes(:attachments).all
- @containers = [ Project.includes(:attachments).find(@project.id)]
- @containers += @project.versions.includes(:attachments).all
-
- ids = []
- @containers.each do |c|
- ids += c.attachments.pluck(:id)
- end
- @containers = [Struct.new(:attachments).new(Attachment.where('id in (?)',ids).reorder(sort))]
+ @containers = [ Project.includes(:attachments).reorder(sort).find(@project.id)]
show_attachments @containers
- respond_to do |format|
- format.html
- format.js
- end
+ @tag_list = attachment_tag_list @all_attachments
+
+ render :layout => 'base_projects'
elsif params[:course_id]
@container_type = 1
-
+ @page = params[:page] ? params[:page].to_i + 1 : 2
if params[:sort]
params[:sort].split(",").each do |sort_type|
order_by = sort_type.split(":")
@@ -440,16 +425,35 @@ class FilesController < ApplicationController
if @project
@addTag=false
if params[:in_project_toolbar]
- @in_project_toolbar = params[:in_project_toolbar]
+ @in_project_toolbar = params[:in_project_toolbar]
end
- container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
- attachments = Attachment.attach_filesex(container, params[:attachments], params[:attachment_type])
- render_attachment_warning_if_needed(container)
-
+ # 发送邮件
+ attachments = Attachment.attach_filesex(@project, params[:attachments], params[:attachment_type])
if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
Mailer.run.attachments_added(attachments[:files])
end
-
+ # end
+ if params[:project_attachment_type] && params[:project_attachment_type].is_a?(Array)
+ params[:project_attachment_type].each do |type|
+ tag_name = get_project_tag_name_by_type_nmuber type
+ if !attachments.empty? && attachments[:files] && tag_name != ""
+ attachments[:files].each do |attachment|
+ attachment.tag_list.add(tag_name)
+ attachment.save
+ end
+ end
+ end
+ else
+ if params[:project_attachment_type] && params[:project_attachment_type] != "6"
+ tag_name = get_project_tag_name_by_type_nmuber params[:project_attachment_type]
+ if !attachments.empty? && attachments[:files] && tag_name != ""
+ attachments[:files].each do |attachment|
+ attachment.tag_list.add(tag_name)
+ attachment.save
+ end
+ end
+ end
+ end
# TODO: 临时用 nyan
sort_init 'created_on', 'desc'
sort_update 'created_on' => "#{Attachment.table_name}.created_on",
@@ -457,14 +461,11 @@ class FilesController < ApplicationController
'size' => "#{Attachment.table_name}.filesize",
'downloads' => "#{Attachment.table_name}.downloads"
- @containers = [Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] #modify by Long Jun
- @containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
-
+ @containers = [Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)]
show_attachments @containers
-
+ @tag_list = attachment_tag_list @all_attachments
@attachtype = 0
@contenttype = 0
-
respond_to do |format|
format.js
format.html {
@@ -592,6 +593,25 @@ class FilesController < ApplicationController
end
end
+ def get_project_tag_name_by_type_nmuber type
+ case type
+ when "1"
+ tag_name = "软件版本"
+ when "2"
+ tag_name = "文档"
+ when "3"
+ tag_name = "代码"
+ when "4"
+ tag_name = "媒体"
+ when "5"
+ tag_name = "论文"
+ when "6"
+ tag_name = "其它"
+ else
+ tag_name = ""
+ end
+ end
+
def get_tag_name_by_type_number type
case type
when "1"
@@ -743,12 +763,33 @@ class FilesController < ApplicationController
end
q = "%#{@q.strip}%"
- @result = find_course_attache q,@course,sort
+ if @project
+ @result = find_project_attache q, @project,sort
+ else
+ @result = find_course_attache q,@course,sort
+ end
@result = visable_attachemnts @result
- @result = @result.select{|attachment| attachment.tag_list.include?(@tag_name)} unless @tag_name.blank?
+ if params[:other]
+ if @project
+ @result = @result.select{|attachment| !attachment.tag_list.include?('软件版本') && !attachment.tag_list.include?('文档') && !attachment.tag_list.include?('代码') && !attachment.tag_list.include?('媒体') && !attachment.tag_list.include?('论文') }
+ else
+ @result = @result.select{|attachment|
+ !attachment.tag_list.include?('课件') &&
+ !attachment.tag_list.include?('软件') &&
+ !attachment.tag_list.include?('媒体') &&
+ !attachment.tag_list.include?('代码') &&
+ !attachment.tag_list.include?('论文') }
+ end
+ else
+ @result = @result.select{|attachment| attachment.tag_list.include?(@tag_name)} unless @tag_name.blank?
+ end
@searched_attach = paginateHelper @result,10
- @tag_list = get_course_tag_list @course
-
+ if @project
+ @tag_list = get_project_tag_list @project
+ @result_search_project = @result
+ else
+ @tag_list = get_course_tag_list @course
+ end
respond_to do |format|
format.js
# format.html
@@ -784,4 +825,8 @@ class FilesController < ApplicationController
def subfield_upload_file
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
end
+
+ def upload_files_menu
+
+ end
end
diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb
index 46362c2d3..d345fba5f 100644
--- a/app/controllers/homework_common_controller.rb
+++ b/app/controllers/homework_common_controller.rb
@@ -63,7 +63,7 @@ class HomeworkCommonController < ApplicationController
end
@homework.end_time = params[:homework_common][:end_time] || Time.now
@homework.course_id = params[:course_id]
- @homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment] : 1
+ @homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment] : 0
homework_detail_manual = @homework.homework_detail_manual || HomeworkDetailManual.new
if @homework.publish_time <= Date.today && homework_detail_manual.comment_status == 0
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb
index 9b81ac775..8fc13c83c 100644
--- a/app/controllers/issues_controller.rb
+++ b/app/controllers/issues_controller.rb
@@ -81,10 +81,11 @@ class IssuesController < ApplicationController
@status_id = params[:status_id]
@subject = params[:subject]
@issue_count = @query.issue_count
- @issue_pages = Paginator.new @issue_count, @limit, params['page'].to_i + 1
+ @issue_pages = Paginator.new @issue_count, @limit, params['page']
+ params[:page] = (params[:page] || 1).to_i + 1 #页码需要加1
@offset ||= @issue_pages.offset
@issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
- :order => sort_clause,
+ :order => 'issues.updated_on desc',
:offset => @offset,
:limit => @limit)
if params[:set_filter]
@@ -136,6 +137,7 @@ class IssuesController < ApplicationController
end
end
# end
+ @jour_reply = Journal.new
@journals = @issue.journals.includes(:user, :details).reorder("#{Journal.table_name}.id ASC").all
@journals.each_with_index {|j,i| j.indice = i+1}
@journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
@@ -152,6 +154,7 @@ class IssuesController < ApplicationController
@project_base_tag = (params[:project_id] || @issue.project) ? 'base_projects':'base'#by young
@available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq
+ @journal = Journal.new(:journalized => @issue)
respond_to do |format|
format.html {
@@ -400,14 +403,16 @@ class IssuesController < ApplicationController
jour.user_id = User.current.id
jour.notes = params[:notes]
jour.journalized = @issue
+ jour.save_attachments(params[:attachments])
jour.save
- user_activity = UserActivity.where("act_type='Issue' and act_id =#{@issue.id}").first
- user_activity.updated_at = jour.created_on
- user_activity.save
+ update_user_activity(@issue.class,@issue.id)
+ update_forge_activity(@issue.class,@issue.id)
+
@user_activity_id = params[:user_activity_id]
if params[:issue_id]
@issue_id = params[:issue_id]
end
+ @priorities = IssuePriority.active
respond_to do |format|
format.js
end
@@ -450,9 +455,9 @@ class IssuesController < ApplicationController
@issue = Issue.find params[:id]
jour.journalized = @issue
jour.save
- user_activity = UserActivity.where("act_type='Issue' and act_id =#{@issue.id}").first
- user_activity.updated_at = jour.created_on
- user_activity.save
+ update_user_activity(@issue.class,@issue.id)
+ update_forge_activity(@issue.class,@issue.id)
+
respond_to do |format|
format.js
end
diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb
index 6f173b7c2..17111b3f3 100644
--- a/app/controllers/messages_controller.rb
+++ b/app/controllers/messages_controller.rb
@@ -22,8 +22,8 @@ class MessagesController < ApplicationController
default_search_scope :messages
before_filter :find_board, :only => [:new, :preview,:edit]
before_filter :find_attachments, :only => [:preview]
- before_filter :find_message, :except => [:new, :preview]
- before_filter :authorize, :except => [:preview, :edit, :destroy, :new]
+ before_filter :find_message, :except => [:new, :preview, :join_org_subfield, :get_subfield_on_click_org, :join_org_subfields]
+ before_filter :authorize, :except => [:preview, :edit, :destroy, :new,:join_org_subfield, :get_subfield_on_click_org, :join_org_subfields]
helper :boards
helper :watchers
@@ -75,7 +75,7 @@ class MessagesController < ApplicationController
@replies = paginateHelper messages_replies,10
@reply = Message.new(:subject => "RE: #{@message.subject}")
render :action => "show", :layout => "base_courses"#by young
- else
+ elsif @project
@reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page
@replies = @topic.children.
includes(:author, :attachments, {:board => :project}).
@@ -86,6 +86,18 @@ class MessagesController < ApplicationController
@reply = Message.new(:subject => "RE: #{@message.subject}")
render :action => "show", :layout => "base_projects"#by young
+ else
+ @reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page
+ @replies = @topic.children.
+ includes(:author, :attachments, {:board => :project}).
+ reorder("#{Message.table_name}.created_on DESC").
+ limit(@reply_pages.per_page).
+ offset(@reply_pages.offset).
+ all
+
+ @reply = Message.new(:subject => "RE: #{@message.subject}")
+ @organization = @org_subfield.organization
+ render :action => "show", :layout => "base_org"#by young
end
end
@@ -164,26 +176,11 @@ class MessagesController < ApplicationController
@reply.subject = "RE: #{@topic.subject}" unless params[:reply][:subject]
# @reply.reply_id = params[:id]
@topic.children << @reply
- course_activity = CourseActivity.where("course_act_type='Message' and course_act_id =#{@topic.id}").first
- if course_activity
- course_activity.updated_at = Time.now
- course_activity.save
- end
- forge_activity = ForgeActivity.where("forge_act_type='Message' and forge_act_id=#{@topic.id}").first
- if forge_activity
- forge_activity.updated_at = Time.now
- forge_activity.save
- end
- user_activity = UserActivity.where("act_type='Message' and act_id =#{@topic.id}").first
- if user_activity
- user_activity.updated_at = Time.now
- user_activity.save
- end
- org_activity = OrgActivity.where("org_act_type='Message' and org_act_id =#{@topic.id}").first
- if org_activity
- org_activity.updated_at = Time.now
- org_activity.save
- end
+ update_course_activity(@topic.class,@topic.id)
+ update_user_activity(@topic.class,@topic.id)
+ update_forge_activity(@topic.class,@topic.id)
+ update_org_activity(@topic.class,@topic.id)
+
#@topic.update_attribute(:updated_on, Time.now)
if !@reply.new_record?
if params[:asset_id]
@@ -199,6 +196,8 @@ class MessagesController < ApplicationController
end
if params[:user_activity_id]
@user_activity_id = params[:user_activity_id]
+ @is_course = params[:is_course]
+ @is_board = params[:is_board]
respond_to do |format|
format.js
end
@@ -219,39 +218,52 @@ class MessagesController < ApplicationController
@isReply = false
if @project
(render_403; return false) unless @message.editable_by?(User.current)
- else
+ elsif @course
(render_403; return false) unless @message.course_editable_by?(User.current)
+ else
+ (render_403; return false) unless @message.org_subfield_editable_by?(User.current)
end
@message.safe_attributes = params[:message]
if request.post? && @message.save
attachments = Attachment.attach_files(@message, params[:attachments])
render_attachment_warning_if_needed(@message)
- flash[:notice] = l(:notice_successful_update)
+ #flash[:notice] = l(:notice_successful_update)
@message.reload
- if params[:is_board]
+ if params[:is_course] && params[:is_course].to_i == 0
+ redirect_to user_activities_path(User.current.id)
+ elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 0
if @project
- redirect_to project_boards_path(@project)
+ redirect_to project_path(@project)
elsif @course
- redirect_to course_boards_path(@course)
+ redirect_to course_activity_path(@course)
end
- else
- redirect_to board_message_url(@message.board, @message.root, :r => (@message.parent_id && @message.id))
- end
- elsif request.get? || request.post?
- if params[:is_board]
+ elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 1
if @project
redirect_to project_boards_path(@project)
elsif @course
redirect_to course_boards_path(@course)
end
else
- respond_to do |format|
- format.html {
- layout_file = @project ? 'base_projects' : 'base_courses'
- render :layout => layout_file
- }
- end
+ redirect_to board_message_url(@message.board, @message.root, :r => (@message.parent_id && @message.id))
+ end
+ elsif request.get? || request.post?
+ if params[:is_course] && params[:is_board]
+ @is_course = params[:is_course]
+ @is_board = params[:is_board]
+ end
+ respond_to do |format|
+ format.html {
+ if @project
+ layout_file = 'base_projects'
+ elsif @course
+ layout_file = 'base_courses'
+ elsif @org_subfield
+ @organization = @org_subfield.organization
+ layout_file = 'base_org'
+ end
+ render :layout => layout_file
+ }
end
end
end
@@ -260,26 +272,46 @@ class MessagesController < ApplicationController
def destroy
if @project
(render_403; return false) unless @message.destroyable_by?(User.current)
- else
+ elsif @course
(render_403; return false) unless @message.course_destroyable_by?(User.current)
+ else
+ (render_403; return false) unless @message.org_subfield_editable_by?(User.current)
end
r = @message.to_param
@message.destroy
# modify by nwb
if @project
- if params[:is_board]
- redirect_to project_boards_url(@project)
+ if params[:is_course] && params[:is_course].to_i == 0
+ redirect_to user_activities_path(User.current.id)
+ elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 0
+ redirect_to project_path(@project)
+ elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 1
+ redirect_to project_boards_path(@project)
+ elsif @message.parent
+ redirect_to board_message_url(@board, @message.parent, :r => r)
else
- redirect_to board_message_url(@board, @topic, :r => @reply)
+ redirect_to project_board_url(@project, @board)
end
elsif @course
+ if params[:is_course] && params[:is_course].to_i == 0
+ redirect_to user_activities_path(User.current.id)
+ elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 0
+ redirect_to course_activity_path(@course)
+ elsif params[:is_course] && params[:is_course].to_i == 1 && params[:is_board] && params[:is_board].to_i == 1
+ redirect_to course_boards_path(@course)
+ elsif @message.parent
+ redirect_to board_message_url(@board, @message.parent, :r => r)
+ else
+ redirect_to course_boards_path(@course)
+ end
+ elsif @org_subfield
if params[:is_board]
- redirect_to course_boards_url(@course)
+ redirect_to organization_path(:id => @org_subfield.organization_id, :org_subfield_id => @org_subfield.id)
else
if @message.parent
redirect_to board_message_url(@board, @message.parent, :r => r)
else
- redirect_to course_board_url(@course, @board)
+ redirect_to organization_path(:id => @org_subfield.organization_id, :org_subfield_id => @org_subfield.id)
end
end
end
@@ -301,6 +333,41 @@ class MessagesController < ApplicationController
render :partial => 'common/preview'
end
+ def join_org_subfield
+ @message = Message.find(params[:message_id])
+ @organizations = User.current.organizations
+ end
+
+ def get_subfield_on_click_org
+ @org = Organization.find(params[:organization_id])
+ end
+
+ def join_org_subfields
+ org_subfield_ids = params[:org_subfields]
+ @message = Message.find(params[:id])
+ # @message.update_attribute(:updated_on, Time.now)
+ # type = @message.board.course_id.nil? ? "Project":"Course"
+ org_subfield_ids.each do |field_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,
+ :created_on => Time.now, :updated_on => Time.now, :locked => @message.locked, :sticky => @message.sticky)
+ @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
+ # OrgSubfieldMessage.create(:org_subfield_id => field_id.to_i, :message_id => mes.id, :message_type => type)
+ # org_acts = OrgActivity.where("container_type='OrgSubfield' and container_id=? and org_act_type='Message' and org_act_id=?", field_id.to_i, @message.id)
+ # if org_acts.all.size() > 0
+ # org_acts.first.update_attribute(:updated_at, Time.now)
+ # else
+ 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
+ end
+
private
def find_message
return unless find_board
@@ -317,6 +384,9 @@ class MessagesController < ApplicationController
@project = @board.project
elsif @board.course_id
@course = @board.course
+ else
+ @org_subfield = @board.org_subfield
+ @organization = @org_subfield
end
rescue ActiveRecord::RecordNotFound
diff --git a/app/controllers/org_document_comments_controller.rb b/app/controllers/org_document_comments_controller.rb
index b8584fea3..7685b77a8 100644
--- a/app/controllers/org_document_comments_controller.rb
+++ b/app/controllers/org_document_comments_controller.rb
@@ -1,16 +1,18 @@
class OrgDocumentCommentsController < ApplicationController
before_filter :find_organization, :only => [:new, :create, :show, :index]
-
+ helper :attachments
layout 'base_org'
def new
@org_document_comment = OrgDocumentComment.new
end
+
def create
@org_document_comment = OrgDocumentComment.new(:organization_id => @organization.id, :creator_id => User.current.id)
@org_document_comment.title = params[:org_document_comment][:title]
@org_document_comment.content = params[:org_document_comment][:content]
+ @org_document_comment.save_attachments(params[:attachments])
if params[:field_id]
@org_document_comment.org_subfield_id = params[:field_id].to_i
end
@@ -26,6 +28,7 @@ class OrgDocumentCommentsController < ApplicationController
redirect_to new_org_document_comment_path(:organization_id => @organization.id)
end
end
+
def show
@document = OrgDocumentComment.find(params[:id])
end
@@ -37,9 +40,12 @@ class OrgDocumentCommentsController < ApplicationController
render_403
end
end
+
def update
@org_document = OrgDocumentComment.find(params[:id])
@org_document.update_attributes(:title => params[:org_document_comment][:title], :content => params[:org_document_comment][:content])
+ Attachment.attach_files(@org_document, params[:attachments])
+ # @org_document.save_attachments(params[:attachments])
if @org_document.parent.nil?
act = OrgActivity.where("org_act_type='OrgDocumentComment' and org_act_id =?", @org_document.id).first
act.update_attributes(:updated_at => @org_document.updated_at)
diff --git a/app/controllers/org_subfields_controller.rb b/app/controllers/org_subfields_controller.rb
index 1dc7885fe..66a236b5b 100644
--- a/app/controllers/org_subfields_controller.rb
+++ b/app/controllers/org_subfields_controller.rb
@@ -1,24 +1,32 @@
-class OrgSubfieldsController < ApplicationController
- def create
- @subfield = OrgSubfield.create(:name => params[:name])
- @organization = Organization.find(params[:organization_id])
- @organization.org_subfields << @subfield
- @subfield.update_attributes(:priority => @subfield.id, :field_type => params[:field_type])
- end
-
- def destroy
- @subfield = OrgSubfield.find(params[:id])
- @organization = Organization.find(@subfield.organization_id)
- @subfield.destroy
- end
-
- def update
- @subfield = OrgSubfield.find(params[:id])
- @organization = Organization.find(@subfield.organization_id)
- @subfield.update_attributes(:name => params[:name])
- end
-
- def show
-
- end
-end
+class OrgSubfieldsController < ApplicationController
+ def create
+ @subfield = OrgSubfield.create(:name => params[:name])
+ @organization = Organization.find(params[:organization_id])
+ @organization.org_subfields << @subfield
+ @subfield.update_attributes(:priority => @subfield.id, :field_type => params[:field_type])
+ end
+
+ def show
+ @org_subfield = OrgSubfield.find(params[:id])
+ @organization = @org_subfield.organization.id
+ @messages = []
+ @messages << @org_subfield.org_document_comments
+ @messages << @org_subfield.messages
+ @messages.sort{|a, b| b.updated_at <=> a.updated_at}
+ respond_to do |format|
+ format.html{render :layout => 'base_org'}
+ end
+ end
+ def destroy
+ @subfield = OrgSubfield.find(params[:id])
+ @organization = Organization.find(@subfield.organization_id)
+ @subfield.destroy
+ end
+
+ def update
+ @subfield = OrgSubfield.find(params[:id])
+ @organization = Organization.find(@subfield.organization_id)
+ @subfield.update_attributes(:name => params[:name])
+ end
+
+end
diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb
index bba1587b6..9f80503d8 100644
--- a/app/controllers/organizations_controller.rb
+++ b/app/controllers/organizations_controller.rb
@@ -1,284 +1,319 @@
-# encoding: utf-8
-class OrganizationsController < ApplicationController
-
-
- helper :sort
- include SortHelper
- helper :custom_fields
- include CustomFieldsHelper
- include AvatarHelper
- include WordsHelper
- include GitlabHelper
- include UserScoreHelper
-
- include PollHelper
- helper :user_score
- helper :journals
-
- # added by liuping 关注
-
- helper :watchers
- helper :activities
-
- ### added by william
- include ActsAsTaggableOn::TagsHelper
-
- # fq
- helper :words
- helper :project_score
- helper :issues
- include UsersHelper
- before_filter :find_organization, :only => [:show, :members]
- layout 'base_org'
- def index
-
- end
- def new
- @organization = Organization.new
- render :layout => 'new_base'
- end
-
- def edit
- @organization = Organization.find(params[:id])
- end
-
- def destroy
- @organization = Organization.find(params[:id])
- @organization.destroy
- respond_to do |format|
- format.html{ redirect_to admin_organization_path }
- end
- end
-
- def create
- @organization = Organization.new
- @organization.name = params[:organization][:name]
- @organization.description = params[:organization][:description]
- @organization.is_public = params[:organization][:is_public]
- @organization.creator_id = User.current.id
- member = OrgMember.new(:user_id => User.current.id)
-
- @organization.org_members << member
- if @organization.save
- OrgMemberRole.create(:org_member_id => member.id, :role_id => 11)
- redirect_to organization_path(@organization)
- end
- end
-
- def show
- if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
- @organization = Organization.find(params[:id])
- if params[:org_subfield_id]
- @org_subfield = OrgSubfield.find(params[:org_subfield_id])
- @org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0
- @org_activities = OrgActivity.where("org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})").order('updated_at desc').page(params[:page] || 1).per(10)
- else
- project_ids = @organization.projects.map(&:id) << 0
- course_ids = @organization.courses.map(&:id) << 0
- course_types = "('Message','News','HomeworkCommon','Poll','Course')"
- case params[:type]
- when nil
- @org_activities = OrgActivity.where("(container_id =? and container_type =?) " +
- "or (container_type ='Project' and org_act_type in ('Issue','Message','ProjectCreateInfo') and container_id in (#{project_ids.join(',')})) "+
- "or (container_type ='Course' and org_act_type in #{course_types} and container_id in (#{course_ids.join(',')}))",
- @organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10)
- when 'project_issue'
- @org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Issue' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
- when 'project_message'
- @org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Message' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
- when 'org'
- @org_activities = OrgActivity.where("container_id =? and container_type =?",@organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10)
- when 'course_homework'
- @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'HomeworkCommon' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
- when 'course_news'
- @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'News' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
- when 'course_message'
- @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'Message' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
- when 'course_poll'
- @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'Poll' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
- end
- end
- @page = params[:page] || 1
- respond_to do |format|
- format.html
- format.js
- end
- else
- render_403
- end
- end
-
- def update
- @organization = Organization.find(params[:id])
- @organization.name = params[:organization][:name]
- @organization.description = params[:organization][:description]
- @organization.domain = params[:organization][:domain]
- @organization.is_public = params[:organization][:is_public] == 'on' ? 1 : 0
- #@organization.name = params[:organization][:name]
- @organization.save
- respond_to do |format|
- format.html { redirect_to setting_organization_path(@organization)}
- end
- end
-
- def check_uniq
- @check = false;
- @org_name = params[:org_name].strip
- @config_page = params[:config_page]
- sameName = @config_page ? Organization.where('name = ? and id != ?',params[:org_name],params[:org_id].to_i).count == 0 : Organization.where('name = ?',params[:org_name]).count == 0
- if sameName == true
- @check = true
- end
- respond_to do |format|
- format.js
- end
- end
-
- def find_organization
- @organization = Organization.find(params[:id])
- end
-
- def setting
- @organization = Organization.find(params[:id])
-
- if User.current.admin? || User.current.admin_of_org?(@organization)
- else
- render_403
- end
- end
-
-
- def clear_org_avatar_temp
-
- end
-
- def set_homepage
- @org = Organization.find(params[:id])
- @org.home_id = params[:home_id]
- @org.save
- # respond_to do |format|
- # format.html {redirect_to organization_path(org)}
- # end
- end
-
- def cancel_homepage
- @org = Organization.find(params[:id])
- @org.home_id = nil
- @org.save
- end
-
- def autocomplete_search
- @project = Project.find(params[:project_id])
- #@flag = params[:flag] || false
- respond_to do |format|
- format.js
- end
- end
-
- def members
- if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
- @members = OrgMember.where("organization_id =?", @organization.id)
- else
- render_403
- end
- end
-
- def more_org_projects
- @organization = Organization.find params[:id]
- @page = params[:page]
- @org_projects = @organization.projects.reorder('created_at').uniq.page((params[:page].to_i || 1) +1).per(5)
- respond_to do |format|
- format.js
- end
- end
-
- def more_org_courses
- @organization = Organization.find(params[:id])
- @page = params[:page]
- @org_courses = @organization.courses.reorder('created_at').uniq.page((params[:page].to_i || 1) + 1 ).per(5)
- respond_to do |format|
- format.js
- end
- end
-
- def join_course_menu
- @organization = Organization.find(params[:id])
- respond_to do |format|
- format.js
- end
- end
-
- def search_courses
- @organization = Organization.find(params[:id])
- condition = '%%'
- if !params[:name].nil?
- condition = "%#{params[:name].strip}%".gsub(" ","")
- end
- sql = "select courses.* from courses inner join members on courses.id = members.course_id where members.user_id = #{User.current.id} and courses.name like '#{condition}'"+
- "and courses.id not in (select distinct org_courses.course_id from org_courses where org_courses.organization_id = #{@organization.id})"
- #user_courses = Course.find_by_sql(sql)
- @courses = Course.find_by_sql(sql)
- # @added_course_ids = @organization.courses.map(&:id)
- # @courses = []
- # user_courses.each do |course|
- # if !@added_course_ids.include?(course.id)
- # @courses << course
- # end
- # end
- end
-
- def join_courses
- @organization = Organization.find(params[:id])
- course_ids = params[:courseNames]
- course_ids.each do |id|
- OrgCourse.create(:organization_id => @organization.id, :course_id => id.to_i, :created_at => Time.now)
- end
- respond_to do |format|
- format.js
- end
- end
-
- def join_project_menu
- @organization = Organization.find(params[:id])
- respond_to do |format|
- format.js
- end
- end
-
- def logout
- logout_user
- respond_to do |format|
- format.html {redirect_to organization_path(params[:id])}
- end
- end
-
- def search_projects
- @organization = Organization.find(params[:id])
- condition = '%%'
- if !params[:name].nil?
- condition = "%#{params[:name].strip}%".gsub(" ","")
- end
- sql = "select projects.* from projects inner join members on projects.id = members.project_id where members.user_id = #{User.current.id} and projects.status != 9 and projects.name like '#{condition}'" +
- " and projects.id not in (select org_projects.project_id from org_projects where organization_id = #{@organization.id})"
- #user_projects = Course.find_by_sql(sql)
- @projects = Course.find_by_sql(sql)
- # @added_course_ids = @organization.projects.map(&:id)
- # @projects = []
- # user_projects.each do |project|
- # if !@added_course_ids.include?(project.id)
- # @projects << project
- # end
- # end
- end
-
- def join_projects
- @organization = Organization.find(params[:id])
- project_ids = params[:projectNames]
- project_ids.each do |id|
- OrgProject.create(:organization_id => @organization.id, :project_id => id.to_i, :created_at => Time.now)
- end
- respond_to do |format|
- format.js
- end
- end
-end
+# encoding: utf-8
+class OrganizationsController < ApplicationController
+
+
+ helper :sort
+ include SortHelper
+ helper :custom_fields
+ include CustomFieldsHelper
+ include AvatarHelper
+ include WordsHelper
+ include GitlabHelper
+ include UserScoreHelper
+
+ include PollHelper
+ helper :user_score
+ helper :journals
+ helper :attachments
+ # added by liuping 关注
+
+ helper :watchers
+ helper :activities
+
+ ### added by william
+ include ActsAsTaggableOn::TagsHelper
+
+ # fq
+ helper :words
+ helper :project_score
+ helper :issues
+ include UsersHelper
+ before_filter :find_organization, :only => [:show, :members, :apply_subdomain]
+ layout 'base_org'
+ def index
+
+ end
+ def new
+ @organization = Organization.new
+ render :layout => 'new_base'
+ end
+
+ def edit
+ @organization = Organization.find(params[:id])
+ end
+
+ def destroy
+ @organization = Organization.find(params[:id])
+ @organization.destroy
+ respond_to do |format|
+ format.html{ redirect_to admin_organization_path }
+ end
+ end
+
+ def create
+ @organization = Organization.new
+ @organization.name = params[:organization][:name]
+ @organization.description = params[:organization][:description]
+ @organization.is_public = params[:organization][:is_public]
+ @organization.creator_id = User.current.id
+ member = OrgMember.new(:user_id => User.current.id)
+
+ @organization.org_members << member
+ if @organization.save
+ OrgMemberRole.create(:org_member_id => member.id, :role_id => 11)
+ redirect_to organization_path(@organization)
+ end
+ end
+
+ def show
+ if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
+ @organization = Organization.find(params[:id])
+ if params[:org_subfield_id]
+ @org_subfield = OrgSubfield.find(params[:org_subfield_id])
+ @org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0
+ @org_activities = OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{@org_subfield.id})").order('updated_at desc').page(params[:page] || 1).per(10)
+ else
+ shield_project_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Project'").map(&:shield_id)
+ shield_course_ids = ShieldActivity.where("container_type='Organization' and container_id=#{@organization.id} and shield_type='Course'").map(&:shield_id)
+ project_ids = (@organization.projects.map(&:id)-shield_project_ids) << 0
+ course_ids = (@organization.courses.map(&:id)-shield_course_ids) << 0
+ course_types = "('Message','News','HomeworkCommon','Poll','Course')"
+ case params[:type]
+ when nil
+ @org_activities = OrgActivity.where("(container_id =? and container_type =?) " +
+ "or (container_type ='Project' and org_act_type in ('Issue','Message','ProjectCreateInfo') and container_id in (#{project_ids.join(',')})) "+
+ "or (container_type ='Course' and org_act_type in #{course_types} and container_id in (#{course_ids.join(',')}))",
+ @organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10)
+ when 'project_issue'
+ @org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Issue' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
+ when 'project_message'
+ @org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Message' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
+ when 'org'
+ @org_activities = OrgActivity.where("container_id =? and container_type =?",@organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10)
+ when 'course_homework'
+ @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'HomeworkCommon' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
+ when 'course_news'
+ @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'News' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
+ when 'course_message'
+ @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'Message' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
+ when 'course_poll'
+ @org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'Poll' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
+ end
+ end
+ @page = params[:page] ? params[:page].to_i : 1
+ respond_to do |format|
+ format.html
+ format.js
+ end
+ else
+ render_403
+ end
+ end
+
+ def update
+ @organization = Organization.find(params[:id])
+ @organization.name = params[:organization][:name]
+ @organization.description = params[:organization][:description]
+ @organization.domain = params[:organization][:domain]
+ @organization.is_public = params[:organization][:is_public] == 'on' ? 1 : 0
+ #@organization.name = params[:organization][:name]
+ @organization.save
+ respond_to do |format|
+ format.html { redirect_to setting_organization_path(@organization)}
+ end
+ end
+
+ def check_uniq
+ @check = false;
+ @org_name = params[:org_name].strip
+ @config_page = params[:config_page]
+ sameName = @config_page ? Organization.where('name = ? and id != ?',params[:org_name],params[:org_id].to_i).count == 0 : Organization.where('name = ?',params[:org_name]).count == 0
+ if sameName == true
+ @check = true
+ end
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def find_organization
+ @organization = Organization.find(params[:id])
+ end
+
+ def setting
+ @organization = Organization.find(params[:id])
+
+ if User.current.admin? || User.current.admin_of_org?(@organization)
+ else
+ render_403
+ end
+ end
+
+
+ def clear_org_avatar_temp
+
+ end
+
+ def set_homepage
+ @org = Organization.find(params[:id])
+ @org.home_id = params[:home_id]
+ @org.save
+ # respond_to do |format|
+ # format.html {redirect_to organization_path(org)}
+ # end
+ end
+
+ def cancel_homepage
+ @org = Organization.find(params[:id])
+ @org.home_id = nil
+ @org.save
+ end
+
+ def autocomplete_search
+ @project = Project.find(params[:project_id])
+ #@flag = params[:flag] || false
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def members
+ if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
+ @members = OrgMember.where("organization_id =?", @organization.id)
+ else
+ render_403
+ end
+ end
+
+ def more_org_projects
+ @organization = Organization.find params[:id]
+ @page = params[:page]
+ @org_projects = @organization.projects.reorder('created_at').uniq.page((params[:page].to_i || 1) +1).per(5)
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def more_org_courses
+ @organization = Organization.find(params[:id])
+ @page = params[:page]
+ @org_courses = @organization.courses.reorder('created_at').uniq.page((params[:page].to_i || 1) + 1 ).per(5)
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def join_course_menu
+ @organization = Organization.find(params[:id])
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def search_courses
+ @organization = Organization.find(params[:id])
+ condition = '%%'
+ if !params[:name].nil?
+ condition = "%#{params[:name].strip}%".gsub(" ","")
+ end
+ sql = "select courses.* from courses inner join members on courses.id = members.course_id where members.user_id = #{User.current.id} and courses.name like '#{condition}'"+
+ "and courses.id not in (select distinct org_courses.course_id from org_courses where org_courses.organization_id = #{@organization.id})"
+ #user_courses = Course.find_by_sql(sql)
+ @courses = Course.find_by_sql(sql)
+ # @added_course_ids = @organization.courses.map(&:id)
+ # @courses = []
+ # user_courses.each do |course|
+ # if !@added_course_ids.include?(course.id)
+ # @courses << course
+ # end
+ # end
+ end
+
+ def join_courses
+ @organization = Organization.find(params[:id])
+ course_ids = params[:courseNames]
+ course_ids.each do |id|
+ OrgCourse.create(:organization_id => @organization.id, :course_id => id.to_i, :created_at => Time.now)
+ end
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def join_project_menu
+ @organization = Organization.find(params[:id])
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def logout
+ logout_user
+ respond_to do |format|
+ format.html {redirect_to organization_path(params[:id])}
+ end
+ end
+
+ def search_projects
+ @organization = Organization.find(params[:id])
+ condition = '%%'
+ if !params[:name].nil?
+ condition = "%#{params[:name].strip}%".gsub(" ","")
+ end
+ sql = "select projects.* from projects inner join members on projects.id = members.project_id where members.user_id = #{User.current.id} and projects.status != 9 and projects.name like '#{condition}'" +
+ " and projects.id not in (select org_projects.project_id from org_projects where organization_id = #{@organization.id})"
+ #user_projects = Course.find_by_sql(sql)
+ @projects = Course.find_by_sql(sql)
+ # @added_course_ids = @organization.projects.map(&:id)
+ # @projects = []
+ # user_projects.each do |project|
+ # if !@added_course_ids.include?(project.id)
+ # @projects << project
+ # end
+ # end
+ end
+
+ def join_projects
+ @organization = Organization.find(params[:id])
+ project_ids = params[:projectNames]
+ project_ids.each do |id|
+ OrgProject.create(:organization_id => @organization.id, :project_id => id.to_i, :created_at => Time.now)
+ end
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def hide_org_subfield
+ @org_subfield = OrgSubfield.find(params[:org_subfield_id])
+ @org_subfield.update_attribute(:hide, 1)
+ end
+
+ def show_org_subfield
+ @org_subfield = OrgSubfield.find(params[:org_subfield_id])
+ @org_subfield.update_attribute(:hide, 0)
+ end
+
+ def org_resources_subfield
+ @org = Organization.find(params[:id])
+ @subfield = @org.org_subfields.where('field_type = "Resource" ')
+ respond_to do | format|
+ format.js
+ end
+ end
+ def apply_subdomain
+ @organization = Organization.find(params[:id])
+ admins = User.where("admin=1")
+ admins.each do |admin|
+ OrgMessage.create(:user_id => admin.id, :organization_id => @organization.id, :message_type => 'ApplySubdomain', :message_id => @organization.id, :sender_id => User.current.id, :viewed => 0, :content => params[:domain])
+ end
+ end
+
+ def agree_apply_subdomain
+ @organization = Organization.find(params[:organization_id])
+ @organization.update_attribute(:domain, params[:org_domain])
+ if OrgMessage.where("message_type='AgreeApplySubdomain' and organization_id=#{@organization.id} and content=?",params[:org_domain]).count == 0
+ OrgMessage.create(:user_id => params[:user_id], :organization_id => @organization.id, :message_type => 'AgreeApplySubdomain', :message_id => @organization.id, :sender_id => User.current.id, :viewed => 0, :content => params[:org_domain])
+ end
+ end
+end
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index ccebdccfa..31c70e92a 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -76,16 +76,17 @@ class ProjectsController < ApplicationController
condition = "%#{params[:name].strip}%".gsub(" ","")
end
limit = 15
- project_org_ids = OrgProject.find_by_sql("select distinct organization_id from org_projects where project_id = #{params[:id]}").map(&:organization_id)
- if project_org_ids.empty?
- @orgs_not_in_project = Organization.where("(is_public or creator_id =?) = 1 and name like ?",User.current.id, condition).page((params[:page].to_i || 1)).per(limit)
- @org_count = Organization.where("is_public = 1 or creator_id =?", User.current.id).where("name like ?", condition).count
- else
- project_org_ids = "(" + project_org_ids.join(',') + ")"
- @orgs_not_in_project = Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?) and name like ?", User.current.id, condition).page((params[:page].to_i || 1)).per(limit)
- @org_count = Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?)", User.current.id).where("name like ?", condition).count
- end
- # @project_count = Project.project_entities.visible.like(params[:name]).page(params[:page]).count
+ project_org_ids = OrgProject.find_by_sql("select distinct organization_id from org_projects where project_id = #{params[:id]}").map(&:organization_id) << 0
+ @orgs_not_in_project = User.current.organizations.where("organizations.id not in (#{project_org_ids.join(',')}) and organizations.name like ?", condition).page(params[:page].to_i || 1).per(limit)
+ @org_count = User.current.organizations.where("organizations.id not in (#{project_org_ids.join(',')}) and organizations.name like '#{condition}'").count
+ # if project_org_ids.empty?
+ # @orgs_not_in_project = Organization.where("(is_public or creator_id =?) = 1 and name like ?",User.current.id, condition).page((params[:page].to_i || 1)).per(limit)
+ # @org_count = Organization.where("is_public = 1 or creator_id =?", User.current.id).where("name like ?", condition).count
+ # else
+ # project_org_ids = "(" + project_org_ids.join(',') + ")"
+ # @orgs_not_in_project = Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?) and name like ?", User.current.id, condition).page((params[:page].to_i || 1)).per(limit)
+ # @org_count = Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?)", User.current.id).where("name like ?", condition).count
+ # end
@orgs_page = Paginator.new @org_count, limit,params[:page]
@no_roll_hint = params[:hint_flag]
#render :json => {:orgs => @orgs_not_in_project, :count => @org_count}.to_json
diff --git a/app/controllers/shield_activities_controller.rb b/app/controllers/shield_activities_controller.rb
new file mode 100644
index 000000000..b2d5191b3
--- /dev/null
+++ b/app/controllers/shield_activities_controller.rb
@@ -0,0 +1,43 @@
+class ShieldActivitiesController < ApplicationController
+ def create
+ if params[:org_id]
+ if params[:project_id]
+ ShieldActivity.create(:container_type => 'Organization', :container_id => params[:org_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i)
+ elsif params[:course_id]
+ ShieldActivity.create(:container_type => 'Organization', :container_id => params[:org_id].to_i, :shield_type => 'Course', :shield_id => params[:course_id].to_i)
+ end
+ elsif params[:user_id]
+ if params[:project_id]
+ ShieldActivity.create(:container_type => 'User', :container_id => params[:user_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i)
+ elsif params[:course_id]
+ ShieldActivity.create(:container_type => 'User', :container_id => params[:user_id].to_i, :shield_type => 'Course', :shield_id => params[:course_id].to_i)
+ end
+ end
+ end
+
+ def show_acts
+ if params[:org_id]
+ if params[:project_id]
+ ShieldActivity.where("container_type='Organization' and container_id=#{params[:org_id].to_i} and shield_type='Project' and shield_id=#{params[:project_id]}").each do |act|
+ act.destroy
+ end
+ # ShieldActivity.create(:container_type => 'Organization', :container_id => params[:org_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i)
+ elsif params[:course_id]
+ ShieldActivity.where("container_type='Organization' and container_id=#{params[:org_id].to_i} and shield_type='Course' and shield_id=#{params[:course_id]}").each do |act|
+ act.destroy
+ end
+ end
+ elsif params[:user_id]
+ if params[:project_id]
+ ShieldActivity.where("container_type='User' and container_id=#{params[:user_id].to_i} and shield_type='Project' and shield_id=#{params[:project_id]}").each do |act|
+ act.destroy
+ end
+ # ShieldActivity.create(:container_type => 'Organization', :container_id => params[:org_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i)
+ elsif params[:course_id]
+ ShieldActivity.where("container_type='User' and container_id=#{params[:user_id].to_i} and shield_type='Course' and shield_id=#{params[:course_id]}").each do |act|
+ act.destroy
+ end
+ end
+ end
+ end
+end
diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb
index 5cb646c8e..2f6c4ecc7 100644
--- a/app/controllers/student_work_controller.rb
+++ b/app/controllers/student_work_controller.rb
@@ -259,16 +259,10 @@ class StudentWorkController < ApplicationController
stu_project.save
end
end
- course_activity = CourseActivity.where("course_act_type='HomeworkCommon' and course_act_id =#{@homework.id}").first
- if course_activity
- course_activity.updated_at = Time.now
- course_activity.save
- end
- user_activity = UserActivity.where("act_type='HomeworkCommon' and act_id =#{@homework.id}").first
- if user_activity
- user_activity.updated_at = Time.now
- user_activity.save
- end
+ update_course_activity(@homework.class,@homework.id)
+ update_user_activity(@homework.class,@homework.id)
+ update_org_activity(@homework.class,@homework.id)
+
course_message = CourseMessage.new(:user_id =>User.current.id,:content=>"new",:course_message_id=>student_work.id,:course_id => @course.id,:course_message_type=>"StudentWork", :status => 9) #作品提交记录
course_message.save
@@ -649,7 +643,8 @@ class StudentWorkController < ApplicationController
if revise_attachments.count == 2
revise_attachments.last.destroy
end
- #@attachment = @work.attachments.where("attachtype = 7").order("created_on desc").first
+ attachment = @work.attachments.where("attachtype = 7").first
+ attachment.update_attributes(:description => params[:description])
respond_to do |format|
format.js
end
diff --git a/app/controllers/system_messages_controller.rb b/app/controllers/system_messages_controller.rb
index 684378e8a..df17ca3e2 100644
--- a/app/controllers/system_messages_controller.rb
+++ b/app/controllers/system_messages_controller.rb
@@ -1,4 +1,5 @@
class SystemMessagesController < ApplicationController
+
# before_filter :message_author, :only => [:show]
#
# def message_author
@@ -41,6 +42,7 @@ class SystemMessagesController < ApplicationController
@system_messages.description = params[:system_message][:description]
@system_messages.subject = params[:system_message][:subject]
@system_messages.user_id = User.current.id
+ # @system_messages.save_attachments(params[:attachments])
respond_to do |format|
if @system_messages.save
format.html {redirect_to user_system_messages_path(User.current)}
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index d40bc7c7c..507dada24 100644
--- a/app/controllers/tags_controller.rb
+++ b/app/controllers/tags_controller.rb
@@ -228,6 +228,12 @@ class TagsController < ApplicationController
@select_tag_name = params[:select_tag_name]
end
+ if @obj && @object_flag == '6' && @obj.container.kind_of?(Project)
+ @project = @obj.container
+ @tag_list = get_course_tag_list @project
+ @select_tag_name = params[:select_tag_name]
+ end
+
if @obj && @object_flag == '6' && @obj.container.kind_of?(OrgSubfield)
@org_subfield = @obj.container
@tag_list = get_org_subfield_tag_list @org_subfield
@@ -320,6 +326,88 @@ class TagsController < ApplicationController
end
end
+ def update_project_tag_name
+ @tag_name = params[:tagName]
+ @rename_tag_name = params[:renameName]
+ @taggable_id = params[:taggableId]
+ @taggable_type = numbers_to_object_type(params[:taggableType])
+ @project_id = params[:projectId]
+
+ @rename_tag = (ActsAsTaggableOn::Tag.find_by_name(@rename_tag_name)) #查找重命名后的tag
+ @tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id #重命名前的tag_id
+ @taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,@taggable_id,@taggable_type) unless @taggable_id.blank?
+ @obj = get_object(@taggable_id,params[:taggableType]) unless @taggable_id.blank?
+ if @taggable_id.blank? #如果没有传tag_id,那么直接更新tag_name就好了。但是要防止 重命名后的tag存在。
+ if @project_id
+ project = Project.find @project_id
+ if project
+ project.attachments.each do |attachment|
+ taggings = ActsAsTaggableOn::Tagging.find_by_tag_id_and_taggable_id_and_taggable_type(@tag_id,attachment.id,attachment.class)
+ if taggings
+ taggings.delete
+ attachment.tag_list.add(@rename_tag_name.split(","))
+ attachment.save
+ end
+ end
+ end
+ end
+ else
+ if(@rename_tag.nil?) #这次命名的是新的tag
+
+ # 是否还有其他记录 引用了 tag_id
+ @tagging = ActsAsTaggableOn::Tagging.where("tag_id = #{@tag_id}")
+ # 如果taggings表中记录为 1 ,那么改变@tag_id对应的tag的名字
+ if @tagging.count == 1
+ @tag = ActsAsTaggableOn::Tag.find_by_id(@tag_id)
+ @tag.update_attributes({:name=>@rename_tag_name})
+ else #如果tagging表中的记录大于1,那么就要新增tag记录
+
+ unless @obj.nil?
+ @obj.tag_list.add(@rename_tag_name.split(","))
+ @obj.save
+ end
+ #删除原来的对应的taggings的记录
+ unless @taggings.nil?
+ @taggings.delete
+ end
+ end
+ else #这是已有的tag
+ # 更改taggings记录里的tag_id
+ unless @taggings.nil?
+ @taggings.update_attributes({:tag_id=>@rename_tag.id})
+ end
+ end
+ end
+
+ @obj_flag = params[:taggableType]
+ if @obj && @obj_flag == '6' && @obj.container.kind_of?(Project)
+ @project = @obj.container
+ @tag_list = @tag_list = get_course_tag_list @project
+ elsif @project_id
+ @project = Project.find(@project_id)
+ @tag_list = get_project_tag_list @project
+
+ #这里要引用FilesController里的逻辑了。将资源库当前的文件列表刷新一遍。
+ @flag = params[:flag] || false
+ sort = ""
+ @sort = ""
+ @order = ""
+ @is_remote = false
+ @isproject = false
+
+ sort = "#{Attachment.table_name}.created_on desc"
+
+ @containers = [ Project.includes(:attachments).reorder(sort).find(@project.id)]
+
+ show_attachments @containers
+ elsif @obj && @obj_flag == '5'
+ @forum = @obj
+ end
+ respond_to do |format|
+ format.js
+ end
+ end
+
def update_org_subfield_tag_name
@tag_name = params[:tagName]
@rename_tag_name = params[:renameName]
@@ -458,6 +546,10 @@ class TagsController < ApplicationController
@course = @obj.container
@tag_list = @tag_list = get_course_tag_list @course
end
+ if @obj && @obj_flag == '6' && @obj.container.kind_of?(Project)
+ @project = @obj.container
+ @tag_list = @tag_list = get_project_tag_list @project
+ end
if @obj && @obj_flag == '6' && @obj.container.kind_of?(OrgSubfield)
@org_subfield = @obj.container
@tag_list = @tag_list = get_org_subfield_tag_list @org_subfield
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index f26f6c118..449d8b9de 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -55,6 +55,7 @@ class UsersController < ApplicationController
before_filter :recorded_visitor, :only => [:show,:user_fanslist,:user_watchlist,:user_visitorlist]
helper :sort
+ helper :attachments
include SortHelper
helper :custom_fields
include CustomFieldsHelper
@@ -63,6 +64,7 @@ class UsersController < ApplicationController
include GitlabHelper
include UserScoreHelper
+
include PollHelper
helper :user_score
helper :journals
@@ -497,7 +499,7 @@ class UsersController < ApplicationController
#提交作品时,计算是否迟交
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
+ student_work.late_penalty = homework.late_penalty
else
student_work.late_penalty = 0
end
@@ -522,7 +524,7 @@ class UsersController < ApplicationController
else
homework.publish_time = params[:homework_common][:publish_time]
end
- homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment] : 1
+ homework.anonymous_comment = params[:homework_common][:anonymous_comment] ? params[:homework_common][:anonymous_comment] : 0
homework.homework_type = params[:homework_type].to_i || 1
homework.late_penalty = 10
homework.teacher_priority = 1
@@ -619,7 +621,7 @@ class UsersController < ApplicationController
end
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')) "+
+ @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc")
elsif params[:type] == "2" #课程资源
user_course_ids = User.current.courses.map { |c| c.id}
@@ -875,7 +877,7 @@ class UsersController < ApplicationController
#显示更多用户课程
def user_courses4show
@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)
+ @courses = @user.courses.visible.where("is_delete =?", 0).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)
end
#显示更多用户项目
@@ -965,9 +967,11 @@ class UsersController < ApplicationController
params[:course_id], 'JoinCourseRequest', User.current.id, @user.id, false)
join_course_messages.update_all(:viewed => true)
end
+ shield_project_ids = ShieldActivity.where("container_type='User' and container_id=#{@user.id} and shield_type='Project'").map(&:shield_id)
+ shield_course_ids = ShieldActivity.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_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(",") + ")"
+ user_project_ids = (@user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")"
+ user_course_ids = (@user.courses.visible.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.courses.visible.map{|course| course.id}-shield_course_ids).join(",") + ")"
course_types = "('Message','News','HomeworkCommon','Poll','Course')"
project_types = "('Message','Issue','ProjectCreateInfo')"
principal_types = "JournalsForMessage"
@@ -1327,12 +1331,12 @@ class UsersController < ApplicationController
if(params[:type].blank?|| params[:type] == "1") #全部
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')) "+
+ @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc")
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')) " +
+ "and container_type in('Project','OrgSubfield','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(',')}))").order("created_on desc")
end
elsif params[:type] == "2" #课程资源
@@ -1389,12 +1393,12 @@ class UsersController < ApplicationController
if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') #全部
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')) "+
+ @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc")
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')) " +
+ "and container_type in('Project','OrgSubfield','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(',')}))").order("created_on desc")
end
elsif params[:type] == "2" #课程资源
@@ -1489,11 +1493,23 @@ class UsersController < ApplicationController
unless course_ids.nil?
course_ids.each do |id|
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
@@ -1513,11 +1529,23 @@ class UsersController < ApplicationController
unless course_ids.nil?
course_ids.each do |id|
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
@@ -1530,7 +1558,7 @@ class UsersController < ApplicationController
@flag = false
end
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')) "+
+ @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc")
@type = params[:type]
@limit = 25
@@ -1559,11 +1587,23 @@ class UsersController < ApplicationController
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
@@ -1582,11 +1622,23 @@ class UsersController < ApplicationController
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
@@ -1598,7 +1650,7 @@ class UsersController < ApplicationController
@flag=true
end
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')) "+
+ @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc")
@type = params[:type]
@limit = 25
@@ -1614,6 +1666,97 @@ class UsersController < ApplicationController
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
+ 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
+ attach_copied_obj.save
+ end
+ end
+ 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|
+
+ 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
+ attach_copied_obj.save
+ end
+ end
+ else
+ @flag=true
+ end
+ user_course_ids = User.current.courses.map { |c| c.id} #我的资源库的话,那么应该是我上传的所有资源 加上 我加入的课程的所有资源
+ @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
+ "or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").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
+ respond_to do |format|
+ format.js
+ end
+ end
+
+ def change_org_subfield
+
+ end
+
# 资源预览
def resource_preview
preview_id = params[:resource_id]
@@ -1826,12 +1969,12 @@ class UsersController < ApplicationController
if(params[:type].blank? || params[:type] == "1") #全部
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')) "+
+ @attachments = Attachment.where("(author_id = #{params[:id]} and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
"or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))").order("created_on desc")
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')) " +
+ "and container_type in('Project','OrgSubfield','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(',')}))").order("created_on desc")
end
elsif params[:type] == "2" #课程资源
@@ -1882,7 +2025,7 @@ class UsersController < ApplicationController
if(params[:type].nil? || params[:type].blank? || params[:type] == "1" || params[:type] == 'all') #全部
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')) "+
+ @attachments = Attachment.where("((author_id = #{params[:id]} and container_type in('Project','OrgSubfield','Principal','Course','Issue','Document','Message','News','StudentWorkScore','HomewCommon')) "+
" or (container_type = 'Course' and container_id in (#{user_course_ids.empty? ? '0': user_course_ids.join(',')}))) and (filename like :p) ",:p=>search).order("created_on desc")
else
user_course_ids = User.find(params[:id]).courses.visible.map { |c| c.id} #如果课程私有资源,那么要看这个资源的课程是不是在 这个user的所有我可见的课程中
@@ -1955,6 +2098,23 @@ class UsersController < ApplicationController
end
end
+ def search_user_org
+ @user = User.current
+ if !params[:search].nil? #发送到有栏目类型为资源的组织中
+ search = "%#{params[:search].to_s.strip.downcase}%"
+ @orgs = @user.organizations.where("name like ?", search).select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Resource'").count > 0}
+ else
+ @orgs = @user.organizations.select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Resource'").count > 0}
+ end
+ @search = params[:search]
+ #这里仅仅是传递需要发送的资源id
+ @send_id = params[:send_id]
+ @send_ids = params[:checkbox1] || params[:send_ids]
+ respond_to do |format|
+ format.js
+ end
+ end
+
private
def find_user
diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb
index df9fd30f2..ebd46caa7 100644
--- a/app/controllers/words_controller.rb
+++ b/app/controllers/words_controller.rb
@@ -57,21 +57,11 @@ class WordsController < ApplicationController
@jfm = add_reply_adapter options
@save_succ = true if @jfm.errors.empty?
if @save_succ
- course_activity = CourseActivity.where("course_act_type='JournalsForMessage' and course_act_id =#{parent_id}").first
- if course_activity
- course_activity.updated_at = Time.now
- course_activity.save
- end
- principal_activity = PrincipalActivity.where("principal_act_type='JournalsForMessage' and principal_act_id =#{parent_id}").first
- if principal_activity
- principal_activity.updated_at = Time.now
- principal_activity.save
- end
- user_activity = UserActivity.where("act_type='JournalsForMessage' and act_id =#{parent_id}").first
- if user_activity
- user_activity.updated_at = Time.now
- user_activity.save
- end
+ update_course_activity('JournalsForMessage',parent_id)
+ update_user_activity('JournalsForMessage',parent_id)
+ update_forge_activity('JournalsForMessage',parent_id)
+ update_org_activity('JournalsForMessage',parent_id)
+ update_principal_activity('JournalsForMessage',parent_id)
end
respond_to do |format|
# format.html {
@@ -236,7 +226,11 @@ class WordsController < ApplicationController
if User.current.logged?
@user = User.find(params[:id])
if params[:new_form][:user_message].size>0 && User.current.logged? && @user
- @user.add_jour(User.current, params[:new_form][:user_message])
+ if params[:private] && params[:private] == '1'
+ @user.journals_for_messages << JournalsForMessage.new(:user_id => User.current.id, :notes => params[:new_form][:user_message], :reply_id => 0, :status => true, :is_readed => false, :private => 1)
+ else
+ @user.add_jour(User.current, params[:new_form][:user_message])
+ end
end
redirect_to feedback_path(@user)
else
@@ -274,16 +268,9 @@ class WordsController < ApplicationController
update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE
end
- course_activity = CourseActivity.where("course_act_type='HomeworkCommon' and course_act_id =#{@homework_common.id}").first
- if course_activity
- course_activity.updated_at = Time.now
- course_activity.save
- end
- user_activity = UserActivity.where("act_type='HomeworkCommon' and act_id =#{@homework_common.id}").first
- if user_activity
- user_activity.updated_at = Time.now
- user_activity.save
- end
+ update_course_activity(@homework_common.class,@homework_common.id)
+ update_user_activity(@homework_common.class,@homework_common.id)
+ update_org_activity(@homework_common.class,@homework_common.id)
respond_to do |format|
format.js{
@user_activity_id = params[:user_activity_id]
diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb
index 2a4430935..d66c6a30d 100644
--- a/app/controllers/zipdown_controller.rb
+++ b/app/controllers/zipdown_controller.rb
@@ -17,6 +17,7 @@ class ZipdownController < ApplicationController
begin
if params[:base64file]
file = Base64.decode64(params[:base64file])
+ file = file.sub('*', '+')
send_file "#{OUTPUT_FOLDER}/#{file}", :filename => filename_for_content_disposition(file), :type => detect_content_type(file)
else
send_file "#{OUTPUT_FOLDER}/#{params[:file]}", :filename => filename_for_content_disposition(params[:filename]), :type => detect_content_type(params[:file])
@@ -118,11 +119,15 @@ class ZipdownController < ApplicationController
[{files:[out_file.file_path], count: 1, index: 1,
real_file: out_file.file_path,
file: File.basename(out_file.file_path),
- base64file: Base64.encode64(File.basename(out_file.file_path)),
+ base64file: encode64(File.basename(out_file.file_path)),
size:(out_file.pack_size / 1024.0 / 1024.0).round(2)
}]
end
+ def encode64(str)
+ Base64.encode64(str).sub('+', '*')
+ end
+
def zip_homework_common homework_common
bid_homework_path = []
digests = []
@@ -142,7 +147,7 @@ class ZipdownController < ApplicationController
[{files:[out_file.file_path], count: 1, index: 1,
real_file: out_file.file_path,
file: File.basename(out_file.file_path),
- base64file: Base64.encode64(File.basename(out_file.file_path)),
+ base64file: encode64(File.basename(out_file.file_path)),
size:(out_file.pack_size / 1024.0 / 1024.0).round(2)
}]
end
diff --git a/app/helpers/api_helper.rb b/app/helpers/api_helper.rb
index f73cc87e6..8324951f9 100644
--- a/app/helpers/api_helper.rb
+++ b/app/helpers/api_helper.rb
@@ -180,7 +180,7 @@ module ApiHelper
if timePassed < 0
updateAtValue = "时间有问题"
elsif timePassed < ONE_MINUTE
- updateAtValue = "一分钟前"
+ updateAtValue = "1分钟前"
elsif timePassed < ONE_HOUR
timeIntoFormat = timePassed / ONE_MINUTE
updateAtValue = timeIntoFormat.to_s + "分钟前"
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 4bdffb9dc..5b7cca7fe 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -48,6 +48,7 @@ module ApplicationHelper
end
end
end
+
# 获取组织成员中文名字
def get_org_member_role_name member
case member.roles[0].name
@@ -58,6 +59,19 @@ module ApplicationHelper
end
end
+ # 判断组织左侧展开或者隐藏
+ def is_hide_org_left obj
+ if obj.nil?
+ return true
+ else
+ if obj.hide == 0
+ return true
+ else
+ return false
+ end
+ end
+ end
+
# Time 2015-03-24 16:38:05
# Author lizanle
# Description after save后需要进行资源记录的更新
@@ -2432,6 +2446,16 @@ module ApplicationHelper
tag_list
end
+ # 获取项目资源的Tag云
+ def get_project_tag_list project
+ all_attachments = project.attachments.select{|attachment| attachment.is_public? ||
+ (attachment.container_type == "Project" && User.current.member_of?(project))||
+ attachment.author_id == User.current.id
+ }
+ tag_list = attachment_tag_list all_attachments
+ tag_list
+ end
+
def get_org_subfield_tag_list org_subfield
all_attachments = org_subfield.attachments.select{|attachment| attachment.is_public? ||
(attachment.container_type == "OrgSubfield" && User.current.member_of_org?(org_subfield.organization))||
@@ -2588,6 +2612,12 @@ module ApplicationHelper
end
end
+ def file_preview_eye(file, html_options={})
+ if %w(pdf pptx doc docx xls xlsx).any?{|x| file.filename.downcase.end_with?(x)}
+ link_to '', download_named_attachment_path(file.id, file.filename, preview: true),html_options
+ end
+ end
+
#将文本内的/n转换为
def text_format text
text.gsub("&","&").gsub("<","<").gsub(">",">").gsub("\n","
").html_safe
@@ -2751,4 +2781,52 @@ int main(int argc, char** argv){
ss.html_safe
end
+ #代码提交数量
+ def changesets_num project
+ g = Gitlab.client
+ project.gpid.nil? ? 0 : g.commits_total_count(project.gpid).count
+ # # commits_total_count(project.gpid)
+ # project.changesets.count
+ end
+
+ #课程动态的更新
+ def update_course_activity type, id
+ course_activity = CourseActivity.where("course_act_type=? and course_act_id =?", type.to_s, id).first
+ if course_activity
+ course_activity.updated_at = Time.now
+ course_activity.save
+ end
+ end
+ #首页动态更新
+ def update_user_activity type, id
+ user_activity = UserActivity.where("act_type=? and act_id =?", type.to_s, id).first
+ if user_activity
+ user_activity.updated_at = Time.now
+ user_activity.save
+ end
+ end
+ #项目动态更新
+ def update_forge_activity type, id
+ forge_activity = ForgeActivity.where("forge_act_type=? and forge_act_id=?", type.to_s, id).first
+ if forge_activity
+ forge_activity.updated_at = Time.now
+ forge_activity.save
+ end
+ end
+ #组织动态更新
+ def update_org_activity type , id
+ org_activity = OrgActivity.where("org_act_type=? and org_act_id =?", type.to_s, id).first
+ if org_activity
+ org_activity.updated_at = Time.now
+ org_activity.save
+ end
+ end
+ #个人动态更新
+ def update_principal_activity type, id
+ principal_activity = PrincipalActivity.where("principal_act_type=? and principal_act_id =?", type.to_s, id).first
+ if principal_activity
+ principal_activity.updated_at = Time.now
+ principal_activity.save
+ end
+ end
end
diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb
index be24629af..3dc2c66af 100644
--- a/app/helpers/attachments_helper.rb
+++ b/app/helpers/attachments_helper.rb
@@ -96,6 +96,7 @@ module AttachmentsHelper
end
false
end
+
#判断项目project中是否包含课件attachment,project中引用了attachment也算作包含
def project_contains_attachment? project,attachment
project.attachments.each do |att|
diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb
index a1b119cb5..097a3c1a4 100644
--- a/app/helpers/courses_helper.rb
+++ b/app/helpers/courses_helper.rb
@@ -507,8 +507,10 @@ module CoursesHelper
#课程实践年份下拉框
def course_time_option year
type = []
+ month = Time.now.month
now_year = year.nil? ? Time.now.year : (Time.now.year <= year ? Time.now.year : year)
- for i in (now_year..now_year + 10)
+ year = month < 3 ? now_year - 1 : now_year
+ for i in (year..year + 10)
option = []
option << i
option << i
diff --git a/app/helpers/org_subfields_helper.rb b/app/helpers/org_subfields_helper.rb
index a9f8a396f..8dad7096f 100644
--- a/app/helpers/org_subfields_helper.rb
+++ b/app/helpers/org_subfields_helper.rb
@@ -1,2 +1,3 @@
module OrgSubfieldsHelper
+ include OrganizationsHelper
end
diff --git a/app/helpers/organizations_helper.rb b/app/helpers/organizations_helper.rb
index 607d2af5c..69c355313 100644
--- a/app/helpers/organizations_helper.rb
+++ b/app/helpers/organizations_helper.rb
@@ -17,6 +17,15 @@ module OrganizationsHelper
s + content_tag('ul', links,:class => 'wlist',:style=>'float:left !important', :id => "org_member_pagination_links" )
end
-
+ def get_default_name field
+ case field.name
+ when 'activity' then
+ return '动态'
+ when 'course' then
+ return '课程'
+ when 'project' then
+ return '项目'
+ end
+ end
end
diff --git a/app/helpers/project_score_helper.rb b/app/helpers/project_score_helper.rb
index d73e1592e..133212718 100644
--- a/app/helpers/project_score_helper.rb
+++ b/app/helpers/project_score_helper.rb
@@ -20,14 +20,6 @@ module ProjectScoreHelper
project.documents.count
end
- #代码提交数量
- def changesets_num project
- g = Gitlab.client
- project.gpid.nil? ? 0 : g.commits_total_count(project.gpid).count
- # # commits_total_count(project.gpid)
- # project.changesets.count
- end
-
#讨论区帖子数量
def board_message_num project
board_message_count = 0
diff --git a/app/helpers/shield_activities_helper.rb b/app/helpers/shield_activities_helper.rb
new file mode 100644
index 000000000..5dcbcca33
--- /dev/null
+++ b/app/helpers/shield_activities_helper.rb
@@ -0,0 +1,2 @@
+module ShieldActivitiesHelper
+end
diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb
index 2e8b98a2d..8847f4163 100644
--- a/app/helpers/tags_helper.rb
+++ b/app/helpers/tags_helper.rb
@@ -73,6 +73,16 @@ def course_contains_attachment? course,attachment
false
end
+#判断项目project中是否包含课件attachment,project中引用了attachment也算作包含
+def project_contains_attachment? project,attachment
+ project.attachments.each do |att|
+ if att.id == attachment.id || (!att.copy_from.nil? && !attachment.copy_from.nil? && att.copy_from == attachment.copy_from) || att.copy_from == attachment.id || att.id == attachment.copy_from
+ return true
+ end
+ end
+ false
+end
+
#判断用户是否拥有不包含当前资源的课程,需用户在该课程中角色为教师且该课程属于当前学期或下一学期
def has_course? user,file
result = false
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
index 963284f7f..bfc01a102 100644
--- a/app/helpers/users_helper.rb
+++ b/app/helpers/users_helper.rb
@@ -49,6 +49,8 @@ module UsersHelper
'批改附件'
when 'Principal'
'用户资源'
+ when 'OrgSubfield'
+ '组织资源'
end
end
@@ -589,7 +591,7 @@ module UsersHelper
option << "请选择发布作业的课程"
option << -1
type << option
- user.courses.visible.select("courses.*,(SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").select{|c| user.allowed_to?(:as_teacher,c)}.each do |course|
+ user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(created_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").select{|c| user.allowed_to?(:as_teacher,c)}.each do |course|
option = []
option << course.name+"("+course.time.to_s+course.term+")"
option << course.id
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index ad5655b02..d90b0368e 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -32,6 +32,7 @@ class Attachment < ActiveRecord::Base
has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy
# end
include UserScoreHelper
+ has_many :attachment_histories
validates :filename, presence: true, length: {maximum: 254}
validates :author, presence: true
@@ -348,11 +349,18 @@ class Attachment < ActiveRecord::Base
# Deletes the file from the file system if it's not referenced by other attachments
def delete_from_disk
- if Attachment.where("disk_filename = ? AND id <> ?", disk_filename, id).empty?
+ #资源存在,且历史记录为0 且 该资源没有存在任何拷贝才能删除资源
+ if Attachment.where("disk_filename = ? AND id <> ?", disk_filename, id).empty? && self.attachment_histories.count == 0 && Attachment.where('copy_from = ?',self.id) .count == 0
delete_from_disk!
end
end
+ #有了历史记录的数据记录是不能被删除的。
+ #true 能被删除 false 不能被删除
+ def destroyable
+ self.attachment_histories.count == 0
+ end
+
# Returns file's location on disk
def diskfile
File.join(self.class.storage_path, disk_directory.to_s, disk_filename.to_s)
@@ -610,7 +618,7 @@ class Attachment < ActiveRecord::Base
end
end
def update_attachment_ealasticsearch_index
- if self.is_public == 1 && ( (self.container_type == 'Project' && Project.find(self.container_id).is_public == 1) ||
+ if self.is_public == 1 && ( ((self.container_type == 'Project' or self.container_type == 'Version') && Project.find(self.container_id).is_public == 1) ||
( self.container_type == 'Course' && Course.find(self.container_id).is_public == 1) ||
self.container_type == 'Principal')
begin
diff --git a/app/models/attachment_history.rb b/app/models/attachment_history.rb
new file mode 100644
index 000000000..2160d242d
--- /dev/null
+++ b/app/models/attachment_history.rb
@@ -0,0 +1,3 @@
+class AttachmentHistory < ActiveRecord::Base
+ belongs_to :attachment,foreign_key: 'attachment_id'
+end
diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb
index 27da33121..db28e55d6 100644
--- a/app/models/blog_comment.rb
+++ b/app/models/blog_comment.rb
@@ -17,6 +17,7 @@ class BlogComment < ActiveRecord::Base
safe_attributes 'title', 'content',"sticky", "locked"
after_save :add_user_activity
+ after_update :update_activity
before_destroy :destroy_user_activity
scope :like, lambda {|arg|
@@ -28,6 +29,15 @@ class BlogComment < ActiveRecord::Base
end
}
+ #动态更新
+ def update_activity
+ user_activity = UserActivity.where("act_type='BlogComment' and act_id =?",self.id).first
+ if user_activity
+ user_activity.updated_at = Time.now
+ user_activity.save
+ end
+ end
+
#在个人动态里面增加当前动态
def add_user_activity
if self.parent_id.nil? #只有发博文才插入动态
diff --git a/app/models/board.rb b/app/models/board.rb
index 67d59e599..b66719edf 100644
--- a/app/models/board.rb
+++ b/app/models/board.rb
@@ -19,6 +19,7 @@ class Board < ActiveRecord::Base
include Redmine::SafeAttributes
belongs_to :project,:touch => true
belongs_to :course,:touch=>true
+ belongs_to :org_subfield, :touch => true
has_many :topics, :class_name => 'Message', :conditions => "#{Message.table_name}.parent_id IS NULL", :order => "#{Message.table_name}.created_on DESC"
has_many :messages, :dependent => :destroy, :order => "#{Message.table_name}.created_on DESC"
belongs_to :last_message, :class_name => 'Message', :foreign_key => :last_message_id
diff --git a/app/models/course.rb b/app/models/course.rb
index 0194a2a9d..4e3b4fff0 100644
--- a/app/models/course.rb
+++ b/app/models/course.rb
@@ -70,7 +70,7 @@ class Course < ActiveRecord::Base
validates_length_of :description, :maximum => 10000
before_save :self_validate
# 公开课程变成私有课程,所有资源都变成私有
- after_update :update_files_public,:update_course_ealasticsearch_index
+ after_update :update_files_public,:update_course_ealasticsearch_index,:update_activity
after_create :create_board_sync, :act_as_course_activity, :act_as_course_message,:create_course_ealasticsearch_index
before_destroy :delete_all_members,:delete_course_ealasticsearch_index
@@ -428,6 +428,12 @@ class Course < ActiveRecord::Base
end
end
end
+#动态的更新
+def update_activity
+ update_course_activity(self.class, self.id)
+ update_user_activity(self.class, self.id)
+ update_org_activity(self.class, self.id)
+end
# Delete the previous articles index in Elasticsearch
# Course.__elasticsearch__.client.indices.delete index: Course.index_name rescue nil
diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb
index 0ad667bd1..f8e222b0f 100644
--- a/app/models/homework_common.rb
+++ b/app/models/homework_common.rb
@@ -26,6 +26,7 @@ class HomeworkCommon < ActiveRecord::Base
:author => :author,
:url => Proc.new {|o| {:controller => 'student_work', :action => 'index', :homework => o.id}}
after_create :act_as_activity, :send_mail, :act_as_course_message
+ after_update :update_activity
after_save :act_as_course_activity
after_destroy :delete_kindeditor_assets
@@ -60,7 +61,12 @@ class HomeworkCommon < ActiveRecord::Base
end
end
end
-
+ #动态的更新
+ def update_activity
+ update_course_activity(self.class, self.id)
+ update_user_activity(self.class, self.id)
+ update_org_activity(self.class, self.id)
+ end
#删除对应的图片
def delete_kindeditor_assets
delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::HOMEWORKCOMMON
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 5ecb3e36f..4dfa643fa 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -84,7 +84,7 @@ class Issue < ActiveRecord::Base
# fq
after_create :act_as_activity,:be_user_score_new_issue,:act_as_forge_activity, :act_as_forge_message, :act_as_at_message
- after_update :be_user_score
+ after_update :be_user_score,:update_activity
after_destroy :down_user_score
# after_create :be_user_score
# end
@@ -126,7 +126,13 @@ class Issue < ActiveRecord::Base
after_save :after_create_from_copy
after_destroy :update_parent_attributes
-
+ #动态的更新
+ def update_activity
+ update_user_activity(self.class, self.id)
+ update_forge_activity(self.class, self.id)
+ update_org_activity(self.class, self.id)
+ end
+
# fq
def act_as_activity
self.acts << Activity.new(:user_id => self.author_id)
diff --git a/app/models/journal.rb b/app/models/journal.rb
index 638a98006..e1464a703 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -17,10 +17,10 @@
class Journal < ActiveRecord::Base
include UserScoreHelper
- belongs_to :journalized, :polymorphic => true
+ belongs_to :journalized, :polymorphic => true,:touch => true
# added as a quick fix to allow eager loading of the polymorphic association
# since always associated to an issue, for now
- belongs_to :issue, :foreign_key => :journalized_id
+ belongs_to :issue, :foreign_key => :journalized_id,:touch => true
belongs_to :user
has_many :details, :class_name => "JournalDetail", :dependent => :delete_all
@@ -31,9 +31,8 @@ class Journal < ActiveRecord::Base
#has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy 评论不应该算入
# 被ForgeMessage虚拟关联
has_many :forge_messages, :class_name => 'ForgeMessage',:as =>:forge_message ,:dependent => :destroy
-
has_many :at_messages, as: :at_message, dependent: :destroy
-
+ acts_as_attachable
attr_accessor :indice
acts_as_event :title =>Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.project_index}#{status}: #{o.issue.subject}" },
@@ -46,8 +45,8 @@ class Journal < ActiveRecord::Base
acts_as_activity_provider :type => 'issues',
:author_key => :user_id,
:find_options => {:include => [{:issue => :project}, :details, :user],
- :conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" +
- " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"}
+ :conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" +
+ "(#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"}
before_create :split_private_notes
diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb
index 59da817f4..9e0ce2dd2 100644
--- a/app/models/journals_for_message.rb
+++ b/app/models/journals_for_message.rb
@@ -15,8 +15,9 @@ class JournalsForMessage < ActiveRecord::Base
"m_parent_id", # 留言信息的父留言id
"is_readed", # 留言是否已读
"m_reply_count", # 留言的回复数量
- "m_reply_id" # 回复某留言的留言id(a留言回复了b留言,这是b留言的id)
- "is_comprehensive_evaluation" # 1 教师评论、2 匿评、3 留言
+ "m_reply_id" , # 回复某留言的留言id(a留言回复了b留言,这是b留言的id)
+ "is_comprehensive_evaluation", # 1 教师评论、2 匿评、3 留言
+ "private"
acts_as_tree :foreign_key => 'm_parent_id', :counter_cache => :m_reply_count, :order => "#{JournalsForMessage.table_name}.created_on ASC"
after_destroy :delete_kindeditor_assets
belongs_to :project,
@@ -69,12 +70,21 @@ class JournalsForMessage < ActiveRecord::Base
validates :notes, presence: true, if: :is_homework_jour?
after_create :act_as_activity, :act_as_course_activity, :act_as_course_message, :act_as_at_message, :act_as_user_feedback_message, :act_as_principal_activity, :act_as_student_score
after_create :reset_counters!
+ after_update :update_ativity
after_destroy :reset_counters!
after_save :be_user_score
after_destroy :down_user_score
# default_scope { where('m_parent_id IS NULL') }
+ #动态的更新
+ def update_activity
+ update_course_activity(self.class, self.id)
+ update_user_activity(self.class, self.id)
+ update_forge_activity(self.class, self.id)
+ update_org_activity(self.class, self.id)
+ update_principal_activity(self.class, self.id)
+ end
def self.create_by_user? user
if user.anonymous?
return false
diff --git a/app/models/mailer.rb b/app/models/mailer.rb
index 1cbe7421c..318de2942 100644
--- a/app/models/mailer.rb
+++ b/app/models/mailer.rb
@@ -155,8 +155,6 @@ class Mailer < ActionMailer::Base
# 发送内容: 项目【缺陷,讨论区,新闻】,课程【通知,留言,新闻】, 贴吧, 个人留言
def send_for_user_activities(user, date_to, days)
date_from = date_to - days.days
- subject = "[ #{user.show_name}#{l(:label_day_mail)}]"
- @subject = " #{user.show_name}#{l(:label_day_mail)}"
date_from = "#{date_from} 17:59:59"
date_to = "#{date_to} 17:59:59"
# 生成token用于直接点击登录
@@ -268,10 +266,14 @@ class Mailer < ActionMailer::Base
has_content = [@issues,@issues_journals,@course_messages,@project_messages,@course_news,@course_news_comments,@project_news,@project_news_comments,@project_attachments,
@course_journal_messages,@user_journal_messages,@project_journal_messages,@forums,@memos,@attachments,@bids,@wiki_contents].any? {|o| !o.empty?}
-
+ total_count = @issues.count + @issues_journals.count + @course_messages.count + @project_messages.count + @course_news.count + @course_news_comments.count + @project_news.count + @project_news_comments.count +
+ @project_attachments.count + @course_journal_messages.count + @user_journal_messages.count + @project_journal_messages.count + @forums.count + @memos.count + @attachments.count +
+ @bids.count + @wiki_contents.count
+ subject = "[ #{user.show_name}#{l(:label_day_mail_first)}#{total_count}#{l(:label_day_mail_last)}]"
+ @subject = " #{user.show_name}#{l(:label_day_mail_first)}#{total_count}#{l(:label_day_mail_last)}"
mylogger.debug "Sent activity mail : #{user.mail} - #{has_content}"
#有内容才发,没有不发
- mail :to => user.mail,:subject => subject if has_content
+ mail :to => user.mail,:subject => @subject if has_content
end
# 作业截止时间邮件提醒
diff --git a/app/models/message.rb b/app/models/message.rb
index 4cdae1f6e..b11b2cc1d 100644
--- a/app/models/message.rb
+++ b/app/models/message.rb
@@ -23,6 +23,8 @@ class Message < ActiveRecord::Base
belongs_to :board,:touch => true
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
+ # has_many :org_subfield_messages, :dependent => :destroy
+ # has_many :org_subfields, :through => :org_subfield_messages
acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC"
acts_as_attachable
@@ -34,6 +36,8 @@ class Message < ActiveRecord::Base
has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy
# 课程动态
has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy
+ has_many :user_acts, :class_name => 'UserActivity',:as =>:user_act ,:dependent => :destroy
+
# end
# 课程/项目 消息
has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy
@@ -42,6 +46,8 @@ class Message < ActiveRecord::Base
has_many :ActivityNotifies,:as => :activity, :dependent => :destroy
+ after_destroy :delete_org_activities
+
acts_as_searchable :columns => ['subject', 'content'],
:include => {:board => :project},
:project_key => "#{Board.table_name}.project_id",
@@ -71,7 +77,7 @@ class Message < ActiveRecord::Base
validate :cannot_reply_to_locked_topic, :on => :create
after_create :add_author_as_watcher, :reset_counters!
- after_update :update_messages_board
+ after_update :update_messages_board, :update_activity
after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets
after_create :act_as_activity,:act_as_course_activity,:be_user_score,:act_as_forge_activity, :act_as_system_message, :send_mail, :act_as_student_score, :act_as_at_message
@@ -148,6 +154,10 @@ class Message < ActiveRecord::Base
usr && usr.logged? && (usr.allowed_to?(:edit_messages, course) || (self.author == usr && usr.allowed_to?(:edit_own_messages, course)))
end
+ def org_subfield_editable_by?(usr)
+ usr && usr.logged? && (usr.admin? || self.author == usr ||usr.admin_of_org?(self.board.org_subfield.organization))
+ end
+
def course_destroyable_by?(usr)
usr && usr.logged? && (usr.allowed_to?(:delete_messages, course) || (self.author == usr && usr.allowed_to?(:delete_own_messages, course)))
end
@@ -172,6 +182,13 @@ class Message < ActiveRecord::Base
def get_notify_is_read()
return @notify_is_read
end
+ #动态的更新
+ def update_activity
+ update_course_activity(self.class, self.id)
+ update_user_activity(self.class, self.id)
+ update_forge_activity(self.class, self.id)
+ update_org_activity(self.class, self.id)
+ end
private
@@ -190,9 +207,8 @@ class Message < ActiveRecord::Base
# Description
def act_as_forge_activity
# 如果project为空,那么就是课程相关的消息
- if !self.board.project.nil? && self.parent_id.nil?
- self.forge_acts << ForgeActivity.new(:user_id => self.author_id,
- :project_id => self.board.project.id)
+ if self.board.project_id != -1 && self.parent_id.nil?
+ self.forge_acts << ForgeActivity.new(:user_id => self.author_id, :project_id => self.board.project.id)
end
end
@@ -225,7 +241,7 @@ class Message < ActiveRecord::Base
end
end
end
- else # 项目相关
+ elsif self.project # 项目相关
if self.parent_id.nil? # 主贴
self.project.members.each do |m|
if m.user_id != self.author_id
@@ -310,4 +326,8 @@ class Message < ActiveRecord::Base
end
end
end
+
+ def delete_org_activities
+ OrgActivity.where("org_act_type='Message' and org_act_id =#{self.id} and container_type='OrgSubfield'").destroy_all
+ end
end
diff --git a/app/models/news.rb b/app/models/news.rb
index a7407c91f..e00437fd8 100644
--- a/app/models/news.rb
+++ b/app/models/news.rb
@@ -56,7 +56,7 @@ class News < ActiveRecord::Base
acts_as_watchable
after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity,:act_as_system_message, :add_author_as_watcher, :send_mail
-
+ after_update :update_activity
after_destroy :delete_kindeditor_assets
scope :visible, lambda {|*args|
@@ -68,6 +68,14 @@ class News < ActiveRecord::Base
}
safe_attributes 'title', 'summary', 'description', 'sticky'
+ #动态的更新
+ def update_activity
+ update_course_activity(self.class, self.id)
+ update_user_activity(self.class, self.id)
+ update_org_activity(self.class, self.id)
+ update_forge_activity(self.class, self.id)
+ end
+
def visible?(user=User.current)
!user.nil? && user.allowed_to?(:view_news, project)
end
diff --git a/app/models/org_document_comment.rb b/app/models/org_document_comment.rb
index e2ce350ce..75db910c3 100644
--- a/app/models/org_document_comment.rb
+++ b/app/models/org_document_comment.rb
@@ -1,20 +1,36 @@
-class OrgDocumentComment < ActiveRecord::Base
- attr_accessible :content, :creator_id, :organization_id, :parent_id, :reply_id, :title,:sticky,:locked
- include Redmine::SafeAttributes
- belongs_to :organization
- belongs_to :creator, :class_name => 'User', :foreign_key => 'creator_id'
- has_many :editor_of_documents, :dependent => :destroy
- acts_as_tree :order => "#{OrgDocumentComment.table_name}.sticky asc, #{OrgDocumentComment.table_name}.created_at desc"
- has_many :org_acts, :class_name => 'OrgActivity',:as =>:org_act ,:dependent => :destroy
- after_create :document_save_as_org_activity
-
- def document_save_as_org_activity
- if(self.parent().nil?)
- self.org_acts << OrgActivity.new(:user_id => User.current.id, :container_id => self.organization.id, :container_type => 'Organization')
- else
- act = OrgActivity.where("org_act_type='OrgDocumentComment' and org_act_id =?", self.root.id).first
- act.update_attributes(:updated_at => self.updated_at)
- end
- end
-
-end
+class OrgDocumentComment < ActiveRecord::Base
+ attr_accessible :content, :creator_id, :organization_id, :parent_id, :reply_id, :title,:sticky,:locked
+ include Redmine::SafeAttributes
+ belongs_to :organization
+ belongs_to :creator, :class_name => 'User', :foreign_key => 'creator_id'
+ has_many :editor_of_documents, :dependent => :destroy
+ acts_as_tree :order => "#{OrgDocumentComment.table_name}.sticky asc, #{OrgDocumentComment.table_name}.created_at desc"
+ acts_as_attachable
+ has_many :org_acts, :class_name => 'OrgActivity',:as =>:org_act ,:dependent => :destroy
+ after_create :document_save_as_org_activity
+ after_update :update_activity
+
+ #动态的更新
+ def update_activity
+ org_activity = OrgActivity.where("org_act_type='OrgDocumentComment' and org_act_id =?", id).first
+ if org_activity
+ org_activity.updated_at = Time.now
+ org_activity.save
+ end
+ end
+
+ def document_save_as_org_activity
+ if(self.parent().nil?)
+ self.org_acts << OrgActivity.new(:user_id => User.current.id, :container_id => self.organization.id, :container_type => 'Organization')
+ else
+ act = OrgActivity.where("org_act_type='OrgDocumentComment' and org_act_id =?", self.root.id).first
+ act.update_attributes(:updated_at => self.updated_at)
+ end
+ end
+
+
+ def project
+
+ end
+
+end
diff --git a/app/models/org_message.rb b/app/models/org_message.rb
new file mode 100644
index 000000000..baedc77f4
--- /dev/null
+++ b/app/models/org_message.rb
@@ -0,0 +1,15 @@
+class OrgMessage < ActiveRecord::Base
+ belongs_to :user
+ belongs_to :organization
+ has_many :message_alls, :as => :message, :dependent => :destroy
+ validates :message_type, :presence => true
+ validates :message_id, :presence => true
+ validates :organization_id, :presence => true
+ after_create :add_user_message
+
+ def add_user_message
+ if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil?
+ self.message_alls << MessageAll.new(:user_id => self.user_id)
+ end
+ end
+end
\ No newline at end of file
diff --git a/app/models/org_subfield.rb b/app/models/org_subfield.rb
index f95bb3eba..0747114ca 100644
--- a/app/models/org_subfield.rb
+++ b/app/models/org_subfield.rb
@@ -1,9 +1,26 @@
-class OrgSubfield < ActiveRecord::Base
- belongs_to :organization, :foreign_key => :organization_id
- has_many :org_document_comments, :dependent => :destroy
- has_many :files
- acts_as_attachable
-
- def project
- end
+class OrgSubfield < ActiveRecord::Base
+ belongs_to :organization, :foreign_key => :organization_id
+ has_many :org_document_comments, :dependent => :destroy
+ has_many :files
+ has_many :org_subfield_messages, :dependent => :destroy
+ has_many :messages, :through => :org_subfield_messages
+ has_many :boards, :dependent => :destroy
+ acts_as_attachable
+ after_create :create_board_sync
+ # 创建资源栏目讨论区
+ def create_board_sync
+ @board = self.boards.build
+ #self.name=" #{l(:label_borad_course) }"
+ @board.name = " #{l(:label_borad_org_subfield) }"#self.name
+ @board.description = self.name.to_s
+ @board.project_id = -1
+ if @board.save
+ logger.debug "[OrgSubfield Model] ===> #{@board.to_json}"
+ else
+ logger.error "[OrgSubfield Model] ===> Auto create board when org_subfield saved, because #{@board.full_messages}"
+ end
+ end
+
+ def project
+ end
end
\ No newline at end of file
diff --git a/app/models/org_subfield_message.rb b/app/models/org_subfield_message.rb
new file mode 100644
index 000000000..64dbdfdf5
--- /dev/null
+++ b/app/models/org_subfield_message.rb
@@ -0,0 +1,3 @@
+class OrgSubfieldMessage < ActiveRecord::Base
+ # attr_accessible :title, :body
+end
diff --git a/app/models/organization.rb b/app/models/organization.rb
index 350dc3080..fcb777fb6 100644
--- a/app/models/organization.rb
+++ b/app/models/organization.rb
@@ -9,9 +9,15 @@ class Organization < ActiveRecord::Base
has_many :org_subfields, :dependent => :destroy
has_many :users, :through => :org_members
validates_uniqueness_of :name
- after_create :save_as_org_activity
+ after_create :save_as_org_activity, :add_default_subfields
def save_as_org_activity
OrgActivity.create(:user_id => User.current.id, :org_act_id => self.id, :org_act_type => 'CreateOrganization', :container_id => self.id, :container_type => 'Organization')
end
+
+ def add_default_subfields
+ OrgSubfield.create(:organization_id => self.id, :name => 'activity', :field_type => 'default')
+ OrgSubfield.create(:organization_id => self.id, :name => 'course', :field_type => 'default')
+ OrgSubfield.create(:organization_id => self.id, :name => 'project', :field_type => 'default')
+ end
end
diff --git a/app/models/poll.rb b/app/models/poll.rb
index 67bb9f5a8..41bfe8a72 100644
--- a/app/models/poll.rb
+++ b/app/models/poll.rb
@@ -14,7 +14,7 @@ class Poll < ActiveRecord::Base
# 课程消息
has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy
after_save :act_as_course_message, :act_as_activity, :act_as_course_activity
-
+ after_update :update_activity
acts_as_event :title => Proc.new {|o| "#{l(:label_course_poll)}: #{o.polls_name}" },
:description => :polls_description,
:datetime => :published_at,
@@ -32,6 +32,13 @@ class Poll < ActiveRecord::Base
self.acts << Activity.new(:user_id => self.user_id)
end
+ #动态的更新
+ def update_activity
+ update_course_activity(self.class, self.id)
+ update_user_activity(self.class, self.id)
+ update_org_activity(self.class, self.id)
+ end
+
#课程动态公共表记录
def act_as_course_activity
if self.polls_type == "Course"
diff --git a/app/models/shield_activity.rb b/app/models/shield_activity.rb
new file mode 100644
index 000000000..8f8447dcf
--- /dev/null
+++ b/app/models/shield_activity.rb
@@ -0,0 +1,3 @@
+class ShieldActivity < ActiveRecord::Base
+
+end
\ No newline at end of file
diff --git a/app/models/system_message.rb b/app/models/system_message.rb
index a05610da7..65623c104 100644
--- a/app/models/system_message.rb
+++ b/app/models/system_message.rb
@@ -7,6 +7,7 @@ class SystemMessage < ActiveRecord::Base
validates_length_of :description, maximum: 10000
has_many :message_alls, :class_name => 'MessageAll',:as =>:message, :dependent => :destroy
+ acts_as_attachable
# 系统消息放置总消息列表
after_create :add_system_message
diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb
index 5d60238bf..6f2819f53 100644
--- a/app/services/courses_service.rb
+++ b/app/services/courses_service.rb
@@ -193,9 +193,12 @@ class CoursesService
@course.extra = 'course' + DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d_%H-%M-%S').to_s
@course.send(:safe_attributes=, params[:course], current_user)
#@course.safe_attributes(current_user,params[:course])
+ @course.password = params[:course][:password]
@course.tea_id = current_user.id
@course.term = params[:term]
@course.time = params[:time]
+ @course.end_term = params[:end_term]
+ @course.end_time = params[:end_time]
#@course.school_id = params[:occupation]
@course.school_id = current_user.user_extensions.school_id
@course.setup_time = params[:setup_time]
diff --git a/app/views/admin/messages.html.erb b/app/views/admin/messages.html.erb
index e4d053d49..040dd0fe8 100644
--- a/app/views/admin/messages.html.erb
+++ b/app/views/admin/messages.html.erb
@@ -19,6 +19,7 @@