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
50c98904
Commit
50c98904
authored
Jan 12, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
made nestedset adhere to ZF coding standards
parent
9df0b72c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
31 deletions
+34
-31
NestedSet.php
draft/Tree/NestedSet.php
+34
-31
No files found.
draft/Tree/NestedSet.php
View file @
50c98904
...
...
@@ -39,11 +39,11 @@ class Doctrine_Tree_NestedSet extends Doctrine_Tree implements Doctrine_Tree_Int
*/
public
function
__construct
(
Doctrine_Table
$table
,
$options
)
{
// set default many root attributes
$options
[
'has_many_roots'
]
=
isset
(
$options
[
'has_many_roots'
])
?
$options
[
'has_many_roots'
]
:
false
;
$options
[
'root_column_name'
]
=
isset
(
$options
[
'root_column_name'
])
?
$options
[
'root_column_name'
]
:
'root_id'
;
parent
::
__construct
(
$table
,
$options
);
// set default many root attributes
$options
[
'has_many_roots'
]
=
isset
(
$options
[
'has_many_roots'
])
?
$options
[
'has_many_roots'
]
:
false
;
$options
[
'root_column_name'
]
=
isset
(
$options
[
'root_column_name'
])
?
$options
[
'root_column_name'
]
:
'root_id'
;
parent
::
__construct
(
$table
,
$options
);
}
/**
...
...
@@ -53,8 +53,9 @@ 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
(
$this
->
getAttribute
(
'has_many_roots'
))
{
$this
->
table
->
setColumn
(
$this
->
getAttribute
(
'root_column_name'
),
"integer"
,
11
);
}
$this
->
table
->
setColumn
(
"lft"
,
"integer"
,
11
);
$this
->
table
->
setColumn
(
"rgt"
,
"integer"
,
11
);
...
...
@@ -67,13 +68,14 @@ class Doctrine_Tree_NestedSet extends Doctrine_Tree implements Doctrine_Tree_Int
*/
public
function
createRoot
(
Doctrine_Record
$record
=
null
)
{
if
(
!
$record
)
{
if
(
!
$record
)
{
$record
=
$this
->
table
->
create
();
}
// if tree is many roots, then get next root id
if
(
$this
->
getAttribute
(
'has_many_roots'
))
$record
->
getNode
()
->
setRootValue
(
$this
->
getNextRootId
());
if
(
$this
->
getAttribute
(
'has_many_roots'
))
{
$record
->
getNode
()
->
setRootValue
(
$this
->
getNextRootId
());
}
$record
->
set
(
'lft'
,
'1'
);
$record
->
set
(
'rgt'
,
'2'
);
...
...
@@ -99,7 +101,7 @@ class Doctrine_Tree_NestedSet extends Doctrine_Tree implements Doctrine_Tree_Int
$root
=
$q
->
execute
()
->
getFirst
();
// if no record is returned, create record
if
(
!
$root
)
{
if
(
!
$root
)
{
$root
=
$this
->
table
->
create
();
}
...
...
@@ -132,7 +134,7 @@ class Doctrine_Tree_NestedSet extends Doctrine_Tree implements Doctrine_Tree_Int
$root
=
$tree
->
getFirst
();
// if no record is returned, create record
if
(
!
$root
)
{
if
(
!
$root
)
{
$root
=
$this
->
table
->
create
();
}
...
...
@@ -194,7 +196,7 @@ class Doctrine_Tree_NestedSet extends Doctrine_Tree implements Doctrine_Tree_Int
*/
public
function
getNextRootId
()
{
return
$this
->
getMaxRootId
()
+
1
;
return
$this
->
getMaxRootId
()
+
1
;
}
/**
...
...
@@ -204,21 +206,21 @@ class Doctrine_Tree_NestedSet extends Doctrine_Tree implements Doctrine_Tree_Int
*/
public
function
getMaxRootId
()
{
$component
=
$this
->
table
->
getComponentName
();
$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";
$dql
=
"SELECT c.
$column
FROM
$component
c ORDER BY c.
$column
desc LIMIT 1"
;
$coll
=
$this
->
table
->
getConnection
()
->
query
(
$dql
);
$max
=
$coll
[
0
]
->
get
(
$column
);
$component
=
$this
->
table
->
getComponentName
();
$column
=
$this
->
getAttribute
(
'root_column_name'
);
$max
=
!
is_null
(
$max
)
?
$max
:
0
;
return
$max
;
// cannot get this dql to work, cannot retrieve result using $coll[0]->max
//$dql = "SELECT MAX(c.$column) FROM $component c";
$dql
=
'SELECT c.'
.
$column
.
' FROM '
.
$component
.
' c ORDER BY c.'
.
$column
.
' DESC LIMIT 1'
;
$coll
=
$this
->
table
->
getConnection
()
->
query
(
$dql
);
$max
=
$coll
[
0
]
->
get
(
$column
);
$max
=
!
is_null
(
$max
)
?
$max
:
0
;
return
$max
;
}
/**
...
...
@@ -230,9 +232,10 @@ class Doctrine_Tree_NestedSet extends Doctrine_Tree implements Doctrine_Tree_Int
*/
public
function
returnQueryWithRootId
(
$query
,
$root_id
=
1
)
{
if
(
$this
->
getAttribute
(
'has_many_roots'
))
$query
->
addWhere
(
$this
->
getAttribute
(
'root_column_name'
)
.
' = ?'
,
$root_id
);
return
$query
;
if
(
$this
->
getAttribute
(
'has_many_roots'
))
{
$query
->
addWhere
(
$this
->
getAttribute
(
'root_column_name'
)
.
' = ?'
,
$root_id
);
}
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