EditController::edit()   B
last analyzed

Complexity

Conditions 6
Paths 7

Size

Total Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
nc 7
nop 1
dl 0
loc 44
rs 8.5937
c 0
b 0
f 0
1
<?php
2
3
namespace Rudolf\Modules\Users\One\Admin\Profile;
4
5
use Rudolf\Component\Alerts\Alert;
6
use Rudolf\Component\Alerts\AlertsCollection;
7
use Rudolf\Framework\Controller\AdminController;
8
9
class EditController extends AdminController
10
{
11
    /**
12
     * @param $id
13
     *
14
     * @throws \Exception
15
     */
16
    public function edit($id)
17
    {
18
        $model = new EditModel();
19
20
        if (!empty($_POST)) {
21
            if (!empty($_POST['password'])) {
22
                if (trim($_POST['password']) === $_POST['password_again'] && $model->updatePassword($id, $_POST['password'])) {
23
                    AlertsCollection::add(
24
                        new Alert(
25
                            'success',
26
                            'Zaktualizowano hasło'
27
                        )
28
                    );
29
                } else {
30
                    AlertsCollection::add(
31
                        new Alert(
32
                            'error',
33
                            'Podane hasła nie są identyczne!'
34
                        )
35
                    );
36
                }
37
            }
38
39
            if ($model->edit($id, $_POST)) {
40
                AlertsCollection::add(
41
                    new Alert(
42
                        'success',
43
                        'Zaktualizowano profil (bez zmiany hasła)'
44
                    )
45
                );
46
                $this->redirect(DIR.'/admin/users/edit/'.$id);
47
            }
48
            AlertsCollection::add(
49
                new Alert(
50
                    'error',
51
                    'Wystąpił nieoczekiwany błąd'
52
                )
53
            );
54
        }
55
56
        $view = new EditView();
57
        $view->display($model->getUserInfoById($id));
58
        $view->render();
59
    }
60
}
61