-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreeBehavior.php
More file actions
62 lines (46 loc) · 1.45 KB
/
TreeBehavior.php
File metadata and controls
62 lines (46 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace Creonit\PropelTreeBehavior;
use Propel\Generator\Model\Behavior;
use Propel\Generator\Model\ForeignKey;
class TreeBehavior extends Behavior
{
public function modifyTable()
{
$table = $this->getTable();
$table->addColumn([
'name' => 'path',
'type' => 'varchar',
'size' => 255
]);
$table->addColumn([
'name' => 'level',
'type' => 'integer',
]);
if(!$table->hasColumn('parent_id')){
$table->addColumn([
'name' => 'parent_id',
'type' => 'integer',
'require' => false,
]);
$fk = new ForeignKey();
$fk->setForeignTableCommonName($table->getCommonName());
$fk->setForeignSchemaName($table->getSchema());
$fk->setDefaultJoin('LEFT JOIN');
$fk->setOnDelete(ForeignKey::CASCADE);
$fk->setOnUpdate(ForeignKey::CASCADE);
$fk->addReference('parent_id', 'id');
$table->addForeignKey($fk);
}
}
public function objectMethods()
{
return $this->renderTemplate('objectMethods', ['table' => $this->getTable()]);
}
public function objectAttributes()
{
return $this->renderTemplate('objectAttributes');
}
public function preSave(){
return $this->renderTemplate('preSave', ['table' => $this->getTable()]);
}
}