|
1
|
|
|
<?php |
|
2
|
|
|
namespace keeko\tools\model; |
|
3
|
|
|
|
|
4
|
|
|
use Propel\Generator\Model\CrossForeignKeys; |
|
5
|
|
|
use Propel\Generator\Model\ForeignKey; |
|
6
|
|
|
use Propel\Generator\Model\Table; |
|
7
|
|
|
|
|
8
|
|
|
class ManyToManyRelationship extends Relationship { |
|
9
|
|
|
|
|
10
|
|
|
/** @var ForeignKey */ |
|
11
|
|
|
protected $lk; |
|
12
|
|
|
|
|
13
|
|
|
/** @var CrossForeignKeys */ |
|
14
|
|
|
protected $cfk; |
|
15
|
|
|
|
|
16
|
|
|
public function __construct(Table $model, CrossForeignKeys $cfk) { |
|
17
|
|
|
$this->model = $model; |
|
18
|
|
|
$this->cfk = $cfk; |
|
19
|
|
|
|
|
20
|
|
|
foreach ($cfk->getMiddleTable()->getForeignKeys() as $fk) { |
|
21
|
|
|
if ($fk->getForeignTable() != $model) { |
|
22
|
|
|
$this->fk = $fk; |
|
23
|
|
|
} else if ($fk->getForeignTable() == $model) { |
|
24
|
|
|
$this->lk = $fk; |
|
25
|
|
|
} |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
$this->foreign = $this->fk->getForeignTable(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Returns the type of this relationship |
|
33
|
|
|
* |
|
34
|
|
|
* @return string |
|
35
|
|
|
*/ |
|
36
|
|
|
public function getType() { |
|
37
|
|
|
return self::MANY_TO_MANY; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Returns the middle table |
|
42
|
|
|
* |
|
43
|
|
|
* @return Table |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getMiddle() { |
|
46
|
|
|
return $this->cfk->getMiddleTable(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Returns the cross foreign keys |
|
51
|
|
|
* |
|
52
|
|
|
* @return CrossForeignKeys |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getCrossForeignKeys() { |
|
55
|
|
|
return $this->cfk; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Returns the local key |
|
60
|
|
|
* |
|
61
|
|
|
* @return ForeignKey |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getLocalKey() { |
|
64
|
|
|
return $this->lk; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function getRelatedName() { |
|
68
|
|
|
$relatedName = $this->lk->getRefPhpName(); |
|
69
|
|
|
if (empty($relatedName)) { |
|
70
|
|
|
$relatedName = $this->foreign->getPhpName(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return $relatedName; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function getReverseRelatedName() { |
|
77
|
|
|
$reverseRelatedName = $this->lk->getPhpName(); |
|
78
|
|
|
if (empty($reverseRelatedName)) { |
|
79
|
|
|
$reverseRelatedName = $this->model->getPhpName(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return $reverseRelatedName; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|