-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageBehavior.php
More file actions
44 lines (36 loc) · 1.19 KB
/
ImageBehavior.php
File metadata and controls
44 lines (36 loc) · 1.19 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
<?php
namespace Creonit\PropelImageBehavior;
use Propel\Generator\Model\Behavior;
use Propel\Generator\Model\ForeignKey;
class ImageBehavior extends Behavior
{
protected $parameters = [
'parameter' => 'image_id',
];
protected function addImageColumn($columnName){
$table = $this->getTable();
$table->addColumn([
'name' => $columnName,
'type' => 'integer'
]);
$fk = new ForeignKey();
$fk->setForeignTableCommonName('image');
$fk->setForeignSchemaName($table->getSchema());
$fk->setDefaultJoin('LEFT JOIN');
$fk->setOnDelete(ForeignKey::SETNULL);
$fk->setOnUpdate(ForeignKey::CASCADE);
$fk->addReference($columnName, 'id');
$table->addForeignKey($fk);
}
public function modifyTable()
{
$columns = explode(',', $this->getParameter('parameter'));
foreach ($columns as $column){
$this->addImageColumn(trim($column));
}
}
public function objectMethods($builder)
{
return $this->renderTemplate('objectMethods', ['table' => $this->getTable(), 'columns' => explode(',', $this->getParameter('parameter'))]);
}
}