diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 2e7f45d2733fb14360bf9e1e6524d57e38b6afe9..3039b8696c42a5bc5f50b414b554b58023109d14 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -10,19 +10,18 @@ class WelcomeController < ApplicationController end @General = mainPage[0]["highlights"].collect do |id| - repository.for(:learning_object).find_by_id(id)[0] + repository.for(:learning_object).find(id) end @Subjects = repository.for(:subject).find_all.take(8) + @Subjects.delete_if do |subject| + if subject['highlights'].nil? || subject['highlights'].empty? + true + end + end @Subjects.each do |subject| - puts subject['highlights'].first - puts '@@@@' - object = repository.for(:learning_object).find_by_id(subject['highlights'].first) - puts object - puts '@@@@' - subject['first_highlight'] = object[0] - puts subject - puts '------------------' + object = repository.for(:learning_object).find(subject['highlights'].first) + subject['first_highlight'] = object end end diff --git a/app/repositories/orient_db/learning_object_repository.rb b/app/repositories/orient_db/learning_object_repository.rb index c3ffb322745321993608d00d8e6ff4de9d3c55f4..5f625e9665f1f9e294cf3a84a5d1692c5950f723 100644 --- a/app/repositories/orient_db/learning_object_repository.rb +++ b/app/repositories/orient_db/learning_object_repository.rb @@ -37,7 +37,7 @@ module OrientDb # learning_object = repository.for(:learning_objects).get_by_dspace_id 123 # def find(id) - result = connection.query "SELECT FROM '#{id}'" + result = connection.query "SELECT FROM #{id}" build_learning_object result.first end @@ -65,29 +65,6 @@ module OrientDb # likes[0]["outE"] #end - def has(rid) - connection.query "SELECT expand(in) FROM (SELECT expand(out_has) FROM User WHERE @rid=#{rid})" - end - - def find_all - connection.query("SELECT FROM LearningObject",{:limit=>-1} ) - end - - def find_by_id(id) - connection.query "SELECT FROM LearningObject where @rid = '#{id}'" - end - - def insert_data (name, url) - connection.command "INSERT INTO LearningObject (name,URL) VALUES ('#{name}','#{url}')" - end - - - def destroy_data(id) - return @connection.command "DELETE VERTEX LearningObject where @rid = '#{id}'" - rescue - return nil - end - private def count_likes(learning_object) @@ -113,7 +90,6 @@ module OrientDb hash.each do |h| learning_objects << build_learning_object(h) end - learning_objects end diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 4dee39f87f9cd16d683019e146711c484e748aa3..0eccf9226ea60947d02cc083565590f38e3e64db 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -59,11 +59,15 @@ </a> </div> <div class="media-body"> - <h4 class="media-heading"><%= highlight['name'] %></h4> + <% if highlight.title.nil? %> + <h4 class="media-heading">Sem TÃtulo</h4> + <% else %> + <h4 class="media-heading"><%= highlight.title %></h4> + <% end %> <span>Por <a>Usuário </a></span> - <span class="glyphicon glyphicon-eye-open"><%= highlight['views'] %>  </span> - <span class="glyphicon glyphicon-star"><%= highlight['likes'] %> </span><br> - <%= highlight['description']%><br> + <span class="glyphicon glyphicon-eye-open"><%= highlight.views.count %>  </span> + <span class="glyphicon glyphicon-star"><%= highlight.likes.count %> </span><br> + <%= highlight.description%><br> Em<b> Biologia</b>, <b>Biologia Marinha</b> </div> </div> @@ -80,17 +84,22 @@ <div class="row"> <div class="col-md-11 col-sm-offset-1 padding-left-0"> + <% unless @Subjects.nil? || @Subjects.empty?%> <h2>Em Destaque</h2> <ul class="list-unstyled"> <% @Subjects.each do |subject|%> <li class="col-sm-3 padding-left-0"> <div class="media"> - <h4><b><%= subject['name']%></b></h4> + <h4><b><%= subject['name'].truncate(20)%></b></h4> <div> <img src="http://dummyimage.com/250x150/363336/fff" alt='dummy image' class="img-responsive"> </div> <div class="media-body"> - <h4 class="media-heading"><%= subject['first_highlight']['name'] %></h4> + <% if subject['first_highlight'].title.nil? %> + <h4 class="media-heading">Sem TÃtulo</h4> + <% else %> + <h4 class="media-heading"><%= subject['first_highlight'].title %></h4> + <% end %> <span>Por <a>Usuário </a></span> <span class="glyphicon glyphicon-eye-open">200  </span> <span class="glyphicon glyphicon-star">4,5 </span> @@ -102,6 +111,7 @@ </li> <% end %> </ul> + <% end %> </div> </div> </div> diff --git a/lib/orient_db/methods/edge_methods.rb b/lib/orient_db/methods/edge_methods.rb index 379a62385bc546dc71a08a8258ac2e76e4ba0576..fdca19f5f04c6256c4ae5376474d74cd8df9289a 100644 --- a/lib/orient_db/methods/edge_methods.rb +++ b/lib/orient_db/methods/edge_methods.rb @@ -3,7 +3,7 @@ module OrientDb module EdgeMethods def get_in_edges_count(edge_class, id) - connection.query sprintf("SELECT COUNT(@rid) FROM %s WHERE in = %d", edge_class, id) + connection.query sprintf("SELECT COUNT(@rid) FROM %s WHERE in = %s", edge_class, id) end def create_edge(edge_class, from_id, to_id) @@ -12,4 +12,4 @@ module OrientDb end end -end \ No newline at end of file +end diff --git a/lib/tasks/mainPage.rake b/lib/tasks/mainPage.rake index d5155cf5a790873da32fa36fc3dcab65c2bb9594..94e506cc436e2d29689046672bff03eba3973215 100644 --- a/lib/tasks/mainPage.rake +++ b/lib/tasks/mainPage.rake @@ -3,12 +3,10 @@ namespace :mainPage do task :highlights => :environment do repository = Portalmec::Application.repository puts 'Generating the main page highlights' - objects = repository.for(:learning_object).find_all + objects = repository.for(:learning_object).all objects = objects.collect do |object| - likes = repository.for(:learning_object).get_likes(object['@rid']).size() - views = repository.for(:learning_object).get_views(object['@rid']).size() - downloads = repository.for(:learning_object).get_downloads(object['@rid']).size() - Ranking::Item.new(object['@rid'],views,downloads,likes) + downloads = 0 + Ranking::Item.new(object.id,object.views.count,downloads,object.likes.count) end rater = Ranking::Rater.new(Ranking::Strategies::BasicRater.new(1000,1,100)) objects = rater.sortByRate(objects).take(5) @@ -22,24 +20,19 @@ namespace :mainPage do puts 'Generate the main page subject highlights' subjects = repository.for(:subject).find_all - puts 'Found the subjects' subjects.each do |subject| - puts subject #pego os objetos sobre aquele subject objects = repository.for(:subject).get_objects(subject['@rid']) - puts objects - puts '-----------------------------------------------' #para todos os objetos eu transformo eles em items para rankear objects = objects.collect do |object| - likes = repository.for(:learning_object).get_likes(object['@rid']).size() - views = repository.for(:learning_object).get_views(object['@rid']).size() - downloads = repository.for(:learning_object).get_downloads(object['@rid']).size() - Ranking::Item.new(object['@rid'],views,downloads,likes) + downloads = 0 + object = repository.for(:learning_object).find(object['@rid']) + Ranking::Item.new(object.id,object.views.count,downloads,object.likes.count) end #rankeio eles - rater = Ranking::Rater.new(Ranking::Strategies::BasicRater.new(1000,1,100)) objects = rater.sortByRate(objects) #adciono no highlights do subject + puts subject['name'] repository.for(:subject).update(subject['@rid'],'set','highlights','[]') objects.each do |object| repository.for(:subject).update(subject['@rid'],'add','highlights',object.name)