diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index a2902e3fc..b15be4896 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -374,6 +374,9 @@ class FilesController < ApplicationController if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') Mailer.run.attachments_added(attachments[:files]) end + # 更新课程英雄榜得分 + update_contributor_score(@course, attachments[:files].first) + # end if params[:course_attachment_type] && params[:course_attachment_type].is_a?(Array) params[:course_attachment_type].each do |type| tag_name = get_tag_name_by_type_number type @@ -423,6 +426,20 @@ class FilesController < ApplicationController end end + def update_contributor_score(course, file ) + unless file.author.allowed_to?(:as_teacher, course) + 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 + end + def get_tag_name_by_type_number type case type when "1" diff --git a/app/controllers/org_courses_controller.rb b/app/controllers/org_courses_controller.rb index 3d1d313c5..d054e41de 100644 --- a/app/controllers/org_courses_controller.rb +++ b/app/controllers/org_courses_controller.rb @@ -3,7 +3,9 @@ class OrgCoursesController < ApplicationController org_ids = params[:orgNames] @course = Course.find(params[:course_id]) org_ids.each do |org_id| - OrgCourse.create(:organization_id => org_id.to_i, :course_id => params[:course_id].to_i, :created_at => Time.now) + if OrgCourse.where("organization_id =? and course_id =?", org_id.to_i, params[:course_id].to_i).count == 0 + OrgCourse.create(:organization_id => org_id.to_i, :course_id => params[:course_id].to_i, :created_at => Time.now) + end end respond_to do |format| format.js diff --git a/app/controllers/org_document_comments_controller.rb b/app/controllers/org_document_comments_controller.rb index 61a27c433..776bd132d 100644 --- a/app/controllers/org_document_comments_controller.rb +++ b/app/controllers/org_document_comments_controller.rb @@ -38,12 +38,19 @@ class OrgDocumentCommentsController < ApplicationController act.update_attributes(:updated_at => @org_document.updated_at) end respond_to do |format| - format.html {redirect_to organization_org_document_comments_path(:organization_id => @org_document.organization.id)} + format.html { + if params[:flag] == 0 + redirect_to organization_org_document_comments_path(:organization_id => @org_document.organization.id) + else + redirect_to org_document_comment_path(@org_document.root.id, :organization_id => @org_document.organization.id) + end + } end end def edit @org_document = OrgDocumentComment.find(params[:id]) + @flag = params[:flag] @organization = Organization.find(params[:organization_id]) end diff --git a/app/controllers/org_projects_controller.rb b/app/controllers/org_projects_controller.rb index 29e60a62a..a455ce408 100644 --- a/app/controllers/org_projects_controller.rb +++ b/app/controllers/org_projects_controller.rb @@ -3,7 +3,9 @@ class OrgProjectsController < ApplicationController org_ids = params[:orgNames] @project = Project.find(params[:project_id]) org_ids.each do |org_id| - OrgProject.create(:organization_id => org_id.to_i, :project_id => params[:project_id].to_i, :created_at => Time.now) + if OrgProject.where("organization_id =? and project_id =?", org_id.to_i, @project.id).count == 0 + OrgProject.create(:organization_id => org_id.to_i, :project_id => params[:project_id].to_i, :created_at => Time.now) + end end respond_to do |format| format.js diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 0d22ab461..ba4dda939 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -175,4 +175,75 @@ class OrganizationsController < ApplicationController 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 inner join org_courses on courses.id = org_courses.course_id where org_courses.organization_id != #{@organization.id} and members.user_id = #{User.current.id} and courses.name like '#{condition}'" + 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}'" + user_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 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}'" + user_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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a65ed639c..046e0c5a0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -83,34 +83,38 @@ module ApplicationHelper when "JournalForMessage" 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) + :news_reply_num => 0, :resource_num => 0, :journal_num => 1, :journal_reply_num => 0, :total_score => 1) else score = course_contributor_score.journal_num + 1 - course_contributor_score.update_attributes(:journal_num => score) + total_score = course_contributor_score.total_score + 1 + course_contributor_score.update_attributes(:journal_num => score, :total_score => total_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) + :news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 2) else score = course_contributor_score.message_num + 2 - course_contributor_score.update_attributes(:message_num => score) + total_score = course_contributor_score.total_score + 2 + course_contributor_score.update_attributes(:message_num => score, :total_score => total_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) + :news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 1) else score = course_contributor_score.message_reply_num + 1 - course_contributor_score.update_attributes(:message_reply_num => score) + total_score = course_contributor_score.total_score + 1 + course_contributor_score.update_attributes(:message_reply_num => score, :total_score => total_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) + :news_reply_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 1) else score = course_contributor_score.news_reply_num + 1 - course_contributor_score.update_attributes(:news_reply_num => score) + total_score = course_contributor_score.total_score + 1 + course_contributor_score.update_attributes(:news_reply_num => score, :total_score => total_score) end end end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 022d86d9b..a1b119cb5 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -751,14 +751,11 @@ module CoursesHelper JOIN students_for_courses ON students_for_courses.student_id = members.user_id AND students_for_courses.course_id = members.course_id WHERE members.course_id = #{course.id} ORDER BY score #{score_sort_by} limit 9" - sql = ActiveRecord::Base.connection() homework_scores = Member.find_by_sql(sql_select) - sql.close() - homework_scores end def contributor_course_scor(course_id) - ccs = CourseContributorScore.where("course_id =?", course_id).limit(9) + ccs = CourseContributorScore.where("course_id =?", course_id).order("total_score desc") .limit(9) end end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 45d19e681..9c6bb9cb1 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -73,11 +73,10 @@ class Attachment < ActiveRecord::Base cattr_accessor :thumbnails_storage_path @@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails") - before_save :files_to_final_location,:act_as_course_activity, :act_as_student_score + before_save :files_to_final_location,:act_as_course_activity after_create :office_conver, :be_user_score,:act_as_forge_activity after_update :office_conver, :be_user_score after_destroy :delete_from_disk,:down_user_score - # after_save :act_as_student_score # add by nwb # 获取所有可公开的资源文件列表 @@ -562,18 +561,4 @@ class Attachment < ActiveRecord::Base end end - # 课程成员得分(英雄榜) - def act_as_student_score - unless self.author.allowed_to?(:as_teacher, self.container) - course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", self.container_id, self.author_id).first - if course_contributor_score.nil? - CourseContributorScore.create(:course_id => self.container_id, :user_id => self.author_id, :message_num => 0, :message_reply_num => 0, - :news_reply_num => 0, :resource_num => 5, :journal_num => 0, :journal_reply_num => 0) - else - score = course_contributor_score.news_reply_num + 5 - course_contributor_score.update_attributes(:resource_num => score) - end - end - end - end diff --git a/app/models/course_contributor_score.rb b/app/models/course_contributor_score.rb index 598b8e014..f2b05458f 100644 --- a/app/models/course_contributor_score.rb +++ b/app/models/course_contributor_score.rb @@ -1,5 +1,5 @@ class CourseContributorScore < ActiveRecord::Base - attr_accessible :course_id, :journal_num, :journal_reply_num, :message_num, :message_reply_num, :news_reply_num, :resource_num, :user_id + attr_accessible :course_id, :journal_num, :journal_reply_num, :message_num, :message_reply_num, :news_reply_num, :resource_num, :user_id, :total_score belongs_to :course belongs_to :user end diff --git a/app/views/courses/_tool_expand.html.erb b/app/views/courses/_tool_expand.html.erb index cec5311c6..9a36b8efb 100644 --- a/app/views/courses/_tool_expand.html.erb +++ b/app/views/courses/_tool_expand.html.erb @@ -2,19 +2,19 @@ <% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) %> <% if show_nav?(@course.homework_commons.count) %>
课程贡献榜
- <% contributor_course_scor(@course.id).each do |student_score| %> -<%=link_to student_score.user, user_path(student_score.user) %>
-- <%#= link_to ma.course_message.title, {:controller => 'news', :action => 'show', :id => ma.course_message.id }, - :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", - :onmouseover =>"message_titile_show($(this),event)", - :onmouseout => "message_titile_hide($(this))" %> - <%= student_score.total_score.to_i %>
- - -课程英雄榜
- <% hero_homework_score(@course, "desc").each do |student_score| %> -<%=link_to student_score.user, user_path(student_score.user) %>
-<%= student_score.score.to_i %>
- - -<%=link_to student_score.user, user_path(student_score.user), :title => student_score.user %>
+<%= student_score.score.to_i %>
+