1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Helmut\Forms\Fields\Name; |
4
|
|
|
|
5
|
|
|
use Helmut\Forms\Field; |
6
|
|
|
use Helmut\Forms\Utility\Validate; |
7
|
|
|
|
8
|
|
|
class Name extends Field { |
9
|
|
|
|
10
|
|
|
protected $default = []; |
11
|
|
|
protected $value_first = ''; |
12
|
|
|
protected $value_surname = ''; |
13
|
12 |
|
protected $value = ''; |
14
|
|
|
|
15
|
12 |
|
public function getValue() |
16
|
12 |
|
{ |
17
|
12 |
|
$values = []; |
18
|
12 |
|
$values[$this->name.'_first'] = $this->value_first; |
19
|
12 |
|
$values[$this->name.'_surname'] = $this->value_surname; |
20
|
|
|
$values[$this->name] = $this->value; |
21
|
|
|
return $values; |
22
|
14 |
|
} |
23
|
|
|
|
24
|
14 |
|
public function getButtonName() |
25
|
|
|
{ |
26
|
|
|
// |
27
|
4 |
|
} |
28
|
|
|
|
29
|
4 |
|
public function renderWith() |
30
|
4 |
|
{ |
31
|
4 |
|
return [ |
32
|
4 |
|
'name_first' => $this->name.'_first', |
33
|
|
|
'name_surname' => $this->name.'_surname', |
34
|
|
|
'value_first' => $this->value_first, |
35
|
|
|
'value_surname' => $this->value_surname, |
36
|
13 |
|
]; |
37
|
|
|
} |
38
|
13 |
|
|
39
|
13 |
|
public function setValueFromDefault() |
40
|
13 |
|
{ |
41
|
13 |
|
if (isset($this->default['first'])) $this->value_first = $this->default['first']; |
42
|
|
|
if (isset($this->default['surname'])) $this->value_surname = $this->default['surname']; |
43
|
1 |
|
$this->value = trim($this->value_first.' '.$this->value_surname); |
44
|
|
|
} |
45
|
1 |
|
|
46
|
1 |
|
public function setValueFromModel($model) |
47
|
1 |
|
{ |
48
|
1 |
|
if (isset($model->{$this->name.'_first'})) $this->value_first = $model->{$this->name.'_first'}; |
49
|
|
|
if (isset($model->{$this->name.'_surname'})) $this->value_surname = $model->{$this->name.'_surname'}; |
50
|
2 |
|
$this->value = trim($this->value_first.' '.$this->value_surname); |
51
|
|
|
} |
52
|
2 |
|
|
53
|
2 |
|
public function setValueFromRequest($request) |
54
|
2 |
|
{ |
55
|
2 |
|
$this->value_first = $request->get($this->name.'_first'); |
56
|
|
|
$this->value_surname = $request->get($this->name.'_surname'); |
57
|
1 |
|
$this->value = trim($this->value_first.' '.$this->value_surname); |
58
|
|
|
} |
59
|
1 |
|
|
60
|
1 |
|
public function fillModelWithValue($model) |
61
|
1 |
|
{ |
62
|
1 |
|
$model->{$this->name.'_first'} = $this->value_first; |
63
|
|
|
$model->{$this->name.'_surname'} = $this->value_surname; |
64
|
1 |
|
$model->{$this->name} = $this->value; |
65
|
|
|
} |
66
|
1 |
|
|
67
|
1 |
|
public function validateRequired() |
68
|
|
|
{ |
69
|
|
|
return Validate::required($this->value_first) |
70
|
|
|
&& Validate::required($this->value_surname); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
} |
74
|
|
|
|