Class: SakaiInfo::User
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(*args) ⇒ User
Returns a new instance of User.
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/sakai-info/user.rb', line 79
def initialize(*args)
case args.size
when 1
dbrow = args[0]
@dbrow = dbrow
@id = dbrow[:user_id]
@eid = User.get_eid(@id)
@email = dbrow[:email]
@name = ((dbrow[:first_name] || "") + " " + (dbrow[:last_name] || "")).strip
@type = dbrow[:type]
when 2
user_id, placeholder_string = args
@id = user_id
@eid=User.get_eid(@id)
@email = @name = @type = placeholder_string
else
raise ArgumentError, "This method takes 1-2 arguments"
end
end
|
Instance Attribute Details
#dbrow ⇒ Object
Returns the value of attribute dbrow.
14
15
16
|
# File 'lib/sakai-info/user.rb', line 14
def dbrow
@dbrow
end
|
#eid ⇒ Object
Returns the value of attribute eid.
14
15
16
|
# File 'lib/sakai-info/user.rb', line 14
def eid
@eid
end
|
#email ⇒ Object
Returns the value of attribute email.
14
15
16
|
# File 'lib/sakai-info/user.rb', line 14
def email
@email
end
|
#name ⇒ Object
Returns the value of attribute name.
14
15
16
|
# File 'lib/sakai-info/user.rb', line 14
def name
@name
end
|
#type ⇒ Object
Returns the value of attribute type.
14
15
16
|
# File 'lib/sakai-info/user.rb', line 14
def type
@type
end
|
Class Method Details
.all_serializations ⇒ Object
243
244
245
246
247
248
249
250
|
# File 'lib/sakai-info/user.rb', line 243
def self.all_serializations
[
:default,
:sites,
:pools,
:mod,
]
end
|
.clear_cache ⇒ Object
22
23
24
25
|
# File 'lib/sakai-info/user.rb', line 22
def self.clear_cache
@@cache = {}
@@id_cache = {}
end
|
.count ⇒ Object
155
156
157
|
# File 'lib/sakai-info/user.rb', line 155
def self.count
DB.connect[:sakai_user].count
end
|
.count_by_realm_id_and_role_id(realm_id, role_id) ⇒ Object
159
160
161
162
|
# File 'lib/sakai-info/user.rb', line 159
def self.count_by_realm_id_and_role_id(realm_id, role_id)
DB.connect[:sakai_realm_rl_gr].
filter(:realm_key => realm_id, :role_key => role_id).count
end
|
.find(id) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/sakai-info/user.rb', line 28
def self.find(id)
if @@cache[id].nil?
eid = User.get_eid(id)
user_id = User.get_user_id(id)
if eid.nil? or user_id.nil?
raise ObjectNotFoundException.new(User, id)
end
row = DB.connect[:sakai_user].where(:user_id => user_id).first
if row.nil?
@@cache[eid] = @@cache[user_id] = User.new(user_id,'Provided')
else
@@cache[eid] = @@cache[user_id] = User.new(row)
end
end
@@cache[id]
end
|
.find_by_name(name) ⇒ Object
192
193
194
|
# File 'lib/sakai-info/user.rb', line 192
def self.find_by_name(name)
User.query_by_name(name).all.collect{|row| @@cache[row[:user_id]] = User.new(row)}
end
|
.find_by_realm_id_and_role_id(realm_id, role_id) ⇒ Object
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
# File 'lib/sakai-info/user.rb', line 164
def self.find_by_realm_id_and_role_id(realm_id, role_id)
nil
end
|
.find_ids_by_name(name) ⇒ Object
196
197
198
|
# File 'lib/sakai-info/user.rb', line 196
def self.find_ids_by_name(name)
User.query_by_name(name).select(:user_id).all.collect{|row|row[:user_id]}
end
|
.get_eid(id) ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/sakai-info/user.rb', line 63
def self.get_eid(id)
if ids = User.get_ids(id)
ids[:eid]
else
nil
end
end
|
.get_ids(id) ⇒ Object
58
59
60
61
|
# File 'lib/sakai-info/user.rb', line 58
def self.get_ids(id)
@@id_cache[id] ||=
DB.connect[:sakai_user_id_map].where(:user_id => id).or(:eid => id).first
end
|
.get_user_id(id) ⇒ Object
71
72
73
74
75
76
77
|
# File 'lib/sakai-info/user.rb', line 71
def self.get_user_id(id)
if ids = User.get_ids(id)
ids[:user_id]
else
nil
end
end
|
.query_by_name(name) ⇒ Object
188
189
190
|
# File 'lib/sakai-info/user.rb', line 188
def self.query_by_name(name)
DB.connect[:sakai_user].where("upper(first_name) like ? or upper(last_name) like ? or upper(first_name)||\' \'||upper(last_name) like ?", "%#{name.upcase}%", "%#{name.upcase}%", "%#{name.upcase}%")
end
|
Instance Method Details
#assignment_content_count ⇒ Object
#assignment_contents ⇒ Object
#assignment_submission_count ⇒ Object
#assignment_submissions ⇒ Object
#default_serialization ⇒ Object
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
# File 'lib/sakai-info/user.rb', line 201
def default_serialization
result = {
"id" => self.id,
"name" => self.name,
"eid" => self.eid,
"email" => self.email,
"type" => self.type,
"user_properties" => UserProperty.find_by_user_id(self.id),
"site_count" => self.site_count,
"question_pool_count" => self.question_pool_count
}
if result["user_properties"] == {}
result.delete("user_properties")
end
result
end
|
#pools_serialization ⇒ Object
233
234
235
236
237
238
239
240
241
|
# File 'lib/sakai-info/user.rb', line 233
def pools_serialization
if self.question_pool_count > 0
{
"question_pools" => self.question_pools.collect { |qp| qp.serialize(:user_summary) }
}
else
{}
end
end
|
#preferences_xml ⇒ Object
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/sakai-info/user.rb', line 143
def preferences_xml
if @preferences_xml.nil?
@preferences_xml = ""
row = DB.connect[:sakai_preferences].filter(:preferences_id => @user_id).first
if not row.nil?
REXML::Document.new(row[:xml].read).write(@preferences_xml, 2)
end
end
@preferences_xml
end
|
#question_pool_count ⇒ Object
111
112
113
|
# File 'lib/sakai-info/user.rb', line 111
def question_pool_count
@question_pool_count ||= QuestionPool.count_by_user_id(@id)
end
|
#site_count ⇒ Object
135
136
137
138
139
140
141
|
# File 'lib/sakai-info/user.rb', line 135
def site_count
if @membership.nil?
Site.count_by_user_id(@id)
else
@membership.length
end
end
|
#sites_serialization ⇒ Object
227
228
229
230
231
|
# File 'lib/sakai-info/user.rb', line 227
def sites_serialization
{
"sites" => self.membership.collect { |sm| sm.serialize(:user_summary) }
}
end
|
#summary_serialization ⇒ Object
218
219
220
221
222
223
224
225
|
# File 'lib/sakai-info/user.rb', line 218
def summary_serialization
{
"id" => self.id,
"eid" => self.eid,
"name" => self.name,
"type" => self.type
}
end
|
#workspace ⇒ Object
103
104
105
|
# File 'lib/sakai-info/user.rb', line 103
def workspace
@workspace ||= Site.find("~" + @id)
end
|