1
|
|
|
<?php |
2
|
|
|
namespace Mezon\Gui\FormBuilder; |
3
|
|
|
|
4
|
|
|
use Mezon\Gui\Field; |
5
|
|
|
use Mezon\Gui\FieldsAlgorithms; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class RowsField |
9
|
|
|
* |
10
|
|
|
* @package FormBuidler |
11
|
|
|
* @subpackage RowsField |
12
|
|
|
* @author Dodonov A.A. |
13
|
|
|
* @version v.1.0 (2019/09/22) |
14
|
|
|
* @copyright Copyright (c) 2019, http://aeon.su |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Rows field control |
19
|
|
|
*/ |
20
|
|
|
class RowsField extends Field |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Rowed field content |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $rowedField = ''; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Constructor |
32
|
|
|
* |
33
|
|
|
* @param array $rows |
34
|
|
|
* controls for row |
35
|
|
|
* @param string $entityName |
36
|
|
|
* name of the entity |
37
|
|
|
*/ |
38
|
|
|
public function __construct(array $rows, string $entityName) |
39
|
|
|
{ |
40
|
|
|
$rowedField = ''; |
41
|
|
|
|
42
|
|
|
$fieldsAlgorithms = new FieldsAlgorithms($rows, $entityName); |
43
|
|
|
|
44
|
|
|
foreach (array_keys($rows) as $fieldName) { |
45
|
|
|
$control = $fieldsAlgorithms->getObject($fieldName); |
46
|
|
|
$rowedField .= $control->html(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$this->rowedField = $rowedField; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Generating input feld |
54
|
|
|
* |
55
|
|
|
* @return string HTML representation of the input field |
56
|
|
|
*/ |
57
|
|
|
public function html(): string |
58
|
|
|
{ |
59
|
|
|
$content = '<div><div class="form-group col-md-12">'; |
60
|
|
|
$content .= '<button class="btn btn-success col-md-2" onclick="add_element_by_template( this , \'' . $this->name . |
61
|
|
|
'\' )">+</button>'; |
62
|
|
|
$content .= '</div></div>'; |
63
|
|
|
|
64
|
|
|
$content = str_replace('{_creation_form_items_counter}', '0', $content); |
65
|
|
|
|
66
|
|
|
$content .= '<template class="' . $this->name . '"><div>'; |
67
|
|
|
$content .= $this->rowedField; |
68
|
|
|
$content .= '<div class="form-group col-md-12">'; |
69
|
|
|
$content .= '<button class="btn btn-success col-md-2" onclick="add_element_by_template( this , \'' . $this->name . |
70
|
|
|
'\' );">+</button>'; |
71
|
|
|
$content .= '<button class="btn btn-danger col-md-2" onclick="remove_element_by_template( this );">-</button>'; |
72
|
|
|
$content .= '</div></div>'; |
73
|
|
|
|
74
|
|
|
return $content . '</template>'; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Does control fills all row |
79
|
|
|
*/ |
80
|
|
|
public function fillAllRow(): bool |
81
|
|
|
{ |
82
|
|
|
return true; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|