Class: Board

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/board.rb

Overview

redMine - project management software Copyright (C) 2006-2007 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

Instance Method Summary collapse

Class Method Details

.reset_counters!(board_id) ⇒ Object

Updates topics_count, messages_count and last_message_id attributes for board_id



43
44
45
46
47
48
49
# File 'app/models/board.rb', line 43

def self.reset_counters!(board_id)
  board_id = board_id.to_i
  update_all("topics_count = (SELECT COUNT(*) FROM #{Message.table_name} WHERE board_id=#{board_id} AND parent_id IS NULL)," +
             " messages_count = (SELECT COUNT(*) FROM #{Message.table_name} WHERE board_id=#{board_id})," +
             " last_message_id = (SELECT MAX(id) FROM #{Message.table_name} WHERE board_id=#{board_id})",
             ["id = ?", board_id])
end

Instance Method Details

#reset_counters!Object



38
39
40
# File 'app/models/board.rb', line 38

def reset_counters!
  self.class.reset_counters!(id)
end

#to_sObject



34
35
36
# File 'app/models/board.rb', line 34

def to_s
  name
end

#visible?(user = User.current) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/models/board.rb', line 30

def visible?(user=User.current)
  !user.nil? && user.allowed_to?(:view_messages, project)
end