backend.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class CoreWorkflow::Condition::Backend
  3. def initialize(condition_object:, result_object:, key:, condition:, value:)
  4. @key = key
  5. @condition_object = condition_object
  6. @result_object = result_object
  7. @condition = condition
  8. @value = value
  9. end
  10. attr_reader :value
  11. def field
  12. @key.sub(%r{.*\.}, '')
  13. end
  14. def object?(object)
  15. @condition_object.attributes.instance_of?(object)
  16. end
  17. def selected
  18. @condition_object.attribute_object.selected
  19. end
  20. def condition_value
  21. Array.wrap(@condition['value']).map do |v|
  22. if v.is_a?(Hash)
  23. v[:value].to_s
  24. else
  25. v.to_s
  26. end
  27. end
  28. end
  29. def time_modifier
  30. if ['before (relative)', 'within last (relative)', 'from (relative)'].include?(@condition['operator'])
  31. -1
  32. else
  33. 1
  34. end
  35. end
  36. def condition_times
  37. return condition_value.map { |v| TimeRangeHelper.relative(range: @condition['range'], value: time_modifier * v.to_i) } if @condition['range']
  38. condition_value.map { |v| Time.zone.parse(v) }
  39. end
  40. def value_times
  41. value.map { |v| Time.zone.parse(v) }
  42. end
  43. def match
  44. false
  45. end
  46. end