Class: Decidim::Admin::ActiveUsersCounter
- Inherits:
-
Query
- Object
- Query
- Decidim::Admin::ActiveUsersCounter
- 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
-
#initialize(organization:, date:, admin: false) ⇒ ActiveUsersCounter
constructor
Initializes the class.
-
#query ⇒ Object
Count the user’s number who have logged in since given date.
Constructor Details
#initialize(organization:, date:, admin: false) ⇒ ActiveUsersCounter
Initializes the class.
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
#query ⇒ Object
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:) end |