Sha256: 9a616ac00d06e7608461d57120f42bbe05b958ff0ec8be733718962fa6764adc

Contents?: true

Size: 1.67 KB

Versions: 22

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true
module Hyrax
  module Statistics
    class QueryService
      # query to find works created during the time range
      # @param [DateTime] start_datetime starting date time for range query
      # @param [DateTime] end_datetime ending date time for range query
      def find_by_date_created(start_datetime, end_datetime = nil)
        return [] if start_datetime.blank? # no date just return nothing
        relation.where(build_date_query(start_datetime, end_datetime))
      end

      def find_registered_in_date_range(start_datetime, end_datetime = nil)
        find_by_date_created(start_datetime, end_datetime).merge(where_registered)
      end

      def find_public_in_date_range(start_datetime, end_datetime = nil)
        find_by_date_created(start_datetime, end_datetime).merge(where_public)
      end

      def where_public
        where_access_is 'public'
      end

      def where_registered
        where_access_is 'registered'
      end

      def build_date_query(start_datetime, end_datetime)
        start_date_str =  start_datetime.utc.strftime(date_format)
        end_date_str = if end_datetime.blank?
                         "*"
                       else
                         end_datetime.utc.strftime(date_format)
                       end
        "system_create_dtsi:[#{start_date_str} TO #{end_date_str}]"
      end

      delegate :count, to: :relation

      def relation
        Hyrax::WorkRelation.new
      end

      private

      def where_access_is(access_level)
        relation.where Hydra.config.permissions.read.group => access_level
      end

      def date_format
        "%Y-%m-%dT%H:%M:%SZ"
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
hyrax-5.0.0.rc2 app/services/hyrax/statistics/query_service.rb
hyrax-5.0.0.rc1 app/services/hyrax/statistics/query_service.rb
hyrax-3.6.0 app/services/hyrax/statistics/query_service.rb
hyrax-4.0.0 app/services/hyrax/statistics/query_service.rb
hyrax-4.0.0.rc3 app/services/hyrax/statistics/query_service.rb
hyrax-4.0.0.rc2 app/services/hyrax/statistics/query_service.rb
hyrax-4.0.0.rc1 app/services/hyrax/statistics/query_service.rb
hyrax-3.5.0 app/services/hyrax/statistics/query_service.rb
hyrax-4.0.0.beta2 app/services/hyrax/statistics/query_service.rb
hyrax-3.4.2 app/services/hyrax/statistics/query_service.rb
hyrax-4.0.0.beta1 app/services/hyrax/statistics/query_service.rb
hyrax-3.4.1 app/services/hyrax/statistics/query_service.rb
hyrax-3.4.0 app/services/hyrax/statistics/query_service.rb
hyrax-3.3.0 app/services/hyrax/statistics/query_service.rb
hyrax-3.2.0 app/services/hyrax/statistics/query_service.rb
hyrax-3.1.0 app/services/hyrax/statistics/query_service.rb
hyrax-3.0.2 app/services/hyrax/statistics/query_service.rb
hyrax-3.0.1 app/services/hyrax/statistics/query_service.rb
hyrax-3.0.0 app/services/hyrax/statistics/query_service.rb
hyrax-3.0.0.pre.rc4 app/services/hyrax/statistics/query_service.rb