Class: SakaiInfo::ForumThread

Inherits:
GenericThread show all
Includes:
ModProps
Defined in:
lib/sakai-info/forum.rb

Instance Attribute Summary collapse

Attributes inherited from SakaiObject

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ModProps

included

Methods inherited from GenericThread

types, valid_message_type?

Methods inherited from SakaiObject

#dbrow_only_serialization, #dbrow_serialization, descendants, #object_type_serialization, #serialize, #shell_serialization, #to_csv, #to_json, #to_yaml

Constructor Details

#initialize(dbrow) ⇒ ForumThread

Returns a new instance of ForumThread.



149
150
151
152
153
154
# File 'lib/sakai-info/forum.rb', line 149

def initialize(dbrow)
  @dbrow = dbrow

  @id = dbrow[:id].to_i
  @title = dbrow[:title]
end

Instance Attribute Details

#dbrowObject (readonly)

Returns the value of attribute dbrow.



125
126
127
# File 'lib/sakai-info/forum.rb', line 125

def dbrow
  @dbrow
end

#titleObject (readonly)

Returns the value of attribute title.



125
126
127
# File 'lib/sakai-info/forum.rb', line 125

def title
  @title
end

Class Method Details

.all_serializationsObject



201
202
203
# File 'lib/sakai-info/forum.rb', line 201

def self.all_serializations
  [ :default, :posts ]
end

.clear_cacheObject



133
134
135
# File 'lib/sakai-info/forum.rb', line 133

def self.clear_cache
  @@cache = {}
end

.count_by_forum_id(forum_id) ⇒ Object



168
169
170
# File 'lib/sakai-info/forum.rb', line 168

def self.count_by_forum_id(forum_id)
  ForumThread.query_by_forum_id(forum_id).count
end

.find(id) ⇒ Object



138
139
140
141
142
143
144
145
146
147
# File 'lib/sakai-info/forum.rb', line 138

def self.find(id)
  if @@cache[id.to_s].nil?
    row = DB.connect[:mfr_topic_t].where(:id => id, :topic_dtype => "DT").first
    if row.nil?
      raise ObjectNotFoundException.new(ForumThread, id)
    end
    @@cache[id.to_s] = ForumThread.new(row)
  end
  @@cache[id.to_s]
end

.find_by_forum_id(forum_id) ⇒ Object



172
173
174
# File 'lib/sakai-info/forum.rb', line 172

def self.find_by_forum_id(forum_id)
  ForumThread.query_by_forum_id(forum_id).all.collect { |r| ForumThread.new(r) }
end

.query_by_forum_id(forum_id) ⇒ Object



164
165
166
# File 'lib/sakai-info/forum.rb', line 164

def self.query_by_forum_id(forum_id)
  DB.connect[:mfr_topic_t].where(:of_surrogatekey => forum_id)
end

Instance Method Details

#default_serializationObject



176
177
178
179
180
181
182
# File 'lib/sakai-info/forum.rb', line 176

def default_serialization
  {
    "id" => self.id,
    "title" => self.title,
    "post_count" => self.post_count,
  }
end

#post_countObject



156
157
158
# File 'lib/sakai-info/forum.rb', line 156

def post_count
  @post_count ||= ForumPost.count_by_thread_id(self.id)
end

#postsObject



160
161
162
# File 'lib/sakai-info/forum.rb', line 160

def posts
  @posts ||= ForumPost.find_by_thread_id(self.id)
end

#posts_serializationObject



184
185
186
187
188
189
190
191
192
# File 'lib/sakai-info/forum.rb', line 184

def posts_serialization
  if self.post_count > 0
    {
      "posts" => self.posts.collect { |p| p.serialize(:summary) }
    }
  else
    { }
  end
end

#summary_serializationObject



194
195
196
197
198
199
# File 'lib/sakai-info/forum.rb', line 194

def summary_serialization
  {
    "id" => self.id,
    "title" => self.title,
  }
end