|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Fi\CoreBundle\Utils; |
|
4
|
|
|
|
|
5
|
|
|
final class TabelleSingletonUtility |
|
6
|
|
|
{ |
|
7
|
|
|
|
|
8
|
|
|
private static $queryTabelle; |
|
9
|
|
|
private static $nometabella; |
|
10
|
|
|
private static $operatore; |
|
11
|
|
|
|
|
12
|
21 |
|
public static function instance($em, $nometabella, $operatore) |
|
13
|
|
|
{ |
|
14
|
21 |
|
static $inst = null; |
|
15
|
21 |
|
if ($inst === null) { |
|
16
|
|
|
self::$nometabella = $nometabella; |
|
17
|
|
|
self::$operatore = $operatore; |
|
18
|
|
|
$inst = new TabelleSingletonUtility($em, $nometabella, $operatore); |
|
19
|
|
|
} |
|
20
|
21 |
|
if ($nometabella != self::$nometabella || $operatore != self::$operatore) { |
|
21
|
15 |
|
self::$nometabella = $nometabella; |
|
22
|
15 |
|
self::$operatore = $operatore; |
|
23
|
15 |
|
$inst = new TabelleSingletonUtility($em, $nometabella, $operatore); |
|
24
|
|
|
} |
|
25
|
21 |
|
return $inst; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Private construct so nobody else can instantiate it |
|
30
|
|
|
* |
|
31
|
|
|
*/ |
|
32
|
15 |
|
private function __construct($em, $nometabella, $operatore) |
|
33
|
|
|
{ |
|
34
|
15 |
|
self::$queryTabelle = $em->getRepository('FiCoreBundle:Tabelle')->findBy(array('operatori_id' => $operatore, 'nometabella' => $nometabella)); |
|
35
|
|
|
|
|
36
|
15 |
|
if (!self::$queryTabelle) { |
|
37
|
15 |
|
self::$queryTabelle = $em->getRepository('FiCoreBundle:Tabelle')->findBy(array('operatori_id' => null, 'nometabella' => $nometabella)); |
|
38
|
|
|
} |
|
39
|
15 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Call this method to get singleton |
|
43
|
|
|
* |
|
44
|
|
|
* @return \Fi\CoreBundle\Entity\Tabelle |
|
45
|
|
|
*/ |
|
46
|
|
|
|
|
47
|
21 |
|
public static function getTabelle() |
|
48
|
|
|
{ |
|
49
|
21 |
|
return self::$queryTabelle; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|