Sha256: 117a7ff84ab44ae000990c67d3636ba6f2c96aa9ed30c8211a77686a341bf010

Contents?: true

Size: 786 Bytes

Versions: 1

Compression:

Stored size: 786 Bytes

Contents

# frozen_string_literal: true
module Decidim
  # This query counts registered users from a collection of organizations
  # in an optional interval of time.
  class StatsUsersCount < Rectify::Query
    def self.for(organization, start_at = nil, end_at = nil)
      new(organization, start_at, end_at).query
    end

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
decidim-core-0.1.0 app/queries/decidim/stats_users_count.rb