Class: Course::Forum

Inherits:
ApplicationRecord show all
Extended by:
FriendlyId
Defined in:
app/models/course/forum.rb

Defined Under Namespace

Modules: ControllerHelper, TopicControllerHidingConcern, TopicControllerLockingConcern, TopicControllerSubscriptionConcern Classes: ComponentController, Controller, ForumsController, PostNotifier, PostsController, Search, Subscription, Topic, TopicNotifier, TopicsController

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#topic_countObject (readonly)

The number of topics in this forum.


12
13
14
15
# File 'app/models/course/forum.rb', line 12

calculated :topic_count, (lambda do
  Course::Forum::Topic.where('course_forum_topics.forum_id = course_forums.id').
    select("count('*')")
end)

#topic_post_countObject (readonly)

The number of posts in this forum.


19
20
21
22
23
24
# File 'app/models/course/forum.rb', line 19

calculated :topic_post_count, (lambda do
  Course::Forum::Topic.
    joining { discussion_topic.outer.posts.outer }.
    where('course_forum_topics.forum_id = course_forums.id').
    select("count('*')")
end)

#topic_view_countObject (readonly)

The number of views in this forum.


28
29
30
31
32
# File 'app/models/course/forum.rb', line 28

calculated :topic_view_count, (lambda do
  Course::Forum::Topic.joins(:views).
    where('course_forum_topics.forum_id = course_forums.id').
    select("count('*')")
end)

Class Method Details

.use_relative_model_naming?Boolean

Returns:

  • (Boolean)

53
54
55
# File 'app/models/course/forum.rb', line 53

def self.use_relative_model_naming?
  true
end

.with_forum_statisticsObject

Augments all returned records with the number of topics, topic posts and topic views in that forum.


43
44
45
46
47
48
49
50
51
# File 'app/models/course/forum.rb', line 43

scope :with_forum_statistics,
(lambda do |user|
  all.calculated(
    :topic_count,
    :topic_view_count,
    :topic_post_count,
    topic_unread_count: user
  )
end)

Instance Method Details

#initialize_duplicate(duplicator, _other) ⇒ Object


70
71
72
# File 'app/models/course/forum.rb', line 70

def initialize_duplicate(duplicator, _other)
  self.course = duplicator.options[:destination_course]
end

#subscribed_by?(user) ⇒ Boolean

Return if a user has subscribed to this forum

Parameters:

  • user (User)

    The user to check

Returns:

  • (Boolean)

    True if the user has subscribed this forum


61
62
63
# File 'app/models/course/forum.rb', line 61

def subscribed_by?(user)
  !subscriptions.where(user: user).empty?
end

#to_partial_pathObject

Rewrite partial path which is used to find a suitable partial to represent the object.


66
67
68
# File 'app/models/course/forum.rb', line 66

def to_partial_path
  'forums/forum'
end