@@ -12,45 +12,45 @@ |
||
12 | 12 | */ |
13 | 13 | class EE_Password_Field extends EE_Text_Field_Base |
14 | 14 | { |
15 | - /** |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - protected $protected_fields; |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + protected $protected_fields; |
|
19 | 19 | |
20 | - /** |
|
21 | - * EE_Password_Field constructor. |
|
22 | - * @param $table_column |
|
23 | - * @param $nicename |
|
24 | - * @param $nullable |
|
25 | - * @param null $default_value |
|
26 | - * @param array $protected_fields |
|
27 | - */ |
|
28 | - public function __construct($table_column, $nicename, $nullable, $default_value = null, $protected_fields = array()) |
|
29 | - { |
|
30 | - $this->protected_fields = $protected_fields; |
|
31 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
32 | - } |
|
20 | + /** |
|
21 | + * EE_Password_Field constructor. |
|
22 | + * @param $table_column |
|
23 | + * @param $nicename |
|
24 | + * @param $nullable |
|
25 | + * @param null $default_value |
|
26 | + * @param array $protected_fields |
|
27 | + */ |
|
28 | + public function __construct($table_column, $nicename, $nullable, $default_value = null, $protected_fields = array()) |
|
29 | + { |
|
30 | + $this->protected_fields = $protected_fields; |
|
31 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Returns the names of the fields on this model that this password field should protect |
|
36 | - * @since $VID:$ |
|
37 | - * @return array |
|
38 | - */ |
|
39 | - public function protectedFields() |
|
40 | - { |
|
41 | - return $this->protected_fields; |
|
42 | - } |
|
34 | + /** |
|
35 | + * Returns the names of the fields on this model that this password field should protect |
|
36 | + * @since $VID:$ |
|
37 | + * @return array |
|
38 | + */ |
|
39 | + public function protectedFields() |
|
40 | + { |
|
41 | + return $this->protected_fields; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Returns whether or not the specified field is protected by this model |
|
46 | - * @since $VID:$ |
|
47 | - * @param $field_name |
|
48 | - * @return bool |
|
49 | - */ |
|
50 | - public function fieldIsProtected($field_name) |
|
51 | - { |
|
52 | - return in_array($field_name, $this->protectedFields(), true); |
|
53 | - } |
|
44 | + /** |
|
45 | + * Returns whether or not the specified field is protected by this model |
|
46 | + * @since $VID:$ |
|
47 | + * @param $field_name |
|
48 | + * @return bool |
|
49 | + */ |
|
50 | + public function fieldIsProtected($field_name) |
|
51 | + { |
|
52 | + return in_array($field_name, $this->protectedFields(), true); |
|
53 | + } |
|
54 | 54 | } |
55 | 55 | // End of file EE_Password_Field.php |
56 | 56 | // Location: ${NAMESPACE}/EE_Password_Field.php |
@@ -7,34 +7,34 @@ |
||
7 | 7 | */ |
8 | 8 | class EEM_Event_Question_Group extends EEM_Base |
9 | 9 | { |
10 | - // private instance of the Attendee object |
|
11 | - protected static $_instance = null; |
|
10 | + // private instance of the Attendee object |
|
11 | + protected static $_instance = null; |
|
12 | 12 | |
13 | - protected function __construct($timezone = null) |
|
14 | - { |
|
15 | - $this->singular_item = __('Event to Question Group Link', 'event_espresso'); |
|
16 | - $this->plural_item = __('Event to Question Group Links', 'event_espresso'); |
|
17 | - $this->_tables = array( |
|
18 | - 'Event_Question_Group'=>new EE_Primary_Table('esp_event_question_group', 'EQG_ID') |
|
19 | - ); |
|
20 | - $this->_fields = array( |
|
21 | - 'Event_Question_Group'=>array( |
|
22 | - 'EQG_ID'=>new EE_Primary_Key_Int_Field('EQG_ID', __('Event to Question Group Link ID', 'event_espresso')), |
|
23 | - 'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'), |
|
24 | - 'QSG_ID'=>new EE_Foreign_Key_Int_Field('QSG_ID', __('Question Group Id', 'event_espresso'), false, 0, 'Question_Group'), |
|
25 | - 'EQG_primary'=>new EE_Boolean_Field('EQG_primary', __('Flag indicating question is only for primary attendees', 'event_espresso'), false, false) |
|
26 | - ) |
|
27 | - ); |
|
28 | - $this->_model_relations = array( |
|
29 | - 'Event'=>new EE_Belongs_To_Relation(), |
|
30 | - 'Question_Group'=>new EE_Belongs_To_Relation() |
|
31 | - ); |
|
32 | - // this model is generally available for reading |
|
33 | - $path_to_event = 'Event'; |
|
34 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
35 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
36 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
37 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
38 | - parent::__construct($timezone); |
|
39 | - } |
|
13 | + protected function __construct($timezone = null) |
|
14 | + { |
|
15 | + $this->singular_item = __('Event to Question Group Link', 'event_espresso'); |
|
16 | + $this->plural_item = __('Event to Question Group Links', 'event_espresso'); |
|
17 | + $this->_tables = array( |
|
18 | + 'Event_Question_Group'=>new EE_Primary_Table('esp_event_question_group', 'EQG_ID') |
|
19 | + ); |
|
20 | + $this->_fields = array( |
|
21 | + 'Event_Question_Group'=>array( |
|
22 | + 'EQG_ID'=>new EE_Primary_Key_Int_Field('EQG_ID', __('Event to Question Group Link ID', 'event_espresso')), |
|
23 | + 'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'), |
|
24 | + 'QSG_ID'=>new EE_Foreign_Key_Int_Field('QSG_ID', __('Question Group Id', 'event_espresso'), false, 0, 'Question_Group'), |
|
25 | + 'EQG_primary'=>new EE_Boolean_Field('EQG_primary', __('Flag indicating question is only for primary attendees', 'event_espresso'), false, false) |
|
26 | + ) |
|
27 | + ); |
|
28 | + $this->_model_relations = array( |
|
29 | + 'Event'=>new EE_Belongs_To_Relation(), |
|
30 | + 'Question_Group'=>new EE_Belongs_To_Relation() |
|
31 | + ); |
|
32 | + // this model is generally available for reading |
|
33 | + $path_to_event = 'Event'; |
|
34 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
35 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
36 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
37 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
38 | + parent::__construct($timezone); |
|
39 | + } |
|
40 | 40 | } |
@@ -31,10 +31,10 @@ |
||
31 | 31 | ); |
32 | 32 | // this model is generally available for reading |
33 | 33 | $path_to_event = 'Event'; |
34 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
35 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
36 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
37 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
34 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
35 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
36 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
37 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
38 | 38 | parent::__construct($timezone); |
39 | 39 | } |
40 | 40 | } |
@@ -1,95 +1,95 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | /** |
4 | - * EEM_Event_Message_Template |
|
5 | - * Model for relation table between EEM_Message_Template_Group and EEM_Event |
|
6 | - * |
|
7 | - * @package Event Espresso |
|
8 | - * @subpackage models |
|
9 | - * @since 4.3.0 |
|
10 | - * @author Darren Ethier |
|
11 | - * |
|
12 | - * ------------------------------------------------------------------------ |
|
13 | - */ |
|
4 | + * EEM_Event_Message_Template |
|
5 | + * Model for relation table between EEM_Message_Template_Group and EEM_Event |
|
6 | + * |
|
7 | + * @package Event Espresso |
|
8 | + * @subpackage models |
|
9 | + * @since 4.3.0 |
|
10 | + * @author Darren Ethier |
|
11 | + * |
|
12 | + * ------------------------------------------------------------------------ |
|
13 | + */ |
|
14 | 14 | class EEM_Event_Message_Template extends EEM_Base |
15 | 15 | { |
16 | 16 | |
17 | - // private instance of the EEM_Event_Message_Template object |
|
18 | - protected static $_instance = null; |
|
17 | + // private instance of the EEM_Event_Message_Template object |
|
18 | + protected static $_instance = null; |
|
19 | 19 | |
20 | - /** |
|
21 | - * private constructor to prevent direct creation |
|
22 | - * @Constructor |
|
23 | - * @access private |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - protected function __construct($timezone = null) |
|
27 | - { |
|
28 | - $this->singlular_item = __('Event Message Template', 'event_espresso'); |
|
29 | - $this->plural_item = __('Event Message Templates', 'event_espresso'); |
|
20 | + /** |
|
21 | + * private constructor to prevent direct creation |
|
22 | + * @Constructor |
|
23 | + * @access private |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + protected function __construct($timezone = null) |
|
27 | + { |
|
28 | + $this->singlular_item = __('Event Message Template', 'event_espresso'); |
|
29 | + $this->plural_item = __('Event Message Templates', 'event_espresso'); |
|
30 | 30 | |
31 | - $this->_tables = array( |
|
32 | - 'Event_Message_Template'=> new EE_Primary_Table('esp_event_message_template', 'EMT_ID') |
|
33 | - ); |
|
34 | - $this->_fields = array( |
|
35 | - 'Event_Message_Template'=>array( |
|
36 | - 'EMT_ID'=>new EE_Primary_Key_Int_Field('EMT_ID', __('Event Message Template ID', 'event_espresso')), |
|
37 | - 'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('The ID to the Event', 'event_espresso'), false, 0, 'Event'), |
|
38 | - 'GRP_ID'=>new EE_Foreign_Key_Int_Field('GRP_ID', __('The ID to the Message Template Group', 'event_espresso'), false, 0, 'Message_Template_Group') |
|
39 | - )); |
|
40 | - $this->_model_relations = array( |
|
41 | - 'Event'=>new EE_Belongs_To_Relation(), |
|
42 | - 'Message_Template_Group'=>new EE_Belongs_To_Relation() |
|
43 | - ); |
|
44 | - $path_to_event = 'Event'; |
|
45 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
46 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
49 | - parent::__construct($timezone); |
|
50 | - } |
|
31 | + $this->_tables = array( |
|
32 | + 'Event_Message_Template'=> new EE_Primary_Table('esp_event_message_template', 'EMT_ID') |
|
33 | + ); |
|
34 | + $this->_fields = array( |
|
35 | + 'Event_Message_Template'=>array( |
|
36 | + 'EMT_ID'=>new EE_Primary_Key_Int_Field('EMT_ID', __('Event Message Template ID', 'event_espresso')), |
|
37 | + 'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('The ID to the Event', 'event_espresso'), false, 0, 'Event'), |
|
38 | + 'GRP_ID'=>new EE_Foreign_Key_Int_Field('GRP_ID', __('The ID to the Message Template Group', 'event_espresso'), false, 0, 'Message_Template_Group') |
|
39 | + )); |
|
40 | + $this->_model_relations = array( |
|
41 | + 'Event'=>new EE_Belongs_To_Relation(), |
|
42 | + 'Message_Template_Group'=>new EE_Belongs_To_Relation() |
|
43 | + ); |
|
44 | + $path_to_event = 'Event'; |
|
45 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
46 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
47 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
48 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
49 | + parent::__construct($timezone); |
|
50 | + } |
|
51 | 51 | |
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * helper method to simply return an array of event ids for events attached to the given |
|
56 | - * message template group. |
|
57 | - * |
|
58 | - * @since 4.3.0 |
|
59 | - * |
|
60 | - * @param int $GRP_ID The MTP group we want attached events for. |
|
61 | - * @return array An array of event ids. |
|
62 | - */ |
|
63 | - public function get_attached_event_ids($GRP_ID) |
|
64 | - { |
|
65 | - $event_ids = $this->_get_all_wpdb_results(array( array( 'GRP_ID' => $GRP_ID ) ), ARRAY_N, 'EVT_ID'); |
|
66 | - $event_ids = call_user_func_array('array_merge', $event_ids); |
|
67 | - return $event_ids; |
|
68 | - } |
|
54 | + /** |
|
55 | + * helper method to simply return an array of event ids for events attached to the given |
|
56 | + * message template group. |
|
57 | + * |
|
58 | + * @since 4.3.0 |
|
59 | + * |
|
60 | + * @param int $GRP_ID The MTP group we want attached events for. |
|
61 | + * @return array An array of event ids. |
|
62 | + */ |
|
63 | + public function get_attached_event_ids($GRP_ID) |
|
64 | + { |
|
65 | + $event_ids = $this->_get_all_wpdb_results(array( array( 'GRP_ID' => $GRP_ID ) ), ARRAY_N, 'EVT_ID'); |
|
66 | + $event_ids = call_user_func_array('array_merge', $event_ids); |
|
67 | + return $event_ids; |
|
68 | + } |
|
69 | 69 | |
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * helper method for clearing event/group relations for the given event ids and grp ids. |
|
74 | - * @param array $GRP_IDs An array of GRP_IDs. Optional. If empty then there must be EVTIDs. |
|
75 | - * @param array $EVT_IDs An array of EVT_IDs. Optional. If empty then there must be |
|
76 | - * GRPIDs. |
|
77 | - * @return int How many rows were deleted. |
|
78 | - */ |
|
79 | - public function delete_event_group_relations($GRP_IDs = array(), $EVT_IDs = array()) |
|
80 | - { |
|
81 | - if (empty($GRP_IDs) && empty($EVT_IDs)) { |
|
82 | - throw new EE_Error(sprintf(__('%s requires either an array of GRP_IDs or EVT_IDs or both, but both cannot be empty.', 'event_espresso'), __METHOD__)); |
|
83 | - } |
|
72 | + /** |
|
73 | + * helper method for clearing event/group relations for the given event ids and grp ids. |
|
74 | + * @param array $GRP_IDs An array of GRP_IDs. Optional. If empty then there must be EVTIDs. |
|
75 | + * @param array $EVT_IDs An array of EVT_IDs. Optional. If empty then there must be |
|
76 | + * GRPIDs. |
|
77 | + * @return int How many rows were deleted. |
|
78 | + */ |
|
79 | + public function delete_event_group_relations($GRP_IDs = array(), $EVT_IDs = array()) |
|
80 | + { |
|
81 | + if (empty($GRP_IDs) && empty($EVT_IDs)) { |
|
82 | + throw new EE_Error(sprintf(__('%s requires either an array of GRP_IDs or EVT_IDs or both, but both cannot be empty.', 'event_espresso'), __METHOD__)); |
|
83 | + } |
|
84 | 84 | |
85 | - if (!empty($GRP_IDs)) { |
|
86 | - $where['GRP_ID'] = array( 'IN', (array) $GRP_IDs ); |
|
87 | - } |
|
85 | + if (!empty($GRP_IDs)) { |
|
86 | + $where['GRP_ID'] = array( 'IN', (array) $GRP_IDs ); |
|
87 | + } |
|
88 | 88 | |
89 | - if (!empty($EVT_IDs)) { |
|
90 | - $where['EVT_ID'] = array( 'IN', (array) $EVT_IDs ); |
|
91 | - } |
|
89 | + if (!empty($EVT_IDs)) { |
|
90 | + $where['EVT_ID'] = array( 'IN', (array) $EVT_IDs ); |
|
91 | + } |
|
92 | 92 | |
93 | - return $this->delete(array( $where ), false); |
|
94 | - } |
|
93 | + return $this->delete(array( $where ), false); |
|
94 | + } |
|
95 | 95 | } |
@@ -42,10 +42,10 @@ discard block |
||
42 | 42 | 'Message_Template_Group'=>new EE_Belongs_To_Relation() |
43 | 43 | ); |
44 | 44 | $path_to_event = 'Event'; |
45 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
46 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
45 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
46 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
47 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
48 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
49 | 49 | parent::__construct($timezone); |
50 | 50 | } |
51 | 51 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function get_attached_event_ids($GRP_ID) |
64 | 64 | { |
65 | - $event_ids = $this->_get_all_wpdb_results(array( array( 'GRP_ID' => $GRP_ID ) ), ARRAY_N, 'EVT_ID'); |
|
65 | + $event_ids = $this->_get_all_wpdb_results(array(array('GRP_ID' => $GRP_ID)), ARRAY_N, 'EVT_ID'); |
|
66 | 66 | $event_ids = call_user_func_array('array_merge', $event_ids); |
67 | 67 | return $event_ids; |
68 | 68 | } |
@@ -82,14 +82,14 @@ discard block |
||
82 | 82 | throw new EE_Error(sprintf(__('%s requires either an array of GRP_IDs or EVT_IDs or both, but both cannot be empty.', 'event_espresso'), __METHOD__)); |
83 | 83 | } |
84 | 84 | |
85 | - if (!empty($GRP_IDs)) { |
|
86 | - $where['GRP_ID'] = array( 'IN', (array) $GRP_IDs ); |
|
85 | + if ( ! empty($GRP_IDs)) { |
|
86 | + $where['GRP_ID'] = array('IN', (array) $GRP_IDs); |
|
87 | 87 | } |
88 | 88 | |
89 | - if (!empty($EVT_IDs)) { |
|
90 | - $where['EVT_ID'] = array( 'IN', (array) $EVT_IDs ); |
|
89 | + if ( ! empty($EVT_IDs)) { |
|
90 | + $where['EVT_ID'] = array('IN', (array) $EVT_IDs); |
|
91 | 91 | } |
92 | 92 | |
93 | - return $this->delete(array( $where ), false); |
|
93 | + return $this->delete(array($where), false); |
|
94 | 94 | } |
95 | 95 | } |
@@ -7,36 +7,36 @@ |
||
7 | 7 | */ |
8 | 8 | class EEM_Event_Venue extends EEM_Base |
9 | 9 | { |
10 | - // private instance of the Attendee object |
|
11 | - protected static $_instance = null; |
|
10 | + // private instance of the Attendee object |
|
11 | + protected static $_instance = null; |
|
12 | 12 | |
13 | - protected function __construct($timezone = null) |
|
14 | - { |
|
15 | - $this->singular_item = __('Event to Question Group Link', 'event_espresso'); |
|
16 | - $this->plural_item = __('Event to Question Group Links', 'event_espresso'); |
|
17 | - $this->_tables = array( |
|
18 | - 'Event_Venue'=>new EE_Primary_Table('esp_event_venue', 'EVV_ID') |
|
19 | - ); |
|
20 | - $this->_fields = array( |
|
21 | - 'Event_Venue'=>array( |
|
22 | - 'EVV_ID'=>new EE_Primary_Key_Int_Field('EVV_ID', __('Event to Venue Link ID', 'event_espresso')), |
|
23 | - 'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'), |
|
24 | - 'VNU_ID'=>new EE_Foreign_Key_Int_Field('VNU_ID', __('Venue ID', 'event_espresso'), false, 0, 'Venue'), |
|
25 | - 'EVV_primary'=>new EE_Boolean_Field('EVV_primary', __("Flag indicating venue is primary one for event", "event_espresso"), false, true) |
|
13 | + protected function __construct($timezone = null) |
|
14 | + { |
|
15 | + $this->singular_item = __('Event to Question Group Link', 'event_espresso'); |
|
16 | + $this->plural_item = __('Event to Question Group Links', 'event_espresso'); |
|
17 | + $this->_tables = array( |
|
18 | + 'Event_Venue'=>new EE_Primary_Table('esp_event_venue', 'EVV_ID') |
|
19 | + ); |
|
20 | + $this->_fields = array( |
|
21 | + 'Event_Venue'=>array( |
|
22 | + 'EVV_ID'=>new EE_Primary_Key_Int_Field('EVV_ID', __('Event to Venue Link ID', 'event_espresso')), |
|
23 | + 'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'), |
|
24 | + 'VNU_ID'=>new EE_Foreign_Key_Int_Field('VNU_ID', __('Venue ID', 'event_espresso'), false, 0, 'Venue'), |
|
25 | + 'EVV_primary'=>new EE_Boolean_Field('EVV_primary', __("Flag indicating venue is primary one for event", "event_espresso"), false, true) |
|
26 | 26 | |
27 | - ) |
|
28 | - ); |
|
29 | - $this->_model_relations = array( |
|
30 | - 'Event'=>new EE_Belongs_To_Relation(), |
|
31 | - 'Venue'=>new EE_Belongs_To_Relation() |
|
32 | - ); |
|
33 | - // this model is generally available for reading |
|
34 | - $path_to_event = 'Event'; |
|
35 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
36 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
37 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
38 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
39 | - $this->model_chain_to_password = $path_to_event; |
|
40 | - parent::__construct($timezone); |
|
41 | - } |
|
27 | + ) |
|
28 | + ); |
|
29 | + $this->_model_relations = array( |
|
30 | + 'Event'=>new EE_Belongs_To_Relation(), |
|
31 | + 'Venue'=>new EE_Belongs_To_Relation() |
|
32 | + ); |
|
33 | + // this model is generally available for reading |
|
34 | + $path_to_event = 'Event'; |
|
35 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
36 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
37 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
38 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
39 | + $this->model_chain_to_password = $path_to_event; |
|
40 | + parent::__construct($timezone); |
|
41 | + } |
|
42 | 42 | } |
@@ -32,10 +32,10 @@ |
||
32 | 32 | ); |
33 | 33 | // this model is generally available for reading |
34 | 34 | $path_to_event = 'Event'; |
35 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
36 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
37 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
38 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
35 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
36 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
37 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
38 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
39 | 39 | $this->model_chain_to_password = $path_to_event; |
40 | 40 | parent::__construct($timezone); |
41 | 41 | } |
@@ -9,661 +9,661 @@ |
||
9 | 9 | class EEM_Datetime extends EEM_Soft_Delete_Base |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * @var EEM_Datetime $_instance |
|
14 | - */ |
|
15 | - protected static $_instance; |
|
16 | - |
|
17 | - |
|
18 | - /** |
|
19 | - * private constructor to prevent direct creation |
|
20 | - * |
|
21 | - * @param string $timezone A string representing the timezone we want to set for returned Date Time Strings |
|
22 | - * (and any incoming timezone data that gets saved). |
|
23 | - * Note this just sends the timezone info to the date time model field objects. |
|
24 | - * Default is NULL |
|
25 | - * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
26 | - * @throws EE_Error |
|
27 | - * @throws InvalidArgumentException |
|
28 | - * @throws InvalidArgumentException |
|
29 | - */ |
|
30 | - protected function __construct($timezone) |
|
31 | - { |
|
32 | - $this->singular_item = esc_html__('Datetime', 'event_espresso'); |
|
33 | - $this->plural_item = esc_html__('Datetimes', 'event_espresso'); |
|
34 | - $this->_tables = array( |
|
35 | - 'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'), |
|
36 | - ); |
|
37 | - $this->_fields = array( |
|
38 | - 'Datetime' => array( |
|
39 | - 'DTT_ID' => new EE_Primary_Key_Int_Field( |
|
40 | - 'DTT_ID', |
|
41 | - esc_html__('Datetime ID', 'event_espresso') |
|
42 | - ), |
|
43 | - 'EVT_ID' => new EE_Foreign_Key_Int_Field( |
|
44 | - 'EVT_ID', |
|
45 | - esc_html__('Event ID', 'event_espresso'), |
|
46 | - false, |
|
47 | - 0, |
|
48 | - 'Event' |
|
49 | - ), |
|
50 | - 'DTT_name' => new EE_Plain_Text_Field( |
|
51 | - 'DTT_name', |
|
52 | - esc_html__('Datetime Name', 'event_espresso'), |
|
53 | - false, |
|
54 | - '' |
|
55 | - ), |
|
56 | - 'DTT_description' => new EE_Post_Content_Field( |
|
57 | - 'DTT_description', |
|
58 | - esc_html__('Description for Datetime', 'event_espresso'), |
|
59 | - false, |
|
60 | - '' |
|
61 | - ), |
|
62 | - 'DTT_EVT_start' => new EE_Datetime_Field( |
|
63 | - 'DTT_EVT_start', |
|
64 | - esc_html__('Start time/date of Event', 'event_espresso'), |
|
65 | - false, |
|
66 | - EE_Datetime_Field::now, |
|
67 | - $timezone |
|
68 | - ), |
|
69 | - 'DTT_EVT_end' => new EE_Datetime_Field( |
|
70 | - 'DTT_EVT_end', |
|
71 | - esc_html__('End time/date of Event', 'event_espresso'), |
|
72 | - false, |
|
73 | - EE_Datetime_Field::now, |
|
74 | - $timezone |
|
75 | - ), |
|
76 | - 'DTT_reg_limit' => new EE_Infinite_Integer_Field( |
|
77 | - 'DTT_reg_limit', |
|
78 | - esc_html__('Registration Limit for this time', 'event_espresso'), |
|
79 | - true, |
|
80 | - EE_INF |
|
81 | - ), |
|
82 | - 'DTT_sold' => new EE_Integer_Field( |
|
83 | - 'DTT_sold', |
|
84 | - esc_html__('How many sales for this Datetime that have occurred', 'event_espresso'), |
|
85 | - true, |
|
86 | - 0 |
|
87 | - ), |
|
88 | - 'DTT_reserved' => new EE_Integer_Field( |
|
89 | - 'DTT_reserved', |
|
90 | - esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'), |
|
91 | - false, |
|
92 | - 0 |
|
93 | - ), |
|
94 | - 'DTT_is_primary' => new EE_Boolean_Field( |
|
95 | - 'DTT_is_primary', |
|
96 | - esc_html__('Flag indicating datetime is primary one for event', 'event_espresso'), |
|
97 | - false, |
|
98 | - false |
|
99 | - ), |
|
100 | - 'DTT_order' => new EE_Integer_Field( |
|
101 | - 'DTT_order', |
|
102 | - esc_html__('The order in which the Datetime is displayed', 'event_espresso'), |
|
103 | - false, |
|
104 | - 0 |
|
105 | - ), |
|
106 | - 'DTT_parent' => new EE_Integer_Field( |
|
107 | - 'DTT_parent', |
|
108 | - esc_html__('Indicates what DTT_ID is the parent of this DTT_ID', 'event_espresso'), |
|
109 | - true, |
|
110 | - 0 |
|
111 | - ), |
|
112 | - 'DTT_deleted' => new EE_Trashed_Flag_Field( |
|
113 | - 'DTT_deleted', |
|
114 | - esc_html__('Flag indicating datetime is archived', 'event_espresso'), |
|
115 | - false, |
|
116 | - false |
|
117 | - ), |
|
118 | - ), |
|
119 | - ); |
|
120 | - $this->_model_relations = array( |
|
121 | - 'Ticket' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
122 | - 'Event' => new EE_Belongs_To_Relation(), |
|
123 | - 'Checkin' => new EE_Has_Many_Relation(), |
|
124 | - ); |
|
125 | - $path_to_event_model = 'Event'; |
|
126 | - $this->model_chain_to_password = $path_to_event_model; |
|
127 | - $this->_model_chain_to_wp_user = $path_to_event_model; |
|
128 | - // this model is generally available for reading |
|
129 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
130 | - $path_to_event_model |
|
131 | - ); |
|
132 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
133 | - $path_to_event_model |
|
134 | - ); |
|
135 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
136 | - $path_to_event_model |
|
137 | - ); |
|
138 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
139 | - $path_to_event_model, |
|
140 | - EEM_Base::caps_edit |
|
141 | - ); |
|
142 | - parent::__construct($timezone); |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * create new blank datetime |
|
148 | - * |
|
149 | - * @access public |
|
150 | - * @return EE_Datetime[] array on success, FALSE on fail |
|
151 | - * @throws EE_Error |
|
152 | - */ |
|
153 | - public function create_new_blank_datetime() |
|
154 | - { |
|
155 | - // makes sure timezone is always set. |
|
156 | - $timezone_string = $this->get_timezone(); |
|
157 | - $blank_datetime = EE_Datetime::new_instance( |
|
158 | - array( |
|
159 | - 'DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS, |
|
160 | - 'DTT_EVT_end' => $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS, |
|
161 | - 'DTT_order' => 1, |
|
162 | - 'DTT_reg_limit' => EE_INF, |
|
163 | - ), |
|
164 | - $timezone_string |
|
165 | - ); |
|
166 | - $blank_datetime->set_start_time( |
|
167 | - $this->convert_datetime_for_query( |
|
168 | - 'DTT_EVT_start', |
|
169 | - '8am', |
|
170 | - 'ga', |
|
171 | - $timezone_string |
|
172 | - ) |
|
173 | - ); |
|
174 | - $blank_datetime->set_end_time( |
|
175 | - $this->convert_datetime_for_query( |
|
176 | - 'DTT_EVT_end', |
|
177 | - '5pm', |
|
178 | - 'ga', |
|
179 | - $timezone_string |
|
180 | - ) |
|
181 | - ); |
|
182 | - return array($blank_datetime); |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * get event start date from db |
|
188 | - * |
|
189 | - * @access public |
|
190 | - * @param int $EVT_ID |
|
191 | - * @return EE_Datetime[] array on success, FALSE on fail |
|
192 | - * @throws EE_Error |
|
193 | - */ |
|
194 | - public function get_all_event_dates($EVT_ID = 0) |
|
195 | - { |
|
196 | - if (! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
197 | - return $this->create_new_blank_datetime(); |
|
198 | - } |
|
199 | - $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID); |
|
200 | - if (empty($results)) { |
|
201 | - return $this->create_new_blank_datetime(); |
|
202 | - } |
|
203 | - return $results; |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - /** |
|
208 | - * get all datetimes attached to an event ordered by the DTT_order field |
|
209 | - * |
|
210 | - * @public |
|
211 | - * @param int $EVT_ID event id |
|
212 | - * @param boolean $include_expired |
|
213 | - * @param boolean $include_deleted |
|
214 | - * @param int $limit If included then limit the count of results by |
|
215 | - * the given number |
|
216 | - * @return EE_Datetime[] |
|
217 | - * @throws EE_Error |
|
218 | - */ |
|
219 | - public function get_datetimes_for_event_ordered_by_DTT_order( |
|
220 | - $EVT_ID, |
|
221 | - $include_expired = true, |
|
222 | - $include_deleted = true, |
|
223 | - $limit = null |
|
224 | - ) { |
|
225 | - // sanitize EVT_ID |
|
226 | - $EVT_ID = absint($EVT_ID); |
|
227 | - $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
228 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
229 | - $where_params = array('Event.EVT_ID' => $EVT_ID); |
|
230 | - $query_params = ! empty($limit) |
|
231 | - ? array( |
|
232 | - $where_params, |
|
233 | - 'limit' => $limit, |
|
234 | - 'order_by' => array('DTT_order' => 'ASC'), |
|
235 | - 'default_where_conditions' => 'none', |
|
236 | - ) |
|
237 | - : array( |
|
238 | - $where_params, |
|
239 | - 'order_by' => array('DTT_order' => 'ASC'), |
|
240 | - 'default_where_conditions' => 'none', |
|
241 | - ); |
|
242 | - if (! $include_expired) { |
|
243 | - $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
244 | - } |
|
245 | - if ($include_deleted) { |
|
246 | - $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
247 | - } |
|
248 | - /** @var EE_Datetime[] $result */ |
|
249 | - $result = $this->get_all($query_params); |
|
250 | - $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
251 | - return $result; |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * Gets the datetimes for the event (with the given limit), and orders them by "importance". |
|
257 | - * By importance, we mean that the primary datetimes are most important (DEPRECATED FOR NOW), |
|
258 | - * and then the earlier datetimes are the most important. |
|
259 | - * Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet. |
|
260 | - * |
|
261 | - * @param int $EVT_ID |
|
262 | - * @param int $limit |
|
263 | - * @return EE_Datetime[]|EE_Base_Class[] |
|
264 | - * @throws EE_Error |
|
265 | - */ |
|
266 | - public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null) |
|
267 | - { |
|
268 | - return $this->get_all( |
|
269 | - array( |
|
270 | - array('Event.EVT_ID' => $EVT_ID), |
|
271 | - 'limit' => $limit, |
|
272 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
273 | - 'default_where_conditions' => 'none', |
|
274 | - ) |
|
275 | - ); |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * @param int $EVT_ID |
|
281 | - * @param boolean $include_expired |
|
282 | - * @param boolean $include_deleted |
|
283 | - * @return EE_Datetime |
|
284 | - * @throws EE_Error |
|
285 | - */ |
|
286 | - public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false) |
|
287 | - { |
|
288 | - $results = $this->get_datetimes_for_event_ordered_by_start_time( |
|
289 | - $EVT_ID, |
|
290 | - $include_expired, |
|
291 | - $include_deleted, |
|
292 | - 1 |
|
293 | - ); |
|
294 | - if ($results) { |
|
295 | - return array_shift($results); |
|
296 | - } |
|
297 | - return null; |
|
298 | - } |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * Gets the 'primary' datetime for an event. |
|
303 | - * |
|
304 | - * @param int $EVT_ID |
|
305 | - * @param bool $try_to_exclude_expired |
|
306 | - * @param bool $try_to_exclude_deleted |
|
307 | - * @return \EE_Datetime |
|
308 | - * @throws EE_Error |
|
309 | - */ |
|
310 | - public function get_primary_datetime_for_event( |
|
311 | - $EVT_ID, |
|
312 | - $try_to_exclude_expired = true, |
|
313 | - $try_to_exclude_deleted = true |
|
314 | - ) { |
|
315 | - if ($try_to_exclude_expired) { |
|
316 | - $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false); |
|
317 | - if ($non_expired) { |
|
318 | - return $non_expired; |
|
319 | - } |
|
320 | - } |
|
321 | - if ($try_to_exclude_deleted) { |
|
322 | - $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true); |
|
323 | - if ($expired_even) { |
|
324 | - return $expired_even; |
|
325 | - } |
|
326 | - } |
|
327 | - return $this->get_oldest_datetime_for_event($EVT_ID, true, true); |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - /** |
|
332 | - * Gets ALL the datetimes for an event (including trashed ones, for now), ordered |
|
333 | - * only by start date |
|
334 | - * |
|
335 | - * @param int $EVT_ID |
|
336 | - * @param boolean $include_expired |
|
337 | - * @param boolean $include_deleted |
|
338 | - * @param int $limit |
|
339 | - * @return EE_Datetime[] |
|
340 | - * @throws EE_Error |
|
341 | - */ |
|
342 | - public function get_datetimes_for_event_ordered_by_start_time( |
|
343 | - $EVT_ID, |
|
344 | - $include_expired = true, |
|
345 | - $include_deleted = true, |
|
346 | - $limit = null |
|
347 | - ) { |
|
348 | - // sanitize EVT_ID |
|
349 | - $EVT_ID = absint($EVT_ID); |
|
350 | - $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
351 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
352 | - $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
|
353 | - if (! $include_expired) { |
|
354 | - $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
355 | - } |
|
356 | - if ($include_deleted) { |
|
357 | - $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
358 | - } |
|
359 | - if ($limit) { |
|
360 | - $query_params['limit'] = $limit; |
|
361 | - } |
|
362 | - /** @var EE_Datetime[] $result */ |
|
363 | - $result = $this->get_all($query_params); |
|
364 | - $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
365 | - return $result; |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered |
|
371 | - * only by start date |
|
372 | - * |
|
373 | - * @param int $TKT_ID |
|
374 | - * @param boolean $include_expired |
|
375 | - * @param boolean $include_deleted |
|
376 | - * @param int $limit |
|
377 | - * @return EE_Datetime[] |
|
378 | - * @throws EE_Error |
|
379 | - */ |
|
380 | - public function get_datetimes_for_ticket_ordered_by_start_time( |
|
381 | - $TKT_ID, |
|
382 | - $include_expired = true, |
|
383 | - $include_deleted = true, |
|
384 | - $limit = null |
|
385 | - ) { |
|
386 | - // sanitize TKT_ID |
|
387 | - $TKT_ID = absint($TKT_ID); |
|
388 | - $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
389 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
390 | - $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
|
391 | - if (! $include_expired) { |
|
392 | - $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
393 | - } |
|
394 | - if ($include_deleted) { |
|
395 | - $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
396 | - } |
|
397 | - if ($limit) { |
|
398 | - $query_params['limit'] = $limit; |
|
399 | - } |
|
400 | - /** @var EE_Datetime[] $result */ |
|
401 | - $result = $this->get_all($query_params); |
|
402 | - $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
403 | - return $result; |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the |
|
409 | - * datetimes. |
|
410 | - * |
|
411 | - * @param int $TKT_ID ID of ticket to retrieve the datetimes for |
|
412 | - * @param boolean $include_expired whether to include expired datetimes or not |
|
413 | - * @param boolean $include_deleted whether to include trashed datetimes or not. |
|
414 | - * @param int|null $limit if null, no limit, if int then limit results by |
|
415 | - * that number |
|
416 | - * @return EE_Datetime[] |
|
417 | - * @throws EE_Error |
|
418 | - */ |
|
419 | - public function get_datetimes_for_ticket_ordered_by_DTT_order( |
|
420 | - $TKT_ID, |
|
421 | - $include_expired = true, |
|
422 | - $include_deleted = true, |
|
423 | - $limit = null |
|
424 | - ) { |
|
425 | - // sanitize id. |
|
426 | - $TKT_ID = absint($TKT_ID); |
|
427 | - $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
428 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
429 | - $where_params = array('Ticket.TKT_ID' => $TKT_ID); |
|
430 | - $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC')); |
|
431 | - if (! $include_expired) { |
|
432 | - $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
433 | - } |
|
434 | - if ($include_deleted) { |
|
435 | - $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
436 | - } |
|
437 | - if ($limit) { |
|
438 | - $query_params['limit'] = $limit; |
|
439 | - } |
|
440 | - /** @var EE_Datetime[] $result */ |
|
441 | - $result = $this->get_all($query_params); |
|
442 | - $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
443 | - return $result; |
|
444 | - } |
|
445 | - |
|
446 | - |
|
447 | - /** |
|
448 | - * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK |
|
449 | - * reason it doesn't exist, we consider the earliest event the most important) |
|
450 | - * |
|
451 | - * @param int $EVT_ID |
|
452 | - * @return EE_Datetime |
|
453 | - * @throws EE_Error |
|
454 | - */ |
|
455 | - public function get_most_important_datetime_for_event($EVT_ID) |
|
456 | - { |
|
457 | - $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1); |
|
458 | - if ($results) { |
|
459 | - return array_shift($results); |
|
460 | - } |
|
461 | - return null; |
|
462 | - } |
|
463 | - |
|
464 | - |
|
465 | - /** |
|
466 | - * This returns a wpdb->results Array of all DTT month and years matching the incoming query params and |
|
467 | - * grouped by month and year. |
|
468 | - * |
|
469 | - * @param array $where_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions |
|
470 | - * @param string $evt_active_status A string representing the evt active status to filter the months by. |
|
471 | - * Can be: |
|
472 | - * - '' = no filter |
|
473 | - * - upcoming = Published events with at least one upcoming datetime. |
|
474 | - * - expired = Events with all datetimes expired. |
|
475 | - * - active = Events that are published and have at least one datetime that |
|
476 | - * starts before now and ends after now. |
|
477 | - * - inactive = Events that are either not published. |
|
478 | - * @return EE_Base_Class[] |
|
479 | - * @throws EE_Error |
|
480 | - * @throws InvalidArgumentException |
|
481 | - * @throws InvalidArgumentException |
|
482 | - */ |
|
483 | - public function get_dtt_months_and_years($where_params, $evt_active_status = '') |
|
484 | - { |
|
485 | - $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start'); |
|
486 | - $current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end'); |
|
487 | - switch ($evt_active_status) { |
|
488 | - case 'upcoming': |
|
489 | - $where_params['Event.status'] = 'publish'; |
|
490 | - // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
491 | - if (isset($where_params['DTT_EVT_start'])) { |
|
492 | - $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start']; |
|
493 | - } |
|
494 | - $where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start); |
|
495 | - break; |
|
496 | - case 'expired': |
|
497 | - if (isset($where_params['Event.status'])) { |
|
498 | - unset($where_params['Event.status']); |
|
499 | - } |
|
500 | - // get events to exclude |
|
501 | - $exclude_query[0] = array_merge( |
|
502 | - $where_params, |
|
503 | - array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end)) |
|
504 | - ); |
|
505 | - // first get all events that have datetimes where its not expired. |
|
506 | - $event_ids = $this->_get_all_wpdb_results( |
|
507 | - $exclude_query, |
|
508 | - OBJECT_K, |
|
509 | - 'Datetime.EVT_ID' |
|
510 | - ); |
|
511 | - $event_ids = array_keys($event_ids); |
|
512 | - if (isset($where_params['DTT_EVT_end'])) { |
|
513 | - $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
514 | - } |
|
515 | - $where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end); |
|
516 | - $where_params['Event.EVT_ID'] = array('NOT IN', $event_ids); |
|
517 | - break; |
|
518 | - case 'active': |
|
519 | - $where_params['Event.status'] = 'publish'; |
|
520 | - if (isset($where_params['DTT_EVT_start'])) { |
|
521 | - $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start']; |
|
522 | - } |
|
523 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
524 | - $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end']; |
|
525 | - } |
|
526 | - $where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start); |
|
527 | - $where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end); |
|
528 | - break; |
|
529 | - case 'inactive': |
|
530 | - if (isset($where_params['Event.status'])) { |
|
531 | - unset($where_params['Event.status']); |
|
532 | - } |
|
533 | - if (isset($where_params['OR'])) { |
|
534 | - $where_params['AND']['OR'] = $where_params['OR']; |
|
535 | - } |
|
536 | - if (isset($where_params['DTT_EVT_end'])) { |
|
537 | - $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
538 | - unset($where_params['DTT_EVT_end']); |
|
539 | - } |
|
540 | - if (isset($where_params['DTT_EVT_start'])) { |
|
541 | - $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start']; |
|
542 | - unset($where_params['DTT_EVT_start']); |
|
543 | - } |
|
544 | - $where_params['AND']['Event.status'] = array('!=', 'publish'); |
|
545 | - break; |
|
546 | - } |
|
547 | - $query_params[0] = $where_params; |
|
548 | - $query_params['group_by'] = array('dtt_year', 'dtt_month'); |
|
549 | - $query_params['order_by'] = array('DTT_EVT_start' => 'DESC'); |
|
550 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset( |
|
551 | - $this->get_timezone(), |
|
552 | - 'DTT_EVT_start' |
|
553 | - ); |
|
554 | - $columns_to_select = array( |
|
555 | - 'dtt_year' => array('YEAR(' . $query_interval . ')', '%s'), |
|
556 | - 'dtt_month' => array('MONTHNAME(' . $query_interval . ')', '%s'), |
|
557 | - 'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'), |
|
558 | - ); |
|
559 | - return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - /** |
|
564 | - * Updates the DTT_sold attribute on each datetime (based on the registrations |
|
565 | - * for the tickets for each datetime) |
|
566 | - * |
|
567 | - * @param EE_Base_Class[]|EE_Datetime[] $datetimes |
|
568 | - * @throws EE_Error |
|
569 | - */ |
|
570 | - public function update_sold($datetimes) |
|
571 | - { |
|
572 | - EE_Error::doing_it_wrong( |
|
573 | - __FUNCTION__, |
|
574 | - esc_html__( |
|
575 | - 'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.', |
|
576 | - 'event_espresso' |
|
577 | - ), |
|
578 | - '4.9.32.rc.005' |
|
579 | - ); |
|
580 | - foreach ($datetimes as $datetime) { |
|
581 | - $datetime->update_sold(); |
|
582 | - } |
|
583 | - } |
|
584 | - |
|
585 | - |
|
586 | - /** |
|
587 | - * Gets the total number of tickets available at a particular datetime |
|
588 | - * (does NOT take into account the datetime's spaces available) |
|
589 | - * |
|
590 | - * @param int $DTT_ID |
|
591 | - * @param array $query_params |
|
592 | - * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF, IF there are NO |
|
593 | - * tickets attached to datetime then FALSE is returned. |
|
594 | - */ |
|
595 | - public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array()) |
|
596 | - { |
|
597 | - $datetime = $this->get_one_by_ID($DTT_ID); |
|
598 | - if ($datetime instanceof EE_Datetime) { |
|
599 | - return $datetime->tickets_remaining($query_params); |
|
600 | - } |
|
601 | - return 0; |
|
602 | - } |
|
603 | - |
|
604 | - |
|
605 | - /** |
|
606 | - * This returns an array of counts of datetimes in the database for each Datetime status that can be queried. |
|
607 | - * |
|
608 | - * @param array $stati_to_include If included you can restrict the statuses we return counts for by including the |
|
609 | - * stati you want counts for as values in the array. An empty array returns counts |
|
610 | - * for all valid stati. |
|
611 | - * @param array $query_params If included can be used to refine the conditions for returning the count (i.e. |
|
612 | - * only for Datetimes connected to a specific event, or specific ticket. |
|
613 | - * @return array The value returned is an array indexed by Datetime Status and the values are the counts. The |
|
614 | - * @throws EE_Error |
|
615 | - * stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming |
|
616 | - * EE_Datetime::expired |
|
617 | - */ |
|
618 | - public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array()) |
|
619 | - { |
|
620 | - // only accept where conditions for this query. |
|
621 | - $_where = isset($query_params[0]) ? $query_params[0] : array(); |
|
622 | - $status_query_args = array( |
|
623 | - EE_Datetime::active => array_merge( |
|
624 | - $_where, |
|
625 | - array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time())) |
|
626 | - ), |
|
627 | - EE_Datetime::upcoming => array_merge( |
|
628 | - $_where, |
|
629 | - array('DTT_EVT_start' => array('>', time())) |
|
630 | - ), |
|
631 | - EE_Datetime::expired => array_merge( |
|
632 | - $_where, |
|
633 | - array('DTT_EVT_end' => array('<', time())) |
|
634 | - ), |
|
635 | - ); |
|
636 | - if (! empty($stati_to_include)) { |
|
637 | - foreach (array_keys($status_query_args) as $status) { |
|
638 | - if (! in_array($status, $stati_to_include, true)) { |
|
639 | - unset($status_query_args[ $status ]); |
|
640 | - } |
|
641 | - } |
|
642 | - } |
|
643 | - // loop through and query counts for each stati. |
|
644 | - $status_query_results = array(); |
|
645 | - foreach ($status_query_args as $status => $status_where_conditions) { |
|
646 | - $status_query_results[ $status ] = EEM_Datetime::count( |
|
647 | - array($status_where_conditions), |
|
648 | - 'DTT_ID', |
|
649 | - true |
|
650 | - ); |
|
651 | - } |
|
652 | - return $status_query_results; |
|
653 | - } |
|
654 | - |
|
655 | - |
|
656 | - /** |
|
657 | - * Returns the specific count for a given Datetime status matching any given query_params. |
|
658 | - * |
|
659 | - * @param string $status Valid string representation for Datetime status requested. (Defaults to Active). |
|
660 | - * @param array $query_params |
|
661 | - * @return int |
|
662 | - * @throws EE_Error |
|
663 | - */ |
|
664 | - public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array()) |
|
665 | - { |
|
666 | - $count = $this->get_datetime_counts_by_status(array($status), $query_params); |
|
667 | - return ! empty($count[ $status ]) ? $count[ $status ] : 0; |
|
668 | - } |
|
12 | + /** |
|
13 | + * @var EEM_Datetime $_instance |
|
14 | + */ |
|
15 | + protected static $_instance; |
|
16 | + |
|
17 | + |
|
18 | + /** |
|
19 | + * private constructor to prevent direct creation |
|
20 | + * |
|
21 | + * @param string $timezone A string representing the timezone we want to set for returned Date Time Strings |
|
22 | + * (and any incoming timezone data that gets saved). |
|
23 | + * Note this just sends the timezone info to the date time model field objects. |
|
24 | + * Default is NULL |
|
25 | + * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
26 | + * @throws EE_Error |
|
27 | + * @throws InvalidArgumentException |
|
28 | + * @throws InvalidArgumentException |
|
29 | + */ |
|
30 | + protected function __construct($timezone) |
|
31 | + { |
|
32 | + $this->singular_item = esc_html__('Datetime', 'event_espresso'); |
|
33 | + $this->plural_item = esc_html__('Datetimes', 'event_espresso'); |
|
34 | + $this->_tables = array( |
|
35 | + 'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'), |
|
36 | + ); |
|
37 | + $this->_fields = array( |
|
38 | + 'Datetime' => array( |
|
39 | + 'DTT_ID' => new EE_Primary_Key_Int_Field( |
|
40 | + 'DTT_ID', |
|
41 | + esc_html__('Datetime ID', 'event_espresso') |
|
42 | + ), |
|
43 | + 'EVT_ID' => new EE_Foreign_Key_Int_Field( |
|
44 | + 'EVT_ID', |
|
45 | + esc_html__('Event ID', 'event_espresso'), |
|
46 | + false, |
|
47 | + 0, |
|
48 | + 'Event' |
|
49 | + ), |
|
50 | + 'DTT_name' => new EE_Plain_Text_Field( |
|
51 | + 'DTT_name', |
|
52 | + esc_html__('Datetime Name', 'event_espresso'), |
|
53 | + false, |
|
54 | + '' |
|
55 | + ), |
|
56 | + 'DTT_description' => new EE_Post_Content_Field( |
|
57 | + 'DTT_description', |
|
58 | + esc_html__('Description for Datetime', 'event_espresso'), |
|
59 | + false, |
|
60 | + '' |
|
61 | + ), |
|
62 | + 'DTT_EVT_start' => new EE_Datetime_Field( |
|
63 | + 'DTT_EVT_start', |
|
64 | + esc_html__('Start time/date of Event', 'event_espresso'), |
|
65 | + false, |
|
66 | + EE_Datetime_Field::now, |
|
67 | + $timezone |
|
68 | + ), |
|
69 | + 'DTT_EVT_end' => new EE_Datetime_Field( |
|
70 | + 'DTT_EVT_end', |
|
71 | + esc_html__('End time/date of Event', 'event_espresso'), |
|
72 | + false, |
|
73 | + EE_Datetime_Field::now, |
|
74 | + $timezone |
|
75 | + ), |
|
76 | + 'DTT_reg_limit' => new EE_Infinite_Integer_Field( |
|
77 | + 'DTT_reg_limit', |
|
78 | + esc_html__('Registration Limit for this time', 'event_espresso'), |
|
79 | + true, |
|
80 | + EE_INF |
|
81 | + ), |
|
82 | + 'DTT_sold' => new EE_Integer_Field( |
|
83 | + 'DTT_sold', |
|
84 | + esc_html__('How many sales for this Datetime that have occurred', 'event_espresso'), |
|
85 | + true, |
|
86 | + 0 |
|
87 | + ), |
|
88 | + 'DTT_reserved' => new EE_Integer_Field( |
|
89 | + 'DTT_reserved', |
|
90 | + esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'), |
|
91 | + false, |
|
92 | + 0 |
|
93 | + ), |
|
94 | + 'DTT_is_primary' => new EE_Boolean_Field( |
|
95 | + 'DTT_is_primary', |
|
96 | + esc_html__('Flag indicating datetime is primary one for event', 'event_espresso'), |
|
97 | + false, |
|
98 | + false |
|
99 | + ), |
|
100 | + 'DTT_order' => new EE_Integer_Field( |
|
101 | + 'DTT_order', |
|
102 | + esc_html__('The order in which the Datetime is displayed', 'event_espresso'), |
|
103 | + false, |
|
104 | + 0 |
|
105 | + ), |
|
106 | + 'DTT_parent' => new EE_Integer_Field( |
|
107 | + 'DTT_parent', |
|
108 | + esc_html__('Indicates what DTT_ID is the parent of this DTT_ID', 'event_espresso'), |
|
109 | + true, |
|
110 | + 0 |
|
111 | + ), |
|
112 | + 'DTT_deleted' => new EE_Trashed_Flag_Field( |
|
113 | + 'DTT_deleted', |
|
114 | + esc_html__('Flag indicating datetime is archived', 'event_espresso'), |
|
115 | + false, |
|
116 | + false |
|
117 | + ), |
|
118 | + ), |
|
119 | + ); |
|
120 | + $this->_model_relations = array( |
|
121 | + 'Ticket' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
122 | + 'Event' => new EE_Belongs_To_Relation(), |
|
123 | + 'Checkin' => new EE_Has_Many_Relation(), |
|
124 | + ); |
|
125 | + $path_to_event_model = 'Event'; |
|
126 | + $this->model_chain_to_password = $path_to_event_model; |
|
127 | + $this->_model_chain_to_wp_user = $path_to_event_model; |
|
128 | + // this model is generally available for reading |
|
129 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
130 | + $path_to_event_model |
|
131 | + ); |
|
132 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
133 | + $path_to_event_model |
|
134 | + ); |
|
135 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
136 | + $path_to_event_model |
|
137 | + ); |
|
138 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
139 | + $path_to_event_model, |
|
140 | + EEM_Base::caps_edit |
|
141 | + ); |
|
142 | + parent::__construct($timezone); |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * create new blank datetime |
|
148 | + * |
|
149 | + * @access public |
|
150 | + * @return EE_Datetime[] array on success, FALSE on fail |
|
151 | + * @throws EE_Error |
|
152 | + */ |
|
153 | + public function create_new_blank_datetime() |
|
154 | + { |
|
155 | + // makes sure timezone is always set. |
|
156 | + $timezone_string = $this->get_timezone(); |
|
157 | + $blank_datetime = EE_Datetime::new_instance( |
|
158 | + array( |
|
159 | + 'DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS, |
|
160 | + 'DTT_EVT_end' => $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS, |
|
161 | + 'DTT_order' => 1, |
|
162 | + 'DTT_reg_limit' => EE_INF, |
|
163 | + ), |
|
164 | + $timezone_string |
|
165 | + ); |
|
166 | + $blank_datetime->set_start_time( |
|
167 | + $this->convert_datetime_for_query( |
|
168 | + 'DTT_EVT_start', |
|
169 | + '8am', |
|
170 | + 'ga', |
|
171 | + $timezone_string |
|
172 | + ) |
|
173 | + ); |
|
174 | + $blank_datetime->set_end_time( |
|
175 | + $this->convert_datetime_for_query( |
|
176 | + 'DTT_EVT_end', |
|
177 | + '5pm', |
|
178 | + 'ga', |
|
179 | + $timezone_string |
|
180 | + ) |
|
181 | + ); |
|
182 | + return array($blank_datetime); |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * get event start date from db |
|
188 | + * |
|
189 | + * @access public |
|
190 | + * @param int $EVT_ID |
|
191 | + * @return EE_Datetime[] array on success, FALSE on fail |
|
192 | + * @throws EE_Error |
|
193 | + */ |
|
194 | + public function get_all_event_dates($EVT_ID = 0) |
|
195 | + { |
|
196 | + if (! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
197 | + return $this->create_new_blank_datetime(); |
|
198 | + } |
|
199 | + $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID); |
|
200 | + if (empty($results)) { |
|
201 | + return $this->create_new_blank_datetime(); |
|
202 | + } |
|
203 | + return $results; |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + /** |
|
208 | + * get all datetimes attached to an event ordered by the DTT_order field |
|
209 | + * |
|
210 | + * @public |
|
211 | + * @param int $EVT_ID event id |
|
212 | + * @param boolean $include_expired |
|
213 | + * @param boolean $include_deleted |
|
214 | + * @param int $limit If included then limit the count of results by |
|
215 | + * the given number |
|
216 | + * @return EE_Datetime[] |
|
217 | + * @throws EE_Error |
|
218 | + */ |
|
219 | + public function get_datetimes_for_event_ordered_by_DTT_order( |
|
220 | + $EVT_ID, |
|
221 | + $include_expired = true, |
|
222 | + $include_deleted = true, |
|
223 | + $limit = null |
|
224 | + ) { |
|
225 | + // sanitize EVT_ID |
|
226 | + $EVT_ID = absint($EVT_ID); |
|
227 | + $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
228 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
229 | + $where_params = array('Event.EVT_ID' => $EVT_ID); |
|
230 | + $query_params = ! empty($limit) |
|
231 | + ? array( |
|
232 | + $where_params, |
|
233 | + 'limit' => $limit, |
|
234 | + 'order_by' => array('DTT_order' => 'ASC'), |
|
235 | + 'default_where_conditions' => 'none', |
|
236 | + ) |
|
237 | + : array( |
|
238 | + $where_params, |
|
239 | + 'order_by' => array('DTT_order' => 'ASC'), |
|
240 | + 'default_where_conditions' => 'none', |
|
241 | + ); |
|
242 | + if (! $include_expired) { |
|
243 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
244 | + } |
|
245 | + if ($include_deleted) { |
|
246 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
247 | + } |
|
248 | + /** @var EE_Datetime[] $result */ |
|
249 | + $result = $this->get_all($query_params); |
|
250 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
251 | + return $result; |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * Gets the datetimes for the event (with the given limit), and orders them by "importance". |
|
257 | + * By importance, we mean that the primary datetimes are most important (DEPRECATED FOR NOW), |
|
258 | + * and then the earlier datetimes are the most important. |
|
259 | + * Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet. |
|
260 | + * |
|
261 | + * @param int $EVT_ID |
|
262 | + * @param int $limit |
|
263 | + * @return EE_Datetime[]|EE_Base_Class[] |
|
264 | + * @throws EE_Error |
|
265 | + */ |
|
266 | + public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null) |
|
267 | + { |
|
268 | + return $this->get_all( |
|
269 | + array( |
|
270 | + array('Event.EVT_ID' => $EVT_ID), |
|
271 | + 'limit' => $limit, |
|
272 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
273 | + 'default_where_conditions' => 'none', |
|
274 | + ) |
|
275 | + ); |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * @param int $EVT_ID |
|
281 | + * @param boolean $include_expired |
|
282 | + * @param boolean $include_deleted |
|
283 | + * @return EE_Datetime |
|
284 | + * @throws EE_Error |
|
285 | + */ |
|
286 | + public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false) |
|
287 | + { |
|
288 | + $results = $this->get_datetimes_for_event_ordered_by_start_time( |
|
289 | + $EVT_ID, |
|
290 | + $include_expired, |
|
291 | + $include_deleted, |
|
292 | + 1 |
|
293 | + ); |
|
294 | + if ($results) { |
|
295 | + return array_shift($results); |
|
296 | + } |
|
297 | + return null; |
|
298 | + } |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * Gets the 'primary' datetime for an event. |
|
303 | + * |
|
304 | + * @param int $EVT_ID |
|
305 | + * @param bool $try_to_exclude_expired |
|
306 | + * @param bool $try_to_exclude_deleted |
|
307 | + * @return \EE_Datetime |
|
308 | + * @throws EE_Error |
|
309 | + */ |
|
310 | + public function get_primary_datetime_for_event( |
|
311 | + $EVT_ID, |
|
312 | + $try_to_exclude_expired = true, |
|
313 | + $try_to_exclude_deleted = true |
|
314 | + ) { |
|
315 | + if ($try_to_exclude_expired) { |
|
316 | + $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false); |
|
317 | + if ($non_expired) { |
|
318 | + return $non_expired; |
|
319 | + } |
|
320 | + } |
|
321 | + if ($try_to_exclude_deleted) { |
|
322 | + $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true); |
|
323 | + if ($expired_even) { |
|
324 | + return $expired_even; |
|
325 | + } |
|
326 | + } |
|
327 | + return $this->get_oldest_datetime_for_event($EVT_ID, true, true); |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + /** |
|
332 | + * Gets ALL the datetimes for an event (including trashed ones, for now), ordered |
|
333 | + * only by start date |
|
334 | + * |
|
335 | + * @param int $EVT_ID |
|
336 | + * @param boolean $include_expired |
|
337 | + * @param boolean $include_deleted |
|
338 | + * @param int $limit |
|
339 | + * @return EE_Datetime[] |
|
340 | + * @throws EE_Error |
|
341 | + */ |
|
342 | + public function get_datetimes_for_event_ordered_by_start_time( |
|
343 | + $EVT_ID, |
|
344 | + $include_expired = true, |
|
345 | + $include_deleted = true, |
|
346 | + $limit = null |
|
347 | + ) { |
|
348 | + // sanitize EVT_ID |
|
349 | + $EVT_ID = absint($EVT_ID); |
|
350 | + $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
351 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
352 | + $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
|
353 | + if (! $include_expired) { |
|
354 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
355 | + } |
|
356 | + if ($include_deleted) { |
|
357 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
358 | + } |
|
359 | + if ($limit) { |
|
360 | + $query_params['limit'] = $limit; |
|
361 | + } |
|
362 | + /** @var EE_Datetime[] $result */ |
|
363 | + $result = $this->get_all($query_params); |
|
364 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
365 | + return $result; |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered |
|
371 | + * only by start date |
|
372 | + * |
|
373 | + * @param int $TKT_ID |
|
374 | + * @param boolean $include_expired |
|
375 | + * @param boolean $include_deleted |
|
376 | + * @param int $limit |
|
377 | + * @return EE_Datetime[] |
|
378 | + * @throws EE_Error |
|
379 | + */ |
|
380 | + public function get_datetimes_for_ticket_ordered_by_start_time( |
|
381 | + $TKT_ID, |
|
382 | + $include_expired = true, |
|
383 | + $include_deleted = true, |
|
384 | + $limit = null |
|
385 | + ) { |
|
386 | + // sanitize TKT_ID |
|
387 | + $TKT_ID = absint($TKT_ID); |
|
388 | + $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
389 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
390 | + $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
|
391 | + if (! $include_expired) { |
|
392 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
393 | + } |
|
394 | + if ($include_deleted) { |
|
395 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
396 | + } |
|
397 | + if ($limit) { |
|
398 | + $query_params['limit'] = $limit; |
|
399 | + } |
|
400 | + /** @var EE_Datetime[] $result */ |
|
401 | + $result = $this->get_all($query_params); |
|
402 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
403 | + return $result; |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the |
|
409 | + * datetimes. |
|
410 | + * |
|
411 | + * @param int $TKT_ID ID of ticket to retrieve the datetimes for |
|
412 | + * @param boolean $include_expired whether to include expired datetimes or not |
|
413 | + * @param boolean $include_deleted whether to include trashed datetimes or not. |
|
414 | + * @param int|null $limit if null, no limit, if int then limit results by |
|
415 | + * that number |
|
416 | + * @return EE_Datetime[] |
|
417 | + * @throws EE_Error |
|
418 | + */ |
|
419 | + public function get_datetimes_for_ticket_ordered_by_DTT_order( |
|
420 | + $TKT_ID, |
|
421 | + $include_expired = true, |
|
422 | + $include_deleted = true, |
|
423 | + $limit = null |
|
424 | + ) { |
|
425 | + // sanitize id. |
|
426 | + $TKT_ID = absint($TKT_ID); |
|
427 | + $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
428 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
429 | + $where_params = array('Ticket.TKT_ID' => $TKT_ID); |
|
430 | + $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC')); |
|
431 | + if (! $include_expired) { |
|
432 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
433 | + } |
|
434 | + if ($include_deleted) { |
|
435 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
436 | + } |
|
437 | + if ($limit) { |
|
438 | + $query_params['limit'] = $limit; |
|
439 | + } |
|
440 | + /** @var EE_Datetime[] $result */ |
|
441 | + $result = $this->get_all($query_params); |
|
442 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
443 | + return $result; |
|
444 | + } |
|
445 | + |
|
446 | + |
|
447 | + /** |
|
448 | + * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK |
|
449 | + * reason it doesn't exist, we consider the earliest event the most important) |
|
450 | + * |
|
451 | + * @param int $EVT_ID |
|
452 | + * @return EE_Datetime |
|
453 | + * @throws EE_Error |
|
454 | + */ |
|
455 | + public function get_most_important_datetime_for_event($EVT_ID) |
|
456 | + { |
|
457 | + $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1); |
|
458 | + if ($results) { |
|
459 | + return array_shift($results); |
|
460 | + } |
|
461 | + return null; |
|
462 | + } |
|
463 | + |
|
464 | + |
|
465 | + /** |
|
466 | + * This returns a wpdb->results Array of all DTT month and years matching the incoming query params and |
|
467 | + * grouped by month and year. |
|
468 | + * |
|
469 | + * @param array $where_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions |
|
470 | + * @param string $evt_active_status A string representing the evt active status to filter the months by. |
|
471 | + * Can be: |
|
472 | + * - '' = no filter |
|
473 | + * - upcoming = Published events with at least one upcoming datetime. |
|
474 | + * - expired = Events with all datetimes expired. |
|
475 | + * - active = Events that are published and have at least one datetime that |
|
476 | + * starts before now and ends after now. |
|
477 | + * - inactive = Events that are either not published. |
|
478 | + * @return EE_Base_Class[] |
|
479 | + * @throws EE_Error |
|
480 | + * @throws InvalidArgumentException |
|
481 | + * @throws InvalidArgumentException |
|
482 | + */ |
|
483 | + public function get_dtt_months_and_years($where_params, $evt_active_status = '') |
|
484 | + { |
|
485 | + $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start'); |
|
486 | + $current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end'); |
|
487 | + switch ($evt_active_status) { |
|
488 | + case 'upcoming': |
|
489 | + $where_params['Event.status'] = 'publish'; |
|
490 | + // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
491 | + if (isset($where_params['DTT_EVT_start'])) { |
|
492 | + $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start']; |
|
493 | + } |
|
494 | + $where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start); |
|
495 | + break; |
|
496 | + case 'expired': |
|
497 | + if (isset($where_params['Event.status'])) { |
|
498 | + unset($where_params['Event.status']); |
|
499 | + } |
|
500 | + // get events to exclude |
|
501 | + $exclude_query[0] = array_merge( |
|
502 | + $where_params, |
|
503 | + array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end)) |
|
504 | + ); |
|
505 | + // first get all events that have datetimes where its not expired. |
|
506 | + $event_ids = $this->_get_all_wpdb_results( |
|
507 | + $exclude_query, |
|
508 | + OBJECT_K, |
|
509 | + 'Datetime.EVT_ID' |
|
510 | + ); |
|
511 | + $event_ids = array_keys($event_ids); |
|
512 | + if (isset($where_params['DTT_EVT_end'])) { |
|
513 | + $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
514 | + } |
|
515 | + $where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end); |
|
516 | + $where_params['Event.EVT_ID'] = array('NOT IN', $event_ids); |
|
517 | + break; |
|
518 | + case 'active': |
|
519 | + $where_params['Event.status'] = 'publish'; |
|
520 | + if (isset($where_params['DTT_EVT_start'])) { |
|
521 | + $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start']; |
|
522 | + } |
|
523 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
524 | + $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end']; |
|
525 | + } |
|
526 | + $where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start); |
|
527 | + $where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end); |
|
528 | + break; |
|
529 | + case 'inactive': |
|
530 | + if (isset($where_params['Event.status'])) { |
|
531 | + unset($where_params['Event.status']); |
|
532 | + } |
|
533 | + if (isset($where_params['OR'])) { |
|
534 | + $where_params['AND']['OR'] = $where_params['OR']; |
|
535 | + } |
|
536 | + if (isset($where_params['DTT_EVT_end'])) { |
|
537 | + $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
538 | + unset($where_params['DTT_EVT_end']); |
|
539 | + } |
|
540 | + if (isset($where_params['DTT_EVT_start'])) { |
|
541 | + $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start']; |
|
542 | + unset($where_params['DTT_EVT_start']); |
|
543 | + } |
|
544 | + $where_params['AND']['Event.status'] = array('!=', 'publish'); |
|
545 | + break; |
|
546 | + } |
|
547 | + $query_params[0] = $where_params; |
|
548 | + $query_params['group_by'] = array('dtt_year', 'dtt_month'); |
|
549 | + $query_params['order_by'] = array('DTT_EVT_start' => 'DESC'); |
|
550 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset( |
|
551 | + $this->get_timezone(), |
|
552 | + 'DTT_EVT_start' |
|
553 | + ); |
|
554 | + $columns_to_select = array( |
|
555 | + 'dtt_year' => array('YEAR(' . $query_interval . ')', '%s'), |
|
556 | + 'dtt_month' => array('MONTHNAME(' . $query_interval . ')', '%s'), |
|
557 | + 'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'), |
|
558 | + ); |
|
559 | + return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + /** |
|
564 | + * Updates the DTT_sold attribute on each datetime (based on the registrations |
|
565 | + * for the tickets for each datetime) |
|
566 | + * |
|
567 | + * @param EE_Base_Class[]|EE_Datetime[] $datetimes |
|
568 | + * @throws EE_Error |
|
569 | + */ |
|
570 | + public function update_sold($datetimes) |
|
571 | + { |
|
572 | + EE_Error::doing_it_wrong( |
|
573 | + __FUNCTION__, |
|
574 | + esc_html__( |
|
575 | + 'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.', |
|
576 | + 'event_espresso' |
|
577 | + ), |
|
578 | + '4.9.32.rc.005' |
|
579 | + ); |
|
580 | + foreach ($datetimes as $datetime) { |
|
581 | + $datetime->update_sold(); |
|
582 | + } |
|
583 | + } |
|
584 | + |
|
585 | + |
|
586 | + /** |
|
587 | + * Gets the total number of tickets available at a particular datetime |
|
588 | + * (does NOT take into account the datetime's spaces available) |
|
589 | + * |
|
590 | + * @param int $DTT_ID |
|
591 | + * @param array $query_params |
|
592 | + * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF, IF there are NO |
|
593 | + * tickets attached to datetime then FALSE is returned. |
|
594 | + */ |
|
595 | + public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array()) |
|
596 | + { |
|
597 | + $datetime = $this->get_one_by_ID($DTT_ID); |
|
598 | + if ($datetime instanceof EE_Datetime) { |
|
599 | + return $datetime->tickets_remaining($query_params); |
|
600 | + } |
|
601 | + return 0; |
|
602 | + } |
|
603 | + |
|
604 | + |
|
605 | + /** |
|
606 | + * This returns an array of counts of datetimes in the database for each Datetime status that can be queried. |
|
607 | + * |
|
608 | + * @param array $stati_to_include If included you can restrict the statuses we return counts for by including the |
|
609 | + * stati you want counts for as values in the array. An empty array returns counts |
|
610 | + * for all valid stati. |
|
611 | + * @param array $query_params If included can be used to refine the conditions for returning the count (i.e. |
|
612 | + * only for Datetimes connected to a specific event, or specific ticket. |
|
613 | + * @return array The value returned is an array indexed by Datetime Status and the values are the counts. The |
|
614 | + * @throws EE_Error |
|
615 | + * stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming |
|
616 | + * EE_Datetime::expired |
|
617 | + */ |
|
618 | + public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array()) |
|
619 | + { |
|
620 | + // only accept where conditions for this query. |
|
621 | + $_where = isset($query_params[0]) ? $query_params[0] : array(); |
|
622 | + $status_query_args = array( |
|
623 | + EE_Datetime::active => array_merge( |
|
624 | + $_where, |
|
625 | + array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time())) |
|
626 | + ), |
|
627 | + EE_Datetime::upcoming => array_merge( |
|
628 | + $_where, |
|
629 | + array('DTT_EVT_start' => array('>', time())) |
|
630 | + ), |
|
631 | + EE_Datetime::expired => array_merge( |
|
632 | + $_where, |
|
633 | + array('DTT_EVT_end' => array('<', time())) |
|
634 | + ), |
|
635 | + ); |
|
636 | + if (! empty($stati_to_include)) { |
|
637 | + foreach (array_keys($status_query_args) as $status) { |
|
638 | + if (! in_array($status, $stati_to_include, true)) { |
|
639 | + unset($status_query_args[ $status ]); |
|
640 | + } |
|
641 | + } |
|
642 | + } |
|
643 | + // loop through and query counts for each stati. |
|
644 | + $status_query_results = array(); |
|
645 | + foreach ($status_query_args as $status => $status_where_conditions) { |
|
646 | + $status_query_results[ $status ] = EEM_Datetime::count( |
|
647 | + array($status_where_conditions), |
|
648 | + 'DTT_ID', |
|
649 | + true |
|
650 | + ); |
|
651 | + } |
|
652 | + return $status_query_results; |
|
653 | + } |
|
654 | + |
|
655 | + |
|
656 | + /** |
|
657 | + * Returns the specific count for a given Datetime status matching any given query_params. |
|
658 | + * |
|
659 | + * @param string $status Valid string representation for Datetime status requested. (Defaults to Active). |
|
660 | + * @param array $query_params |
|
661 | + * @return int |
|
662 | + * @throws EE_Error |
|
663 | + */ |
|
664 | + public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array()) |
|
665 | + { |
|
666 | + $count = $this->get_datetime_counts_by_status(array($status), $query_params); |
|
667 | + return ! empty($count[ $status ]) ? $count[ $status ] : 0; |
|
668 | + } |
|
669 | 669 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | ), |
118 | 118 | ), |
119 | 119 | ); |
120 | - $this->_model_relations = array( |
|
120 | + $this->_model_relations = array( |
|
121 | 121 | 'Ticket' => new EE_HABTM_Relation('Datetime_Ticket'), |
122 | 122 | 'Event' => new EE_Belongs_To_Relation(), |
123 | 123 | 'Checkin' => new EE_Has_Many_Relation(), |
@@ -126,16 +126,16 @@ discard block |
||
126 | 126 | $this->model_chain_to_password = $path_to_event_model; |
127 | 127 | $this->_model_chain_to_wp_user = $path_to_event_model; |
128 | 128 | // this model is generally available for reading |
129 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
129 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public( |
|
130 | 130 | $path_to_event_model |
131 | 131 | ); |
132 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
132 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected( |
|
133 | 133 | $path_to_event_model |
134 | 134 | ); |
135 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
135 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected( |
|
136 | 136 | $path_to_event_model |
137 | 137 | ); |
138 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
138 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected( |
|
139 | 139 | $path_to_event_model, |
140 | 140 | EEM_Base::caps_edit |
141 | 141 | ); |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | */ |
194 | 194 | public function get_all_event_dates($EVT_ID = 0) |
195 | 195 | { |
196 | - if (! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
196 | + if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
197 | 197 | return $this->create_new_blank_datetime(); |
198 | 198 | } |
199 | 199 | $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID); |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | 'order_by' => array('DTT_order' => 'ASC'), |
240 | 240 | 'default_where_conditions' => 'none', |
241 | 241 | ); |
242 | - if (! $include_expired) { |
|
242 | + if ( ! $include_expired) { |
|
243 | 243 | $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
244 | 244 | } |
245 | 245 | if ($include_deleted) { |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
351 | 351 | $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
352 | 352 | $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
353 | - if (! $include_expired) { |
|
353 | + if ( ! $include_expired) { |
|
354 | 354 | $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
355 | 355 | } |
356 | 356 | if ($include_deleted) { |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
389 | 389 | $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
390 | 390 | $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
391 | - if (! $include_expired) { |
|
391 | + if ( ! $include_expired) { |
|
392 | 392 | $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
393 | 393 | } |
394 | 394 | if ($include_deleted) { |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
429 | 429 | $where_params = array('Ticket.TKT_ID' => $TKT_ID); |
430 | 430 | $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC')); |
431 | - if (! $include_expired) { |
|
431 | + if ( ! $include_expired) { |
|
432 | 432 | $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
433 | 433 | } |
434 | 434 | if ($include_deleted) { |
@@ -551,10 +551,10 @@ discard block |
||
551 | 551 | $this->get_timezone(), |
552 | 552 | 'DTT_EVT_start' |
553 | 553 | ); |
554 | - $columns_to_select = array( |
|
555 | - 'dtt_year' => array('YEAR(' . $query_interval . ')', '%s'), |
|
556 | - 'dtt_month' => array('MONTHNAME(' . $query_interval . ')', '%s'), |
|
557 | - 'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'), |
|
554 | + $columns_to_select = array( |
|
555 | + 'dtt_year' => array('YEAR('.$query_interval.')', '%s'), |
|
556 | + 'dtt_month' => array('MONTHNAME('.$query_interval.')', '%s'), |
|
557 | + 'dtt_month_num' => array('MONTH('.$query_interval.')', '%s'), |
|
558 | 558 | ); |
559 | 559 | return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
560 | 560 | } |
@@ -633,17 +633,17 @@ discard block |
||
633 | 633 | array('DTT_EVT_end' => array('<', time())) |
634 | 634 | ), |
635 | 635 | ); |
636 | - if (! empty($stati_to_include)) { |
|
636 | + if ( ! empty($stati_to_include)) { |
|
637 | 637 | foreach (array_keys($status_query_args) as $status) { |
638 | - if (! in_array($status, $stati_to_include, true)) { |
|
639 | - unset($status_query_args[ $status ]); |
|
638 | + if ( ! in_array($status, $stati_to_include, true)) { |
|
639 | + unset($status_query_args[$status]); |
|
640 | 640 | } |
641 | 641 | } |
642 | 642 | } |
643 | 643 | // loop through and query counts for each stati. |
644 | 644 | $status_query_results = array(); |
645 | 645 | foreach ($status_query_args as $status => $status_where_conditions) { |
646 | - $status_query_results[ $status ] = EEM_Datetime::count( |
|
646 | + $status_query_results[$status] = EEM_Datetime::count( |
|
647 | 647 | array($status_where_conditions), |
648 | 648 | 'DTT_ID', |
649 | 649 | true |
@@ -664,6 +664,6 @@ discard block |
||
664 | 664 | public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array()) |
665 | 665 | { |
666 | 666 | $count = $this->get_datetime_counts_by_status(array($status), $query_params); |
667 | - return ! empty($count[ $status ]) ? $count[ $status ] : 0; |
|
667 | + return ! empty($count[$status]) ? $count[$status] : 0; |
|
668 | 668 | } |
669 | 669 | } |
@@ -20,380 +20,380 @@ |
||
20 | 20 | class EEM_Payment_Method extends EEM_Base |
21 | 21 | { |
22 | 22 | |
23 | - const scope_cart = 'CART'; |
|
24 | - |
|
25 | - const scope_admin = 'ADMIN'; |
|
26 | - |
|
27 | - const scope_api = 'API'; |
|
28 | - |
|
29 | - /** |
|
30 | - * |
|
31 | - * @type EEM_Payment_Method |
|
32 | - */ |
|
33 | - protected static $_instance = null; |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * private constructor to prevent direct creation |
|
39 | - * @Constructor |
|
40 | - * @access protected |
|
41 | - * @return EEM_Payment_Method |
|
42 | - */ |
|
43 | - protected function __construct($timezone = null) |
|
44 | - { |
|
45 | - $this->singlular_item = __('Payment Method', 'event_espresso'); |
|
46 | - $this->plural_item = __('Payment Methods', 'event_espresso'); |
|
47 | - $this->_tables = array( 'Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID') ); |
|
48 | - $this->_fields = array( |
|
49 | - 'Payment_Method' => array( |
|
50 | - 'PMD_ID' => new EE_Primary_Key_Int_Field('PMD_ID', __("ID", 'event_espresso')), |
|
51 | - 'PMD_type' => new EE_Plain_Text_Field('PMD_type', __("Payment Method Type", 'event_espresso'), false, 'Admin_Only'), |
|
52 | - 'PMD_name' => new EE_Plain_Text_Field('PMD_name', __("Name", 'event_espresso'), false), |
|
53 | - 'PMD_desc' => new EE_Post_Content_Field('PMD_desc', __("Description", 'event_espresso'), false, ''), |
|
54 | - 'PMD_admin_name' => new EE_Plain_Text_Field('PMD_admin_name', __("Admin-Only Name", 'event_espresso'), true), |
|
55 | - 'PMD_admin_desc' => new EE_Post_Content_Field('PMD_admin_desc', __("Admin-Only Description", 'event_espresso'), true), |
|
56 | - 'PMD_slug' => new EE_Slug_Field('PMD_slug', __("Slug", 'event_espresso'), false), |
|
57 | - 'PMD_order' => new EE_Integer_Field('PMD_order', __("Order", 'event_espresso'), false, 0), |
|
58 | - 'PMD_debug_mode' => new EE_Boolean_Field('PMD_debug_mode', __("Debug Mode On?", 'event_espresso'), false, false), |
|
59 | - 'PMD_wp_user' => new EE_WP_User_Field('PMD_wp_user', __("Payment Method Creator ID", 'event_espresso'), false), |
|
60 | - 'PMD_open_by_default' => new EE_Boolean_Field('PMD_open_by_default', __("Open by Default?", 'event_espresso'), false, false), 'PMD_button_url' => new EE_Plain_Text_Field('PMD_button_url', __("Button URL", 'event_espresso'), true, ''), |
|
61 | - 'PMD_scope' => new EE_Serialized_Text_Field('PMD_scope', __("Usable From?", 'event_espresso'), false, array()), // possible values currently are 'CART','ADMIN','API' |
|
62 | - ) ); |
|
63 | - $this->_model_relations = array( |
|
64 | - 'Payment' => new EE_Has_Many_Relation(), |
|
65 | - 'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'), |
|
66 | - 'Transaction' => new EE_Has_Many_Relation(), |
|
67 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
68 | - ); |
|
69 | - parent::__construct($timezone); |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * Gets one by the slug provided |
|
76 | - * @param string $slug |
|
77 | - * @return EE_Payment_Method |
|
78 | - */ |
|
79 | - public function get_one_by_slug($slug) |
|
80 | - { |
|
81 | - return $this->get_one(array( array( 'PMD_slug' => $slug ) )); |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * Gets all the acceptable scopes for payment methods. |
|
88 | - * Keys are their names as store din the DB, and values are nice names for displaying them |
|
89 | - * @return array |
|
90 | - */ |
|
91 | - public function scopes() |
|
92 | - { |
|
93 | - return apply_filters( |
|
94 | - 'FHEE__EEM_Payment_Method__scopes', |
|
95 | - array( |
|
96 | - self::scope_cart => __("Front-end Registration Page", 'event_espresso'), |
|
97 | - self::scope_admin => __("Admin Registration Page (no online processing)", 'event_espresso') |
|
98 | - ) |
|
99 | - ); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * Determines if this is an valid scope |
|
106 | - * @param string $scope like one of EEM_Payment_Method::instance()->scopes() |
|
107 | - * @return boolean |
|
108 | - */ |
|
109 | - public function is_valid_scope($scope) |
|
110 | - { |
|
111 | - $scopes = $this->scopes(); |
|
112 | - if (isset($scopes[ $scope ])) { |
|
113 | - return true; |
|
114 | - } else { |
|
115 | - return false; |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * Gets all active payment methods |
|
123 | - * @param string $scope one of |
|
124 | - * @param array $query_params |
|
125 | - * @throws EE_Error |
|
126 | - * @return EE_Payment_Method[] |
|
127 | - */ |
|
128 | - public function get_all_active($scope = null, $query_params = array()) |
|
129 | - { |
|
130 | - if (! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
131 | - $query_params['order_by'] = array( 'PMD_order' => 'ASC', 'PMD_ID' => 'ASC' ); |
|
132 | - } |
|
133 | - return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params)); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Counts all active gateways in the specified scope |
|
138 | - * @param string $scope one of EEM_Payment_Method::scope_* |
|
139 | - * @param array $query_params |
|
140 | - * @return int |
|
141 | - */ |
|
142 | - public function count_active($scope = null, $query_params = array()) |
|
143 | - { |
|
144 | - return $this->count($this->_get_query_params_for_all_active($scope, $query_params)); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
149 | - * argument to get all active for a given scope |
|
150 | - * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
151 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
152 | - * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
153 | - * @throws EE_Error |
|
154 | - */ |
|
155 | - protected function _get_query_params_for_all_active($scope = null, $query_params = array()) |
|
156 | - { |
|
157 | - if ($scope) { |
|
158 | - if ($this->is_valid_scope($scope)) { |
|
159 | - return array_replace_recursive(array( array( 'PMD_scope' => array( 'LIKE', "%$scope%" ) ) ), $query_params); |
|
160 | - } else { |
|
161 | - throw new EE_Error(sprintf(__("'%s' is not a valid scope for a payment method", "event_espresso"), $scope)); |
|
162 | - } |
|
163 | - } else { |
|
164 | - $acceptable_scopes = array(); |
|
165 | - $count = 0; |
|
166 | - foreach ($this->scopes() as $scope_name => $desc) { |
|
167 | - $count++; |
|
168 | - $acceptable_scopes[ 'PMD_scope*' . $count ] = array( 'LIKE', '%' . $scope_name . '%' ); |
|
169 | - } |
|
170 | - return array_replace_recursive(array( array( 'OR*active_scope' => $acceptable_scopes ) ), $query_params); |
|
171 | - } |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
176 | - * argument to get all active for a given scope |
|
177 | - * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
178 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
179 | - * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
180 | - * @throws EE_Error |
|
181 | - */ |
|
182 | - public function get_query_params_for_all_active($scope = null, $query_params = array()) |
|
183 | - { |
|
184 | - return $this->_get_query_params_for_all_active($scope, $query_params); |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * Gets one active payment method. see @get_all_active for documentation |
|
190 | - * @param string $scope |
|
191 | - * @param array $query_params |
|
192 | - * @return EE_Payment_Method |
|
193 | - */ |
|
194 | - public function get_one_active($scope = null, $query_params = array()) |
|
195 | - { |
|
196 | - return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params)); |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * Gets one payment method of that type, regardless of whether its active or not |
|
203 | - * @param string $type |
|
204 | - * @return EE_Payment_Method |
|
205 | - */ |
|
206 | - public function get_one_of_type($type) |
|
207 | - { |
|
208 | - return $this->get_one(array( array( 'PMD_type' => $type ) )); |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * Overrides parent ot also check by the slug |
|
215 | - * @see EEM_Base::ensure_is_obj() |
|
216 | - * @param string|int|EE_Payment_Method $base_class_obj_or_id |
|
217 | - * @param boolean $ensure_is_in_db |
|
218 | - * @return EE_Payment_Method |
|
219 | - * @throws EE_Error |
|
220 | - */ |
|
221 | - public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = false) |
|
222 | - { |
|
223 | - // first: check if it's a slug |
|
224 | - if (is_string($base_class_obj_or_id)) { |
|
225 | - $obj = $this->get_one_by_slug($base_class_obj_or_id); |
|
226 | - if ($obj) { |
|
227 | - return $obj; |
|
228 | - } |
|
229 | - } |
|
230 | - // ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID) |
|
231 | - try { |
|
232 | - return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db); |
|
233 | - } catch (EE_Error $e) { |
|
234 | - // handle it outside the catch |
|
235 | - } |
|
236 | - throw new EE_Error(sprintf(__("'%s' is neither a Payment Method ID, slug, nor object.", "event_espresso"), $base_class_obj_or_id)); |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * Gets the ID of this object, or if its a string finds the object's id |
|
243 | - * associated with that slug |
|
244 | - * @param mixed $base_obj_or_id_or_slug |
|
245 | - * @return int |
|
246 | - */ |
|
247 | - public function ensure_is_ID($base_obj_or_id_or_slug) |
|
248 | - { |
|
249 | - if (is_string($base_obj_or_id_or_slug)) { |
|
250 | - // assume it's a slug |
|
251 | - $base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug); |
|
252 | - } |
|
253 | - return parent::ensure_is_ID($base_obj_or_id_or_slug); |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * Verifies the button urls on all the passed payment methods have a valid button url. If not, resets them to their default. |
|
260 | - * @param EE_Payment_Method[] $payment_methods. If NULL is provided defaults to all payment methods active in the cart |
|
261 | - */ |
|
262 | - public function verify_button_urls($payment_methods = null) |
|
263 | - { |
|
264 | - $payment_methods = is_array($payment_methods) ? $payment_methods : $this->get_all_active(EEM_Payment_Method::scope_cart); |
|
265 | - foreach ($payment_methods as $payment_method) { |
|
266 | - try { |
|
267 | - $current_button_url = $payment_method->button_url(); |
|
268 | - $buttons_urls_to_try = apply_filters('FHEE__EEM_Payment_Method__verify_button_urls__button_urls_to_try', array( |
|
269 | - 'current_ssl' => str_replace("http://", "https://", $current_button_url), |
|
270 | - 'current' => str_replace("https://", "http://", $current_button_url), |
|
271 | - 'default_ssl' => str_replace("http://", "https://", $payment_method->type_obj()->default_button_url()), |
|
272 | - 'default' => str_replace("https://", "http://", $payment_method->type_obj()->default_button_url()), |
|
273 | - )); |
|
274 | - foreach ($buttons_urls_to_try as $button_url_to_try) { |
|
275 | - if ((// this is the current url and it exists, regardless of SSL issues |
|
276 | - $button_url_to_try == $current_button_url && |
|
277 | - EEH_URL::remote_file_exists( |
|
278 | - $button_url_to_try, |
|
279 | - array( |
|
280 | - 'sslverify' => false, |
|
281 | - 'limit_response_size' => 4095,// we don't really care for a full response, but we do want headers at least. Lets just ask for a one block |
|
282 | - ) |
|
283 | - ) |
|
284 | - ) |
|
285 | - || |
|
286 | - (// this is NOT the current url and it exists with a working SSL cert |
|
287 | - $button_url_to_try != $current_button_url && |
|
288 | - EEH_URL::remote_file_exists($button_url_to_try) |
|
289 | - ) ) { |
|
290 | - if ($current_button_url != $button_url_to_try) { |
|
291 | - $payment_method->save(array( 'PMD_button_url' => $button_url_to_try )); |
|
292 | - EE_Error::add_attention(sprintf(__("Payment Method %s's button url was set to %s, because the old image either didnt exist or SSL was recently enabled.", "event_espresso"), $payment_method->name(), $button_url_to_try)); |
|
293 | - } |
|
294 | - // this image exists. So if wasn't set before, now it is; |
|
295 | - // or if it was already set, we have nothing to do |
|
296 | - break; |
|
297 | - } |
|
298 | - } |
|
299 | - } catch (EE_Error $e) { |
|
300 | - $payment_method->set_active(false); |
|
301 | - } |
|
302 | - } |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * Overrides parent to not only turn wpdb results into EE_Payment_Method objects, |
|
309 | - * but also verifies the payment method type of each is a usable object. If not, |
|
310 | - * deactivate it, sets a notification, and deactivates it |
|
311 | - * |
|
312 | - * @param array $rows |
|
313 | - * @return EE_Payment_Method[] |
|
314 | - * @throws InvalidDataTypeException |
|
315 | - */ |
|
316 | - protected function _create_objects($rows = array()) |
|
317 | - { |
|
318 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
319 | - $payment_methods = parent::_create_objects($rows); |
|
320 | - /* @var $payment_methods EE_Payment_Method[] */ |
|
321 | - $usable_payment_methods = array(); |
|
322 | - foreach ($payment_methods as $key => $payment_method) { |
|
323 | - if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { |
|
324 | - $usable_payment_methods[ $key ] = $payment_method; |
|
325 | - // some payment methods enqueue their scripts in EE_PMT_*::__construct |
|
326 | - // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue |
|
327 | - // its scripts). but for backwards-compat we should continue to do that |
|
328 | - $payment_method->type_obj(); |
|
329 | - } elseif ($payment_method->active()) { |
|
330 | - // only deactivate and notify the admin if the payment is active somewhere |
|
331 | - $payment_method->deactivate(); |
|
332 | - $payment_method->save(); |
|
333 | - do_action( |
|
334 | - 'AHEE__EEM_Payment_Method___create_objects_auto_deactivated_payment_method', |
|
335 | - $payment_method |
|
336 | - ); |
|
337 | - new PersistentAdminNotice( |
|
338 | - 'auto-deactivated-' . $payment_method->type(), |
|
339 | - sprintf( |
|
340 | - __( |
|
341 | - 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
|
342 | - 'event_espresso' |
|
343 | - ), |
|
344 | - $payment_method->admin_name(), |
|
345 | - '<br />', |
|
346 | - '<a href="' . admin_url('plugins.php') . '">', |
|
347 | - '</a>' |
|
348 | - ), |
|
349 | - true |
|
350 | - ); |
|
351 | - } |
|
352 | - } |
|
353 | - return $usable_payment_methods; |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - |
|
358 | - /** |
|
359 | - * Gets all the payment methods which can be used for transaction |
|
360 | - * (according to the relations between payment methods and events, and |
|
361 | - * the currencies used for the transaction and their relation to payment methods) |
|
362 | - * @param EE_Transaction $transaction |
|
363 | - * @param string $scope @see EEM_Payment_Method::get_all_for_events |
|
364 | - * @return EE_Payment_Method[] |
|
365 | - */ |
|
366 | - public function get_all_for_transaction($transaction, $scope) |
|
367 | - { |
|
368 | - // give addons a chance to override what payment methods are chosen based on the transaction |
|
369 | - return apply_filters( |
|
370 | - 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods', |
|
371 | - $this->get_all_active($scope, array( 'group_by' => 'PMD_type' )), |
|
372 | - $transaction, |
|
373 | - $scope |
|
374 | - ); |
|
375 | - } |
|
376 | - |
|
377 | - |
|
378 | - /** |
|
379 | - * Returns the payment method used for the last payment made for a registration. |
|
380 | - * |
|
381 | - * Note: if an offline payment method was selected on the related transaction then this will have no payment methods returned. |
|
382 | - * It will ONLY return a payment method for a PAYMENT recorded against the registration. |
|
383 | - * |
|
384 | - * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the registration. |
|
385 | - * @return EE_Payment|null |
|
386 | - */ |
|
387 | - public function get_last_used_for_registration($registration_or_reg_id) |
|
388 | - { |
|
389 | - $registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id); |
|
390 | - |
|
391 | - $query_params = array( |
|
392 | - 0 => array( |
|
393 | - 'Payment.Registration.REG_ID' => $registration_id, |
|
394 | - ), |
|
395 | - 'order_by' => array( 'Payment.PAY_ID' => 'DESC' ) |
|
396 | - ); |
|
397 | - return $this->get_one($query_params); |
|
398 | - } |
|
23 | + const scope_cart = 'CART'; |
|
24 | + |
|
25 | + const scope_admin = 'ADMIN'; |
|
26 | + |
|
27 | + const scope_api = 'API'; |
|
28 | + |
|
29 | + /** |
|
30 | + * |
|
31 | + * @type EEM_Payment_Method |
|
32 | + */ |
|
33 | + protected static $_instance = null; |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * private constructor to prevent direct creation |
|
39 | + * @Constructor |
|
40 | + * @access protected |
|
41 | + * @return EEM_Payment_Method |
|
42 | + */ |
|
43 | + protected function __construct($timezone = null) |
|
44 | + { |
|
45 | + $this->singlular_item = __('Payment Method', 'event_espresso'); |
|
46 | + $this->plural_item = __('Payment Methods', 'event_espresso'); |
|
47 | + $this->_tables = array( 'Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID') ); |
|
48 | + $this->_fields = array( |
|
49 | + 'Payment_Method' => array( |
|
50 | + 'PMD_ID' => new EE_Primary_Key_Int_Field('PMD_ID', __("ID", 'event_espresso')), |
|
51 | + 'PMD_type' => new EE_Plain_Text_Field('PMD_type', __("Payment Method Type", 'event_espresso'), false, 'Admin_Only'), |
|
52 | + 'PMD_name' => new EE_Plain_Text_Field('PMD_name', __("Name", 'event_espresso'), false), |
|
53 | + 'PMD_desc' => new EE_Post_Content_Field('PMD_desc', __("Description", 'event_espresso'), false, ''), |
|
54 | + 'PMD_admin_name' => new EE_Plain_Text_Field('PMD_admin_name', __("Admin-Only Name", 'event_espresso'), true), |
|
55 | + 'PMD_admin_desc' => new EE_Post_Content_Field('PMD_admin_desc', __("Admin-Only Description", 'event_espresso'), true), |
|
56 | + 'PMD_slug' => new EE_Slug_Field('PMD_slug', __("Slug", 'event_espresso'), false), |
|
57 | + 'PMD_order' => new EE_Integer_Field('PMD_order', __("Order", 'event_espresso'), false, 0), |
|
58 | + 'PMD_debug_mode' => new EE_Boolean_Field('PMD_debug_mode', __("Debug Mode On?", 'event_espresso'), false, false), |
|
59 | + 'PMD_wp_user' => new EE_WP_User_Field('PMD_wp_user', __("Payment Method Creator ID", 'event_espresso'), false), |
|
60 | + 'PMD_open_by_default' => new EE_Boolean_Field('PMD_open_by_default', __("Open by Default?", 'event_espresso'), false, false), 'PMD_button_url' => new EE_Plain_Text_Field('PMD_button_url', __("Button URL", 'event_espresso'), true, ''), |
|
61 | + 'PMD_scope' => new EE_Serialized_Text_Field('PMD_scope', __("Usable From?", 'event_espresso'), false, array()), // possible values currently are 'CART','ADMIN','API' |
|
62 | + ) ); |
|
63 | + $this->_model_relations = array( |
|
64 | + 'Payment' => new EE_Has_Many_Relation(), |
|
65 | + 'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'), |
|
66 | + 'Transaction' => new EE_Has_Many_Relation(), |
|
67 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
68 | + ); |
|
69 | + parent::__construct($timezone); |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * Gets one by the slug provided |
|
76 | + * @param string $slug |
|
77 | + * @return EE_Payment_Method |
|
78 | + */ |
|
79 | + public function get_one_by_slug($slug) |
|
80 | + { |
|
81 | + return $this->get_one(array( array( 'PMD_slug' => $slug ) )); |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * Gets all the acceptable scopes for payment methods. |
|
88 | + * Keys are their names as store din the DB, and values are nice names for displaying them |
|
89 | + * @return array |
|
90 | + */ |
|
91 | + public function scopes() |
|
92 | + { |
|
93 | + return apply_filters( |
|
94 | + 'FHEE__EEM_Payment_Method__scopes', |
|
95 | + array( |
|
96 | + self::scope_cart => __("Front-end Registration Page", 'event_espresso'), |
|
97 | + self::scope_admin => __("Admin Registration Page (no online processing)", 'event_espresso') |
|
98 | + ) |
|
99 | + ); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * Determines if this is an valid scope |
|
106 | + * @param string $scope like one of EEM_Payment_Method::instance()->scopes() |
|
107 | + * @return boolean |
|
108 | + */ |
|
109 | + public function is_valid_scope($scope) |
|
110 | + { |
|
111 | + $scopes = $this->scopes(); |
|
112 | + if (isset($scopes[ $scope ])) { |
|
113 | + return true; |
|
114 | + } else { |
|
115 | + return false; |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * Gets all active payment methods |
|
123 | + * @param string $scope one of |
|
124 | + * @param array $query_params |
|
125 | + * @throws EE_Error |
|
126 | + * @return EE_Payment_Method[] |
|
127 | + */ |
|
128 | + public function get_all_active($scope = null, $query_params = array()) |
|
129 | + { |
|
130 | + if (! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
131 | + $query_params['order_by'] = array( 'PMD_order' => 'ASC', 'PMD_ID' => 'ASC' ); |
|
132 | + } |
|
133 | + return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params)); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Counts all active gateways in the specified scope |
|
138 | + * @param string $scope one of EEM_Payment_Method::scope_* |
|
139 | + * @param array $query_params |
|
140 | + * @return int |
|
141 | + */ |
|
142 | + public function count_active($scope = null, $query_params = array()) |
|
143 | + { |
|
144 | + return $this->count($this->_get_query_params_for_all_active($scope, $query_params)); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
149 | + * argument to get all active for a given scope |
|
150 | + * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
151 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
152 | + * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
153 | + * @throws EE_Error |
|
154 | + */ |
|
155 | + protected function _get_query_params_for_all_active($scope = null, $query_params = array()) |
|
156 | + { |
|
157 | + if ($scope) { |
|
158 | + if ($this->is_valid_scope($scope)) { |
|
159 | + return array_replace_recursive(array( array( 'PMD_scope' => array( 'LIKE', "%$scope%" ) ) ), $query_params); |
|
160 | + } else { |
|
161 | + throw new EE_Error(sprintf(__("'%s' is not a valid scope for a payment method", "event_espresso"), $scope)); |
|
162 | + } |
|
163 | + } else { |
|
164 | + $acceptable_scopes = array(); |
|
165 | + $count = 0; |
|
166 | + foreach ($this->scopes() as $scope_name => $desc) { |
|
167 | + $count++; |
|
168 | + $acceptable_scopes[ 'PMD_scope*' . $count ] = array( 'LIKE', '%' . $scope_name . '%' ); |
|
169 | + } |
|
170 | + return array_replace_recursive(array( array( 'OR*active_scope' => $acceptable_scopes ) ), $query_params); |
|
171 | + } |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
176 | + * argument to get all active for a given scope |
|
177 | + * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
178 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
179 | + * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
180 | + * @throws EE_Error |
|
181 | + */ |
|
182 | + public function get_query_params_for_all_active($scope = null, $query_params = array()) |
|
183 | + { |
|
184 | + return $this->_get_query_params_for_all_active($scope, $query_params); |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * Gets one active payment method. see @get_all_active for documentation |
|
190 | + * @param string $scope |
|
191 | + * @param array $query_params |
|
192 | + * @return EE_Payment_Method |
|
193 | + */ |
|
194 | + public function get_one_active($scope = null, $query_params = array()) |
|
195 | + { |
|
196 | + return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params)); |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * Gets one payment method of that type, regardless of whether its active or not |
|
203 | + * @param string $type |
|
204 | + * @return EE_Payment_Method |
|
205 | + */ |
|
206 | + public function get_one_of_type($type) |
|
207 | + { |
|
208 | + return $this->get_one(array( array( 'PMD_type' => $type ) )); |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * Overrides parent ot also check by the slug |
|
215 | + * @see EEM_Base::ensure_is_obj() |
|
216 | + * @param string|int|EE_Payment_Method $base_class_obj_or_id |
|
217 | + * @param boolean $ensure_is_in_db |
|
218 | + * @return EE_Payment_Method |
|
219 | + * @throws EE_Error |
|
220 | + */ |
|
221 | + public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = false) |
|
222 | + { |
|
223 | + // first: check if it's a slug |
|
224 | + if (is_string($base_class_obj_or_id)) { |
|
225 | + $obj = $this->get_one_by_slug($base_class_obj_or_id); |
|
226 | + if ($obj) { |
|
227 | + return $obj; |
|
228 | + } |
|
229 | + } |
|
230 | + // ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID) |
|
231 | + try { |
|
232 | + return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db); |
|
233 | + } catch (EE_Error $e) { |
|
234 | + // handle it outside the catch |
|
235 | + } |
|
236 | + throw new EE_Error(sprintf(__("'%s' is neither a Payment Method ID, slug, nor object.", "event_espresso"), $base_class_obj_or_id)); |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * Gets the ID of this object, or if its a string finds the object's id |
|
243 | + * associated with that slug |
|
244 | + * @param mixed $base_obj_or_id_or_slug |
|
245 | + * @return int |
|
246 | + */ |
|
247 | + public function ensure_is_ID($base_obj_or_id_or_slug) |
|
248 | + { |
|
249 | + if (is_string($base_obj_or_id_or_slug)) { |
|
250 | + // assume it's a slug |
|
251 | + $base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug); |
|
252 | + } |
|
253 | + return parent::ensure_is_ID($base_obj_or_id_or_slug); |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * Verifies the button urls on all the passed payment methods have a valid button url. If not, resets them to their default. |
|
260 | + * @param EE_Payment_Method[] $payment_methods. If NULL is provided defaults to all payment methods active in the cart |
|
261 | + */ |
|
262 | + public function verify_button_urls($payment_methods = null) |
|
263 | + { |
|
264 | + $payment_methods = is_array($payment_methods) ? $payment_methods : $this->get_all_active(EEM_Payment_Method::scope_cart); |
|
265 | + foreach ($payment_methods as $payment_method) { |
|
266 | + try { |
|
267 | + $current_button_url = $payment_method->button_url(); |
|
268 | + $buttons_urls_to_try = apply_filters('FHEE__EEM_Payment_Method__verify_button_urls__button_urls_to_try', array( |
|
269 | + 'current_ssl' => str_replace("http://", "https://", $current_button_url), |
|
270 | + 'current' => str_replace("https://", "http://", $current_button_url), |
|
271 | + 'default_ssl' => str_replace("http://", "https://", $payment_method->type_obj()->default_button_url()), |
|
272 | + 'default' => str_replace("https://", "http://", $payment_method->type_obj()->default_button_url()), |
|
273 | + )); |
|
274 | + foreach ($buttons_urls_to_try as $button_url_to_try) { |
|
275 | + if ((// this is the current url and it exists, regardless of SSL issues |
|
276 | + $button_url_to_try == $current_button_url && |
|
277 | + EEH_URL::remote_file_exists( |
|
278 | + $button_url_to_try, |
|
279 | + array( |
|
280 | + 'sslverify' => false, |
|
281 | + 'limit_response_size' => 4095,// we don't really care for a full response, but we do want headers at least. Lets just ask for a one block |
|
282 | + ) |
|
283 | + ) |
|
284 | + ) |
|
285 | + || |
|
286 | + (// this is NOT the current url and it exists with a working SSL cert |
|
287 | + $button_url_to_try != $current_button_url && |
|
288 | + EEH_URL::remote_file_exists($button_url_to_try) |
|
289 | + ) ) { |
|
290 | + if ($current_button_url != $button_url_to_try) { |
|
291 | + $payment_method->save(array( 'PMD_button_url' => $button_url_to_try )); |
|
292 | + EE_Error::add_attention(sprintf(__("Payment Method %s's button url was set to %s, because the old image either didnt exist or SSL was recently enabled.", "event_espresso"), $payment_method->name(), $button_url_to_try)); |
|
293 | + } |
|
294 | + // this image exists. So if wasn't set before, now it is; |
|
295 | + // or if it was already set, we have nothing to do |
|
296 | + break; |
|
297 | + } |
|
298 | + } |
|
299 | + } catch (EE_Error $e) { |
|
300 | + $payment_method->set_active(false); |
|
301 | + } |
|
302 | + } |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * Overrides parent to not only turn wpdb results into EE_Payment_Method objects, |
|
309 | + * but also verifies the payment method type of each is a usable object. If not, |
|
310 | + * deactivate it, sets a notification, and deactivates it |
|
311 | + * |
|
312 | + * @param array $rows |
|
313 | + * @return EE_Payment_Method[] |
|
314 | + * @throws InvalidDataTypeException |
|
315 | + */ |
|
316 | + protected function _create_objects($rows = array()) |
|
317 | + { |
|
318 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
319 | + $payment_methods = parent::_create_objects($rows); |
|
320 | + /* @var $payment_methods EE_Payment_Method[] */ |
|
321 | + $usable_payment_methods = array(); |
|
322 | + foreach ($payment_methods as $key => $payment_method) { |
|
323 | + if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { |
|
324 | + $usable_payment_methods[ $key ] = $payment_method; |
|
325 | + // some payment methods enqueue their scripts in EE_PMT_*::__construct |
|
326 | + // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue |
|
327 | + // its scripts). but for backwards-compat we should continue to do that |
|
328 | + $payment_method->type_obj(); |
|
329 | + } elseif ($payment_method->active()) { |
|
330 | + // only deactivate and notify the admin if the payment is active somewhere |
|
331 | + $payment_method->deactivate(); |
|
332 | + $payment_method->save(); |
|
333 | + do_action( |
|
334 | + 'AHEE__EEM_Payment_Method___create_objects_auto_deactivated_payment_method', |
|
335 | + $payment_method |
|
336 | + ); |
|
337 | + new PersistentAdminNotice( |
|
338 | + 'auto-deactivated-' . $payment_method->type(), |
|
339 | + sprintf( |
|
340 | + __( |
|
341 | + 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
|
342 | + 'event_espresso' |
|
343 | + ), |
|
344 | + $payment_method->admin_name(), |
|
345 | + '<br />', |
|
346 | + '<a href="' . admin_url('plugins.php') . '">', |
|
347 | + '</a>' |
|
348 | + ), |
|
349 | + true |
|
350 | + ); |
|
351 | + } |
|
352 | + } |
|
353 | + return $usable_payment_methods; |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + |
|
358 | + /** |
|
359 | + * Gets all the payment methods which can be used for transaction |
|
360 | + * (according to the relations between payment methods and events, and |
|
361 | + * the currencies used for the transaction and their relation to payment methods) |
|
362 | + * @param EE_Transaction $transaction |
|
363 | + * @param string $scope @see EEM_Payment_Method::get_all_for_events |
|
364 | + * @return EE_Payment_Method[] |
|
365 | + */ |
|
366 | + public function get_all_for_transaction($transaction, $scope) |
|
367 | + { |
|
368 | + // give addons a chance to override what payment methods are chosen based on the transaction |
|
369 | + return apply_filters( |
|
370 | + 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods', |
|
371 | + $this->get_all_active($scope, array( 'group_by' => 'PMD_type' )), |
|
372 | + $transaction, |
|
373 | + $scope |
|
374 | + ); |
|
375 | + } |
|
376 | + |
|
377 | + |
|
378 | + /** |
|
379 | + * Returns the payment method used for the last payment made for a registration. |
|
380 | + * |
|
381 | + * Note: if an offline payment method was selected on the related transaction then this will have no payment methods returned. |
|
382 | + * It will ONLY return a payment method for a PAYMENT recorded against the registration. |
|
383 | + * |
|
384 | + * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the registration. |
|
385 | + * @return EE_Payment|null |
|
386 | + */ |
|
387 | + public function get_last_used_for_registration($registration_or_reg_id) |
|
388 | + { |
|
389 | + $registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id); |
|
390 | + |
|
391 | + $query_params = array( |
|
392 | + 0 => array( |
|
393 | + 'Payment.Registration.REG_ID' => $registration_id, |
|
394 | + ), |
|
395 | + 'order_by' => array( 'Payment.PAY_ID' => 'DESC' ) |
|
396 | + ); |
|
397 | + return $this->get_one($query_params); |
|
398 | + } |
|
399 | 399 | } |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.74.rc.004'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.74.rc.004'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |