Class: SakaiInfo::ContentCollection
Instance Attribute Summary collapse
Attributes inherited from Content
#parent_id
Attributes inherited from SakaiObject
#id
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Content
all_serializations, #binary_entity, #child_summary_serialization, #effective_realm, #mod_details_serialization, #mod_serialization, #original_mod_details_serialization, #original_mod_serialization, #parent, #properties_serialization, #realm, #realm_serialization
Methods included from ModProps
included
Methods inherited from SakaiObject
all_serializations, #dbrow_only_serialization, #dbrow_serialization, descendants, #object_type_serialization, #serialize, #shell_serialization, #to_csv, #to_json, #to_yaml
Constructor Details
Returns a new instance of ContentCollection.
329
330
331
332
333
334
335
336
337
|
# File 'lib/sakai-info/content.rb', line 329
def initialize(dbrow)
@dbrow = dbrow
@id = @dbrow[:collection_id]
@parent_id = @dbrow[:in_collection]
@table_name = "content_collection"
@id_column = "collection_id"
end
|
Instance Attribute Details
#dbrow ⇒ Object
Returns the value of attribute dbrow.
322
323
324
|
# File 'lib/sakai-info/content.rb', line 322
def dbrow
@dbrow
end
|
Class Method Details
.clear_cache ⇒ Object
324
325
326
|
# File 'lib/sakai-info/content.rb', line 324
def self.clear_cache
@@cache = {}
end
|
.count_by_parent(parent_id) ⇒ Object
.find(id) ⇒ Object
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
# File 'lib/sakai-info/content.rb', line 339
def self.find(id)
if id !~ /\/$/
id += "/"
end
if @@cache[id].nil?
row = DB.connect[:content_collection].where(:collection_id => id).first
if row.nil?
raise ObjectNotFoundException.new(ContentCollection, id)
end
@@cache[id] = ContentCollection.new(row)
end
@@cache[id]
end
|
.find!(id) ⇒ Object
return a content collection, even if it’s a missing one
.find_by_parent(parent_id) ⇒ Object
471
472
473
474
475
476
477
478
|
# File 'lib/sakai-info/content.rb', line 471
def self.find_by_parent(parent_id)
collections = []
ContentCollection.query_by_parent(parent_id).all.each do |row|
@@cache[row[:collection_id]] = ContentCollection.new(row)
collections << @@cache[row[:collection_id]]
end
collections
end
|
.find_portfolio_interaction_collections ⇒ Object
363
364
365
366
367
368
369
370
371
|
# File 'lib/sakai-info/content.rb', line 363
def self.find_portfolio_interaction_collections
collections = []
DB.connect[:content_collection].
where(Sequel.like(:collection_id, '%/portfolio-interaction/')) do |row|
@@cache[row[:collection_id]] = ContentCollection.new(row)
collections << @@cache[row[:collection_id]]
end
collections
end
|
.query_by_parent(parent_id) ⇒ Object
463
464
465
|
# File 'lib/sakai-info/content.rb', line 463
def self.query_by_parent(parent_id)
DB.connect[:content_collection].where(:in_collection => parent_id)
end
|
Instance Method Details
#child_counts ⇒ Object
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
|
# File 'lib/sakai-info/content.rb', line 388
def child_counts
@child_collection_count ||= if @child_collections.nil?
ContentCollection.count_by_parent(@id)
else
@child_collections.length
end
@child_resource_count ||= if @child_resources.nil?
ContentResource.count_by_parent(@id)
else
@child_resources.length
end
{
"collections" => @child_collection_count,
"resources" => @child_resource_count,
"total" => @child_collection_count + @child_resource_count
}
end
|
#children_serialization ⇒ Object
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
|
# File 'lib/sakai-info/content.rb', line 427
def children_serialization
result = {
"collections" => self.children["collections"].collect { |cc|
cc.serialize(:child_summary, :children)
},
"resources" => self.children["resources"].collect { |cr|
cr.serialize(:child_summary)
}
}
if result["collections"] == []
result.delete("collections")
end
if result["resources"] == []
result.delete("resources")
end
result
end
|
#default_serialization ⇒ Object
406
407
408
409
410
411
412
|
# File 'lib/sakai-info/content.rb', line 406
def default_serialization
{
"id" => self.id,
"size_on_disk" => self.size_on_disk,
"children" => self.child_counts,
}
end
|
#detailed_summary_serialization ⇒ Object
420
421
422
423
424
425
|
# File 'lib/sakai-info/content.rb', line 420
def detailed_summary_serialization
{
"id" => self.id,
"size_on_disk" => self.size_on_disk,
}
end
|
#full_children_serialization ⇒ Object
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
|
# File 'lib/sakai-info/content.rb', line 445
def full_children_serialization
result = {
"collections" => self.children["collections"].collect { |cc|
cc.serialize(:detailed_summary, :full_children)
},
"resources" => self.children["resources"].collect { |cr|
cr.serialize(:detailed_summary)
}
}
if result["collections"] == []
result.delete("collections")
end
if result["resources"] == []
result.delete("resources")
end
result
end
|
#size_on_disk ⇒ Object
373
374
375
376
377
|
# File 'lib/sakai-info/content.rb', line 373
def size_on_disk
@size_on_disk ||=
DB.connect[:content_resource].select(Sequel.function(:sum, :file_size).as(:total_size)).
where(Sequel.like(:resource_id, "#{@id}%")).first[:total_size].to_i
end
|
#summary_serialization ⇒ Object
414
415
416
417
418
|
# File 'lib/sakai-info/content.rb', line 414
def summary_serialization
{
"id" => self.id,
}
end
|