78 lines
No EOL
2.5 KiB
PHP
78 lines
No EOL
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Traits;
|
|
|
|
use App\Campagne;
|
|
use App\Coupon;
|
|
use App\Contact;
|
|
use App\Calendrier;
|
|
use App\Mur;
|
|
use App\Statistique;
|
|
use App\Panier;
|
|
use DateTime;
|
|
|
|
trait GraphTrait {
|
|
|
|
// ------ Make Labels
|
|
public function getLabelsForStats($startdate, $enddate){
|
|
// ---- Calcul de l'intervalle en jour
|
|
$datetime1 = new DateTime($startdate);
|
|
$datetime2 = new DateTime($enddate);
|
|
$interval = $datetime1->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)->first();
|
|
if(isset($stat->stat_couponPrinted)){
|
|
$dataCoupon[] = $stat->stat_couponPrinted;
|
|
} 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;
|
|
}
|
|
} |