Class: Decidim::ActionDelegator::ParticipantsCsvImporter

Inherits:
CsvImporter
  • Object
show all
Defined in:
app/services/decidim/action_delegator/participants_csv_importer.rb

Instance Method Summary collapse

Methods inherited from CsvImporter

#generate_info_message, #handle_import_error, #handle_skipped_row, #headers, #import!, #initialize, #invalid_email?

Constructor Details

This class inherits a constructor from Decidim::ActionDelegator::CsvImporter

Instance Method Details

#process(row, params, details_csv, import_summary, iterator) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/decidim/action_delegator/participants_csv_importer.rb', line 6

def process(row, params, details_csv, import_summary, iterator)
  weight = ponderation_value(row["weight"].strip) if row["weight"].present?

  @form = form(Decidim::ActionDelegator::Admin::ParticipantForm).from_params(params, setting: @current_setting)

  if participant_exists?(@form)
    mismatch_fields = mismatched_fields(@form)
    message = generate_info_message(mismatch_fields)
    handle_skipped_row(row, details_csv, import_summary, iterator, message)
    return false
  end
  if phone_exists?(@form)
    reason = I18n.t("phone_exists", scope: "decidim.action_delegator.participants_csv_importer.import")
    handle_skipped_row(row, details_csv, import_summary, iterator, reason)
    return false
  end
  if weight.present? && find_ponderation(weight).nil?
    reason = I18n.t("ponderation_not_found", scope: "decidim.action_delegator.participants_csv_importer.import")
    handle_skipped_row(row, details_csv, import_summary, iterator, reason)
    return false
  end

  true
end