feeds_controller.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class KnowledgeBase::Public::FeedsController < KnowledgeBase::Public::BaseController
  3. before_action :ensure_response_format
  4. helper_method :build_original_url, :publishing_date, :updating_date
  5. def root
  6. @answers = @knowledge_base
  7. .answers
  8. .localed(system_locale_via_uri)
  9. .sorted_by_published
  10. .limit(10)
  11. @root_url = custom_path_if_needed(help_root_url, @knowledge_base, full: true)
  12. render template: 'knowledge_base/feeds/feed'
  13. end
  14. def category
  15. @category = find_category(params[:category])
  16. @answers = @category
  17. .self_with_children_answers
  18. .localed(system_locale_via_uri)
  19. .sorted_by_published
  20. .limit(10)
  21. @root_url = custom_path_if_needed(help_category_url, @knowledge_base, full: true)
  22. render template: 'knowledge_base/feeds/feed'
  23. end
  24. private
  25. def ensure_response_format
  26. request.format = :atom
  27. end
  28. def build_original_url(answer)
  29. translation = answer.translations.first
  30. url = help_answer_url(answer.category, translation, locale: translation.kb_locale.system_locale.locale)
  31. custom_path_if_needed url, @knowledge_base, full: true
  32. end
  33. def publishing_date(answer)
  34. answer.published_at
  35. end
  36. def updating_date(answer)
  37. [answer.published_at, answer.updated_at].compact.max
  38. end
  39. end