From 7d9f05ae9c478baa8a29cdb21880ae9e6251d219 Mon Sep 17 00:00:00 2001 From: Tallys Martins Date: Mon, 16 Nov 2015 21:05:23 -0200 Subject: [PATCH] Added software ratings statistics auto sum --- src/noosfero-spb/software_communities/lib/ext/create_organization_rating_comment.rb | 13 ++++++++----- src/noosfero-spb/software_communities/lib/ext/organization_ratings_plugin_profile_controller.rb | 12 ++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 src/noosfero-spb/software_communities/lib/ext/organization_ratings_plugin_profile_controller.rb diff --git a/src/noosfero-spb/software_communities/lib/ext/create_organization_rating_comment.rb b/src/noosfero-spb/software_communities/lib/ext/create_organization_rating_comment.rb index 71f6c44..b8bb580 100644 --- a/src/noosfero-spb/software_communities/lib/ext/create_organization_rating_comment.rb +++ b/src/noosfero-spb/software_communities/lib/ext/create_organization_rating_comment.rb @@ -4,11 +4,14 @@ CreateOrganizationRatingComment.class_eval do after_save :clear_rejected_rating_values def clear_rejected_rating_values - if(self.status == Task::Status::CANCELLED) - rating = OrganizationRating.find(self.organization_rating_id) - rating.saved_value = 0 - rating.people_benefited = 0 - rating.save + if(self.status == Task::Status::FINISHED) + rating = OrganizationRating.find_by_id(self.organization_rating_id) + software = SoftwareInfo.find_by_community_id(self.target_id) + if software.present? and rating.present? + software.saved_resources += rating.saved_value if rating.saved_value + software.benefited_people += rating.people_benefited if rating.people_benefited + software.save + end end end end diff --git a/src/noosfero-spb/software_communities/lib/ext/organization_ratings_plugin_profile_controller.rb b/src/noosfero-spb/software_communities/lib/ext/organization_ratings_plugin_profile_controller.rb new file mode 100644 index 0000000..270bc73 --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/ext/organization_ratings_plugin_profile_controller.rb @@ -0,0 +1,12 @@ +require_dependency "organization_ratings_plugin_profile_controller" + +OrganizationRatingsPluginProfileController.class_eval do + before_filter :xd + + def xd + if params[:organization_rating].present? && (params[:organization_rating][:people_benefited].present? || params[:organization_rating][:saved_value].present?) + params.merge!("comments" => {"body" => _("No comment") }) unless params[:comments][:body].present? + end + end + +end -- libgit2 0.21.2