132 lines
5.8 KiB
PHP
132 lines
5.8 KiB
PHP
<?php
|
|
/**
|
|
* Class pour afficher un thermomètre - Conçu pour bootstrap
|
|
* Créer par Jean-Sébastien Proulx
|
|
* Date: 2020-11-20
|
|
* Time: 09:47
|
|
*/
|
|
|
|
namespace clsThermometer;
|
|
|
|
|
|
class clsThermometer {
|
|
private $fltGoal = 0;
|
|
private $fltAmount = 0;
|
|
private $fltProgress = 0;
|
|
|
|
function __construct($fltGoal = 100, $fltAmount = 50) {
|
|
$this->fltGoal = $fltGoal;
|
|
$this->fltAmount = $fltAmount;
|
|
|
|
if (floatval($fltGoal) <= 0) {
|
|
$this->fltGoal = $fltAmount;
|
|
}
|
|
|
|
if (floatval($fltAmount) <= 0) {
|
|
$this->fltProgress = 0;
|
|
} else {
|
|
if (floatval($fltAmount) >= floatval($fltGoal)){
|
|
$this->fltProgress = 100;
|
|
} else {
|
|
$this->fltProgress = floatval($fltAmount) / floatval($fltGoal) * 100;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function fxShow($strOrientation = 'h', $intDecimal = 0, $strFormat = 'money', $strSuffix = '', $strAmountLabel = '', $strGoalLabel = '', $strLanguage = 'fr') {
|
|
$strHTML = $strAmountValue = $strGoalValue = '';
|
|
|
|
switch (trim(strval($strFormat))) {
|
|
case 'money':
|
|
$strAmountValue = $this->fxSetMoney($this->fltAmount, $strLanguage);
|
|
$strGoalValue = $this->fxSetMoney($this->fltGoal, $strLanguage);
|
|
break;
|
|
case 'time':
|
|
$strAmountValue = fxSecondsToTime($this->fltAmount);
|
|
$strGoalValue = fxSecondsToTime($this->fltGoal);
|
|
break;
|
|
case 'distance':
|
|
default:
|
|
$strAmountValue = $this->fxSetNumberFormat($this->fltAmount, $intDecimal, $strLanguage);
|
|
$strGoalValue = $this->fxSetNumberFormat($this->fltGoal, $intDecimal, $strLanguage);
|
|
break;
|
|
}
|
|
|
|
if ($strOrientation == 'h') {
|
|
$strHTML = '
|
|
<div class="mb-5 text-center">
|
|
<div class="row p-2">
|
|
<div class="col-12 col-lg-6 text-left h3">
|
|
' . $strAmountLabel . ': ' . $strAmountValue . $strSuffix . '
|
|
</div>
|
|
<div class="col-12 col-lg-6 text-left text-lg-right h3">
|
|
' . $strGoalLabel . ': ' . $strGoalValue . $strSuffix . '
|
|
</div>
|
|
</div>
|
|
<div class="progress" style="font-size: 1rem; height: 3rem;">
|
|
<span class="badge badge-light d-none">' . round($this->fltProgress) . '%</span>
|
|
<div class="progress-bar bg-danger progress-bar-striped" role="progressbar" style="width: ' . ceil($this->fltProgress) . '%;" aria-valuenow="' . ceil($this->fltProgress) . '" aria-valuemin="0" aria-valuemax="100">
|
|
|
|
</div>
|
|
</div>
|
|
<div class="text-center py-2">
|
|
<span class="h4">
|
|
' . round($this->fltProgress) . '%
|
|
</span>
|
|
</div>
|
|
</div>
|
|
';
|
|
} elseif ($strOrientation == 'v') {
|
|
$strHTML = '
|
|
<div class="mb-5">
|
|
<div class="row justify-content-center">
|
|
<div class="col-12 col-lg-6 text-left h3">
|
|
' . $strAmountLabel . ': ' . $strAmountValue . $strSuffix . '
|
|
</div>
|
|
<div class="col-12 col-lg-6 text-left text-lg-right h3">
|
|
' . $strGoalLabel . ': ' . $strGoalValue . $strSuffix . '
|
|
</div>
|
|
<div class="col-6 col-md-4 col-lg-3">
|
|
<div class=" d-block mx-auto position-relative rounded-pill" style="background-color: #eee; height: 25rem; width: 3rem;">
|
|
<div class="amount bg-danger d-block position-absolute progress-bar-striped rounded-pill" style="bottom: 2rem; height: calc(' . ceil($this->fltProgress) . '% - 2.5rem); left: .5rem; width: 2rem; z-index: 20;"></div>
|
|
</div>
|
|
<div class="d-block mx-auto position-relative rounded-circle" style="background-color: #eee; height: 5rem; top: -3.5rem; width: 5rem;">
|
|
<div class="d-block h5 text-center text-white position-absolute" style="width: 5rem; top: 1.75rem; z-index: 50;">
|
|
' . round($this->fltProgress) . '%
|
|
</div>
|
|
<div class="bg-danger d-block position-absolute progress-bar-striped rounded-circle" style="top: .5rem; height: 4rem; left: .5rem; width: 4rem;"></div>
|
|
<div class="bg-danger d-block position-relative progress-bar-striped" style="height: 1.25rem; width: 2rem; top: .5rem; right: -1.5rem; z-index: 30;">
|
|
<span></span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
';
|
|
}
|
|
|
|
return $strHTML;
|
|
}
|
|
|
|
private function fxSetMoney($strValue, $strLanguage) {
|
|
if ($strLanguage == 'fr') {
|
|
$strValue = number_format($strValue, 2, ',', ' ');
|
|
$strValue .= ' $';
|
|
} else {
|
|
$strValue = number_format($strValue, 2, '.', ',');
|
|
$strValue = '$ ' . $strValue;
|
|
}
|
|
|
|
return $strValue;
|
|
}
|
|
|
|
private function fxSetNumberFormat($strValue, $intDecimal, $strLanguage) {
|
|
if ($strLanguage == 'fr') {
|
|
$strValue = number_format($strValue, intval($intDecimal), ',', ' ');
|
|
} else {
|
|
$strValue = number_format($strValue, intval($intDecimal), '.', ',');
|
|
}
|
|
|
|
return $strValue;
|
|
}
|
|
}
|