Skip to content
Snippets Groups Projects
Commit 8faed759 authored by Bruno Nocera Zanette's avatar Bruno Nocera Zanette
Browse files

Refactor code to use LearningObject Model

Before these changes, the view was using the hash returned by OrientDB directly.
parent 8700152a
No related branches found
No related tags found
No related merge requests found
......@@ -10,10 +10,10 @@ class LearningObjectsController < ApplicationController
# GET /learning_objects/1
# GET /learning_objects/1.json
def show
@object = repository.for(:learning_object).get_by_dspaceid params[:id]
unless @object.nil?
@like_counts = repository.for(:edge).get_in_edges_count "Likes", @object.first["@rid"]
unless @learning_object.nil?
@like_counts = repository.for(:edge).get_in_edges_count "Likes", @learning_object.id
end
puts @learning_object.metadata
end
# GET /learning_objects/new
......@@ -68,7 +68,7 @@ class LearningObjectsController < ApplicationController
private
# Use callbacks to share common setup or constraints between actions.
def set_learning_object
@learning_object = repository.for(:learning_object).find(params[:id])
@learning_object = repository.for(:learning_object).get_by_dspaceid params[:id]
end
# Never trust parameters from the scary internet, only allow the white list through.
......
......@@ -2,7 +2,16 @@ class LearningObject
include ActiveModel::Model
attr_accessor :id, :name, :title, :author_id, :description, :date, :exercises,
:references, :supplementary_material, :license_name, :license_uri,
:files
attr_accessor :id, :id_dspace, :title, :description, :date_creation,
:thumbnail, :metadata
def initialize args
@id = args[:id] || ''
@id_dspace = args[:id_dspace] || ''
@title = args[:title] || ''
@description = args[:description] || ''
@date_creation = args[:date_creation] || ''
@thumbnail = args[:thumbnail] || ''
@metadata = args[:metadata] || []
end
end
......@@ -8,7 +8,8 @@ module OrientDb
end
def get_by_dspaceid(id_dspace)
OrientDb::Client.instance.query "SELECT FROM LearningObject WHERE id_dspace=#{id_dspace}"
result = OrientDb::Client.instance.query "SELECT FROM LearningObject WHERE id_dspace=#{id_dspace}"
return initialize_learning_object result.first
end
def save(object)
......@@ -22,6 +23,15 @@ module OrientDb
private
def initialize_learning_object args
LearningObject.new(
:id => args["@rid"],
:id_dspace => args["id_dspace"],
:title => args["dc_title"],
:metadata => args
)
end
def find_by_id(rid)
@connection.query "SELECT FROM User WHERE @rid=#{rid}"
end
......
<h1><%= @object[0]["dc_title"] %></h1>
<h1><%= @learning_object.title %></h1>
<ul>
<li><b>Autor: </b><%= get_object_property(@object,"dc_contributor_author") %></li>
<li><b>Tipo: </b><%= get_object_property(@object,"dc_type") %></li>
<li><b>Data: </b><%= get_object_property(@object,"dc_date_available") %></li>
<li><b>Linguagem: </b><%= get_object_property(@object,"dc_language") %></li>
<li><b>Autor: </b><%= @learning_object.metadata["dc_contributor_author"] %></li>
<li><b>Tipo: </b><%= @learning_object.metadata["dc_type"] %></li>
<li><b>Data: </b><%= @learning_object.metadata["dc_date_available"] %></li>
<li><b>Linguagem: </b><%= @learning_object.metadata["dc_language"] %></li>
<li><b>Categorias: </b></li>
<ul>
<% get_object_property(@object,"dc_subject_category").each do |category| %>
<% @learning_object.metadata["dc_subject_category"].each do |category| %>
<li><%= category %></li>
<% end %>
</ul>
......@@ -16,7 +17,7 @@
"Curtir",
{ action: "create_like", controller: "edges" },
method: :post,
params: { from_id: " #14:0", to_id: get_object_property(@object,"@rid") }
params: { from_id: "#14:0", to_id: @learning_object.id }
)%>
Total Curtir: <%= get_object_property(@like_counts,"COUNT") %>
......
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