|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Classes\AdapterMakerFile\ZendFrameworkOne; |
|
4
|
|
|
|
|
5
|
|
|
use Classes\AdapterMakerFile\AbstractAdapter; |
|
6
|
|
|
use Classes\AdapterConfig\ZendFrameworkOne; |
|
7
|
|
|
use Classes\Maker\AbstractMaker; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @author Pedro Alarcao <[email protected]> |
|
11
|
|
|
* @link https://github.com/pedro151/orm-generator |
|
12
|
|
|
*/ |
|
13
|
|
|
class DbTable extends AbstractAdapter |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
public $pastName = 'DbTable'; |
|
17
|
|
|
protected $fileTpl = "dbtable.php"; |
|
18
|
|
|
protected $fileFixedData = array ( |
|
19
|
|
|
'parentclass' => array ( |
|
20
|
|
|
'name' => "TableAbstract" , |
|
21
|
|
|
'tpl' => "dbtable_abstract.php" |
|
22
|
|
|
) |
|
23
|
|
|
); |
|
24
|
|
|
|
|
25
|
|
|
protected $overwrite = true; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param \Classes\MakerFile $makerFile |
|
29
|
|
|
* @param \Classes\Db\DbTable $dbTable |
|
30
|
|
|
* |
|
31
|
|
|
* @return array |
|
32
|
|
|
*/ |
|
33
|
|
|
public function parseRelation ( \Classes\MakerFile $makerFile, \Classes\Db\DbTable $dbTable ) |
|
34
|
|
|
{ |
|
35
|
|
|
$referenceMap = ''; |
|
36
|
|
|
$references = array (); |
|
37
|
|
|
$dependentTables = ''; |
|
38
|
|
|
$dependents = array (); |
|
39
|
|
|
foreach ( $dbTable->getForeingkeys () as $objColumn ) |
|
40
|
|
|
{ |
|
41
|
|
|
$constrant = $objColumn->getFks (); |
|
42
|
|
|
$variable = $constrant->getNameConstrant () . ZendFrameworkOne::SEPARETOR . $objColumn->getName (); |
|
43
|
|
|
|
|
44
|
|
|
$arrClass = array ( |
|
45
|
|
|
$makerFile->getConfig ()->createClassNamespace ( $constrant ), |
|
46
|
|
|
'DbTable', |
|
47
|
|
|
AbstractMaker::getClassName ( $constrant->getTable () ) |
|
48
|
|
|
); |
|
49
|
|
|
$class = implode ( ZendFrameworkOne::SEPARETOR , array_filter ( $arrClass ) ); |
|
50
|
|
|
|
|
51
|
|
|
$references[] = sprintf ( |
|
52
|
|
|
" |
|
53
|
|
|
'%s' => array ( |
|
54
|
|
|
'columns' => '%s' , |
|
55
|
|
|
'refTableClass' => '%s', |
|
56
|
|
|
'refColumns' =>'%s' |
|
57
|
|
|
)", |
|
58
|
|
|
AbstractMaker::getClassName ( $variable ), |
|
59
|
|
|
$objColumn->getName (), |
|
60
|
|
|
$class, |
|
61
|
|
|
$constrant->getColumn () |
|
62
|
|
|
|
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
if ( sizeof ( $references ) > 0 ) |
|
67
|
|
|
{ |
|
68
|
|
|
$referenceMap = "protected \$_referenceMap = array(" . |
|
69
|
|
|
join ( ',', $references ) . "\n );"; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
foreach ( $dbTable->getDependences () as $objColumn ) |
|
73
|
|
|
{ |
|
74
|
|
|
foreach ( $objColumn->getDependences () as $dependence ) |
|
75
|
|
|
{ |
|
76
|
|
|
$arrClass = array ( |
|
77
|
|
|
$makerFile->getConfig ()->createClassNamespace ( $dependence ), |
|
78
|
|
|
'DbTable', |
|
79
|
|
|
AbstractMaker::getClassName ( $dependence->getTable () ) |
|
80
|
|
|
); |
|
81
|
|
|
$class = implode ( ZendFrameworkOne::SEPARETOR , array_filter ( $arrClass ) ); |
|
82
|
|
|
|
|
83
|
|
|
if(!in_array($class,$dependents)){ |
|
84
|
|
|
$dependents[] = $class; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
if ( sizeof ( $dependents ) > 0 ) |
|
90
|
|
|
{ |
|
91
|
|
|
$dependentTables = "protected \$_dependentTables = array(\n '" . |
|
92
|
|
|
join ( "',\n '", $dependents ) . "'\n );"; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
return array ( |
|
97
|
|
|
'referenceMap' => $referenceMap, |
|
98
|
|
|
'dependentTables' => $dependentTables |
|
99
|
|
|
); |
|
100
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
} |
|
104
|
|
|
|