| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class SfPropelBehaviorSymfony extends SfPropelBehaviorBase |
|---|
| 20 |
{ |
|---|
| 21 |
protected $parameters = array( |
|---|
| 22 |
'form' => 'true', |
|---|
| 23 |
'filter' => 'true', |
|---|
| 24 |
); |
|---|
| 25 |
|
|---|
| 26 |
public function modifyDatabase() |
|---|
| 27 |
{ |
|---|
| 28 |
foreach ($this->getDatabase()->getTables() as $table) |
|---|
| 29 |
{ |
|---|
| 30 |
$behaviors = $table->getBehaviors(); |
|---|
| 31 |
|
|---|
| 32 |
if (!isset($behaviors['symfony'])) |
|---|
| 33 |
{ |
|---|
| 34 |
$behavior = clone $this; |
|---|
| 35 |
$table->addBehavior($behavior); |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
if (!isset($behaviors['symfony_behaviors']) && $this->getBuildProperty('propel.builder.addBehaviors')) |
|---|
| 40 |
{ |
|---|
| 41 |
$class = Propel::importClass($this->getBuildProperty('propel.behavior.symfony_behaviors.class')); |
|---|
| 42 |
$behavior = new $class(); |
|---|
| 43 |
$behavior->setName('symfony_behaviors'); |
|---|
| 44 |
$table->addBehavior($behavior); |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
if (!isset($behaviors['symfony_timestampable'])) |
|---|
| 49 |
{ |
|---|
| 50 |
$parameters = array(); |
|---|
| 51 |
foreach ($table->getColumns() as $column) |
|---|
| 52 |
{ |
|---|
| 53 |
if (!isset($parameters['create_column']) && in_array($column->getName(), array('created_at', 'created_on'))) |
|---|
| 54 |
{ |
|---|
| 55 |
$parameters['create_column'] = $column->getName(); |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
if (!isset($parameters['update_column']) && in_array($column->getName(), array('updated_at', 'updated_on'))) |
|---|
| 59 |
{ |
|---|
| 60 |
$parameters['update_column'] = $column->getName(); |
|---|
| 61 |
} |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
if ($parameters) |
|---|
| 65 |
{ |
|---|
| 66 |
$class = Propel::importClass($this->getBuildProperty('propel.behavior.symfony_timestampable.class')); |
|---|
| 67 |
$behavior = new $class(); |
|---|
| 68 |
$behavior->setName('symfony_timestampable'); |
|---|
| 69 |
$behavior->setParameters($parameters); |
|---|
| 70 |
$table->addBehavior($behavior); |
|---|
| 71 |
} |
|---|
| 72 |
} |
|---|
| 73 |
} |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
public function objectAttributes() |
|---|
| 77 |
{ |
|---|
| 78 |
if ($this->isDisabled()) |
|---|
| 79 |
{ |
|---|
| 80 |
return; |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
return <<<EOF |
|---|
| 84 |
|
|---|
| 85 |
const PEER = '{$this->getTable()->getPhpName()}Peer'; |
|---|
| 86 |
|
|---|
| 87 |
EOF; |
|---|
| 88 |
} |
|---|
| 89 |
|
|---|
| 90 |
public function staticAttributes() |
|---|
| 91 |
{ |
|---|
| 92 |
if ($this->isDisabled()) |
|---|
| 93 |
{ |
|---|
| 94 |
return; |
|---|
| 95 |
} |
|---|
| 96 |
|
|---|
| 97 |
$behaviors = $this->getTable()->getBehaviors(); |
|---|
| 98 |
$isI18n = isset($behaviors['symfony_i18n']) ? 'true' : 'false'; |
|---|
| 99 |
|
|---|
| 100 |
return <<<EOF |
|---|
| 101 |
|
|---|
| 102 |
/** |
|---|
| 103 |
* Indicates whether the current model includes I18N. |
|---|
| 104 |
*/ |
|---|
| 105 |
const IS_I18N = {$isI18n}; |
|---|
| 106 |
|
|---|
| 107 |
EOF; |
|---|
| 108 |
} |
|---|
| 109 |
|
|---|
| 110 |
public function staticMethods() |
|---|
| 111 |
{ |
|---|
| 112 |
if ($this->isDisabled()) |
|---|
| 113 |
{ |
|---|
| 114 |
return; |
|---|
| 115 |
} |
|---|
| 116 |
|
|---|
| 117 |
$unices = array(); |
|---|
| 118 |
foreach ($this->getTable()->getUnices() as $unique) |
|---|
| 119 |
{ |
|---|
| 120 |
$unices[] = sprintf("array('%s')", implode("', '", $unique->getColumns())); |
|---|
| 121 |
} |
|---|
| 122 |
$unices = implode(', ', array_unique($unices)); |
|---|
| 123 |
|
|---|
| 124 |
return <<<EOF |
|---|
| 125 |
|
|---|
| 126 |
/** |
|---|
| 127 |
* Returns an array of arrays that contain columns in each unique index. |
|---|
| 128 |
* |
|---|
| 129 |
* @return array |
|---|
| 130 |
*/ |
|---|
| 131 |
static public function getUniqueColumnNames() |
|---|
| 132 |
{ |
|---|
| 133 |
return array({$unices}); |
|---|
| 134 |
} |
|---|
| 135 |
|
|---|
| 136 |
EOF; |
|---|
| 137 |
} |
|---|
| 138 |
} |
|---|
| 139 |
|
|---|