Class: Decidim::StatsUsersCount

Inherits:
Query
  • Object
show all
Defined in:
decidim-core/app/queries/decidim/stats_users_count.rb

Overview

This query counts registered users from a collection of organizations in an optional interval of time.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Query

#cached_query, #each, #eager?, #exists?, merge, #none?, #relation?, #|

Constructor Details

#initialize(organization, start_at = nil, end_at = nil) ⇒ StatsUsersCount

Returns a new instance of StatsUsersCount.



11
12
13
14
15
# File 'decidim-core/app/queries/decidim/stats_users_count.rb', line 11

def initialize(organization, start_at = nil, end_at = nil)
  @organization = organization
  @start_at = start_at
  @end_at = end_at
end

Class Method Details

.for(organization, start_at = nil, end_at = nil) ⇒ Object



7
8
9
# File 'decidim-core/app/queries/decidim/stats_users_count.rb', line 7

def self.for(organization, start_at = nil, end_at = nil)
  new(organization, start_at, end_at).query
end

Instance Method Details

#queryObject



17
18
19
20
21
22
# File 'decidim-core/app/queries/decidim/stats_users_count.rb', line 17

def query
  users = Decidim::User.where(organization: @organization).not_deleted.not_blocked.confirmed
  users = users.where("created_at >= ?", @start_at) if @start_at.present?
  users = users.where("created_at <= ?", @end_at) if @end_at.present?
  users.count
end