Class: Board
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Board
- Includes:
- Redmine::SafeAttributes
- Defined in:
- app/models/board.rb
Overview
Redmine - project management software Copyright © 2006-2022 Jean-Philippe Lang
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Class Method Summary collapse
- .board_tree(boards, parent_id = nil, level = 0) ⇒ Object
-
.reset_counters!(board_id) ⇒ Object
Updates topics_count, messages_count and last_message_id attributes for
board_id
.
Instance Method Summary collapse
- #reload(*args) ⇒ Object
- #reset_counters! ⇒ Object
- #to_s ⇒ Object
-
#topics ⇒ Object
Returns a scope for the board topics (messages without parent).
- #valid_parents ⇒ Object
- #visible?(user = User.current) ⇒ Boolean
Methods included from Redmine::SafeAttributes
#delete_unsafe_attributes, included, #safe_attribute?, #safe_attribute_names, #safe_attributes=
Class Method Details
.board_tree(boards, parent_id = nil, level = 0) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/board.rb', line 80 def self.board_tree(boards, parent_id=nil, level=0) tree = [] boards.select {|board| board.parent_id == parent_id}.sort_by(&:position).each do |board| tree << [board, level] tree += board_tree(boards, board.id, level+1) end if block_given? tree.each do |board, level| yield board, level end end tree end |
.reset_counters!(board_id) ⇒ Object
Updates topics_count, messages_count and last_message_id attributes for board_id
68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/models/board.rb', line 68 def self.reset_counters!(board_id) board_id = board_id.to_i Board.where(:id => board_id). update_all( ["topics_count = (SELECT COUNT(*) FROM #{Message.table_name}" \ " WHERE board_id=:id AND parent_id IS NULL)," \ " messages_count = (SELECT COUNT(*) FROM #{Message.table_name} WHERE board_id=:id)," \ " last_message_id = (SELECT MAX(id) FROM #{Message.table_name} WHERE board_id=:id)", :id => board_id] ) end |
Instance Method Details
#reload(*args) ⇒ Object
45 46 47 48 |
# File 'app/models/board.rb', line 45 def reload(*args) @valid_parents = nil super end |
#reset_counters! ⇒ Object
63 64 65 |
# File 'app/models/board.rb', line 63 def reset_counters! self.class.reset_counters!(id) end |
#to_s ⇒ Object
50 51 52 |
# File 'app/models/board.rb', line 50 def to_s name end |
#topics ⇒ Object
Returns a scope for the board topics (messages without parent)
55 56 57 |
# File 'app/models/board.rb', line 55 def topics .where(:parent_id => nil) end |
#valid_parents ⇒ Object
59 60 61 |
# File 'app/models/board.rb', line 59 def valid_parents @valid_parents ||= project.boards - self_and_descendants end |
#visible?(user = User.current) ⇒ Boolean
41 42 43 |
# File 'app/models/board.rb', line 41 def visible?(user=User.current) !user.nil? && user.allowed_to?(:view_messages, project) end |