backend.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 condition_value
  18. Array.wrap(@condition['value']).map do |v|
  19. if v.is_a?(Hash)
  20. v[:value].to_s
  21. else
  22. v.to_s
  23. end
  24. end
  25. end
  26. def time_modifier
  27. if ['before (relative)', 'within last (relative)', 'from (relative)'].include?(@condition['operator'])
  28. -1
  29. else
  30. 1
  31. end
  32. end
  33. def condition_times
  34. return condition_value.map { |v| TimeRangeHelper.relative(range: @condition['range'], value: time_modifier * v.to_i) } if @condition['range']
  35. condition_value.map { |v| Time.zone.parse(v) }
  36. end
  37. def value_times
  38. value.map { |v| Time.zone.parse(v) }
  39. end
  40. def match
  41. false
  42. end
  43. end