Sha256: afe726e866760fc3f17c135969303e48b4730d801e913b9fecb589dff4701cf1

Contents?: true

Size: 1.1 KB

Versions: 12

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # Counts active users making a distinction between whether they are admins or participants
    class ActiveUsersCounter < Decidim::Query
      # Initializes the class.
      #
      # @param organization [Organization] Current organization
      # @param date [Date] Period time to make users count check
      # @param admin [boolean] Possible values : t for Admin or f for participant
      def initialize(organization:, date:, admin: false)
        @organization = organization
        @date = date
        @admin = admin
      end

      # Count the user's number who have logged in since given date
      #
      # Returns an ActiveRecord::Relation
      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

      private

      attr_reader :organization, :date, :admin
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-admin-0.27.9 app/queries/decidim/admin/active_users_counter.rb
decidim-admin-0.27.8 app/queries/decidim/admin/active_users_counter.rb
decidim-admin-0.27.7 app/queries/decidim/admin/active_users_counter.rb
decidim-admin-0.27.6 app/queries/decidim/admin/active_users_counter.rb
decidim-admin-0.27.5 app/queries/decidim/admin/active_users_counter.rb
decidim-admin-0.27.4 app/queries/decidim/admin/active_users_counter.rb
decidim-admin-0.27.3 app/queries/decidim/admin/active_users_counter.rb
decidim-admin-0.27.2 app/queries/decidim/admin/active_users_counter.rb
decidim-admin-0.27.1 app/queries/decidim/admin/active_users_counter.rb
decidim-admin-0.27.0 app/queries/decidim/admin/active_users_counter.rb
decidim-admin-0.27.0.rc2 app/queries/decidim/admin/active_users_counter.rb
decidim-admin-0.27.0.rc1 app/queries/decidim/admin/active_users_counter.rb