Test Failed
Push — master ( 869dac...c08d94 )
by Alexey
05:56
created

Form   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 63
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A beforeSave() 0 5 2
A relations() 0 13 1
1
<?php
2
3
/**
4
 * Form
5
 *
6
 * @author Alexey Krupskiy <[email protected]>
7
 * @link http://inji.ru/
8
 * @copyright 2015 Alexey Krupskiy
9
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
10
 */
11
12
namespace UserForms;
13
14
/**
15
 *
16
 * @property string $name
17
 * @property string $description
18
 * @property int $user_id
19
 * @property string $submit
20
 * @property string $date_create
21
 * @property-read \Users\User $user
22
 * @property-read \UserForms\Input[] $inputs
23
 * @method inputs (Array $options)
24
 */
25
class Form extends \Model {
26
27
    public static $objectName = 'Форма обращения с сайта';
28
    public static $labels = [
29
        'name' => 'Название',
30
        'description' => 'Описание',
31
        'user_id' => 'Пользователь',
32
        'inputs' => 'Поля формы',
33
        'submit' => 'Текст кнопки отправки',
34
        'date_create' => 'Дата'
35
    ];
36
    public static $cols = [
37
        'name' => ['type' => 'text'],
38
        'submit' => ['type' => 'text'],
39
        'description' => ['type' => 'html'],
40
        'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'],
41
        'date_create' => ['type' => 'dateTime'],
42
        //Менеджеры
43
        'inputsMgr' => ['type' => 'dataManager', 'relation' => 'inputs'],
44
    ];
45
    public static $dataManagers = [
46
        'manager' => [
47
            'cols' => [
48
                'name',
49
                'inputs',
50
                'submit',
51
                'user_id',
52
                'date_create',
53
            ]
54
        ]
55
    ];
56
    public static $forms = [
57
        'manager' => [
58
            'name' => 'Форма приема обращений с сайта',
59
            'map' => [
60
                ['name', 'submit'],
61
                ['description'],
62
                ['inputsMgr'],
63
            ]
64
        ]
65
    ];
66
67
    public function beforeSave() {
68
        if (!$this->id) {
69
            $this->user_id = \Users\User::$cur->id;
70
        }
71
    }
72
73
    public static function relations() {
74
        return [
75
            'user' => [
76
                'model' => '\Users\User',
77
                'col' => 'user_id'
78
            ],
79
            'inputs' => [
80
                'type' => 'many',
81
                'model' => '\UserForms\Input',
82
                'col' => 'form_id',
83
            ],
84
        ];
85
    }
86
87
}
88