web/lib/Zend/Navigation/Container.php
changeset 1230 68c69c656a2c
parent 807 877f952ae2bd
equal deleted inserted replaced
1229:5a6b6e770365 1230:68c69c656a2c
    12  * obtain it through the world-wide-web, please send an email
    12  * obtain it through the world-wide-web, please send an email
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category  Zend
    15  * @category  Zend
    16  * @package   Zend_Navigation
    16  * @package   Zend_Navigation
    17  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    17  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @license   http://framework.zend.com/license/new-bsd     New BSD License
    18  * @license   http://framework.zend.com/license/new-bsd     New BSD License
    19  * @version    $Id: Container.php 25237 2013-01-22 08:32:38Z frosch $
    19  * @version    $Id$
    20  */
    20  */
    21 
    21 
    22 /**
    22 /**
    23  * Zend_Navigation_Container
    23  * Zend_Navigation_Container
    24  *
    24  *
    25  * Container class for Zend_Navigation_Page classes.
    25  * Container class for Zend_Navigation_Page classes.
    26  *
    26  *
    27  * @category  Zend
    27  * @category  Zend
    28  * @package   Zend_Navigation
    28  * @package   Zend_Navigation
    29  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    29  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    30  * @license   http://framework.zend.com/license/new-bsd     New BSD License
    30  * @license   http://framework.zend.com/license/new-bsd     New BSD License
    31  */
    31  */
    32 abstract class Zend_Navigation_Container implements RecursiveIterator, Countable
    32 abstract class Zend_Navigation_Container implements RecursiveIterator, Countable
    33 {
    33 {
    34     /**
    34     /**
    35      * Contains sub pages
    35      * Contains sub pages
    36      *
    36      *
    37      * @var array
    37      * @var Zend_Navigation_Page[]
    38      */
    38      */
    39     protected $_pages = array();
    39     protected $_pages = array();
    40 
    40 
    41     /**
    41     /**
    42      * An index that contains the order in which to iterate pages
    42      * An index that contains the order in which to iterate pages
   141     }
   141     }
   142 
   142 
   143     /**
   143     /**
   144      * Adds several pages at once
   144      * Adds several pages at once
   145      *
   145      *
   146      * @param  array|Zend_Config|Zend_Navigation_Container  $pages  pages to add
   146      * @param  Zend_Navigation_Page[]|Zend_Config|Zend_Navigation_Container  $pages  pages to add
   147      * @return Zend_Navigation_Container                    fluent interface,
   147      * @return Zend_Navigation_Container                    fluent interface,
   148      *                                                      returns self
   148      *                                                      returns self
   149      * @throws Zend_Navigation_Exception                    if $pages is not 
   149      * @throws Zend_Navigation_Exception                    if $pages is not 
   150      *                                                      array, Zend_Config or
   150      *                                                      array, Zend_Config or
   151      *                                                      Zend_Navigation_Container
   151      *                                                      Zend_Navigation_Container
   176     }
   176     }
   177 
   177 
   178     /**
   178     /**
   179      * Sets pages this container should have, removing existing pages
   179      * Sets pages this container should have, removing existing pages
   180      *
   180      *
   181      * @param  array $pages               pages to set
   181      * @param  Zend_Navigation_Page[] $pages               pages to set
   182      * @return Zend_Navigation_Container  fluent interface, returns self
   182      * @return Zend_Navigation_Container  fluent interface, returns self
   183      */
   183      */
   184     public function setPages(array $pages)
   184     public function setPages(array $pages)
   185     {
   185     {
   186         $this->removePages();
   186         $this->removePages();
   188     }
   188     }
   189 
   189 
   190     /**
   190     /**
   191      * Returns pages in the container
   191      * Returns pages in the container
   192      *
   192      *
   193      * @return array  array of Zend_Navigation_Page instances
   193      * @return Zend_Navigation_Page[]  array of Zend_Navigation_Page instances
   194      */
   194      */
   195     public function getPages()
   195     public function getPages()
   196     {
   196     {
   197         return $this->_pages;
   197         return $this->_pages;
   198     }
   198     }
   199 
   199 
   200     /**
   200     /**
   201      * Removes the given page from the container
   201      * Removes the given page from the container
   202      *
   202      *
   203      * @param  Zend_Navigation_Page|int $page  page to remove, either a page
   203      * @param  Zend_Navigation_Page|int $page      page to remove, either a page
   204      *                                         instance or a specific page order
   204      *                                             instance or a specific page order
   205      * @return bool                            whether the removal was
   205      * @param  bool                     $recursive [optional] whether to remove recursively
   206      *                                         successful
   206      * @return bool whether the removal was successful
   207      */
   207      */
   208     public function removePage($page)
   208     public function removePage($page, $recursive = false)
   209     {
   209     {
   210         if ($page instanceof Zend_Navigation_Page) {
   210         if ($page instanceof Zend_Navigation_Page) {
   211             $hash = $page->hashCode();
   211             $hash = $page->hashCode();
   212         } elseif (is_int($page)) {
   212         } elseif (is_int($page)) {
   213             $this->_sort();
   213             $this->_sort();
   221         if (isset($this->_pages[$hash])) {
   221         if (isset($this->_pages[$hash])) {
   222             unset($this->_pages[$hash]);
   222             unset($this->_pages[$hash]);
   223             unset($this->_index[$hash]);
   223             unset($this->_index[$hash]);
   224             $this->_dirtyIndex = true;
   224             $this->_dirtyIndex = true;
   225             return true;
   225             return true;
       
   226         }
       
   227 
       
   228         if ($recursive) {
       
   229             /** @var Zend_Navigation_Page $childPage */
       
   230             foreach ($this->_pages as $childPage) {
       
   231                 if ($childPage->hasPage($page, true)) {
       
   232                     $childPage->removePage($page, true);
       
   233                     return true;
       
   234                 }
       
   235             }
   226         }
   236         }
   227 
   237 
   228         return false;
   238         return false;
   229     }
   239     }
   230 
   240 
   347      *
   357      *
   348      * @param  string $property  name of property to match against
   358      * @param  string $property  name of property to match against
   349      * @param  mixed  $value     value to match property against
   359      * @param  mixed  $value     value to match property against
   350      * @param  bool   $useRegex  [optional] if true PHP's preg_match is used.
   360      * @param  bool   $useRegex  [optional] if true PHP's preg_match is used.
   351      *                           Default is false.
   361      *                           Default is false.
   352      * @return array             array containing only Zend_Navigation_Page
   362      * @return Zend_Navigation_Page[] array containing only Zend_Navigation_Page
   353      *                           instances
   363      *                           instances
   354      */
   364      */
   355     public function findAllBy($property, $value, $useRegex = false)
   365     public function findAllBy($property, $value, $useRegex = false)
   356     {        
   366     {        
   357         $found = array();
   367         $found = array();
   472     }
   482     }
   473 
   483 
   474     /**
   484     /**
   475      * Returns an array representation of all pages in container
   485      * Returns an array representation of all pages in container
   476      *
   486      *
   477      * @return array
   487      * @return Zend_Navigation_Page[]
   478      */
   488      */
   479     public function toArray()
   489     public function toArray()
   480     {
   490     {
   481         $pages = array();
   491         $pages = array();
   482 
   492