TypeAddController::add()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 36
rs 9.344
c 0
b 0
f 0
1
<?php
2
3
namespace Rudolf\Modules\Appearance\Menu\Type;
4
5
use Rudolf\Component\Alerts\Alert;
6
use Rudolf\Component\Alerts\AlertsCollection;
7
use Rudolf\Framework\Controller\AdminController;
8
9
class TypeAddController extends AdminController
10
{
11
    /**
12
     * @throws \Exception
13
     */
14
    public function add()
15
    {
16
        if (isset($_POST['add'])) {
17
            $model = new TypeAddModel();
18
            $id = $model->add($_POST);
19
            if ($id) {
20
                AlertsCollection::add(new Alert(
21
                    'success',
22
                    'Poprawnie dodano!'
23
                ));
24
                $this->redirectTo(DIR.'/admin/appearance/menu/edit-type/'.$id);
25
                return;
26
            }
27
            AlertsCollection::add(new Alert(
28
                'error',
29
                'Coś się zepsuło!'
30
            ));
31
            $item = new MenuType([
32
                'id' => -1,
33
                'title' => $_POST['title'],
34
                'menu_type' => $_POST['menu_type'],
35
                'description' => $_POST['description'],
36
            ]);
37
        } else {
38
            $item = new MenuType([
39
                'id' => -1,
40
                'title' => '',
41
                'menu_type' => '',
42
                'description' => ''
43
            ]);
44
        }
45
46
        $view = new TypeAddView();
47
        $view->display($item);
48
        $view->render();
49
    }
50
}
51