diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index cf4e6a8e9..b878a14ac 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -251,7 +251,7 @@ class AttachmentsController < ApplicationController @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","downloads") + @old_attachment.attributes = @attachment.attributes.dup.except("id","container_id","container_type","is_public","downloads", "quotes") @old_attachment.save #删除当前记录 @attachment.delete diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index a40b24fe2..b288629c8 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -406,10 +406,14 @@ class FilesController < ApplicationController @container_type = 2 @containers = [ OrgSubfield.includes(:attachments).reorder(sort).find(@org_subfield.id)] @organization = Organization.find(@containers.first.organization_id) - show_attachments @containers - @tag_list = attachment_tag_list @all_attachments - @page = params[:page] || 1 - render :layout => 'base_org' + if @organization.is_public? or User.current.admin? or User.current.member_of_org?(@organization) + show_attachments @containers + @tag_list = attachment_tag_list @all_attachments + @page = params[:page] || 1 + render :layout => 'base_org' + else + render_403 + end # @subfield = params[:org_subfield_id] end @@ -555,7 +559,8 @@ class FilesController < ApplicationController end end # 更新课程英雄榜得分 - update_contributor_score(@course, attachments[:files].first) + course_member_score(@course.id, attachments[:files].first.author_id, "Attachment") + # end # end # TODO: 临时用 nyan sort_init 'created_on', 'desc' @@ -628,18 +633,6 @@ class FilesController < ApplicationController end end - def update_contributor_score(course, file ) - course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", course.id, file.author.id).first - if course_contributor_score.nil? - CourseContributorScore.create(:course_id => course.id, :user_id => file.author.id, :message_num => 0, :message_reply_num => 0, - :news_reply_num => 0, :resource_num => 5, :journal_num => 0, :journal_reply_num => 0, :total_score => 5) - else - score = course_contributor_score.resource_num + 5 - total_score = course_contributor_score.total_score + 5 - course_contributor_score.update_attributes(:resource_num => score, :total_score => total_score) - end - end - def get_project_tag_name_by_type_nmuber type case type when "1" @@ -859,7 +852,15 @@ class FilesController < ApplicationController q = "%#{@q.strip}%" @result = find_org_subfield_attache q,@org_subfield,sort @result = visable_attachemnts @result - @result = @result.select{|attachment| attachment.tag_list.include?(@tag_name)} unless @tag_name.blank? + if params[:other] + @result = @result.select{|attachment| + attachment.tag_list.exclude?('软件') && + attachment.tag_list.exclude?('媒体') && + attachment.tag_list.exclude?('代码') + } + else + @result = @result.select{|attachment| attachment.tag_list.include?(@tag_name)} unless @tag_name.blank? + end @searched_attach = paginateHelper @result,10 @tag_list = get_org_subfield_tag_list @org_subfield diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 00b11323b..ba6c136bb 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -17,9 +17,9 @@ class HomeworkCommonController < ApplicationController @page = params[:page] ? params[:page].to_i + 1 : 0 @is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) if @is_teacher - @homeworks = @course.homework_commons.order("created_at desc").limit(10).offset(@page * 10) + @homeworks = @course.homework_commons.order("updated_at desc").limit(10).offset(@page * 10) else - @homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at desc").limit(10).offset(@page * 10) + @homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("updated_at desc").limit(10).offset(@page * 10) end @is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher)) @is_new = params[:is_new] diff --git a/app/controllers/org_subfields_controller.rb b/app/controllers/org_subfields_controller.rb index 2a4bcf9c8..9337c5fd2 100644 --- a/app/controllers/org_subfields_controller.rb +++ b/app/controllers/org_subfields_controller.rb @@ -33,61 +33,65 @@ class OrgSubfieldsController < ApplicationController domain = Secdomain.where("subname=?", request.subdomain).first @organization = Organization.find(domain.pid) end - @org_subfield = OrgSubfield.find_by_sql("select distinct org_subfields.* from org_subfields,"+ - "subfield_subdomain_dirs where org_subfields.id = subfield_subdomain_dirs.org_subfield_id and "+ - " org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir_name]}'").first - if @org_subfield.field_type == 'Post' + if @organization.is_public? or User.current.admin? or User.current.member_of_org?(@organization) + @org_subfield = OrgSubfield.find_by_sql("select distinct org_subfields.* from org_subfields,"+ + "subfield_subdomain_dirs where org_subfields.id = subfield_subdomain_dirs.org_subfield_id and "+ + " org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir_name]}'").first + if @org_subfield.field_type == 'Post' @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) #redirect_to organization_path(@organization, :org_subfield_id => @org_subfield.id) - else - if params[:sort] - params[:sort].split(",").each do |sort_type| - order_by = sort_type.split(":") - case order_by[0] - when "filename" - attribute = "filename" - when "size" - attribute = "filesize" - when "attach_type" - attribute = "attachtype" - when "content_type" - attribute = "created_on" - when "field_file_dense" - attribute = "is_public" - when "downloads" - attribute = "downloads" - when "created_on" - attribute = "created_on" - when "quotes" - attribute = "quotes" - else - attribute = "created_on" - end - @sort = order_by[0] - @order = order_by[1] - if order_by.count == 1 && attribute - sort += "#{Attachment.table_name}.#{attribute} asc " - if sort_type != params[:sort].split(",").last - sort += "," + else + if params[:sort] + params[:sort].split(",").each do |sort_type| + order_by = sort_type.split(":") + case order_by[0] + when "filename" + attribute = "filename" + when "size" + attribute = "filesize" + when "attach_type" + attribute = "attachtype" + when "content_type" + attribute = "created_on" + when "field_file_dense" + attribute = "is_public" + when "downloads" + attribute = "downloads" + when "created_on" + attribute = "created_on" + when "quotes" + attribute = "quotes" + else + attribute = "created_on" end - elsif order_by.count == 2 && order_by[1] - sort += "#{Attachment.table_name}.#{attribute} #{order_by[1]} " - if sort_type != params[:sort].split(",").last - sort += "," + @sort = order_by[0] + @order = order_by[1] + if order_by.count == 1 && attribute + sort += "#{Attachment.table_name}.#{attribute} asc " + if sort_type != params[:sort].split(",").last + sort += "," + end + elsif order_by.count == 2 && order_by[1] + sort += "#{Attachment.table_name}.#{attribute} #{order_by[1]} " + if sort_type != params[:sort].split(",").last + sort += "," + end end end + else + sort = "#{Attachment.table_name}.created_on desc" end - else - sort = "#{Attachment.table_name}.created_on desc" + @container_type = 2 + @containers = [OrgSubfield.includes(:attachments).reorder(sort).find(@org_subfield.id)] + @organization = Organization.find(@containers.first.organization_id) + show_attachments @containers + @tag_list = attachment_tag_list @all_attachments end - @container_type = 2 - @containers = [ OrgSubfield.includes(:attachments).reorder(sort).find(@org_subfield.id)] - @organization = Organization.find(@containers.first.organization_id) - show_attachments @containers - @tag_list = attachment_tag_list @all_attachments + @page = params[:page] || 1 + else + render_403 end - @page = params[:page] || 1 #render :layout => 'base_org' end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index b650afe1b..3d5030c29 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -406,6 +406,7 @@ class ProjectsController < ApplicationController end flash.now[:error] = html if !html.to_s.blank? end + # for:设置默认分支 scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first @repository = Repository.factory(scm) @repository.is_default = @project.repository.nil? diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index f7845d6f1..9bb6055ee 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -140,7 +140,7 @@ class RepositoriesController < ApplicationController attrs = {:parent_id => project.parent_id}.reject {|k,v| v.nil?} redirect_to new_project_url(attrs, :course => '0') else - redirect_to settings_project_url(project) + redirect_to project_path(project) end } format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => project.id) } @@ -431,7 +431,10 @@ update def entry entry_and_raw(false) - render :layout => 'base_projects' + @content = @repository.cat(@path, @rev) + if is_entry_text_data?(@content, @path) + render :layout => 'base_projects' + end end def entry_and_raw(is_raw) @@ -443,9 +446,7 @@ update @content = @repository.cat(@path, @rev) (show_error_not_found; return) unless @content - if is_raw || - (@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) || - ! is_entry_text_data?(@content, @path) + if is_raw || (@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) || !is_entry_text_data?(@content, @path) # Force the download send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) } send_type = Redmine::MimeType.of(@path) diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index a38d83851..0c8bb6c01 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -303,6 +303,7 @@ class StudentWorkController < ApplicationController stu_project.save end end + @homework.update_attributes(:updated_at => Time.now) update_course_activity(@homework.class,@homework.id) update_user_activity(@homework.class,@homework.id) update_org_activity(@homework.class,@homework.id) @@ -500,6 +501,10 @@ class StudentWorkController < ApplicationController when 3 #学生评分 学生评分显示平均分 @work.student_score = @work.student_works_scores.where(:reviewer_role => 3).average(:score).try(:round, 2).to_f end + @homework.update_attributes(:updated_at => Time.now) + update_course_activity(@homework.class,@homework.id) + update_user_activity(@homework.class,@homework.id) + update_org_activity(@homework.class,@homework.id) if @work.save respond_to do |format| format.js diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 61f6118ad..ea984aa80 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -58,6 +58,7 @@ class UsersController < ApplicationController helper :sort helper :attachments include SortHelper + include ApplicationHelper helper :custom_fields include CustomFieldsHelper include AvatarHelper @@ -425,9 +426,9 @@ class UsersController < ApplicationController homework = HomeworkCommon.find params[:homework].to_i if !params[:search].nil? search = "%#{params[:search].to_s.strip.downcase}%" - @course = @user.courses.where("#{Course.table_name}.id != #{homework.course_id} and #{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p",:p=>search).select { |course| @user.allowed_to?(:as_teacher,course)} + @course = @user.courses.where("is_delete = 0 and #{Course.table_name}.id != #{homework.course_id} and #{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p",:p=>search).select { |course| @user.allowed_to?(:as_teacher,course)} else - @course = @user.courses.where("#{Course.table_name}.id != #{homework.course_id}").select { |course| @user.allowed_to?(:as_teacher,course)} + @course = @user.courses.where("is_delete = 0 and #{Course.table_name}.id != #{homework.course_id}").select { |course| @user.allowed_to?(:as_teacher,course)} end @search = params[:search] #这里仅仅是传递需要发送的资源id @@ -690,6 +691,11 @@ class UsersController < ApplicationController end student_work.save + homework.update_attributes(:updated_at => Time.now) + update_course_activity(homework.class,homework.id) + update_user_activity(homework.class,homework.id) + update_org_activity(homework.class,homework.id) + flash[:notice] = l(:notice_successful_create) redirect_to student_work_index_url(:homework => params[:homework]) else @@ -1693,17 +1699,17 @@ class UsersController < ApplicationController @flag = true if params[:send_id].present? send_id = params[:send_id] - ori = Attachment.find_by_id(send_id) + @ori = Attachment.find_by_id(send_id) course_ids = params[:course_ids] if course_ids.nil? @flag = false end unless course_ids.nil? course_ids.each do |id| - next if ori.blank? + 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 + 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 @@ -1711,21 +1717,21 @@ class UsersController < ApplicationController end end next if @exist - attach_copied_obj = ori.copy - attach_copied_obj.tag_list.add(ori.tag_list) # tag关联 + 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 + attach_copied_obj.copy_from = @ori.copy_from.nil? ? @ori.id : @ori.copy_from #发送要添加copy_from if attach_copied_obj.attachtype == nil attach_copied_obj.attachtype = 4 end if attach_copied_obj.save # 更新引用次数 - quotes = ori.quotes.to_i + 1 - ori.update_attribute(:quotes, quotes) unless ori.nil? - ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) + quotes = @ori.quotes.to_i + 1 + @ori.update_attribute(:quotes, quotes) unless @ori.nil? + @ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) end @save_message = attach_copied_obj.errors.full_messages end @@ -1837,6 +1843,7 @@ class UsersController < ApplicationController Project.find(project_id).project_score.attach_num + 1) end end + @ori = ori end elsif params[:send_ids].present? send_ids = params[:send_ids].split(" ") @@ -1941,6 +1948,7 @@ class UsersController < ApplicationController end end end + @ori = ori elsif params[:send_ids].present? send_ids = params[:send_ids].split(" ") subfield_id = params[:subfield] diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index d1aa67483..e6d1d9117 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -276,7 +276,7 @@ class WordsController < ApplicationController ids = params[:asset_id].split(',') update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE end - + @homework_common.update_attributes(:updated_at => Time.now) 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) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 22890fd9a..594a4380d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -117,56 +117,102 @@ module ApplicationHelper when "HomeworkCommon" if course_contributor_score.nil? CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0, - :news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :homework_journal_num => 1 , :total_score => 1) + :news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :homework_journal_num => 1) else score = course_contributor_score.homework_journal_num + 1 - total_score = course_contributor_score.total_score + 1 - course_contributor_score.update_attributes(:homework_journal_num => score, :total_score => total_score) + course_contributor_score.update_attributes(:homework_journal_num => score) end - when "JournalForMessage" + # 课程留言 + when "Course" if course_contributor_score.nil? CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0, - :news_reply_num => 0, :resource_num => 0, :journal_num => 1, :journal_reply_num => 0, :total_score => 1) + :news_reply_num => 0, :resource_num => 0, :journal_num => 1, :journal_reply_num => 0) else score = course_contributor_score.journal_num + 1 - total_score = course_contributor_score.total_score + 1 - course_contributor_score.update_attributes(:journal_num => score, :total_score => total_score) + course_contributor_score.update_attributes(:journal_num => score) end when "Message" if course_contributor_score.nil? - CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 2, :message_reply_num => 0, - :news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 2) + CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 1, :message_reply_num => 0, + :news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0) else - score = course_contributor_score.message_num + 2 - total_score = course_contributor_score.total_score + 2 - course_contributor_score.update_attributes(:message_num => score, :total_score => total_score) + score = course_contributor_score.message_num + 1 + course_contributor_score.update_attributes(:message_num => score) end when "MessageReply" if course_contributor_score.nil? CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 1, - :news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 1) + :news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0) else score = course_contributor_score.message_reply_num + 1 - total_score = course_contributor_score.total_score + 1 - course_contributor_score.update_attributes(:message_reply_num => score, :total_score => total_score) + course_contributor_score.update_attributes(:message_reply_num => score) end when "NewReply" if course_contributor_score.nil? CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0, - :news_reply_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 1) + :news_reply_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0) else score = course_contributor_score.news_reply_num + 1 - total_score = course_contributor_score.total_score + 1 - course_contributor_score.update_attributes(:news_reply_num => score, :total_score => total_score) + course_contributor_score.update_attributes(:news_reply_num => score) end when "News" if course_contributor_score.nil? CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0, - :news_reply_num => 0, :news_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 1) + :news_reply_num => 0, :news_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0) else score = course_contributor_score.news_num + 1 - total_score = course_contributor_score.total_score + 1 - course_contributor_score.update_attributes(:news_num => score, :total_score => total_score) + course_contributor_score.update_attributes(:news_num => score) + end + when "Attachment" + if course_contributor_score.nil? + CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0, + :news_reply_num => 0, :news_num => 0, :resource_num => 1, :journal_num => 0, :journal_reply_num => 0) + else + score = course_contributor_score.resource_num + 1 + course_contributor_score.update_attributes(:resource_num => score) + end + end + end + + # 删除某条记录相应减少课程统计数 + def down_course_score_num (course_id,user_id,type) + course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", course_id, user_id).first + case type + when "HomeworkCommon" + unless course_contributor_score.nil? + score = course_contributor_score.homework_journal_num - 1 + course_contributor_score.update_attribute(:homework_journal_num, score < 0 ? 0 : score) + end + # 课程留言 + when "Course" + unless course_contributor_score.nil? + score = course_contributor_score.journal_num - 1 + course_contributor_score.update_attribute(:journal_num, score < 0 ? 0 : score) + end + when "Message" + unless course_contributor_score.nil? + score = course_contributor_score.message_num - 1 + course_contributor_score.update_attribute(:message_num, score < 0 ? 0 : score) + end + when "MessageReply" + unless course_contributor_score.nil? + score = course_contributor_score.message_reply_num - 1 + course_contributor_score.update_attribute(:message_reply_num, score < 0 ? 0 : score) + end + when "NewReply" + unless course_contributor_score.nil? + score = course_contributor_score.news_reply_num - 1 + course_contributor_score.update_attribute(:news_reply_num, score < 0 ? 0 : score) + end + when "News" + unless course_contributor_score.nil? + score = course_contributor_score.news_num - 1 + course_contributor_score.update_attribute(:news_num, score < 0 ? 0 : score) + end + when "Attachment" + unless course_contributor_score.nil? + score = course_contributor_score.resource_num - 1 + course_contributor_score.update_attribute(:resource_num, score < 0 ? 0 : score) end end end @@ -2049,9 +2095,11 @@ module ApplicationHelper course = attachment.container candown= User.current.member_of_course?(course) || (course.is_public==1 && attachment.is_public == 1) elsif attachment.container.is_a?(OrgSubfield) - candown = true + org = attachment.container.organization + candown = User.current.member_of_org?(org) || (org.is_public && attachment.is_public == 1) elsif attachment.container.is_a?(OrgDocumentComment) - candown = true + org = attachment.container.organization + candown = User.current.member_of_org?(org) || (org.is_public && attachment.is_public == 1) elsif (attachment.container.has_attribute?(:board) || attachment.container.has_attribute?(:board_id)) && attachment.container.board && attachment.container.board.course course = attachment.container.board.course diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb index 6b748649b..238999a71 100644 --- a/app/helpers/files_helper.rb +++ b/app/helpers/files_helper.rb @@ -126,7 +126,7 @@ module FilesHelper (attachment.container_type == "Course" && User.current.allowed_to?(:as_teacher,Course.find(attachment.container_id)))|| (attachment.container_type == "Course" && User.current.member_of_course?(Course.find(attachment.container_id)) && attachment.is_publish == 1)|| attachment.author_id == User.current.id || - attachment.container_type == "OrgSubfield" + (attachment.container_type == "OrgSubfield" and User.current.member_of_org?(attachment.container.organization)) result << attachment end end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 82f648ad9..9f0c2c559 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -43,6 +43,7 @@ class Attachment < ActiveRecord::Base #elasticsearch include Elasticsearch::Model + include ApplicationHelper #elasticsearch kaminari init Kaminari::Hooks.init Elasticsearch::Model::Response::Response.__send__ :include, Elasticsearch::Model::Response::Pagination::Kaminari @@ -92,7 +93,7 @@ class Attachment < ActiveRecord::Base after_save :act_as_course_activity after_create :office_conver, :be_user_score,:act_as_forge_activity,:create_attachment_ealasticsearch_index after_update :office_conver, :be_user_score,:update_attachment_ealasticsearch_index - after_destroy :delete_from_disk,:down_user_score,:delete_attachment_ealasticsearch_index, :decrease_attchments_count + after_destroy :delete_from_disk,:down_user_score,:delete_attachment_ealasticsearch_index, :decrease_attchments_count, :down_course_score # add by nwb # 获取所有可公开的资源文件列表 @@ -655,6 +656,12 @@ class Attachment < ActiveRecord::Base self.container.project_score.update_attribute(:attach_num, attach_count < 0 ? 0 : attach_count) end end + + def down_course_score + if self.container_type == "Course" + down_course_score_num(self.container_id, self.author_id, "Attachment") + end + end end # Delete the previous articles index in Elasticsearch diff --git a/app/models/comment.rb b/app/models/comment.rb index 4d7af1d73..b87203a50 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -36,6 +36,7 @@ class Comment < ActiveRecord::Base validates_presence_of :commented, :author, :comments safe_attributes 'comments' after_create :send_mail, :act_as_system_message, :act_as_student_score + after_destroy :down_course_score def act_as_system_message if self.commented.course @@ -86,4 +87,11 @@ class Comment < ActiveRecord::Base end end + # 课程新闻数减少 + def down_course_score + if self.commented.course + down_course_score_num(self.commented.course.id, self.author_id, "NewReply") + end + end + end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 7990979e4..dae779b65 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -73,7 +73,7 @@ class JournalsForMessage < ActiveRecord::Base #after_update :update_activity after_destroy :reset_counters! after_save :be_user_score - after_destroy :down_user_score + after_destroy :down_user_score, :down_course_score # default_scope { where('m_parent_id IS NULL') } @@ -184,6 +184,7 @@ class JournalsForMessage < ActiveRecord::Base end end end + # 更新用户分数 -by zjc def down_user_score #删除了留言回复 @@ -286,10 +287,19 @@ class JournalsForMessage < ActiveRecord::Base # 课程成员得分(活跃度) def act_as_student_score if self.jour_type == "Course" - course_member_score(self.jour_id, self.user_id, "JournalForMessage") + course_member_score(self.jour_id, self.user_id, "Course") elsif self.jour_type == "HomeworkCommon" course_member_score(self.jour.course_id, self.user_id, "HomeworkCommon") end end + # 删除操作的时候相应扣掉回复数 + def down_course_score + if self.jour_type == "Course" + down_course_score_num(self.jour_id, self.user_id, "Course") + elsif self.jour_type == "HomeworkCommon" + down_course_score_num(self.jour.course_id, self.user_id, "HomeworkCommon") + end + end + end diff --git a/app/models/message.rb b/app/models/message.rb index 44f2d2c80..0ddc6f8e0 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -79,7 +79,7 @@ class Message < ActiveRecord::Base after_create :add_author_as_watcher, :reset_counters!, :add_boards_count after_update :update_messages_board, :update_activity - after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets, :decrease_boards_count + after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets, :decrease_boards_count, :down_course_score 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 #before_save :be_user_score @@ -354,6 +354,18 @@ class Message < ActiveRecord::Base end end + # 删除帖子的时候更新课程帖子总数, 删除回复的时候减少总数 + def down_course_score + if self.course + if self.parent_id.nil? # 发帖 + down_course_score_num(self.course.id, self.author_id, "Message") + else + # 回帖 + down_course_score_num(self.course.id, self.author_id, "MessageReply") + 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 diff --git a/app/models/news.rb b/app/models/news.rb index 028b6d737..6746d90cd 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -61,7 +61,7 @@ class News < ActiveRecord::Base after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity,:act_as_system_message, :add_author_as_watcher, :send_mail, :add_news_count, :act_as_student_score after_update :update_activity - after_destroy :delete_kindeditor_assets, :decrease_news_count, :delete_org_activities + after_destroy :delete_kindeditor_assets, :decrease_news_count, :delete_org_activities, :down_course_score scope :visible, lambda {|*args| includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args)) @@ -195,10 +195,18 @@ class News < ActiveRecord::Base OrgActivity.where("container_type='OrgSubfield' and org_act_type='News' and org_act_id=?", self.id).destroy_all end + # 新增新闻统计数增加 def act_as_student_score if self.course course_member_score(self.course.id, self.author_id, "News") end end + # 删除新闻统计数减少 + def down_course_score + if self.course + down_course_score_num(self.course.id, self.author_id, "News") + end + end + end \ No newline at end of file diff --git a/app/views/courses/_recommendation.html.erb b/app/views/courses/_recommendation.html.erb index f26c5fd41..f697383ca 100644 --- a/app/views/courses/_recommendation.html.erb +++ b/app/views/courses/_recommendation.html.erb @@ -6,7 +6,7 @@
<%=link_to e_course.name, course_path(e_course.id), :class => "hidden fl w170" %>
+<%=link_to e_course.name, course_path(e_course.id), :class => "hidden fl w170" %>
<% if e_course.attachments.count > 0 %> <%= l(:project_module_attachments) %>(<%= link_to e_course.attachments.count, course_files_path(e_course), :class => "linkBlue2" %>) @@ -14,6 +14,7 @@ <% if e_course.homework_commons.count > 0 %> <%= l(:label_homework_commont) %>(<%= link_to e_course.homework_commons.count, homework_common_index_path(:course=>e_course.id), :class => "linkBlue2" %>) <% end %> +
文件大小:<%= number_to_human_size(file.filesize) %>
-下载<%= file.downloads%> | 引用<%= file.quotes.nil? ? 0:file.quotes %>
-文件大小:<%= number_to_human_size(file.filesize) %>
+下载<%= file.downloads%> | 引用<%= file.quotes.nil? ? 0:file.quotes %>
+共有 <%= @all_attachments.count %> 个资源
+共有 <%= User.current.member_of_org?(@org_subfield.organization) ? @all_attachments.count : @all_attachments.select{|attach| attach.is_public == 1 }.count %> 个资源
<% if @order == "asc" %> 按 <%= link_to "时间",params.merge(:sort=>"created_on:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"created_on"} %> / diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index 2a44f2980..8f6628b62 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -143,18 +143,19 @@ <% unless contributor_course_scor(@course.id).count == 0 %>