From ec2f88ed95285baf49ad02159207d758b5eaafbf Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Fri, 3 Apr 2020 02:27:41 +0200 Subject: summary inclusion min & max setting --- app/class/Summary.php | 139 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 app/class/Summary.php (limited to 'app/class/Summary.php') 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 @@ +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 .= ''; + } + $sumstring .= '
  • ' . $link . '
  • '; + } elseif ($h = $last) { + $sumstring .= '
  • ' . $link . '
  • '; + } + $last = $h; + } + } + for ($i = 1; $i <= ($last); $i++) { + $sumstring .= ''; + } + 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 -- cgit v1.2.3