Skip to content
Snippets Groups Projects
Commit fe1219a5 authored by Mauricio Giacomini Girardello's avatar Mauricio Giacomini Girardello
Browse files

build all user objects in learning_object repository

parent cca7012b
No related branches found
No related tags found
No related merge requests found
...@@ -7,7 +7,7 @@ class LearningObjectBuilder ...@@ -7,7 +7,7 @@ class LearningObjectBuilder
# #
def self.build(objects = []) def self.build(objects = [])
lo = [] lo = []
objects = [objects] if objects.class == String objects = [objects] if objects.class == String || objects.class == Hash
objects.each do |object| objects.each do |object|
unless object['rid'].blank? unless object['rid'].blank?
o = Rails.cache.fetch(cache_key(object['rid'], object['last_modified'])) unless object['last_modified'].blank? o = Rails.cache.fetch(cache_key(object['rid'], object['last_modified'])) unless object['last_modified'].blank?
...@@ -31,15 +31,15 @@ class LearningObjectBuilder ...@@ -31,15 +31,15 @@ class LearningObjectBuilder
# cache object when build # cache object when build
lo = Rails.cache.fetch(cache_key(args['@rid'], args['last_modified']), expires_in: 12.hours) do lo = Rails.cache.fetch(cache_key(args['@rid'], args['last_modified']), expires_in: 12.hours) do
obj = LearningObject.new( obj = LearningObject.new(
id: args['@rid'], id: args['@rid'],
name: args['name'], name: args['name'],
description: args['description'], description: args['description'],
thumbnail: (args['thumbnail'] or ''), thumbnail: (args['thumbnail'] or ''),
id_dspace: args['id_dspace'], id_dspace: args['id_dspace'],
type: args['type'], type: args['type'],
bitstreams: args['bitstreams'], bitstreams: args['bitstreams'],
last_modified: args['last_modified'], last_modified: args['last_modified'],
metadata: JSON.parse(args['metadata']) metadata: JSON.parse(args['metadata'])
) )
obj.created_at = DateTime.strptime(args['created_at'], "%Y-%m-%d %H:%M:%S") unless args['created_at'].nil? obj.created_at = DateTime.strptime(args['created_at'], "%Y-%m-%d %H:%M:%S") unless args['created_at'].nil?
obj.last_modified = DateTime.strptime(args['last_modified'], "%Y-%m-%d %H:%M:%S") unless args['last_modified'].nil? obj.last_modified = DateTime.strptime(args['last_modified'], "%Y-%m-%d %H:%M:%S") unless args['last_modified'].nil?
......
class LearningObjectsController < ApplicationController class LearningObjectsController < ApplicationController
before_action :set_learning_object, only: [:show, :edit, :update, :destroy, :like, :bookmarks, :collections] before_action :set_learning_object, only: [:show, :edit, :update, :destroy, :like, :bookmarks, :collections]
after_action :increment_learning_object_views, only: [:show] after_action :increment_learning_object_views, only: [:show]
before_action :authenticate_user!, except: [:index, :show, :like] before_action :authenticate_user!, except: [:index, :show]
before_action :set_complaint_messages, only: :show before_action :set_complaint_messages, only: :show
# GET /learning_objects # GET /learning_objects
......
...@@ -17,7 +17,7 @@ module OrientDb ...@@ -17,7 +17,7 @@ module OrientDb
if !edge_exists? "Views", user.rid, learning_object.id if !edge_exists? "Views", user.rid, learning_object.id
create_and_set_edge "Views", user.rid, learning_object.id, values create_and_set_edge "Views", user.rid, learning_object.id, values
learning_object.views = learning_object.views + 1 learning_object.views = learning_object.views + 1
# If exists, update the date property of view # If exists, update the date property of view
else else
edge = get_edges "Views", "in", learning_object.id edge = get_edges "Views", "in", learning_object.id
edge = edge.first edge = edge.first
...@@ -132,16 +132,8 @@ module OrientDb ...@@ -132,16 +132,8 @@ module OrientDb
build_object result.first build_object result.first
end end
##
# This method return all learning objects of +user+ scope.
#
# No users have objects.
# Learning Object submission was not implemented yet.
# For now, an empty array is returned.
def all(user) def all(user)
#result = select_by_property(odb_class, "p_id", user.id) build_objects(get_edges_end('PublishedBy', 'out', user.rid) || [])
#build_objects result
[]
end end
def all_by_score_from_offset_to_limit(offset, limit) def all_by_score_from_offset_to_limit(offset, limit)
...@@ -305,19 +297,19 @@ module OrientDb ...@@ -305,19 +297,19 @@ module OrientDb
def max_likes def max_likes
Rails.cache.fetch('max_likes', expires_in: 6.hours) do Rails.cache.fetch('max_likes', expires_in: 6.hours) do
get_max_from_edge("Likes","in") get_max_from_edge("Likes", "in")
end end
end end
def max_views def max_views
Rails.cache.fetch('max_views', expires_in: 6.hours) do Rails.cache.fetch('max_views', expires_in: 6.hours) do
get_max_from_edge("Views","in") get_max_from_edge("Views", "in")
end end
end end
def max_downloads def max_downloads
Rails.cache.fetch('max_downloads', expires_in: 6.hours) do Rails.cache.fetch('max_downloads', expires_in: 6.hours) do
get_max_from_edge("Downloads","in") get_max_from_edge("Downloads", "in")
end end
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment