partial #1464
This commit is contained in:
parent
2891148001
commit
c8b1086fcd
@ -12,21 +12,81 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
|||||||
|
|
||||||
$this->chart = new Crunchbutton_Chart;
|
$this->chart = new Crunchbutton_Chart;
|
||||||
|
|
||||||
$query = '';
|
|
||||||
$union = '';
|
|
||||||
|
|
||||||
switch ( $this->chartId ) {
|
switch ( $this->chartId ) {
|
||||||
|
|
||||||
case 'new-users-per-week':
|
/* Users */
|
||||||
|
case 'users-reclaimed-per-week':
|
||||||
|
$chart = new Crunchbutton_Chart_User();
|
||||||
|
$this->renderColumn( $chart->reclaimedByWeek( true ) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'users-active-per-week':
|
||||||
|
$chart = new Crunchbutton_Chart_User();
|
||||||
|
$this->renderColumn( $chart->activeByWeek( true ) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'users-new-per-day':
|
||||||
|
$chart = new Crunchbutton_Chart_User();
|
||||||
|
$this->renderColumn( $chart->newByDay( true ) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'users-new-per-week':
|
||||||
$chart = new Crunchbutton_Chart_User();
|
$chart = new Crunchbutton_Chart_User();
|
||||||
$this->renderColumn( $chart->newByWeek( true ) );
|
$this->renderColumn( $chart->newByWeek( true ) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'new-users-per-month':
|
case 'users-new-per-month':
|
||||||
$chart = new Crunchbutton_Chart_User();
|
$chart = new Crunchbutton_Chart_User();
|
||||||
$this->renderColumn( $chart->newByMonth( true ) );
|
$this->renderColumn( $chart->newByMonth( true ) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'users-active-per-month':
|
||||||
|
$chart = new Crunchbutton_Chart_User();
|
||||||
|
$this->renderColumn( $chart->activeByMonth( true ) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'users-new-per-active-users-per-week':
|
||||||
|
$chart = new Crunchbutton_Chart_User();
|
||||||
|
$this->renderColumn( $chart->newPerActiveByWeek( true ) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'users-new-per-active-users-per-month':
|
||||||
|
$chart = new Crunchbutton_Chart_User();
|
||||||
|
$this->renderColumn( $chart->newPerActiveByMonth( true ) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'users-unique-per-week':
|
||||||
|
$chart = new Crunchbutton_Chart_User();
|
||||||
|
$this->renderColumn( $chart->uniqueByWeek( true ) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'users-unique-per-month':
|
||||||
|
$chart = new Crunchbutton_Chart_User();
|
||||||
|
$this->renderColumn( $chart->uniqueByMonth( true ) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'users-new-per-week-by-community':
|
||||||
|
$chart = new Crunchbutton_Chart_User();
|
||||||
|
$this->renderColumn( $chart->newByWeekByCommunity( true ) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'users-active-per-week-by-community':
|
||||||
|
$chart = new Crunchbutton_Chart_User();
|
||||||
|
$this->renderColumn( $chart->activeByWeekByCommunity( true ) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'users-new-per-active-users-by-community':
|
||||||
|
$chart = new Crunchbutton_Chart_User();
|
||||||
|
$this->renderColumn( $chart->newPerActiveByWeekByCommunity( true ) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'users-unique-per-week-by-community':
|
||||||
|
$chart = new Crunchbutton_Chart_User();
|
||||||
|
$this->renderColumn( $chart->uniqueByWeekByCommunity( true ) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Revenue */
|
||||||
|
|
||||||
case 'gross-revenue-per-week':
|
case 'gross-revenue-per-week':
|
||||||
$chart = new Crunchbutton_Chart_Revenue();
|
$chart = new Crunchbutton_Chart_Revenue();
|
||||||
$this->renderColumn( $chart->byWeek( true ) );
|
$this->renderColumn( $chart->byWeek( true ) );
|
||||||
@ -37,35 +97,7 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
|||||||
$this->renderColumn( $chart->byMonth( true ) );
|
$this->renderColumn( $chart->byMonth( true ) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'active-users-per-week':
|
/* Orders */
|
||||||
$chart = new Crunchbutton_Chart_User();
|
|
||||||
$this->renderColumn( $chart->activeByWeek( true ) );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'active-users-per-month':
|
|
||||||
$chart = new Crunchbutton_Chart_User();
|
|
||||||
$this->renderColumn( $chart->activeByMonth( true ) );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'new-users-per-active-users-per-week':
|
|
||||||
$chart = new Crunchbutton_Chart_User();
|
|
||||||
$this->renderColumn( $chart->newPerActiveByWeek( true ) );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'new-users-per-active-users-per-month':
|
|
||||||
$chart = new Crunchbutton_Chart_User();
|
|
||||||
$this->renderColumn( $chart->newPerActiveByMonth( true ) );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'unique-users-per-week':
|
|
||||||
$chart = new Crunchbutton_Chart_User();
|
|
||||||
$this->renderColumn( $chart->uniqueByWeek( true ) );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'unique-users-per-month':
|
|
||||||
$chart = new Crunchbutton_Chart_User();
|
|
||||||
$this->renderColumn( $chart->uniqueByMonth( true ) );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'orders-by-user-per-week':
|
case 'orders-by-user-per-week':
|
||||||
$chart = new Crunchbutton_Chart_Order();
|
$chart = new Crunchbutton_Chart_Order();
|
||||||
@ -92,61 +124,39 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
|||||||
$this->renderColumn( $order->byWeekPerCommunity( true ) );
|
$this->renderColumn( $order->byWeekPerCommunity( true ) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'new-users-per-week-by-community':
|
|
||||||
$chart = new Crunchbutton_Chart_User();
|
|
||||||
$this->renderColumn( $chart->newByWeekByCommunity( true ) );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'active-users-per-week-by-community':
|
|
||||||
$chart = new Crunchbutton_Chart_User();
|
|
||||||
$this->renderColumn( $chart->activeByWeekByCommunity( true ) );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'new-users-per-active-users-by-community':
|
|
||||||
$chart = new Crunchbutton_Chart_User();
|
|
||||||
$this->renderColumn( $chart->newPerActiveByWeekByCommunity( true ) );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'unique-users-per-week-by-community':
|
|
||||||
$chart = new Crunchbutton_Chart_User();
|
|
||||||
$this->renderColumn( $chart->uniqueByWeekByCommunity( true ) );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'orders-by-weekday-by-community':
|
case 'orders-by-weekday-by-community':
|
||||||
$order = new Crunchbutton_Chart_Order();
|
$order = new Crunchbutton_Chart_Order();
|
||||||
$this->renderArea( $order->byWeekdayByCommunity( true ) );
|
$this->renderArea( $order->byWeekdayByCommunity( true ) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'repeat-orders-per-active-user':
|
case 'orders-repeat-per-active-user':
|
||||||
$order = new Crunchbutton_Chart_Order();
|
$order = new Crunchbutton_Chart_Order();
|
||||||
$this->renderColumn( $order->repeatByActiveuserByWeek( true ) );
|
$this->renderColumn( $order->repeatByActiveuserByWeek( true ) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'reclaimed-users-per-week':
|
/* Churn */
|
||||||
$chart = new Crunchbutton_Chart_User();
|
|
||||||
$this->renderColumn( $chart->reclaimedByWeek( true ) );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'churn-rate-per-active-user-per-month':
|
case 'churn-rate-per-active-user-per-month':
|
||||||
$chart = new Crunchbutton_Chart_Churn();
|
$chart = new Crunchbutton_Chart_Churn();
|
||||||
$this->renderColumn( $chart->activeByMonth( true ) );
|
$this->renderColumn( $chart->activeByMonth( true ) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'churn-rate-per-active-user-per-week':
|
case 'churn-rate-per-active-user-per-week':
|
||||||
$chart = new Crunchbutton_Chart_Churn();
|
$chart = new Crunchbutton_Chart_Churn();
|
||||||
$this->renderColumn( $chart->activeByWeek( true ) );
|
$this->renderColumn( $chart->activeByWeek( true ) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'churn-rate-per-week':
|
case 'churn-rate-per-week':
|
||||||
$chart = new Crunchbutton_Chart_Churn();
|
$chart = new Crunchbutton_Chart_Churn();
|
||||||
$this->renderColumn( $chart->byWeek( true ) );
|
$this->renderColumn( $chart->byWeek( true ) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'churn-rate-per-month':
|
case 'churn-rate-per-month':
|
||||||
$chart = new Crunchbutton_Chart_Churn();
|
$chart = new Crunchbutton_Chart_Churn();
|
||||||
$this->renderColumn( $chart->byMonth( true ) );
|
$this->renderColumn( $chart->byMonth( true ) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* Others */
|
||||||
case 'weeks':
|
case 'weeks':
|
||||||
echo $this->chart->weeksToJson();
|
echo $this->chart->weeksToJson();
|
||||||
break;
|
break;
|
||||||
@ -178,11 +188,14 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
|||||||
'from' => $this->chart->from,
|
'from' => $this->chart->from,
|
||||||
'to_month' => $this->chart->to_month,
|
'to_month' => $this->chart->to_month,
|
||||||
'from_month' => $this->chart->from_month,
|
'from_month' => $this->chart->from_month,
|
||||||
|
'to_day' => $this->chart->to_day,
|
||||||
|
'from_day' => $this->chart->from_day,
|
||||||
'months' => $months,
|
'months' => $months,
|
||||||
'number' => $this->number,
|
'number' => $this->number,
|
||||||
'unit' => $params[ 'unit' ] ,
|
'unit' => $params[ 'unit' ] ,
|
||||||
'totalWeeks' => $this->chart->totalWeeks(),
|
'totalWeeks' => $this->chart->totalWeeks(),
|
||||||
'totalMonths' => $this->chart->totalMonths()
|
'totalMonths' => $this->chart->totalMonths(),
|
||||||
|
'totalDays' => $this->chart->totalDays(),
|
||||||
]]);
|
]]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -42,8 +42,9 @@ class Controller_home extends Crunchbutton_Controller_Account {
|
|||||||
'month' => 'Month',
|
'month' => 'Month',
|
||||||
),
|
),
|
||||||
/* OK */
|
/* OK */
|
||||||
'new-users-per-' => array(
|
'users-new-per-' => array(
|
||||||
'_title' => 'New Users per',
|
'_title' => 'New Users per',
|
||||||
|
'day' => 'Day',
|
||||||
'week' => 'Week',
|
'week' => 'Week',
|
||||||
'month' => 'Month',
|
'month' => 'Month',
|
||||||
),
|
),
|
||||||
@ -54,13 +55,13 @@ class Controller_home extends Crunchbutton_Controller_Account {
|
|||||||
'month' => 'Month',
|
'month' => 'Month',
|
||||||
),
|
),
|
||||||
/* OK */
|
/* OK */
|
||||||
'active-users-per-' => array(
|
'users-active-per-' => array(
|
||||||
'_title' => 'Active users per',
|
'_title' => 'Active users per',
|
||||||
'week' => 'Week',
|
'week' => 'Week',
|
||||||
'month' => 'Month',
|
'month' => 'Month',
|
||||||
),
|
),
|
||||||
/* OK */
|
/* OK */
|
||||||
'unique-users-per-' => array(
|
'users-unique-per-' => array(
|
||||||
'_title' => 'Unique Users per',
|
'_title' => 'Unique Users per',
|
||||||
'week' => 'Week',
|
'week' => 'Week',
|
||||||
'month' => 'Month',
|
'month' => 'Month',
|
||||||
@ -72,7 +73,7 @@ class Controller_home extends Crunchbutton_Controller_Account {
|
|||||||
'month' => 'Month',
|
'month' => 'Month',
|
||||||
),
|
),
|
||||||
/* OK */
|
/* OK */
|
||||||
'new-users-per-active-users-per-' => array(
|
'users-new-per-active-users-per-' => array(
|
||||||
'_title' => 'New Users per Active Users per',
|
'_title' => 'New Users per Active Users per',
|
||||||
'week' => 'Week',
|
'week' => 'Week',
|
||||||
'month' => 'Month',
|
'month' => 'Month',
|
||||||
@ -90,12 +91,12 @@ class Controller_home extends Crunchbutton_Controller_Account {
|
|||||||
'month' => 'Month',
|
'month' => 'Month',
|
||||||
),
|
),
|
||||||
|
|
||||||
'active-users-per-week-by-community' => 'Active Users per Week by Community',
|
'users-active-per-week-by-community' => 'Active Users per Week by Community',
|
||||||
'new-users-per-week-by-community' => 'New Users per Week by Community',
|
'users-new-per-week-by-community' => 'New Users per Week by Community',
|
||||||
'new-users-per-active-users-by-community' => 'New Users per Active Users By Community',
|
'users-new-per-active-users-by-community' => 'New Users per Active Users By Community',
|
||||||
'unique-users-per-week-by-community' => 'Unique Users per Week by Community',
|
'users-unique-per-week-by-community' => 'Unique Users per Week by Community',
|
||||||
'repeat-orders-per-active-user' => 'Repeat Orders per Active User',
|
'orders-repeat-per-active-user' => 'Repeat Orders per Active User',
|
||||||
'reclaimed-users-per-week' => 'Reclaimed Users per Week',
|
'users-reclaimed-per-week' => 'Reclaimed Users per Week',
|
||||||
),
|
),
|
||||||
'Tracking Marketing Efforts' => array(
|
'Tracking Marketing Efforts' => array(
|
||||||
'active-users-per-week' => 'Active Users per Week',
|
'active-users-per-week' => 'Active Users per Week',
|
||||||
|
|||||||
@ -22,15 +22,34 @@ class Crunchbutton_Chart extends Cana_Model {
|
|||||||
|
|
||||||
$this->activeUsersInterval = ( $_REQUEST[ 'activeUserDays' ] ? $_REQUEST[ 'activeUserDays' ] : $this->activeUsersInterval );
|
$this->activeUsersInterval = ( $_REQUEST[ 'activeUserDays' ] ? $_REQUEST[ 'activeUserDays' ] : $this->activeUsersInterval );
|
||||||
|
|
||||||
|
$this->allDays = $this->allDays();
|
||||||
|
$this->allWeeks = $this->allWeeks();
|
||||||
|
$this->allMonths = $this->allMonths();
|
||||||
|
|
||||||
switch ( $interval ) {
|
switch ( $interval ) {
|
||||||
|
|
||||||
|
case 'day':
|
||||||
|
|
||||||
|
$this->from_day = ( $_REQUEST[ 'from' ] ? $_REQUEST[ 'from' ] : 1 );
|
||||||
|
$this->from_day = ( ( $this->from_day < 1 ) ? 1 : $this->from_day );
|
||||||
|
$this->to_day = ( $_REQUEST[ 'to' ] ? $_REQUEST[ 'to' ] : 1 );
|
||||||
|
|
||||||
|
$this->dayFrom = $this->allDays[ $this->from_day - 1 ];
|
||||||
|
$this->dayTo = $this->allDays[ $this->to_day - 1 ];
|
||||||
|
|
||||||
|
$this->from = array_search( $this->dayToWeek( $this->monthFrom ), $this->allWeeks() );
|
||||||
|
$this->to = array_search( $this->dayToWeek( $this->monthTo ), $this->allWeeks() );
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
case 'month':
|
case 'month':
|
||||||
|
|
||||||
$this->from_month = ( $_REQUEST[ 'from' ] ? $_REQUEST[ 'from' ] : 1 );
|
$this->from_month = ( $_REQUEST[ 'from' ] ? $_REQUEST[ 'from' ] : 1 );
|
||||||
$this->from_month = ( ( $this->from_month < 1 ) ? 1 : $this->from_month );
|
$this->from_month = ( ( $this->from_month < 1 ) ? 1 : $this->from_month );
|
||||||
$this->to_month = ( $_REQUEST[ 'to' ] ? $_REQUEST[ 'to' ] : 1 );
|
$this->to_month = ( $_REQUEST[ 'to' ] ? $_REQUEST[ 'to' ] : 1 );
|
||||||
|
|
||||||
$this->monthFrom = $this->allMonths()[ $this->from_month - 1 ];
|
$this->monthFrom = $this->allMonths[ $this->from_month - 1 ];
|
||||||
$this->monthTo = $this->allMonths()[ $this->to_month - 1 ];
|
$this->monthTo = $this->allMonths[ $this->to_month - 1 ];
|
||||||
|
|
||||||
$this->from = array_search( $this->monthToWeek( $this->monthFrom ), $this->allWeeks() );
|
$this->from = array_search( $this->monthToWeek( $this->monthFrom ), $this->allWeeks() );
|
||||||
$this->to = array_search( $this->monthToWeek( $this->monthTo ), $this->allWeeks() );
|
$this->to = array_search( $this->monthToWeek( $this->monthTo ), $this->allWeeks() );
|
||||||
@ -39,21 +58,42 @@ class Crunchbutton_Chart extends Cana_Model {
|
|||||||
|
|
||||||
case 'week':
|
case 'week':
|
||||||
default:
|
default:
|
||||||
|
|
||||||
$this->from = ( $_REQUEST[ 'from' ] ? $_REQUEST[ 'from' ] : 1 );
|
$this->from = ( $_REQUEST[ 'from' ] ? $_REQUEST[ 'from' ] : 1 );
|
||||||
$this->from = ( ( $this->from < 1 ) ? 1 : $this->from );
|
$this->from = ( ( $this->from < 1 ) ? 1 : $this->from );
|
||||||
$this->to = ( $_REQUEST[ 'to' ] ? $_REQUEST[ 'to' ] : $this->totalWeeks() );
|
$this->to = ( $_REQUEST[ 'to' ] ? $_REQUEST[ 'to' ] : $this->totalWeeks() );
|
||||||
|
|
||||||
$this->weekFrom = $this->allWeeks()[ $this->from - 1 ];
|
$this->weekFrom = $this->allWeeks[ $this->from - 1 ];
|
||||||
$this->weekTo = $this->allWeeks()[ $this->to - 1 ];
|
$this->weekTo = $this->allWeeks[ $this->to - 1 ];
|
||||||
|
|
||||||
$this->from_month = array_search( $this->weekToMonth( $this->weekFrom ), $this->allMonths() );
|
$this->from_month = array_search( $this->weekToMonth( $this->weekFrom ), $this->allMonths() );
|
||||||
$this->to_month = array_search( $this->weekToMonth( $this->weekTo ), $this->allMonths() );
|
$this->to_month = array_search( $this->weekToMonth( $this->weekTo ), $this->allMonths() );
|
||||||
|
|
||||||
$this->monthFrom = $this->allMonths()[ $this->from_month ];
|
$this->monthFrom = $this->allMonths()[ $this->from_month ];
|
||||||
$this->monthTo = $this->allMonths()[ $this->to_month ];
|
$this->monthTo = $this->allMonths[ $this->to_month ];
|
||||||
|
|
||||||
$this->from_month++;
|
$this->from_month++;
|
||||||
$this->to_month++;
|
$this->to_month++;
|
||||||
|
|
||||||
|
$this->from_day = array_search( $this->weekToDay( $this->weekFrom ), $this->allDays() );
|
||||||
|
$this->to_day = array_search( $this->weekToDay( $this->weekTo ), $this->allDays() );
|
||||||
|
|
||||||
|
if( $this->from_day ){
|
||||||
|
$this->dayFrom = $this->allDays[ $this->from_day ];
|
||||||
|
$this->from_day++;
|
||||||
|
} else {
|
||||||
|
$this->dayFrom = $this->allDays()[ 0 ];
|
||||||
|
$this->from_day = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( $this->to_day ){
|
||||||
|
$this->dayTo = $this->allDays[ $this->to_day ];
|
||||||
|
$this->to_day++;
|
||||||
|
} else {
|
||||||
|
$this->dayTo = $this->allDays[ $this->totalDays() - 1 ];
|
||||||
|
$this->to_day = $this->totalDays() + 1;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,6 +138,11 @@ class Crunchbutton_Chart extends Cana_Model {
|
|||||||
return $days;
|
return $days;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function totalDays(){
|
||||||
|
$days = $this->allDays();
|
||||||
|
return sizeof( $days );
|
||||||
|
}
|
||||||
|
|
||||||
public function allWeeks(){
|
public function allWeeks(){
|
||||||
if( !$this->_weeks ){
|
if( !$this->_weeks ){
|
||||||
$query = "SELECT DISTINCT( YEARWEEK( o.date ) ) week FROM `order` o WHERE YEARWEEK( o.date ) IS NOT NULL ORDER BY week ASC";
|
$query = "SELECT DISTINCT( YEARWEEK( o.date ) ) week FROM `order` o WHERE YEARWEEK( o.date ) IS NOT NULL ORDER BY week ASC";
|
||||||
@ -114,6 +159,11 @@ class Crunchbutton_Chart extends Cana_Model {
|
|||||||
return $this->_weeks;
|
return $this->_weeks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function totalWeeks(){
|
||||||
|
$weeks = $this->allWeeks();
|
||||||
|
return sizeof( $weeks );
|
||||||
|
}
|
||||||
|
|
||||||
public function weeksToJson(){
|
public function weeksToJson(){
|
||||||
$allWeeks = $this->allWeeks();
|
$allWeeks = $this->allWeeks();
|
||||||
$weeks = [];
|
$weeks = [];
|
||||||
@ -123,19 +173,23 @@ class Crunchbutton_Chart extends Cana_Model {
|
|||||||
return json_encode( $weeks );
|
return json_encode( $weeks );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function totalWeeks(){
|
public function weekToMonth( $week ){
|
||||||
$weeks = $this->allWeeks();
|
return date( 'Y-m', strtotime( 'sunday ' . substr( $week, 0, 4 ) . 'W' . substr( $week, 4, 2 ) ) );
|
||||||
return sizeof( $weeks );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function weekToMonth( $week ){
|
public function weekToDay( $week, $day = 'first' ){
|
||||||
return date( 'Y-m', strtotime( substr( $week, 0, 4 ) . 'W' . substr( $week, 4, 2 ) . ' Sunday' ) );
|
$day = ( $day == 'first' ) ? '-0' : '-6';
|
||||||
|
return date( 'Y-m-d', strtotime( substr( $week, 0, 4 ) . 'W' . substr( $week, 4, 2 ) . $day ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function monthToWeek( $month ){
|
public function monthToWeek( $month ){
|
||||||
return date( 'YW', strtotime( $month . '-01' ) );
|
return date( 'YW', strtotime( $month . '-01' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function dayToWeek( $day ){
|
||||||
|
return date( 'YW', strtotime( $day ) );
|
||||||
|
}
|
||||||
|
|
||||||
public function getMonthsFromWeeks(){
|
public function getMonthsFromWeeks(){
|
||||||
$months = [];
|
$months = [];
|
||||||
$allWeeks = $this->allWeeks();
|
$allWeeks = $this->allWeeks();
|
||||||
@ -155,9 +209,32 @@ class Crunchbutton_Chart extends Cana_Model {
|
|||||||
|
|
||||||
public function parseWeek( $week, $showYear = false ){
|
public function parseWeek( $week, $showYear = false ){
|
||||||
$dateStr = ( $showYear ) ? 'M d Y' : 'M d';
|
$dateStr = ( $showYear ) ? 'M d Y' : 'M d';
|
||||||
return date( $dateStr, strtotime( substr( $week, 0, 4 ) . 'W' . substr( $week, 4, 2 ) . '-7' ) );
|
return date( $dateStr, strtotime( substr( $week, 0, 4 ) . 'W' . substr( $week, 4, 2 ) . '-0' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function parseDay( $day, $showYear = false ){
|
||||||
|
$dateStr = ( $showYear ) ? 'M d Y' : 'M d';
|
||||||
|
return date( $dateStr, strtotime( $day ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function parseDataDaysSimple( $query, $type = 'Total' ){
|
||||||
|
|
||||||
|
$data = c::db()->get( $query );
|
||||||
|
|
||||||
|
$_days = [];
|
||||||
|
foreach ( $data as $item ) {
|
||||||
|
$_days[ $item->Day ] = $item->Total;
|
||||||
|
}
|
||||||
|
|
||||||
|
$allDays = $this->allDays();
|
||||||
|
$data = [];
|
||||||
|
for( $i = $this->from_day -1 ; $i < $this->to_day; $i++ ){
|
||||||
|
$day = $allDays[ $i ];
|
||||||
|
$total = ( $_days[ $day ] ) ? $_days[ $day ] : 0;
|
||||||
|
$data[] = ( object ) array( 'Label' => $this->parseDay( $day ), 'Total' => $total, 'Type' => $type );
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
public function parseDataWeeksSimple( $query, $type = 'Total' ){
|
public function parseDataWeeksSimple( $query, $type = 'Total' ){
|
||||||
|
|
||||||
|
|||||||
@ -44,31 +44,21 @@ class Crunchbutton_Chart_User extends Crunchbutton_Chart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function newByMonth( $render = false ){
|
public function newByMonth( $render = false ){
|
||||||
$query = '';
|
|
||||||
$union = '';
|
|
||||||
|
|
||||||
$allMonths = $this->allMonths();
|
|
||||||
|
|
||||||
for( $i = $this->from_month -1 ; $i < $this->to_month; $i++ ){
|
|
||||||
$month = $allMonths[ $i ];
|
|
||||||
$query .= $union . "SELECT '{$month}' AS Month,
|
|
||||||
COUNT(*) AS Total
|
|
||||||
FROM
|
|
||||||
(SELECT COUNT(*) orders,
|
|
||||||
u.phone,
|
|
||||||
o.date,
|
|
||||||
u.id_user
|
|
||||||
FROM `order` o
|
|
||||||
INNER JOIN user u ON u.id_user = o.id_user
|
|
||||||
LEFT JOIN community c ON o.id_community = c.id_community
|
|
||||||
WHERE o.date <= LAST_DAY( STR_TO_DATE( '{$month}', '%Y-%m' ) )
|
|
||||||
{$this->queryExcludeCommunties}
|
|
||||||
{$this->queryExcludeUsers}
|
|
||||||
GROUP BY u.phone HAVING orders = 1) Orders
|
|
||||||
WHERE Orders.date BETWEEN '{$month}-01' AND LAST_DAY( STR_TO_DATE( '{$month}', '%Y-%m' ) )";
|
|
||||||
$union = ' UNION ';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
$query = "SELECT SUM(1) AS Total,
|
||||||
|
DATE_FORMAT(o.date ,'%Y-%m') AS Month
|
||||||
|
FROM `order` o
|
||||||
|
INNER JOIN
|
||||||
|
(SELECT min(id_order) id_order,
|
||||||
|
u.phone
|
||||||
|
FROM `order` o
|
||||||
|
INNER JOIN USER u ON u.id_user = o.id_user
|
||||||
|
LEFT JOIN community c ON o.id_community = c.id_community
|
||||||
|
{$this->queryExcludeCommunties}
|
||||||
|
{$this->queryExcludeUsers}
|
||||||
|
GROUP BY u.phone) orders ON o.id_order = orders.id_order
|
||||||
|
GROUP BY DATE_FORMAT(o.date ,'%Y-%m') HAVING Month BETWEEN '{$this->monthFrom}' AND '{$this->monthTo}'";
|
||||||
|
|
||||||
$parsedData = $this->parseDataMonthSimple( $query, $this->description );
|
$parsedData = $this->parseDataMonthSimple( $query, $this->description );
|
||||||
if( $render ){
|
if( $render ){
|
||||||
return array( 'data' => $parsedData, 'unit' => $this->unity, 'interval' => 'month' );
|
return array( 'data' => $parsedData, 'unit' => $this->unity, 'interval' => 'month' );
|
||||||
@ -167,39 +157,45 @@ class Crunchbutton_Chart_User extends Crunchbutton_Chart {
|
|||||||
return $parsedData;
|
return $parsedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function newByDay( $render = false ){
|
||||||
|
$query = "SELECT SUM(1) AS Total,
|
||||||
|
DATE_FORMAT(o.date ,'%Y-%m-%d') AS Day
|
||||||
|
FROM `order` o
|
||||||
|
INNER JOIN
|
||||||
|
(SELECT min(id_order) id_order,
|
||||||
|
u.phone
|
||||||
|
FROM `order` o
|
||||||
|
INNER JOIN USER u ON u.id_user = o.id_user
|
||||||
|
LEFT JOIN community c ON o.id_community = c.id_community
|
||||||
|
GROUP BY u.phone) orders ON o.id_order = orders.id_order
|
||||||
|
GROUP BY DATE_FORMAT(o.date ,'%Y-%m-%d') HAVING Day BETWEEN '{$this->dayFrom}' AND '{$this->dayTo}'";
|
||||||
|
|
||||||
|
$parsedData = $this->parseDataDaysSimple( $query, $this->description );
|
||||||
|
if( $render ){
|
||||||
|
return array( 'data' => $parsedData, 'unit' => $this->unity, 'interval' => 'day' );
|
||||||
|
}
|
||||||
|
return $parsedData;
|
||||||
|
}
|
||||||
|
|
||||||
public function newByWeek( $render = false ){
|
public function newByWeek( $render = false ){
|
||||||
|
|
||||||
$query = '';
|
$query = "SELECT SUM(1) AS Total,
|
||||||
$union = '';
|
YEARWEEK(o.date) AS Week
|
||||||
|
FROM `order` o
|
||||||
$allWeeks = $this->allWeeks();
|
INNER JOIN
|
||||||
|
(SELECT min(id_order) id_order,
|
||||||
for( $i = $this->from -1 ; $i < $this->to; $i++ ){
|
u.phone
|
||||||
$week = $allWeeks[ $i ];
|
FROM `order` o
|
||||||
$query .= $union . "SELECT '{$week}' AS Week,
|
INNER JOIN USER u ON u.id_user = o.id_user
|
||||||
COUNT(*) AS Total
|
LEFT JOIN community c ON o.id_community = c.id_community
|
||||||
FROM
|
GROUP BY u.phone) orders ON o.id_order = orders.id_order
|
||||||
(SELECT COUNT(*) orders,
|
GROUP BY YEARWEEK(o.date) HAVING Week BETWEEN '{$this->weekFrom}' AND '{$this->weekTo}'";
|
||||||
u.phone,
|
|
||||||
o.date,
|
|
||||||
u.id_user
|
|
||||||
FROM `order` o
|
|
||||||
INNER JOIN user u ON u.id_user = o.id_user
|
|
||||||
LEFT JOIN community c ON o.id_community = c.id_community
|
|
||||||
WHERE o.date <= STR_TO_DATE('{$week} Saturday', '%X%V %W')
|
|
||||||
{$this->queryExcludeCommunties}
|
|
||||||
{$this->queryExcludeUsers}
|
|
||||||
GROUP BY u.phone HAVING orders = 1) Orders
|
|
||||||
WHERE Orders.date BETWEEN STR_TO_DATE('{$week} Sunday', '%X%V %W') AND STR_TO_DATE('{$week} Saturday', '%X%V %W')";
|
|
||||||
$union = ' UNION ';
|
|
||||||
}
|
|
||||||
|
|
||||||
$parsedData = $this->parseDataWeeksSimple( $query, $this->description );
|
$parsedData = $this->parseDataWeeksSimple( $query, $this->description );
|
||||||
if( $render ){
|
if( $render ){
|
||||||
return array( 'data' => $parsedData, 'unit' => $this->unity );
|
return array( 'data' => $parsedData, 'unit' => $this->unity );
|
||||||
}
|
}
|
||||||
return $parsedData;
|
return $parsedData;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function newPerActiveByWeekByCommunity( $render = false ){
|
public function newPerActiveByWeekByCommunity( $render = false ){
|
||||||
|
|||||||
@ -93,6 +93,10 @@
|
|||||||
?>
|
?>
|
||||||
Months from <?php echo $from_month; ?> to <?php echo $to_month; ?> (of <?php echo $totalMonths; ?>):
|
Months from <?php echo $from_month; ?> to <?php echo $to_month; ?> (of <?php echo $totalMonths; ?>):
|
||||||
<?php
|
<?php
|
||||||
|
} else if( $interval == 'day' ){
|
||||||
|
?>
|
||||||
|
Months from <?php echo $from_day; ?> to <?php echo $to_day; ?> (of <?php echo $totalDays; ?>):
|
||||||
|
<?php
|
||||||
} ?>
|
} ?>
|
||||||
</div>
|
</div>
|
||||||
<div class="span8">
|
<div class="span8">
|
||||||
@ -120,6 +124,7 @@ $(function () {
|
|||||||
labels : {
|
labels : {
|
||||||
rotation: -45,
|
rotation: -45,
|
||||||
align: 'right'
|
align: 'right'
|
||||||
|
<?php if( $interval == 'day' ){ ?>,step:10<?php } ?>
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
yAxis: {
|
yAxis: {
|
||||||
@ -162,6 +167,11 @@ $(function () {
|
|||||||
values: [ <?php echo $from_month; ?>, <?php echo $to_month; ?> ],
|
values: [ <?php echo $from_month; ?>, <?php echo $to_month; ?> ],
|
||||||
max: <?php echo $totalMonths; ?>,
|
max: <?php echo $totalMonths; ?>,
|
||||||
<?php
|
<?php
|
||||||
|
} else if( $interval == 'day' ){
|
||||||
|
?>
|
||||||
|
values: [ <?php echo $from_day; ?>, <?php echo $to_day; ?> ],
|
||||||
|
max: <?php echo $totalDays; ?>,
|
||||||
|
<?php
|
||||||
} ?>
|
} ?>
|
||||||
change: function( event, ui ) {
|
change: function( event, ui ) {
|
||||||
var activeUserDays = $( '#active-user-days' ).val();
|
var activeUserDays = $( '#active-user-days' ).val();
|
||||||
|
|||||||
@ -305,7 +305,7 @@
|
|||||||
$( '#button-reload' ).click( function(){
|
$( '#button-reload' ).click( function(){
|
||||||
$( '.chart' ).each( function(){
|
$( '.chart' ).each( function(){
|
||||||
var chart = $( this );
|
var chart = $( this );
|
||||||
if( chart.attr( 'opened' ) ){
|
if( chart.attr( 'opened' ) == 'true' ){
|
||||||
loadChart( chart.attr( 'id' ), true );
|
loadChart( chart.attr( 'id' ), true );
|
||||||
$( '#button-reload' ).find( 'i' ).addClass( 'icon-spin ' );
|
$( '#button-reload' ).find( 'i' ).addClass( 'icon-spin ' );
|
||||||
setTimeout( function(){
|
setTimeout( function(){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user