Class: Decidim::Budgets::Admin::OrderReminderForm

Inherits:
Form show all
Defined in:
decidim-budgets/app/forms/decidim/budgets/admin/order_reminder_form.rb

Constant Summary

Constants included from AttributeObject::TypeMap

AttributeObject::TypeMap::Boolean, AttributeObject::TypeMap::Decimal

Instance Attribute Summary

Attributes inherited from AttributeObject::Form

#context

Instance Method Summary collapse

Methods inherited from AttributeObject::Form

ensure_hash, from_model, from_params, hash_from, infer_model_name, #map_model, mimic, mimicked_model_name, model_name, #persisted?, #to_key, #to_model, #to_param, #valid?, #with_context

Methods included from AttributeObject::Model

#[], #[]=, #attributes, #attributes_with_values, #initialize, #to_h

Instance Method Details

#minimum_interval_between_remindersObject


38
39
40
# File 'decidim-budgets/app/forms/decidim/budgets/admin/order_reminder_form.rb', line 38

def minimum_interval_between_reminders
  24.hours
end

#reminder_amountObject


7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'decidim-budgets/app/forms/decidim/budgets/admin/order_reminder_form.rb', line 7

def reminder_amount
  @reminder_amount ||= if !voting_enabled? || voting_ends_soon?
                         0
                       else
                         user_ids = []
                         unfinished_orders.each do |order|
                           reminder = Decidim::Reminder.find_by(component: current_component, user: order.user)
                           if !reminder || (reminder.deliveries.present? && reminder.deliveries.last.created_at < minimum_interval_between_reminders.ago)
                             user_ids << order.user.id
                           end
                         end
                         user_ids.uniq.count
                       end
end

#voting_enabled?Boolean

Returns:


22
23
24
# File 'decidim-budgets/app/forms/decidim/budgets/admin/order_reminder_form.rb', line 22

def voting_enabled?
  current_component.current_settings.votes == "enabled"
end

#voting_ends_soon?Boolean

Returns:


26
27
28
29
30
31
32
33
34
35
36
# File 'decidim-budgets/app/forms/decidim/budgets/admin/order_reminder_form.rb', line 26

def voting_ends_soon?
  return false unless participatory_space.respond_to? :active_step
  return false if participatory_space.active_step.blank?

  time_zone = current_organization.time_zone
  return false if time_zone.blank?

  end_time = current_component.participatory_space.active_step[:end_date].in_time_zone(time_zone).end_of_day

  6.hours.from_now >= end_time
end