ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ProgressMeter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\UI\Implementation\Component\ComponentHelper;
25
31{
32 use ComponentHelper;
33
34 protected int $maximum;
35 private int $required;
36 protected int $main;
37 protected int $comparison;
38
39 public function __construct(int $maximum, int $main, ?int $required = null, ?int $comparison = null)
40 {
41 $this->maximum = $maximum;
42 $this->main = $this->getSafe($main);
43
44 if ($required != null) {
45 $this->required = $this->getSafe($required);
46 } else {
47 $this->required = $this->getSafe($maximum);
48 }
49 if ($comparison != null) {
50 $this->comparison = $this->getSafe($comparison);
51 } else {
52 $this->comparison = 0;
53 }
54 }
55
59 public function getMaximum()
60 {
61 return $this->maximum;
62 }
63
67 public function getRequired()
68 {
69 return $this->getSafe($this->required);
70 }
71
75 public function getRequiredAsPercent(): int
76 {
77 return $this->getAsPercentage($this->required);
78 }
79
83 public function getMainValue()
84 {
85 return $this->getSafe($this->main);
86 }
87
91 public function getMainValueAsPercent(): int
92 {
93 return $this->getAsPercentage($this->main);
94 }
95
99 protected function getSafe(int $int): int
100 {
101 return (($int < 0) ? 0 : ($int > $this->getMaximum() ? $this->getMaximum() : $int));
102 }
103
107 protected function getAsPercentage(int $int): int
108 {
109 return (int) round(100 / $this->getMaximum() * $this->getSafe($int), 0, PHP_ROUND_HALF_UP);
110 }
111}
getAsPercentage(int $int)
get an integer value as percent value
getSafe(int $int)
Get integer value "1" if a value is negative or "maximum" if value is more than maximum.
__construct(int $maximum, int $main, ?int $required=null, ?int $comparison=null)