2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-24 20:45:05 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
|
|
|
class SlugP2pCampaignNamingAlgorithm < CopyNamingAlgorithm
|
|
|
|
attr_accessor :nonprofit_id
|
|
|
|
# @param [Integer] nonprofit_id
|
|
|
|
def initialize(nonprofit_id)
|
2019-07-30 21:29:24 +00:00
|
|
|
@nonprofit_id = nonprofit_id
|
2018-05-24 20:45:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def copy_addition
|
2019-07-30 21:29:24 +00:00
|
|
|
''
|
2018-05-24 20:45:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def max_copies
|
|
|
|
999
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_name_for_entity(name_entity)
|
|
|
|
name_entity.slug
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_already_used_name_entities(base_name)
|
2019-07-30 21:29:24 +00:00
|
|
|
end_name = '\\_\\d{3}'
|
2019-02-05 22:57:45 +00:00
|
|
|
Campaign.where('slug SIMILAR TO ? AND nonprofit_id = ?', base_name + end_name, nonprofit_id).select('slug')
|
2018-05-24 20:45:05 +00:00
|
|
|
end
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|