Class: SakaiInfo::Quiz
Constant Summary
collapse
- INACTIVE =
0
- ACTIVE =
1
- DELETED =
aka ‘DEAD’ in the Scholar source
2
- RETRACTED_FOR_EDITING =
3
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, site = nil) ⇒ Quiz
a note about quizzes: they do not link directly back to sites instead, they link back only via the sam_authzdata_t table
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/sakai-info/quiz.rb', line 30
def initialize(dbrow, site = nil)
@site = nil
if site.is_a? String
begin
@site = Site.find(site)
rescue ObjectNotFoundException
@site = nil
end
elsif site.is_a? Site
@site = site
end
@id = dbrow[:id]
@title = dbrow[:title]
@dbrow = dbrow
if @site.nil?
DB.connect[:sam_authzdata_t].select(Sequel.function(:distinct, :agentid)).
where(:qualifierid => @id).
where(:functionid => ["OWN_PUBLISHED_ASSESSMENT","EDIT_ASSESSMENT"]).
all.each do |row|
begin
site = Site.find(row[:agentid])
@site = site
rescue ObjectNotFoundException
@site = nil
end
break if not @site.nil?
end
end
end
|
Instance Attribute Details
#dbrow ⇒ Object
Returns the value of attribute dbrow.
14
15
16
|
# File 'lib/sakai-info/quiz.rb', line 14
def dbrow
@dbrow
end
|
#site ⇒ Object
Returns the value of attribute site.
14
15
16
|
# File 'lib/sakai-info/quiz.rb', line 14
def site
@site
end
|
#title ⇒ Object
Returns the value of attribute title.
14
15
16
|
# File 'lib/sakai-info/quiz.rb', line 14
def title
@title
end
|
Class Method Details
.all_serializations ⇒ Object
222
223
224
225
226
227
228
|
# File 'lib/sakai-info/quiz.rb', line 222
def self.all_serializations
[
:default,
:sections,
:items,
]
end
|
.clear_cache ⇒ Object
22
23
24
|
# File 'lib/sakai-info/quiz.rb', line 22
def self.clear_cache
@@cache = {}
end
|
.count_by_site_id(site_id) ⇒ Object
.find_by_site_id(site_id) ⇒ Object
Instance Method Details
#access_control ⇒ Object
131
132
133
|
# File 'lib/sakai-info/quiz.rb', line 131
def access_control
@access_control ||= self.access_control_class.find(self.id)
end
|
#access_control_summary_serialization ⇒ Object
188
189
190
191
192
|
# File 'lib/sakai-info/quiz.rb', line 188
def access_control_summary_serialization
result = self.summary_serialization
result.delete("id")
result
end
|
#authorizations ⇒ Object
139
140
141
|
# File 'lib/sakai-info/quiz.rb', line 139
def authorizations
@authorizations ||= self.authorization_class.find_by_quiz_id(self.id)
end
|
#authorizations_serialization ⇒ Object
212
213
214
215
216
|
# File 'lib/sakai-info/quiz.rb', line 212
def authorizations_serialization
{
"authorizations" => self.authorizations.collect { |a| a.serialize(:quiz_summary) }
}
end
|
#auths_serialization ⇒ Object
218
219
220
|
# File 'lib/sakai-info/quiz.rb', line 218
def auths_serialization
self.authorizations_serialization
end
|
#default_serialization ⇒ Object
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/sakai-info/quiz.rb', line 143
def default_serialization
result = {
"id" => self.id,
"title" => self.title,
"site" => nil,
"status" => self.status,
"type" => self.quiz_type,
"section_count" => self.section_count,
"item_count" => self.item_count,
"attempt_count" => nil,
"access_control" => self.access_control.serialize(:quiz_summary)
}
if not self.site.nil?
result["site"] = self.site.serialize(:summary)
end
if self.respond_to? :attempt_count
result["attempt_count"] = self.attempt_count
else
result.delete("attempt_count")
end
result
end
|
#item_count ⇒ Object
123
124
125
|
# File 'lib/sakai-info/quiz.rb', line 123
def item_count
@item_count ||= self.item_class.count_by_quiz_id(self.id)
end
|
#items ⇒ Object
127
128
129
|
# File 'lib/sakai-info/quiz.rb', line 127
def items
@items ||= self.item_class.find_by_quiz_id(self.id)
end
|
#items_serialization ⇒ Object
200
201
202
203
204
|
# File 'lib/sakai-info/quiz.rb', line 200
def items_serialization
{
"items" => self.items.collect { |i| i.serialize(:quiz_summary) }
}
end
|
135
136
137
|
# File 'lib/sakai-info/quiz.rb', line 135
def metadata
@metadata ||= self.metadata_class.find_by_quiz_id(self.id)
end
|
206
207
208
209
210
|
# File 'lib/sakai-info/quiz.rb', line 206
def metadata_serialization
{
"metadata" => self.metadata.collect { |m| [m.key, m.value] }.to_h
}
end
|
#quiz_type ⇒ Object
96
97
98
|
# File 'lib/sakai-info/quiz.rb', line 96
def quiz_type
nil
end
|
#section_count ⇒ Object
115
116
117
|
# File 'lib/sakai-info/quiz.rb', line 115
def section_count
@section_count ||= self.section_class.count_by_quiz_id(@id)
end
|
#sections ⇒ Object
119
120
121
|
# File 'lib/sakai-info/quiz.rb', line 119
def sections
@sections ||= self.section_class.find_by_quiz_id(@id)
end
|
#sections_serialization ⇒ Object
194
195
196
197
198
|
# File 'lib/sakai-info/quiz.rb', line 194
def sections_serialization
{
"sections" => self.sections.collect{|s|s.serialize(:quiz_summary)}
}
end
|
#site_summary_serialization ⇒ Object
180
181
182
183
184
185
186
|
# File 'lib/sakai-info/quiz.rb', line 180
def site_summary_serialization
{
"id" => self.id,
"title" => self.title,
"status" => self.status,
}
end
|
#status ⇒ Object
105
106
107
108
109
110
111
112
113
|
# File 'lib/sakai-info/quiz.rb', line 105
def status
case @dbrow[:status].to_i
when INACTIVE then "inactive"
when ACTIVE then "active"
when DELETED then "deleted"
when RETRACTED_FOR_EDITING then "retracted for editing"
else "unknown status '#{@dbrow[:status].to_i}'"
end
end
|
#summary_serialization ⇒ Object
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/sakai-info/quiz.rb', line 166
def summary_serialization
result = {
"id" => self.id,
"title" => self.title,
"site_id" => nil,
"status" => self.status,
"type" => self.quiz_type
}
if not self.site.nil?
result["site_id"] = self.site.id
end
result
end
|