Skip to content

Commit eeb363b

Browse files
committed
init work
1 parent 83289ae commit eeb363b

File tree

6 files changed

+250
-117
lines changed

6 files changed

+250
-117
lines changed

custom/panel_templates/Default/assets/css/custom.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,3 +469,8 @@ footer.sticky-footer {
469469
height: 16px;
470470
width: 16px;
471471
}
472+
473+
/* Make buttons dimmed when parent table row is not hovered */
474+
.forumEditingRow:not(:hover) .btn {
475+
opacity: 0.5;
476+
}

custom/panel_templates/Default/forum/forums.tpl

Lines changed: 139 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -36,56 +36,123 @@
3636
<div class="card shadow mb-4">
3737
<div class="card-body">
3838

39-
<a href="{$NEW_FORUM_LINK}" class="btn btn-primary" {if count($FORUMS_ARRAY)}
40-
style="margin-bottom: 15px;" {/if}>{$NEW_FORUM}</a>
41-
{if !count($FORUMS_ARRAY)}
42-
<hr />
39+
<a href="{$NEW_CATEGORY_LINK}" class="btn btn-primary">
40+
{$NEW_CATEGORY}
41+
</a>
42+
{if count($CATEGORIES_ARRAY)}
43+
<hr>
4344
{/if}
4445

4546
<!-- Success and Error Alerts -->
4647
{include file='includes/alerts.tpl'}
4748

48-
{if count($FORUMS_ARRAY)}
49-
<div class="table-responsive">
50-
<table class="table">
51-
<tbody id="sortable">
52-
{foreach from=$FORUMS_ARRAY item=item name=forum_array}
53-
<tr data-id="{$item.id}">
54-
<td {if $item.parent_forum} style="padding-left:{math equation="x * y" x=25 y=$item.parent_forum_count}px" {/if}>
55-
<a href="{$item.edit_link}">{$item.title}</a>{if $item.parent_forum}
56-
<small>| {$item.parent_forum}</small>{/if}<br />{$item.description}
57-
</td>
58-
<td width="10%">
59-
<div class="float-md-right">
60-
{if $item.up_link}
61-
<form action="{$item.up_link}" method="post"
62-
style="display: inline">
63-
<input type="hidden" name="token" value="{$TOKEN}" />
64-
<button class="btn btn-success btn-sm"><i
65-
class="fas fa-chevron-up"></i></button>
66-
</form>
49+
{if count($CATEGORIES_ARRAY)}
50+
{foreach from=$CATEGORIES_ARRAY item=category}
51+
<table class="table table-bordered table-sm">
52+
<thead>
53+
<tr style="background-color: #ededed;" class="forumEditingRow">
54+
<th style="width: 70%">
55+
{$category.title}
56+
{if $category.description}
57+
<br>
58+
<small>
59+
{$category.description}
60+
</small>
6761
{/if}
68-
{if $item.down_link}
69-
<form action="{$item.down_link}" method="post"
70-
style="display: inline">
71-
<input type="hidden" name="token" value="{$TOKEN}" />
72-
<button class="btn btn-warning btn-sm"><i
73-
class="fas fa-chevron-down"></i></button>
74-
</form>
62+
</th>
63+
<th class="text-right align-middle">
64+
<a class="btn btn-primary btn-sm" href="{$category.new_forum_link}">
65+
{$NEW_FORUM}
66+
</a>
67+
<a class="btn btn-secondary btn-sm" href="{$category.edit_link}">
68+
{$EDIT}
69+
</a>
70+
{if count($CATEGORIES_ARRAY) > 1}
71+
<button class="btn btn-secondary btn-sm">
72+
<i class="fas fa-up-down-left-right"></i>
73+
</button>
7574
{/if}
76-
<a href="{$item.delete_link}" class="btn btn-danger btn-sm"><i
77-
class="fas fa-trash"></i></a>
78-
</div>
79-
</td>
80-
</tr>
81-
{/foreach}
82-
</tbody>
83-
</table>
84-
</div>
75+
<a class="btn btn-danger btn-sm" href="{$category.delete_link}">
76+
<i class="fas fa-trash"></i>
77+
</a>
78+
</th>
79+
</tr>
80+
</thead>
81+
<tbody>
82+
{foreach from=$category.subforums item=subforum}
83+
<tr class="forumEditingRow">
84+
<td style="width: 70%">
85+
{$subforum.title}
86+
{if $subforum.description}
87+
<br>
88+
<small>
89+
{$subforum.description}
90+
</small>
91+
{/if}
92+
</td>
93+
<td class="text-right align-middle">
94+
<a class="btn btn-secondary btn-sm" href="{$subforum.edit_link}">
95+
Edit
96+
</a>
97+
{if count($category.subforums) > 1}
98+
<button class="btn btn-secondary btn-sm">
99+
<i class="fas fa-up-down-left-right"></i>
100+
</button>
101+
{/if}
102+
<a class="btn btn-danger btn-sm" href="{$subforum.delete_link}">
103+
<i class="fas fa-trash"></i>
104+
</a>
105+
</td>
106+
</tr>
107+
{/foreach}
108+
</tbody>
109+
</table>
110+
{/foreach}
85111
{else}
86-
<p>{$NO_FORUMS}</p>
112+
<p>{$NO_FORUMS}</p>
87113
{/if}
88114

115+
{* {if count($FORUMS_ARRAY)}*}
116+
{* <div class="table-responsive">*}
117+
{* <table class="table">*}
118+
{* <tbody id="sortable">*}
119+
{* {foreach from=$FORUMS_ARRAY item=item name=forum_array}*}
120+
{* <tr data-id="{$item.id}">*}
121+
{* <td {if $item.parent_forum} style="padding-left:{math equation="x * y" x=25 y=$item.parent_forum_count}px" {/if}>*}
122+
{* <a href="{$item.edit_link}">{$item.title}</a>{if $item.parent_forum}*}
123+
{* <small>| {$item.parent_forum}</small>{/if}<br />{$item.description}*}
124+
{* </td>*}
125+
{* <td width="10%">*}
126+
{* <div class="float-md-right">*}
127+
{* {if $item.up_link}*}
128+
{* <form action="{$item.up_link}" method="post"*}
129+
{* style="display: inline">*}
130+
{* <input type="hidden" name="token" value="{$TOKEN}" />*}
131+
{* <button class="btn btn-success btn-sm"><i*}
132+
{* class="fas fa-chevron-up"></i></button>*}
133+
{* </form>*}
134+
{* {/if}*}
135+
{* {if $item.down_link}*}
136+
{* <form action="{$item.down_link}" method="post"*}
137+
{* style="display: inline">*}
138+
{* <input type="hidden" name="token" value="{$TOKEN}" />*}
139+
{* <button class="btn btn-warning btn-sm"><i*}
140+
{* class="fas fa-chevron-down"></i></button>*}
141+
{* </form>*}
142+
{* {/if}*}
143+
{* <a href="{$item.delete_link}" class="btn btn-danger btn-sm"><i*}
144+
{* class="fas fa-trash"></i></a>*}
145+
{* </div>*}
146+
{* </td>*}
147+
{* </tr>*}
148+
{* {/foreach}*}
149+
{* </tbody>*}
150+
{* </table>*}
151+
{* </div>*}
152+
{* {else}*}
153+
{* <p>{$NO_FORUMS}</p>*}
154+
{* {/if}*}
155+
89156
</div>
90157
</div>
91158

@@ -109,38 +176,38 @@
109176
{include file='scripts.tpl'}
110177

111178
<script type="text/javascript">
112-
$(document).ready(function () {
113-
$("#sortable").sortable({
114-
start: function (event, ui) {
115-
let start_pos = ui.item.index();
116-
ui.item.data('startPos', start_pos);
117-
},
118-
update: function (event, ui) {
119-
let forums = $("#sortable").children();
120-
let toSubmit = [];
121-
forums.each(function () {
122-
toSubmit.push($(this).data().id);
123-
});
124-
125-
$.ajax({
126-
url: "{$REORDER_DRAG_URL}",
127-
type: "GET",
128-
data: {
129-
action: "order",
130-
dir: "drag",
131-
{literal}forums: JSON.stringify({"forums": toSubmit}){/literal}
132-
},
133-
success: function (response) {
134-
// Success
135-
},
136-
error: function (xhr) {
137-
// Error
138-
console.log(xhr);
139-
}
140-
});
141-
}
142-
});
143-
});
179+
{*$(document).ready(function () {*}
180+
{* $("#sortable").sortable({*}
181+
{* start: function (event, ui) {*}
182+
{* let start_pos = ui.item.index();*}
183+
{* ui.item.data('startPos', start_pos);*}
184+
{* },*}
185+
{* update: function (event, ui) {*}
186+
{* let forums = $("#sortable").children();*}
187+
{* let toSubmit = [];*}
188+
{* forums.each(function () {*}
189+
{* toSubmit.push($(this).data().id);*}
190+
{* });*}
191+
192+
{* $.ajax({*}
193+
{* url: "{$REORDER_DRAG_URL}",*}
194+
{* type: "GET",*}
195+
{* data: {*}
196+
{* action: "order",*}
197+
{* dir: "drag",*}
198+
{* {literal}forums: JSON.stringify({"forums": toSubmit}){/literal}*}
199+
{* },*}
200+
{* success: function (response) {*}
201+
{* // Success*}
202+
{* },*}
203+
{* error: function (xhr) {*}
204+
{* // Error*}
205+
{* console.log(xhr);*}
206+
{* }*}
207+
{* });*}
208+
{* }*}
209+
{* });*}
210+
{*});*}
144211
</script>
145212
146213
</body>

custom/panel_templates/Default/forum/forums_new_step_1.tpl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@
7878
</div>
7979
<div class="form-group">
8080
<input type="hidden" name="token" value="{$TOKEN}">
81+
{if $PRESELECTED_CATEGORY}
82+
<input type="hidden" name="pre_selected_category" value="{$PRESELECTED_CATEGORY}">
83+
{/if}
8184
<input type="submit" class="btn btn-primary" value="{$SUBMIT}">
8285
</div>
8386
</form>
@@ -132,4 +135,4 @@
132135

133136
</body>
134137

135-
</html>
138+
</html>

custom/panel_templates/Default/forum/forums_new_step_2.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
<label for="InputParent">{$SELECT_PARENT_FORUM}</label>
5656
<select class="form-control" id="InputParent" name="parent">
5757
{foreach from=$PARENT_FORUMS item=item}
58-
<option value="{$item.id}">{$item.name}</option>
58+
<option value="{$item.id}" {if isset($PRESELECTED_CATEGORY) && $PRESELECTED_CATEGORY == $item.id}selected{/if}>{$item.name}</option>
5959
{/foreach}
6060
</select>
6161
</div>
@@ -152,4 +152,4 @@
152152

153153
</body>
154154

155-
</html>
155+
</html>

modules/Forum/classes/Forum.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,16 +796,30 @@ public function getAnySubforums(
796796
* @return array An array of the ids of the labels the user has access to
797797
*/
798798
public static function getAccessibleLabels(array $labels, array $user_groups): array {
799-
return array_reduce($labels, function(&$prev, $topic_label) use ($user_groups) {
799+
return array_reduce($labels, static function (&$prev, $topic_label) use ($user_groups) {
800800
$label = DB::getInstance()->get('forums_topic_labels', ['id', $topic_label])->first();
801801
if ($label) {
802802
$label_group_ids = explode(',', $label->gids);
803-
$hasPerm = array_reduce($user_groups, fn($prev, $group_id) => $prev || in_array($group_id, $label_group_ids));
803+
$hasPerm = array_reduce($user_groups, static fn ($prev, $group_id) => $prev || in_array($group_id, $label_group_ids));
804804
if ($hasPerm) {
805805
$prev[] = $label->id;
806806
}
807807
}
808808
return $prev;
809809
}, []);
810810
}
811+
812+
public function recursiveGetSubForums(int $parent_id, array $current = []): array {
813+
$forums = $this->_db->query(
814+
'SELECT * FROM nl2_forums WHERE parent = ? ORDER BY forum_order',
815+
[$parent_id]
816+
);
817+
if ($forums->count()) {
818+
foreach ($forums->results() as $forum) {
819+
$current[$parent_id][] = $forum;
820+
$current = $this->recursiveGetSubForums($forum->id, $current);
821+
}
822+
}
823+
return $current;
824+
}
811825
}

0 commit comments

Comments
 (0)