Mise à jour de GitLab prévue ce samedi 8 mai 2021 à partir de 9h00 CET | GitLab upgrade planned this Saturday May 4th of 2021 from 9:00 AM CET

Commit 0d5c1b7a authored by Boris Paing's avatar Boris Paing

FIX: mv crowdfunding -> crowdfunding2

parent 69b49bfd
......@@ -4,9 +4,9 @@ $pageTitle = _("Encouragez-nous !");
$pageDescription = _("");
include('cesiumDownloads.php');
require_once('vendor/crowdfunding/Crowdfunding.class.php');
require_once('vendor/crowdfunding/Chart.class.php');
require_once('vendor/crowdfunding/Graph.class.php');
require_once('vendor/crowdfunding2/Crowdfunding.class.php');
require_once('vendor/crowdfunding2/Chart.class.php');
require_once('vendor/crowdfunding2/Graph.class.php');
include('head.php');
......@@ -270,7 +270,7 @@ $amountCumulativeGraph->setStyle('steppedLine', false);
$chart->addGraph($amountCumulativeGraph);
echo $chart->getScripts(LANG, '#chart', $rootURL . '/vendor/crowdfunding/');
echo $chart->getScripts(LANG, '#chart', $rootURL . '/vendor/crowdfunding2/');
?>
......
crowdfunding @ 30700cc1
Subproject commit 30700cc15d7c6864564800696cf1c2caa28832d3
/img/qrcodes/
/tests/
/cache/
<?php
class Avatar {
private $content;
public $contentType;
public function __construct ($content, $contentType) {
$this->content = $content;
$this->contentType = $contentType;
}
public function getContent () {
return $this->content;
}
public function getContentType () {
return $this->contentType;
}
}
<?php
require_once('Graph.class.php');
class Chart {
private $crowdfunding;
private $points = NULL;
private $displayTarget = true;
private $graphs = [];
public function __construct ($crowdfunding) {
$this->crowdfunding = $crowdfunding;
}
private function addLastPointOfCumulativeGraph ($lastAmount) {
$lastDay = NULL;
if ($this->crowdfunding->isOver()) {
$lastDay = $this->crowdfunding->getEndDate();
} elseif ($this->crowdfunding->hasStartedYet()) {
$lastDay = $this->crowdfunding->today;
}
if (isset($lastDay)) {
$followingDay = (clone $lastDay)->add(new DateInterval('P1D'));
$this->points['amountCollectedByDayCumulative'][] = [
't' => $lastDay->getTimestamp() * 1000,
'y' => $this->crowdfunding->convertIntoChosenUnit($lastAmount)
];
$this->points['amountCollectedByDayCumulative'][] = [
't' => $followingDay->getTimestamp() * 1000,
'y' => $this->crowdfunding->convertIntoChosenUnit($lastAmount)
];
}
}
private function addSecondPointOfTarget ($target) {
$d = NULL;
if ($this->crowdfunding->isOver()) {
$d = $this->crowdfunding->getEndDate();
} else {
if (!$this->crowdfunding->isEvergreen()) {
$d = $this->crowdfunding->getEndDate();
} else {
if ($this->crowdfunding->isEvergreen() == 'monthly') {
// last point will be the last day of the month the campaign starts
$dateOfLastDayOfTheMonth = new DateTime($this->crowdfunding->getStartDate()->format("Y-m-t"));
$d = $dateOfLastDayOfTheMonth;
} else { //if ($this->crowdfunding->isEvergreen() == 'forever') {
if ($this->crowdfunding->hasStartedYet()) {
$d = $this->crowdfunding->now;
} else {
$dateOfLastDayOfTheMonth = new DateTime($this->getStartDate()->format("Y-m-t"));
$d = $dateOfLastDayOfTheMonth;
}
}
}
}
$d->add(new DateInterval('P1D'));
$this->points['targetLine'][] = [
't' => $d->getTimestamp() * 1000,
'y' => $target
];
}
public function displayTarget ($bool = NULL) {
if (isset($bool)) {
$this->displayTarget = $bool;
} else {
return $this->displayTarget;
}
}
public function addGraph ($g) {
$this->graphs[] = $g;
}
private function setPoints () {
$dailyAmount = 0;
$dailyAmountCumulative = 0;
$t_0 = (clone $this->crowdfunding->getStartDate());
$mt_0 = $t_0->getTimestamp() * 1000;
if ($this->crowdfunding->hasTarget()) {
// On trace la droite de l'objectif
$this->points['targetLine'][] = [
't' => $mt_0,
'y' => $this->crowdfunding->getTarget()
];
// For x axis scaling
$this->addSecondPointOfTarget($this->crowdfunding->getTarget());
}
/*
$this->points['amountCollectedByDayCumulative'][] = [
't' => $mt_0,
'y' => 0
];
*/
$tx = $this->crowdfunding->getDonationsList();
if (empty($tx)) {
// For y axis scaling
$this->points['amountCollectedByDay'][] = [
't' => $mt_0,
'y' => 0
];
} else {
$currentDay = new DateTime();
$dayBefore = clone $this->crowdfunding->getStartDate();
foreach ($tx as $t) {
$dailyAmountCumulative += $t->getAmount();
$dailyAmount += $t->getAmount();
$currentDay->setTimestamp($t->getDate()->getTimestamp());
$currentDay->setTime(0, 0, 0);
if ($currentDay != $dayBefore) {
$this->points['amountCollectedByDay'][] = [
't' => $dayBefore->getTimestamp() * 1000,
'y' => $this->crowdfunding->convertIntoChosenUnit($dailyAmount)
];
$this->points['amountCollectedByDayCumulative'][] = [
't' => $dayBefore->getTimestamp() * 1000,
'y' => $this->crowdfunding->convertIntoChosenUnit($dailyAmountCumulative)
];
$lastDailyAmount = $dailyAmount;
$dailyAmount = 0;
}
$dayBefore = clone $currentDay;
}
// Add latest day's tx
$this->points['amountCollectedByDay'][] = [
't' => $dayBefore->getTimestamp() * 1000,
'y' => $this->crowdfunding->convertIntoChosenUnit($lastDailyAmount)
];
$this->addLastPointOfCumulativeGraph($dailyAmountCumulative);
}
}
public function getAmountCollectedByDayPoints () {
if (empty($this->points)) {
$this->setPoints();
}
return json_encode($this->points['amountCollectedByDay']);
}
public function getAmountCollectedByDayCumulativePoints () {
if (empty($this->points)) {
$this->setPoints();
}
$points = isset($this->points['amountCollectedByDayCumulative']) ? $this->points['amountCollectedByDayCumulative'] : [];
return json_encode($points);
}
public function getTargetLinePoints () {
if (empty($this->points)) {
$this->setPoints();
}
return json_encode($this->points['targetLine']);
}
public function setTargetLineColor ($colorStr) {
$this->targetLineColor = new Color($colorStr);
}
public function getScripts ($lang, $whereToInsertChart = 'main', $dir = '') {
if (empty($this->points)) {
$this->setPoints();
}
$out = '<script src="'. $dir .'lib/js/moment.min.js"></script>';
$out .= '<script src="'. $dir .'locales/moment.js/'. $lang .'.js"></script>';
$out .= '<script src="'. $dir .'lib/js/chart.min.js"></script>';
$out .= '<script>
window.onload = function() {
moment.locale(\''. $lang .'\');
var currentLocaleData = moment.localeData();
var dateFormat = currentLocaleData.longDateFormat(\'L\');
var hourFormat = currentLocaleData.longDateFormat(\'LT\');
var container = document.querySelector(\''. $whereToInsertChart .'\');
var div = document.createElement(\'div\');
div.classList.add(\'chart-container\');
var canvas = document.createElement(\'canvas\');
div.appendChild(canvas);
container.appendChild(div);
var chartData = {
datasets: [';
foreach ($this->graphs as $g) {
$out .= $g->getGraph() . ', ';
}
$out .= '
]
};
new Chart(canvas.getContext(\'2d\'), {
type: \'bar\',
data: chartData,
options: {
responsive: true,
animation: {
duration: 1800,
easing: \'easeInCubic\'
},
title: {
display: true
},
scales: {
xAxes: [{
type: \'time\',
time: {
minUnit: \'day\',
tooltipFormat: dateFormat
}
}]
},
tooltips: {
intersect: false
}
}
});
}
</script>';
return $out;
}
}
<?php
class Color {
private $hex;
private $rgb;
private $hsl;
private $alpha;
private $validColorsList = [
'white' => 'ffffff',
'silver' => 'C0C0C0',
'gray' => '808080',
'black' => '000000',
'red' => 'FF0000',
'maroon' => '800000',
'yellow' => 'FFFF00',
'olive' => '808000',
'lime' => '00FF00',
'green' => '008000',
'acqua' => '00FFFF',
'cyan' => '00FFFF',
'teal' => '008080',
'blue' => '0000FF',
'navy' => '000080',
'fuchsia' => 'FF00FF',
'magenta' => 'FF00FF',
'purple' => '800080'
];
private $regexes = [
'hex3' => '/^([a-fA-F0-9]{3}){1,2}$/',
'hex6' => '/^#(([a-fA-F0-9]{3}){1,2})$/',
'rgb' => '/^rgb\( *(0?[0-9]{1,2}|1[0-9]{1,2}|2[0-4][0-9]|25[0-5])\, *(0?[0-9]{1,2}|1[0-9]{1,2}|2[0-4][0-9]|25[0-5]), *(0?[0-9]{1,2}|1[0-9]{1,2}|2[0-4][0-9]|25[0-5]) *\)$/',
'rgba' =>'/^hsla\( *(0?[0-9]{1,2}|1[0-9]{1,2}|2[0-4][0-9]|25[0-5])\, *(0?[0-9]{1,2}|1[0-9]{1,2}|2[0-4][0-9]|25[0-5]), (0?[0-9]{1,2}|1[0-9]{1,2}|2[0-4][0-9]|25[0-5])\, *((0\.[0-9]{1,2}|1))\)$/',
'hsl' => '/^hsl\( *(0?[0-9]{1,2}|1[0-9]{1,2}|2[0-4][0-9]|25[0-5])\, *([0-9]{1,3}(\.[0-9]{0,2})?)%, *([0-9]{1,3}(\.[0-9]{0,2})?)% *\)$/',
'hsla' => '/^hsla\( *(0?[0-9]{1,2}|1[0-9]{1,2}|2[0-4][0-9]|25[0-5])\, *([0-9]{1,3}(\.[0-9]{0,2})?)%, *([0-9]{1,3}(\.[0-9]{0,2})?)%\, *((0\.[0-9]{1,2}|1))\)$/',
];
public function __construct ($colorStr) {
if ($colorStr == 'transparent') {
} else if (array_key_exists($colorStr, $this->validColorsList)) {
$this->hex = $this->validColorsList[$colorStr];
} else if (preg_match($this->regexes['hex3'], $colorStr)) {
$this->hex = $colorStr;
} else if (preg_match($this->regexes['hex6'], $colorStr, $matches)) {
$this->hex = $matches[1];
} else if (preg_match($this->regexes['rgb'], $colorStr, $matches)) {
$this->rgb = array(
'r' => $matches[1],
'g' => $matches[2],
'b' => $matches[3],
);
} else if (preg_match($this->regexes['rgba'], $colorStr, $matches)) {
$this->rgb = array(
'r' => $matches[1],
'g' => $matches[2],
'b' => $matches[3],
'a' =>$matches[5],
);
} else if (preg_match($this->regexes['hsl'], $colorStr, $matches)) {
$this->hsl = array(
'h' => $matches[1],
's' => $matches[2],
'l' => $matches[3],
);
} else if (preg_match($this->regexes['hsla'], $colorStr, $matches)) {
$this->hsl = array(
'h' => $matches[1],
's' => $matches[2],
'l' => $matches[3],
'a' => $matches[5],
);
} else {
$additionnalMsg = '';
if(empty($colorStr)) {
$additionnalMsg = _('Les couleurs hexadécimales doivent être écrites sans le caractère #');
} else {
$additionnalMsg = sprintf(_('Vous avez écrit : %s'), htmlspecialchars($colorStr));
}
throw new Exception(_('La couleur %s n\'est pas au bon format.') . "\n" .
$additionnalMsg . "\n" .
_('Vérifiez votre syntaxe.'));
}
}
public function getRGB () {
if (isset($this->rgb)) {
return $this->rgb;
} elseif (isset($this->hex)) {
return $this->hex2RGB($this->hex);
}
}
public function getRGBa () {
if (isset($this->rgba)) {
return $this->rgba;
}
}
public function getHSLa () {
if (isset($this->hsla)) {
return $this->hsla;
}
}
public function getHex () {
if (isset($this->hex)) {
return $this->hex;
} elseif (isset($this->rgb)) {
return $this->RGB2hex($this->rgb);
}
}
public function getColorAllocation ($imgRessource) {
list($r, $g, $b) = $this->getRGB();
return imageColorAllocate($imgRessource, $r, $g, $b);
}
public function RGB2hex () {
}
public function hex2RGB ($hexStr) {
$strLen = strlen($hexStr);
if ($strLen == 6) { //If a proper hex code, convert using bitwise operation. No overhead... faster
$colorVal = hexdec($hexStr);
$r = 0xFF & ($colorVal >> 0x10);
$g = 0xFF & ($colorVal >> 0x8);
$b = 0xFF & $colorVal;
} elseif ($strLen == 3) { //if shorthand notation, need some string manipulations
$r = hexdec(str_repeat(substr($hexStr, 0, 1), 2));
$g = hexdec(str_repeat(substr($hexStr, 1, 1), 2));
$b = hexdec(str_repeat(substr($hexStr, 2, 1), 2));
} else {
throw new Exception(_('Le paramètre %s n\'est pas une couleur.') . "\n" . _('Vérifiez votre syntaxe.'));
}
$this->rgb = array($r, $g, $b);
return $this->rgb;
}