Class: Course::Forum::Search

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model, ActiveModel::Validations
Defined in:
app/models/course/forum/search.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(search_params) ⇒ Search

Prepares parameters for the search.

Parameters:

  • search_params (Hash)

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

def initialize(search_params)
  @course = search_params[:course]
  @course_user_id = search_params[:course_user_id]
  @start_time = parse_time(:start_time, search_params[:start_time])
  @end_time = parse_time(:end_time, search_params[:end_time])

  @course_user = @course.course_users.find(course_user_id) if course_user_id
  @user = course_user.user if course_user
end

Instance Attribute Details

#course_userObject (readonly)

Returns the value of attribute course_user


6
7
8
# File 'app/models/course/forum/search.rb', line 6

def course_user
  @course_user
end

#course_user_idObject (readonly)

Returns the value of attribute course_user_id


6
7
8
# File 'app/models/course/forum/search.rb', line 6

def course_user_id
  @course_user_id
end

#end_timeObject (readonly)

Returns the value of attribute end_time


7
8
9
# File 'app/models/course/forum/search.rb', line 7

def end_time
  @end_time
end

#start_timeObject (readonly)

Returns the value of attribute start_time


7
8
9
# File 'app/models/course/forum/search.rb', line 7

def start_time
  @start_time
end

Instance Method Details

#postsArray<Course::Discussion::Post>

Returns a list of students' Course::Discussion::Posts created during the specified time period by the given CourseUser.

Returns:


30
31
32
33
34
35
36
37
38
39
# File 'app/models/course/forum/search.rb', line 30

def posts
  return [] unless valid?

  @posts ||=
    Course::Discussion::Post.forum_posts.from_course(@course).
    includes(topic: { actable: :forum }).
    calculated(:upvotes, :downvotes).
    where(created_at: start_time..end_time).
    where(creator_id: @user)
end