sakai-info 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +12 -6
- data/README.md +50 -78
- data/ROADMAP.md +19 -17
- data/bin/sakai-info +94 -43
- data/lib/sakai-info.rb +32 -5
- data/lib/sakai-info/announcement.rb +30 -34
- data/lib/sakai-info/assignment.rb +45 -80
- data/lib/sakai-info/authz.rb +77 -94
- data/lib/sakai-info/cli.rb +1 -23
- data/lib/sakai-info/cli/help.rb +45 -35
- data/lib/sakai-info/content.rb +28 -49
- data/lib/sakai-info/database.rb +114 -0
- data/lib/sakai-info/gradebook.rb +48 -50
- data/lib/sakai-info/group.rb +21 -32
- data/lib/sakai-info/message.rb +16 -25
- data/lib/sakai-info/sakai_object.rb +11 -4
- data/lib/sakai-info/samigo.rb +38 -61
- data/lib/sakai-info/site.rb +128 -186
- data/lib/sakai-info/user.rb +77 -68
- data/lib/sakai-info/version.rb +1 -1
- metadata +36 -11
- data/lib/sakai-info/configuration.rb +0 -288
- data/lib/sakai-info/db.rb +0 -19
- data/lib/sakai-info/instance.rb +0 -122
data/lib/sakai-info/group.rb
CHANGED
@@ -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-
|
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
|
-
|
31
|
-
|
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
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
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
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
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.
|
113
|
-
|
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
|
data/lib/sakai-info/message.rb
CHANGED
@@ -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-
|
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
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
79
|
-
|
80
|
-
|
81
|
-
|
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.
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
id = row[
|
99
|
-
title = row[
|
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
|
data/lib/sakai-info/samigo.rb
CHANGED
@@ -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-
|
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.
|
26
|
-
|
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.
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
@@cache[row[
|
44
|
-
results << @@cache[row[
|
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
|
51
|
-
|
52
|
-
|
53
|
-
|
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.
|
89
|
-
|
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.
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
@@cache[row[
|
107
|
-
results << @@cache[row[
|
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
|
114
|
-
|
115
|
-
|
116
|
-
|
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.
|
152
|
-
|
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.
|
166
|
-
|
167
|
-
|
168
|
-
results << @@cache[row[
|
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
|
-
|
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
|
-
|
184
|
-
DB.connect.
|
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
|
data/lib/sakai-info/site.rb
CHANGED
@@ -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-
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
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
|
-
|
88
|
-
DB.connect.
|
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
|
-
|
98
|
-
DB.connect.
|
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
|
-
|
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
|
-
|
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
|
-
|
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.
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
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
|
-
|
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
|
-
|
255
|
-
|
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
|
-
|
263
|
-
|
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
|
-
|
271
|
-
|
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.
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
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,
|
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
|
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
|
397
|
-
result =
|
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
|
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
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
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.
|
467
|
-
|
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
|
-
|
477
|
-
|
478
|
-
|
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
|
-
|
494
|
-
|
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
|
-
|
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.
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
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
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
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.
|
571
|
-
|
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
|
-
|
587
|
-
|
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
|
-
|
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.
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
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
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
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.
|
672
|
-
|
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.
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
results << SiteMembership.new(site_id, row[
|
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.
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
results << SiteMembership.new(row[
|
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
|