From 8f542ffd024039485d189ce4119ecd0302e156be Mon Sep 17 00:00:00 2001 From: Alessandro Ferro <49845537+xfarrow@users.noreply.github.com> Date: Mon, 7 Mar 2022 12:00:41 +0100 Subject: [PATCH] breadcrumb --- phpxpress/examples/breadcrumb.php | 20 +++++++ phpxpress/phpxpress/breadcrumb.php | 94 ++++++++++++++++++++++++++++++ phpxpress/phpxpress/card.php | 2 +- phpxpress/phpxpress/table.php | 4 +- 4 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 phpxpress/examples/breadcrumb.php create mode 100644 phpxpress/phpxpress/breadcrumb.php diff --git a/phpxpress/examples/breadcrumb.php b/phpxpress/examples/breadcrumb.php new file mode 100644 index 0000000..e2eca44 --- /dev/null +++ b/phpxpress/examples/breadcrumb.php @@ -0,0 +1,20 @@ + + + Card example + + + setDataSource($links); + $breadcrumb->draw(); + + ?> + + \ No newline at end of file diff --git a/phpxpress/phpxpress/breadcrumb.php b/phpxpress/phpxpress/breadcrumb.php new file mode 100644 index 0000000..fe8cfd3 --- /dev/null +++ b/phpxpress/phpxpress/breadcrumb.php @@ -0,0 +1,94 @@ + "xyz.com/home" , "Starred" => "xyz.com/home/starred", "Reading" => "xyz.com/home/starred/reading"); + ** Will produce: + ** Home / Starred / Reading + */ + function setDataSource($dataSource){ + if(!is_array($dataSource)) + throw new InvalidArgumentException('Parameter dataSource must be an array.'); + + foreach($dataSource as $caption => $link){ + $this->addElement($caption, $link); + } + } + + /* + ** Adds an element at the end of the Breadcrumb + */ + function addElement($caption, $link){ + + if(isset($this->locations)) + $this->locations[$caption] = $link; + + else + $this->locations = array($caption => $link); + + $this->activeLocation = $caption; + } + + /* + ** You can specify either a scalar (the (n-1)th to be activated) + ** or a string (the caption to be activated) + */ + function setActiveLocation($activeLocation){ + + if(!is_scalar($activeLocation) && !is_string($activeLocation)) + throw new InvalidArgumentException('Parameter activeLocation can be either an int or a string. None of these provided.'); + + $this->activeLocation = $activeLocation; + } + + function setDivider($divider){ + $this->divider = $divider; + } + + function draw(){ + + $iterator = 0; + + if(!isset($this->divider)) + echo '