2014-02-03 19:23:00 +00:00
|
|
|
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
2013-08-15 22:21:47 +00:00
|
|
|
|
|
|
|
class Ticket::Number < ApplicationLib
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
generate new ticket number
|
|
|
|
|
|
|
|
result = Ticket::Number.generate
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
result = "1234556" # new ticket number
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.generate
|
2014-02-03 19:23:00 +00:00
|
|
|
|
2013-08-15 22:21:47 +00:00
|
|
|
# generate number
|
|
|
|
(1..50_000).each { |i|
|
|
|
|
number = adapter.generate
|
|
|
|
ticket = Ticket.where( :number => number ).first
|
|
|
|
return number if !ticket
|
|
|
|
}
|
|
|
|
raise "Can't generate new ticket number!"
|
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
check if string contrains a valid ticket number
|
|
|
|
|
|
|
|
result = Ticket::Number.check('some string [Ticket#123456]')
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
result = ticket # Ticket model of ticket with matching ticket number
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.check(string)
|
|
|
|
adapter.check(string)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.adapter
|
|
|
|
|
|
|
|
# load backend based on config
|
|
|
|
adapter_name = Setting.get('ticket_number')
|
|
|
|
if !adapter_name
|
|
|
|
raise "Missing ticket_number setting option"
|
|
|
|
end
|
|
|
|
adapter = self.load_adapter(adapter_name)
|
|
|
|
if !adapter
|
|
|
|
raise "Can't load ticket_number adapter '#{adapter_name}'"
|
|
|
|
end
|
|
|
|
adapter
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|