diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index c0e99d546..44248ceae 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -705,7 +705,7 @@ class CoursesController < ApplicationController #"show_course_journals_for_messages" => true, "show_bids" => true, "show_homeworks" => true, - #"show_polls" => 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/controllers/poll_controller.rb b/app/controllers/poll_controller.rb index b897d039a..32ec3dad2 100644 --- a/app/controllers/poll_controller.rb +++ b/app/controllers/poll_controller.rb @@ -29,7 +29,7 @@ class PollController < ApplicationController end #已提交问卷的用户不能再访问该界面 if has_commit_poll?(@poll.id,User.current.id) && (!User.current.admin?) - render_403 + redirect_to poll_index_url(:polls_type => "Course", :polls_group_id => @course.id) else @can_edit_poll = (!has_commit_poll?(@poll.id,User.current.id)) || User.current.admin? @percent = get_percent(@poll,User.current) diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 2e06e3a43..801d98b0b 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -691,9 +691,11 @@ module CoursesHelper #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 + # 动态目前只统计发布的问卷,关闭的问卷不在动态内显示 + # Poll.where(polls_group_id: @course_ids, polls_type: Course, polls_status: 2||3).where("published_at>?",date_from).each do |poll| + 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 diff --git a/app/models/poll.rb b/app/models/poll.rb index 943c08b51..64e9df79a 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -7,22 +7,24 @@ class Poll < ActiveRecord::Base 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 + 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_event :title => Proc.new {|o| "#{l(:label_course_poll)}: #{o.polls_name}" }, + :description => :polls_description, + :datetime => :published_at, + :author => :user, + :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 + acts_as_activity_provider :type => 'polls', + #:permission => :view_course_polls, + :find_options => {:select => "#{Poll.table_name}.*", + :joins => "LEFT JOIN #{Course.table_name} ON ( #{Poll.table_name}.polls_type='Course' AND #{Poll.table_name}.polls_status= 2 AND #{Poll.table_name}.polls_group_id = #{Course.table_name}.id )"}, + :timestamp => "#{self.table_name}.published_at", + :author_key => :user_id -# def act_as_activity -# self.acts << Activity.new(:user_id => self.user_id) -# end + def act_as_activity + self.acts << Activity.new(:user_id => self.user_id) + end end diff --git a/config/locales/courses/zh.yml b/config/locales/courses/zh.yml index e0a39f51d..0f6c1fa01 100644 --- a/config/locales/courses/zh.yml +++ b/config/locales/courses/zh.yml @@ -90,4 +90,6 @@ zh: #setting label_user_name: "用户名称" - #setting end \ No newline at end of file + #setting end + + label_course_poll: 课程问卷 \ No newline at end of file diff --git a/lib/redmine.rb b/lib/redmine.rb index ad73c2db1..ed96e01ff 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -118,7 +118,7 @@ Redmine::AccessControl.map do |map| map.permission :projects_attachments_download,{:attachments => :download},:belong_to_project => true map.permission :course_attachments_download,{:attachments => :download},:belong_to_course => true map.permission :contest_attachments_download,{:attachments => :download},:belong_to_contest => true - + map.permission :view_polls, {}, :public => true, :read => true map.permission :view_homeworks, {}, :public => true, :read => true map.course_module :files do |map| @@ -487,7 +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' + activity.register :polls, :class_name => 'Poll' end Redmine::Search.map do |search|