diff($datetime2); $days = $interval->format('%a'); // ---- Labels des graphiques $labels = []; for ($i = 0; $i <= $days; $i++) { $date = date('d/m/Y', strtotime("+" . $i . " days", strtotime($startdate))); array_push($labels, $date); } return $labels; } // ---- Data for global graph public function getDataForCamp($labels, $campid) { $dataGlobal = []; foreach ($labels as $label) { $date = date('Y-m-d', strtotime(str_replace('/', '-', $label))); $stat = Statistique::where(['stat_campId' => $campid])->whereDate('created_at', '=', $date)->sum('stat_couponPrinted'); if (isset($stat)) { $dataGlobal[] = $stat; } else { $dataGlobal[] = 0; } } return $dataGlobal; } // ---- Data for one coupon on one camp public function getDataForCoupon($labels, $campid, $coupon) { $dataCoupon = []; foreach ($labels as $label) { $date = date('Y-m-d', strtotime(str_replace('/', '-', $label))); $stat = Statistique::where(['stat_campId' => $campid, 'stat_couponId' => $coupon->coupon_id])->whereDate('created_at', '=', $date)->sum('stat_couponPrinted'); if (isset($stat)) { $dataCoupon[] = $stat; } else { $dataCoupon[] = 0; } } return $dataCoupon; } // ---- Data for one coupon all camp public function getDataForCouponAllCamp($labels, $coupon) { $dataCoupon = []; foreach ($labels as $label) { $date = date('Y-m-d', strtotime(str_replace('/', '-', $label))); $stat = Statistique::where(['stat_couponId' => $coupon->coupon_id])->whereDate('created_at', '=', $date)->sum('stat_couponPrinted'); if (isset($stat)) { $dataCoupon[] = $stat; } else { $dataCoupon[] = 0; } } return $dataCoupon; } }