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 = ''; $out .= ''; $out .= ''; $out .= ''; return $out; } }