Class: SakaiInfo::Site
- Inherits:
-
SakaiObject
- Object
- SakaiObject
- SakaiInfo::Site
- Includes:
- ModProps
- Defined in:
- lib/sakai-info/site.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#dbrow ⇒ Object
readonly
Returns the value of attribute dbrow.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes inherited from SakaiObject
Class Method Summary collapse
- .all_serializations ⇒ Object
- .clear_cache ⇒ Object
-
.count ⇒ Object
finders/counters.
- .count_by_property(name, value) ⇒ Object
- .count_by_type(type) ⇒ Object
- .count_by_user_id(user_id) ⇒ Object
- .find(id) ⇒ Object
- .find!(id) ⇒ Object
- .find_all ⇒ Object
- .find_all_ids ⇒ Object
- .find_all_non_workspace_ids ⇒ Object
- .find_all_workspace_ids ⇒ Object
- .find_by_title(title) ⇒ Object
- .find_by_type(type) ⇒ Object
- .find_ids_by_property(property_name, property_value) ⇒ Object
- .find_ids_by_semester(term_eid) ⇒ Object
- .find_ids_by_title(title) ⇒ Object
- .find_ids_by_type(type) ⇒ Object
-
.query_by_title(title) ⇒ Object
by_title: uses like.
-
.query_by_type(type) ⇒ Object
by_type queries.
Instance Method Summary collapse
-
#announcement_channel ⇒ Object
announcement properties.
- #announcement_count ⇒ Object
- #announcements ⇒ Object
- #announcements_serialization ⇒ Object
- #assignment_count ⇒ Object
- #assignments ⇒ Object
- #assignments_serialization ⇒ Object
- #attachment_storage ⇒ Object
-
#calendar ⇒ Object
calendar.
- #calendar_event_count ⇒ Object
- #calendar_events_serialization ⇒ Object
-
#default_serialization ⇒ Object
serialization methods.
- #disk_serialization ⇒ Object
- #disk_unformatted_serialization ⇒ Object
-
#disk_usage_csv ⇒ Object
generate a CSV line for disk usage reporting.
- #dropbox_storage ⇒ Object
-
#forum_count ⇒ Object
forum properties.
- #forums ⇒ Object
- #forums_serialization ⇒ Object
-
#gradebook ⇒ Object
gradebook properties.
- #gradebook_serialization ⇒ Object
-
#group_count ⇒ Object
group properties.
- #groups ⇒ Object
- #groups_serialization ⇒ Object
-
#initialize(dbrow) ⇒ Site
constructor
A new instance of Site.
- #join_role ⇒ Object
- #joinable? ⇒ Boolean
- #melete_storage ⇒ Object
- #membership ⇒ Object
- #page_count ⇒ Object
- #pages ⇒ Object
- #pages_serialization ⇒ Object
- #pending_quiz_count ⇒ Object
- #pending_quizzes ⇒ Object
- #properties ⇒ Object
- #published? ⇒ Boolean
-
#published_quiz_count ⇒ Object
samigo quiz properties.
- #published_quizzes ⇒ Object
- #quizzes_serialization ⇒ Object
-
#realm ⇒ Object
authz/realm properties.
- #realm_serialization ⇒ Object
-
#resource_storage ⇒ Object
content properties.
- #summary_serialization ⇒ Object
- #total_disk_usage ⇒ Object
- #user_count ⇒ Object
- #users_serialization ⇒ Object
Methods included from ModProps
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
Returns a new instance of Site.
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/sakai-info/site.rb', line 50 def initialize(dbrow) @dbrow = dbrow @id = dbrow[:site_id] @title = dbrow[:title] @type = dbrow[:type] @is_joinable = (dbrow[:joinable].to_i == 1) @is_published = (dbrow[:published].to_i == 1) @join_role_string = dbrow[:join_role].to_s end |
Instance Attribute Details
#dbrow ⇒ Object (readonly)
Returns the value of attribute dbrow.
14 15 16 |
# File 'lib/sakai-info/site.rb', line 14 def dbrow @dbrow end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
14 15 16 |
# File 'lib/sakai-info/site.rb', line 14 def title @title end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
14 15 16 |
# File 'lib/sakai-info/site.rb', line 14 def type @type end |
Class Method Details
.all_serializations ⇒ Object
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 |
# File 'lib/sakai-info/site.rb', line 448 def self.all_serializations [ :default, :users, :pages, :groups, :quizzes, :disk, :assignments, :announcements, :gradebook, :realm, :forums, :calendar_events, :mod, ] end |
.clear_cache ⇒ Object
22 23 24 |
# File 'lib/sakai-info/site.rb', line 22 def self.clear_cache @@cache = {} end |
.count ⇒ Object
finders/counters
220 221 222 |
# File 'lib/sakai-info/site.rb', line 220 def self.count DB.connect[:sakai_site].count end |
.count_by_property(name, value) ⇒ Object
228 229 230 231 |
# File 'lib/sakai-info/site.rb', line 228 def self.count_by_property(name, value) DB.connect[:sakai_site_property]. where(:name => name, Sequel.function(:to_char, :value) => value).count end |
.count_by_type(type) ⇒ Object
282 283 284 |
# File 'lib/sakai-info/site.rb', line 282 def self.count_by_type(type) Site.query_by_type(type).count end |
.count_by_user_id(user_id) ⇒ Object
224 225 226 |
# File 'lib/sakai-info/site.rb', line 224 def self.count_by_user_id(user_id) DB.connect[:sakai_site_user].where(:user_id => user_id).count end |
.find(id) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/sakai-info/site.rb', line 27 def self.find(id) if @@cache[id].nil? row = DB.connect[:sakai_site].where(:site_id => id).first if row.nil? raise ObjectNotFoundException.new(Site, id) end @@cache[id] = Site.new(row) end @@cache[id] end |
.find!(id) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/sakai-info/site.rb', line 39 def self.find!(id) begin site = Site.find(id) rescue ObjectNotFoundException => e if e.classname == Site.name site = MissingSite.find(id) end end site end |
.find_all ⇒ Object
241 242 243 |
# File 'lib/sakai-info/site.rb', line 241 def self.find_all DB.connect[:sakai_site].select(:site_id).all.collect{|row| @@cache[row[:site_id]] = Site.new(row)} end |
.find_all_ids ⇒ Object
245 246 247 |
# File 'lib/sakai-info/site.rb', line 245 def self.find_all_ids DB.connect[:sakai_site].select(:site_id).all.collect{|r| r[:site_id]} end |
.find_all_non_workspace_ids ⇒ Object
254 255 256 257 |
# File 'lib/sakai-info/site.rb', line 254 def self.find_all_non_workspace_ids DB.connect[:sakai_site].select(:site_id). where(~Sequel.like(:site_id, "~%")).all.collect{|r| r[:site_id]} end |
.find_all_workspace_ids ⇒ Object
249 250 251 252 |
# File 'lib/sakai-info/site.rb', line 249 def self.find_all_workspace_ids DB.connect[:sakai_site].select(:site_id). where(Sequel.like(:site_id, "~%")).all.collect{|r| r[:site_id]} end |
.find_by_title(title) ⇒ Object
269 270 271 |
# File 'lib/sakai-info/site.rb', line 269 def self.find_by_title(title) Site.query_by_title(title).all.collect{|row| @@cache[row[:site_id]] = Site.new(row)} end |
.find_by_type(type) ⇒ Object
286 287 288 |
# File 'lib/sakai-info/site.rb', line 286 def self.find_by_type(type) Site.query_by_type(type).all.collect{|row| @@cache[row[:site_id]] = Site.new(row)} end |
.find_ids_by_property(property_name, property_value) ⇒ Object
233 234 235 |
# File 'lib/sakai-info/site.rb', line 233 def self.find_ids_by_property(property_name, property_value) SiteProperty.find_site_ids_by_property(property_name, property_value) end |
.find_ids_by_semester(term_eid) ⇒ Object
237 238 239 |
# File 'lib/sakai-info/site.rb', line 237 def self.find_ids_by_semester(term_eid) Site.find_ids_by_property("term_eid", term_eid) end |
.find_ids_by_title(title) ⇒ Object
273 274 275 |
# File 'lib/sakai-info/site.rb', line 273 def self.find_ids_by_title(title) Site.query_by_title(title).select(:site_id).all.collect{|row|row[:site_id]} end |
.find_ids_by_type(type) ⇒ Object
259 260 261 262 |
# File 'lib/sakai-info/site.rb', line 259 def self.find_ids_by_type(type) DB.connect[:sakai_site].select(:site_id). where(:type => type).all.collect{|r| r[:site_id]} end |
Instance Method Details
#announcement_channel ⇒ Object
announcement properties
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/sakai-info/site.rb', line 122 def announcement_channel if @announcement_channel.nil? begin @announcement_channel = AnnouncementChannel.find_by_site_id(self.id) rescue ObjectNotFoundException @announcement_channel = -1 return nil end elsif @announcement_channel == -1 return nil end @announcement_channel end |
#announcement_count ⇒ Object
141 142 143 144 |
# File 'lib/sakai-info/site.rb', line 141 def announcement_count return 0 if self.announcement_channel.nil? @announcement_count ||= self.announcement_channel.announcement_count end |
#announcements ⇒ Object
136 137 138 139 |
# File 'lib/sakai-info/site.rb', line 136 def announcements return nil if self.announcement_channel.nil? @announcements ||= self.announcement_channel.announcements end |
#announcements_serialization ⇒ Object
406 407 408 409 410 411 412 413 414 |
# File 'lib/sakai-info/site.rb', line 406 def announcements_serialization if self.announcement_count > 0 { "announcements" => self.announcements.collect { |annc| annc.serialize(:summary) } } else {} end end |
#assignment_count ⇒ Object
99 100 101 |
# File 'lib/sakai-info/site.rb', line 99 def assignment_count @assignment_count ||= Assignment.count_by_site_id(@id) end |
#assignments ⇒ Object
85 86 87 |
# File 'lib/sakai-info/site.rb', line 85 def assignments @assignments ||= Assignment.find_by_site_id(@id) end |
#assignments_serialization ⇒ Object
396 397 398 399 400 401 402 403 404 |
# File 'lib/sakai-info/site.rb', line 396 def assignments_serialization if self.assignment_count > 0 { "assignments" => self.assignments.collect { |asn| asn.serialize(:summary) } } else {} end end |
#attachment_storage ⇒ Object
195 196 197 198 |
# File 'lib/sakai-info/site.rb', line 195 def = "/attachment/#{@id}/" @attachment_storage ||= ContentCollection.find!() end |
#calendar ⇒ Object
calendar
178 179 180 |
# File 'lib/sakai-info/site.rb', line 178 def calendar @calendar ||= Calendar.find!(@id) end |
#calendar_event_count ⇒ Object
182 183 184 |
# File 'lib/sakai-info/site.rb', line 182 def calendar_event_count @calendar_event_count ||= self.calendar.event_count end |
#calendar_events_serialization ⇒ Object
442 443 444 445 446 |
# File 'lib/sakai-info/site.rb', line 442 def calendar_events_serialization { "calendar_events" => self.calendar.events.collect { |e| e.serialize(:summary) } } end |
#default_serialization ⇒ Object
serialization methods
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/sakai-info/site.rb', line 292 def default_serialization result = { "id" => self.id, "title" => self.title, "type" => self.type, "is_published" => self.published?, "site_properties" => self.properties, "providers" => self.realm.providers, "is_joinable" => self.joinable?, "join_role" => (self.joinable? ? self.join_role.name : nil), "user_count" => self.user_count, "group_count" => self.group_count, "page_count" => self.page_count, "pending_quiz_count" => self.pending_quiz_count, "published_quiz_count" => self.published_quiz_count, "assignment_count" => self.assignment_count, "announcement_count" => self.announcement_count, "gradebook_item_count" => (self.gradebook.nil? ? 0 : self.gradebook.item_count), "forum_count" => self.forum_count, "calendar_event_count" => self.calendar_event_count, } if result["providers"].nil? or result["providers"] == "" or result["providers"] == [] result.delete("providers") end if result["is_joinable"] == false result.delete("join_role") end if result["site_properties"] == {} result.delete("site_properties") end if self.gradebook.nil? result.delete("gradebook_item_count") end result end |
#disk_serialization ⇒ Object
386 387 388 389 390 391 392 393 394 |
# File 'lib/sakai-info/site.rb', line 386 def disk_serialization result = disk_unformatted_serialization["disk_usage"] result.keys.each do |key| result[key] = Util.format_filesize(result[key]) end { "disk_usage" => result } end |
#disk_unformatted_serialization ⇒ Object
371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
# File 'lib/sakai-info/site.rb', line 371 def disk_unformatted_serialization { "disk_usage" => { "resources" => self.resource_storage.size_on_disk, "attachments" => self..size_on_disk, "melete" => self.melete_storage.size_on_disk, "dropbox" => self.dropbox_storage.size_on_disk, "total" => (self.resource_storage.size_on_disk + self..size_on_disk + self.melete_storage.size_on_disk + self.dropbox_storage.size_on_disk) } } end |
#disk_usage_csv ⇒ Object
generate a CSV line for disk usage reporting
215 216 217 |
# File 'lib/sakai-info/site.rb', line 215 def disk_usage_csv "#{@id},#{@type},#{resource_storage.size_on_disk},#{.size_on_disk},#{melete_storage.size_on_disk},#{dropbox_storage.size_on_disk},#{total_disk_usage}" end |
#dropbox_storage ⇒ Object
205 206 207 208 |
# File 'lib/sakai-info/site.rb', line 205 def dropbox_storage dropbox_collection_id = "/group-user/#{@id}/" @dropbox_storage ||= ContentCollection.find!(dropbox_collection_id) end |
#forum_count ⇒ Object
forum properties
169 170 171 |
# File 'lib/sakai-info/site.rb', line 169 def forum_count @forum_count ||= Forum.count_by_site_id(@id) end |
#forums ⇒ Object
173 174 175 |
# File 'lib/sakai-info/site.rb', line 173 def forums @forums ||= Forum.find_by_site_id(@id) end |
#forums_serialization ⇒ Object
432 433 434 435 436 437 438 439 440 |
# File 'lib/sakai-info/site.rb', line 432 def forums_serialization if self.forum_count > 0 { "forums" => self.forums.collect { |fr| fr.serialize(:summary) } } else {} end end |
#gradebook ⇒ Object
gradebook properties
164 165 166 |
# File 'lib/sakai-info/site.rb', line 164 def gradebook @gradebook ||= Gradebook.find_by_site_id(@id).first end |
#gradebook_serialization ⇒ Object
416 417 418 419 420 421 422 423 424 |
# File 'lib/sakai-info/site.rb', line 416 def gradebook_serialization if self.gradebook { "gradebook" => self.gradebook.serialize(:site_summary, :items) } else {} end end |
#group_count ⇒ Object
group properties
113 114 115 |
# File 'lib/sakai-info/site.rb', line 113 def group_count @group_count ||= Group.count_by_site_id(@id) end |
#groups ⇒ Object
117 118 119 |
# File 'lib/sakai-info/site.rb', line 117 def groups @groups ||= Group.find_by_site_id(@id) end |
#groups_serialization ⇒ Object
349 350 351 352 353 |
# File 'lib/sakai-info/site.rb', line 349 def groups_serialization { "groups" => self.groups.collect { |grp| grp.serialize(:summary) } } end |
#join_role ⇒ Object
69 70 71 |
# File 'lib/sakai-info/site.rb', line 69 def join_role @join_role_string end |
#joinable? ⇒ Boolean
61 62 63 |
# File 'lib/sakai-info/site.rb', line 61 def joinable? @is_joinable end |
#melete_storage ⇒ Object
200 201 202 203 |
# File 'lib/sakai-info/site.rb', line 200 def melete_storage melete_collection_id = "/private/meleteDocs/#{@id}/" @melete_storage ||= ContentCollection.find!(melete_collection_id) end |
#membership ⇒ Object
77 78 79 |
# File 'lib/sakai-info/site.rb', line 77 def membership @membership ||= SiteMembership.find_by_site_id(@id) end |
#page_count ⇒ Object
94 95 96 97 |
# File 'lib/sakai-info/site.rb', line 94 def page_count @page_count ||= DB.connect[:sakai_site_page].filter(:site_id => @id).count end |
#pages ⇒ Object
81 82 83 |
# File 'lib/sakai-info/site.rb', line 81 def pages @pages ||= Page.find_by_site_id(@id) end |
#pages_serialization ⇒ Object
343 344 345 346 347 |
# File 'lib/sakai-info/site.rb', line 343 def pages_serialization { "pages" => self.pages.collect { |pg| pg.serialize(:site_summary) } } end |
#pending_quiz_count ⇒ Object
151 152 153 |
# File 'lib/sakai-info/site.rb', line 151 def pending_quiz_count @pending_quiz_count ||= PendingQuiz.count_by_site_id(@id) end |
#pending_quizzes ⇒ Object
159 160 161 |
# File 'lib/sakai-info/site.rb', line 159 def pending_quizzes @pending_quizzes ||= PendingQuiz.find_by_site_id(@id) end |
#properties ⇒ Object
73 74 75 |
# File 'lib/sakai-info/site.rb', line 73 def properties @properties ||= SiteProperty.find_by_site_id(@id) end |
#published? ⇒ Boolean
65 66 67 |
# File 'lib/sakai-info/site.rb', line 65 def published? @is_published end |
#published_quiz_count ⇒ Object
samigo quiz properties
147 148 149 |
# File 'lib/sakai-info/site.rb', line 147 def published_quiz_count @published_quiz_count ||= PublishedQuiz.count_by_site_id(@id) end |
#published_quizzes ⇒ Object
155 156 157 |
# File 'lib/sakai-info/site.rb', line 155 def published_quizzes @published_quizzes ||= PublishedQuiz.find_by_site_id(@id) end |
#quizzes_serialization ⇒ Object
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
# File 'lib/sakai-info/site.rb', line 355 def quizzes_serialization result = {} if self.pending_quiz_count > 0 or self.published_quiz_count > 0 result["quizzes"] = {} end if self.pending_quiz_count > 0 result["quizzes"]["pending"] = self.pending_quizzes.collect { |pq| pq.serialize(:site_summary) } end if self.published_quiz_count > 0 result["quizzes"]["published"] = self.published_quizzes.collect { |pq| pq.serialize(:site_summary) } end result end |
#realm ⇒ Object
authz/realm properties
104 105 106 |
# File 'lib/sakai-info/site.rb', line 104 def realm @authz_realm ||= AuthzRealm.find_by_site_id(@id) end |
#realm_serialization ⇒ Object
426 427 428 429 430 |
# File 'lib/sakai-info/site.rb', line 426 def realm_serialization { "realm_roles" => self.realm.realm_roles.collect { |rr| rr.serialize(:summary) } } end |
#resource_storage ⇒ Object
content properties
187 188 189 190 191 192 193 |
# File 'lib/sakai-info/site.rb', line 187 def resource_storage resource_collection_id = "/group/#{@id}/" if @type == "myworkspace" or @type == "guestworkspace" resource_collection_id = "/user/#{@id.sub(/^~/,'')}" end @resource_storage ||= ContentCollection.find!(resource_collection_id) end |
#summary_serialization ⇒ Object
328 329 330 331 332 333 334 335 |
# File 'lib/sakai-info/site.rb', line 328 def summary_serialization { "id" => self.id, "title" => self.title, "type" => self.type, "created_by" => self.created_by.eid } end |
#total_disk_usage ⇒ Object
210 211 212 |
# File 'lib/sakai-info/site.rb', line 210 def total_disk_usage resource_storage.size_on_disk + .size_on_disk + melete_storage.size_on_disk + dropbox_storage.size_on_disk end |
#user_count ⇒ Object
89 90 91 92 |
# File 'lib/sakai-info/site.rb', line 89 def user_count @user_count ||= DB.connect[:sakai_site_user].filter(:site_id => @id).count end |
#users_serialization ⇒ Object
337 338 339 340 341 |
# File 'lib/sakai-info/site.rb', line 337 def users_serialization { "users" => self.membership.collect { |sm| sm.serialize(:site_summary) } } end |