Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
02efd7f7
Commit
02efd7f7
authored
Feb 08, 2007
by
joesimms
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring for tree implementation
parent
8eabed57
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
58 additions
and
34 deletions
+58
-34
Pessimistic.php
lib/Doctrine/Locking/Manager/Pessimistic.php
+3
-2
Node.php
lib/Doctrine/Node.php
+1
-1
NestedSet.php
lib/Doctrine/Node/NestedSet.php
+6
-4
PreOrderIterator.php
lib/Doctrine/Node/NestedSet/PreOrderIterator.php
+2
-2
Set.php
lib/Doctrine/Query/Set.php
+2
-1
Where.php
lib/Doctrine/Query/Where.php
+3
-2
Record.php
lib/Doctrine/Record.php
+25
-4
Table.php
lib/Doctrine/Table.php
+9
-13
NestedSet.php
lib/Doctrine/Tree/NestedSet.php
+7
-5
No files found.
lib/Doctrine/Locking/Manager/Pessimistic.php
View file @
02efd7f7
...
@@ -102,6 +102,7 @@ class Doctrine_Locking_Manager_Pessimistic
...
@@ -102,6 +102,7 @@ class Doctrine_Locking_Manager_Pessimistic
$key
=
$record
->
obtainIdentifier
();
$key
=
$record
->
obtainIdentifier
();
$gotLock
=
false
;
$gotLock
=
false
;
$time
=
time
();
if
(
is_array
(
$key
))
{
if
(
is_array
(
$key
))
{
// Composite key
// Composite key
...
@@ -118,7 +119,7 @@ class Doctrine_Locking_Manager_Pessimistic
...
@@ -118,7 +119,7 @@ class Doctrine_Locking_Manager_Pessimistic
$stmt
->
bindParam
(
':object_type'
,
$objectType
);
$stmt
->
bindParam
(
':object_type'
,
$objectType
);
$stmt
->
bindParam
(
':object_key'
,
$key
);
$stmt
->
bindParam
(
':object_key'
,
$key
);
$stmt
->
bindParam
(
':user_ident'
,
$userIdent
);
$stmt
->
bindParam
(
':user_ident'
,
$userIdent
);
$stmt
->
bindParam
(
':ts_obtained'
,
time
()
);
$stmt
->
bindParam
(
':ts_obtained'
,
$time
);
try
{
try
{
$stmt
->
execute
();
$stmt
->
execute
();
...
@@ -138,7 +139,7 @@ class Doctrine_Locking_Manager_Pessimistic
...
@@ -138,7 +139,7 @@ class Doctrine_Locking_Manager_Pessimistic
WHERE object_type = :object_type AND
WHERE object_type = :object_type AND
object_key = :object_key AND
object_key = :object_key AND
user_ident = :user_ident"
);
user_ident = :user_ident"
);
$stmt
->
bindParam
(
':ts'
,
time
()
);
$stmt
->
bindParam
(
':ts'
,
$time
);
$stmt
->
bindParam
(
':object_type'
,
$objectType
);
$stmt
->
bindParam
(
':object_type'
,
$objectType
);
$stmt
->
bindParam
(
':object_key'
,
$key
);
$stmt
->
bindParam
(
':object_key'
,
$key
);
$stmt
->
bindParam
(
':user_ident'
,
$lockingUserIdent
);
$stmt
->
bindParam
(
':user_ident'
,
$lockingUserIdent
);
...
...
lib/Doctrine/Node.php
View file @
02efd7f7
...
@@ -129,7 +129,7 @@ class Doctrine_Node implements IteratorAggregate
...
@@ -129,7 +129,7 @@ class Doctrine_Node implements IteratorAggregate
$options
=
(
isset
(
$this
->
iteratorOptions
)
?
$this
->
iteratorOptions
:
array
());
$options
=
(
isset
(
$this
->
iteratorOptions
)
?
$this
->
iteratorOptions
:
array
());
}
}
$implName
=
$this
->
record
->
getTable
()
->
get
TreeImplName
(
);
$implName
=
$this
->
record
->
getTable
()
->
get
Option
(
'treeImpl'
);
$iteratorClass
=
'Doctrine_Node_'
.
$implName
.
'_'
.
ucfirst
(
strtolower
(
$type
))
.
'OrderIterator'
;
$iteratorClass
=
'Doctrine_Node_'
.
$implName
.
'_'
.
ucfirst
(
strtolower
(
$type
))
.
'OrderIterator'
;
return
new
$iteratorClass
(
$this
->
record
,
$options
);
return
new
$iteratorClass
(
$this
->
record
,
$options
);
...
...
lib/Doctrine/Node/NestedSet.php
View file @
02efd7f7
...
@@ -187,8 +187,9 @@ class Doctrine_Node_NestedSet extends Doctrine_Node implements Doctrine_Node_Int
...
@@ -187,8 +187,9 @@ class Doctrine_Node_NestedSet extends Doctrine_Node implements Doctrine_Node_Int
{
{
$q
=
$this
->
record
->
getTable
()
->
createQuery
();
$q
=
$this
->
record
->
getTable
()
->
createQuery
();
$parent
=
$q
->
where
(
'lft < ? AND rgt > ?'
,
array
(
$this
->
getLeftValue
(),
$this
->
getRightValue
()))
$componentName
=
$this
->
record
->
getTable
()
->
getComponentName
();
->
orderBy
(
'rgt asc'
)
$parent
=
$q
->
where
(
"
$componentName
.lft < ? AND
$componentName
.rgt > ?"
,
array
(
$this
->
getLeftValue
(),
$this
->
getRightValue
()))
->
orderBy
(
"
$componentName
.rgt asc"
)
->
execute
()
->
execute
()
->
getFirst
();
->
getFirst
();
...
@@ -207,8 +208,9 @@ class Doctrine_Node_NestedSet extends Doctrine_Node implements Doctrine_Node_Int
...
@@ -207,8 +208,9 @@ class Doctrine_Node_NestedSet extends Doctrine_Node implements Doctrine_Node_Int
{
{
$q
=
$this
->
record
->
getTable
()
->
createQuery
();
$q
=
$this
->
record
->
getTable
()
->
createQuery
();
$ancestors
=
$q
->
where
(
'lft < ? AND rgt > ?'
,
array
(
$this
->
getLeftValue
(),
$this
->
getRightValue
()))
$componentName
=
$this
->
record
->
getTable
()
->
getComponentName
();
->
orderBy
(
'lft asc'
)
$ancestors
=
$q
->
where
(
"
$componentName
.lft < ? AND
$componentName
.rgt > ?"
,
array
(
$this
->
getLeftValue
(),
$this
->
getRightValue
()))
->
orderBy
(
"
$componentName
.lft asc"
)
->
execute
();
->
execute
();
return
$ancestors
;
return
$ancestors
;
...
...
lib/Doctrine/Node/NestedSet/PreOrderIterator.php
View file @
02efd7f7
...
@@ -68,9 +68,9 @@ class Doctrine_Node_NestedSet_PreOrderIterator implements Iterator
...
@@ -68,9 +68,9 @@ class Doctrine_Node_NestedSet_PreOrderIterator implements Iterator
$params
=
array
(
$record
->
get
(
'lft'
),
$record
->
get
(
'rgt'
));
$params
=
array
(
$record
->
get
(
'lft'
),
$record
->
get
(
'rgt'
));
if
(
isset
(
$opts
[
'include_record'
])
&&
$opts
[
'include_record'
])
{
if
(
isset
(
$opts
[
'include_record'
])
&&
$opts
[
'include_record'
])
{
$query
=
$q
->
where
(
"
$componentName
.lft >= ? AND
$componentName
.rgt <= ?"
,
$params
)
->
orderBy
(
'lft asc'
);
$query
=
$q
->
where
(
"
$componentName
.lft >= ? AND
$componentName
.rgt <= ?"
,
$params
)
->
orderBy
(
"
$componentName
.lft asc"
);
}
else
{
}
else
{
$query
=
$q
->
where
(
"
$componentName
.lft > ? AND
$componentName
.rgt < ?"
,
$params
)
->
orderBy
(
'lft asc'
);
$query
=
$q
->
where
(
"
$componentName
.lft > ? AND
$componentName
.rgt < ?"
,
$params
)
->
orderBy
(
"
$componentName
.lft asc"
);
}
}
$query
=
$record
->
getTable
()
->
getTree
()
->
returnQueryWithRootId
(
$query
,
$record
->
getNode
()
->
getRootValue
());
$query
=
$record
->
getTable
()
->
getTree
()
->
returnQueryWithRootId
(
$query
,
$record
->
getNode
()
->
getRootValue
());
...
...
lib/Doctrine/Query/Set.php
View file @
02efd7f7
...
@@ -47,7 +47,8 @@ class Doctrine_Query_Set extends Doctrine_Query_Part
...
@@ -47,7 +47,8 @@ class Doctrine_Query_Set extends Doctrine_Query_Part
$alias
=
$this
->
query
->
getTableAlias
(
$reference
);
$alias
=
$this
->
query
->
getTableAlias
(
$reference
);
$result
[]
=
$alias
.
'.'
.
$field
.
' = '
.
$set
[
1
];
$fieldname
=
$alias
?
$alias
.
'.'
.
$field
:
$field
;
$result
[]
=
$fieldname
.
' = '
.
$set
[
1
];
}
}
return
implode
(
', '
,
$result
);
return
implode
(
', '
,
$result
);
...
...
lib/Doctrine/Query/Where.php
View file @
02efd7f7
...
@@ -171,8 +171,9 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
...
@@ -171,8 +171,9 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition
$value
=
$enumIndex
;
$value
=
$enumIndex
;
}
}
default
:
default
:
$where
=
$alias
.
'.'
.
$field
.
' '
$fieldname
=
$alias
?
$alias
.
'.'
.
$field
:
$field
;
.
$operator
.
' '
.
$value
;
$where
=
$fieldname
.
' '
.
$operator
.
' '
.
$value
;
}
}
}
}
}
}
...
...
lib/Doctrine/Record.php
View file @
02efd7f7
...
@@ -78,6 +78,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -78,6 +78,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @var object Doctrine_Table $_table the factory that created this data access object
* @var object Doctrine_Table $_table the factory that created this data access object
*/
*/
protected
$_table
;
protected
$_table
;
/**
* @var Doctrine_Node_<TreeImpl> node object
*/
protected
$_node
;
/**
/**
* @var integer $_id the primary keys of this object
* @var integer $_id the primary keys of this object
*/
*/
...
@@ -1532,10 +1536,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -1532,10 +1536,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
public
function
hasIndex
(
$name
)
public
function
hasIndex
(
$name
)
{
{
}
public
function
actsAsTree
(
$treeImplName
,
$args
)
{
}
}
/**
/**
* addListener
* addListener
...
@@ -1591,6 +1591,27 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
...
@@ -1591,6 +1591,27 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
}
}
return
$this
;
return
$this
;
}
}
/**
* getter for node assciated with this record
*
* @return mixed if tree returns Doctrine_Node otherwise returns false
*/
public
function
getNode
()
{
if
(
!
$this
->
_table
->
isTree
())
return
false
;
if
(
!
isset
(
$this
->
_node
))
$this
->
_node
=
Doctrine_Node
::
factory
(
$this
,
$this
->
getTable
()
->
getOption
(
'treeImpl'
),
$this
->
getTable
()
->
getOption
(
'treeOptions'
));
return
$this
->
_node
;
}
/**
* used to delete node from tree - MUST BE USE TO DELETE RECORD IF TABLE ACTS AS TREE
*
*/
public
function
deleteNode
()
{
$this
->
getNode
()
->
delete
();
}
/**
/**
* returns a string representation of this object
* returns a string representation of this object
*/
*/
...
...
lib/Doctrine/Table.php
View file @
02efd7f7
...
@@ -206,6 +206,10 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
...
@@ -206,6 +206,10 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
if
(
method_exists
(
$record
,
'setTableDefinition'
))
{
if
(
method_exists
(
$record
,
'setTableDefinition'
))
{
$record
->
setTableDefinition
();
$record
->
setTableDefinition
();
// set the table definition for the given tree implementation
if
(
$this
->
isTree
())
$this
->
getTree
()
->
setTableDefinition
();
$this
->
columnCount
=
count
(
$this
->
columns
);
$this
->
columnCount
=
count
(
$this
->
columns
);
if
(
isset
(
$this
->
columns
))
{
if
(
isset
(
$this
->
columns
))
{
...
@@ -298,6 +302,10 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
...
@@ -298,6 +302,10 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$record
->
setUp
();
$record
->
setUp
();
// if tree, set up tree
if
(
$this
->
isTree
())
$this
->
getTree
()
->
setUp
();
// save parents
// save parents
array_pop
(
$names
);
array_pop
(
$names
);
$this
->
parents
=
$names
;
$this
->
parents
=
$names
;
...
@@ -1377,15 +1385,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
...
@@ -1377,15 +1385,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
{
{
return
$this
->
data
;
return
$this
->
data
;
}
}
/**
* returns a string representation of this object
*
* @return string
*/
public
function
setTree
(
$implName
,
$options
)
{
$this
->
setOption
(
'treeImpl'
,
$implName
);
$this
->
setOption
(
'treeOptions'
,
$options
);
}
/**
/**
* getter for associated tree
* getter for associated tree
*
*
...
@@ -1398,9 +1397,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
...
@@ -1398,9 +1397,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$this
->
options
[
'treeImpl'
],
$this
->
options
[
'treeImpl'
],
$this
->
options
[
'treeOptions'
]
$this
->
options
[
'treeOptions'
]
);
);
// set the table definition for the given tree implementation
$this
->
tree
->
setTableDefinition
();
}
}
return
$this
->
tree
;
return
$this
->
tree
;
}
}
...
@@ -1409,7 +1405,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
...
@@ -1409,7 +1405,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
/**
/**
* determine if table acts as tree
* determine if table acts as tree
*
*
* @return mixed if tree return
instance of Doctrine_Tre
e, otherwise returns false
* @return mixed if tree return
tru
e, otherwise returns false
*/
*/
public
function
isTree
()
{
public
function
isTree
()
{
return
(
!
is_null
(
$this
->
options
[
'treeImpl'
]))
?
true
:
false
;
return
(
!
is_null
(
$this
->
options
[
'treeImpl'
]))
?
true
:
false
;
...
...
lib/Doctrine/Tree/NestedSet.php
View file @
02efd7f7
...
@@ -40,8 +40,9 @@ class Doctrine_Tree_NestedSet extends Doctrine_Tree implements Doctrine_Tree_Int
...
@@ -40,8 +40,9 @@ class Doctrine_Tree_NestedSet extends Doctrine_Tree implements Doctrine_Tree_Int
public
function
__construct
(
Doctrine_Table
$table
,
$options
)
public
function
__construct
(
Doctrine_Table
$table
,
$options
)
{
{
// set default many root attributes
// set default many root attributes
$options
[
'has_many_roots'
]
=
isset
(
$options
[
'has_many_roots'
])
?
$options
[
'has_many_roots'
]
:
false
;
$options
[
'hasManyRoots'
]
=
isset
(
$options
[
'hasManyRoots'
])
?
$options
[
'hasManyRoots'
]
:
false
;
$options
[
'root_column_name'
]
=
isset
(
$options
[
'root_column_name'
])
?
$options
[
'root_column_name'
]
:
'root_id'
;
if
(
$options
[
'hasManyRoots'
])
$options
[
'rootColumnName'
]
=
isset
(
$options
[
'rootColumnName'
])
?
$options
[
'rootColumnName'
]
:
'root_id'
;
parent
::
__construct
(
$table
,
$options
);
parent
::
__construct
(
$table
,
$options
);
}
}
...
@@ -73,7 +74,7 @@ class Doctrine_Tree_NestedSet extends Doctrine_Tree implements Doctrine_Tree_Int
...
@@ -73,7 +74,7 @@ class Doctrine_Tree_NestedSet extends Doctrine_Tree implements Doctrine_Tree_Int
}
}
// if tree is many roots, then get next root id
// if tree is many roots, then get next root id
if
(
$root
=
$this
->
getAttribute
(
'
root_column_name
'
))
{
if
(
$root
=
$this
->
getAttribute
(
'
hasManyRoots
'
))
{
$record
->
getNode
()
->
setRootValue
(
$this
->
getNextRootId
());
$record
->
getNode
()
->
setRootValue
(
$this
->
getNextRootId
());
}
}
...
@@ -121,9 +122,10 @@ class Doctrine_Tree_NestedSet extends Doctrine_Tree implements Doctrine_Tree_Int
...
@@ -121,9 +122,10 @@ class Doctrine_Tree_NestedSet extends Doctrine_Tree implements Doctrine_Tree_Int
{
{
// fetch tree
// fetch tree
$q
=
$this
->
table
->
createQuery
();
$q
=
$this
->
table
->
createQuery
();
$componentName
=
$this
->
table
->
getComponentName
();
$q
=
$q
->
where
(
'lft >= ?'
,
1
)
$q
=
$q
->
where
(
"
$componentName
.lft >= ?"
,
1
)
->
orderBy
(
'lft asc'
);
->
orderBy
(
"
$componentName
.lft asc"
);
// if tree has many roots, then specify root id
// if tree has many roots, then specify root id
$rootId
=
isset
(
$options
[
'root_id'
])
?
$options
[
'root_id'
]
:
'1'
;
$rootId
=
isset
(
$options
[
'root_id'
])
?
$options
[
'root_id'
]
:
'1'
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment