Class: Workarea::Admin::BlogCommentsViewModel

Inherits:
ApplicationViewModel
  • Object
show all
Defined in:
app/view_models/workarea/admin/blog_comments_view_model.rb

Instance Method Summary collapse

Instance Method Details

#blogObject



39
40
41
42
# File 'app/view_models/workarea/admin/blog_comments_view_model.rb', line 39

def blog
  return nil unless blog_entry.present?
  blog_entry.blog
end

#blog_entryObject



33
34
35
36
37
# File 'app/view_models/workarea/admin/blog_comments_view_model.rb', line 33

def blog_entry
  return nil unless options[:content_blog_entry_id].present?
  @blog_entry ||= Content::BlogEntry.find_by(slug:
    options[:content_blog_entry_id])
end

#commentsObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/view_models/workarea/admin/blog_comments_view_model.rb', line 9

def comments
  return @comments if defined?(@comments)

  comments = if options[:content_blog_entry_id].present?
    blog_entry
      .comments
      .page(options[:page])
      .per(per_page)
      .order_by(options[:built_sort])
  else
    Content::BlogComment
      .page(options[:page])
      .per(per_page)
      .order_by(options[:built_sort])
  end

  @comments = PagedArray.from(
    comments,
    comments.current_page,
    per_page,
    comments.total_count
  )
end