-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathCategories.php
More file actions
97 lines (77 loc) · 3.02 KB
/
Categories.php
File metadata and controls
97 lines (77 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* Copyright (C) 2015-2019 FeatherBB
* based on code by (C) 2008-2015 FluxBB
* and Rickard Andersson (C) 2002-2008 PunBB
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
*/
namespace FeatherBB\Model\Admin;
use FeatherBB\Core\Database as DB;
use FeatherBB\Core\Interfaces\Hooks;
class Categories
{
public function addCategory($catName)
{
$catName = Hooks::fire('model.admin.categories.add_category', $catName);
$setAddCategory = ['cat_name' => $catName];
return DB::table('categories')
->create()
->set($setAddCategory)
->save();
}
public function updateCategory(array $category)
{
$category = Hooks::fire('model.admin.categories.update_category', $category);
$setUpdateCategory = ['cat_name' => $category['name'],
'disp_position' => $category['order']];
return DB::table('categories')
->findOne($category['id'])
->set($setUpdateCategory)
->save();
}
public function deleteCategory($catToDelete)
{
$catToDelete = Hooks::fire('model.admin.categories.delete_category_start', $catToDelete);
$forumsInCat = DB::table('forums')
->select('id')
->where('cat_id', $catToDelete);
$forumsInCat = Hooks::fireDB('model.admin.categories.delete_forums_in_cat_query', $forumsInCat);
$forumsInCat = $forumsInCat->findMany();
foreach ($forumsInCat as $forum) {
// Prune all posts and topics
$this->maintenance = new \FeatherBB\Model\Admin\Maintenance();
$this->maintenance->prune($forum->id, 1, -1);
// Delete forum
DB::table('forums')
->findOne($forum->id)
->delete();
}
// Delete orphan redirect forums
$orphans = DB::table('topics')
->tableAlias('t1')
->leftOuterJoin('topics', ['t1.moved_to', '=', 't2.id'], 't2')
->whereNull('t2.id')
->whereNotNull('t1.moved_to');
$orphans = Hooks::fireDB('model.admin.categories.delete_orphan_forums_query', $orphans);
$orphans = $orphans->findMany();
if (count($orphans) > 0) {
$orphans->deleteMany();
}
// Delete category
$result = DB::table('categories');
$result = Hooks::fireDB('model.admin.categories.find_forums_in_cat', $result);
$result = $result->findOne($catToDelete)->delete();
return true;
}
public function categoryList()
{
$catList = [];
$selectGetCatList = ['id', 'cat_name', 'disp_position'];
$catList = DB::table('categories')
->select($selectGetCatList)
->orderByAsc('disp_position');
$catList = Hooks::fireDB('model.admin.categories.get_cat_list', $catList);
$catList = $catList->findArray();
return $catList;
}
}