PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.4
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.4
4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 4.2.1 All 138 releases
learnpress / inc / Statistics / PeriodRange.php

PeriodRange.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.4, at inc/Statistics/PeriodRange.php

92 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class PeriodRange
4 *
5 * @package LearnPress/Classes/Statistics
6 * @since 4.4.2
7 */
8
9 namespace LearnPress\Statistics;
10
11 defined( 'ABSPATH' ) || exit();
12
13 /**
14 * Value object describing one resolved statistics window.
15 *
16 * Carries both the concrete [ start … end ] datetimes and the legacy-compatible
17 * { filter_type, time } pair consumed by LP_Statistics_DB / DashboardStatisticsDB,
18 * so existing query methods keep working unchanged. `granularity` is the explicit
19 * chart resolution — the DB group-by never re-guesses it.
20 *
21 * Instances are only built by PeriodResolver.
22 *
23 * @since 4.4.2
24 */
25 class PeriodRange {
26 /**
27 * @var string Requested preset id, e.g. 'month', 'last_quarter', 'custom'.
28 */
29 public $preset;
30
31 /**
32 * @var string Window start, 'Y-m-d H:i:s'.
33 */
34 public $start;
35
36 /**
37 * @var string Window end, 'Y-m-d H:i:s'.
38 */
39 public $end;
40
41 /**
42 * @var string Chart resolution: PeriodResolver::GRAN_HOUR|GRAN_DAY|GRAN_MONTH.
43 */
44 public $granularity;
45
46 /**
47 * @var string Human label, e.g. 'Month to date (Jul 1 – 14)'.
48 */
49 public $label;
50
51 /**
52 * @var string Legacy DB filter type paired with $time: date|custom.
53 */
54 public $filter_type;
55
56 /**
57 * @var string|int Legacy DB filter value paired with $filter_type.
58 */
59 public $time;
60
61 /**
62 * @param string $preset Preset id as requested.
63 * @param string $start 'Y-m-d H:i:s'.
64 * @param string $end 'Y-m-d H:i:s'.
65 * @param string $granularity hour|day|month.
66 * @param string $label Display label.
67 * @param string $filter_type Legacy DB filter type.
68 * @param string|int $time Legacy DB filter value.
69 */
70 public function __construct( string $preset, string $start, string $end, string $granularity, string $label, string $filter_type, $time ) {
71 $this->preset = $preset;
72 $this->start = $start;
73 $this->end = $end;
74 $this->granularity = $granularity;
75 $this->label = $label;
76 $this->filter_type = $filter_type;
77 $this->time = $time;
78 }
79
80 /**
81 * The { filter_type, time } pair every legacy DB method understands.
82 *
83 * @return array [ 'filter_type' => string, 'time' => string|int ]
84 */
85 public function legacy_pair(): array {
86 return array(
87 'filter_type' => $this->filter_type,
88 'time' => $this->time,
89 );
90 }
91 }
92