Commit 8dc99daa authored by zYne's avatar zYne

Refactored many classes

parent 26624104
......@@ -373,7 +373,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$query = "SELECT ".$fields." FROM ".$this->table->getTableName();
// apply column aggregation inheritance
foreach ($this->table->getInheritanceMap() as $k => $v) {
$map = $this->table->inheritanceMap;
foreach ($map as $k => $v) {
$where[] = $k." = ?";
$params[] = $v;
}
......
......@@ -314,7 +314,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
$table = $record->getTable();
$keys = $table->getPrimaryKeys();
$seq = $record->getTable()->getSequenceName();
$seq = $record->getTable()->sequenceName;
if ( ! empty($seq)) {
$id = $this->conn->sequence->nextId($seq);
......@@ -329,7 +329,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
if (empty($seq) && count($keys) == 1 && $keys[0] == $table->getIdentifier()) {
if (strtolower($this->conn->getName()) == 'pgsql') {
$seq = $table->getTableName() . '_' . $keys[0];
$seq = $table->getTableName() . '_' . $keys[0];
}
$id = $this->conn->sequence->lastInsertId($seq);
......
......@@ -269,7 +269,7 @@ class Doctrine_Expression extends Doctrine_Connection_Module
*
* @param string|array(string) strings that will be concatinated.
*/
public function concat(array $args)
public function concat($args)
{
$cols = $this->getIdentifiers($args);
return 'CONCAT(' . join(', ', $cols) . ')';
......
......@@ -632,8 +632,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access
$array = array();
foreach ($this->tables as $alias => $table) {
$array[$alias][] = $table->getInheritanceMap();
};
$array[$alias][] = $table->inheritanceMap;
}
// apply inheritance maps
$str = "";
......
......@@ -1346,17 +1346,20 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
$this->needsSubquery = true;
}
if( ! $loadFields || $fk->getTable()->usesInheritanceMap() || $joinCondition) {
$map = $fk->getTable()->inheritanceMap;
if( ! $loadFields || ! empty($map) || $joinCondition) {
$this->subqueryAliases[] = $tname2;
}
if($fk instanceof Doctrine_Relation_Association) {
if ($fk instanceof Doctrine_Relation_Association) {
$asf = $fk->getAssociationFactory();
$assocTableName = $asf->getTableName();
if( ! $loadFields || $fk->getTable()->usesInheritanceMap() || $joinCondition) {
if( ! $loadFields || ! empty($map) || $joinCondition) {
$this->subqueryAliases[] = $assocTableName;
}
......@@ -1368,15 +1371,25 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
$assocAlias = $this->aliasHandler->generateShortAlias($assocTableName);
}
$this->parts['join'][$tname][$assocTableName] = $join . $assocTableName . ' ' . $assocAlias .' ON ' . $tname . '.'
$this->parts['join'][$tname][$assocTableName] = $join . $assocTableName . ' ' . $assocAlias . ' ON ' . $tname . '.'
. $table->getIdentifier() . ' = '
. $assocAlias . '.' . $fk->getLocal();
if ($fk instanceof Doctrine_Relation_Association_Self) {
$this->parts['join'][$tname][$assocTableName] .= ' OR ' . $tname . '.' . $table->getIdentifier() . ' = '
. $assocAlias . '.' . $fk->getForeign();
}
$this->parts['join'][$tname][$tname2] = $join . $aliasString . ' ON ' . $tname2 . '.'
. $fk->getTable()->getIdentifier() . ' = '
. $assocAlias . '.' . $fk->getForeign()
. $joinCondition;
if ($fk instanceof Doctrine_Relation_Association_Self) {
$this->parts['join'][$tname][$tname2] .= ' OR ' . $tname2 . '.' . $table->getIdentifier() . ' = '
. $assocAlias . '.' . $fk->getLocal();
}
} else {
$this->parts['join'][$tname][$tname2] = $join . $aliasString
. ' ON ' . $tname . '.'
......
......@@ -1068,7 +1068,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
}
}
foreach ($this->_table->getInheritanceMap() as $k => $v) {
foreach ($this->_table->inheritanceMap as $k => $v) {
$old = $this->get($k, false);
if ((string) $old !== (string) $v || $old === null) {
......@@ -1477,7 +1477,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
}
public function setTableName($tableName)
{
$this->_table->setTableName($tableName);
$this->_table->tableName = $tableName;
}
public function setInheritanceMap($map)
{
......
......@@ -51,10 +51,10 @@ class Doctrine_Relation_Association_Self extends Doctrine_Relation_Association
' WHERE '.$this->foreign.
' = ?';
$dql = 'FROM '.$this->table->getComponentName();
$dql .= '.'.$this->associationTable->getComponentName();
$dql .= ' WHERE '.$this->table->getComponentName().'.'.$this->table->getIdentifier().' IN ('.$sub.')';
$dql .= ' || '.$this->table->getComponentName().'.'.$this->table->getIdentifier().' IN ('.$sub2.')';
$dql = 'FROM ' . $this->table->getComponentName();
$dql .= '.' . $this->associationTable->getComponentName();
$dql .= ' WHERE ' . $this->table->getComponentName() . '.' . $this->table->getIdentifier() . ' IN (' . $sub . ')';
$dql .= ' || ' . $this->table->getComponentName() . '.' . $this->table->getIdentifier() . ' IN (' . $sub2 . ')';
break;
case 'collection':
$sub = substr(str_repeat('?, ', $count),0,-2);
......
......@@ -109,10 +109,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
* determining its state
*/
private $columnCount;
/**
* @var array $parents the parent classes of this component
*/
private $parents = array();
/**
* @var boolean $hasDefaultValues whether or not this table has default values
*/
......@@ -122,6 +118,8 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
*
* -- name name of the component, for example component name of the GroupTable is 'Group'
*
* -- parents the parent classes of this component
*
* -- declaringClass name of the table definition declaring class (when using inheritance the class
* that defines the table structure can be any class in the inheritance hierarchy,
* hence we need reflection to check out which class actually calls setTableDefinition)
......@@ -308,7 +306,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
// save parents
array_pop($names);
$this->parents = $names;
$this->options['parents'] = $names;
$this->query = 'SELECT ' . implode(', ', array_keys($this->columns)) . ' FROM ' . $this->getTableName();
......@@ -392,6 +390,28 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
throw $e;
}
}
/**
* __get
* an alias for getOption
*
* @param string $option
*/
public function __get($option)
{
if (isset($this->options[$option])) {
return $this->options[$option];
}
return null;
}
/**
* __isset
*
* @param string $option
*/
public function __isset($option)
{
return isset($this->options[$option]);
}
/**
* createQuery
* creates a new Doctrine_Query object and adds the component name
......@@ -430,11 +450,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
}
$this->options[$name] = $value;
}
public function usesInheritanceMap()
{
return ( ! empty($this->options['inheritanceMap']));
}
public function getOption($name)
{
if (isset($this->options[$name])) {
......@@ -592,72 +607,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
{
return in_array($key,$this->primaryKeys);
}
/**
* @param $sequence
* @return void
*/
final public function setSequenceName($sequence)
{
$this->options['sequenceName'] = $sequence;
}
/**
* @return string sequence name
*/
final public function getSequenceName()
{
return $this->options['sequenceName'];
}
/**
* getParents
*/
final public function getParents()
{
return $this->parents;
}
/**
* @return boolean
*/
final public function hasInheritanceMap()
{
return (empty($this->options['inheritanceMap']));
}
/**
* @return array inheritance map (array keys as fields)
*/
final public function getInheritanceMap()
{
return $this->options['inheritanceMap'];
}
/**
* return all composite paths in the form [component1].[component2]. . .[componentN]
* @return array
*/
final public function getCompositePaths()
{
$array = array();
$name = $this->getComponentName();
foreach ($this->bound as $k=>$a) {
try {
$fk = $this->getRelation($k);
switch ($fk->getType()) {
case Doctrine_Relation::ONE_COMPOSITE:
case Doctrine_Relation::MANY_COMPOSITE:
$n = $fk->getTable()->getComponentName();
$array[] = $name.".".$n;
$e = $fk->getTable()->getCompositePaths();
if ( ! empty($e)) {
foreach ($e as $name) {
$array[] = $name.".".$n.".".$name;
}
}
break;
};
} catch(Doctrine_Table_Exception $e) {
}
}
return $array;
}
/**
* returns all bound relations
*
......@@ -788,14 +737,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$this->bound[$alias] = array($field, $type, $localKey, $name);
}
/**
* getComponentName
* @return string the component name
*/
public function getComponentName()
{
return $this->options['name'];
}
/**
* @return Doctrine_Connection
*/
......@@ -960,26 +901,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
return $this->relations;
}
/**
* sets the database table name
*
* @param string $name database table name
* @return void
*/
final public function setTableName($name)
{
$this->options['tableName'] = $name;
}
/**
* returns the database table name
*
* @return string
*/
final public function getTableName()
{
return $this->options['tableName'];
}
/**
* create
* creates a new record
......@@ -1182,17 +1103,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
}
return $coll;
}
/**
* sets enumerated value array for given field
*
* @param string $field
* @param array $values
* @return void
*/
final public function setEnumValues($field, array $values)
{
$this->options['enumMap'][strtolower($field)] = $values;
}
/**
* @param string $field
* @return array
......@@ -1403,6 +1313,14 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
}
return false;
}
public function getComponentName()
{
return $this->options['name'];
}
public function getTableName()
{
return $this->options['tableName'];
}
/**
* determine if table acts as tree
*
......
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