Skip to content

Commit

Permalink
Update HtmlBreadcrumb.php
Browse files Browse the repository at this point in the history
  • Loading branch information
jcheron committed Jun 17, 2021
1 parent ab2190d commit c627f69
Showing 1 changed file with 64 additions and 50 deletions.
114 changes: 64 additions & 50 deletions Ajax/semantic/html/collections/HtmlBreadcrumb.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php

namespace Ajax\semantic\html\collections;

use Ajax\semantic\html\base\HtmlSemNavElement;
use Ajax\semantic\html\base\HtmlSemDoubleElement;

use Ajax\semantic\html\elements\HtmlIcon;
use Ajax\JsUtils;

Expand All @@ -17,11 +15,13 @@
* @version 1.001
*/
class HtmlBreadcrumb extends HtmlSemNavElement {

/**
*
* @var integer the start index for href generation
*/
protected $startIndex=0;
protected $startIndex = 0;

/**
*
* @var boolean $autoActive sets the last element's class to <b>active</b> if true
Expand All @@ -32,7 +32,7 @@ class HtmlBreadcrumb extends HtmlSemNavElement {
*
* @var boolean if set to true, the path of the elements is absolute
*/
protected $absolutePaths=false;
protected $absolutePaths = false;

/**
*
Expand All @@ -44,31 +44,37 @@ class HtmlBreadcrumb extends HtmlSemNavElement {
*
* @param string $identifier
* @param array $items
* @param boolean $autoActive sets the last element's class to <b>active</b> if true
* @param callable $hrefFunction the function who generates the href elements. default : function($e){return $e->getContent()}
* @param boolean $autoActive
* sets the last element's class to <b>active</b> if true
* @param callable $hrefFunction
* the function who generates the href elements. default : function($e){return $e->getContent()}
*/
public function __construct($identifier, $items=array(), $autoActive=true, $startIndex=0, $hrefFunction=NULL) {
public function __construct($identifier, $items = array(), $autoActive = true, $startIndex = 0, $hrefFunction = NULL) {
parent::__construct($identifier, "div", "ui breadcrumb");
$this->startIndex=$startIndex;
$this->autoActive=$autoActive;
$this->_contentSeparator="<div class='divider'> / </div>";
$this->_hrefFunction=function (HtmlSemDoubleElement $e) {
$this->startIndex = $startIndex;
$this->autoActive = $autoActive;
$this->_contentSeparator = "<div class='divider'> / </div>";
$this->_hrefFunction = function (HtmlSemDoubleElement $e) {
return $e->getContent();
};
if (isset($hrefFunction)) {
$this->_hrefFunction=$hrefFunction;
$this->_hrefFunction = $hrefFunction;
}
$this->addItems($items);
}

/**
* Associate an ajax get to the breadcrumb elements, displayed in $targetSelector
* $this->attr member is used to build each element url
* @param string $targetSelector the target of the get
*
* @param string $targetSelector
* the target of the get
* @return HtmlBreadcrumb
*/
public function autoGetOnClick($targetSelector) {
return $this->getOnClick($this->root, $targetSelector, array ("attr" => $this->attr ));
return $this->getOnClick($this->root, $targetSelector, array(
"attr" => $this->attr
));
}

public function contentAsString() {
Expand All @@ -79,37 +85,41 @@ public function contentAsString() {
}

/**
*
* @param int $index
*/
public function setActive($index=null) {
if (!isset($index)) {
$index=sizeof($this->content) - 1;
public function setActive($index = null) {
if (! isset($index)) {
$index = sizeof($this->content) - 1;
}
$activeItem=$this->content[$index];
$activeItem = $this->content[$index];
$activeItem->addToProperty("class", "active");
$activeItem->setTagName("div");
}

/**
* Adds new elements in breadcrumbs corresponding to request dispatcher : controllerName, actionName, parameters
*
* @param JsUtils $js
* @param object $dispatcher the request dispatcher
* @param object $dispatcher
* the request dispatcher
* @return HtmlBreadcrumb
*/
public function fromDispatcher(JsUtils $js,$dispatcher, $startIndex=0) {
$this->startIndex=$startIndex;
public function fromDispatcher(JsUtils $js, $dispatcher, $startIndex = 0) {
$this->startIndex = $startIndex;
return $this->addItems($js->fromDispatcher($dispatcher));
}

/**
* Returns the url of the element at $index or the breadcrumbs url if $index is ommited
*
* @param int $index
* @param string $separator
* @return string
*/
public function getHref($index=null, $separator="/") {
if (!isset($index)) {
$index=sizeof($this->content);
public function getHref($index = null, $separator = "/") {
if (! isset($index)) {
$index = sizeof($this->content);
}
if ($this->absolutePaths === true) {
return $this->_hrefFunction($this->content[$index]);
Expand All @@ -123,34 +133,35 @@ public function getHref($index=null, $separator="/") {
/**
* sets the function who generates the href elements.
* default : function($element){return $element->getContent()}
*
* @param callable $_hrefFunction
* @return HtmlBreadcrumb
*/
public function setHrefFunction($_hrefFunction) {
$this->_hrefFunction=$_hrefFunction;
$this->_hrefFunction = $_hrefFunction;
return $this;
}

public function setStartIndex($startIndex) {
$this->startIndex=$startIndex;
$this->startIndex = $startIndex;
return $this;
}

public function setAutoActive($autoActive) {
$this->autoActive=$autoActive;
$this->autoActive = $autoActive;
return $this;
}

/*
* (non-PHPdoc)
* @see \Ajax\bootstrap\html\BaseHtml::compile()
*/
public function compile(JsUtils $js=NULL, &$view=NULL) {
public function compile(JsUtils $js = NULL, &$view = NULL) {
if ($this->autoActive) {
$this->setActive();
}
$count=$this->count();
for($i=1; $i < $count; $i++) {
$count = $this->count();
for ($i = 1; $i < $count; $i ++) {
$this->content[$i]->wrap($this->getContentDivider($i - 1));
}
return parent::compile($js, $view);
Expand All @@ -160,16 +171,16 @@ public function compile(JsUtils $js=NULL, &$view=NULL) {
* (non-PHPdoc)
* @see \Ajax\bootstrap\html\base\BaseHtml::on()
*/
public function on($event, $jsCode, $stopPropagation=false, $preventDefault=false) {
foreach ( $this->content as $element ) {
public function on($event, $jsCode, $stopPropagation = false, $preventDefault = false) {
foreach ($this->content as $element) {
$element->on($event, $jsCode, $stopPropagation, $preventDefault);
}
return $this;
}

public function _ajaxOn($operation, $event, $url, $responseElement="", $parameters=array()) {
foreach ( $this->content as $element ) {
if ($element->getProperty($this->attr) != NULL){
public function _ajaxOn($operation, $event, $url, $responseElement = "", $parameters = array()) {
foreach ($this->content as $element) {
if ($element->getProperty($this->attr) != NULL) {
$element->_ajaxOn($operation, $event, $url, $responseElement, $parameters);
}
}
Expand All @@ -178,33 +189,37 @@ public function _ajaxOn($operation, $event, $url, $responseElement="", $paramete

/**
*
* {@inheritDoc}
* {@inheritdoc}
*
* @see \Ajax\common\html\HtmlCollection::createItem()
*/
protected function createItem($value) {
$count=$this->count();
$itemO=new HtmlSemDoubleElement("item-" . $this->identifier . "-" . $count, "a", "section");
if (\is_array($value))
$itemO->fromArray($value);
else {
$count = $this->count();
$itemO = new HtmlSemDoubleElement("item-" . $this->identifier . "-" . $count, "a", "section");
if (\is_array($value)) {
@list ($text, $href) = $value;
$itemO->setContent($text);
$itemO->setProperty('href', $href);
} else {
$itemO->setContent($value);
}
return $itemO;
}

public function addIconAt($icon, $index) {
$item=$this->getItem($index);
$item = $this->getItem($index);
if (isset($item)) {
$icon=new HtmlIcon("icon-" . $this->identifier, $icon);
$icon = new HtmlIcon("icon-" . $this->identifier, $icon);
$item->wrapContent($icon);
}
}

public function addItem($item) {
$count=$this->count();
$itemO=parent::addItem($item);
$this->addToPropertyCtrl("class", "section", array ("section" ));
$count = $this->count();
$itemO = parent::addItem($item);
$this->addToPropertyCtrl("class", "section", array(
"section"
));
$itemO->setProperty($this->attr, $this->getHref($count));
return $itemO;
}
Expand All @@ -214,12 +229,11 @@ public function asTexts() {
}

public function setAbsolutePaths($absolutePaths) {
$this->absolutePaths=$absolutePaths;
$size=\sizeof($this->content);
for($i=0;$i<$size;$i++){
$this->absolutePaths = $absolutePaths;
$size = \sizeof($this->content);
for ($i = 0; $i < $size; $i ++) {
$this->content[$i]->setProperty($this->attr, $this->getHref($i));
}
return $this;
}

}

0 comments on commit c627f69

Please sign in to comment.