Passed
Push — master ( 73d14c...8a9029 )
by Mihail
04:02
created

ActionFieldUpdate   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A profileFieldUpdate() 0 17 4
1
<?php
2
3
namespace Apps\Controller\Admin\Profile;
4
5
use Apps\Model\Admin\Profile\FormFieldUpdate;
6
use Ffcms\Core\App;
7
use Ffcms\Core\Arch\View;
8
use Ffcms\Core\Network\Request;
9
use Ffcms\Core\Network\Response;
10
use Apps\ActiveRecord\ProfileField;
11
12
/**
13
 * Trait ActionFieldUpdate
14
 * @package Apps\Controller\Admin\Profile
15
 * @property Request $request
16
 * @property Response $response
17
 * @property View $view
18
 */
19
trait ActionFieldUpdate
20
{
21
22
    /**
23
     * Add new or edit exist additional fields for user profiles
24
     * @param string|null $id
25
     * @return string
26
     * @throws \Ffcms\Core\Exception\SyntaxException
27
     */
28
    public function profileFieldUpdate($id = null)
29
    {
30
        // get current record or new and init form DI
31
        $record = ProfileField::findOrNew($id);
32
        $model = new FormFieldUpdate($record);
33
34
        // check if form is submitted
35
        if ($model->send() && $model->validate()) {
36
            $model->save();
37
            if ($record->id) {
38
                $this->response->redirect('profile/fieldlist');
39
            }
40
            App::$Session->getFlashBag()->add('success', __('Profile field was successful updated'));
41
        }
42
43
        return $this->view->render('profile/field_update', [
44
            'model' => $model
45
        ]);
46
    }
47
}