Issues

ZF-10459: Zend_Navigation_Container->removePage() should have option to remove page recursively

Issue Type: Improvement Created: 2010-09-15T13:29:58.000+0000 Last Updated: 2013-03-13T20:55:22.000+0000 Status: Open Fix version(s): - Next Mini Release ()

Reporter: Jiri Havlik (havlikjiri) Assignee: Frank Brückner (frosch) Tags: - Zend_Navigation

Related issues: - ZF-9994

Attachments:

Description

Comments

Posted by Kai Uwe (kaiuwe) on 2011-03-20T17:16:54.000+0000

I don't understand your problem. Can you give an example?

<pre class="highlight">
// Navigation
$container = new Zend_Navigation(array(
    array(
        'label' => 'Home',
        'uri'   => 'home',
    ),
    array(
        'label' => 'Products',
        'uri'   => 'products',
        'pages' => array(
            array(
                'label' => 'DVD',
                'uri'   => 'dvd',
            ),
            array(
                'label' => 'Games',
                'uri'   => 'games',
            ),
            array(
                'label' => 'Music',
                'uri'   => 'music',
            ),
        ),
    ),
    array(
        'label' => 'Contact',
        'uri'   => 'contact',
    ),
    array(
        'label' => 'imprint',
        'uri'   => 'imprint',
    ),
));

// View
$view = new Zend_View();

echo '

Output 1:

';
echo $view->navigation($container)->menu();

// Remove page "Products"
$container->removePage(1);

echo '

Output 2:

';
echo $view->navigation($container)->menu();


<pre class="highlight">

Output 1:

        <a href="home">Home</a>
    
    
        <a href="products">Products</a>

                <a href="dvd">DVD</a>
            
            
                <a href="games">Games</a>
            
            
                <a href="music">Music</a>
            
        
    
        <a href="contact">Contact</a>
    
    
        <a href="imprint">imprint</a>
    

Output 2:

        <a href="home">Home</a>
    
    
        <a href="contact">Contact</a>
    
    
        <a href="imprint">imprint</a>
    

Posted by Kai Uwe (kaiuwe) on 2011-06-09T07:13:33.000+0000

Hi Jiri, Any comments on this?

Posted by Jiri Havlik (havlikjiri) on 2011-06-09T07:53:38.000+0000

Hi Kai,

my problem is that it is not possible to remove pages in subcontainers. Eg. page DVD cant be deleted by calling something like $container->removePageByUri(dvd, true); Where "true" means Search all containers recursively. You have to get the right container first and then delete your page.

I think that it would be nice to have a function which searches all containers recursively for page given to delete.

Posted by Kai Uwe (kaiuwe) on 2011-06-09T08:41:10.000+0000

Ah, I understand.

|findOneBy|removeOneBy| |findAllBy|removeAllBy| |findBy|removeBy|

I think for the implementation, we can use all "find" methods.

<pre class="highlight">
public function removeOneBy($property, $value)
{
    $page = $this->findOneBy($property, $value);
    
    if (null !== $page) {
        return $this->removePage($page);
    }
    
    return false;
}

public function removeAllBy($property, $value)
{
    $pages = $this->findAllBy($property, $value);
    
    if (false !== empty($pages)) {
        foreach ($pages as $page) {
            $this->removePage($page);
        }
        
        return true
    }
    
    return false;
}

public function removeBy($property, $value, $all = false)
{
    if ($all) {
        return $this->removeAllBy($property, $value);
    } else {
        return $this->removeOneBy($property, $value);
    }
}

I will write some unit test.

Thanks for your fast feedback!

Posted by Frank Brückner (frosch) on 2011-09-23T08:15:28.000+0000

Based on the new filter options (useRegex). See ZF-9994

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts