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
198
199
200
201
202
203
204
|
# File 'lib/sakai-info/quiz.rb', line 198
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
89
90
91
92
93
94
|
# File 'lib/sakai-info/quiz.rb', line 89
def self.count_by_site_id(site_id)
{
"pending_count" => PendingQuiz.count_by_site_id(site_id),
"published_count" => PublishedQuiz.count_by_site_id(site_id)
}
end
|
.find(id) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/sakai-info/quiz.rb', line 64
def self.find(id)
id = id.to_s
if @@cache[id].nil?
quiz = nil
begin
quiz = PendingQuiz.find(id)
rescue ObjectNotFoundException
begin
quiz = PublishedQuiz.find(id)
rescue ObjectNotFoundException
raise ObjectNotFoundException.new(Quiz, id)
end
end
@@cache[id] = quiz
end
@@cache[id]
end
|
.find_by_site_id(site_id) ⇒ Object
82
83
84
85
86
87
|
# File 'lib/sakai-info/quiz.rb', line 82
def self.find_by_site_id(site_id)
{
"pending" => PendingQuiz.find_by_site_id(site_id),
"published" => PublishedQuiz.find_by_site_id(site_id)
}
end
|
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
180
181
182
183
184
|
# File 'lib/sakai-info/quiz.rb', line 180
def access_control_summary_serialization
result = self.summary_serialization
result.delete("id")
result
end
|
#default_serialization ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'lib/sakai-info/quiz.rb', line 135
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
192
193
194
195
196
|
# File 'lib/sakai-info/quiz.rb', line 192
def items_serialization
{
"items" => self.items.collect { |i| i.serialize(:quiz_summary) }
}
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
186
187
188
189
190
|
# File 'lib/sakai-info/quiz.rb', line 186
def sections_serialization
{
"sections" => self.sections.collect{|s|s.serialize(:quiz_summary)}
}
end
|
#site_summary_serialization ⇒ Object
172
173
174
175
176
177
178
|
# File 'lib/sakai-info/quiz.rb', line 172
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
158
159
160
161
162
163
164
165
166
167
168
169
170
|
# File 'lib/sakai-info/quiz.rb', line 158
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
|