Class: StatisticsPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/statistics_presenter.rb

Instance Method Summary collapse

Instance Method Details

#as_json(options = {}) ⇒ Object


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
# File 'app/presenters/statistics_presenter.rb', line 3

def as_json(options={})
  result = {
    'name' => AppConfig.settings.pod_name,
    'version' => AppConfig.version_string,
    'registrations_open' => AppConfig.settings.enable_registrations
  }
  if AppConfig.privacy.statistics.user_counts?
    result['total_users'] = User.count
    result['active_users_halfyear'] = User.halfyear_actives.count
    result['active_users_monthly'] = User.monthly_actives.count
  end
  if AppConfig.privacy.statistics.post_counts?
    result['local_posts'] = self.local_posts
  end
  if AppConfig.privacy.statistics.comment_counts?
    result['local_comments'] = self.local_comments
  end

  AppConfig.services.each do |service, options|
    result[service] = options ? !!options["enable"] : false
  
  end

  result
end

#local_commentsObject


33
34
35
# File 'app/presenters/statistics_presenter.rb', line 33

def local_comments
  Comment.joins(:author).where("owner_id IS NOT null").count
end

#local_postsObject


29
30
31
# File 'app/presenters/statistics_presenter.rb', line 29

def local_posts
  Post.where(:type => "StatusMessage").joins(:author).where("owner_id IS NOT null").count
end