Class: SakaiInfo::Forum
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 SakaiObject
#dbrow_only_serialization, #dbrow_serialization, descendants, #object_type_serialization, #serialize, #shell_serialization, #to_csv, #to_json, #to_yaml
Constructor Details
#initialize(dbrow) ⇒ Forum
Returns a new instance of Forum.
38
39
40
41
42
43
44
45
46
|
# File 'lib/sakai-info/forum.rb', line 38
def initialize(dbrow)
@dbrow = dbrow
@id = dbrow[:id].to_i
@title = dbrow[:title]
@area_id = dbrow[:surrogatekey]
@site_id_is_nil = false
end
|
Instance Attribute Details
#dbrow ⇒ Object
Returns the value of attribute dbrow.
14
15
16
|
# File 'lib/sakai-info/forum.rb', line 14
def dbrow
@dbrow
end
|
#title ⇒ Object
Returns the value of attribute title.
14
15
16
|
# File 'lib/sakai-info/forum.rb', line 14
def title
@title
end
|
Class Method Details
.all_serializations ⇒ Object
119
120
121
|
# File 'lib/sakai-info/forum.rb', line 119
def self.all_serializations
[ :default, :threads ]
end
|
.clear_cache ⇒ Object
22
23
24
|
# File 'lib/sakai-info/forum.rb', line 22
def self.clear_cache
@@cache = {}
end
|
.count_by_site_id(site_id) ⇒ Object
88
89
90
|
# File 'lib/sakai-info/forum.rb', line 88
def self.count_by_site_id(site_id)
Forum.query_by_site_id(site_id).count
end
|
.find(id) ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/sakai-info/forum.rb', line 27
def self.find(id)
if @@cache[id.to_s].nil?
row = DB.connect[:mfr_open_forum_t].where(:id => id).first
if row.nil?
raise ObjectNotFoundException.new(Forum, id)
end
@@cache[id.to_s] = Forum.new(row)
end
@@cache[id.to_s]
end
|
.find_by_site_id(site_id) ⇒ Object
92
93
94
95
|
# File 'lib/sakai-info/forum.rb', line 92
def self.find_by_site_id(site_id)
Forum.query_by_site_id(site_id).all.
collect { |row| @@cache[row[:id].to_i.to_s] = Forum.new(row) }
end
|
.query_by_site_id(site_id) ⇒ Object
80
81
82
83
84
85
86
|
# File 'lib/sakai-info/forum.rb', line 80
def self.query_by_site_id(site_id)
db = DB.connect
db[:mfr_open_forum_t].
where(:surrogatekey =>
db[:mfr_area_t].select(:id).where(:context_id => site_id)).
where(:forum_dtype => "DF")
end
|
Instance Method Details
#default_serialization ⇒ Object
97
98
99
100
101
102
103
104
|
# File 'lib/sakai-info/forum.rb', line 97
def default_serialization
{
"id" => self.id,
"title" => self.title,
"site" => self.site.serialize(:summary),
"thread_count" => self.thread_count,
}
end
|
#site ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/sakai-info/forum.rb', line 64
def site
if self.site_id.nil?
return nil
end
@site ||= Site.find(self.site_id)
end
|
#site_id ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/sakai-info/forum.rb', line 48
def site_id
return nil if @site_id_is_nil
if @site_id.nil?
result = DB.connect[:mfr_area_t].
select(:context_id).where(:id => @area_id).first
if result.nil?
@site_id_is_nil = true
return nil
else
@site_id = result[:context_id]
end
end
@site_id
end
|
#summary_serialization ⇒ Object
112
113
114
115
116
117
|
# File 'lib/sakai-info/forum.rb', line 112
def summary_serialization
{
"id" => self.id,
"title" => self.title
}
end
|
#threads_serialization ⇒ Object
106
107
108
109
110
|
# File 'lib/sakai-info/forum.rb', line 106
def threads_serialization
{
"threads" => self.threads.collect { |t| t.serialize(:summary) }
}
end
|