diff options
author | Ivan Enderlin <ivan.enderlin@hoa-project.net> | 2013-09-17 10:57:16 +0200 |
---|---|---|
committer | Ivan Enderlin <ivan.enderlin@hoa-project.net> | 2013-09-17 10:57:16 +0200 |
commit | fe57496b2d32826beff4da7e0bee877cbf8ff4a8 (patch) | |
tree | f5459ea4c78172550301e1566a316dacb9fe4520 /Model | |
parent | 443060f138b5d097a9d809a685afb084f2cb259a (diff) | |
download | Praspel-fe57496b2d32826beff4da7e0bee877cbf8ff4a8.zip Praspel-fe57496b2d32826beff4da7e0bee877cbf8ff4a8.tar.gz Praspel-fe57496b2d32826beff4da7e0bee877cbf8ff4a8.tar.bz2 |
Add getNth() method: get clauses from positions.
Diffstat (limited to 'Model')
-rw-r--r-- | Model/Collection.php | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/Model/Collection.php b/Model/Collection.php index f84a507..597ffde 100644 --- a/Model/Collection.php +++ b/Model/Collection.php @@ -86,6 +86,13 @@ class Collection protected $_clauses = array(); /** + * Mapping from position to clauses (instead of identifier). + * + * @var \Hoa\Praspel\Model\Collection array + */ + protected $_mapping = array(); + + /** * Reference clause. * * @var \Hoa\Praspel\Model\Clause object @@ -143,6 +150,7 @@ class Collection $clause = $this->getClause(); $this->_clauses[$offset] = clone $clause; + $this->_mapping[] = &$this->_clauses[$offset]; $postClone = $this->getPostClone(); if(null !== $postClone) @@ -156,7 +164,7 @@ class Collection * Alias of $this->offsetGet($offset). * * @access public - * @param string $offset Offset. + * @param string $identifier Identifier. * @return \Hoa\Praspel\Model\Clause */ public function get ( $offset ) { @@ -165,6 +173,21 @@ class Collection } /** + * Get a clause from its position. + * + * @access public + * @param string $position Position. + * @return \Hoa\Praspel\Model\Clause + */ + public function getNth ( $position ) { + + if(!isset($this->_mapping[$position])) + return null; + + return $this->_mapping[$position]; + } + + /** * Disabled. * * @access public |