AdminController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A onlyPost() 0 6 2
A onlyAdmin() 0 5 2
1
<?php
2
3
namespace Core;
4
5
/**
6
 * The parent controller for all admin section controllers
7
 * Class AdminController
8
 * @package Core
9
 */
10
abstract class AdminController extends Controller
11
{
12
    /**
13
     * Out placeholders for modules
14
     * @var object
15
     */
16
    protected $alertBox;
17
18
    public function __construct(Container $container)
19
    {
20
21
        $this->loadModules[] = 'AlertBox';
22
        parent::__construct($container);
23
24
        //Sending the auth level to the data
25
        $this->data['userRole'] = $this->auth->getUserRole();
26
        $this->data['userLevel'] = $this->auth->getUserLevel();
27
28
    }
29
30
    /**
31
     * Only allow admin
32
     */
33
    protected function onlyAdmin()
34
    {
35
        if (!$this->auth->isAdmin()) {
36
            $this->alertBox->setAlert("Only admins can access this", 'error');
37
            $this->container->getResponse()->redirect('/admin');
38
        }
39
    }
40
41
    /**
42
     * Only allow post messages
43
     */
44
    protected function onlyPost()
45
    {
46
        //is post
47
        if (!$this->request->isPost()) {
48
            $this->alertBox->setAlert('Only post messages allowed', 'error');
49
            $this->response->redirect('/admin');
50
        }
51
    }
52
53
54
}