|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Cdf\BiCoreBundle\Twig\Extension; |
|
4
|
|
|
|
|
5
|
|
|
use Cdf\BiCoreBundle\Utils\Entity\DoctrineFieldReader; |
|
6
|
|
|
use Twig\Extension\AbstractExtension; |
|
7
|
|
|
use Twig\TwigFunction; |
|
8
|
|
|
|
|
9
|
|
|
class ObjectToTabellaExtension extends AbstractExtension |
|
10
|
|
|
{ |
|
11
|
|
|
private string $tableprefix; |
|
12
|
|
|
|
|
13
|
25 |
|
public function __construct(string $tableprefix) |
|
14
|
|
|
{ |
|
15
|
25 |
|
$this->tableprefix = $tableprefix; |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
1 |
|
public function getFunctions(): array |
|
19
|
|
|
{ |
|
20
|
1 |
|
return array( |
|
21
|
1 |
|
new TwigFunction('object2view', [$this, 'object2View']), |
|
22
|
1 |
|
new TwigFunction('field2object', [$this, 'field2Object']), |
|
23
|
1 |
|
new TwigFunction('joinfieldid', [$this, 'joinFieldId']), |
|
24
|
1 |
|
); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* |
|
29
|
|
|
* @param mixed $object |
|
30
|
|
|
* @param string $type |
|
31
|
|
|
* @param array<mixed> $decodifiche |
|
32
|
|
|
* @return mixed|null |
|
33
|
|
|
*/ |
|
34
|
7 |
|
public function object2View($object, ?string $type = null, $decodifiche = null) |
|
35
|
|
|
{ |
|
36
|
7 |
|
$dfr = new DoctrineFieldReader($this->tableprefix); |
|
37
|
|
|
|
|
38
|
7 |
|
return $dfr->object2View($object, $type, $decodifiche); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $fieldname |
|
44
|
|
|
* @param mixed $object |
|
45
|
|
|
* @param array<mixed> $decodifiche |
|
46
|
|
|
* @return mixed|null |
|
47
|
|
|
*/ |
|
48
|
7 |
|
public function field2Object($fieldname, $object, $decodifiche = null) |
|
49
|
|
|
{ |
|
50
|
7 |
|
$dfr = new DoctrineFieldReader($this->tableprefix); |
|
51
|
|
|
|
|
52
|
7 |
|
return $dfr->getField2Object($fieldname, $object, $decodifiche); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* |
|
57
|
|
|
* @param mixed $object |
|
58
|
|
|
* @return int|null |
|
59
|
|
|
*/ |
|
60
|
3 |
|
public function joinFieldId($object) |
|
61
|
|
|
{ |
|
62
|
3 |
|
$valore = null; |
|
63
|
3 |
|
if ($object) { |
|
64
|
2 |
|
$valore = $object->getId(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
3 |
|
return $valore; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|