Class: Board

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

Overview

– copyright ChiliProject is a project management system.

Copyright (C) 2010-2013 the ChiliProject Team

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.

See doc/COPYRIGHT.rdoc for more details. ++

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


40
41
42
43
44
45
46
# File 'app/models/board.rb', line 40

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


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

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

#to_sObject


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

def to_s
  name
end

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

Returns:

  • (Boolean)

27
28
29
# File 'app/models/board.rb', line 27

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