Completed
Push — master ( 6c0113...525414 )
by Konstantinos
04:07
created

AdminController::landingAction()   B

Complexity

Conditions 6
Paths 4

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 28
rs 8.439
cc 6
eloc 19
nc 4
nop 1
1
<?php
2
3
4
class AdminController extends HTMLController
5
{
6
    public function listAction()
7
    {
8
        $rolesToDisplay = Role::getLeaderRoles();
9
        $roles = array();
10
11
        foreach ($rolesToDisplay as $role) {
12
            $roleMembers = $role->getUsers();
13
14
            if (count($roleMembers) > 0) {
15
                $roles[] = array(
16
                    "role"    => $role,
17
                    "members" => $roleMembers
18
                );
19
            }
20
        }
21
22
        return array("role_sections" => $roles);
23
    }
24
25
    public function landingAction(Player $me) {
26
        $pages = $roles = null;
27
28
        if (
29
            $me->hasPermission(Permission::SOFT_DELETE_PAGE)
30
            || $me->hasPermission(Permission::EDIT_PAGE)
31
        ) {
32
            $pages = Page::getQueryBuilder()
33
                ->where('status')->notEquals('active')
34
                ->where('status')->notEquals('deleted')
35
                ->getModels($fast = true);
36
        }
37
38
        if (
39
            $me->hasPermission(Permission::CREATE_ROLE)
40
            || $me->hasPermission(Permission::EDIT_ROLE)
41
            || $me->hasPermission(Permission::HARD_DELETE_ROLE)
42
        ) {
43
            $roles = Role::getQueryBuilder()
44
                ->sortBy('display_order')
45
                ->getModels($fast = true);
46
        }
47
48
        return array(
49
            'pages' => $pages,
50
            'roles' => $roles
51
        );
52
    }
53
54
    public function wipeAction(Player $me)
55
    {
56
        $wipeable = array('Ban', 'Map', 'Match', 'News', 'NewsCategory', 'Page', 'Server', 'Team');
57
        $models   = array();
58
59
        foreach ($wipeable as $type) {
60
            if (!$me->hasPermission($type::HARD_DELETE_PERMISSION)) {
61
                continue;
62
            }
63
64
            $models = array_merge($models, $type::getQueryBuilder()
65
                ->where('status')->equals('deleted')
66
                ->getModels());
67
        }
68
69
        return array('models' => $models);
70
    }
71
}
72