Forked from
PortalMEC / portalmec
2634 commits behind the upstream repository.
-
Matheus Agio Nerone authored
Signed-off-by:
Matheus Agio Nerone <man13@inf.ufpr.br>
Matheus Agio Nerone authoredSigned-off-by:
Matheus Agio Nerone <man13@inf.ufpr.br>
learning_object_builder.rb 1.71 KiB
class LearningObjectBuilder < Builder
extend RepositoriesProxy
##
# receive a list of ids and return a list of learning objects
# useful for search pagination
#
def self.build(objects = [])
lo = []
objects = [objects] if objects.class == String || objects.class == Hash
objects.each do |object|
unless object['rid'].blank?
o = Rails.cache.fetch(cache_key(object['rid'], object['last_modified'])) unless object['last_modified'].blank?
o = learning_object_repository.find object['rid'] if o.nil?
lo << o
end
end
lo
end
def self.build_from_orientdb(args = {})
lo = nil
unless args.nil?
# cache object when build
lo = Rails.cache.fetch(cache_key(args['@rid'], args['last_modified']), expires_in: 12.hours) do
args['metadata'] = JSON.parse(args['metadata']) if args['metadata'].class == String
obj = LearningObject.new(
id: args['@rid'],
name: args['name'],
description: args['description'],
thumbnail: (args['thumbnail'] or ''),
id_dspace: args['id_dspace'],
type: args['type'],
attachment: LearningObject::Attachment.new(args['bitstreams']),
last_modified: args['last_modified'],
metadata: args['metadata']
)
obj.created_at = DateTime.strptime(args['created_at'], "%Y-%m-%d %H:%M:%S") unless args['created_at'].blank?
obj.last_modified = DateTime.strptime(args['last_modified'], "%Y-%m-%d %H:%M:%S") unless args['last_modified'].blank?
obj.published_at = DateTime.strptime(args['published_at'], "%Y-%m-%d %H:%M:%S") unless args['published_at'].blank?
obj
end
end
lo
end
end