1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Yandex PHP Library |
4
|
|
|
* |
5
|
|
|
* @copyright NIX Solutions Ltd. |
6
|
|
|
* @link https://github.com/nixsolutions/yandex-php-library |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @namespace |
11
|
|
|
*/ |
12
|
|
|
namespace Yandex\DataSync\Models\Database\Delta; |
13
|
|
|
|
14
|
|
|
use Yandex\Common\Model; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class RecordField |
18
|
|
|
* |
19
|
|
|
* @category Yandex |
20
|
|
|
* @package DataSync |
21
|
|
|
* |
22
|
|
|
* @author Alexander Khaylo <[email protected]> |
23
|
|
|
* @created 02.03.16 12:38 |
24
|
|
|
*/ |
25
|
|
|
class RecordField extends Model |
26
|
|
|
{ |
27
|
|
|
protected $propNameMap = [ |
28
|
|
|
'change_type' => 'changeType', |
29
|
|
|
'field_id' => 'fieldId', |
30
|
|
|
'list_item' => 'listItem', |
31
|
|
|
'list_item_dest' => 'listItemDest' |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
protected $mappingClasses = [ |
35
|
|
|
'value' => 'Yandex\DataSync\Models\Database\Delta\RecordFieldValue' |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Adding a new field or change existing values. |
40
|
|
|
*/ |
41
|
|
|
const CHANGE_TYPE_SET = 'set'; |
42
|
|
|
/** |
43
|
|
|
* Deleting field. |
44
|
|
|
*/ |
45
|
|
|
const CHANGE_TYPE_DELETE = 'delete'; |
46
|
|
|
|
47
|
|
|
//this change is only available for the field, which has a data type list ( DATA_TYPE_LIST ). |
48
|
|
|
/** |
49
|
|
|
* Add a new item to the list. |
50
|
|
|
*/ |
51
|
|
|
const CHANGE_TYPE_LIST_ITEM_INSERT = 'list_item_insert'; |
52
|
|
|
/** |
53
|
|
|
* Set the value for the element at the specified index. |
54
|
|
|
*/ |
55
|
|
|
const CHANGE_TYPE_LIST_ITEM_SET = 'list_item_set'; |
56
|
|
|
/** |
57
|
|
|
* Move element of the array. |
58
|
|
|
*/ |
59
|
|
|
const CHANGE_TYPE_LIST_ITEM_MOVE = 'list_item_move'; |
60
|
|
|
/** |
61
|
|
|
* Delete a list item. |
62
|
|
|
*/ |
63
|
|
|
const CHANGE_TYPE_LIST_ITEM_DELETE = 'list_item_delete'; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var string |
67
|
|
|
*/ |
68
|
|
|
protected $changeType; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var string |
72
|
|
|
*/ |
73
|
|
|
protected $fieldId; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* The index of the list, to which is applied the change. |
77
|
|
|
* This field is specified with any change, starting with "list_item". |
78
|
|
|
* |
79
|
|
|
* @var int |
80
|
|
|
*/ |
81
|
|
|
protected $listItem; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* The new list item index. It specifies the type of change at the list item move. |
85
|
|
|
* |
86
|
|
|
* @var int |
87
|
|
|
*/ |
88
|
|
|
protected $listItemDest; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @var RecordFieldValue |
92
|
|
|
*/ |
93
|
|
|
protected $value; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
1 |
|
public function getChangeType() |
99
|
|
|
{ |
100
|
1 |
|
return $this->changeType; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param string $changeType |
105
|
|
|
* |
106
|
|
|
* @return $this |
107
|
|
|
*/ |
108
|
5 |
|
public function setChangeType($changeType) |
109
|
|
|
{ |
110
|
5 |
|
$this->changeType = $changeType; |
111
|
5 |
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return string |
116
|
|
|
*/ |
117
|
2 |
|
public function getFieldId() |
118
|
|
|
{ |
119
|
2 |
|
return $this->fieldId; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param string $fieldId |
124
|
|
|
* |
125
|
|
|
* @return $this |
126
|
|
|
*/ |
127
|
5 |
|
public function setFieldId($fieldId) |
128
|
|
|
{ |
129
|
5 |
|
$this->fieldId = $fieldId; |
130
|
5 |
|
return $this; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return int |
135
|
|
|
*/ |
136
|
1 |
|
public function getListItem() |
137
|
|
|
{ |
138
|
1 |
|
return $this->listItem; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @param int $listItem |
143
|
|
|
* |
144
|
|
|
* @return $this |
145
|
|
|
*/ |
146
|
1 |
|
public function setListItem($listItem) |
147
|
|
|
{ |
148
|
1 |
|
$this->listItem = $listItem; |
149
|
1 |
|
return $this; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @return int |
154
|
|
|
*/ |
155
|
1 |
|
public function getListItemDest() |
156
|
|
|
{ |
157
|
1 |
|
return $this->listItemDest; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param int $listItemDest |
162
|
|
|
* |
163
|
|
|
* @return $this |
164
|
|
|
*/ |
165
|
1 |
|
public function setListItemDest($listItemDest) |
166
|
|
|
{ |
167
|
1 |
|
$this->listItemDest = $listItemDest; |
168
|
1 |
|
return $this; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @return RecordFieldValue |
173
|
|
|
*/ |
174
|
2 |
|
public function getValue() |
175
|
|
|
{ |
176
|
2 |
|
return $this->value; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @param RecordFieldValue $value |
181
|
|
|
* |
182
|
|
|
* @return $this |
183
|
|
|
*/ |
184
|
4 |
|
public function setValue(RecordFieldValue $value) |
185
|
|
|
{ |
186
|
4 |
|
$this->value = $value; |
187
|
4 |
|
return $this; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Get array from object |
192
|
|
|
* |
193
|
|
|
* @param array|object $data |
194
|
|
|
* |
195
|
|
|
* @return array |
196
|
|
|
*/ |
197
|
4 |
|
protected function toArrayRecursive($data) |
198
|
|
|
{ |
199
|
|
|
|
200
|
4 |
|
if ($data instanceof RecordFieldValue) { |
201
|
4 |
|
return $data->toArrayRecursive($data); |
|
|
|
|
202
|
|
|
} else { |
203
|
4 |
|
return parent::toArrayRecursive($data); |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
} |
207
|
|
|
|
This check looks for access to methods that are not accessible from the current context.
If you need to make a method accessible to another context you can raise its visibility level in the defining class.