sakai-info 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@
2
2
  # SakaiInfo::Group library
3
3
  #
4
4
  # Created 2012-02-17 daveadams@gmail.com
5
- # Last updated 2012-02-17 daveadams@gmail.com
5
+ # Last updated 2012-02-24 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -27,16 +27,11 @@ module SakaiInfo
27
27
  @@cache = {}
28
28
  def self.find(id)
29
29
  if @@cache[id].nil?
30
- site_id = title = nil
31
- DB.connect.exec("select site_id, title from sakai_site_group " +
32
- "where group_id = :id", id) do |row|
33
- site_id = row[0]
34
- title = row[1]
35
- @@cache[id] = Group.new(id, site_id, title)
36
- end
37
- if site_id.nil? or name.nil?
30
+ row = DB.connect[:sakai_site_group].filter(:group_id => id).first
31
+ if row.nil?
38
32
  raise ObjectNotFoundException.new(Group, id)
39
33
  end
34
+ @@cache[id] = Group.new(id, row[:site_id], row[:title])
40
35
  end
41
36
  @@cache[id]
42
37
  end
@@ -46,25 +41,17 @@ module SakaiInfo
46
41
  if @@cache_by_site_id[site_id].nil?
47
42
  @@cache_by_site_id[site_id] = []
48
43
  site = Site.find(site_id)
49
- DB.connect.exec("select group_id, title " +
50
- "from sakai_site_group " +
51
- "where site_id = :site_id", site_id) do |row|
52
- id = row[0]
53
- title = row[1]
54
- @@cache[id] = Group.new(id, site, title)
55
- @@cache_by_site_id[site_id] << @@cache[id]
44
+
45
+ DB.connect[:sakai_site_group].filter(:site_id => site_id).all.each do |row|
46
+ @@cache[row[:group_id]] = Group.new(row[:group_id], site, row[:title])
47
+ @@cache_by_site_id[site_id] << @@cache[row[:group_id]]
56
48
  end
57
49
  end
58
50
  @@cache_by_site_id[site_id]
59
51
  end
60
52
 
61
53
  def self.count_by_site_id(site_id)
62
- count = 0
63
- DB.connect.exec("select count(*) from sakai_site_group " +
64
- "where site_id=:site_id", site_id) do |row|
65
- count = row[0].to_i
66
- end
67
- count
54
+ DB.connect[:sakai_site_group].filter(:site_id => site_id).count
68
55
  end
69
56
 
70
57
  def properties
@@ -100,20 +87,22 @@ module SakaiInfo
100
87
  end
101
88
 
102
89
  class GroupProperty
103
- attr_reader :name, :value
104
-
105
- def initialize(name, value)
106
- @name = name
107
- @value = value
90
+ def self.get(group_id, property_name)
91
+ row = DB.connect[:sakai_site_group_property].
92
+ filter(:group_id => group_id, :name => property_name).first
93
+ if row.nil?
94
+ nil
95
+ else
96
+ row[:value].read
97
+ end
108
98
  end
109
99
 
110
100
  def self.find_by_group_id(group_id)
111
- properties = []
112
- DB.connect.exec("select name, value from sakai_site_group_property " +
113
- "where group_id=:group_id", group_id) do |row|
114
- properties << GroupProperty.new(row[0], row[1].read)
101
+ properties = {}
102
+ DB.connect[:sakai_site_group_property].where(:group_id => group_id).all.each do |row|
103
+ properties[row[:name]] = row[:value].read
115
104
  end
116
- properties
105
+ return properties
117
106
  end
118
107
  end
119
108
  end
@@ -2,7 +2,7 @@
2
2
  # SakaiInfo::Message library
3
3
  #
4
4
  # Created 2012-02-17 daveadams@gmail.com
5
- # Last updated 2012-02-18 daveadams@gmail.com
5
+ # Last updated 2012-02-24 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -36,14 +36,10 @@ module SakaiInfo
36
36
  raise UnknownMessageTypeException
37
37
  end
38
38
 
39
- count = 0
40
- DB.connect.exec("select count(*) from mfr_message_t " +
41
- "where message_dtype = :t " +
42
- "and to_char(created,'YYYY-MM-DD') = :d",
43
- message_type, date_str) do |row|
44
- count = row[0].to_i
45
- end
46
- count
39
+ DB.connect.fetch("select count(*) as count from mfr_message_t " +
40
+ "where message_dtype = ? and " +
41
+ "to_char(created,'YYYY-MM-DD') = ? ",
42
+ message_type, date_str).first[:count].to_i
47
43
  end
48
44
 
49
45
  private
@@ -75,28 +71,23 @@ module SakaiInfo
75
71
  @@cache = {}
76
72
 
77
73
  def self.count_by_site_id(site_id)
78
- count = 0
79
- DB.connect.exec("select count(*) from mfr_open_forum_t " +
80
- "where surrogatekey = (select id from mfr_area_t " +
81
- "where type_uuid = :type_uuid " +
82
- "and context_id = :site_id)",
83
- MessageTypeUUID::FORUM_POST, site_id) do |row|
84
- count = row[0].to_i
85
- end
86
- count
74
+ DB.connect.fetch("select count(*) as count from mfr_open_forum_t " +
75
+ "where surrogatekey = (select id from mfr_area_t " +
76
+ "where type_uuid = ? and context_id = ?)",
77
+ MessageTypeUUID::FORUM_POST, site_id).first[:count].to_i
87
78
  end
88
79
 
89
80
  @@cache_by_site_id = {}
90
81
  def self.find_by_site_id(site_id)
91
82
  if @@cache_by_site_id[site_id].nil?
92
83
  @@cache_by_site_id[site_id] = []
93
- DB.connect.exec("select id, title from mfr_open_forum_t " +
94
- "where surrogatekey = (select id from mfr_area_t " +
95
- "where type_uuid = :type_uuid " +
96
- "and context_id = :site_id) order by sort_index",
97
- MessageTypeUUID::FORUM_POST, site_id) do |row|
98
- id = row[0].to_i.to_s
99
- title = row[1]
84
+ DB.connect.fetch("select id, title from mfr_open_forum_t " +
85
+ "where surrogatekey = (select id from mfr_area_t " +
86
+ "where type_uuid = ? " +
87
+ "and context_id = ?) order by sort_index",
88
+ MessageTypeUUID::FORUM_POST, site_id) do |row|
89
+ id = row[:id].to_i.to_s
90
+ title = row[:title]
100
91
  @@cache[id] = Forum.new(id, title)
101
92
  @@cache_by_site_id[site_id] << @@cache[id]
102
93
  end
@@ -47,12 +47,19 @@ module SakaiInfo
47
47
  object_type_serialization
48
48
  end
49
49
 
50
- def to_yaml
51
- serialize.to_yaml
50
+ def to_yaml(*q)
51
+ serialize(q).to_yaml
52
52
  end
53
53
 
54
- def to_json
55
- serialize.to_json
54
+ def to_json(*q)
55
+ serialize(q).to_json
56
+ end
57
+
58
+ # support for CLI -- returns an array of symbols that can be
59
+ # passed back to #serialize, #to_yaml, or #to_json
60
+ # should be reimplemented in all object classes
61
+ def self.all_serializations
62
+ [:default]
56
63
  end
57
64
  end
58
65
  end
@@ -2,7 +2,7 @@
2
2
  # SakaiInfo::Samigo library
3
3
  #
4
4
  # Created 2012-02-17 daveadams@gmail.com
5
- # Last updated 2012-02-18 daveadams@gmail.com
5
+ # Last updated 2012-02-24 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -22,13 +22,11 @@ module SakaiInfo
22
22
  @@cache = {}
23
23
  def self.find(id)
24
24
  if @@cache[id].nil?
25
- DB.connect.exec("select title, agent_id from sam_assessmentbase_t " +
26
- "where id=:quizid", id) do |row|
27
- @@cache[id] = PendingQuiz.new(id, row[0], Site.find(row[1]))
28
- end
29
- if @@cache[id].nil?
25
+ row = DB.connect[:sam_assessmentbase_t].filter(:id => id).first
26
+ if row.nil?
30
27
  raise ObjectNotFoundException.new(PendingQuiz, id)
31
28
  end
29
+ @@cache[id] = PendingQuiz.new(id, row[0], Site.find(row[1]))
32
30
  end
33
31
  @@cache[id]
34
32
  end
@@ -36,25 +34,21 @@ module SakaiInfo
36
34
  def self.find_by_site_id(site_id)
37
35
  results = []
38
36
  site = Site.find(site_id)
39
- DB.connect.exec("select id, title from sam_assessmentbase_t " +
40
- "where id in (select qualifierid from sam_authzdata_t " +
41
- "where agentid=:site_id and " +
42
- "functionid='EDIT_ASSESSMENT')", site_id) do |row|
43
- @@cache[row[0]] = PendingQuiz.new(row[0].to_i, row[1], site)
44
- results << @@cache[row[0]]
37
+ DB.connect.fetch("select id, title from sam_assessmentbase_t " +
38
+ "where id in (select qualifierid from sam_authzdata_t " +
39
+ "where agentid=? and functionid='EDIT_ASSESSMENT')",
40
+ site_id) do |row|
41
+ @@cache[row[:id]] = PendingQuiz.new(row[:id].to_i, row[:title], site)
42
+ results << @@cache[row[:id]]
45
43
  end
46
44
  results
47
45
  end
48
46
 
49
47
  def self.count_by_site_id(site_id)
50
- count = 0
51
- DB.connect.exec("select count(*) from sam_publishedassessment_t " +
52
- "where id in (select qualifierid from sam_authzdata_t " +
53
- "where agentid=:site_id and " +
54
- "functionid='EDIT_ASSESSMENT')", site_id) do |row|
55
- count = row[0].to_i
56
- end
57
- count
48
+ DB.connect.fetch("select count(*) as count from sam_publishedassessment_t " +
49
+ "where id in (select qualifierid from sam_authzdata_t " +
50
+ "where agentid=? and functionid='EDIT_ASSESSMENT')",
51
+ site_id).first[:count].to_i
58
52
  end
59
53
 
60
54
  def default_serialization
@@ -85,13 +79,12 @@ module SakaiInfo
85
79
  @@cache = {}
86
80
  def self.find(id)
87
81
  if @@cache[id].nil?
88
- DB.connect.exec("select title, agent_id from sam_publishedassessment_t " +
89
- "where id=:quizid", id) do |row|
90
- @@cache[id] = PublishedQuiz.new(id, row[0], Site.find(row[1]))
91
- end
92
- if @@cache[id].nil?
82
+ row = DB.connect[:sam_publishedassessment_t].filter(:id => id).first
83
+ if row.nil?
93
84
  raise ObjectNotFoundException.new(PublishedQuiz, id)
94
85
  end
86
+
87
+ @@cache[id] = PublishedQuiz.new(id, row[:title], Site.find(row[:agent_id]))
95
88
  end
96
89
  @@cache[id]
97
90
  end
@@ -99,25 +92,21 @@ module SakaiInfo
99
92
  def self.find_by_site_id(site_id)
100
93
  results = []
101
94
  site = Site.find(site_id)
102
- DB.connect.exec("select id, title from sam_publishedassessment_t " +
103
- "where id in (select qualifierid from sam_authzdata_t " +
104
- "where agentid=:site_id and " +
105
- "functionid='OWN_PUBLISHED_ASSESSMENT')", site_id) do |row|
106
- @@cache[row[0]] = PublishedQuiz.new(row[0].to_i, row[1], site)
107
- results << @@cache[row[0]]
95
+ DB.connect.fetch("select id, title from sam_publishedassessment_t " +
96
+ "where id in (select qualifierid from sam_authzdata_t " +
97
+ "where agentid=? and functionid='OWN_PUBLISHED_ASSESSMENT')",
98
+ site_id) do |row|
99
+ @@cache[row[:id]] = PublishedQuiz.new(row[:id].to_i, row[:title], site)
100
+ results << @@cache[row[:id]]
108
101
  end
109
102
  results
110
103
  end
111
104
 
112
105
  def self.count_by_site_id(site_id)
113
- count = 0
114
- DB.connect.exec("select count(*) from sam_publishedassessment_t " +
115
- "where id in (select qualifierid from sam_authzdata_t " +
116
- "where agentid=:site_id " +
117
- "and functionid='OWN_PUBLISHED_ASSESSMENT')", site_id) do |row|
118
- count = row[0].to_i
119
- end
120
- count
106
+ DB.connect.fetch("select count(*) as count from sam_publishedassessment_t " +
107
+ "where id in (select qualifierid from sam_authzdata_t " +
108
+ "where agentid=? and functionid='OWN_PUBLISHED_ASSESSMENT')",
109
+ site_id).first[:count].to_i
121
110
  end
122
111
 
123
112
  def default_serialization
@@ -148,13 +137,11 @@ module SakaiInfo
148
137
  @@cache = {}
149
138
  def self.find(id)
150
139
  if @@cache[id].nil?
151
- DB.connect.exec("select title, ownerid from sam_questionpool_t " +
152
- "where questionpoolid=:id", id) do |row|
153
- @@cache[id] = QuestionPool.new(id, row[0], User.find(row[1]))
154
- end
155
- if @@cache[id].nil?
140
+ row = DB.connect[:sam_questionpool_t].filter(:id => id).first
141
+ if row.nil?
156
142
  raise ObjectNotFoundException.new(QuestionPool, id)
157
143
  end
144
+ @@cache[id] = QuestionPool.new(id, row[:title], User.find(row[:owner_id]))
158
145
  end
159
146
  @@cache[id]
160
147
  end
@@ -162,31 +149,21 @@ module SakaiInfo
162
149
  def self.find_by_user_id(user_id)
163
150
  results = []
164
151
  user = User.find(user_id)
165
- DB.connect.exec("select questionpoolid, title from sam_questionpool_t " +
166
- "where ownerid=:userid", user_id) do |row|
167
- @@cache[row[0]] = QuestionPool.new(row[0].to_i, row[1], user)
168
- results << @@cache[row[0]]
152
+ DB.connect[:sam_questionpool_t].filter(:ownerid => user_id).all.each do |row|
153
+ @@cache[row[:questionpoolid]] =
154
+ QuestionPool.new(row[:questionpoolid].to_i, row[:title], user)
155
+ results << @@cache[row[:questionpoolid]]
169
156
  end
170
157
  results
171
158
  end
172
159
 
173
160
  def self.count_by_user_id(user_id)
174
- count = 0
175
- DB.connect.exec("select count(*) from sam_questionpool_t " +
176
- "where ownerid=:userid", user_id) do |row|
177
- count = row[0].to_i
178
- end
179
- count
161
+ DB.connect[:sam_questionpool_t].filter(:ownerid => user_id).count
180
162
  end
181
163
 
182
164
  def item_count
183
- if @item_count.nil?
184
- DB.connect.exec("select count(*) from sam_questionpoolitem_t " +
185
- "where questionpoolid=:id", @id) do |row|
186
- @item_count = row[0].to_i
187
- end
188
- end
189
- @item_count
165
+ @item_count ||=
166
+ DB.connect[:sam_questionpoolitem_t].filter(:questionpoolid => @id).count
190
167
  end
191
168
 
192
169
  # serialization
@@ -2,7 +2,7 @@
2
2
  # SakaiInfo::Site library
3
3
  #
4
4
  # Created 2012-02-17 daveadams@gmail.com
5
- # Last updated 2012-02-17 daveadams@gmail.com
5
+ # Last updated 2012-02-24 daveadams@gmail.com
6
6
  #
7
7
  # https://github.com/daveadams/sakai-info
8
8
  #
@@ -17,24 +17,25 @@ module SakaiInfo
17
17
  @@cache = {}
18
18
  def self.find(id)
19
19
  if @@cache[id].nil?
20
- site_id = title = type = created_at = created_by_user_id =
21
- modified_at = modified_by_user_id = joinable = join_role = nil
22
- DB.connect.exec("select site_id, title, type, " +
23
- "createdby, to_char(createdon,'YYYY-MM-DD HH24:MI:SS'), " +
24
- "modifiedby, to_char(modifiedon,'YYYY-MM-DD HH24:MI:SS'), " +
25
- "joinable, join_role " +
26
- "from sakai_site where site_id = :site_id", id) do |row|
27
- site_id, title, type, created_by_user_id, created_at, modified_by_user_id, modified_at, joinable_n, join_role = *row
28
- if joinable_n.to_i == 1
29
- joinable = true
30
- else
31
- joinable = false
32
- end
33
- end
34
- if site_id.nil?
20
+ db = DB.connect
21
+ row = db.fetch("select site_id, title, type, " +
22
+ "createdby, modifiedby, " +
23
+ "to_char(createdon,'YYYY-MM-DD HH24:MI:SS') as created_at, " +
24
+ "to_char(modifiedon,'YYYY-MM-DD HH24:MI:SS') as modified_at, " +
25
+ "joinable, join_role " +
26
+ "from sakai_site where site_id=?", id).first
27
+ if row.nil?
35
28
  raise ObjectNotFoundException.new(Site, id)
36
29
  end
37
- @@cache[id] = Site.new(id, title, type, created_by_user_id, created_at, modified_by_user_id, modified_at, joinable, join_role)
30
+
31
+ joinable = false
32
+ if row[:joinable].to_i == 1
33
+ joinable = true
34
+ end
35
+
36
+ @@cache[id] = Site.new(id, row[:title], row[:type], row[:createdby],
37
+ row[:created_at], row[:modifiedby], row[:modified_at],
38
+ joinable, row[:join_role])
38
39
  end
39
40
  @@cache[id]
40
41
  end
@@ -84,23 +85,13 @@ module SakaiInfo
84
85
  end
85
86
 
86
87
  def user_count
87
- if @user_count.nil?
88
- DB.connect.exec("select count(*) from sakai_site_user " +
89
- "where site_id=:siteid", @id) do |row|
90
- @user_count = row[0].to_i
91
- end
92
- end
93
- @user_count
88
+ @user_count ||=
89
+ DB.connect[:sakai_site_user].filter(:site_id => @id).count
94
90
  end
95
91
 
96
92
  def page_count
97
- if @page_count.nil?
98
- DB.connect.exec("select count(*) from sakai_site_page " +
99
- "where site_id=:siteid", @id) do |row|
100
- @page_count = row[0].to_i
101
- end
102
- end
103
- @page_count
93
+ @page_count ||=
94
+ DB.connect[:sakai_site_page].filter(:site_id => @id).count
104
95
  end
105
96
 
106
97
  def assignment_count
@@ -202,105 +193,68 @@ module SakaiInfo
202
193
  end
203
194
 
204
195
  # finders/counters
205
- @@total_site_count = nil
206
196
  def self.count
207
- if @@total_site_count.nil?
208
- @@total_site_count = 0
209
- DB.connect.exec("select count(*) from sakai_site") do |row|
210
- @@total_site_count = row[0].to_i
211
- end
212
- end
213
- @@total_site_count
197
+ DB.connect[:sakai_site].count
214
198
  end
215
199
 
216
200
  def self.count_by_user_id(user_id)
217
- user_count = 0
218
- DB.connect.exec("select count(*) from sakai_site_user " +
219
- "where user_id=:user_id", user_id) do |row|
220
- user_count = row[0].to_i
221
- end
222
- user_count
201
+ DB.connect[:sakai_site_user].where(:user_id => user_id).count
223
202
  end
224
203
 
225
204
  def self.count_by_type(type)
226
- type_count = 0
227
- DB.connect.exec("select count(*) from sakai_site " +
228
- "where type=:type", type) do |row|
229
- type_count = row[0].to_i
230
- end
231
- type_count
205
+ DB.connect[:sakai_site].where(:type => type).count
232
206
  end
233
207
 
234
- def self.count_by_semester(term_eid)
235
- prop_name = "term_eid"
236
- sem_count = 0
237
- DB.connect.exec("select count(*) from sakai_site_property " +
238
- "where name=:name and to_char(value)=:term_eid",
239
- prop_name, term_eid) do |row|
240
- sem_count = row[0].to_i
241
- end
242
- sem_count
208
+ def self.count_by_property(name, value)
209
+ DB.connect[:sakai_site_property].
210
+ where(:name => name, :to_char.sql_function(:value) => value).count
211
+ end
212
+
213
+ def self.find_ids_by_property(property_name, property_value)
214
+ SiteProperty.find_site_ids_by_property(property_name, property_value)
215
+ end
216
+
217
+ def self.find_ids_by_semester(term_eid)
218
+ Site.find_ids_by_property("term_eid", term_eid)
243
219
  end
244
220
 
245
221
  def self.find_all_ids
246
- ids = []
247
- DB.connect.exec("select site_id from sakai_site") do |row|
248
- ids << row[0]
249
- end
250
- ids
222
+ DB.connect[:sakai_site].select(:site_id).all.collect{|r| r[:site_id]}
251
223
  end
252
224
 
253
225
  def self.find_all_workspace_ids
254
- ids = []
255
- DB.connect.exec("select site_id from sakai_site where site_id like '~%'") do |row|
256
- ids << row[0]
257
- end
258
- ids
226
+ DB.connect[:sakai_site].select(:site_id).
227
+ where(:site_id.like("~%")).all.collect{|r| r[:site_id]}
259
228
  end
260
229
 
261
230
  def self.find_all_non_workspace_ids
262
- ids = []
263
- DB.connect.exec("select site_id from sakai_site where site_id not like '~%'") do |row|
264
- ids << row[0]
265
- end
266
- ids
231
+ DB.connect[:sakai_site].select(:site_id).
232
+ where(~:site_id.like("~%")).all.collect{|r| r[:site_id]}
267
233
  end
268
234
 
269
235
  def self.find_ids_by_type(type)
270
- ids = []
271
- DB.connect.exec("select site_id from sakai_site where type=:type", type) do |row|
272
- ids << row[0]
273
- end
274
- ids
236
+ DB.connect[:sakai_site].select(:site_id).
237
+ where(:type => type).all.collect{|r| r[:site_id]}
275
238
  end
276
239
 
277
240
  def self.find_by_type(type)
278
241
  sites = []
279
- DB.connect.exec("select site_id, title, type, " +
280
- "createdby, to_char(createdon,'YYYY-MM-DD HH24:MI:SS'), " +
281
- "modifiedby, to_char(modifiedon,'YYYY-MM-DD HH24:MI:SS'), " +
282
- "joinable, join_role " +
283
- "from sakai_site where type = :type", type) do |row|
242
+ DB.connect.fetch("select site_id, title, type, " +
243
+ "createdby, modifiedby, " +
244
+ "to_char(createdon,'YYYY-MM-DD HH24:MI:SS') as created_at, " +
245
+ "to_char(modifiedon,'YYYY-MM-DD HH24:MI:SS') as modified_at, " +
246
+ "joinable, join_role " +
247
+ "from sakai_site where type = ?", type) do |row|
284
248
  joinable = false
285
- site_id, title, type, created_by_user_id, created_at,
286
- modified_by_user_id, modified_at, joinable_n, join_role = *row
287
249
  if joinable_n.to_i == 1
288
250
  joinable = true
289
251
  end
290
- @@cache[site_id] = Site.new(site_id, title, type, created_by_user_id, created_at, modified_by_user_id, modified_at, joinable, join_role)
291
- sites << @@cache[site_id]
252
+ @@cache[row[:site_id]] = Site.new(row[:site_id], row[:title], row[:type], row[:createdby], row[:created_at], row[:modifiedby], row[:modified_at], joinable, row[:join_role])
253
+ sites << @@cache[row[:site_id]]
292
254
  end
293
255
  sites
294
256
  end
295
257
 
296
- def self.find_ids_by_property(property_name, property_value)
297
- SiteProperty.find_site_ids_by_property(property_name, property_value)
298
- end
299
-
300
- def self.find_ids_by_semester(term_eid)
301
- find_ids_by_property("term_eid", term_eid)
302
- end
303
-
304
258
  # serialization methods
305
259
  def default_serialization
306
260
  result = {
@@ -378,7 +332,7 @@ module SakaiInfo
378
332
  result
379
333
  end
380
334
 
381
- def disk_serialization
335
+ def disk_unformatted_serialization
382
336
  {
383
337
  "disk_usage" => {
384
338
  "resources" => self.resource_storage.size_on_disk,
@@ -393,10 +347,10 @@ module SakaiInfo
393
347
  }
394
348
  end
395
349
 
396
- def disk_formatted_serialization
397
- result = disk_serialization["disk_usage"]
350
+ def disk_serialization
351
+ result = disk_unformatted_serialization["disk_usage"]
398
352
  result.keys.each do |key|
399
- result[key] = format_filesize(result[key])
353
+ result[key] = Util.format_filesize(result[key])
400
354
  end
401
355
  {
402
356
  "disk_usage" => result
@@ -433,7 +387,7 @@ module SakaiInfo
433
387
  end
434
388
  end
435
389
 
436
- def realm_roles_serialization
390
+ def realm_serialization
437
391
  {
438
392
  "realm_roles" => self.realm.realm_roles.collect { |rr| rr.serialize(:summary) }
439
393
  }
@@ -448,39 +402,38 @@ module SakaiInfo
448
402
  {}
449
403
  end
450
404
  end
405
+
406
+ def self.all_serializations
407
+ [
408
+ :default, :users, :pages, :groups, :quizzes, :disk, :assignments,
409
+ :announcements, :gradebook, :realm, :forums
410
+ ]
411
+ end
451
412
  end
452
413
 
453
414
  class SiteProperty
454
415
  def self.get(site_id, property_name)
455
- value = nil
456
- DB.connect.exec("select value from sakai_site_property " +
457
- "where site_id=:site_id and name=:name",
458
- site_id, property_name) do |row|
459
- value = row[0].read
416
+ row = DB.connect[:sakai_site_property].
417
+ where(:site_id => site_id, :name => property_name).first
418
+ if row.nil?
419
+ nil
420
+ else
421
+ row[:value].read
460
422
  end
461
- return value
462
423
  end
463
424
 
464
425
  def self.find_by_site_id(site_id)
465
426
  properties = {}
466
- DB.connect.exec("select name, value from sakai_site_property " +
467
- "where site_id=:site_id", site_id) do |row|
468
- name = row[0]
469
- value = row[1].read
470
- properties[name] = value
427
+ DB.connect[:sakai_site_property].where(:site_id => site_id).all.each do |row|
428
+ properties[row[:name]] = row[:value].read
471
429
  end
472
430
  return properties
473
431
  end
474
432
 
475
433
  def self.find_site_ids_by_property(name, value)
476
- ids = []
477
- DB.connect.exec("select distinct(site_id) from sakai_site_property " +
478
- "where name=:name " +
479
- "and to_char(value)=:value",
480
- name, value) do |row|
481
- ids << row[0]
482
- end
483
- ids
434
+ DB.connect[:sakai_site_property].
435
+ where(:name => name, :to_char.sql_function(:value) => value).
436
+ all.collect{|r| r[:site_id]}
484
437
  end
485
438
  end
486
439
 
@@ -490,18 +443,13 @@ module SakaiInfo
490
443
  @@cache = {}
491
444
  def self.find(id)
492
445
  if @@cache[id].nil?
493
- title = order = layout = site = nil
494
- DB.connect.exec("select title, site_order, layout, site_id " +
495
- "from sakai_site_page where page_id = :page_id", id) do |row|
496
- title = row[0]
497
- order = row[1].to_i
498
- layout = row[2]
499
- site = Site.find(row[3])
500
- end
501
- if title.nil?
446
+ row = DB.connect[:sakai_site_page].where(:page_id => id).first
447
+ if row.nil?
502
448
  raise ObjectNotFoundException(Page, id)
503
449
  end
504
- @@cache[id] = Page.new(id, title, order, layout, site)
450
+
451
+ site = Site.find(row[:site_id])
452
+ @@cache[id] = Page.new(id, row[:title], row[:order].to_i, row[:layout], site)
505
453
  end
506
454
  @@cache[id]
507
455
  end
@@ -509,11 +457,12 @@ module SakaiInfo
509
457
  def self.find_by_site_id(site_id)
510
458
  results = []
511
459
  site = Site.find(site_id)
512
- DB.connect.exec("select page_id, title, site_order, layout " +
513
- "from sakai_site_page where site_id = :site_id " +
514
- "order by site_order", site_id) do |row|
515
- @@cache[row[0]] = Page.new(row[0], row[1], row[2].to_i, row[3], site)
516
- results << @@cache[row[0]]
460
+ DB.connect[:sakai_site_page].
461
+ where(:site_id => site_id).order(:site_order).all.each do |row|
462
+ @@cache[row[:page_id]] =
463
+ Page.new(row[:page_id], row[:title], row[:site_order].to_i,
464
+ row[:layout], site)
465
+ results << @@cache[row[:page_id]]
517
466
  end
518
467
  results
519
468
  end
@@ -557,21 +506,19 @@ module SakaiInfo
557
506
 
558
507
  class PageProperty
559
508
  def self.get(page_id, property_name)
560
- value = nil
561
- DB.connect.exec("select value from sakai_site_page_property " +
562
- "where page_id=:page_id and name=:name", page_id, property_name) do |row|
563
- value = row[0].read
509
+ row = DB.connect[:sakai_site_page_property].
510
+ filter(:page_id => page_id, :name => property_name).first
511
+ if row.nil?
512
+ nil
513
+ else
514
+ row[:value].read
564
515
  end
565
- return value
566
516
  end
567
517
 
568
518
  def self.find_by_page_id(page_id)
569
519
  properties = {}
570
- DB.connect.exec("select name, value from sakai_site_page_property " +
571
- "where page_id=:page_id", page_id) do |row|
572
- name = row[0]
573
- value = row[1].read
574
- properties[name] = value
520
+ DB.connect[:sakai_site_page_property].where(:page_id => page_id).all.each do |row|
521
+ properties[row[:name]] = row[:value].read
575
522
  end
576
523
  return properties
577
524
  end
@@ -583,18 +530,15 @@ module SakaiInfo
583
530
  @@cache = {}
584
531
  def self.find(id)
585
532
  if @@cache[id].nil?
586
- tool_id = title = registration = page_order = layout_hints = page = nil
587
- DB.connect.exec("select tool_id, title, registration, page_order, " +
588
- "layout_hints, page_id " +
589
- "from sakai_site_tool where tool_id = :tool_id", id) do |row|
590
- tool_id, title, registration, page_order_s, layout_hints, page_id = *row
591
- page_order = page_order_s.to_i
592
- page = Page.find(page_id)
593
- end
594
- if tool_id.nil?
533
+ row = DB.connect[:sakai_site_tool].where(:tool_id => id).first
534
+ if row.nil?
595
535
  raise ObjectNotFoundException.new(Tool, id)
596
536
  end
597
- @@cache[id] = Tool.new(tool_id, title, registration, page_order, layout_hints, page)
537
+
538
+ page = Page.find(row[:page_id])
539
+ @@cache[id] =
540
+ Tool.new(id, row[:title], row[:registration], row[:page_order].to_i,
541
+ row[:layout_hints], page)
598
542
  end
599
543
  @@cache[id]
600
544
  end
@@ -602,11 +546,12 @@ module SakaiInfo
602
546
  def self.find_by_page_id(page_id)
603
547
  results = []
604
548
  page = Page.find(page_id)
605
- DB.connect.exec("select tool_id, title, registration, page_order, layout_hints " +
606
- "from sakai_site_tool where page_id = :page_id " +
607
- "order by page_order", page_id) do |row|
608
- @@cache[row[0]] = Tool.new(row[0], row[1], row[2], row[3].to_i, row[4], page)
609
- results << @@cache[row[0]]
549
+ DB.connect[:sakai_site_tool].
550
+ where(:page_id => page_id).order(:page_order).all.each do |row|
551
+ @@cache[row[:tool_id]] =
552
+ Tool.new(row[:tool_id], row[:title], row[:registration], row[:page_order].to_i,
553
+ row[:layout_hints], page)
554
+ results << @@cache[row[:tool_id]]
610
555
  end
611
556
  results
612
557
  end
@@ -657,22 +602,19 @@ module SakaiInfo
657
602
 
658
603
  class ToolProperty
659
604
  def self.get(tool_id, property_name)
660
- value = nil
661
- DB.connect.exec("select value from sakai_site_tool_property " +
662
- "where tool_id=:tool_id and name=:name",
663
- tool_id, property_name) do |row|
664
- value = row[0].read
605
+ row = DB.connect[:sakai_site_tool_property].
606
+ filter(:tool_id => tool_id, :name => property_name).first
607
+ if row.nil?
608
+ nil
609
+ else
610
+ row[:value].read
665
611
  end
666
- return value
667
612
  end
668
613
 
669
614
  def self.find_by_tool_id(tool_id)
670
615
  properties = {}
671
- DB.connect.exec("select name, value from sakai_site_tool_property " +
672
- "where tool_id=:tool_id", tool_id) do |row|
673
- name = row[0]
674
- value = row[1].read
675
- properties[name] = value
616
+ DB.connect[:sakai_site_tool_property].where(:tool_id => tool_id).all.each do |row|
617
+ properties[row[:name]] = row[:value].read
676
618
  end
677
619
  return properties
678
620
  end
@@ -689,26 +631,26 @@ module SakaiInfo
689
631
 
690
632
  def self.find_by_site_id(site_id)
691
633
  results = []
692
- DB.connect.exec("select srrg.user_id, srr.role_name " +
693
- "from sakai_realm_rl_gr srrg, sakai_realm_role srr, sakai_realm sr " +
694
- "where srrg.role_key = srr.role_key " +
695
- "and srrg.realm_key = sr.realm_key " +
696
- "and sr.realm_id = '/site/'||:site_id", site_id) do |row|
697
- results << SiteMembership.new(site_id, row[0], row[1])
634
+ DB.connect.fetch("select srrg.user_id, srr.role_name " +
635
+ "from sakai_realm_rl_gr srrg, sakai_realm_role srr, sakai_realm sr " +
636
+ "where srrg.role_key = srr.role_key " +
637
+ "and srrg.realm_key = sr.realm_key " +
638
+ "and sr.realm_id = '/site/' || ? ", site_id) do |row|
639
+ results << SiteMembership.new(site_id, row[:user_id], row[:role_name])
698
640
  end
699
641
  results
700
642
  end
701
643
 
702
644
  def self.find_by_user_id(user_id)
703
645
  results = []
704
- DB.connect.exec("select substr(sr.realm_id,7), srr.role_name " +
705
- "from sakai_realm_rl_gr srrg, sakai_realm_role srr, sakai_realm sr " +
706
- "where srrg.role_key = srr.role_key " +
707
- "and srrg.realm_key = sr.realm_key " +
708
- "and srrg.user_id = :1 " +
709
- "and sr.realm_id like '/site/%' " +
710
- "and sr.realm_id not like '%/group/%'", user_id) do |row|
711
- results << SiteMembership.new(row[0], user_id, row[1])
646
+ DB.connect.fetch("select substr(sr.realm_id,7) as site_id, srr.role_name as role_name " +
647
+ "from sakai_realm_rl_gr srrg, sakai_realm_role srr, sakai_realm sr " +
648
+ "where srrg.role_key = srr.role_key " +
649
+ "and srrg.realm_key = sr.realm_key " +
650
+ "and srrg.user_id = ? " +
651
+ "and sr.realm_id like '/site/%' " +
652
+ "and sr.realm_id not like '%/group/%'", user_id) do |row|
653
+ results << SiteMembership.new(row[:site_id], user_id, row[:role_name])
712
654
  end
713
655
  results
714
656
  end