本文整理汇总了PHP中Zend\Navigation\Page\AbstractPage类的典型用法代码示例。如果您正苦于以下问题:PHP AbstractPage类的具体用法?PHP AbstractPage怎么用?PHP AbstractPage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AbstractPage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: htmlify
/**
* Returns an HTML string containing an 'a' element for the given page
*
* @param AbstractPage $page page to generate HTML for
* @param boolean $hasParent if the breadcrumb has a parent
* @return string
*/
public function htmlify(AbstractPage $page, $hasParent = false)
{
$html = '<li';
if (!$hasParent) {
$html .= ' class="active"';
}
$html .= '>';
$label = $page->getLabel();
if (null !== ($translator = $this->getTranslator())) {
$label = $translator->translate($label, $this->getTranslatorTextDomain());
}
$escaper = $this->view->plugin('escapeHtml');
$label = $escaper($label);
if ($page->getHref() && ($hasParent || !$hasParent && $this->getLinkLast())) {
$anchorAttribs = $this->htmlAttribs(array('href' => $page->getHref()));
$html .= '<a' . $anchorAttribs . '>' . $label . '</a>';
} else {
$html .= $label;
}
if ($hasParent) {
$html .= '<span class="divider">' . $this->getSeparator() . '</span>';
}
$html .= '</li>';
return $html;
}
示例2: decorateDropdown
protected function decorateDropdown($content, \Zend\Navigation\Page\AbstractPage $page, $renderIcons = true, $activeIconInverse = true, array $options = array())
{
//Get attribs
$liAttribs = array('id' => $page->getId(), 'class' => 'dropdown' . ($page->isActive(true) ? ' active' : ''));
$html = "\n" . '<li' . $this->htmlAttribs($liAttribs) . '>' . "\n" . $content . "\n</li>";
return $html;
}
示例3: acceptAcl
/**
* Determines whether a page should be accepted by ACL when iterating
*
* Rules:
* - If helper has no ACL, page is accepted
* - If page has a resource or privilege defined, page is accepted
* if the ACL allows access to it using the helper's role
* - If page has no resource or privilege, page is accepted
*
* @param AbstractPage $page page to check
* @return bool whether page is accepted by ACL
*/
protected function acceptAcl(AbstractPage $page)
{
if (!($acl = $this->getAcl())) {
// no acl registered means don't use acl
return true;
}
$role = $this->getRole();
$roles = $this->getRoles();
$resource = $page->getResource();
if ($resource === NULL) {
return true;
}
$resource = $this->acl->hasResourceOrParent($resource);
if ($resource === false || $resource === NULL) {
return false;
}
if (!$roles) {
$roles = array($role);
}
if ($resource) {
foreach ($roles as $r) {
/**
* TODO: for now this has been set to allow an item if its resource is not found
*/
if (!$acl->hasResource($resource) || $acl->isAllowed($r, $resource)) {
return true;
}
}
return false;
}
return true;
}
示例4: isActive
protected function isActive(AbstractPage $page, $recursive = true)
{
if ($page->get('identifier') != $this->identifier && $recursive) {
foreach ($page->getPages() as $subPage) {
if ($this->isActive($subPage, $recursive)) {
return true;
}
}
return false;
}
return $page->get('identifier') == $this->identifier;
}
示例5: htmlifyLabel
public function htmlifyLabel(AbstractPage $page)
{
$label = $this->translate($page->getLabel(), $page->getTextDomain());
/** @var \Zend\View\Helper\EscapeHtml $escaper */
$escaper = $this->view->plugin('escapeHtml');
$label = $escaper($label);
if (isset($page->icon)) {
$attribs = array('class' => 'fa fa-' . $page->icon);
$label = '<i ' . $this->htmlAttribs($attribs) . '></i> ' . $label;
}
return $label;
}
示例6: getLiClass
/**
* Get list item class.
*
* @param AbstractPage $page
*
* @return string
*/
public function getLiClass(AbstractPage $page)
{
/* @var $escaper \Zend\View\Helper\EscapeHtmlAttr */
$escaper = $this->getView()->plugin('escapeHtmlAttr');
$liClasses = array($this->liClass);
if ($this->getAddClassToListItem()) {
$liClasses[] = $page->getClass();
}
if ($page->hasPages()) {
$liClasses[] = $this->getLiHasMenuClass();
}
if ($page->isActive(true)) {
$liClasses[] = $this->getLiActiveClass();
}
return $escaper(implode(' ', $liClasses));
}
示例7: htmlify
/**
* Returns an HTML string containing an 'a' element for the given page if
* the page's href is not empty, and a 'span' element if it is empty
*
* Overrides {@link AbstractHelper::htmlify()}.
*
* @param AbstractPage $page page to generate HTML for
* @param bool $escapeLabel Whether or not to escape the label
* @param bool $addClassToListItem Whether or not to add the page class to the list item
* @return string
*/
public function htmlify(AbstractPage $page, $escapeLabel = true, $addClassToListItem = false)
{
// get attribs for element
$attribs = array('id' => $page->getId(), 'title' => $page->getTitle());
if ($addClassToListItem === false) {
$attribs['class'] = $page->getClass();
}
// does page have a href?
$href = $page->getHref();
if ('#' !== $href) {
$element = 'a';
$attribs['href'] = $href;
$attribs['target'] = $page->getTarget();
} else {
$element = 'span';
}
$html = '<' . $element . $this->htmlAttribs($attribs) . '>';
$label = $page->getLabel();
//$this->translate(, $page->getTextDomain());
if ($escapeLabel === true) {
/** @var \Zend\View\Helper\EscapeHtml $escaper */
$escaper = $this->view->plugin('escapeHtml');
$html .= $escaper($label);
} else {
$html .= $label;
}
$html .= '</' . $element . '>';
return $html;
}
示例8: testShouldFailIfUnableToDetermineType
public function testShouldFailIfUnableToDetermineType()
{
try {
$page = AbstractPage::factory(array('label' => 'My Invalid Page'));
} catch (Navigation\Exception\InvalidArgumentException $e) {
return;
}
$this->fail('An exception has not been thrown for invalid page type');
}
示例9: indexAction
/**
* Get the feed list and the posts of the feed we are looking at now
*
* @return void
*/
public function indexAction()
{
$viewData = array();
$flashMessenger = $this->flashMessenger();
$username = $this->params()->fromRoute('username');
$currentFeedId = $this->params()->fromRoute('feed_id');
$userData = ApiClient::getUser($username);
if ($userData !== FALSE) {
$hydrator = new ClassMethods();
$user = $hydrator->hydrate($userData, new User());
} else {
$this->getResponse()->setStatusCode(404);
return;
}
$subscribeForm = new SubscribeForm();
$unsubscribeForm = new UnsubscribeForm();
$subscribeForm->setAttribute('action', $this->url()->fromRoute('feeds-subscribe', array('username' => $username)));
$unsubscribeForm->setAttribute('action', $this->url()->fromRoute('feeds-unsubscribe', array('username' => $username)));
$hydrator = new ClassMethods();
$response = ApiClient::getFeeds($username);
$feeds = array();
foreach ($response as $r) {
$feeds[$r['id']] = $hydrator->hydrate($r, new Feed());
}
if ($currentFeedId === null && !empty($feeds)) {
$currentFeedId = reset($feeds)->getId();
}
$feedsMenu = new Navigation();
$router = $this->getEvent()->getRouter();
$routeMatch = $this->getEvent()->getRouteMatch()->setParam('feed_id', $currentFeedId);
foreach ($feeds as $f) {
$feedsMenu->addPage(AbstractPage::factory(array('title' => $f->getTitle(), 'icon' => $f->getIcon(), 'route' => 'feeds', 'routeMatch' => $routeMatch, 'router' => $router, 'params' => array('username' => $username, 'feed_id' => $f->getId()))));
}
$currentFeed = $currentFeedId != null ? $feeds[$currentFeedId] : null;
if ($currentFeed != null) {
$paginator = new Paginator(new ArrayAdapter($currentFeed->getArticles()));
$paginator->setItemCountPerPage(5);
$paginator->setCurrentPageNumber($this->params()->fromRoute('page'));
$viewData['paginator'] = $paginator;
$viewData['feedId'] = $currentFeedId;
}
$unsubscribeForm->get('feed_id')->setValue($currentFeedId);
$viewData['subscribeForm'] = $subscribeForm;
$viewData['unsubscribeForm'] = $unsubscribeForm;
$viewData['username'] = $username;
$viewData['feedsMenu'] = $feedsMenu;
$viewData['user'] = $user;
$viewData['paginator'] = $paginator;
$viewData['feedId'] = $currentFeedId;
$viewData['feed'] = $currentFeed;
$this->layout()->username = $username;
if ($flashMessenger->hasMessages()) {
$viewData['flashMessages'] = $flashMessenger->getMessages();
}
return $viewData;
}
示例10: htmlify
/**
* @override htmlify from the parent/base/super class
*/
public function htmlify(AbstractPage $page, $escapeLabel = true, $addClassToListItem = false)
{
// !!! This method will be executed in the namespace of the class
// !!! But the methods of the super/base class will be executed in its own namespace
// get label and title for translating
$label = $page->getLabel();
$title = $page->getTitle();
// translate label and title?
if (null !== ($translator = $this->getTranslator())) {
$textDomain = $this->getTranslatorTextDomain();
if (is_string($label) && !empty($label)) {
$label = $translator->translate($label, $textDomain);
}
if (is_string($title) && !empty($title)) {
$title = $translator->translate($title, $textDomain);
}
}
// get attribs for element
$attribs = array('id' => $page->getId(), 'title' => $title);
$attribs['class'] = '';
if ($addClassToListItem === false) {
$attribs['class'] = $page->getClass();
}
// Stoyan
$attribs['class'] .= $attribs['class'] ? ' ' : '';
$attribs['class'] .= $page->getAnchorClass();
// echo 'Menu<pre>';
// echo 'Class: ' . $page->getClass();
// echo 'Anchor Class: ' . $page->getAnchorClass();
// print_r($attribs);
// echo '</pre>';
// does page have a href?
$href = $page->getHref();
if ($href) {
$element = 'a';
$attribs['href'] = $href;
$attribs['target'] = $page->getTarget();
} else {
$element = 'span';
}
$html = '<' . $element . $this->htmlAttribs($attribs) . '>';
if ($escapeLabel === true) {
$escaper = $this->view->plugin('escapeHtml');
$html .= $escaper($label);
} else {
$html .= $label;
}
$html .= '</' . $element . '>';
return $html;
}
示例11: acceptAcl
/**
* Determines whether a page should be accepted by ACL when iterating
*
* Rules:
* - If helper has no ACL, page is accepted
* - If page has a resource or privilege defined, page is accepted
* if the ACL allows access to it using the helper's role
* - If page has no resource or privilege, page is accepted
*
* @param AbstractPage $page page to check
* @return bool whether page is accepted by ACL
*/
protected function acceptAcl(AbstractPage $page)
{
if (!($acl = $this->getAcl())) {
// no acl registered means don't use acl
return true;
}
$role = $this->getRole();
$roles = $this->getRoles();
$resource = $page->getResource();
$privilege = $page->getPrivilege();
if (!$roles) {
$roles = array($roles);
}
if ($resource || $privilege) {
foreach ($roles as $r) {
// determine using helper role and page resource/privilege
return $acl->hasResource($resource) && $acl->isAllowed($r, $resource);
}
return false;
}
return true;
}
示例12: testGetChildrenShouldReturnTheCurrentPage
public function testGetChildrenShouldReturnTheCurrentPage()
{
$container = new Navigation\Navigation();
$page = Page\AbstractPage::factory(array('type' => 'uri'));
$container->addPage($page);
$this->assertEquals($page, $container->getChildren());
}
示例13: htmlify
/**
* Returns an HTML string containing an 'a' element for the given page if
* the page's href is not empty, and a 'span' element if it is empty
*
* Overrides {@link AbstractHelper::htmlify()}.
*
* @param AbstractPage $page page to generate HTML for
* @param bool $escapeLabel Whether or not to escape the label
* @return string HTML string for the given page
*/
public function htmlify(AbstractPage $page, $escapeLabel = true)
{
// get label and title for translating
$label = $page->getLabel();
$title = $page->getTitle();
// translate label and title?
if (null !== ($translator = $this->getTranslator())) {
$textDomain = $this->getTranslatorTextDomain();
if (is_string($label) && !empty($label)) {
$label = $translator->translate($label, $textDomain);
}
if (is_string($title) && !empty($title)) {
$title = $translator->translate($title, $textDomain);
}
}
// get attribs for element
$attribs = array('id' => $page->getId(), 'title' => $title, 'class' => $page->getClass());
// does page have a href?
$href = $page->getHref();
if ($href) {
$element = 'a';
$attribs['href'] = $href;
$attribs['target'] = $page->getTarget();
} else {
$element = 'span';
}
$html = '<' . $element . $this->htmlAttribs($attribs) . '>';
if ($escapeLabel === true) {
$escaper = $this->view->plugin('escapeHtml');
$html .= $escaper($label);
} else {
$html .= $label;
}
$html .= '</' . $element . '>';
return $html;
}
示例14: hasPage
/**
* Checks if the container has the given page
*
* @param Page\AbstractPage $page page to look for
* @param bool $recursive [optional] whether to search recursively.
* Default is false.
* @return bool whether page is in container
*/
public function hasPage(Page\AbstractPage $page, $recursive = false)
{
if (array_key_exists($page->hashCode(), $this->index)) {
return true;
} elseif ($recursive) {
foreach ($this->pages as $childPage) {
if ($childPage->hasPage($page, true)) {
return true;
}
}
}
return false;
}
示例15: htmlify
/**
* Returns an HTML string containing an 'a' element for the given page
*
* @param AbstractPage $page page to generate HTML for
* @return string
*/
public function htmlify(AbstractPage $page)
{
// get label and title for translating
$label = $page->getLabel();
$title = $page->getTitle();
if (null !== ($translator = $this->getTranslator())) {
$textDomain = $this->getTranslatorTextDomain();
if (is_string($label) && !empty($label)) {
$label = $translator->translate($label, $textDomain);
}
if (is_string($title) && !empty($title)) {
$title = $translator->translate($title, $textDomain);
}
}
// get attribs for anchor element
$attribs = array('id' => $page->getId(), 'title' => $title, 'class' => $page->getClass(), 'href' => $page->getHref(), 'target' => $page->getTarget());
$escaper = $this->view->plugin('escapeHtml');
return '<a' . $this->htmlAttribs($attribs) . '>' . $escaper($label) . '</a>';
}