diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-09-27 17:28:22 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-09-27 17:28:22 +0000 |
commit | a96421019f3a813b93798e4ec8099edd09f8a661 (patch) | |
tree | 102827aea563063b29ae21800bfff88fb16550f9 /lib/plugins/acts_as_watchable | |
parent | d723bea502faedb218f929b40849935d61c577e2 (diff) | |
download | redmine-a96421019f3a813b93798e4ec8099edd09f8a661.tar.gz redmine-a96421019f3a813b93798e4ec8099edd09f8a661.zip |
Search engines now supports pagination.
Results are sorted in reverse chronological order.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@766 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/plugins/acts_as_watchable')
-rw-r--r-- | lib/plugins/acts_as_watchable/init.rb | 3 | ||||
-rw-r--r-- | lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb | 53 |
2 files changed, 56 insertions, 0 deletions
diff --git a/lib/plugins/acts_as_watchable/init.rb b/lib/plugins/acts_as_watchable/init.rb new file mode 100644 index 000000000..f39cc7d18 --- /dev/null +++ b/lib/plugins/acts_as_watchable/init.rb @@ -0,0 +1,3 @@ +# Include hook code here +require File.dirname(__FILE__) + '/lib/acts_as_watchable' +ActiveRecord::Base.send(:include, Redmine::Acts::Watchable) diff --git a/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb b/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb new file mode 100644 index 000000000..c789017e5 --- /dev/null +++ b/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb @@ -0,0 +1,53 @@ +# ActsAsWatchable +module Redmine + module Acts + module Watchable + def self.included(base) + base.extend ClassMethods + end + + module ClassMethods + def acts_as_watchable(options = {}) + return if self.included_modules.include?(Redmine::Acts::Watchable::InstanceMethods) + send :include, Redmine::Acts::Watchable::InstanceMethods + + class_eval do + has_many :watchers, :as => :watchable, :dependent => :delete_all + end + end + end + + module InstanceMethods + def self.included(base) + base.extend ClassMethods + end + + def add_watcher(user) + self.watchers << Watcher.new(:user => user) + end + + def remove_watcher(user) + return nil unless user && user.is_a?(User) + Watcher.delete_all "watchable_type = '#{self.class}' AND watchable_id = #{self.id} AND user_id = #{user.id}" + end + + def watched_by?(user) + !self.watchers.find(:first, + :conditions => ["#{Watcher.table_name}.user_id = ?", user.id]).nil? + end + + def watcher_recipients + self.watchers.collect { |w| w.user.mail } + end + + module ClassMethods + def watched_by(user) + find(:all, + :include => :watchers, + :conditions => ["#{Watcher.table_name}.user_id = ?", user.id]) + end + end + end + end + end +end
\ No newline at end of file |