diff --git a/app/controllers/learning_objects_controller.rb b/app/controllers/learning_objects_controller.rb index 2b4dc78fb8d094ee26b1f03e9db5c487d5d59efc..ac12721c749a8c9e0ad7fb1a2a79631f7d3a4601 100644 --- a/app/controllers/learning_objects_controller.rb +++ b/app/controllers/learning_objects_controller.rb @@ -1,5 +1,5 @@ class LearningObjectsController < ApplicationController - before_action :set_learning_object, only: [:show, :edit, :update, :destroy, :like, :bookmark] + before_action :set_learning_object, only: [:show, :edit, :update, :destroy, :like, :bookmarks, :collections] after_action :increment_learning_object_views, only: [:show] before_action :authenticate_user!, except: [:index, :show, :like] before_action :set_complaint_messages, only: :show @@ -88,6 +88,11 @@ class LearningObjectsController < ApplicationController end end + # GET /learning_objects/1/collections.json + def collections + @collections = @learning_object.collections + end + private # Use callbacks to share common setup or constraints between actions. diff --git a/app/models/learning_object.rb b/app/models/learning_object.rb index 5f9b4f8cbcb543a434d3af3cd4bb347322f280f4..aa2935bd697cca8ded5de6787894a7e6dfee189c 100644 --- a/app/models/learning_object.rb +++ b/app/models/learning_object.rb @@ -16,6 +16,10 @@ class LearningObject super(params.merge(defaults)) end + def collections + collection_repository.find_by_learning_object self + end + def like(user) learning_object_repository.like user, self end diff --git a/app/repositories/orient_db/collection_repository.rb b/app/repositories/orient_db/collection_repository.rb index 00fd055e1558651126b6101e7be9810a29df6dd9..8b8be44f814b18fe351a131cc0804d63194664f6 100644 --- a/app/repositories/orient_db/collection_repository.rb +++ b/app/repositories/orient_db/collection_repository.rb @@ -43,7 +43,16 @@ module OrientDb def all(user) query = sprintf("select * from (select expand(in('BelongsTo')) from %s) where name<>'Bookmarks'", user.rid) - objects = build_objects connection.query(query) + build_objects connection.query(query) + end + + def find_by_learning_object(learning_object) + if learning_object.id.to_s.empty? + return [] + end + + query = sprintf("select * from %s where learning_objects contains %s", odb_class, learning_object.id) + build_objects connection.query(query) end def bookmarks(user)