list.rb 897 B

1234567891011121314151617181920212223242526
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Service::User::Overview::List < Service::Base
  3. attr_reader :user
  4. def initialize(user)
  5. super()
  6. @user = user
  7. end
  8. def execute
  9. scope = Ticket::OverviewsPolicy::Scope
  10. .new(user, Overview)
  11. .resolve
  12. .joins("LEFT JOIN user_overview_sortings ON user_overview_sortings.overview_id = overviews.id AND user_overview_sortings.user_id = #{user.id}")
  13. .select('overviews.*, user_overview_sortings.prio as user_prio, user_overview_sortings.id as user_prio_id')
  14. case ActiveRecord::Base.connection_db_config.configuration_hash[:adapter]
  15. when 'postgresql'
  16. scope.reorder('user_prio NULLS LAST, user_prio_id NULLS LAST, prio, id')
  17. when 'mysql2'
  18. scope.reorder(Arel.sql('ISNULL(user_prio), user_prio, ISNULL(user_prio_id), user_prio_id, prio, id'))
  19. end
  20. end
  21. end