Class: Decidim::Admin::ActiveUsersCounter

Inherits:
Query
  • Object
show all
Defined in:
app/queries/decidim/admin/active_users_counter.rb

Overview

Counts active users making a distinction between whether they are admins or participants

Instance Method Summary collapse

Constructor Details

#initialize(organization:, date:, admin: false) ⇒ ActiveUsersCounter

Initializes the class.

Parameters:

  • organization (Organization)

    Current organization

  • date (Date)

    Period time to make users count check

  • admin (boolean) (defaults to: false)

    Possible values : t for Admin or f for participant



12
13
14
15
16
# File 'app/queries/decidim/admin/active_users_counter.rb', line 12

def initialize(organization:, date:, admin: false)
  @organization = organization
  @date = date
  @admin = admin
end

Instance Method Details

#queryObject

Count the user’s number who have logged in since given date

Returns an ActiveRecord::Relation



21
22
23
24
25
26
27
# File 'app/queries/decidim/admin/active_users_counter.rb', line 21

def query
  return Decidim::User.none unless organization && date

  query = Decidim::User.left_outer_joins(:organization).where(decidim_organizations: { id: organization.id })
  query = query.where("#{Decidim::User.table_name}.current_sign_in_at >= ?", date)
  query.where(admin: admin)
end