WC_Admin_Report::calculate_current_range
Get the current range and calculate the start and end dates.
Метод класса: WC_Admin_Report{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$WC_Admin_Report = new WC_Admin_Report(); $WC_Admin_Report->calculate_current_range( $current_range );
- $current_range(строка) (обязательный)
- Type of range.
Код WC_Admin_Report::calculate_current_range() WC Admin Report::calculate current range WC 10.4.3
public function calculate_current_range( $current_range ) {
// phpcs:disable WordPress.DateTime.RestrictedFunctions.date_date, WordPress.DateTime.CurrentTimeTimestamp.Requested
// phpcs:disable WordPress.Security.NonceVerification.Recommended
switch ( $current_range ) {
case 'custom':
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
$this->start_date = max( strtotime( '-20 years' ), strtotime( sanitize_text_field( wp_unslash( $_GET['start_date'] ) ) ) );
if ( empty( $_GET['end_date'] ) ) {
$this->end_date = strtotime( 'midnight', current_time( 'timestamp' ) );
} else {
$this->end_date = strtotime( 'midnight', strtotime( sanitize_text_field( wp_unslash( $_GET['end_date'] ) ) ) );
}
$interval = 0;
$min_date = $this->start_date;
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
while ( ( $min_date = strtotime( '+1 MONTH', $min_date ) ) <= $this->end_date ) {
$interval ++;
}
// 3 months max for day view
if ( $interval > 3 ) {
$this->chart_groupby = 'month';
} else {
$this->chart_groupby = 'day';
}
break;
case 'year':
$this->start_date = strtotime( date( 'Y-01-01', current_time( 'timestamp' ) ) );
$this->end_date = strtotime( 'midnight', current_time( 'timestamp' ) );
$this->chart_groupby = 'month';
break;
case 'last_month':
$first_day_current_month = strtotime( date( 'Y-m-01', current_time( 'timestamp' ) ) );
$this->start_date = strtotime( date( 'Y-m-01', strtotime( '-1 DAY', $first_day_current_month ) ) );
$this->end_date = strtotime( date( 'Y-m-t', strtotime( '-1 DAY', $first_day_current_month ) ) );
$this->chart_groupby = 'day';
break;
case 'month':
$this->start_date = strtotime( date( 'Y-m-01', current_time( 'timestamp' ) ) );
$this->end_date = strtotime( 'midnight', current_time( 'timestamp' ) );
$this->chart_groupby = 'day';
break;
case '7day':
$this->start_date = strtotime( '-6 days', strtotime( 'midnight', current_time( 'timestamp' ) ) );
$this->end_date = strtotime( 'midnight', current_time( 'timestamp' ) );
$this->chart_groupby = 'day';
break;
}
// Group by.
switch ( $this->chart_groupby ) {
case 'day':
$this->group_by_query = 'YEAR(posts.post_date), MONTH(posts.post_date), DAY(posts.post_date)';
$this->chart_interval = absint( ceil( max( 0, ( $this->end_date - $this->start_date ) / ( 60 * 60 * 24 ) ) ) );
$this->barwidth = 60 * 60 * 24 * 1000;
break;
case 'month':
$this->group_by_query = 'YEAR(posts.post_date), MONTH(posts.post_date)';
$this->chart_interval = 0;
$min_date = strtotime( date( 'Y-m-01', $this->start_date ) );
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
while ( ( $min_date = strtotime( '+1 MONTH', $min_date ) ) <= $this->end_date ) {
$this->chart_interval ++;
}
$this->barwidth = 60 * 60 * 24 * 7 * 4 * 1000;
break;
}
// phpcs:enable WordPress.Security.NonceVerification.Recommended
// phpcs:enable WordPress.DateTime.RestrictedFunctions.date_date, WordPress.DateTime.CurrentTimeTimestamp.Requested
}