houdini/lib/slug_p2p_campaign_naming_algorithm.rb
2018-05-24 15:45:05 -05:00

27 lines
No EOL
656 B
Ruby

# 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)
@nonprofit_id = nonprofit_id
end
def copy_addition
""
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)
end_name = "\\_\\d{3}"
Campaign.where('slug SIMILAR TO ? AND nonprofit_id = ? AND (deleted IS NULL OR deleted = false)', base_name + end_name, nonprofit_id).select('slug')
end
end