ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ProgressMeter.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2017 Ralph Dittrich <dittrich@qualitus.de> Extended GPL, see docs/LICENSE */
4 
6 
7 use ILIAS\UI\Component as C;
9 
14 class ProgressMeter implements C\Chart\ProgressMeter\ProgressMeter
15 {
16  use ComponentHelper;
17 
21  protected $maximum;
22 
26  private $required;
27 
31  protected $main;
32 
36  protected $comparison;
37 
41  public function __construct($maximum, $main, $required = null, $comparison = null)
42  {
43  $this->checkIntArg("maximum", $maximum);
44  $this->maximum = $maximum;
45  $this->checkIntArg("main", $main);
46  $this->main = $this->getSafe($main);
47 
48  if ($required != null) {
49  $this->checkIntArg("required", $required);
50  $this->required = $this->getSafe($required);
51  } else {
52  $this->checkIntArg("required", $maximum);
53  $this->required = $this->getSafe($maximum);
54  }
55  if ($comparison != null) {
56  $this->checkIntArg("comparison", $comparison);
57  $this->comparison = $this->getSafe($comparison);
58  } else {
59  $this->comparison = 0;
60  }
61  }
62 
66  public function getMaximum()
67  {
68  return $this->maximum;
69  }
70 
74  public function getRequired()
75  {
76  return $this->getSafe($this->required);
77  }
78 
84  public function getRequiredAsPercent()
85  {
86  return $this->getAsPercentage($this->required);
87  }
88 
92  public function getMainValue()
93  {
94  return $this->getSafe($this->main);
95  }
96 
102  public function getMainValueAsPercent()
103  {
104  return $this->getAsPercentage($this->main);
105  }
106 
113  protected function getSafe($a_int)
114  {
115  return (($a_int < 0) ? 0 : ($a_int > $this->getMaximum() ? $this->getMaximum() : $a_int));
116  }
117 
124  protected function getAsPercentage($a_int)
125  {
126  return round(100 / $this->getMaximum() * $this->getSafe($a_int), 0, PHP_ROUND_HALF_UP);
127  }
128 }
trait ComponentHelper
Provides common functionality for component implementations.
__construct($maximum, $main, $required=null, $comparison=null)
getSafe($a_int)
Get integer value "1" if a value is negative or "maximum" if value is more then maximum.
checkIntArg($which, $value)
Throw an InvalidArgumentException if $value is no int.
getAsPercentage($a_int)
get an integer value as percent value