/**
* Returns a nested unordered list of SimplePage links
*
* @uses simple_pages_get_links_for_children_pages()
* @uses nav()
* @param integer|null The id of the parent page.  If null, it uses the current simple page
* @param string The method by which you sort pages. Options are 'order' (default) and 'alpha'.
* @param boolean Whether to return only published pages.
* @return string
*/
function simple_pages_navigation($parentId = 0, $sort = 'order', $requiresIsPublished = true)
{
    $html = '';
    $childPageLinks = simple_pages_get_links_for_children_pages($parentId, $sort, $requiresIsPublished);
    if ($childPageLinks) {
        $html .= '<div class="simple-pages-navigation">' . "\n";
        $html .= nav($childPageLinks);
        $html .= '</div>' . "\n";
    }
    return $html;
}
 public function testGetPageLinksForPublishedPages()
 {
     $pages = $this->db->getTable('SimplePagesPage')->findAll();
     $this->assertEquals(1, count($pages));
     $aboutPage = $pages[0];
     $testPage1 = $this->_addTestPage('Test Title 1', 'testslug1', 'testtext1');
     $testPage1->parent_id = $aboutPage->id;
     $testPage1->order = 1;
     $testPage1->is_published = 1;
     $testPage1->save();
     $testPage2 = $this->_addTestPage('Test Title 2', 'testslug2', 'testtext2');
     $testPage2->parent_id = $aboutPage->id;
     $testPage2->order = 2;
     $testPage2->is_published = 1;
     $testPage2->save();
     $testPage3 = $this->_addTestPage('Test Title 3', 'testslug3', 'testtext3');
     $testPage3->parent_id = $aboutPage->id;
     $testPage3->order = 3;
     $testPage3->is_published = 0;
     $testPage3->save();
     $testPage4 = $this->_addTestPage('Test Title 4', 'testslug4', 'testtext4');
     $testPage4->parent_id = $testPage2->id;
     $testPage4->order = 1;
     $testPage4->is_published = 0;
     $testPage4->save();
     $testPage5 = $this->_addTestPage('Test Title 5', 'testslug5', 'testtext5');
     $testPage5->parent_id = $testPage2->id;
     $testPage5->order = 2;
     $testPage5->is_published = 1;
     $testPage5->save();
     $this->dispatch('/');
     $actualNavLinks = simple_pages_get_links_for_children_pages($aboutPage->id, 'order', true);
     $this->assertEquals(2, count($actualNavLinks));
     $expectedNavLinks = array();
     $expectedNavLinks[] = array('label' => 'Test Title 1', 'uri' => public_url('testslug1'));
     $expectedNavLinks[] = array('label' => 'Test Title 2', 'uri' => public_url('testslug2'), 'pages' => array(array('label' => 'Test Title 5', 'uri' => public_url('testslug5'))));
     $this->assertEquals($expectedNavLinks, $actualNavLinks);
 }
 /**
  * Add the pages to the public main navigation options.
  * 
  * @param array Navigation array.
  * @return array Filtered navigation array.
  */
 public function filterPublicNavigationMain($nav)
 {
     $navLinks = simple_pages_get_links_for_children_pages(0, 0, 'order', true);
     $nav = array_merge($nav, $navLinks);
     return $nav;
 }