예제 #1
0
    /**
     * Returns HTML anchor for the given pages
     *
     * @param  Zym_Navigation_Page $page  page to get anchor for
     * @return string
     */
    public function getPageAnchor(Zym_Navigation_Page $page)
    {
        // get label and title for translating
        $label = $page->getLabel();
        $title = $page->getTitle();
        
        if ($this->_useTranslator && $t = $this->_getTranslator()) {
            $label = $t->translate($label);
            $title = $t->translate($title);
        }
        
        // get attribs for anchor element
        $attribs = array(
            'id'     => $page->getId(),
            'title'  => $title,
            'class'  => $page->getClass()
        );

        $href = $page->getHref();

        if ($href) {
            $attribs['href'] = $href;
            $attribs['target'] = $page->getTarget();
            $element = 'a';
        } else {
            $element = 'span';
        }

        return '<' . $element . ' ' . $this->_htmlAttribs($attribs) . '>'
             . $this->getView()->escape($label)
             . '</' . $element . '>';
    }
예제 #2
0
 /**
  * Returns HTML anchor for the given pages
  *
  * @param  Zym_Navigation_Page $page  page to get anchor for
  * @return string
  */
 public function getPageAnchor(Zym_Navigation_Page $page)
 {
     // get attribs for anchor element
     $attribs = array('id' => $page->getId(), 'title' => $page->getTitle(), 'class' => $page->getClass());
     $href = $page->getHref();
     if ($href) {
         $attribs['href'] = $href;
         $attribs['target'] = $page->getTarget();
         $element = 'a';
     } else {
         $element = 'span';
     }
     return '<' . $element . ' ' . $this->_htmlAttribs($attribs) . '>' . $page->getLabel() . '</' . $element . '>';
 }
예제 #3
0
 /**
  * The page factory should not work with page types that don't exist
  *
  */
 public function testShouldFailForNonExistantType()
 {
     $pageConfig = array('type' => 'My_NonExistant_Page', 'label' => 'My non-existant Page');
     try {
         $page = Zym_Navigation_Page::factory($pageConfig);
     } catch (Zend_Exception $e) {
         return;
     }
     $msg = 'A Zend_Exception has not been thrown for non-existant class';
     $this->fail($msg);
 }
예제 #4
0
 /**
  * Returns an absolute URL for the given page
  *
  * @param  Zym_Navigation_Page $page  page to get URL from
  * @return string
  */
 protected function _getUrl(Zym_Navigation_Page $page)
 {
     $href = $page->getHref();
     if ($href[0] == '/') {
         $url = $this->_getServerUrl() . $href;
     } elseif (@preg_match('/^https?:\\/\\//m', $href)) {
         $url = $href;
     } else {
         $url = $this->_getServerUrl() . rtrim($this->getView()->url(), '/') . '/' . $href;
         //exit("got url '$url'\n");
     }
     return $this->_xmlEscape($url);
 }
예제 #5
0
 /**
  * Tests the toArray() method
  *
  */
 public function testToArrayMethod()
 {
     $options = array(
         'label'    => 'foo',
         'uri'      => '#',
         'id'       => 'my-id',
         'class'    => 'my-class',
         'title'    => 'my-title',
         'target'   => 'my-target',
         'position' => 100,
         'active'   => true,
         'visible'  => false,
     
         'resource' => 'joker',
         'privilege' => null,
     
         'foo'      => 'bar',
         'meaning'  => 42,
     
         'pages'    => array(
             array(
                 'label' => 'foo.bar',
                 'uri'   => '#'
             ),
             array(
                 'label' => 'foo.baz',
                 'uri'   => '#'
             )
         )
     );
     
     $page = Zym_Navigation_Page::factory($options);
     $toArray = $page->toArray();
     
     // tweak options to what we expect toArray() to contain
     $options['type'] = 'Zym_Navigation_Page_Uri';
     
     // calculate diff between toArray() and $options
     $diff = array_diff_assoc($toArray, $options);
     
     // should be no diff
     $this->assertEquals(array(), $diff);
     
     // $toArray should have 2 sub pages
     $this->assertEquals(2, count($toArray['pages']));
     
     // tweak options to what we expect sub page 1 to be
     $options['label'] = 'foo.bar';
     $options['position'] = null;
     $options['id'] = null;
     $options['class'] = null;
     $options['title'] = null;
     $options['target'] = null;
     $options['resource'] = null;
     $options['active'] = false;
     $options['visible'] = true;
     unset($options['foo']);
     unset($options['meaning']);
     
     // assert that there is no diff from what we expect
     $subPageOneDiff = array_diff_assoc($toArray['pages'][0], $options);
     $this->assertEquals(array(), $subPageOneDiff);
     
     // tweak options to what we expect sub page 2 to be
     $options['label'] = 'foo.baz';
     
     // assert that there is no diff from what we expect
     $subPageTwoDiff = array_diff_assoc($toArray['pages'][1], $options);
     $this->assertEquals(array(), $subPageTwoDiff);
 }
예제 #6
0
 /**
  * When setting new parent for page that already has a parent, it should
  * be removed from the old parent
  *
  */
 public function testSetParentShouldRemoveFromOldParentPage()
 {
     $page1 = Zym_Navigation_Page::factory(array('label' => 'Page 1', 'uri' => '#'));
     $page2 = Zym_Navigation_Page::factory(array('label' => 'Page 2', 'uri' => '#'));
     $page2->setParent($page1);
     $page2->setParent(null);
     $this->assertEquals(null, $page2->getParent());
     $this->assertEquals(false, $page1->hasPages());
 }
예제 #7
0
 /**
  * Returns an array representation of the page
  *
  * @return array
  */
 public function toArray()
 {
     return array_merge(parent::toArray(), array('uri' => $this->getUri()));
 }
예제 #8
0
 /**
  * Adds a page to the container
  * 
  * @param  Zym_Navigation_Page|array|Zend_Config $page  page to add
  * @return Zym_Navigation_Container
  * @throws InvalidArgumentException  if invalid page is given
  */
 public function addPage($page)
 {
     if (is_array($page) || $page instanceof Zend_Config) {
         require_once 'Zym/Navigation/Page.php';
         $page = Zym_Navigation_Page::factory($page);
     } elseif (!$page instanceof Zym_Navigation_Page) {
         $msg = '$page must be Zym_Navigation_Page|array|Zend_Config';
         throw new InvalidArgumentException($msg);
     }
     
     $id = spl_object_hash($page);
     
     if (array_key_exists($id, $this->_order)) {
         return $this;
     }
     
     $this->_pages[$id] = $page;
     $this->_order[$id] = $page->getPosition();
     $this->_orderUpdated = true;
     
     $page->setParent($this);
     
     return $this;
 }
예제 #9
0
<?php

require_once 'Zym/Navigation/Page.php';
class My_Navigation_Page extends Zym_Navigation_Page
{
    protected $_foo;
    protected $_fooBar;
    public function setFoo($foo)
    {
        $this->_foo = $foo;
    }
    public function setFooBar($fooBar)
    {
        $this->_fooBar = $fooBar;
    }
}
// can now construct using
$page = new My_Navigation_Page(array('label' => 'Property names are translated', 'foo' => 'bar', 'foo_bar' => 'baz'));
// ...or
$page = Zym_Navigation_Page::factory(array('type' => 'My_Navigation_Page', 'label' => 'Property names are translated', 'foo' => 'bar', 'foo_bar' => 'baz'));
예제 #10
0
<?php

class My_Navigation_Page extends Zym_Navigation_Page
{
    protected $_fooBar = 'ok';
    public function setFooBar($fooBar)
    {
        $this->_fooBar = $fooBar;
    }
}
$page = Zym_Navigation_Page::factory(array('type' => 'My_Navigation_Page', 'label' => 'My custom page', 'foo_bar' => 'foo bar'));
예제 #11
0
 /**
  * Determines whether a page should be accepted when iterating
  *
  * @param Zym_Navigation_Page $page  page to check
  * @param bool $recursive  [optional] whether it should check recursively
  */
 protected function _accept(Zym_Navigation_Page $page, $recursive = true)
 {
     // accept by default
     $accept = true;
     if (!$page->isVisible($recursive)) {
         // don't accept invisible pages
         $accept = false;
     } elseif (!$this->_acceptAcl($page, $recursive)) {
         // acl is not amused
         $accept = false;
     }
     return $accept;
 }
예제 #12
0
 /**
  * Returns an array representation of the page
  *
  * @return array
  */
 public function toArray()
 {
     return array_merge(parent::toArray(), array('action' => $this->getAction(), 'controller' => $this->getController(), 'module' => $this->getModule(), 'params' => $this->getParams(), 'route' => $this->getRoute(), 'reset_params' => $this->getResetParams()));
 }
예제 #13
0
 /**
  * Determines whether a page should be accepted when iterating
  *
  * @param Zym_Navigation_Page $page  page to verify
  */
 protected function _accept(Zym_Navigation_Page $page, $recursive = true)
 {
     if (!$page->isVisible($recursive)) {
         // don't accept invisible pages
         return false;
     }
     if (null !== $this->_acl) {
         // determine using ACL
         return $this->_acceptAcl($page, $recursive);
     }
     // accept by default
     return true;
 }