| 1 |
<?php //phpcs:ignore |
| 2 |
|
| 3 |
/** |
| 4 |
* SummaryController — composes the /analytics/summary response. |
| 5 |
* |
| 6 |
* @package Disco |
| 7 |
* @subpackage Disco\App\Analytics\Controllers |
| 8 |
* @since 1.3.23 |
| 9 |
*/ |
| 10 |
|
| 11 |
namespace Disco\App\Analytics\Controllers; |
| 12 |
|
| 13 |
use Disco\App\Analytics\Services\SummaryService; |
| 14 |
|
| 15 |
/** |
| 16 |
* Resolves periods and delegates to SummaryService. |
| 17 |
* |
| 18 |
* No SQL and no query building here — pure orchestration. |
| 19 |
*/ |
| 20 |
class SummaryController extends BaseController { |
| 21 |
|
| 22 |
/** |
| 23 |
* Returns the full summary payload for the given request args. |
| 24 |
* |
| 25 |
* @param array $args Request args with date_from and date_to as Y-m-d strings (optional). |
| 26 |
*/ |
| 27 |
public static function get_summary( array $args ): array { |
| 28 |
$current = self::resolve_current_period( $args ); |
| 29 |
$compare = self::resolve_compare_period( $current ); |
| 30 |
|
| 31 |
return array( |
| 32 |
'current_period' => array( 'from' => $current['from'], 'to' => $current['to'] ), |
| 33 |
'compare_period' => array( 'from' => $compare['from'], 'to' => $compare['to'] ), |
| 34 |
'data' => SummaryService::get_summary( $current, $compare ), |
| 35 |
); |
| 36 |
} |
| 37 |
|
| 38 |
} |
| 39 |
|