ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ProgressMeter.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
23 use ILIAS\UI\Component as C;
25 
30 class ProgressMeter implements C\Chart\ProgressMeter\ProgressMeter
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 }
__construct(int $maximum, int $main, int $required=null, int $comparison=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Factory.php:21