|
1
|
|
|
<?php |
|
2
|
|
|
namespace lsx_health_plan\classes\frontend; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Holds the functionality to check and control your status with the current plan. |
|
6
|
|
|
* |
|
7
|
|
|
* @package lsx-health-plan |
|
8
|
|
|
*/ |
|
9
|
|
|
class Plan_Query { |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Holds class instance |
|
13
|
|
|
* |
|
14
|
|
|
* @since 1.0.0 |
|
15
|
|
|
* |
|
16
|
|
|
* @var object \lsx_health_plan\classes\frontend\Plan_Query() |
|
17
|
|
|
*/ |
|
18
|
|
|
protected static $instance = null; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Holds the sections for the current plan. |
|
22
|
|
|
* |
|
23
|
|
|
* @var array |
|
24
|
|
|
*/ |
|
25
|
|
|
public $sections = array(); |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Holds the variable true/false if the current plan has sections or not. |
|
29
|
|
|
* |
|
30
|
|
|
* @var array |
|
31
|
|
|
*/ |
|
32
|
|
|
public $has_sections = false; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Contructor |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct() { |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Return an instance of this class. |
|
42
|
|
|
* |
|
43
|
|
|
* @since 1.0.0 |
|
44
|
|
|
* |
|
45
|
|
|
* @return object \lsx_health_plan\classes\frontend\Plan_Query() A single instance of this class. |
|
46
|
|
|
*/ |
|
47
|
|
|
public static function get_instance() { |
|
48
|
|
|
// If the single instance hasn't been set, set it now. |
|
49
|
|
|
if ( null === self::$instance ) { |
|
50
|
|
|
self::$instance = new self(); |
|
51
|
|
|
} |
|
52
|
|
|
return self::$instance; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Undocumented function |
|
57
|
|
|
* |
|
58
|
|
|
* @return void |
|
59
|
|
|
*/ |
|
60
|
|
|
public function query_sections( $plan_id = '' ) { |
|
61
|
|
|
if ( '' === $plan_id ) { |
|
62
|
|
|
$plan_id = get_the_ID(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$section_array = get_post_meta( $plan_id, 'plan_sections', true ); |
|
66
|
|
|
if ( ! empty( $section_array ) ) { |
|
67
|
|
|
$this->has_sections = true; |
|
|
|
|
|
|
68
|
|
|
$this->sections = $section_array; |
|
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
return $this->has_sections; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function get_sections( $group = false ) { |
|
74
|
|
|
$sections = $this->sections; |
|
75
|
|
|
if ( false !== $group ) { |
|
76
|
|
|
$sections = $this->group_sections( $sections ); |
|
77
|
|
|
} |
|
78
|
|
|
return $sections; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function get_section_count() { |
|
82
|
|
|
return count( $this->sections ); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* This will group the sections by their "Group" field. |
|
87
|
|
|
* |
|
88
|
|
|
* @param array $sections |
|
89
|
|
|
* @return array |
|
90
|
|
|
*/ |
|
91
|
|
|
public function group_sections( $sections = array() ) { |
|
92
|
|
|
$groups = array(); |
|
93
|
|
|
if ( ! empty( $sections ) ) { |
|
94
|
|
|
foreach ( $sections as $section_key => $section_values ) { |
|
95
|
|
|
$group_key = apply_filters( 'lsx_hp_default_plan_group', __( 'Daily Plan', 'lsx-health-plan' ) ); |
|
96
|
|
|
if ( isset( $section_values['group'] ) && '' !== $section_values['group'] ) { |
|
97
|
|
|
$group_key = $section_values['group']; |
|
98
|
|
|
} |
|
99
|
|
|
$group_key = sanitize_title( $group_key ); |
|
100
|
|
|
$groups[ $group_key ][ $section_key ] = $section_values; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
return $groups; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..