Skip to content

Commit 3f36237

Browse files
committed
Adding the ability to edit categories. Fixing board admin to drill down child boards forever
1 parent 2b9c040 commit 3f36237

File tree

8 files changed

+136
-37
lines changed

8 files changed

+136
-37
lines changed

src/controllers/Forum/Core_CategoryController.php

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public function getView($categorySlug)
1515
$this->setViewData('category', $category);
1616
}
1717

18-
public function getAdd()
19-
{
18+
public function getAdd()
19+
{
2020
// Make sure they can access this whole area
2121
$this->checkPermission('FORUM_ADMIN');
2222

@@ -67,5 +67,62 @@ public function postAdd()
6767

6868
return $this->redirect(null, $category->name.' has been submitted.');
6969
}
70-
}
70+
}
71+
72+
public function getEdit($categoryId)
73+
{
74+
// Make sure they can access this whole area
75+
$this->checkPermission('FORUM_ADMIN');
76+
77+
$category = Forum_Category::find($categoryId);
78+
79+
// Get the information
80+
$categories = $this->arrayToSelect(Forum_Category::orderBy('position', 'asc')->get(), 'position', 'name', 'Place After...');
81+
$types = $this->arrayToSelect(Forum_Category_Type::orderByNameAsc()->get(), 'id', 'name', 'Select Category Type');
82+
83+
// Set the template
84+
$this->setViewData('category', $category);
85+
$this->setViewData('categories', $categories);
86+
$this->setViewData('types', $types);
87+
}
88+
89+
public function postEdit($categoryId)
90+
{
91+
// Handle any form data
92+
$input = Input::all();
93+
94+
if ($input != null) {
95+
// Get the new position
96+
if (isset($input['position']) && $input['position'] != 0) {
97+
$position = $input['position'] + 1;
98+
// Set all others properly
99+
$moveCategories = Forum_Category::where('position', '>=', $position)->get();
100+
if ($moveCategories != null) {
101+
foreach ($moveCategories as $category) {
102+
$category->moveDown();
103+
}
104+
}
105+
} elseif ($input['position'] == 0) {
106+
$firstCategory = Forum_Category::orderBy('position', 'desc')->first();
107+
if ($firstCategory != null) {
108+
$position = $firstCategory->position + 1;
109+
} else {
110+
$position = 1;
111+
}
112+
} else {
113+
$position = 1;
114+
}
115+
116+
$category = Forum_Category::find($categoryId);
117+
$category->name = $input['name'];
118+
$category->forum_category_type_id = (isset($input['forum_category_type_id']) && $input['forum_category_type_id'] != 0 ? $input['forum_category_type_id'] : null);
119+
$category->keyName = Str::slug($input['name']);
120+
$category->description = $input['description'];
121+
$category->position = $position;
122+
123+
$this->checkErrorsSave($category);
124+
125+
return $this->redirect(null, $category->name.' has been submitted.');
126+
}
127+
}
71128
}

src/views/forum/admin/boards.blade.php

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -38,40 +38,15 @@
3838
</tbody>
3939
</table>
4040
</div>
41-
@if (count($boardsWithChildren) > 0)
42-
@foreach ($boardsWithChildren as $board)
43-
<div class="panel panel-default" style="margin-left: 20px;">
44-
<div class="panel-heading">{{ $board->name }} child boards</div>
45-
<table class="table table-inner table-condensed table-striped table-hover" id="board_{{ $board->id }}">
46-
<thead>
47-
<tr>
48-
<th style="width: 2%;">&nbsp;</th>
49-
<th style="width: 49%;">Name</th>
50-
<th style="width: 49%;">Actions</th>
51-
</tr>
52-
</thead>
53-
<tbody>
54-
@foreach ($board->children as $child)
55-
<tr id="{{ $child->id }}">
56-
<td style="cursor: move;"><i class="fa fa-arrows-v" title="Change order"></i></td>
57-
<td>
58-
<a href="javascript: void(0);" class="editable" id="name" data-type="text" data-pk="{{ $child->id }}">
59-
{{ $child->name }}
60-
</a>
61-
</td>
62-
<td>
63-
<div class="btn-group">
64-
{{ HTML::link('forum/board/edit/'. $child->id, 'Edit', array('class' => 'btn btn-xs btn-primary')) }}
65-
{{ HTML::link('forum/admin/delete-board/'. $child->id, 'Delete', array('class' => 'confirm-remove btn btn-xs btn-danger')) }}
66-
</div>
67-
</td>
68-
</tr>
69-
@endforeach
70-
</tbody>
71-
</table>
72-
</div>
41+
@while (count($boardsWithChildren) > 0)
42+
<?php
43+
$currentBoardsWithChildren = $boardsWithChildren;
44+
$boardsWithChildren = array();
45+
?>
46+
@foreach ($currentBoardsWithChildren as $board)
47+
@include('forum.admin.components.boards', array('width' => 20))
7348
@endforeach
74-
@endif
49+
@endwhile
7550
@endforeach
7651
</div>
7752
</div>

src/views/forum/admin/categories.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
</td>
2222
<td>
2323
<div class="btn-group">
24+
{{ HTML::link('forum/category/edit/'. $category->id, 'Edit', array('class' => 'btn btn-xs btn-primary')) }}
2425
{{ HTML::link('forum/admin/delete-category/'. $category->id, 'Delete', array('class' => 'confirm-remove btn btn-xs btn-danger')) }}
2526
</div>
2627
</td>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php $newChildren = array(); ?>
2+
<div class="panel panel-default" style="margin-left: {{ $width }}px;">
3+
<div class="panel-heading">{{ $board->name }} child boards</div>
4+
<table class="table table-inner table-condensed table-striped table-hover" id="board_{{ $board->id }}">
5+
<thead>
6+
<tr>
7+
<th style="width: 2%;">&nbsp;</th>
8+
<th style="width: 49%;">Name</th>
9+
<th style="width: 49%;">Actions</th>
10+
</tr>
11+
</thead>
12+
<tbody>
13+
@foreach ($board->children as $child)
14+
<tr id="{{ $child->id }}">
15+
<td style="cursor: move;"><i class="fa fa-arrows-v" title="Change order"></i></td>
16+
<td>
17+
<a href="javascript: void(0);" class="editable" id="name" data-type="text" data-pk="{{ $child->id }}">
18+
{{ $child->name }}
19+
</a>
20+
</td>
21+
<td>
22+
<div class="btn-group">
23+
{{ HTML::link('forum/board/edit/'. $child->id, 'Edit', array('class' => 'btn btn-xs btn-primary')) }}
24+
{{ HTML::link('forum/admin/delete-board/'. $child->id, 'Delete', array('class' => 'confirm-remove btn btn-xs btn-danger')) }}
25+
</div>
26+
</td>
27+
</tr>
28+
@if ($child->children->count() > 0)
29+
<?php $newChildren[] = $child; ?>
30+
@endif
31+
@endforeach
32+
</tbody>
33+
</table>
34+
</div>
35+
@if (count($newChildren) > 0)
36+
@foreach ($newChildren as $board)
37+
@include('forum.admin.components.boards', array('width' => $width + 20))
38+
@endforeach
39+
@endif

src/views/forum/board/add.blade.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
<div class="row">
33
<small>
44
<ul class="breadcrumb">
5-
<li>{{ HTML::link('forum', 'Forums') }}</li>
5+
<li>{{ HTML::link('/forum', 'Forums') }}</li>
66
@if ($category != null)
77
<li>{{ HTML::link('forum/category/view/'. $category->id, $category->name) }}</li>
88
@endif
9+
<li>{{ HTML::link('/forum/admin/dashboard', 'Admin') }}</li>
910
<li class="active">Add Board</li>
1011
</ul>
1112
</small>

src/views/forum/board/edit.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<ul class="breadcrumb">
55
<li>{{ HTML::link('forum', 'Forums') }}</li>
66
<li>{{ HTML::link('forum/category/view/'. $board->category->id, $board->category->name) }}</li>
7+
<li>{{ HTML::link('/forum/admin/dashboard', 'Admin') }}</li>
78
<li class="active">Edit Board</li>
89
</ul>
910
</small>

src/views/forum/category/add.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<small>
44
<ul class="breadcrumb">
55
<li>{{ HTML::link('forum', 'Forums') }}</li>
6+
<li>{{ HTML::link('/forum/admin/dashboard', 'Admin') }}</li>
67
<li class="active">Add Category</li>
78
</ul>
89
</small>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{{ bForm::open() }}
2+
<div class="row">
3+
<small>
4+
<ul class="breadcrumb">
5+
<li>{{ HTML::link('forum', 'Forums') }}</li>
6+
<li>{{ HTML::link('/forum/admin/dashboard', 'Admin') }}</li>
7+
<li class="active">Edit Category</li>
8+
</ul>
9+
</small>
10+
<div class="col-md-offset-3 col-md-6">
11+
<div class="panel panel-default">
12+
<div class="panel-heading">Add new forum category</div>
13+
<div class="panel-body">
14+
{{ bForm::text('name', $category->name, array('placeholder' => 'Name'), 'Name') }}
15+
{{ bForm::select('forum_category_type_id', $types, $category->forum_category_type_id, array(), 'Type') }}
16+
{{ bForm::select('position', $categories, $category->position, array(), 'Position') }}
17+
{{ bForm::textarea('description', $category->description, array('placeholder' => 'Description'), 'Description') }}
18+
{{ bForm::submit('Update Category', array('class' => 'btn btn-sm btn-primary')) }}
19+
</div>
20+
</div>
21+
</div>
22+
</div>
23+
</div>
24+
{{ bForm::close() }}

0 commit comments

Comments
 (0)