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

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

Instance Method Summary collapse

Instance Method Details

#minimum_interval_between_remindersObject



38
39
40
# File '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 '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:

  • (Boolean)


22
23
24
# File '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:

  • (Boolean)


26
27
28
29
30
31
32
33
34
35
36
# File '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