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 $tableprefix; |
12
|
|
|
|
13
|
25 |
|
public function __construct($tableprefix) |
14
|
|
|
{ |
15
|
25 |
|
$this->tableprefix = $tableprefix; |
16
|
25 |
|
} |
17
|
|
|
|
18
|
1 |
|
public function getFunctions() |
19
|
|
|
{ |
20
|
|
|
return array( |
21
|
1 |
|
new TwigFunction('object2view', array($this, 'object2View', 'is_safe' => array('html'))), |
22
|
1 |
|
new TwigFunction('field2object', array($this, 'field2Object', 'is_safe' => array('html'))), |
23
|
1 |
|
new TwigFunction('joinfieldid', array($this, 'joinFieldId', 'is_safe' => array('html'))), |
24
|
|
|
); |
25
|
|
|
} |
26
|
|
|
|
27
|
7 |
|
public function object2View($object, $type = null, $decodifiche = null) |
28
|
|
|
{ |
29
|
7 |
|
$dfr = new DoctrineFieldReader($this->tableprefix); |
30
|
|
|
|
31
|
7 |
|
return $dfr->object2View($object, $type, $decodifiche); |
32
|
|
|
} |
33
|
|
|
|
34
|
7 |
|
public function field2Object($fieldname, $object, $decodifiche = null) |
35
|
|
|
{ |
36
|
7 |
|
$dfr = new DoctrineFieldReader($this->tableprefix); |
37
|
|
|
|
38
|
7 |
|
return $dfr->getField2Object($fieldname, $object, $decodifiche); |
39
|
|
|
} |
40
|
|
|
|
41
|
3 |
|
public function joinFieldId($object) |
42
|
|
|
{ |
43
|
3 |
|
$valore = null; |
44
|
3 |
|
if ($object) { |
45
|
2 |
|
$valore = $object->getId(); |
46
|
|
|
} |
47
|
|
|
|
48
|
3 |
|
return $valore; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|