Refactored many classes
This commit is contained in:
parent
2662410495
commit
8dc99daa9f
@ -373,7 +373,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
|||||||
$query = "SELECT ".$fields." FROM ".$this->table->getTableName();
|
$query = "SELECT ".$fields." FROM ".$this->table->getTableName();
|
||||||
|
|
||||||
// apply column aggregation inheritance
|
// apply column aggregation inheritance
|
||||||
foreach ($this->table->getInheritanceMap() as $k => $v) {
|
$map = $this->table->inheritanceMap;
|
||||||
|
foreach ($map as $k => $v) {
|
||||||
$where[] = $k." = ?";
|
$where[] = $k." = ?";
|
||||||
$params[] = $v;
|
$params[] = $v;
|
||||||
}
|
}
|
||||||
|
@ -314,7 +314,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
|
|||||||
$table = $record->getTable();
|
$table = $record->getTable();
|
||||||
$keys = $table->getPrimaryKeys();
|
$keys = $table->getPrimaryKeys();
|
||||||
|
|
||||||
$seq = $record->getTable()->getSequenceName();
|
$seq = $record->getTable()->sequenceName;
|
||||||
|
|
||||||
if ( ! empty($seq)) {
|
if ( ! empty($seq)) {
|
||||||
$id = $this->conn->sequence->nextId($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 (empty($seq) && count($keys) == 1 && $keys[0] == $table->getIdentifier()) {
|
||||||
|
|
||||||
if (strtolower($this->conn->getName()) == 'pgsql') {
|
if (strtolower($this->conn->getName()) == 'pgsql') {
|
||||||
$seq = $table->getTableName() . '_' . $keys[0];
|
$seq = $table->getTableName() . '_' . $keys[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
$id = $this->conn->sequence->lastInsertId($seq);
|
$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.
|
* @param string|array(string) strings that will be concatinated.
|
||||||
*/
|
*/
|
||||||
public function concat(array $args)
|
public function concat($args)
|
||||||
{
|
{
|
||||||
$cols = $this->getIdentifiers($args);
|
$cols = $this->getIdentifiers($args);
|
||||||
return 'CONCAT(' . join(', ', $cols) . ')';
|
return 'CONCAT(' . join(', ', $cols) . ')';
|
||||||
|
@ -632,8 +632,8 @@ abstract class Doctrine_Hydrate extends Doctrine_Access
|
|||||||
$array = array();
|
$array = array();
|
||||||
|
|
||||||
foreach ($this->tables as $alias => $table) {
|
foreach ($this->tables as $alias => $table) {
|
||||||
$array[$alias][] = $table->getInheritanceMap();
|
$array[$alias][] = $table->inheritanceMap;
|
||||||
};
|
}
|
||||||
|
|
||||||
// apply inheritance maps
|
// apply inheritance maps
|
||||||
$str = "";
|
$str = "";
|
||||||
|
@ -1346,17 +1346,20 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
|
|||||||
$this->needsSubquery = true;
|
$this->needsSubquery = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ! $loadFields || $fk->getTable()->usesInheritanceMap() || $joinCondition) {
|
|
||||||
|
$map = $fk->getTable()->inheritanceMap;
|
||||||
|
|
||||||
|
if( ! $loadFields || ! empty($map) || $joinCondition) {
|
||||||
$this->subqueryAliases[] = $tname2;
|
$this->subqueryAliases[] = $tname2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if($fk instanceof Doctrine_Relation_Association) {
|
if ($fk instanceof Doctrine_Relation_Association) {
|
||||||
$asf = $fk->getAssociationFactory();
|
$asf = $fk->getAssociationFactory();
|
||||||
|
|
||||||
$assocTableName = $asf->getTableName();
|
$assocTableName = $asf->getTableName();
|
||||||
|
|
||||||
if( ! $loadFields || $fk->getTable()->usesInheritanceMap() || $joinCondition) {
|
if( ! $loadFields || ! empty($map) || $joinCondition) {
|
||||||
$this->subqueryAliases[] = $assocTableName;
|
$this->subqueryAliases[] = $assocTableName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1368,15 +1371,25 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
|
|||||||
$assocAlias = $this->aliasHandler->generateShortAlias($assocTableName);
|
$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() . ' = '
|
. $table->getIdentifier() . ' = '
|
||||||
. $assocAlias . '.' . $fk->getLocal();
|
. $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 . '.'
|
$this->parts['join'][$tname][$tname2] = $join . $aliasString . ' ON ' . $tname2 . '.'
|
||||||
. $fk->getTable()->getIdentifier() . ' = '
|
. $fk->getTable()->getIdentifier() . ' = '
|
||||||
. $assocAlias . '.' . $fk->getForeign()
|
. $assocAlias . '.' . $fk->getForeign()
|
||||||
. $joinCondition;
|
. $joinCondition;
|
||||||
|
|
||||||
|
if ($fk instanceof Doctrine_Relation_Association_Self) {
|
||||||
|
$this->parts['join'][$tname][$tname2] .= ' OR ' . $tname2 . '.' . $table->getIdentifier() . ' = '
|
||||||
|
. $assocAlias . '.' . $fk->getLocal();
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$this->parts['join'][$tname][$tname2] = $join . $aliasString
|
$this->parts['join'][$tname][$tname2] = $join . $aliasString
|
||||||
. ' ON ' . $tname . '.'
|
. ' 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);
|
$old = $this->get($k, false);
|
||||||
|
|
||||||
if ((string) $old !== (string) $v || $old === null) {
|
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)
|
public function setTableName($tableName)
|
||||||
{
|
{
|
||||||
$this->_table->setTableName($tableName);
|
$this->_table->tableName = $tableName;
|
||||||
}
|
}
|
||||||
public function setInheritanceMap($map)
|
public function setInheritanceMap($map)
|
||||||
{
|
{
|
||||||
|
@ -51,10 +51,10 @@ class Doctrine_Relation_Association_Self extends Doctrine_Relation_Association
|
|||||||
' WHERE '.$this->foreign.
|
' WHERE '.$this->foreign.
|
||||||
' = ?';
|
' = ?';
|
||||||
|
|
||||||
$dql = 'FROM '.$this->table->getComponentName();
|
$dql = 'FROM ' . $this->table->getComponentName();
|
||||||
$dql .= '.'.$this->associationTable->getComponentName();
|
$dql .= '.' . $this->associationTable->getComponentName();
|
||||||
$dql .= ' WHERE '.$this->table->getComponentName().'.'.$this->table->getIdentifier().' IN ('.$sub.')';
|
$dql .= ' WHERE ' . $this->table->getComponentName() . '.' . $this->table->getIdentifier() . ' IN (' . $sub . ')';
|
||||||
$dql .= ' || '.$this->table->getComponentName().'.'.$this->table->getIdentifier().' IN ('.$sub2.')';
|
$dql .= ' || ' . $this->table->getComponentName() . '.' . $this->table->getIdentifier() . ' IN (' . $sub2 . ')';
|
||||||
break;
|
break;
|
||||||
case 'collection':
|
case 'collection':
|
||||||
$sub = substr(str_repeat('?, ', $count),0,-2);
|
$sub = substr(str_repeat('?, ', $count),0,-2);
|
||||||
|
@ -109,10 +109,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
* determining its state
|
* determining its state
|
||||||
*/
|
*/
|
||||||
private $columnCount;
|
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
|
* @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'
|
* -- 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
|
* -- 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,
|
* 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)
|
* 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
|
// save parents
|
||||||
array_pop($names);
|
array_pop($names);
|
||||||
$this->parents = $names;
|
$this->options['parents'] = $names;
|
||||||
|
|
||||||
$this->query = 'SELECT ' . implode(', ', array_keys($this->columns)) . ' FROM ' . $this->getTableName();
|
$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;
|
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
|
* createQuery
|
||||||
* creates a new Doctrine_Query object and adds the component name
|
* 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;
|
$this->options[$name] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function usesInheritanceMap()
|
|
||||||
{
|
|
||||||
return ( ! empty($this->options['inheritanceMap']));
|
|
||||||
}
|
|
||||||
public function getOption($name)
|
public function getOption($name)
|
||||||
{
|
{
|
||||||
if (isset($this->options[$name])) {
|
if (isset($this->options[$name])) {
|
||||||
@ -592,72 +607,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
{
|
{
|
||||||
return in_array($key,$this->primaryKeys);
|
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
|
* returns all bound relations
|
||||||
*
|
*
|
||||||
@ -788,14 +737,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
|
|
||||||
$this->bound[$alias] = array($field, $type, $localKey, $name);
|
$this->bound[$alias] = array($field, $type, $localKey, $name);
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* getComponentName
|
|
||||||
* @return string the component name
|
|
||||||
*/
|
|
||||||
public function getComponentName()
|
|
||||||
{
|
|
||||||
return $this->options['name'];
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* @return Doctrine_Connection
|
* @return Doctrine_Connection
|
||||||
*/
|
*/
|
||||||
@ -960,26 +901,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
|
|
||||||
return $this->relations;
|
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
|
* create
|
||||||
* creates a new record
|
* creates a new record
|
||||||
@ -1182,17 +1103,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
}
|
}
|
||||||
return $coll;
|
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
|
* @param string $field
|
||||||
* @return array
|
* @return array
|
||||||
@ -1403,6 +1313,14 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
public function getComponentName()
|
||||||
|
{
|
||||||
|
return $this->options['name'];
|
||||||
|
}
|
||||||
|
public function getTableName()
|
||||||
|
{
|
||||||
|
return $this->options['tableName'];
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* determine if table acts as tree
|
* determine if table acts as tree
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user