From e030c12be8828d0d4b4f51da762017b0c6242ced Mon Sep 17 00:00:00 2001 From: whimlex Date: Thu, 9 Apr 2015 15:18:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=8A=A8=E6=80=81=E8=AE=A1?= =?UTF-8?q?=E6=95=B0=E5=92=8C=E6=98=BE=E7=A4=BA=E7=BB=9F=E4=B8=80=EF=BC=9B?= =?UTF-8?q?=E9=97=AE=E5=8D=B7=E8=AE=A1=E6=95=B0=E5=AF=B9=E5=AD=A6=E7=94=9F?= =?UTF-8?q?=E5=92=8C=E8=80=81=E5=B8=88=E5=92=8C=E6=98=BE=E7=A4=BA=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=EF=BC=9B=E8=AF=BE=E7=A8=8B=E8=B5=84=E6=BA=90=E5=BA=93?= =?UTF-8?q?=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 5 ++- app/helpers/courses_helper.rb | 61 +++++++++++++++++++-------- app/models/journals_for_message.rb | 1 + app/models/poll.rb | 19 +++++++++ app/views/files/_course_list.html.erb | 2 +- lib/redmine.rb | 4 ++ 6 files changed, 71 insertions(+), 21 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index a243018ba..8e57fab4d 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -681,9 +681,10 @@ class CoursesController < ApplicationController "show_course_files" => true, "show_course_news" => true, "show_course_messages" => true, - "show_course_journals_for_messages" => true, + #"show_course_journals_for_messages" => true, "show_bids" => true, - "show_homeworks" => true + "show_homeworks" => true, + #"show_polls" => true } @date_to ||= Date.today + 1 @date_from = (@date_to - @days) > @course.created_at.to_date ? (@date_to - @days) : @course.created_at.to_date diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 3adcdb09e..f4a5ac193 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -52,7 +52,7 @@ module CoursesHelper end def course_poll_count - Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id}").count + Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id} and polls_status in (2,3)").count end def course_feedback_count @@ -632,48 +632,73 @@ module CoursesHelper #获取课程动态 def get_course_activity courses, activities @course_ids=activities.keys() - @bid_ids = [] days = Setting.activity_days_default.to_i - date_to ||= Date.today + 1 - date_from = date_to - days-1.years + #原来课程动态计算当期时间前(一年+一月)的动态 + # date_to ||= Date.today + 1 + # #date_from = date_to - days-1.years + date_from = @course.created_at.to_date-days #file_count Attachment.where(container_id: @course_ids, container_type: Course).where("created_on>?", date_from).each do |attachment| + if attachment.is_public? || User.current.member_of_course?(@course) || User.current.admin? activities[attachment.container_id]+=1 + else + activities[attachment.container_id] + end end + #message_count + #Board.where(course_id: @course_ids).each do |board| + # activities[board.course_id]+=board.messages.where("updated_on>?", date_from).count + #end + #message_count Board.where(course_id: @course_ids).each do |board| -# activities[board.course_id]+=1 - activities[board.course_id]+=board.messages.where("updated_on>?", date_from).count + countmessage = 0 + # 课程人员退出课程后,之前在讨论区回帖不计入课程动态统计 + board.messages.where("updated_on>?", date_from).each do |message| + if message.author.member_of_course?(@course) + countmessage+=1 + end + end + activities[board.course_id]+=countmessage end #news News.where(course_id: @course_ids).where("created_on>?",date_from).each do |news| + if news.author.member_of_course?(@course) activities[news.course_id]+=1 + end end - #feedbackc_count - JournalsForMessage.where(jour_id: @course_ids, jour_type: Course).each do |jourformess| - activities[jourformess.jour_id]+=1 - end + #feedback_count 留言目前有问题留待下一步处理 + #JournalsForMessage.where(jour_id: @course_ids, jour_type: Course).each do |jourformess| + # activities[jourformess.jour_id]+=1 + #end #homework_count - #HomeworkForCourse.where(course_id: @course_ids).each do |homework| - # @bid_ids<?",date_from).count - - #end + HomeworkForCourse.where(course_id: @course_ids).each do |homework| + countbid=0 + # @bid_ids<?",date_from).each do |bid| + countbid+=1 + end + activities[homework.course_id]+=countbid + end #@bid_ids.each do |bid_id| # activities[] +=Bid.where(id: bid_id ).where("created_on>?",date_from).count + #end + #poll_count + #Poll.where(polls_group_id: @course_ids, polls_type: Course, polls_status: 2||3).where("published_at>?",date_from).each do |poll| + # activities[poll.polls_group_id]+=1 + #end #end - # 动态数 + 1 ( 某某创建了该课程 ) - # activities.each_pair { |key, value| activities[key] = value + 1 } + activities.each_pair { |key, value| activities[key] = value + 1 } return activities end @@ -759,7 +784,7 @@ module CoursesHelper def visable_attachemnts_incourse course result = [] course.attachments.each do |attachment| - if attachment.is_public? || User.current.member_of_course?(course) + if attachment.is_public? || User.current.member_of_course?(course) || User.current.admin? result << attachment end end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 6875e6f4a..dda45965e 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -49,6 +49,7 @@ class JournalsForMessage < ActiveRecord::Base acts_as_activity_provider :type => 'course_journals_for_messages', :author_key => :user_id, + :permission => :view_course_journals_for_messages, :timestamp => "#{self.table_name}.updated_on", :find_options => {:include => :course } diff --git a/app/models/poll.rb b/app/models/poll.rb index 06f1369c1..943c08b51 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -6,4 +6,23 @@ class Poll < ActiveRecord::Base has_many :poll_questions, :dependent => :destroy,:order => "#{PollQuestion.table_name}.question_number" has_many :poll_users, :dependent => :destroy has_many :users, :through => :poll_users #该文件被哪些用户提交答案过 + # 添加课程的poll动态 +# has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy +# after_create :act_as_activity + +# acts_as_event :title => Proc.new {|o| "#{l(:label_my_message)} ##{o.id}: #{o.name}" }, +# :description => :description, +# :author => :author, +# :url => Proc.new {|o| {:controller => 'poll', :action => 'show', :id => o.id}} + +# acts_as_activity_provider :type => 'polls', +# :permission => :view_course_polls, + #:find_options => {:include => [:course, :author]}, + #:timestamp => "#{self.table_name}.published_at", +# :author_key => :author_id + +# def act_as_activity +# self.acts << Activity.new(:user_id => self.user_id) +# end + end diff --git a/app/views/files/_course_list.html.erb b/app/views/files/_course_list.html.erb index 7fc079bcb..3d692a36b 100644 --- a/app/views/files/_course_list.html.erb +++ b/app/views/files/_course_list.html.erb @@ -15,7 +15,7 @@
-<% curse_attachments.sort.reverse.each do |file| %> +<% curse_attachments.each do |file| %> <% if file.is_public? || User.current.member_of_course?(course) %>
diff --git a/lib/redmine.rb b/lib/redmine.rb index 6a74b4d3c..b8284ddc5 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -137,6 +137,9 @@ Redmine::AccessControl.map do |map| map.permission :paret_in_homework,{},:require => :member ,:belong_to_course => true end +# map.course_module :polls do |map| +# map.permission :view_course_polls, {:polls => [:index,:show]},:require => :member, :belong_to_course => true +# end map.course_module :boards do |map| # map.permission :manage_boards, {:boards => [:new, :create, :edit, :update, :destroy]}, :require => :member @@ -484,6 +487,7 @@ Redmine::Activity.map do |activity| activity.register :course_messages, :default => false, :class_name => 'Message' activity.register :homeworks, :class_name => 'Bid' +# activity.register :polls, :class_name => 'Poll' end Redmine::Search.map do |search|