Class: Formol::Forum
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Formol::Forum
- Includes:
- Tracking, RankedModel
- Defined in:
- app/models/formol/forum.rb
Class Method Summary collapse
-
.ready_for_breadcrumb ⇒ Object
this scope eager loads conveniently topic for using it in breadcrumb.
-
.reorganize(forum_ids, category_id = nil) ⇒ Object
Sorts topics from an array of ids and sets the new category.
-
.unread(user) ⇒ Object
return all unread forums for a given user.
Instance Method Summary collapse
-
#mark_as_read(user) ⇒ Object
Mark all unread topics as read for a given user.
- #read?(user) ⇒ Boolean
-
#register_last_post(post) ⇒ Object
Register a post being the last one of the current forum.
-
#unregister_last_post ⇒ Object
Unregister a post by re-assigning last post.
Class Method Details
.ready_for_breadcrumb ⇒ Object
this scope eager loads conveniently topic for using it in breadcrumb
38 39 40 |
# File 'app/models/formol/forum.rb', line 38 def includes(:category) end |
.reorganize(forum_ids, category_id = nil) ⇒ Object
Sorts topics from an array of ids and sets the new category
53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/models/formol/forum.rb', line 53 def reorganize(forum_ids, category_id = nil) category = Formol::Category.find(category_id) if category_id #TODO: should maybe optimize this? (forum_ids || []).each_with_index do |forum_id, index| attr = { :position => index } attr[:category] = category if category_id find(forum_id).update_attributes(attr) end end |
.unread(user) ⇒ Object
return all unread forums for a given user
43 44 45 46 47 |
# File 'app/models/formol/forum.rb', line 43 def unread(user) unread_scope_base(user) .select('DISTINCT formol_forums.id') .joins(:topics => :last_post) end |
Instance Method Details
#mark_as_read(user) ⇒ Object
Mark all unread topics as read for a given user
78 79 80 81 82 |
# File 'app/models/formol/forum.rb', line 78 def mark_as_read(user) topics.unread(user).each do |unread| unread.track_for_user!(user) end end |
#read?(user) ⇒ Boolean
84 85 86 |
# File 'app/models/formol/forum.rb', line 84 def read?(user) topics.unread(user).blank? end |
#register_last_post(post) ⇒ Object
Register a post being the last one of the current forum
67 68 69 |
# File 'app/models/formol/forum.rb', line 67 def register_last_post(post) update_attribute(:last_post, post) end |
#unregister_last_post ⇒ Object
Unregister a post by re-assigning last post. Needed when a post is destroyed
73 74 75 |
# File 'app/models/formol/forum.rb', line 73 def unregister_last_post update_attributes!(:last_post => posts.order('formol_posts.id').last) end |