diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2020-04-03 02:27:41 +0200 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2020-04-03 02:27:41 +0200 |
commit | ec2f88ed95285baf49ad02159207d758b5eaafbf (patch) | |
tree | 82d0ea3e9dd0f243f920a0bc7fd614cda2bd1003 /app/class/Summary.php | |
parent | 55b3aa3552b0627510bce66ff208529c168a2836 (diff) | |
download | wcms-ec2f88ed95285baf49ad02159207d758b5eaafbf.tar.gz wcms-ec2f88ed95285baf49ad02159207d758b5eaafbf.zip |
summary inclusion min & max setting
Diffstat (limited to 'app/class/Summary.php')
-rw-r--r-- | app/class/Summary.php | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/app/class/Summary.php b/app/class/Summary.php new file mode 100644 index 0000000..288ad2d --- /dev/null +++ b/app/class/Summary.php @@ -0,0 +1,139 @@ +<?php + +namespace Wcms; + +class Summary extends Item +{ + /** @var string full regex match */ + protected $fullmatch; + + /** @var string full options code line */ + protected $options = ''; + + /** @var int Minimum summary level*/ + protected $min = 1; + + /** @var int Maximum summary level*/ + protected $max = 6; + + /** @var array Headers datas */ + protected $sum = []; + + + + + + public function __construct(array $datas = []) + { + $this->hydrate($datas); + $this->readoptions(); + } + + + public function readoptions() + { + parse_str($this->options, $datas); + $this->hydrate($datas); + } + + + /** + * Generate a Summary based on header ids. Need to use `$this->headerid` before to scan text + * + * @return string html list with anchor link + */ + public function sumparser() + { + $filteredsum = []; + + foreach ($this->sum as $key => $menu) { + $deepness = array_keys($menu)[0]; + if($deepness >= $this->min && $deepness <= $this->max) { + $filteredsum[$key] = $menu; + } + } + + $sumstring = ''; + $last = 0; + foreach ($filteredsum as $title => $list) { + foreach ($list as $h => $link) { + if ($h > $last) { + for ($i = 1; $i <= ($h - $last); $i++) { + $sumstring .= '<ul>'; + } + $sumstring .= '<li><a href="#' . $title . '">' . $link . '</a></li>'; + } elseif ($h < $last) { + for ($i = 1; $i <= ($last - $h); $i++) { + $sumstring .= '</ul>'; + } + $sumstring .= '<li><a href="#' . $title . '">' . $link . '</a></li>'; + } elseif ($h = $last) { + $sumstring .= '<li><a href="#' . $title . '">' . $link . '</a></li>'; + } + $last = $h; + } + } + for ($i = 1; $i <= ($last); $i++) { + $sumstring .= '</ul>'; + } + return $sumstring; + } + + + + // __________________________________________________ G E T ____________________________________________________________ + + + public function fullmatch() + { + return $this->fullmatch; + } + + public function options() + { + return $this->options; + } + + + // __________________________________________________ S E T ____________________________________________________________ + + + public function setfullmatch(string $fullmatch) + { + $this->fullmatch = $fullmatch; + } + + + public function setoptions(string $options) + { + if (!empty($options)) { + $this->options = $options; + } + } + + public function setmin($min) + { + $min = intval($min); + if($min >= 1 && $min <= 6) { + $this->min = $min; + } + } + + public function setmax($max) + { + $max = intval($max); + if($max >= 1 && $max <= 6) { + $this->max = $max; + } + } + + public function setsum(array $sum) + { + $this->sum = $sum; + } + +} + + + +?>
\ No newline at end of file |