trabajo-afectivo/app/models/ticket/subject.rb

84 lines
2.4 KiB
Ruby
Raw Normal View History

2016-10-19 03:11:36 +00:00
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
module Ticket::Subject
=begin
build new subject with ticket number in there
ticket = Ticket.find(123)
result = ticket.subject_build('some subject', is_reply_true_false)
returns
result = "[Ticket#1234567] some subject"
=end
def subject_build(subject, is_reply = false)
# clena subject
subject = subject_clean(subject)
ticket_hook = Setting.get('ticket_hook')
ticket_hook_divider = Setting.get('ticket_hook_divider')
ticket_subject_re = Setting.get('ticket_subject_re')
if is_reply && !ticket_subject_re.empty?
subject = "#{ticket_subject_re}: #{subject}"
end
# none position
if Setting.get('ticket_hook_position') == 'none'
return subject
end
# right position
if Setting.get('ticket_hook_position') == 'right'
2016-05-03 00:36:44 +00:00
return subject + " [#{ticket_hook}#{ticket_hook_divider}#{number}]"
2015-04-27 21:27:51 +00:00
end
# left position
"[#{ticket_hook}#{ticket_hook_divider}#{number}] " + subject
end
=begin
clean subject remove ticket number and other not needed chars
ticket = Ticket.find(123)
result = ticket.subject_clean('[Ticket#1234567] some subject')
returns
result = "some subject"
=end
def subject_clean(subject)
ticket_hook = Setting.get('ticket_hook')
ticket_hook_divider = Setting.get('ticket_hook_divider')
ticket_subject_size = Setting.get('ticket_subject_size')
# remove all possible ticket hook formats with []
subject = subject.gsub(/\[#{ticket_hook}: #{number}\](\s+?|)/, '')
subject = subject.gsub(/\[#{ticket_hook}:#{number}\](\s+?|)/, '')
subject = subject.gsub(/\[#{ticket_hook}#{ticket_hook_divider}#{number}\](\s+?|)/, '')
# remove all possible ticket hook formats without []
subject = subject.gsub(/#{ticket_hook}: #{number}(\s+?|)/, '')
subject = subject.gsub(/#{ticket_hook}:#{number}(\s+?|)/, '')
subject = subject.gsub(/#{ticket_hook}#{ticket_hook_divider}#{number}(\s+?|)/, '')
# remove leading "..:\s" and "..[\d+]:\s" e. g. "Re: " or "Re[5]: "
subject = subject.gsub(/^(..(\[\d+\])?:\s)+/, '')
# resize subject based on config
if subject.length > ticket_subject_size.to_i
subject = subject[ 0, ticket_subject_size.to_i ] + '[...]'
2015-04-27 21:27:51 +00:00
end
2016-07-16 21:43:08 +00:00
subject.gsub!(/^[[:space:]]+/, '')
subject.gsub!(/[[:space:]]+$/, '')
subject
end
2014-02-03 19:23:00 +00:00
end