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
3fc9edf8
Commit
3fc9edf8
authored
Jan 15, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Hierarchical data handling implementation moved from draft to main lib
parent
41063482
Changes
20
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
2195 additions
and
0 deletions
+2195
-0
Node.php
lib/Doctrine/Node.php
+157
-0
AdjacencyList.php
lib/Doctrine/Node/AdjacencyList.php
+34
-0
LevelOrderIterator.php
lib/Doctrine/Node/AdjacencyList/LevelOrderIterator.php
+33
-0
PostOrderIterator.php
lib/Doctrine/Node/AdjacencyList/PostOrderIterator.php
+33
-0
PreOrderIterator.php
lib/Doctrine/Node/AdjacencyList/PreOrderIterator.php
+33
-0
Exception.php
lib/Doctrine/Node/Exception.php
+33
-0
Interface.php
lib/Doctrine/Node/Interface.php
+267
-0
MaterializedPath.php
lib/Doctrine/Node/MaterializedPath.php
+34
-0
LevelOrderIterator.php
lib/Doctrine/Node/MaterializedPath/LevelOrderIterator.php
+67
-0
PostOrderIterator.php
lib/Doctrine/Node/MaterializedPath/PostOrderIterator.php
+67
-0
PreOrderIterator.php
lib/Doctrine/Node/MaterializedPath/PreOrderIterator.php
+67
-0
NestedSet.php
lib/Doctrine/Node/NestedSet.php
+723
-0
LevelOrderIterator.php
lib/Doctrine/Node/NestedSet/LevelOrderIterator.php
+33
-0
PostOrderIterator.php
lib/Doctrine/Node/NestedSet/PostOrderIterator.php
+33
-0
PreOrderIterator.php
lib/Doctrine/Node/NestedSet/PreOrderIterator.php
+177
-0
AdjacencyList.php
lib/Doctrine/Tree/AdjacencyList.php
+33
-0
Exception.php
lib/Doctrine/Tree/Exception.php
+33
-0
Interface.php
lib/Doctrine/Tree/Interface.php
+64
-0
MaterializedPath.php
lib/Doctrine/Tree/MaterializedPath.php
+33
-0
NestedSet.php
lib/Doctrine/Tree/NestedSet.php
+241
-0
No files found.
lib/Doctrine/Node.php
0 → 100644
View file @
3fc9edf8
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Node
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Joe Simms <joe.simms@websites4.com>
*/
class
Doctrine_Node
implements
IteratorAggregate
{
/**
* @param object $record reference to associated Doctrine_Record instance
*/
protected
$record
;
/**
* @param array $options
*/
protected
$options
;
/**
* @param string $iteratorType (Pre | Post | Level)
*/
protected
$iteratorType
;
/**
* @param array $iteratorOptions
*/
protected
$iteratorOptions
;
/**
* contructor, creates node with reference to record and any options
*
* @param object $record instance of Doctrine_Record
* @param array $options options
*/
public
function
__construct
(
Doctrine_Record
$record
,
$options
)
{
$this
->
record
=
$record
;
$this
->
options
=
$options
;
}
/**
* factory method to return node instance based upon chosen implementation
*
* @param object $record instance of Doctrine_Record
* @param string $impName implementation (NestedSet, AdjacencyList, MaterializedPath)
* @param array $options options
* @return object $options instance of Doctrine_Node
*/
public
static
function
factory
(
Doctrine_Record
$record
,
$implName
,
$options
=
array
())
{
$class
=
'Doctrine_Node_'
.
$implName
;
if
(
!
class_exists
(
$class
))
{
throw
new
Doctrine_Node_Exception
(
"The class
$class
must exist and extend Doctrine_Node"
);
}
return
new
$class
(
$record
,
$options
);
}
/**
* setter for record attribute
*
* @param object $record instance of Doctrine_Record
*/
public
function
setRecord
(
Doctrine_Record
$record
)
{
$this
->
record
=
$record
;
}
/**
* getter for record attribute
*
* @return object instance of Doctrine_Record
*/
public
function
getRecord
()
{
return
$this
->
record
;
}
/**
* convenience function for getIterator
*
* @param string $type type of iterator (Pre | Post | Level)
* @param array $options options
*/
public
function
traverse
(
$type
=
'Pre'
,
$options
=
array
())
{
return
$this
->
getIterator
(
$type
,
$options
);
}
/**
* get iterator
*
* @param string $type type of iterator (Pre | Post | Level)
* @param array $options options
*/
public
function
getIterator
(
$type
=
null
,
$options
=
null
)
{
if
(
$type
===
null
)
{
$type
=
(
isset
(
$this
->
iteratorType
)
?
$this
->
iteratorType
:
'Pre'
);
}
if
(
$options
===
null
)
{
$options
=
(
isset
(
$this
->
iteratorOptions
)
?
$this
->
iteratorOptions
:
array
());
}
$implName
=
$this
->
record
->
getTable
()
->
getTreeImplName
();
$iteratorClass
=
'Doctrine_Node_'
.
$implName
.
'_'
.
ucfirst
(
strtolower
(
$type
))
.
'OrderIterator'
;
return
new
$iteratorClass
(
$this
->
record
,
$options
);
}
/**
* sets node's iterator type
*
* @param int
*/
public
function
setIteratorType
(
$type
)
{
$this
->
iteratorType
=
$type
;
}
/**
* sets node's iterator options
*
* @param int
*/
public
function
setIteratorOptions
(
$options
)
{
$this
->
iteratorOptions
=
$options
;
}
}
lib/Doctrine/Node/AdjacencyList.php
0 → 100644
View file @
3fc9edf8
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Node_AdjacencyList
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Joe Simms <joe.simms@websites4.com>
*/
class
Doctrine_Node_AdjacencyList
extends
Doctrine_Node
implements
Doctrine_Node_Interface
{}
lib/Doctrine/Node/AdjacencyList/LevelOrderIterator.php
0 → 100644
View file @
3fc9edf8
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Node_AdjacencyList_LevelOrderIterator
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Joe Simms <joe.simms@websites4.com>
*/
class
Doctrine_Node_AdjacencyList_LevelOrderIterator
implements
Iterator
{}
lib/Doctrine/Node/AdjacencyList/PostOrderIterator.php
0 → 100644
View file @
3fc9edf8
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Node_AdjacencyList_PostOrderIterator
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Joe Simms <joe.simms@websites4.com>
*/
class
Doctrine_Node_AdjacencyList_PostOrderIterator
implements
Iterator
{}
lib/Doctrine/Node/AdjacencyList/PreOrderIterator.php
0 → 100644
View file @
3fc9edf8
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Node_AdjacencyList_PreOrderIterator
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Joe Simms <joe.simms@websites4.com>
*/
class
Doctrine_Node_AdjacencyList_PreOrderIterator
implements
Iterator
{}
lib/Doctrine/Node/Exception.php
0 → 100644
View file @
3fc9edf8
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Node_Exception
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Joe Simms <joe.simms@websites4.com>
*/
class
Doctrine_Node_Exception
extends
Doctrine_Exception
{}
lib/Doctrine/Node/Interface.php
0 → 100644
View file @
3fc9edf8
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Node_Interface
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Joe Simms <joe.simms@websites4.com>
*/
interface
Doctrine_Node_Interface
{
/**
* test if node has previous sibling
*
* @return bool
*/
public
function
hasPrevSibling
();
/**
* test if node has next sibling
*
* @return bool
*/
public
function
hasNextSibling
();
/**
* test if node has children
*
* @return bool
*/
public
function
hasChildren
();
/**
* test if node has parent
*
* @return bool
*/
public
function
hasParent
();
/**
* gets record of prev sibling or empty record
*
* @return object Doctrine_Record
*/
public
function
getPrevSibling
();
/**
* gets record of next sibling or empty record
*
* @return object Doctrine_Record
*/
public
function
getNextSibling
();
/**
* gets siblings for node
*
* @return array array of sibling Doctrine_Record objects
*/
public
function
getSiblings
(
$includeNode
=
false
);
/**
* gets record of first child or empty record
*
* @return object Doctrine_Record
*/
public
function
getFirstChild
();
/**
* gets record of last child or empty record
*
* @return object Doctrine_Record
*/
public
function
getLastChild
();
/**
* gets children for node (direct descendants only)
*
* @return array array of sibling Doctrine_Record objects
*/
public
function
getChildren
();
/**
* gets descendants for node (direct descendants only)
*
* @return iterator iterator to traverse descendants from node
*/
public
function
getDescendants
();
/**
* gets record of parent or empty record
*
* @return object Doctrine_Record
*/
public
function
getParent
();
/**
* gets ancestors for node
*
* @return object Doctrine_Collection
*/
public
function
getAncestors
();
/**
* gets path to node from root, uses record::toString() method to get node names
*
* @param string $seperator path seperator
* @param bool $includeNode whether or not to include node at end of path
* @return string string representation of path
*/
public
function
getPath
(
$seperator
=
' > '
,
$includeNode
=
false
);
/**
* gets level (depth) of node in the tree
*
* @return int
*/
public
function
getLevel
();
/**
* gets number of children (direct descendants)
*
* @return int
*/
public
function
getNumberChildren
();
/**
* gets number of descendants (children and their children)
*
* @return int
*/
public
function
getNumberDescendants
();
/**
* inserts node as parent of dest record
*
* @return bool
*/
public
function
insertAsParentOf
(
Doctrine_Record
$dest
);
/**
* inserts node as previous sibling of dest record
*
* @return bool
*/
public
function
insertAsPrevSiblingOf
(
Doctrine_Record
$dest
);
/**
* inserts node as next sibling of dest record
*
* @return bool
*/
public
function
insertAsNextSiblingOf
(
Doctrine_Record
$dest
);
/**
* inserts node as first child of dest record
*
* @return bool
*/
public
function
insertAsFirstChildOf
(
Doctrine_Record
$dest
);
/**
* inserts node as first child of dest record
*
* @return bool
*/
public
function
insertAsLastChildOf
(
Doctrine_Record
$dest
);
/**
* moves node as prev sibling of dest record
*
*/
public
function
moveAsPrevSiblingOf
(
Doctrine_Record
$dest
);
/**
* moves node as next sibling of dest record
*
*/
public
function
moveAsNextSiblingOf
(
Doctrine_Record
$dest
);
/**
* moves node as first child of dest record
*
*/
public
function
moveAsFirstChildOf
(
Doctrine_Record
$dest
);
/**
* moves node as last child of dest record
*
*/
public
function
moveAsLastChildOf
(
Doctrine_Record
$dest
);
/**
* adds node as last child of record
*
*/
public
function
addChild
(
Doctrine_Record
$record
);
/**
* determines if node is leaf
*
* @return bool
*/
public
function
isLeaf
();
/**
* determines if node is root
*
* @return bool
*/
public
function
isRoot
();
/**
* determines if node is equal to subject node
*
* @return bool
*/
public
function
isEqualTo
(
Doctrine_Record
$subj
);
/**
* determines if node is child of subject node
*
* @return bool
*/
public
function
isDescendantOf
(
Doctrine_Record
$subj
);
/**
* determines if node is child of or sibling to subject node
*
* @return bool
*/
public
function
isDescendantOfOrEqualTo
(
Doctrine_Record
$subj
);
/**
* determines if node is valid
*
* @return bool
*/
public
function
isValidNode
();
/**
* deletes node and it's descendants
*
*/
public
function
delete
();
}
lib/Doctrine/Node/MaterializedPath.php
0 → 100644
View file @
3fc9edf8
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Node_MaterializedPath
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Joe Simms <joe.simms@websites4.com>
*/
class
Doctrine_Node_MaterializedPath
extends
Doctrine_Node
implements
Doctrine_Node_Interface
{}
lib/Doctrine/Node/MaterializedPath/LevelOrderIterator.php
0 → 100644
View file @
3fc9edf8
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Node_MaterializedPath_LevelOrderIterator
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Joe Simms <joe.simms@websites4.com>
*/
class
Doctrine_Node_MaterializedPath_LevelOrderIterator
implements
Iterator
{
private
$topNode
=
null
;
private
$curNode
=
null
;
public
function
__construct
(
$node
,
$opts
)
{
throw
new
Doctrine_Exception
(
'Not yet implemented'
);
}
public
function
rewind
()
{
throw
new
Doctrine_Exception
(
'Not yet implemented'
);
}
public
function
valid
()
{
throw
new
Doctrine_Exception
(
'Not yet implemented'
);
}
public
function
current
()
{
throw
new
Doctrine_Exception
(
'Not yet implemented'
);
}
public
function
key
()
{
throw
new
Doctrine_Exception
(
'Not yet implemented'
);
}
public
function
next
()
{
throw
new
Doctrine_Exception
(
'Not yet implemented'
);
}
}
lib/Doctrine/Node/MaterializedPath/PostOrderIterator.php
0 → 100644
View file @
3fc9edf8
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Node_MaterializedPath_PostOrderIterator
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Joe Simms <joe.simms@websites4.com>
*/
class
Doctrine_Node_MaterializedPath_PostOrderIterator
implements
Iterator
{
private
$topNode
=
null
;
private
$curNode
=
null
;
public
function
__construct
(
$node
,
$opts
)
{
throw
new
Doctrine_Exception
(
'Not yet implemented'
);
}
public
function
rewind
()
{
throw
new
Doctrine_Exception
(
'Not yet implemented'
);
}
public
function
valid
()
{
throw
new
Doctrine_Exception
(
'Not yet implemented'
);
}
public
function
current
()
{
throw
new
Doctrine_Exception
(
'Not yet implemented'
);
}
public
function
key
()
{
throw
new
Doctrine_Exception
(
'Not yet implemented'
);
}
public
function
next
()
{
throw
new
Doctrine_Exception
(
'Not yet implemented'
);
}
}
lib/Doctrine/Node/MaterializedPath/PreOrderIterator.php
0 → 100644
View file @
3fc9edf8
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Node_MaterializedPath_PreOrderIterator
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Joe Simms <joe.simms@websites4.com>
*/
class
Doctrine_Node_MaterializedPath_PreOrderIterator
implements
Iterator
{
private
$topNode
=
null
;
private
$curNode
=
null
;
public
function
__construct
(
$node
,
$opts
)
{
throw
new
Doctrine_Exception
(
'Not yet implemented'
);
}
public
function
rewind
()
{
throw
new
Doctrine_Exception
(
'Not yet implemented'
);
}
public
function
valid
()
{
throw
new
Doctrine_Exception
(
'Not yet implemented'
);
}
public
function
current
()
{
throw
new
Doctrine_Exception
(
'Not yet implemented'
);
}
public
function
key
()
{
throw
new
Doctrine_Exception
(
'Not yet implemented'
);
}
public
function
next
()
{
throw
new
Doctrine_Exception
(
'Not yet implemented'
);
}
}
lib/Doctrine/Node/NestedSet.php
0 → 100644
View file @
3fc9edf8
This diff is collapsed.
Click to expand it.
lib/Doctrine/Node/NestedSet/LevelOrderIterator.php
0 → 100644
View file @
3fc9edf8
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Node_NestedSet_LevelOrderIterator
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Joe Simms <joe.simms@websites4.com>
*/
class
Doctrine_Node_NestedSet_LevelOrderIterator
implements
Iterator
{}
lib/Doctrine/Node/NestedSet/PostOrderIterator.php
0 → 100644
View file @
3fc9edf8
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Node_NestedSet_PostOrderIterator
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Joe Simms <joe.simms@websites4.com>
*/
class
Doctrine_Node_NestedSet_PostOrderIterator
implements
Iterator
{}
lib/Doctrine/Node/NestedSet/PreOrderIterator.php
0 → 100644
View file @
3fc9edf8
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Node_NestedSet_PreOrderIterator
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Joe Simms <joe.simms@websites4.com>
*/
class
Doctrine_Node_NestedSet_PreOrderIterator
implements
Iterator
{
/**
* @var Doctrine_Collection $collection
*/
protected
$collection
;
/**
* @var array $keys
*/
protected
$keys
;
/**
* @var mixed $key
*/
protected
$key
;
/**
* @var integer $index
*/
protected
$index
;
/**
* @var integer $index
*/
protected
$prevIndex
;
/**
* @var integer $index
*/
protected
$traverseLevel
;
/**
* @var integer $count
*/
protected
$count
;
public
function
__construct
(
$record
,
$opts
)
{
$componentName
=
$record
->
getTable
()
->
getComponentName
();
$q
=
$record
->
getTable
()
->
createQuery
();
$params
=
array
(
$record
->
get
(
'lft'
),
$record
->
get
(
'rgt'
));
if
(
isset
(
$opts
[
'include_record'
])
&&
$opts
[
'include_record'
])
{
$query
=
$q
->
where
(
"
$componentName
.lft >= ? AND
$componentName
.rgt <= ?"
,
$params
)
->
orderBy
(
'lft asc'
);
}
else
{
$query
=
$q
->
where
(
"
$componentName
.lft > ? AND
$componentName
.rgt < ?"
,
$params
)
->
orderBy
(
'lft asc'
);
}
$query
=
$record
->
getTable
()
->
getTree
()
->
returnQueryWithRootId
(
$query
,
$record
->
getNode
()
->
getRootValue
());
$this
->
maxLevel
=
isset
(
$opts
[
'depth'
])
?
(
$opts
[
'depth'
]
+
$record
->
getNode
()
->
getLevel
())
:
0
;
$this
->
options
=
$opts
;
$this
->
collection
=
isset
(
$opts
[
'collection'
])
?
$opts
[
'collection'
]
:
$query
->
execute
();
$this
->
keys
=
$this
->
collection
->
getKeys
();
$this
->
count
=
$this
->
collection
->
count
();
$this
->
index
=
-
1
;
$this
->
level
=
$record
->
getNode
()
->
getLevel
();
$this
->
prevLeft
=
$record
->
getNode
()
->
getLeftValue
();
echo
$this
->
maxDepth
;
// clear the table identity cache
$record
->
getTable
()
->
clear
();
}
/**
* rewinds the iterator
*
* @return void
*/
public
function
rewind
()
{
$this
->
index
=
-
1
;
$this
->
key
=
null
;
}
/**
* returns the current key
*
* @return integer
*/
public
function
key
()
{
return
$this
->
key
;
}
/**
* returns the current record
*
* @return Doctrine_Record
*/
public
function
current
()
{
$record
=
$this
->
collection
->
get
(
$this
->
key
);
$record
->
getNode
()
->
setLevel
(
$this
->
level
);
return
$record
;
}
/**
* advances the internal pointer
*
* @return void
*/
public
function
next
()
{
while
(
$current
=
$this
->
advanceIndex
())
{
if
(
$this
->
maxLevel
&&
(
$this
->
level
>
$this
->
maxLevel
))
{
continue
;
}
return
$current
;
}
return
false
;
}
/**
* @return boolean whether or not the iteration will continue
*/
public
function
valid
()
{
return
(
$this
->
index
<
$this
->
count
);
}
public
function
count
()
{
return
$this
->
count
;
}
private
function
updateLevel
()
{
if
(
!
(
isset
(
$this
->
options
[
'include_record'
])
&&
$this
->
options
[
'include_record'
]
&&
$this
->
index
==
0
))
{
$left
=
$this
->
collection
->
get
(
$this
->
key
)
->
getNode
()
->
getLeftValue
();
$this
->
level
+=
$this
->
prevLeft
-
$left
+
2
;
$this
->
prevLeft
=
$left
;
}
}
private
function
advanceIndex
()
{
$this
->
index
++
;
$i
=
$this
->
index
;
if
(
isset
(
$this
->
keys
[
$i
]))
{
$this
->
key
=
$this
->
keys
[
$i
];
$this
->
updateLevel
();
return
$this
->
current
();
}
return
false
;
}
}
lib/Doctrine/Tree/AdjacencyList.php
0 → 100644
View file @
3fc9edf8
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Tree_AdjacencyList
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Joe Simms <joe.simms@websites4.com>
*/
class
Doctrine_Tree_AdjacencyList
extends
Doctrine_Tree
implements
Doctrine_Tree_Interface
{}
lib/Doctrine/Tree/Exception.php
0 → 100644
View file @
3fc9edf8
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Tree_Exception
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class
Doctrine_Tree_Exception
extends
Doctrine_Exception
{}
lib/Doctrine/Tree/Interface.php
0 → 100644
View file @
3fc9edf8
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Tree_Interface
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Joe Simms <joe.simms@websites4.com>
*/
interface
Doctrine_Tree_Interface
{
/**
* creates root node from given record or from a new record
*
* @param object $record instance of Doctrine_Record
*/
public
function
createRoot
(
Doctrine_Record
$record
=
null
);
/**
* returns root node
*
* @return object $record instance of Doctrine_Record
*/
public
function
findRoot
(
$root_id
=
1
);
/**
* optimised method to returns iterator for traversal of the entire tree from root
*
* @param array $options options
* @return object $iterator instance of Doctrine_Node_<Implementation>_PreOrderIterator
*/
public
function
fetchTree
(
$options
=
array
());
/**
* optimised method that returns iterator for traversal of the tree from the given record primary key
*
* @param mixed $pk primary key as used by table::find() to locate node to traverse tree from
* @param array $options options
* @return iterator instance of Doctrine_Node_<Implementation>_PreOrderIterator
*/
public
function
fetchBranch
(
$pk
,
$options
=
array
());
}
lib/Doctrine/Tree/MaterializedPath.php
0 → 100644
View file @
3fc9edf8
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Tree_MaterializedPath
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Joe Simms <joe.simms@websites4.com>
*/
class
Doctrine_Tree_MaterializedPath
extends
Doctrine_Tree
implements
Doctrine_Tree_Interface
{}
lib/Doctrine/Tree/NestedSet.php
0 → 100644
View file @
3fc9edf8
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Tree_NestedSet
*
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
* @author Joe Simms <joe.simms@websites4.com>
*/
class
Doctrine_Tree_NestedSet
extends
Doctrine_Tree
implements
Doctrine_Tree_Interface
{
/**
* constructor, creates tree with reference to table and sets default root options
*
* @param object $table instance of Doctrine_Table
* @param array $options options
*/
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
);
}
/**
* used to define table attributes required for the NestetSet implementation
* adds lft and rgt columns for corresponding left and right values
*
*/
public
function
setTableDefinition
()
{
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
);
}
/**
* creates root node from given record or from a new record
*
* @param object $record instance of Doctrine_Record
*/
public
function
createRoot
(
Doctrine_Record
$record
=
null
)
{
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
());
}
$record
->
set
(
'lft'
,
'1'
);
$record
->
set
(
'rgt'
,
'2'
);
$record
->
save
();
return
$record
;
}
/**
* returns root node
*
* @return object $record instance of Doctrine_Record
*/
public
function
findRoot
(
$rootId
=
1
)
{
$q
=
$this
->
table
->
createQuery
();
$q
=
$q
->
where
(
'lft = ?'
,
1
);
// if tree has many roots, then specify root id
$q
=
$this
->
returnQueryWithRootId
(
$q
,
$rootId
);
$root
=
$q
->
execute
()
->
getFirst
();
// if no record is returned, create record
if
(
!
$root
)
{
$root
=
$this
->
table
->
create
();
}
// set level to prevent additional query to determine level
$root
->
getNode
()
->
setLevel
(
0
);
return
$root
;
}
/**
* optimised method to returns iterator for traversal of the entire tree from root
*
* @param array $options options
* @return object $iterator instance of Doctrine_Node_NestedSet_PreOrderIterator
*/
public
function
fetchTree
(
$options
=
array
())
{
// fetch tree
$q
=
$this
->
table
->
createQuery
();
$q
=
$q
->
where
(
'lft >= ?'
,
1
)
->
orderBy
(
'lft asc'
);
// if tree has many roots, then specify root id
$rootId
=
isset
(
$options
[
'root_id'
])
?
$options
[
'root_id'
]
:
'1'
;
$q
=
$this
->
returnQueryWithRootId
(
$q
,
$rootId
);
$tree
=
$q
->
execute
();
$root
=
$tree
->
getFirst
();
// if no record is returned, create record
if
(
!
$root
)
{
$root
=
$this
->
table
->
create
();
}
if
(
$root
->
exists
())
{
// set level to prevent additional query
$root
->
getNode
()
->
setLevel
(
0
);
// default to include root node
$options
=
array_merge
(
array
(
'include_record'
=>
true
),
$options
);
// remove root node from collection if not required
if
(
$options
[
'include_record'
]
==
false
)
{
$tree
->
remove
(
0
);
}
// set collection for iterator
$options
[
'collection'
]
=
$tree
;
return
$root
->
getNode
()
->
traverse
(
'Pre'
,
$options
);
}
// TODO: no default return value or exception thrown?
}
/**
* optimised method that returns iterator for traversal of the tree from the given record primary key
*
* @param mixed $pk primary key as used by table::find() to locate node to traverse tree from
* @param array $options options
* @return iterator instance of Doctrine_Node_<Implementation>_PreOrderIterator
*/
public
function
fetchBranch
(
$pk
,
$options
=
array
())
{
$record
=
$this
->
table
->
find
(
$pk
);
if
(
$record
->
exists
())
{
$options
=
array_merge
(
array
(
'include_record'
=>
true
),
$options
);
return
$record
->
getNode
()
->
traverse
(
'Pre'
,
$options
);
}
// TODO: if record doesn't exist, throw exception or similar?
}
/**
* fetch root nodes
*
* @return collection Doctrine_Collection
*/
public
function
fetchRoots
()
{
$q
=
$this
->
table
->
createQuery
();
$q
=
$q
->
where
(
'lft = ?'
,
1
);
return
$q
->
execute
();
}
/**
* calculates the next available root id
*
* @return integer
*/
public
function
getNextRootId
()
{
return
$this
->
getMaxRootId
()
+
1
;
}
/**
* calculates the current max root id
*
* @return integer
*/
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
);
$max
=
!
is_null
(
$max
)
?
$max
:
0
;
return
$max
;
}
/**
* returns parsed query with root id where clause added if applicable
*
* @param object $query Doctrine_Query
* @param integer $root_id id of destination root
* @return object Doctrine_Query
*/
public
function
returnQueryWithRootId
(
$query
,
$rootId
=
1
)
{
if
(
$this
->
getAttribute
(
'has_many_roots'
))
{
$query
->
addWhere
(
$this
->
getAttribute
(
'root_column_name'
)
.
' = ?'
,
$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