OdooMapper.php
1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace artbox\odoo\components;
use yii\base\Object;
class OdooMapper extends Object
{
public $map = [];
/**
* Map odoo array to artbox array
*
* @param array $odoo
*
* @return array
*/
public function toArtbox(array $odoo): array
{
$result = [];
foreach ($this->map as $index => $value) {
if (isset($odoo[ $index ])) {
if (is_string($value)) {
$result[ $value ] = $odoo[ $index ];
} else {
$result[ $value[ 'attribute' ] ] = call_user_func($value[ 'artbox' ], $odoo[ $index ]);
}
}
}
return $result;
}
/**
* Map artbox array to odoo array
*
* @param array $artbox
*
* @return array
*/
public function toOdoo(array $artbox): array
{
$result = [];
foreach ($this->map as $index => $value) {
if (is_string($value)) {
if (isset($artbox[ $value ])) {
$result[ $index ] = $artbox[ $value ];
}
} else {
if (isset($artbox[ $value[ 'attribute' ] ])) {
$result[ $index ] = call_user_func($value[ 'odoo' ], $artbox[ $value[ 'attribute' ] ]);
}
}
}
return $result;
}
}