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
484fb080
Commit
484fb080
authored
Jan 16, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
little refactorings
parent
4ff559ce
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
30 deletions
+33
-30
NestedSet.php
lib/Doctrine/Node/NestedSet.php
+25
-22
NestedSet.php
lib/Doctrine/Tree/NestedSet.php
+8
-8
No files found.
lib/Doctrine/Node/NestedSet.php
View file @
484fb080
...
...
@@ -281,7 +281,7 @@ class Doctrine_Node_NestedSet extends Doctrine_Node implements Doctrine_Node_Int
$this
->
shiftRLValues
(
$dest
->
getNode
()
->
getRightValue
()
+
2
,
1
);
$newLeft
=
$dest
->
getNode
()
->
getLeftValue
();
$newRight
=
$dest
->
getNode
()
->
getRightValue
()
+
2
;
$newRight
=
$dest
->
getNode
()
->
getRightValue
()
+
2
;
$newRoot
=
$dest
->
getNode
()
->
getRootValue
();
$this
->
insertNode
(
$newLeft
,
$newRight
,
$newRoot
);
...
...
@@ -437,7 +437,7 @@ class Doctrine_Node_NestedSet extends Doctrine_Node implements Doctrine_Node_Int
*/
public
function
isLeaf
()
{
return
((
$this
->
getRightValue
()
-
$this
->
getLeftValue
())
==
1
);
return
((
$this
->
getRightValue
()
-
$this
->
getLeftValue
())
==
1
);
}
/**
...
...
@@ -447,7 +447,7 @@ class Doctrine_Node_NestedSet extends Doctrine_Node implements Doctrine_Node_Int
*/
public
function
isRoot
()
{
return
(
$this
->
getLeftValue
()
==
1
);
return
(
$this
->
getLeftValue
()
==
1
);
}
/**
...
...
@@ -457,17 +457,20 @@ class Doctrine_Node_NestedSet extends Doctrine_Node implements Doctrine_Node_Int
*/
public
function
isEqualTo
(
Doctrine_Record
$subj
)
{
return
((
$this
->
getLeftValue
()
==
$subj
->
getNode
()
->
getLeftValue
())
and
(
$this
->
getRightValue
()
==
$subj
->
getNode
()
->
getRightValue
())
and
(
$this
->
getRootValue
()
==
$subj
->
getNode
()
->
getRootValue
()));
return
((
$this
->
getLeftValue
()
==
$subj
->
getNode
()
->
getLeftValue
())
&&
(
$this
->
getRightValue
()
==
$subj
->
getNode
()
->
getRightValue
())
&&
(
$this
->
getRootValue
()
==
$subj
->
getNode
()
->
getRootValue
())
);
}
/**
* determines if node is child of subject node
*
* @return bool
* @return bool
*/
public
function
isDescendantOf
(
Doctrine_Record
$subj
)
{
return
((
$this
->
getLeftValue
()
>
$subj
->
getNode
()
->
getLeftValue
())
and
(
$this
->
getRightValue
()
<
$subj
->
getNode
()
->
getRightValue
())
and
(
$this
->
getRootValue
()
==
$subj
->
getNode
()
->
getRootValue
()));
return
((
$this
->
getLeftValue
()
>
$subj
->
getNode
()
->
getLeftValue
())
&&
(
$this
->
getRightValue
()
<
$subj
->
getNode
()
->
getRightValue
())
&&
(
$this
->
getRootValue
()
==
$subj
->
getNode
()
->
getRootValue
()));
}
/**
...
...
@@ -477,7 +480,7 @@ class Doctrine_Node_NestedSet extends Doctrine_Node implements Doctrine_Node_Int
*/
public
function
isDescendantOfOrEqualTo
(
Doctrine_Record
$subj
)
{
return
((
$this
->
getLeftValue
()
>=
$subj
->
getNode
()
->
getLeftValue
())
and
(
$this
->
getRightValue
()
<=
$subj
->
getNode
()
->
getRightValue
())
and
(
$this
->
getRootValue
()
==
$subj
->
getNode
()
->
getRootValue
()));
return
((
$this
->
getLeftValue
()
>=
$subj
->
getNode
()
->
getLeftValue
())
&&
(
$this
->
getRightValue
()
<=
$subj
->
getNode
()
->
getRightValue
())
&&
(
$this
->
getRootValue
()
==
$subj
->
getNode
()
->
getRootValue
()));
}
/**
...
...
@@ -502,7 +505,7 @@ class Doctrine_Node_NestedSet extends Doctrine_Node implements Doctrine_Node_Int
$componentName
=
$this
->
record
->
getTable
()
->
getComponentName
();
$q
=
$q
->
where
(
"
$componentName
.lft >= ? AND
$componentName
.rgt <= ?"
,
array
(
$this
->
getLeftValue
(),
$this
->
getRightValue
()));
$q
=
$q
->
where
(
$componentName
.
'.lft >= ? AND '
.
$componentName
.
'.rgt <= ?'
,
array
(
$this
->
getLeftValue
(),
$this
->
getRightValue
()));
$q
=
$this
->
record
->
getTable
()
->
getTree
()
->
returnQueryWithRootId
(
$q
,
$this
->
getRootValue
());
...
...
@@ -566,28 +569,28 @@ class Doctrine_Node_NestedSet extends Doctrine_Node implements Doctrine_Node_Int
* @param int $first First node to be shifted
* @param int $delta Value to be shifted by, can be negative
*/
private
function
shiftR
LValues
(
$first
,
$delta
,
$root_i
d
=
1
)
private
function
shiftR
lValues
(
$first
,
$delta
,
$rootI
d
=
1
)
{
$qLeft
=
$this
->
record
->
getTable
()
->
create
Query
();
$qRight
=
$this
->
record
->
getTable
()
->
create
Query
();
$qLeft
=
new
Doctrine_
Query
();
$qRight
=
new
Doctrine_
Query
();
// TODO: Wrap in transaction
// shift left columns
$qLeft
=
$qLeft
->
update
(
$this
->
record
->
getTable
()
->
getComponentName
())
->
set
(
'lft'
,
"lft +
$delta
"
)
->
set
(
'lft'
,
'lft + '
.
$delta
)
->
where
(
'lft >= ?'
,
$first
);
$qLeft
=
$this
->
record
->
getTable
()
->
getTree
()
->
returnQueryWithRootId
(
$qLeft
,
$root
_i
d
);
$qLeft
=
$this
->
record
->
getTable
()
->
getTree
()
->
returnQueryWithRootId
(
$qLeft
,
$root
I
d
);
$resultLeft
=
$qLeft
->
execute
();
// shift right columns
$resultRight
=
$qRight
->
update
(
$this
->
record
->
getTable
()
->
getComponentName
())
->
set
(
'rgt'
,
"rgt +
$delta
"
)
->
set
(
'rgt'
,
'rgt + '
.
$delta
)
->
where
(
'rgt >= ?'
,
$first
);
$qRight
=
$this
->
record
->
getTable
()
->
getTree
()
->
returnQueryWithRootId
(
$qRight
,
$root
_i
d
);
$qRight
=
$this
->
record
->
getTable
()
->
getTree
()
->
returnQueryWithRootId
(
$qRight
,
$root
I
d
);
$resultRight
=
$qRight
->
execute
();
}
...
...
@@ -600,28 +603,28 @@ class Doctrine_Node_NestedSet extends Doctrine_Node implements Doctrine_Node_Int
* @param int $last Last node to be shifted (L value)
* @param int $delta Value to be shifted by, can be negative
*/
private
function
shiftR
LRange
(
$first
,
$last
,
$delta
,
$root_i
d
=
1
)
private
function
shiftR
lRange
(
$first
,
$last
,
$delta
,
$rootI
d
=
1
)
{
$qLeft
=
$this
->
record
->
getTable
()
->
create
Query
();
$qRight
=
$this
->
record
->
getTable
()
->
create
Query
();
$qLeft
=
new
Doctrine_
Query
();
$qRight
=
new
Doctrine_
Query
();
// TODO : Wrap in transaction
// shift left column values
$qLeft
=
$qLeft
->
update
(
$this
->
record
->
getTable
()
->
getComponentName
())
->
set
(
'lft'
,
"lft +
$delta
"
)
->
set
(
'lft'
,
'lft + '
.
$delta
)
->
where
(
'lft >= ? AND lft <= ?'
,
array
(
$first
,
$last
));
$qLeft
=
$this
->
record
->
getTable
()
->
getTree
()
->
returnQueryWithRootId
(
$qLeft
,
$root
_i
d
);
$qLeft
=
$this
->
record
->
getTable
()
->
getTree
()
->
returnQueryWithRootId
(
$qLeft
,
$root
I
d
);
$resultLeft
=
$qLeft
->
execute
();
// shift right column values
$qRight
=
$qRight
->
update
(
$this
->
record
->
getTable
()
->
getComponentName
())
->
set
(
'rgt'
,
"rgt +
$delta
"
)
->
set
(
'rgt'
,
'rgt + '
.
$delta
)
->
where
(
'rgt >= ? AND rgt <= ?'
,
array
(
$first
,
$last
));
$qRight
=
$this
->
record
->
getTable
()
->
getTree
()
->
returnQueryWithRootId
(
$qRight
,
$root
_i
d
);
$qRight
=
$this
->
record
->
getTable
()
->
getTree
()
->
returnQueryWithRootId
(
$qRight
,
$root
I
d
);
$resultRight
=
$qRight
->
execute
();
}
...
...
lib/Doctrine/Tree/NestedSet.php
View file @
484fb080
...
...
@@ -53,12 +53,12 @@ class Doctrine_Tree_NestedSet extends Doctrine_Tree implements Doctrine_Tree_Int
*/
public
function
setTableDefinition
()
{
if
(
$
this
->
getAttribute
(
'has_many_roots
'
))
{
$this
->
table
->
setColumn
(
$
this
->
getAttribute
(
'root_column_name'
),
"integer"
,
11
);
if
(
$
root
=
$this
->
getAttribute
(
'root_column_name
'
))
{
$this
->
table
->
setColumn
(
$
root
,
'integer'
,
11
);
}
$this
->
table
->
setColumn
(
"lft"
,
"integer"
,
11
);
$this
->
table
->
setColumn
(
"rgt"
,
"integer"
,
11
);
$this
->
table
->
setColumn
(
'lft'
,
'integer'
,
11
);
$this
->
table
->
setColumn
(
'rgt'
,
'integer'
,
11
);
}
/**
...
...
@@ -73,7 +73,7 @@ class Doctrine_Tree_NestedSet extends Doctrine_Tree implements Doctrine_Tree_Int
}
// if tree is many roots, then get next root id
if
(
$this
->
getAttribute
(
'has_many_roots
'
))
{
if
(
$root
=
$this
->
getAttribute
(
'root_column_name
'
))
{
$record
->
getNode
()
->
setRootValue
(
$this
->
getNextRootId
());
}
...
...
@@ -207,7 +207,7 @@ class Doctrine_Tree_NestedSet extends Doctrine_Tree implements Doctrine_Tree_Int
public
function
getMaxRootId
()
{
$component
=
$this
->
table
->
getComponentName
();
$column
=
$this
->
getAttribute
(
'root_column_name'
);
$column
=
$this
->
getAttribute
(
'root_column_name'
);
// cannot get this dql to work, cannot retrieve result using $coll[0]->max
//$dql = "SELECT MAX(c.$column) FROM $component c";
...
...
@@ -232,8 +232,8 @@ class Doctrine_Tree_NestedSet extends Doctrine_Tree implements Doctrine_Tree_Int
*/
public
function
returnQueryWithRootId
(
$query
,
$rootId
=
1
)
{
if
(
$this
->
getAttribute
(
'has_many_roots
'
))
{
$query
->
addWhere
(
$
this
->
getAttribute
(
'root_column_name'
)
.
' = ?'
,
$rootId
);
if
(
$root
=
$this
->
getAttribute
(
'root_column_name
'
))
{
$query
->
addWhere
(
$
root
.
' = ?'
,
$rootId
);
}
return
$query
;
...
...
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