Class: Admin::ForumController

Inherits:
AdminController
  • Object
show all
Defined in:
app/controllers/admin/forum_controller.rb

Instance Method Summary collapse

Instance Method Details

#create_categoryObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/admin/forum_controller.rb', line 62

def create_category
  add_sid(:topic_category)
  @topic_category = TopicCategory.new(params[:topic_category])

  @topic_category.read_access_level = 0
  @topic_category.write_access_level = 1
  @topic_category.is_open = true
  if @topic_category.save
    flash[:notice] = "Category created"
    redirect_to "/admin/forums"
  else
    @topic ||= Topic.new
    render "index"
  end 
end

#create_topicObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/admin/forum_controller.rb', line 42

def create_topic
  add_sid(:topic)
  @topic = Topic.new(params[:topic])
  @topic.is_open = true
  @topic.system_id = _sid
  @topic.is_visible = true
  @topic.read_access_level = 0
  @topic.write_access_level = 1

  @selected_cat = @topic.topic_category_id
 @topic_category ||= TopicCategory.new 

  if @topic.save
    flash[:notice] = "Topic created"
    redirect_to "/admin/forums?selected_cat=#{@selected_cat}"
  else
    render "index"
  end
end

#delete_categoryObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/admin/forum_controller.rb', line 13

def delete_category
  @category = TopicCategory.find_sys_id(_sid, params[:id])

  if @category.topics.count > 0 
    flash[:notice] = "This category can't be deleted because it contains topic(s).  Delete those first."
  else
    TopicCategory.delete_all("id = #{params[:id]} and system_id = #{_sid}")
    flash[:notice] = "Category deleted"
  end

  redirect_to "/admin/forums"
end

#edit_categoryObject



26
27
28
29
# File 'app/controllers/admin/forum_controller.rb', line 26

def edit_category
  @category = TopicCategory.find_sys_id(_sid, params[:id])
  render "admin/forum/category"
end

#indexObject



7
8
9
10
11
# File 'app/controllers/admin/forum_controller.rb', line 7

def index
 @topic_category ||= TopicCategory.new 
 @topic ||= Topic.new
 @selected_cat = params[:selected_cat]
end

#update_categoryObject



31
32
33
34
35
36
37
38
39
# File 'app/controllers/admin/forum_controller.rb', line 31

def update_category
  @category = TopicCategory.find_sys_id(_sid, params[:id])
  if @category.update_attributes(params[:topic_category])
    flash[:notice] = "Category Updated"
    redirect_to "/admin/forums"
  else
    render "admin/forum/category"
  end
end