Class: Course::Forum::ForumsController

Inherits:
Controller show all
Defined in:
app/controllers/course/forum/forums_controller.rb

Instance Method Summary collapse

Methods included from ApplicationSignInCallbacksConcern

#sign_in

Methods included from ApplicationPaginationConcern

#page_param

Methods included from ApplicationAnnouncementsConcern

#global_announcements, #unread_global_announcements

Methods included from ApplicationInstanceUserConcern

#current_instance_user

Methods included from ApplicationUserTimeZoneConcern

#set_time_zone

Methods included from ApplicationUserConcern

#handle_access_denied, #publicly_accessible?

Methods included from ApplicationComponentsConcern

#handle_component_not_found

Instance Method Details

#createObject


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

def create
  if @forum.save
    redirect_to course_forums_path(current_course), success: t('.success', name: @forum.name)
  else
    render 'new'
  end
end

#destroyObject


39
40
41
42
43
44
45
46
# File 'app/controllers/course/forum/forums_controller.rb', line 39

def destroy
  if @forum.destroy
    redirect_to course_forums_path(current_course), success: t('.success', name: @forum.name)
  else
    redirect_to course_forum_path(current_course, @forum),
                danger: t('.failure', error: @forum.errors.full_messages.to_sentence)
  end
end

#editObject


27
28
# File 'app/controllers/course/forum/forums_controller.rb', line 27

def edit
end

#indexObject


6
7
8
9
# File 'app/controllers/course/forum/forums_controller.rb', line 6

def index
  @forums = @forums.order(:created_at).with_forum_statistics(current_user)
  @unresolved_forums_ids = Course::Forum::Topic.filter_unresolved_forum(@forums.map(&:id))
end

#mark_all_as_readObject


81
82
83
84
85
86
# File 'app/controllers/course/forum/forums_controller.rb', line 81

def mark_all_as_read
  topics = Course::Forum::Topic.from_course(current_course).
           accessible_by(current_ability).unread_by(current_user).to_a
  Course::Forum::Topic.mark_as_read!(topics, for: current_user)
  redirect_to course_forums_path(current_course), success: t('.success')
end

#mark_as_readObject


88
89
90
91
92
93
# File 'app/controllers/course/forum/forums_controller.rb', line 88

def mark_as_read
  topics = @forum.topics.accessible_by(current_ability).to_a
  Course::Forum::Topic.mark_as_read!(topics, for: current_user)

  redirect_to course_forum_path(current_course, @forum), success: t('.success')
end

#newObject


16
17
# File 'app/controllers/course/forum/forums_controller.rb', line 16

def new
end

#next_unreadObject


70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/course/forum/forums_controller.rb', line 70

def next_unread
  topic = Course::Forum::Topic.from_course(current_course).
          accessible_by(current_ability).unread_by(current_user).first

  if topic
    redirect_to course_forum_topic_path(current_course, topic.forum, topic)
  else
    redirect_to course_forums_path(current_course), notice: t('.notice')
  end
end

#searchObject


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

def search
  @search = Course::Forum::Search.new(search_params)
end

#showObject


11
12
13
14
# File 'app/controllers/course/forum/forums_controller.rb', line 11

def show
  @topics = @forum.topics.accessible_by(current_ability).order_by_latest_post.with_topic_statistics.
            page(page_param).with_read_marks_for(current_user).includes(:creator).with_latest_post
end

#subscribeObject


48
49
50
51
52
53
54
55
# File 'app/controllers/course/forum/forums_controller.rb', line 48

def subscribe
  if @forum.subscriptions.create(user: current_user)
    flash.now[:success] = t('.success', name: @forum.name)
  else
    flash.now[:danger] = t('.failure', error: @forum.errors.full_messages.to_sentence)
  end
  render 'update_subscribe_button'
end

#unsubscribeObject


57
58
59
60
61
62
63
64
# File 'app/controllers/course/forum/forums_controller.rb', line 57

def unsubscribe
  if @forum.subscriptions.where(user: current_user).delete_all > 0
    flash.now[:success] = t('.success', name: @forum.name)
  else
    flash.now[:danger] = t('.failure')
  end
  render 'update_subscribe_button'
end

#updateObject


30
31
32
33
34
35
36
37
# File 'app/controllers/course/forum/forums_controller.rb', line 30

def update
  if @forum.update_attributes(forum_params)
    redirect_to course_forum_path(current_course, @forum),
                success: t('.success', name: @forum.name)
  else
    render 'edit'
  end
end