cirandas.net

ref: master

plugins/organization_ratings/lib/organization_ratings_plugin.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
class OrganizationRatingsPlugin < Noosfero::Plugin
  include Noosfero::Plugin::HotSpot

  def self.plugin_name
    "Organization Ratings"
  end

  def self.plugin_description
    _("A plugin that allows you to rate a organization and comment about it.")
  end

  module Hotspots
    def organization_ratings_plugin_comments_extra_fields
      nil
    end

    def organization_ratings_title
      nil
    end

    def organization_ratings_plugin_star_message
      nil
    end

    def organization_ratings_plugin_task_extra_fields user_rating
      nil
    end

    def organization_ratings_plugin_container_extra_fields user_rating
      nil
    end

    def organization_ratings_plugin_rating_created rating, params
      nil
    end
  end

  # Plugin Hotspot to display the average rating
  def display_organization_average_rating organization
    unless organization.nil?
      average_rating = OrganizationRating.average_rating organization.id

      Proc::new {
        render :file => 'blocks/display_organization_average_rating',
               :locals => {
                 :profile_identifier => organization.identifier,
                 :average_rating => average_rating
               }
      }
    end
  end

  def more_comments_count owner
    if owner.kind_of?(Environment) then
      owner.profiles.sum(:comments_count)
    elsif owner.kind_of?(Profile) then
      owner.comments_count
    else
      0
    end
  end

  def self.extra_blocks
    {
      OrganizationRatingsBlock => {:type => [Enterprise, Community], :position => ['1']},
      AverageRatingBlock => {:type => [Enterprise, Community]}
    }
  end

  def stylesheet?
    true
  end

  def js_files
    %w(
      rate.js
      organization_rating_management.js
    )
  end

end