Commit a9e5a359 authored by zYne's avatar zYne

plugin refactoring continues

parent a73ce3a4
......@@ -98,7 +98,65 @@ class Doctrine_Plugin
{
return $this->_options;
}
/**
* generates foreign keys for the plugin table based on the owner table
*
* the foreign keys generated by this method can be used for
* setting the relations between the owner and the plugin classes
*
* @param Doctrine_Table $table the table object that owns the plugin
* @return array an array of foreign key definitions
*/
public function generateForeignKeys(Doctrine_Table $table)
{
$fk = array();
foreach ((array) $table->getIdentifier() as $column) {
$def = $table->getDefinitionOf($column);
unset($def['autoincrement']);
unset($def['sequence']);
unset($def['primary']);
$col = strtolower(Doctrine::tableize($table->getComponentName()) . '_' . $column);
$def['primary'] = true;
$fk[$col] = $def;
}
return $fk;
}
/**
* generates a relation array to given table
*
* this method can be used for generating the relation from the plugin
* table to the owner table
*
* @param Doctrine_Table $table the table object to construct the relation to
* @param array $foreignKeys an array of foreign keys
* @return array the generated relation array
*/
public function generateRelation(Doctrine_Table $table, array $foreignKeys)
{
$local = (count($foreignKeys) > 1) ? array_keys($foreignKeys) : key($foreignKeys);
$relation = array($table->getComponentName() =>
array('local' => $local,
'foreign' => $table->getIdentifier(),
'onDelete' => 'CASCADE',
'onUpdate' => 'CASCADE'));
return $relation;
}
/**
* generates the class definition for plugin class
*
* @param array $options plugin class options, keys representing the option names
* and values as option values
* @param array $columns the plugin class columns, keys representing the column names
* and values as column definitions
* @param array $relations the bound relations of the plugin class
* @return void
*/
public function generateClass($options, $columns, $relations)
{
$builder = new Doctrine_Import_Builder();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment