@@ -17,122 +17,122 @@ |
||
17 | 17 | class GatewayDataFormatter implements GatewayDataFormatterInterface |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * Gets the text to use for a gateway's line item name when this is a partial payment |
|
22 | - * |
|
23 | - * @param \EEI_Payment $payment |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public function formatPartialPaymentLineItemName(\EEI_Payment $payment) |
|
27 | - { |
|
28 | - return apply_filters( |
|
29 | - 'EEG_Paypal_Pro__do_direct_payment__partial_amount_line_item_name', |
|
30 | - $payment->get_first_event_name(), |
|
31 | - $this, |
|
32 | - $payment |
|
33 | - ); |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * Gets the text to use for a gateway's line item description when this is a partial payment |
|
40 | - * |
|
41 | - * @param \EEI_Payment $payment |
|
42 | - * @return string |
|
43 | - */ |
|
44 | - public function formatPartialPaymentLineItemDesc(\EEI_Payment $payment) |
|
45 | - { |
|
46 | - return apply_filters( |
|
47 | - 'FHEE__EE_Gateway___partial_payment_desc', |
|
48 | - sprintf( |
|
49 | - __("Payment of %s for %s", "event_espresso"), |
|
50 | - $payment->get_pretty('PAY_amount', 'no_currency_code'), |
|
51 | - $payment->get_first_event_name() |
|
52 | - ), |
|
53 | - $this, |
|
54 | - $payment |
|
55 | - ); |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * Gets the name to use for a line item when sending line items to the gateway |
|
62 | - * |
|
63 | - * @param \EEI_Line_Item $line_item |
|
64 | - * @param \EEI_Payment $payment |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function formatLineItemName(\EEI_Line_Item $line_item, \EEI_Payment $payment) |
|
68 | - { |
|
69 | - return apply_filters( |
|
70 | - 'FHEE__EE_gateway___line_item_name', |
|
71 | - sprintf( |
|
72 | - _x('%1$s for %2$s', 'Ticket for Event', 'event_espresso'), |
|
73 | - $line_item->name(), |
|
74 | - $line_item->ticket_event_name() |
|
75 | - ), |
|
76 | - $this, |
|
77 | - $line_item, |
|
78 | - $payment |
|
79 | - ); |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * Gets the description to use for a line item when sending line items to the gateway |
|
86 | - * |
|
87 | - * @param \EEI_Line_Item $line_item |
|
88 | - * @param \EEI_Payment $payment |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public function formatLineItemDesc(\EEI_Line_Item $line_item, \EEI_Payment $payment) |
|
92 | - { |
|
93 | - return apply_filters( |
|
94 | - 'FHEE__EE_Gateway___line_item_desc', |
|
95 | - $line_item->desc(), |
|
96 | - $this, |
|
97 | - $line_item, |
|
98 | - $payment |
|
99 | - ); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * Gets the order description that should generally be sent to gateways |
|
106 | - * |
|
107 | - * @param \EEI_Payment $payment |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - public function formatOrderDescription(\EEI_Payment $payment) |
|
111 | - { |
|
112 | - return apply_filters( |
|
113 | - 'FHEE__EE_Gateway___order_description', |
|
114 | - sprintf( |
|
115 | - __('Event Registrations from %1$s for %2$s', "event_espresso"), |
|
116 | - get_bloginfo('name'), |
|
117 | - $payment->get_first_event_name() |
|
118 | - ), |
|
119 | - $this, |
|
120 | - $payment |
|
121 | - ); |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * Formats the amount so it can generally be sent to gateways |
|
128 | - * |
|
129 | - * @param float $amount |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - public function formatCurrency($amount) |
|
133 | - { |
|
134 | - return number_format($amount, 2, '.', ''); |
|
135 | - } |
|
20 | + /** |
|
21 | + * Gets the text to use for a gateway's line item name when this is a partial payment |
|
22 | + * |
|
23 | + * @param \EEI_Payment $payment |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public function formatPartialPaymentLineItemName(\EEI_Payment $payment) |
|
27 | + { |
|
28 | + return apply_filters( |
|
29 | + 'EEG_Paypal_Pro__do_direct_payment__partial_amount_line_item_name', |
|
30 | + $payment->get_first_event_name(), |
|
31 | + $this, |
|
32 | + $payment |
|
33 | + ); |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * Gets the text to use for a gateway's line item description when this is a partial payment |
|
40 | + * |
|
41 | + * @param \EEI_Payment $payment |
|
42 | + * @return string |
|
43 | + */ |
|
44 | + public function formatPartialPaymentLineItemDesc(\EEI_Payment $payment) |
|
45 | + { |
|
46 | + return apply_filters( |
|
47 | + 'FHEE__EE_Gateway___partial_payment_desc', |
|
48 | + sprintf( |
|
49 | + __("Payment of %s for %s", "event_espresso"), |
|
50 | + $payment->get_pretty('PAY_amount', 'no_currency_code'), |
|
51 | + $payment->get_first_event_name() |
|
52 | + ), |
|
53 | + $this, |
|
54 | + $payment |
|
55 | + ); |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * Gets the name to use for a line item when sending line items to the gateway |
|
62 | + * |
|
63 | + * @param \EEI_Line_Item $line_item |
|
64 | + * @param \EEI_Payment $payment |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function formatLineItemName(\EEI_Line_Item $line_item, \EEI_Payment $payment) |
|
68 | + { |
|
69 | + return apply_filters( |
|
70 | + 'FHEE__EE_gateway___line_item_name', |
|
71 | + sprintf( |
|
72 | + _x('%1$s for %2$s', 'Ticket for Event', 'event_espresso'), |
|
73 | + $line_item->name(), |
|
74 | + $line_item->ticket_event_name() |
|
75 | + ), |
|
76 | + $this, |
|
77 | + $line_item, |
|
78 | + $payment |
|
79 | + ); |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * Gets the description to use for a line item when sending line items to the gateway |
|
86 | + * |
|
87 | + * @param \EEI_Line_Item $line_item |
|
88 | + * @param \EEI_Payment $payment |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public function formatLineItemDesc(\EEI_Line_Item $line_item, \EEI_Payment $payment) |
|
92 | + { |
|
93 | + return apply_filters( |
|
94 | + 'FHEE__EE_Gateway___line_item_desc', |
|
95 | + $line_item->desc(), |
|
96 | + $this, |
|
97 | + $line_item, |
|
98 | + $payment |
|
99 | + ); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * Gets the order description that should generally be sent to gateways |
|
106 | + * |
|
107 | + * @param \EEI_Payment $payment |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + public function formatOrderDescription(\EEI_Payment $payment) |
|
111 | + { |
|
112 | + return apply_filters( |
|
113 | + 'FHEE__EE_Gateway___order_description', |
|
114 | + sprintf( |
|
115 | + __('Event Registrations from %1$s for %2$s', "event_espresso"), |
|
116 | + get_bloginfo('name'), |
|
117 | + $payment->get_first_event_name() |
|
118 | + ), |
|
119 | + $this, |
|
120 | + $payment |
|
121 | + ); |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * Formats the amount so it can generally be sent to gateways |
|
128 | + * |
|
129 | + * @param float $amount |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + public function formatCurrency($amount) |
|
133 | + { |
|
134 | + return number_format($amount, 2, '.', ''); |
|
135 | + } |
|
136 | 136 | } |
137 | 137 | // End of file GatewayDataFormatter.php |
138 | 138 | // Location: core\services\gateways/GatewayDataFormatter.php |
139 | 139 | \ No newline at end of file |
@@ -16,65 +16,65 @@ |
||
16 | 16 | interface GatewayDataFormatterInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * Gets the text to use for a gateway's line item name when this is a partial payment |
|
21 | - * |
|
22 | - * @param \EEI_Payment $payment |
|
23 | - * @return string |
|
24 | - */ |
|
25 | - public function formatPartialPaymentLineItemName(\EEI_Payment $payment); |
|
19 | + /** |
|
20 | + * Gets the text to use for a gateway's line item name when this is a partial payment |
|
21 | + * |
|
22 | + * @param \EEI_Payment $payment |
|
23 | + * @return string |
|
24 | + */ |
|
25 | + public function formatPartialPaymentLineItemName(\EEI_Payment $payment); |
|
26 | 26 | |
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * Gets the text to use for a gateway's line item description when this is a partial payment |
|
31 | - * |
|
32 | - * @param \EEI_Payment $payment |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - public function formatPartialPaymentLineItemDesc(\EEI_Payment $payment); |
|
29 | + /** |
|
30 | + * Gets the text to use for a gateway's line item description when this is a partial payment |
|
31 | + * |
|
32 | + * @param \EEI_Payment $payment |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public function formatPartialPaymentLineItemDesc(\EEI_Payment $payment); |
|
36 | 36 | |
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * Gets the name to use for a line item when sending line items to the gateway |
|
41 | - * |
|
42 | - * @param \EEI_Line_Item $line_item |
|
43 | - * @param \EEI_Payment $payment |
|
44 | - * @return string |
|
45 | - */ |
|
46 | - public function formatLineItemName(\EEI_Line_Item $line_item, \EEI_Payment $payment); |
|
39 | + /** |
|
40 | + * Gets the name to use for a line item when sending line items to the gateway |
|
41 | + * |
|
42 | + * @param \EEI_Line_Item $line_item |
|
43 | + * @param \EEI_Payment $payment |
|
44 | + * @return string |
|
45 | + */ |
|
46 | + public function formatLineItemName(\EEI_Line_Item $line_item, \EEI_Payment $payment); |
|
47 | 47 | |
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * Gets the description to use for a line item when sending line items to the gateway |
|
52 | - * |
|
53 | - * @param \EEI_Line_Item $line_item |
|
54 | - * @param \EEI_Payment $payment |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - public function formatLineItemDesc(\EEI_Line_Item $line_item, \EEI_Payment $payment); |
|
50 | + /** |
|
51 | + * Gets the description to use for a line item when sending line items to the gateway |
|
52 | + * |
|
53 | + * @param \EEI_Line_Item $line_item |
|
54 | + * @param \EEI_Payment $payment |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + public function formatLineItemDesc(\EEI_Line_Item $line_item, \EEI_Payment $payment); |
|
58 | 58 | |
59 | 59 | |
60 | 60 | |
61 | - /** |
|
62 | - * Gets the order description that should generally be sent to gateways |
|
63 | - * |
|
64 | - * @param \EEI_Payment $payment |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function formatOrderDescription(\EEI_Payment $payment); |
|
61 | + /** |
|
62 | + * Gets the order description that should generally be sent to gateways |
|
63 | + * |
|
64 | + * @param \EEI_Payment $payment |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function formatOrderDescription(\EEI_Payment $payment); |
|
68 | 68 | |
69 | 69 | |
70 | 70 | |
71 | - /** |
|
72 | - * Formats the amount so it can generally be sent to gateways |
|
73 | - * |
|
74 | - * @param float $amount |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - public function formatCurrency($amount); |
|
71 | + /** |
|
72 | + * Formats the amount so it can generally be sent to gateways |
|
73 | + * |
|
74 | + * @param float $amount |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + public function formatCurrency($amount); |
|
78 | 78 | } |
79 | 79 | // End of file GatewayDataFormatterInterface.php |
80 | 80 | // Location: core\services\payment_methods\gateways/GatewayDataFormatterInterface.php |
81 | 81 | \ No newline at end of file |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | public function getModelSchemaForFields(array $model_fields, array $schema) |
65 | 65 | { |
66 | 66 | foreach ($model_fields as $field => $model_field) { |
67 | - if (! $model_field instanceof EE_Model_Field_Base) { |
|
67 | + if ( ! $model_field instanceof EE_Model_Field_Base) { |
|
68 | 68 | continue; |
69 | 69 | } |
70 | 70 | $schema['properties'][$field] = $model_field->getSchema(); |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | public function getModelSchemaForRelations(array $relations_on_model, array $schema) |
96 | 96 | { |
97 | 97 | foreach ($relations_on_model as $model_name => $relation) { |
98 | - if (! $relation instanceof EE_Model_Relation_Base) { |
|
98 | + if ( ! $relation instanceof EE_Model_Relation_Base) { |
|
99 | 99 | continue; |
100 | 100 | } |
101 | 101 | $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation |
@@ -25,120 +25,120 @@ |
||
25 | 25 | class JsonModelSchema |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * @var \EEM_Base |
|
30 | - */ |
|
31 | - protected $model; |
|
32 | - |
|
33 | - /** |
|
34 | - * JsonModelSchema constructor. |
|
35 | - * |
|
36 | - * @param \EEM_Base $model |
|
37 | - */ |
|
38 | - public function __construct(EEM_Base $model) |
|
39 | - { |
|
40 | - $this->model = $model; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Return the schema for a given model from a given model. |
|
45 | - * @param \EEM_Base $model |
|
46 | - * @return array |
|
47 | - */ |
|
48 | - public function getModelSchema() |
|
49 | - { |
|
50 | - return $this->getModelSchemaForRelations( |
|
51 | - $this->model->relation_settings(), |
|
52 | - $this->getModelSchemaForFields( |
|
53 | - $this->model->field_settings(), |
|
54 | - $this->getInitialSchemaStructure() |
|
55 | - ) |
|
56 | - ); |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * Get the schema for a given set of model fields. |
|
62 | - * @param \EE_Model_Field_Base[] $model_fields |
|
63 | - * @return array |
|
64 | - */ |
|
65 | - public function getModelSchemaForFields(array $model_fields, array $schema) |
|
66 | - { |
|
67 | - foreach ($model_fields as $field => $model_field) { |
|
68 | - if (! $model_field instanceof EE_Model_Field_Base) { |
|
69 | - continue; |
|
70 | - } |
|
71 | - $schema['properties'][$field] = $model_field->getSchema(); |
|
72 | - |
|
73 | - //if this is a primary key field add the primary key item |
|
74 | - if ($model_field instanceof EE_Primary_Key_Field_Base) { |
|
75 | - $schema['properties'][$field]['primary_key'] = true; |
|
76 | - if ($model_field instanceof EE_Primary_Key_Int_Field) { |
|
77 | - $schema['properties'][$field]['readonly'] = true; |
|
78 | - } |
|
79 | - } |
|
80 | - |
|
81 | - //if this is a foreign key field add the foreign key item |
|
82 | - if ($model_field instanceof EE_Foreign_Key_Field_Base) { |
|
83 | - $schema['properties'][$field]['foreign_key'] = array( |
|
84 | - 'description' => esc_html__('This is a foreign key the points to the given models.', 'event_espresso'), |
|
85 | - 'type' => 'array', |
|
86 | - 'enum' => $model_field->get_model_class_names_pointed_to() |
|
87 | - ); |
|
88 | - } |
|
89 | - } |
|
90 | - return $schema; |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * Get the schema for a given set of model relations |
|
96 | - * @param EE_Model_Relation_Base[] $relations_on_model |
|
97 | - * @return array |
|
98 | - */ |
|
99 | - public function getModelSchemaForRelations(array $relations_on_model, array $schema) |
|
100 | - { |
|
101 | - foreach ($relations_on_model as $model_name => $relation) { |
|
102 | - if (! $relation instanceof EE_Model_Relation_Base) { |
|
103 | - continue; |
|
104 | - } |
|
105 | - $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation |
|
106 | - ? strtolower($model_name) |
|
107 | - : EEH_Inflector::pluralize_and_lower($model_name); |
|
108 | - $schema['properties'][$model_name_for_schema] = $relation->getSchema(); |
|
109 | - $schema['properties'][$model_name_for_schema]['relation_model'] = $model_name; |
|
110 | - } |
|
111 | - return $schema; |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * Outputs the schema header for a model. |
|
117 | - * @param \EEM_Base $model |
|
118 | - * @return array |
|
119 | - */ |
|
120 | - public function getInitialSchemaStructure() |
|
121 | - { |
|
122 | - return array( |
|
123 | - '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
124 | - 'title' => $this->model->get_this_model_name(), |
|
125 | - 'type' => 'object', |
|
126 | - 'properties' => array() |
|
127 | - ); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * Allows one to just use the object as a string to get the json. |
|
133 | - * eg. |
|
134 | - * |
|
135 | - * $json_schema = new JsonModelSchema(EEM_Event::instance()); |
|
136 | - * echo $json_schema; //outputs the schema as a json formatted string. |
|
137 | - * |
|
138 | - * @return bool|false|mixed|string |
|
139 | - */ |
|
140 | - public function __toString() |
|
141 | - { |
|
142 | - return wp_json_encode($this->getModelSchema()); |
|
143 | - } |
|
28 | + /** |
|
29 | + * @var \EEM_Base |
|
30 | + */ |
|
31 | + protected $model; |
|
32 | + |
|
33 | + /** |
|
34 | + * JsonModelSchema constructor. |
|
35 | + * |
|
36 | + * @param \EEM_Base $model |
|
37 | + */ |
|
38 | + public function __construct(EEM_Base $model) |
|
39 | + { |
|
40 | + $this->model = $model; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Return the schema for a given model from a given model. |
|
45 | + * @param \EEM_Base $model |
|
46 | + * @return array |
|
47 | + */ |
|
48 | + public function getModelSchema() |
|
49 | + { |
|
50 | + return $this->getModelSchemaForRelations( |
|
51 | + $this->model->relation_settings(), |
|
52 | + $this->getModelSchemaForFields( |
|
53 | + $this->model->field_settings(), |
|
54 | + $this->getInitialSchemaStructure() |
|
55 | + ) |
|
56 | + ); |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * Get the schema for a given set of model fields. |
|
62 | + * @param \EE_Model_Field_Base[] $model_fields |
|
63 | + * @return array |
|
64 | + */ |
|
65 | + public function getModelSchemaForFields(array $model_fields, array $schema) |
|
66 | + { |
|
67 | + foreach ($model_fields as $field => $model_field) { |
|
68 | + if (! $model_field instanceof EE_Model_Field_Base) { |
|
69 | + continue; |
|
70 | + } |
|
71 | + $schema['properties'][$field] = $model_field->getSchema(); |
|
72 | + |
|
73 | + //if this is a primary key field add the primary key item |
|
74 | + if ($model_field instanceof EE_Primary_Key_Field_Base) { |
|
75 | + $schema['properties'][$field]['primary_key'] = true; |
|
76 | + if ($model_field instanceof EE_Primary_Key_Int_Field) { |
|
77 | + $schema['properties'][$field]['readonly'] = true; |
|
78 | + } |
|
79 | + } |
|
80 | + |
|
81 | + //if this is a foreign key field add the foreign key item |
|
82 | + if ($model_field instanceof EE_Foreign_Key_Field_Base) { |
|
83 | + $schema['properties'][$field]['foreign_key'] = array( |
|
84 | + 'description' => esc_html__('This is a foreign key the points to the given models.', 'event_espresso'), |
|
85 | + 'type' => 'array', |
|
86 | + 'enum' => $model_field->get_model_class_names_pointed_to() |
|
87 | + ); |
|
88 | + } |
|
89 | + } |
|
90 | + return $schema; |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * Get the schema for a given set of model relations |
|
96 | + * @param EE_Model_Relation_Base[] $relations_on_model |
|
97 | + * @return array |
|
98 | + */ |
|
99 | + public function getModelSchemaForRelations(array $relations_on_model, array $schema) |
|
100 | + { |
|
101 | + foreach ($relations_on_model as $model_name => $relation) { |
|
102 | + if (! $relation instanceof EE_Model_Relation_Base) { |
|
103 | + continue; |
|
104 | + } |
|
105 | + $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation |
|
106 | + ? strtolower($model_name) |
|
107 | + : EEH_Inflector::pluralize_and_lower($model_name); |
|
108 | + $schema['properties'][$model_name_for_schema] = $relation->getSchema(); |
|
109 | + $schema['properties'][$model_name_for_schema]['relation_model'] = $model_name; |
|
110 | + } |
|
111 | + return $schema; |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * Outputs the schema header for a model. |
|
117 | + * @param \EEM_Base $model |
|
118 | + * @return array |
|
119 | + */ |
|
120 | + public function getInitialSchemaStructure() |
|
121 | + { |
|
122 | + return array( |
|
123 | + '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
124 | + 'title' => $this->model->get_this_model_name(), |
|
125 | + 'type' => 'object', |
|
126 | + 'properties' => array() |
|
127 | + ); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * Allows one to just use the object as a string to get the json. |
|
133 | + * eg. |
|
134 | + * |
|
135 | + * $json_schema = new JsonModelSchema(EEM_Event::instance()); |
|
136 | + * echo $json_schema; //outputs the schema as a json formatted string. |
|
137 | + * |
|
138 | + * @return bool|false|mixed|string |
|
139 | + */ |
|
140 | + public function __toString() |
|
141 | + { |
|
142 | + return wp_json_encode($this->getModelSchema()); |
|
143 | + } |
|
144 | 144 | } |
@@ -16,23 +16,23 @@ |
||
16 | 16 | interface FormatterInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * Applies the formatting to all items in the array |
|
21 | - * |
|
22 | - * @param array $input accepts a multi-dimensional array, but all "leaf nodes" are easily cast to a string |
|
23 | - * @return array |
|
24 | - */ |
|
25 | - public function formatArray($input); |
|
26 | - |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * Formats the string |
|
31 | - * |
|
32 | - * @param string|int|float $input anything easily cast into a string |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - public function format($input); |
|
19 | + /** |
|
20 | + * Applies the formatting to all items in the array |
|
21 | + * |
|
22 | + * @param array $input accepts a multi-dimensional array, but all "leaf nodes" are easily cast to a string |
|
23 | + * @return array |
|
24 | + */ |
|
25 | + public function formatArray($input); |
|
26 | + |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * Formats the string |
|
31 | + * |
|
32 | + * @param string|int|float $input anything easily cast into a string |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public function format($input); |
|
36 | 36 | } |
37 | 37 | // End of file FormatterInterface.php |
38 | 38 | // Location: core\services\formatters/FormatterInterface.php |
39 | 39 | \ No newline at end of file |
@@ -234,7 +234,7 @@ |
||
234 | 234 | /** |
235 | 235 | * delete multiple transients and remove tracking |
236 | 236 | * |
237 | - * @param array $transient_keys [required] array of full or partial transient keys to be deleted |
|
237 | + * @param string[] $transient_keys [required] array of full or partial transient keys to be deleted |
|
238 | 238 | */ |
239 | 239 | public function deleteMany(array $transient_keys) |
240 | 240 | { |
@@ -1,10 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\services\cache; |
3 | 3 | |
4 | -use EE_Error; |
|
5 | -use WP_Error; |
|
6 | -use wpdb; |
|
7 | - |
|
8 | 4 | defined('EVENT_ESPRESSO_VERSION') || exit; |
9 | 5 | |
10 | 6 |
@@ -23,361 +23,361 @@ |
||
23 | 23 | class TransientCacheStorage implements CacheStorageInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * wp-option option_name for tracking transients |
|
28 | - * |
|
29 | - * @type string |
|
30 | - */ |
|
31 | - const TRANSIENT_SCHEDULE_OPTIONS_KEY = 'ee_transient_schedule'; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var int $current_time |
|
35 | - */ |
|
36 | - private $current_time = 0; |
|
37 | - |
|
38 | - /** |
|
39 | - * how often to perform transient cleanup |
|
40 | - * |
|
41 | - * @var string $transient_cleanup_frequency |
|
42 | - */ |
|
43 | - private $transient_cleanup_frequency = 'hour'; |
|
44 | - |
|
45 | - /** |
|
46 | - * options for how often to perform transient cleanup |
|
47 | - * |
|
48 | - * @var array $transient_cleanup_frequency_options |
|
49 | - */ |
|
50 | - private $transient_cleanup_frequency_options = array(); |
|
51 | - |
|
52 | - /** |
|
53 | - * @var array $transients |
|
54 | - */ |
|
55 | - private $transients = array(); |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * TransientCacheStorage constructor. |
|
61 | - */ |
|
62 | - public function __construct() |
|
63 | - { |
|
64 | - $this->transient_cleanup_frequency = $this->setTransientCleanupFrequency(); |
|
65 | - // round current time down to closest 5 minutes to simplify scheduling |
|
66 | - $this->current_time = $this->roundTimestamp(time(), '5-minutes', false); |
|
67 | - $this->transients = (array)get_option(TransientCacheStorage::TRANSIENT_SCHEDULE_OPTIONS_KEY, array()); |
|
68 | - if ( ! (defined('DOING_AJAX') && DOING_AJAX) && $this->transient_cleanup_frequency !== 'off') { |
|
69 | - add_action('shutdown', array($this, 'checkTransientCleanupSchedule'), 999); |
|
70 | - } |
|
71 | - } |
|
72 | - |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * Sets how often transient cleanup occurs |
|
77 | - * |
|
78 | - * @return int |
|
79 | - */ |
|
80 | - private function setTransientCleanupFrequency() |
|
81 | - { |
|
82 | - // sets how often transients are cleaned up |
|
83 | - $this->transient_cleanup_frequency_options = apply_filters( |
|
84 | - 'FHEE__TransientCacheStorage__transient_cleanup_schedule_options', |
|
85 | - array( |
|
86 | - 'off', |
|
87 | - '15-minutes', |
|
88 | - 'hour', |
|
89 | - '12-hours', |
|
90 | - 'day', |
|
91 | - ) |
|
92 | - ); |
|
93 | - $transient_cleanup_frequency = apply_filters( |
|
94 | - 'FHEE__TransientCacheStorage__transient_cleanup_schedule', |
|
95 | - 'hour' |
|
96 | - ); |
|
97 | - return in_array( |
|
98 | - $transient_cleanup_frequency, |
|
99 | - $this->transient_cleanup_frequency_options, |
|
100 | - true |
|
101 | - ) |
|
102 | - ? $transient_cleanup_frequency |
|
103 | - : 'hour'; |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * we need to be able to round timestamps off to match the set transient cleanup frequency |
|
110 | - * so if a transient is set to expire at 1:17 pm for example, and our cleanup schedule is every hour, |
|
111 | - * then that timestamp needs to be rounded up to 2:00 pm so that it is removed |
|
112 | - * during the next scheduled cleanup after its expiration. |
|
113 | - * We also round off the current time timestamp to the closest 5 minutes |
|
114 | - * just to make the timestamps a little easier to round which helps with debugging. |
|
115 | - * |
|
116 | - * @param int $timestamp [required] |
|
117 | - * @param string $cleanup_frequency |
|
118 | - * @param bool $round_up |
|
119 | - * @return false|int |
|
120 | - */ |
|
121 | - private function roundTimestamp($timestamp, $cleanup_frequency = 'hour', $round_up = true) |
|
122 | - { |
|
123 | - $cleanup_frequency = $cleanup_frequency ? $cleanup_frequency : $this->transient_cleanup_frequency; |
|
124 | - // in order to round the time to the closest xx minutes (or hours), |
|
125 | - // we take the minutes (or hours) portion of the timestamp and divide it by xx, |
|
126 | - // round down to a whole number, then multiply by xx to bring us almost back up to where we were |
|
127 | - // why round down ? so the minutes (or hours) don't go over 60 (or 24) |
|
128 | - // and bump the hour, which could bump the day, which could bump the month, etc, |
|
129 | - // which would be bad because we don't always want to round up, |
|
130 | - // but when we do we can easily achieve that by simply adding the desired offset, |
|
131 | - $minutes = '00'; |
|
132 | - $hours = 'H'; |
|
133 | - switch ($cleanup_frequency) { |
|
134 | - case '5-minutes' : |
|
135 | - $minutes = floor((int)date('i', $timestamp) / 5) * 5; |
|
136 | - $minutes = str_pad($minutes, 2, '0', STR_PAD_LEFT); |
|
137 | - $offset = MINUTE_IN_SECONDS * 5; |
|
138 | - break; |
|
139 | - case '15-minutes' : |
|
140 | - $minutes = floor((int)date('i', $timestamp) / 15) * 15; |
|
141 | - $minutes = str_pad($minutes, 2, '0', STR_PAD_LEFT); |
|
142 | - $offset = MINUTE_IN_SECONDS * 15; |
|
143 | - break; |
|
144 | - case '12-hours' : |
|
145 | - $hours = floor((int)date('H', $timestamp) / 12) * 12; |
|
146 | - $hours = str_pad($hours, 2, '0', STR_PAD_LEFT); |
|
147 | - $offset = HOUR_IN_SECONDS * 12; |
|
148 | - break; |
|
149 | - case 'day' : |
|
150 | - $hours = '03'; // run cleanup at 3:00 am (or first site hit after that) |
|
151 | - $offset = DAY_IN_SECONDS; |
|
152 | - break; |
|
153 | - case 'hour' : |
|
154 | - default : |
|
155 | - $offset = HOUR_IN_SECONDS; |
|
156 | - break; |
|
157 | - } |
|
158 | - $rounded_timestamp = strtotime(date("Y-m-d {$hours}:{$minutes}:00", $timestamp)); |
|
159 | - $rounded_timestamp += $round_up ? $offset : 0; |
|
160 | - return apply_filters( |
|
161 | - 'FHEE__TransientCacheStorage__roundTimestamp__timestamp', |
|
162 | - $rounded_timestamp, |
|
163 | - $timestamp, |
|
164 | - $cleanup_frequency, |
|
165 | - $round_up |
|
166 | - ); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * Saves supplied data to a transient |
|
173 | - * if an expiration is set, then it automatically schedules the transient for cleanup |
|
174 | - * |
|
175 | - * @param string $transient_key [required] |
|
176 | - * @param string $data [required] |
|
177 | - * @param int $expiration number of seconds until the cache expires |
|
178 | - * @return bool |
|
179 | - */ |
|
180 | - public function add($transient_key, $data, $expiration = 0) |
|
181 | - { |
|
182 | - $expiration = (int)abs($expiration); |
|
183 | - $saved = set_transient($transient_key, $data, $expiration); |
|
184 | - if ($saved && $expiration) { |
|
185 | - $this->scheduleTransientCleanup($transient_key, $expiration); |
|
186 | - } |
|
187 | - return $saved; |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * retrieves transient data |
|
194 | - * automatically triggers early cache refresh for standard cache items |
|
195 | - * in order to avoid cache stampedes on busy sites. |
|
196 | - * For non-standard cache items like PHP Session data where early refreshing is not wanted, |
|
197 | - * the $standard_cache parameter should be set to false when retrieving data |
|
198 | - * |
|
199 | - * @param string $transient_key [required] |
|
200 | - * @param bool $standard_cache |
|
201 | - * @return mixed|null |
|
202 | - */ |
|
203 | - public function get($transient_key, $standard_cache = true) |
|
204 | - { |
|
205 | - // to avoid cache stampedes (AKA:dogpiles) for standard cache items, |
|
206 | - // check if known cache expires within the next minute, |
|
207 | - // and if so, remove it from our tracking and and return nothing. |
|
208 | - // this should trigger the cache content to be regenerated during this request, |
|
209 | - // while allowing any following requests to still access the existing cache |
|
210 | - // until it gets replaced with the refreshed content |
|
211 | - if ( |
|
212 | - $standard_cache |
|
213 | - && isset($this->transients[$transient_key]) |
|
214 | - && $this->transients[$transient_key] - time() <= MINUTE_IN_SECONDS |
|
215 | - ) { |
|
216 | - unset($this->transients[$transient_key]); |
|
217 | - $this->updateTransients(); |
|
218 | - return null; |
|
219 | - } |
|
220 | - $content = get_transient($transient_key); |
|
221 | - return $content !== false ? $content : null; |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * delete a single transient and remove tracking |
|
228 | - * |
|
229 | - * @param string $transient_key [required] full or partial transient key to be deleted |
|
230 | - */ |
|
231 | - public function delete($transient_key) |
|
232 | - { |
|
233 | - $this->deleteMany(array($transient_key)); |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * delete multiple transients and remove tracking |
|
240 | - * |
|
241 | - * @param array $transient_keys [required] array of full or partial transient keys to be deleted |
|
242 | - */ |
|
243 | - public function deleteMany(array $transient_keys) |
|
244 | - { |
|
245 | - $full_transient_keys = array(); |
|
246 | - foreach ($this->transients as $transient_key => $expiration) { |
|
247 | - foreach ($transient_keys as $transient_key_to_delete) { |
|
248 | - if (strpos($transient_key, $transient_key_to_delete) !== false) { |
|
249 | - $full_transient_keys[] = $transient_key; |
|
250 | - } |
|
251 | - } |
|
252 | - } |
|
253 | - if ($this->deleteTransientKeys($full_transient_keys)) { |
|
254 | - $this->updateTransients(); |
|
255 | - } |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * sorts transients numerically by timestamp |
|
262 | - * then saves the transient schedule to a WP option |
|
263 | - */ |
|
264 | - private function updateTransients() |
|
265 | - { |
|
266 | - asort($this->transients, SORT_NUMERIC); |
|
267 | - update_option( |
|
268 | - TransientCacheStorage::TRANSIENT_SCHEDULE_OPTIONS_KEY, |
|
269 | - $this->transients |
|
270 | - ); |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * schedules a transient for cleanup by adding it to the transient tracking |
|
277 | - * |
|
278 | - * @param string $transient_key [required] |
|
279 | - * @param int $expiration [required] |
|
280 | - */ |
|
281 | - private function scheduleTransientCleanup($transient_key, $expiration) |
|
282 | - { |
|
283 | - // make sure a valid future timestamp is set |
|
284 | - $expiration += $expiration < time() ? time() : 0; |
|
285 | - // and round to the closest 15 minutes |
|
286 | - $expiration = $this->roundTimestamp($expiration); |
|
287 | - // save transients to clear using their ID as the key to avoid duplicates |
|
288 | - $this->transients[$transient_key] = $expiration; |
|
289 | - $this->updateTransients(); |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * Since our tracked transients are sorted by their timestamps |
|
296 | - * we can grab the first transient and see when it is scheduled for cleanup. |
|
297 | - * If that timestamp is less than or equal to the current time, |
|
298 | - * then cleanup is triggered |
|
299 | - */ |
|
300 | - public function checkTransientCleanupSchedule() |
|
301 | - { |
|
302 | - if (empty($this->transients)) { |
|
303 | - return; |
|
304 | - } |
|
305 | - // when do we run the next cleanup job? |
|
306 | - reset($this->transients); |
|
307 | - $next_scheduled_cleanup = current($this->transients); |
|
308 | - // if the next cleanup job is scheduled for the current hour |
|
309 | - if ($next_scheduled_cleanup <= $this->current_time) { |
|
310 | - if ($this->cleanupExpiredTransients()) { |
|
311 | - $this->updateTransients(); |
|
312 | - } |
|
313 | - } |
|
314 | - } |
|
315 | - |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * loops through the array of tracked transients, |
|
320 | - * compiles a list of those that have expired, and sends that list off for deletion. |
|
321 | - * Also removes any bad records from the transients array |
|
322 | - * |
|
323 | - * @return bool |
|
324 | - */ |
|
325 | - private function cleanupExpiredTransients() |
|
326 | - { |
|
327 | - $update = false; |
|
328 | - // filter the query limit. Set to 0 to turn off garbage collection |
|
329 | - $limit = (int)abs( |
|
330 | - apply_filters( |
|
331 | - 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
|
332 | - 50 |
|
333 | - ) |
|
334 | - ); |
|
335 | - // non-zero LIMIT means take out the trash |
|
336 | - if ($limit) { |
|
337 | - $transient_keys = array(); |
|
338 | - foreach ($this->transients as $transient_key => $expiration) { |
|
339 | - if ($expiration > $this->current_time) { |
|
340 | - continue; |
|
341 | - } |
|
342 | - if ( ! $expiration || ! $transient_key) { |
|
343 | - unset($this->transients[$transient_key]); |
|
344 | - $update = true; |
|
345 | - continue; |
|
346 | - } |
|
347 | - $transient_keys[] = $transient_key; |
|
348 | - } |
|
349 | - // delete expired keys, but maintain value of $update if nothing is deleted |
|
350 | - $update = $this->deleteTransientKeys($transient_keys, $limit) ? true : $update; |
|
351 | - do_action( 'FHEE__TransientCacheStorage__clearExpiredTransients__end', $this); |
|
352 | - } |
|
353 | - return $update; |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - |
|
358 | - /** |
|
359 | - * calls delete_transient() on each transient key provided, up to the specified limit |
|
360 | - * |
|
361 | - * @param array $transient_keys [required] |
|
362 | - * @param int $limit |
|
363 | - * @return bool |
|
364 | - */ |
|
365 | - private function deleteTransientKeys(array $transient_keys, $limit = 50) |
|
366 | - { |
|
367 | - if (empty($transient_keys)) { |
|
368 | - return false; |
|
369 | - } |
|
370 | - $counter = 0; |
|
371 | - foreach ($transient_keys as $transient_key) { |
|
372 | - if($counter === $limit){ |
|
373 | - break; |
|
374 | - } |
|
375 | - delete_transient($transient_key); |
|
376 | - unset($this->transients[$transient_key]); |
|
377 | - $counter++; |
|
378 | - } |
|
379 | - return $counter > 0; |
|
380 | - } |
|
26 | + /** |
|
27 | + * wp-option option_name for tracking transients |
|
28 | + * |
|
29 | + * @type string |
|
30 | + */ |
|
31 | + const TRANSIENT_SCHEDULE_OPTIONS_KEY = 'ee_transient_schedule'; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var int $current_time |
|
35 | + */ |
|
36 | + private $current_time = 0; |
|
37 | + |
|
38 | + /** |
|
39 | + * how often to perform transient cleanup |
|
40 | + * |
|
41 | + * @var string $transient_cleanup_frequency |
|
42 | + */ |
|
43 | + private $transient_cleanup_frequency = 'hour'; |
|
44 | + |
|
45 | + /** |
|
46 | + * options for how often to perform transient cleanup |
|
47 | + * |
|
48 | + * @var array $transient_cleanup_frequency_options |
|
49 | + */ |
|
50 | + private $transient_cleanup_frequency_options = array(); |
|
51 | + |
|
52 | + /** |
|
53 | + * @var array $transients |
|
54 | + */ |
|
55 | + private $transients = array(); |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * TransientCacheStorage constructor. |
|
61 | + */ |
|
62 | + public function __construct() |
|
63 | + { |
|
64 | + $this->transient_cleanup_frequency = $this->setTransientCleanupFrequency(); |
|
65 | + // round current time down to closest 5 minutes to simplify scheduling |
|
66 | + $this->current_time = $this->roundTimestamp(time(), '5-minutes', false); |
|
67 | + $this->transients = (array)get_option(TransientCacheStorage::TRANSIENT_SCHEDULE_OPTIONS_KEY, array()); |
|
68 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && $this->transient_cleanup_frequency !== 'off') { |
|
69 | + add_action('shutdown', array($this, 'checkTransientCleanupSchedule'), 999); |
|
70 | + } |
|
71 | + } |
|
72 | + |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * Sets how often transient cleanup occurs |
|
77 | + * |
|
78 | + * @return int |
|
79 | + */ |
|
80 | + private function setTransientCleanupFrequency() |
|
81 | + { |
|
82 | + // sets how often transients are cleaned up |
|
83 | + $this->transient_cleanup_frequency_options = apply_filters( |
|
84 | + 'FHEE__TransientCacheStorage__transient_cleanup_schedule_options', |
|
85 | + array( |
|
86 | + 'off', |
|
87 | + '15-minutes', |
|
88 | + 'hour', |
|
89 | + '12-hours', |
|
90 | + 'day', |
|
91 | + ) |
|
92 | + ); |
|
93 | + $transient_cleanup_frequency = apply_filters( |
|
94 | + 'FHEE__TransientCacheStorage__transient_cleanup_schedule', |
|
95 | + 'hour' |
|
96 | + ); |
|
97 | + return in_array( |
|
98 | + $transient_cleanup_frequency, |
|
99 | + $this->transient_cleanup_frequency_options, |
|
100 | + true |
|
101 | + ) |
|
102 | + ? $transient_cleanup_frequency |
|
103 | + : 'hour'; |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * we need to be able to round timestamps off to match the set transient cleanup frequency |
|
110 | + * so if a transient is set to expire at 1:17 pm for example, and our cleanup schedule is every hour, |
|
111 | + * then that timestamp needs to be rounded up to 2:00 pm so that it is removed |
|
112 | + * during the next scheduled cleanup after its expiration. |
|
113 | + * We also round off the current time timestamp to the closest 5 minutes |
|
114 | + * just to make the timestamps a little easier to round which helps with debugging. |
|
115 | + * |
|
116 | + * @param int $timestamp [required] |
|
117 | + * @param string $cleanup_frequency |
|
118 | + * @param bool $round_up |
|
119 | + * @return false|int |
|
120 | + */ |
|
121 | + private function roundTimestamp($timestamp, $cleanup_frequency = 'hour', $round_up = true) |
|
122 | + { |
|
123 | + $cleanup_frequency = $cleanup_frequency ? $cleanup_frequency : $this->transient_cleanup_frequency; |
|
124 | + // in order to round the time to the closest xx minutes (or hours), |
|
125 | + // we take the minutes (or hours) portion of the timestamp and divide it by xx, |
|
126 | + // round down to a whole number, then multiply by xx to bring us almost back up to where we were |
|
127 | + // why round down ? so the minutes (or hours) don't go over 60 (or 24) |
|
128 | + // and bump the hour, which could bump the day, which could bump the month, etc, |
|
129 | + // which would be bad because we don't always want to round up, |
|
130 | + // but when we do we can easily achieve that by simply adding the desired offset, |
|
131 | + $minutes = '00'; |
|
132 | + $hours = 'H'; |
|
133 | + switch ($cleanup_frequency) { |
|
134 | + case '5-minutes' : |
|
135 | + $minutes = floor((int)date('i', $timestamp) / 5) * 5; |
|
136 | + $minutes = str_pad($minutes, 2, '0', STR_PAD_LEFT); |
|
137 | + $offset = MINUTE_IN_SECONDS * 5; |
|
138 | + break; |
|
139 | + case '15-minutes' : |
|
140 | + $minutes = floor((int)date('i', $timestamp) / 15) * 15; |
|
141 | + $minutes = str_pad($minutes, 2, '0', STR_PAD_LEFT); |
|
142 | + $offset = MINUTE_IN_SECONDS * 15; |
|
143 | + break; |
|
144 | + case '12-hours' : |
|
145 | + $hours = floor((int)date('H', $timestamp) / 12) * 12; |
|
146 | + $hours = str_pad($hours, 2, '0', STR_PAD_LEFT); |
|
147 | + $offset = HOUR_IN_SECONDS * 12; |
|
148 | + break; |
|
149 | + case 'day' : |
|
150 | + $hours = '03'; // run cleanup at 3:00 am (or first site hit after that) |
|
151 | + $offset = DAY_IN_SECONDS; |
|
152 | + break; |
|
153 | + case 'hour' : |
|
154 | + default : |
|
155 | + $offset = HOUR_IN_SECONDS; |
|
156 | + break; |
|
157 | + } |
|
158 | + $rounded_timestamp = strtotime(date("Y-m-d {$hours}:{$minutes}:00", $timestamp)); |
|
159 | + $rounded_timestamp += $round_up ? $offset : 0; |
|
160 | + return apply_filters( |
|
161 | + 'FHEE__TransientCacheStorage__roundTimestamp__timestamp', |
|
162 | + $rounded_timestamp, |
|
163 | + $timestamp, |
|
164 | + $cleanup_frequency, |
|
165 | + $round_up |
|
166 | + ); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * Saves supplied data to a transient |
|
173 | + * if an expiration is set, then it automatically schedules the transient for cleanup |
|
174 | + * |
|
175 | + * @param string $transient_key [required] |
|
176 | + * @param string $data [required] |
|
177 | + * @param int $expiration number of seconds until the cache expires |
|
178 | + * @return bool |
|
179 | + */ |
|
180 | + public function add($transient_key, $data, $expiration = 0) |
|
181 | + { |
|
182 | + $expiration = (int)abs($expiration); |
|
183 | + $saved = set_transient($transient_key, $data, $expiration); |
|
184 | + if ($saved && $expiration) { |
|
185 | + $this->scheduleTransientCleanup($transient_key, $expiration); |
|
186 | + } |
|
187 | + return $saved; |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * retrieves transient data |
|
194 | + * automatically triggers early cache refresh for standard cache items |
|
195 | + * in order to avoid cache stampedes on busy sites. |
|
196 | + * For non-standard cache items like PHP Session data where early refreshing is not wanted, |
|
197 | + * the $standard_cache parameter should be set to false when retrieving data |
|
198 | + * |
|
199 | + * @param string $transient_key [required] |
|
200 | + * @param bool $standard_cache |
|
201 | + * @return mixed|null |
|
202 | + */ |
|
203 | + public function get($transient_key, $standard_cache = true) |
|
204 | + { |
|
205 | + // to avoid cache stampedes (AKA:dogpiles) for standard cache items, |
|
206 | + // check if known cache expires within the next minute, |
|
207 | + // and if so, remove it from our tracking and and return nothing. |
|
208 | + // this should trigger the cache content to be regenerated during this request, |
|
209 | + // while allowing any following requests to still access the existing cache |
|
210 | + // until it gets replaced with the refreshed content |
|
211 | + if ( |
|
212 | + $standard_cache |
|
213 | + && isset($this->transients[$transient_key]) |
|
214 | + && $this->transients[$transient_key] - time() <= MINUTE_IN_SECONDS |
|
215 | + ) { |
|
216 | + unset($this->transients[$transient_key]); |
|
217 | + $this->updateTransients(); |
|
218 | + return null; |
|
219 | + } |
|
220 | + $content = get_transient($transient_key); |
|
221 | + return $content !== false ? $content : null; |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * delete a single transient and remove tracking |
|
228 | + * |
|
229 | + * @param string $transient_key [required] full or partial transient key to be deleted |
|
230 | + */ |
|
231 | + public function delete($transient_key) |
|
232 | + { |
|
233 | + $this->deleteMany(array($transient_key)); |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * delete multiple transients and remove tracking |
|
240 | + * |
|
241 | + * @param array $transient_keys [required] array of full or partial transient keys to be deleted |
|
242 | + */ |
|
243 | + public function deleteMany(array $transient_keys) |
|
244 | + { |
|
245 | + $full_transient_keys = array(); |
|
246 | + foreach ($this->transients as $transient_key => $expiration) { |
|
247 | + foreach ($transient_keys as $transient_key_to_delete) { |
|
248 | + if (strpos($transient_key, $transient_key_to_delete) !== false) { |
|
249 | + $full_transient_keys[] = $transient_key; |
|
250 | + } |
|
251 | + } |
|
252 | + } |
|
253 | + if ($this->deleteTransientKeys($full_transient_keys)) { |
|
254 | + $this->updateTransients(); |
|
255 | + } |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * sorts transients numerically by timestamp |
|
262 | + * then saves the transient schedule to a WP option |
|
263 | + */ |
|
264 | + private function updateTransients() |
|
265 | + { |
|
266 | + asort($this->transients, SORT_NUMERIC); |
|
267 | + update_option( |
|
268 | + TransientCacheStorage::TRANSIENT_SCHEDULE_OPTIONS_KEY, |
|
269 | + $this->transients |
|
270 | + ); |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * schedules a transient for cleanup by adding it to the transient tracking |
|
277 | + * |
|
278 | + * @param string $transient_key [required] |
|
279 | + * @param int $expiration [required] |
|
280 | + */ |
|
281 | + private function scheduleTransientCleanup($transient_key, $expiration) |
|
282 | + { |
|
283 | + // make sure a valid future timestamp is set |
|
284 | + $expiration += $expiration < time() ? time() : 0; |
|
285 | + // and round to the closest 15 minutes |
|
286 | + $expiration = $this->roundTimestamp($expiration); |
|
287 | + // save transients to clear using their ID as the key to avoid duplicates |
|
288 | + $this->transients[$transient_key] = $expiration; |
|
289 | + $this->updateTransients(); |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * Since our tracked transients are sorted by their timestamps |
|
296 | + * we can grab the first transient and see when it is scheduled for cleanup. |
|
297 | + * If that timestamp is less than or equal to the current time, |
|
298 | + * then cleanup is triggered |
|
299 | + */ |
|
300 | + public function checkTransientCleanupSchedule() |
|
301 | + { |
|
302 | + if (empty($this->transients)) { |
|
303 | + return; |
|
304 | + } |
|
305 | + // when do we run the next cleanup job? |
|
306 | + reset($this->transients); |
|
307 | + $next_scheduled_cleanup = current($this->transients); |
|
308 | + // if the next cleanup job is scheduled for the current hour |
|
309 | + if ($next_scheduled_cleanup <= $this->current_time) { |
|
310 | + if ($this->cleanupExpiredTransients()) { |
|
311 | + $this->updateTransients(); |
|
312 | + } |
|
313 | + } |
|
314 | + } |
|
315 | + |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * loops through the array of tracked transients, |
|
320 | + * compiles a list of those that have expired, and sends that list off for deletion. |
|
321 | + * Also removes any bad records from the transients array |
|
322 | + * |
|
323 | + * @return bool |
|
324 | + */ |
|
325 | + private function cleanupExpiredTransients() |
|
326 | + { |
|
327 | + $update = false; |
|
328 | + // filter the query limit. Set to 0 to turn off garbage collection |
|
329 | + $limit = (int)abs( |
|
330 | + apply_filters( |
|
331 | + 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
|
332 | + 50 |
|
333 | + ) |
|
334 | + ); |
|
335 | + // non-zero LIMIT means take out the trash |
|
336 | + if ($limit) { |
|
337 | + $transient_keys = array(); |
|
338 | + foreach ($this->transients as $transient_key => $expiration) { |
|
339 | + if ($expiration > $this->current_time) { |
|
340 | + continue; |
|
341 | + } |
|
342 | + if ( ! $expiration || ! $transient_key) { |
|
343 | + unset($this->transients[$transient_key]); |
|
344 | + $update = true; |
|
345 | + continue; |
|
346 | + } |
|
347 | + $transient_keys[] = $transient_key; |
|
348 | + } |
|
349 | + // delete expired keys, but maintain value of $update if nothing is deleted |
|
350 | + $update = $this->deleteTransientKeys($transient_keys, $limit) ? true : $update; |
|
351 | + do_action( 'FHEE__TransientCacheStorage__clearExpiredTransients__end', $this); |
|
352 | + } |
|
353 | + return $update; |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + |
|
358 | + /** |
|
359 | + * calls delete_transient() on each transient key provided, up to the specified limit |
|
360 | + * |
|
361 | + * @param array $transient_keys [required] |
|
362 | + * @param int $limit |
|
363 | + * @return bool |
|
364 | + */ |
|
365 | + private function deleteTransientKeys(array $transient_keys, $limit = 50) |
|
366 | + { |
|
367 | + if (empty($transient_keys)) { |
|
368 | + return false; |
|
369 | + } |
|
370 | + $counter = 0; |
|
371 | + foreach ($transient_keys as $transient_key) { |
|
372 | + if($counter === $limit){ |
|
373 | + break; |
|
374 | + } |
|
375 | + delete_transient($transient_key); |
|
376 | + unset($this->transients[$transient_key]); |
|
377 | + $counter++; |
|
378 | + } |
|
379 | + return $counter > 0; |
|
380 | + } |
|
381 | 381 | |
382 | 382 | |
383 | 383 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $this->transient_cleanup_frequency = $this->setTransientCleanupFrequency(); |
65 | 65 | // round current time down to closest 5 minutes to simplify scheduling |
66 | 66 | $this->current_time = $this->roundTimestamp(time(), '5-minutes', false); |
67 | - $this->transients = (array)get_option(TransientCacheStorage::TRANSIENT_SCHEDULE_OPTIONS_KEY, array()); |
|
67 | + $this->transients = (array) get_option(TransientCacheStorage::TRANSIENT_SCHEDULE_OPTIONS_KEY, array()); |
|
68 | 68 | if ( ! (defined('DOING_AJAX') && DOING_AJAX) && $this->transient_cleanup_frequency !== 'off') { |
69 | 69 | add_action('shutdown', array($this, 'checkTransientCleanupSchedule'), 999); |
70 | 70 | } |
@@ -132,17 +132,17 @@ discard block |
||
132 | 132 | $hours = 'H'; |
133 | 133 | switch ($cleanup_frequency) { |
134 | 134 | case '5-minutes' : |
135 | - $minutes = floor((int)date('i', $timestamp) / 5) * 5; |
|
135 | + $minutes = floor((int) date('i', $timestamp) / 5) * 5; |
|
136 | 136 | $minutes = str_pad($minutes, 2, '0', STR_PAD_LEFT); |
137 | 137 | $offset = MINUTE_IN_SECONDS * 5; |
138 | 138 | break; |
139 | 139 | case '15-minutes' : |
140 | - $minutes = floor((int)date('i', $timestamp) / 15) * 15; |
|
140 | + $minutes = floor((int) date('i', $timestamp) / 15) * 15; |
|
141 | 141 | $minutes = str_pad($minutes, 2, '0', STR_PAD_LEFT); |
142 | 142 | $offset = MINUTE_IN_SECONDS * 15; |
143 | 143 | break; |
144 | 144 | case '12-hours' : |
145 | - $hours = floor((int)date('H', $timestamp) / 12) * 12; |
|
145 | + $hours = floor((int) date('H', $timestamp) / 12) * 12; |
|
146 | 146 | $hours = str_pad($hours, 2, '0', STR_PAD_LEFT); |
147 | 147 | $offset = HOUR_IN_SECONDS * 12; |
148 | 148 | break; |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | */ |
180 | 180 | public function add($transient_key, $data, $expiration = 0) |
181 | 181 | { |
182 | - $expiration = (int)abs($expiration); |
|
182 | + $expiration = (int) abs($expiration); |
|
183 | 183 | $saved = set_transient($transient_key, $data, $expiration); |
184 | 184 | if ($saved && $expiration) { |
185 | 185 | $this->scheduleTransientCleanup($transient_key, $expiration); |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | { |
327 | 327 | $update = false; |
328 | 328 | // filter the query limit. Set to 0 to turn off garbage collection |
329 | - $limit = (int)abs( |
|
329 | + $limit = (int) abs( |
|
330 | 330 | apply_filters( |
331 | 331 | 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
332 | 332 | 50 |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | } |
349 | 349 | // delete expired keys, but maintain value of $update if nothing is deleted |
350 | 350 | $update = $this->deleteTransientKeys($transient_keys, $limit) ? true : $update; |
351 | - do_action( 'FHEE__TransientCacheStorage__clearExpiredTransients__end', $this); |
|
351 | + do_action('FHEE__TransientCacheStorage__clearExpiredTransients__end', $this); |
|
352 | 352 | } |
353 | 353 | return $update; |
354 | 354 | } |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | } |
370 | 370 | $counter = 0; |
371 | 371 | foreach ($transient_keys as $transient_key) { |
372 | - if($counter === $limit){ |
|
372 | + if ($counter === $limit) { |
|
373 | 373 | break; |
374 | 374 | } |
375 | 375 | delete_transient($transient_key); |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | use OutOfBoundsException; |
14 | 14 | |
15 | 15 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
16 | - exit('No direct script access allowed'); |
|
16 | + exit('No direct script access allowed'); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | |
@@ -32,502 +32,502 @@ discard block |
||
32 | 32 | { |
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * This was the best coffee related name I could think of to represent class name "aliases" |
|
37 | - * So classes can be found via an alias identifier, |
|
38 | - * that is revealed when it is run through... the filters... eh? get it? |
|
39 | - * |
|
40 | - * @var array $filters |
|
41 | - */ |
|
42 | - private $filters = array(); |
|
43 | - |
|
44 | - /** |
|
45 | - * These are the classes that will actually build the objects (to order of course) |
|
46 | - * |
|
47 | - * @var array $coffee_makers |
|
48 | - */ |
|
49 | - private $coffee_makers = array(); |
|
50 | - |
|
51 | - /** |
|
52 | - * where the instantiated "singleton" objects are stored |
|
53 | - * |
|
54 | - * @var CollectionInterface $carafe |
|
55 | - */ |
|
56 | - private $carafe; |
|
57 | - |
|
58 | - /** |
|
59 | - * collection of Recipes that instruct us how to brew objects |
|
60 | - * |
|
61 | - * @var CollectionInterface $recipes |
|
62 | - */ |
|
63 | - private $recipes; |
|
64 | - |
|
65 | - /** |
|
66 | - * collection of closures for brewing objects |
|
67 | - * |
|
68 | - * @var CollectionInterface $reservoir |
|
69 | - */ |
|
70 | - private $reservoir; |
|
71 | - |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * CoffeeShop constructor |
|
76 | - */ |
|
77 | - public function __construct() |
|
78 | - { |
|
79 | - // array for storing class aliases |
|
80 | - $this->filters = array(); |
|
81 | - // create collection for storing shared services |
|
82 | - $this->carafe = new LooseCollection( '' ); |
|
83 | - // create collection for storing recipes that tell how to build services and entities |
|
84 | - $this->recipes = new Collection('EventEspresso\core\services\container\RecipeInterface'); |
|
85 | - // create collection for storing closures for constructing new entities |
|
86 | - $this->reservoir = new Collection('Closure'); |
|
87 | - // create collection for storing the generators that build our services and entity closures |
|
88 | - $this->coffee_makers = new Collection('EventEspresso\core\services\container\CoffeeMakerInterface'); |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * Returns true if the container can return an entry for the given identifier. |
|
95 | - * Returns false otherwise. |
|
96 | - * `has($identifier)` returning true does not mean that `get($identifier)` will not throw an exception. |
|
97 | - * It does however mean that `get($identifier)` will not throw a `ServiceNotFoundException`. |
|
98 | - * |
|
99 | - * @param string $identifier Identifier of the entry to look for. |
|
100 | - * Typically a Fully Qualified Class Name |
|
101 | - * @return boolean |
|
102 | - */ |
|
103 | - public function has($identifier) |
|
104 | - { |
|
105 | - $identifier = $this->filterIdentifier($identifier); |
|
106 | - return $this->carafe->has($identifier); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * finds a previously brewed (SHARED) service and returns it |
|
113 | - * |
|
114 | - * @param string $identifier Identifier for the entity class to be constructed. |
|
115 | - * Typically a Fully Qualified Class Name |
|
116 | - * @return mixed |
|
117 | - * @throws ServiceNotFoundException No service was found for this identifier. |
|
118 | - */ |
|
119 | - public function get($identifier) |
|
120 | - { |
|
121 | - $identifier = $this->filterIdentifier($identifier); |
|
122 | - if ($this->carafe->has($identifier)) { |
|
123 | - return $this->carafe->get($identifier); |
|
124 | - } |
|
125 | - throw new ServiceNotFoundException($identifier); |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * returns an instance of the requested entity type using the supplied arguments. |
|
132 | - * If a shared service is requested and an instance is already in the carafe, then it will be returned. |
|
133 | - * If it is not already in the carafe, then the service will be constructed, added to the carafe, and returned |
|
134 | - * If the request is for a new entity and a closure exists in the reservoir for creating it, |
|
135 | - * then a new entity will be instantiated from the closure and returned. |
|
136 | - * If a closure does not exist, then one will be built and added to the reservoir |
|
137 | - * before instantiating the requested entity. |
|
138 | - * |
|
139 | - * @param string $identifier Identifier for the entity class to be constructed. |
|
140 | - * Typically a Fully Qualified Class Name |
|
141 | - * @param array $arguments an array of arguments to be passed to the entity constructor |
|
142 | - * @param string $type |
|
143 | - * @return mixed |
|
144 | - * @throws ServiceNotFoundException No service was found for this identifier. |
|
145 | - */ |
|
146 | - public function brew($identifier, $arguments = array(), $type = '') |
|
147 | - { |
|
148 | - // resolve any class aliases that may exist |
|
149 | - $identifier = $this->filterIdentifier($identifier); |
|
150 | - try { |
|
151 | - // is a shared service being requested? |
|
152 | - if (empty($type) || $type === CoffeeMaker::BREW_SHARED) { |
|
153 | - // if a shared service was requested and an instance is in the carafe, then return it |
|
154 | - return $this->get($identifier); |
|
155 | - } |
|
156 | - } catch (ServiceNotFoundException $e) { |
|
157 | - // if not then we'll just catch the ServiceNotFoundException but not do anything just yet, |
|
158 | - // and instead, attempt to build whatever was requested |
|
159 | - } |
|
160 | - $brewed = false; |
|
161 | - // if the reservoir doesn't have a closure already for the requested identifier, |
|
162 | - // then neither a shared service nor a closure for making entities has been built yet |
|
163 | - if ( ! $this->reservoir->has($identifier)) { |
|
164 | - // so let's brew something up and add it to the proper collection |
|
165 | - $brewed = $this->makeCoffee($identifier, $arguments, $type); |
|
166 | - } |
|
167 | - // was the brewed item a callable factory function ? |
|
168 | - if (is_callable($brewed)) { |
|
169 | - // then instantiate a new entity from the cached closure |
|
170 | - $entity = $brewed($arguments); |
|
171 | - } else if ($brewed) { |
|
172 | - // requested object was a shared entity, so attempt to get it from the carafe again |
|
173 | - // because if it wasn't there before, then it should have just been brewed and added, |
|
174 | - // but if it still isn't there, then this time |
|
175 | - // the thrown ServiceNotFoundException will not be caught |
|
176 | - $entity = $this->get($identifier); |
|
177 | - } else { |
|
178 | - // if identifier is for a non-shared entity, |
|
179 | - // then either a cached closure already existed, or was just brewed |
|
180 | - $closure = $this->reservoir->get($identifier); |
|
181 | - $entity = $closure($arguments); |
|
182 | - } |
|
183 | - return $entity; |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * @param CoffeeMakerInterface $coffee_maker |
|
190 | - * @param string $type |
|
191 | - * @return bool |
|
192 | - */ |
|
193 | - public function addCoffeeMaker(CoffeeMakerInterface $coffee_maker, $type) |
|
194 | - { |
|
195 | - $type = CoffeeMaker::validateType($type); |
|
196 | - return $this->coffee_makers->add($coffee_maker, $type); |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * @param string $identifier |
|
203 | - * @param callable $closure |
|
204 | - * @return callable|null |
|
205 | - */ |
|
206 | - public function addClosure($identifier, $closure) |
|
207 | - { |
|
208 | - if ( ! is_callable($closure)) { |
|
209 | - throw new InvalidDataTypeException('$closure', $closure, 'Closure'); |
|
210 | - } |
|
211 | - $identifier = $this->processIdentifier($identifier); |
|
212 | - if ($this->reservoir->add($closure, $identifier)) { |
|
213 | - return $closure; |
|
214 | - } |
|
215 | - return null; |
|
216 | - } |
|
217 | - |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * @param string $identifier |
|
222 | - * @return boolean |
|
223 | - */ |
|
224 | - public function removeClosure($identifier) |
|
225 | - { |
|
226 | - $identifier = $this->processIdentifier($identifier); |
|
227 | - if ($this->reservoir->has($identifier)) { |
|
228 | - $this->reservoir->remove($this->reservoir->get($identifier)); |
|
229 | - if ( ! $this->reservoir->has($identifier)) { |
|
230 | - return true; |
|
231 | - } |
|
232 | - } |
|
233 | - return false; |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * @param string $identifier Identifier for the entity class that the service applies to |
|
240 | - * Typically a Fully Qualified Class Name |
|
241 | - * @param mixed $service |
|
242 | - * @return bool |
|
243 | - */ |
|
244 | - public function addService($identifier, $service) |
|
245 | - { |
|
246 | - $identifier = $this->processIdentifier($identifier); |
|
247 | - $service = $this->validateService($identifier, $service); |
|
248 | - return $this->carafe->add($service, $identifier); |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - |
|
253 | - /** |
|
254 | - * @param string $identifier |
|
255 | - * @return boolean |
|
256 | - */ |
|
257 | - public function removeService($identifier) |
|
258 | - { |
|
259 | - $identifier = $this->processIdentifier($identifier); |
|
260 | - if ($this->carafe->has($identifier)) { |
|
261 | - $this->carafe->remove($this->carafe->get($identifier)); |
|
262 | - if ( ! $this->carafe->has($identifier)) { |
|
263 | - return true; |
|
264 | - } |
|
265 | - } |
|
266 | - return false; |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * Adds instructions on how to brew objects |
|
273 | - * |
|
274 | - * @param RecipeInterface $recipe |
|
275 | - * @return mixed |
|
276 | - */ |
|
277 | - public function addRecipe(RecipeInterface $recipe) |
|
278 | - { |
|
279 | - $this->addAliases($recipe->identifier(), $recipe->filters()); |
|
280 | - $identifier = $this->processIdentifier($recipe->identifier()); |
|
281 | - return $this->recipes->add($recipe, $identifier); |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * @param string $identifier The Recipe's identifier |
|
288 | - * @return boolean |
|
289 | - */ |
|
290 | - public function removeRecipe($identifier) |
|
291 | - { |
|
292 | - $identifier = $this->processIdentifier($identifier); |
|
293 | - if ($this->recipes->has($identifier)) { |
|
294 | - $this->recipes->remove( |
|
295 | - $this->recipes->get($identifier) |
|
296 | - ); |
|
297 | - if ( ! $this->recipes->has($identifier)) { |
|
298 | - return true; |
|
299 | - } |
|
300 | - } |
|
301 | - return false; |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * Get instructions on how to brew objects |
|
308 | - * |
|
309 | - * @param string $identifier Identifier for the entity class that the recipe applies to |
|
310 | - * Typically a Fully Qualified Class Name |
|
311 | - * @param string $type |
|
312 | - * @return RecipeInterface |
|
313 | - */ |
|
314 | - public function getRecipe($identifier, $type = '') |
|
315 | - { |
|
316 | - $identifier = $this->processIdentifier($identifier); |
|
317 | - if ($this->recipes->has($identifier)) { |
|
318 | - return $this->recipes->get($identifier); |
|
319 | - } |
|
320 | - $default_recipes = $this->getDefaultRecipes(); |
|
321 | - $matches = array(); |
|
322 | - foreach ($default_recipes as $wildcard => $default_recipe) { |
|
323 | - // is the wildcard recipe prefix in the identifier ? |
|
324 | - if (strpos($identifier, $wildcard) !== false) { |
|
325 | - // track matches and use the number of wildcard characters matched for the key |
|
326 | - $matches[strlen($wildcard)] = $default_recipe; |
|
327 | - } |
|
328 | - } |
|
329 | - if (count($matches) > 0) { |
|
330 | - // sort our recipes by the number of wildcard characters matched |
|
331 | - ksort($matches); |
|
332 | - // then grab the last recipe form the list, since it had the most matching characters |
|
333 | - $match = array_pop($matches); |
|
334 | - // since we are using a default recipe, we need to set it's identifier and fqcn |
|
335 | - return $this->copyDefaultRecipe($match, $identifier, $type); |
|
336 | - } |
|
337 | - if ($this->recipes->has(Recipe::DEFAULT_ID)) { |
|
338 | - // since we are using a default recipe, we need to set it's identifier and fqcn |
|
339 | - return $this->copyDefaultRecipe($this->recipes->get(Recipe::DEFAULT_ID), $identifier, $type); |
|
340 | - } |
|
341 | - throw new OutOfBoundsException( |
|
342 | - sprintf( |
|
343 | - __('Could not brew coffee because no recipes were found for class "%1$s".', 'event_espresso'), |
|
344 | - $identifier |
|
345 | - ) |
|
346 | - ); |
|
347 | - } |
|
348 | - |
|
349 | - |
|
350 | - |
|
351 | - /** |
|
352 | - * adds class name aliases to list of filters |
|
353 | - * |
|
354 | - * @param string $identifier Identifier for the entity class that the alias applies to |
|
355 | - * Typically a Fully Qualified Class Name |
|
356 | - * @param array|string $aliases |
|
357 | - * @return void |
|
358 | - * @throws InvalidIdentifierException |
|
359 | - */ |
|
360 | - public function addAliases($identifier, $aliases) |
|
361 | - { |
|
362 | - if (empty($aliases)) { |
|
363 | - return; |
|
364 | - } |
|
365 | - $identifier = $this->processIdentifier($identifier); |
|
366 | - foreach ((array)$aliases as $alias) { |
|
367 | - $this->filters[$this->processIdentifier($alias)] = $identifier; |
|
368 | - } |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * Adds a service to one of the internal collections |
|
375 | - * |
|
376 | - * @param $identifier |
|
377 | - * @param array $arguments |
|
378 | - * @param string $type |
|
379 | - * @return mixed |
|
380 | - * @throws ServiceExistsException |
|
381 | - */ |
|
382 | - private function makeCoffee($identifier, $arguments = array(), $type = '') |
|
383 | - { |
|
384 | - if ((empty($type) || $type === CoffeeMaker::BREW_SHARED) && $this->has($identifier)) { |
|
385 | - throw new ServiceExistsException($identifier); |
|
386 | - } |
|
387 | - $identifier = $this->filterIdentifier($identifier); |
|
388 | - $recipe = $this->getRecipe($identifier, $type); |
|
389 | - $type = ! empty($type) ? $type : $recipe->type(); |
|
390 | - $coffee_maker = $this->getCoffeeMaker($type); |
|
391 | - return $coffee_maker->brew($recipe, $arguments); |
|
392 | - } |
|
393 | - |
|
394 | - |
|
395 | - |
|
396 | - /** |
|
397 | - * filters alias identifiers to find the real class name |
|
398 | - * |
|
399 | - * @param string $identifier Identifier for the entity class that the filter applies to |
|
400 | - * Typically a Fully Qualified Class Name |
|
401 | - * @return string |
|
402 | - * @throws InvalidIdentifierException |
|
403 | - */ |
|
404 | - private function filterIdentifier($identifier) |
|
405 | - { |
|
406 | - $identifier = $this->processIdentifier($identifier); |
|
407 | - return isset($this->filters[$identifier]) && ! empty($this->filters[$identifier]) |
|
408 | - ? $this->filters[$identifier] |
|
409 | - : $identifier; |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * verifies and standardizes identifiers |
|
416 | - * |
|
417 | - * @param string $identifier Identifier for the entity class |
|
418 | - * Typically a Fully Qualified Class Name |
|
419 | - * @return string |
|
420 | - * @throws InvalidIdentifierException |
|
421 | - */ |
|
422 | - private function processIdentifier($identifier) |
|
423 | - { |
|
424 | - if ( ! is_string($identifier)) { |
|
425 | - throw new InvalidIdentifierException( |
|
426 | - is_object($identifier) ? get_class($identifier) : gettype($identifier), |
|
427 | - '\Fully\Qualified\ClassName' |
|
428 | - ); |
|
429 | - } |
|
430 | - return ltrim($identifier, '\\'); |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * @param string $type |
|
437 | - * @return CoffeeMakerInterface |
|
438 | - * @throws InvalidDataTypeException |
|
439 | - * @throws InvalidClassException |
|
440 | - */ |
|
441 | - private function getCoffeeMaker($type) |
|
442 | - { |
|
443 | - if ( ! $this->coffee_makers->has($type)) { |
|
444 | - throw new OutOfBoundsException( |
|
445 | - __('The requested coffee maker is either missing or invalid.', 'event_espresso') |
|
446 | - ); |
|
447 | - } |
|
448 | - return $this->coffee_makers->get($type); |
|
449 | - } |
|
450 | - |
|
451 | - |
|
452 | - |
|
453 | - /** |
|
454 | - * Retrieves all recipes that use a wildcard "*" in their identifier |
|
455 | - * This allows recipes to be set up for handling |
|
456 | - * legacy classes that do not support PSR-4 autoloading. |
|
457 | - * for example: |
|
458 | - * using "EEM_*" for a recipe identifier would target all legacy models like EEM_Attendee |
|
459 | - * |
|
460 | - * @return array |
|
461 | - */ |
|
462 | - private function getDefaultRecipes() |
|
463 | - { |
|
464 | - $default_recipes = array(); |
|
465 | - $this->recipes->rewind(); |
|
466 | - while ($this->recipes->valid()) { |
|
467 | - $identifier = $this->recipes->getInfo(); |
|
468 | - // does this recipe use a wildcard ? (but is NOT the global default) |
|
469 | - if ($identifier !== Recipe::DEFAULT_ID && strpos($identifier, '*') !== false) { |
|
470 | - // strip the wildcard and use identifier as key |
|
471 | - $default_recipes[str_replace('*', '', $identifier)] = $this->recipes->current(); |
|
472 | - } |
|
473 | - $this->recipes->next(); |
|
474 | - } |
|
475 | - return $default_recipes; |
|
476 | - } |
|
477 | - |
|
478 | - |
|
479 | - |
|
480 | - /** |
|
481 | - * clones a default recipe and then copies details |
|
482 | - * from the incoming request to it so that it can be used |
|
483 | - * |
|
484 | - * @param RecipeInterface $default_recipe |
|
485 | - * @param string $identifier |
|
486 | - * @param string $type |
|
487 | - * @return RecipeInterface |
|
488 | - */ |
|
489 | - private function copyDefaultRecipe(RecipeInterface $default_recipe, $identifier, $type = '') |
|
490 | - { |
|
491 | - $recipe = clone $default_recipe; |
|
492 | - if ( ! empty($type)) { |
|
493 | - $recipe->setType($type); |
|
494 | - } |
|
495 | - // is this the base default recipe ? |
|
496 | - if ($default_recipe->identifier() === Recipe::DEFAULT_ID) { |
|
497 | - $recipe->setIdentifier($identifier); |
|
498 | - $recipe->setFqcn($identifier); |
|
499 | - return $recipe; |
|
500 | - } |
|
501 | - $recipe->setIdentifier($identifier); |
|
502 | - foreach ($default_recipe->paths() as $path) { |
|
503 | - $path = str_replace('*', $identifier, $path); |
|
504 | - if (is_readable($path)) { |
|
505 | - $recipe->setPaths($path); |
|
506 | - } |
|
507 | - } |
|
508 | - $recipe->setFqcn($identifier); |
|
509 | - return $recipe; |
|
510 | - } |
|
511 | - |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * @param string $identifier Identifier for the entity class that the service applies to |
|
516 | - * Typically a Fully Qualified Class Name |
|
517 | - * @param mixed $service |
|
518 | - * @return object |
|
519 | - * @throws InvalidServiceException |
|
520 | - */ |
|
521 | - private function validateService($identifier, $service) |
|
522 | - { |
|
523 | - if ( ! is_object($service)) { |
|
524 | - throw new InvalidServiceException( |
|
525 | - $identifier, |
|
526 | - $service |
|
527 | - ); |
|
528 | - } |
|
529 | - return $service; |
|
530 | - } |
|
35 | + /** |
|
36 | + * This was the best coffee related name I could think of to represent class name "aliases" |
|
37 | + * So classes can be found via an alias identifier, |
|
38 | + * that is revealed when it is run through... the filters... eh? get it? |
|
39 | + * |
|
40 | + * @var array $filters |
|
41 | + */ |
|
42 | + private $filters = array(); |
|
43 | + |
|
44 | + /** |
|
45 | + * These are the classes that will actually build the objects (to order of course) |
|
46 | + * |
|
47 | + * @var array $coffee_makers |
|
48 | + */ |
|
49 | + private $coffee_makers = array(); |
|
50 | + |
|
51 | + /** |
|
52 | + * where the instantiated "singleton" objects are stored |
|
53 | + * |
|
54 | + * @var CollectionInterface $carafe |
|
55 | + */ |
|
56 | + private $carafe; |
|
57 | + |
|
58 | + /** |
|
59 | + * collection of Recipes that instruct us how to brew objects |
|
60 | + * |
|
61 | + * @var CollectionInterface $recipes |
|
62 | + */ |
|
63 | + private $recipes; |
|
64 | + |
|
65 | + /** |
|
66 | + * collection of closures for brewing objects |
|
67 | + * |
|
68 | + * @var CollectionInterface $reservoir |
|
69 | + */ |
|
70 | + private $reservoir; |
|
71 | + |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * CoffeeShop constructor |
|
76 | + */ |
|
77 | + public function __construct() |
|
78 | + { |
|
79 | + // array for storing class aliases |
|
80 | + $this->filters = array(); |
|
81 | + // create collection for storing shared services |
|
82 | + $this->carafe = new LooseCollection( '' ); |
|
83 | + // create collection for storing recipes that tell how to build services and entities |
|
84 | + $this->recipes = new Collection('EventEspresso\core\services\container\RecipeInterface'); |
|
85 | + // create collection for storing closures for constructing new entities |
|
86 | + $this->reservoir = new Collection('Closure'); |
|
87 | + // create collection for storing the generators that build our services and entity closures |
|
88 | + $this->coffee_makers = new Collection('EventEspresso\core\services\container\CoffeeMakerInterface'); |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * Returns true if the container can return an entry for the given identifier. |
|
95 | + * Returns false otherwise. |
|
96 | + * `has($identifier)` returning true does not mean that `get($identifier)` will not throw an exception. |
|
97 | + * It does however mean that `get($identifier)` will not throw a `ServiceNotFoundException`. |
|
98 | + * |
|
99 | + * @param string $identifier Identifier of the entry to look for. |
|
100 | + * Typically a Fully Qualified Class Name |
|
101 | + * @return boolean |
|
102 | + */ |
|
103 | + public function has($identifier) |
|
104 | + { |
|
105 | + $identifier = $this->filterIdentifier($identifier); |
|
106 | + return $this->carafe->has($identifier); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * finds a previously brewed (SHARED) service and returns it |
|
113 | + * |
|
114 | + * @param string $identifier Identifier for the entity class to be constructed. |
|
115 | + * Typically a Fully Qualified Class Name |
|
116 | + * @return mixed |
|
117 | + * @throws ServiceNotFoundException No service was found for this identifier. |
|
118 | + */ |
|
119 | + public function get($identifier) |
|
120 | + { |
|
121 | + $identifier = $this->filterIdentifier($identifier); |
|
122 | + if ($this->carafe->has($identifier)) { |
|
123 | + return $this->carafe->get($identifier); |
|
124 | + } |
|
125 | + throw new ServiceNotFoundException($identifier); |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * returns an instance of the requested entity type using the supplied arguments. |
|
132 | + * If a shared service is requested and an instance is already in the carafe, then it will be returned. |
|
133 | + * If it is not already in the carafe, then the service will be constructed, added to the carafe, and returned |
|
134 | + * If the request is for a new entity and a closure exists in the reservoir for creating it, |
|
135 | + * then a new entity will be instantiated from the closure and returned. |
|
136 | + * If a closure does not exist, then one will be built and added to the reservoir |
|
137 | + * before instantiating the requested entity. |
|
138 | + * |
|
139 | + * @param string $identifier Identifier for the entity class to be constructed. |
|
140 | + * Typically a Fully Qualified Class Name |
|
141 | + * @param array $arguments an array of arguments to be passed to the entity constructor |
|
142 | + * @param string $type |
|
143 | + * @return mixed |
|
144 | + * @throws ServiceNotFoundException No service was found for this identifier. |
|
145 | + */ |
|
146 | + public function brew($identifier, $arguments = array(), $type = '') |
|
147 | + { |
|
148 | + // resolve any class aliases that may exist |
|
149 | + $identifier = $this->filterIdentifier($identifier); |
|
150 | + try { |
|
151 | + // is a shared service being requested? |
|
152 | + if (empty($type) || $type === CoffeeMaker::BREW_SHARED) { |
|
153 | + // if a shared service was requested and an instance is in the carafe, then return it |
|
154 | + return $this->get($identifier); |
|
155 | + } |
|
156 | + } catch (ServiceNotFoundException $e) { |
|
157 | + // if not then we'll just catch the ServiceNotFoundException but not do anything just yet, |
|
158 | + // and instead, attempt to build whatever was requested |
|
159 | + } |
|
160 | + $brewed = false; |
|
161 | + // if the reservoir doesn't have a closure already for the requested identifier, |
|
162 | + // then neither a shared service nor a closure for making entities has been built yet |
|
163 | + if ( ! $this->reservoir->has($identifier)) { |
|
164 | + // so let's brew something up and add it to the proper collection |
|
165 | + $brewed = $this->makeCoffee($identifier, $arguments, $type); |
|
166 | + } |
|
167 | + // was the brewed item a callable factory function ? |
|
168 | + if (is_callable($brewed)) { |
|
169 | + // then instantiate a new entity from the cached closure |
|
170 | + $entity = $brewed($arguments); |
|
171 | + } else if ($brewed) { |
|
172 | + // requested object was a shared entity, so attempt to get it from the carafe again |
|
173 | + // because if it wasn't there before, then it should have just been brewed and added, |
|
174 | + // but if it still isn't there, then this time |
|
175 | + // the thrown ServiceNotFoundException will not be caught |
|
176 | + $entity = $this->get($identifier); |
|
177 | + } else { |
|
178 | + // if identifier is for a non-shared entity, |
|
179 | + // then either a cached closure already existed, or was just brewed |
|
180 | + $closure = $this->reservoir->get($identifier); |
|
181 | + $entity = $closure($arguments); |
|
182 | + } |
|
183 | + return $entity; |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * @param CoffeeMakerInterface $coffee_maker |
|
190 | + * @param string $type |
|
191 | + * @return bool |
|
192 | + */ |
|
193 | + public function addCoffeeMaker(CoffeeMakerInterface $coffee_maker, $type) |
|
194 | + { |
|
195 | + $type = CoffeeMaker::validateType($type); |
|
196 | + return $this->coffee_makers->add($coffee_maker, $type); |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * @param string $identifier |
|
203 | + * @param callable $closure |
|
204 | + * @return callable|null |
|
205 | + */ |
|
206 | + public function addClosure($identifier, $closure) |
|
207 | + { |
|
208 | + if ( ! is_callable($closure)) { |
|
209 | + throw new InvalidDataTypeException('$closure', $closure, 'Closure'); |
|
210 | + } |
|
211 | + $identifier = $this->processIdentifier($identifier); |
|
212 | + if ($this->reservoir->add($closure, $identifier)) { |
|
213 | + return $closure; |
|
214 | + } |
|
215 | + return null; |
|
216 | + } |
|
217 | + |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * @param string $identifier |
|
222 | + * @return boolean |
|
223 | + */ |
|
224 | + public function removeClosure($identifier) |
|
225 | + { |
|
226 | + $identifier = $this->processIdentifier($identifier); |
|
227 | + if ($this->reservoir->has($identifier)) { |
|
228 | + $this->reservoir->remove($this->reservoir->get($identifier)); |
|
229 | + if ( ! $this->reservoir->has($identifier)) { |
|
230 | + return true; |
|
231 | + } |
|
232 | + } |
|
233 | + return false; |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * @param string $identifier Identifier for the entity class that the service applies to |
|
240 | + * Typically a Fully Qualified Class Name |
|
241 | + * @param mixed $service |
|
242 | + * @return bool |
|
243 | + */ |
|
244 | + public function addService($identifier, $service) |
|
245 | + { |
|
246 | + $identifier = $this->processIdentifier($identifier); |
|
247 | + $service = $this->validateService($identifier, $service); |
|
248 | + return $this->carafe->add($service, $identifier); |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + |
|
253 | + /** |
|
254 | + * @param string $identifier |
|
255 | + * @return boolean |
|
256 | + */ |
|
257 | + public function removeService($identifier) |
|
258 | + { |
|
259 | + $identifier = $this->processIdentifier($identifier); |
|
260 | + if ($this->carafe->has($identifier)) { |
|
261 | + $this->carafe->remove($this->carafe->get($identifier)); |
|
262 | + if ( ! $this->carafe->has($identifier)) { |
|
263 | + return true; |
|
264 | + } |
|
265 | + } |
|
266 | + return false; |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * Adds instructions on how to brew objects |
|
273 | + * |
|
274 | + * @param RecipeInterface $recipe |
|
275 | + * @return mixed |
|
276 | + */ |
|
277 | + public function addRecipe(RecipeInterface $recipe) |
|
278 | + { |
|
279 | + $this->addAliases($recipe->identifier(), $recipe->filters()); |
|
280 | + $identifier = $this->processIdentifier($recipe->identifier()); |
|
281 | + return $this->recipes->add($recipe, $identifier); |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * @param string $identifier The Recipe's identifier |
|
288 | + * @return boolean |
|
289 | + */ |
|
290 | + public function removeRecipe($identifier) |
|
291 | + { |
|
292 | + $identifier = $this->processIdentifier($identifier); |
|
293 | + if ($this->recipes->has($identifier)) { |
|
294 | + $this->recipes->remove( |
|
295 | + $this->recipes->get($identifier) |
|
296 | + ); |
|
297 | + if ( ! $this->recipes->has($identifier)) { |
|
298 | + return true; |
|
299 | + } |
|
300 | + } |
|
301 | + return false; |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * Get instructions on how to brew objects |
|
308 | + * |
|
309 | + * @param string $identifier Identifier for the entity class that the recipe applies to |
|
310 | + * Typically a Fully Qualified Class Name |
|
311 | + * @param string $type |
|
312 | + * @return RecipeInterface |
|
313 | + */ |
|
314 | + public function getRecipe($identifier, $type = '') |
|
315 | + { |
|
316 | + $identifier = $this->processIdentifier($identifier); |
|
317 | + if ($this->recipes->has($identifier)) { |
|
318 | + return $this->recipes->get($identifier); |
|
319 | + } |
|
320 | + $default_recipes = $this->getDefaultRecipes(); |
|
321 | + $matches = array(); |
|
322 | + foreach ($default_recipes as $wildcard => $default_recipe) { |
|
323 | + // is the wildcard recipe prefix in the identifier ? |
|
324 | + if (strpos($identifier, $wildcard) !== false) { |
|
325 | + // track matches and use the number of wildcard characters matched for the key |
|
326 | + $matches[strlen($wildcard)] = $default_recipe; |
|
327 | + } |
|
328 | + } |
|
329 | + if (count($matches) > 0) { |
|
330 | + // sort our recipes by the number of wildcard characters matched |
|
331 | + ksort($matches); |
|
332 | + // then grab the last recipe form the list, since it had the most matching characters |
|
333 | + $match = array_pop($matches); |
|
334 | + // since we are using a default recipe, we need to set it's identifier and fqcn |
|
335 | + return $this->copyDefaultRecipe($match, $identifier, $type); |
|
336 | + } |
|
337 | + if ($this->recipes->has(Recipe::DEFAULT_ID)) { |
|
338 | + // since we are using a default recipe, we need to set it's identifier and fqcn |
|
339 | + return $this->copyDefaultRecipe($this->recipes->get(Recipe::DEFAULT_ID), $identifier, $type); |
|
340 | + } |
|
341 | + throw new OutOfBoundsException( |
|
342 | + sprintf( |
|
343 | + __('Could not brew coffee because no recipes were found for class "%1$s".', 'event_espresso'), |
|
344 | + $identifier |
|
345 | + ) |
|
346 | + ); |
|
347 | + } |
|
348 | + |
|
349 | + |
|
350 | + |
|
351 | + /** |
|
352 | + * adds class name aliases to list of filters |
|
353 | + * |
|
354 | + * @param string $identifier Identifier for the entity class that the alias applies to |
|
355 | + * Typically a Fully Qualified Class Name |
|
356 | + * @param array|string $aliases |
|
357 | + * @return void |
|
358 | + * @throws InvalidIdentifierException |
|
359 | + */ |
|
360 | + public function addAliases($identifier, $aliases) |
|
361 | + { |
|
362 | + if (empty($aliases)) { |
|
363 | + return; |
|
364 | + } |
|
365 | + $identifier = $this->processIdentifier($identifier); |
|
366 | + foreach ((array)$aliases as $alias) { |
|
367 | + $this->filters[$this->processIdentifier($alias)] = $identifier; |
|
368 | + } |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * Adds a service to one of the internal collections |
|
375 | + * |
|
376 | + * @param $identifier |
|
377 | + * @param array $arguments |
|
378 | + * @param string $type |
|
379 | + * @return mixed |
|
380 | + * @throws ServiceExistsException |
|
381 | + */ |
|
382 | + private function makeCoffee($identifier, $arguments = array(), $type = '') |
|
383 | + { |
|
384 | + if ((empty($type) || $type === CoffeeMaker::BREW_SHARED) && $this->has($identifier)) { |
|
385 | + throw new ServiceExistsException($identifier); |
|
386 | + } |
|
387 | + $identifier = $this->filterIdentifier($identifier); |
|
388 | + $recipe = $this->getRecipe($identifier, $type); |
|
389 | + $type = ! empty($type) ? $type : $recipe->type(); |
|
390 | + $coffee_maker = $this->getCoffeeMaker($type); |
|
391 | + return $coffee_maker->brew($recipe, $arguments); |
|
392 | + } |
|
393 | + |
|
394 | + |
|
395 | + |
|
396 | + /** |
|
397 | + * filters alias identifiers to find the real class name |
|
398 | + * |
|
399 | + * @param string $identifier Identifier for the entity class that the filter applies to |
|
400 | + * Typically a Fully Qualified Class Name |
|
401 | + * @return string |
|
402 | + * @throws InvalidIdentifierException |
|
403 | + */ |
|
404 | + private function filterIdentifier($identifier) |
|
405 | + { |
|
406 | + $identifier = $this->processIdentifier($identifier); |
|
407 | + return isset($this->filters[$identifier]) && ! empty($this->filters[$identifier]) |
|
408 | + ? $this->filters[$identifier] |
|
409 | + : $identifier; |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * verifies and standardizes identifiers |
|
416 | + * |
|
417 | + * @param string $identifier Identifier for the entity class |
|
418 | + * Typically a Fully Qualified Class Name |
|
419 | + * @return string |
|
420 | + * @throws InvalidIdentifierException |
|
421 | + */ |
|
422 | + private function processIdentifier($identifier) |
|
423 | + { |
|
424 | + if ( ! is_string($identifier)) { |
|
425 | + throw new InvalidIdentifierException( |
|
426 | + is_object($identifier) ? get_class($identifier) : gettype($identifier), |
|
427 | + '\Fully\Qualified\ClassName' |
|
428 | + ); |
|
429 | + } |
|
430 | + return ltrim($identifier, '\\'); |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * @param string $type |
|
437 | + * @return CoffeeMakerInterface |
|
438 | + * @throws InvalidDataTypeException |
|
439 | + * @throws InvalidClassException |
|
440 | + */ |
|
441 | + private function getCoffeeMaker($type) |
|
442 | + { |
|
443 | + if ( ! $this->coffee_makers->has($type)) { |
|
444 | + throw new OutOfBoundsException( |
|
445 | + __('The requested coffee maker is either missing or invalid.', 'event_espresso') |
|
446 | + ); |
|
447 | + } |
|
448 | + return $this->coffee_makers->get($type); |
|
449 | + } |
|
450 | + |
|
451 | + |
|
452 | + |
|
453 | + /** |
|
454 | + * Retrieves all recipes that use a wildcard "*" in their identifier |
|
455 | + * This allows recipes to be set up for handling |
|
456 | + * legacy classes that do not support PSR-4 autoloading. |
|
457 | + * for example: |
|
458 | + * using "EEM_*" for a recipe identifier would target all legacy models like EEM_Attendee |
|
459 | + * |
|
460 | + * @return array |
|
461 | + */ |
|
462 | + private function getDefaultRecipes() |
|
463 | + { |
|
464 | + $default_recipes = array(); |
|
465 | + $this->recipes->rewind(); |
|
466 | + while ($this->recipes->valid()) { |
|
467 | + $identifier = $this->recipes->getInfo(); |
|
468 | + // does this recipe use a wildcard ? (but is NOT the global default) |
|
469 | + if ($identifier !== Recipe::DEFAULT_ID && strpos($identifier, '*') !== false) { |
|
470 | + // strip the wildcard and use identifier as key |
|
471 | + $default_recipes[str_replace('*', '', $identifier)] = $this->recipes->current(); |
|
472 | + } |
|
473 | + $this->recipes->next(); |
|
474 | + } |
|
475 | + return $default_recipes; |
|
476 | + } |
|
477 | + |
|
478 | + |
|
479 | + |
|
480 | + /** |
|
481 | + * clones a default recipe and then copies details |
|
482 | + * from the incoming request to it so that it can be used |
|
483 | + * |
|
484 | + * @param RecipeInterface $default_recipe |
|
485 | + * @param string $identifier |
|
486 | + * @param string $type |
|
487 | + * @return RecipeInterface |
|
488 | + */ |
|
489 | + private function copyDefaultRecipe(RecipeInterface $default_recipe, $identifier, $type = '') |
|
490 | + { |
|
491 | + $recipe = clone $default_recipe; |
|
492 | + if ( ! empty($type)) { |
|
493 | + $recipe->setType($type); |
|
494 | + } |
|
495 | + // is this the base default recipe ? |
|
496 | + if ($default_recipe->identifier() === Recipe::DEFAULT_ID) { |
|
497 | + $recipe->setIdentifier($identifier); |
|
498 | + $recipe->setFqcn($identifier); |
|
499 | + return $recipe; |
|
500 | + } |
|
501 | + $recipe->setIdentifier($identifier); |
|
502 | + foreach ($default_recipe->paths() as $path) { |
|
503 | + $path = str_replace('*', $identifier, $path); |
|
504 | + if (is_readable($path)) { |
|
505 | + $recipe->setPaths($path); |
|
506 | + } |
|
507 | + } |
|
508 | + $recipe->setFqcn($identifier); |
|
509 | + return $recipe; |
|
510 | + } |
|
511 | + |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * @param string $identifier Identifier for the entity class that the service applies to |
|
516 | + * Typically a Fully Qualified Class Name |
|
517 | + * @param mixed $service |
|
518 | + * @return object |
|
519 | + * @throws InvalidServiceException |
|
520 | + */ |
|
521 | + private function validateService($identifier, $service) |
|
522 | + { |
|
523 | + if ( ! is_object($service)) { |
|
524 | + throw new InvalidServiceException( |
|
525 | + $identifier, |
|
526 | + $service |
|
527 | + ); |
|
528 | + } |
|
529 | + return $service; |
|
530 | + } |
|
531 | 531 | |
532 | 532 | } |
533 | 533 | // End of file CoffeeShop.php |
@@ -921,7 +921,7 @@ discard block |
||
921 | 921 | /** |
922 | 922 | * Sets deleted |
923 | 923 | * @param boolean $deleted |
924 | - * @return boolean |
|
924 | + * @return boolean|null |
|
925 | 925 | */ |
926 | 926 | public function set_deleted($deleted) { |
927 | 927 | if ( $deleted ) { |
@@ -969,6 +969,7 @@ discard block |
||
969 | 969 | * |
970 | 970 | * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
971 | 971 | * @param bool $check_approved This is used to indicate whether the caller wants can_checkin to also consider registration status as well as datetime access. |
972 | + * @param integer $DTT_OR_ID |
|
972 | 973 | * |
973 | 974 | * @return bool |
974 | 975 | */ |
@@ -1107,7 +1108,7 @@ discard block |
||
1107 | 1108 | * Returns the latest datetime related to this registration (via the ticket attached to the registration). |
1108 | 1109 | * "Latest" is defined by the `DTT_EVT_start` column. |
1109 | 1110 | * |
1110 | - * @return EE_Datetime|null |
|
1111 | + * @return null|EE_Base_Class |
|
1111 | 1112 | * @throws \EE_Error |
1112 | 1113 | */ |
1113 | 1114 | public function get_latest_related_datetime() { |
@@ -1378,7 +1379,7 @@ discard block |
||
1378 | 1379 | * This grabs the payment method corresponding to the last payment made for the amount owing on the registration. |
1379 | 1380 | * Note: if there are no payments on the registration there will be no payment method returned. |
1380 | 1381 | * |
1381 | - * @return EE_Payment_Method|null |
|
1382 | + * @return null|EE_Base_Class |
|
1382 | 1383 | */ |
1383 | 1384 | public function payment_method() { |
1384 | 1385 | return EEM_Payment_Method::instance()->get_last_used_for_registration( $this ); |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | |
36 | 36 | /** |
37 | 37 | * extra meta key for tracking reg status os trashed registrations |
38 | - * |
|
38 | + * |
|
39 | 39 | * @type string |
40 | 40 | */ |
41 | 41 | const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status'; |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | |
44 | 44 | /** |
45 | 45 | * extra meta key for tracking if registration has reserved ticket |
46 | - * |
|
46 | + * |
|
47 | 47 | * @type string |
48 | 48 | */ |
49 | 49 | const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket'; |
@@ -89,15 +89,15 @@ discard block |
||
89 | 89 | |
90 | 90 | |
91 | 91 | |
92 | - /** |
|
93 | - * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can be routed to internal methods |
|
94 | - * |
|
95 | - * @param string $field_name |
|
96 | - * @param mixed $field_value |
|
97 | - * @param bool $use_default |
|
98 | - * @throws \EE_Error |
|
99 | - * @throws \RuntimeException |
|
100 | - */ |
|
92 | + /** |
|
93 | + * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can be routed to internal methods |
|
94 | + * |
|
95 | + * @param string $field_name |
|
96 | + * @param mixed $field_value |
|
97 | + * @param bool $use_default |
|
98 | + * @throws \EE_Error |
|
99 | + * @throws \RuntimeException |
|
100 | + */ |
|
101 | 101 | public function set( $field_name, $field_value, $use_default = FALSE ) { |
102 | 102 | switch( $field_name ) { |
103 | 103 | case 'REG_code' : |
@@ -115,18 +115,18 @@ discard block |
||
115 | 115 | |
116 | 116 | |
117 | 117 | |
118 | - /** |
|
119 | - * Set Status ID |
|
120 | - * updates the registration status and ALSO... |
|
121 | - * calls reserve_registration_space() if the reg status changes TO approved from any other reg status |
|
122 | - * calls release_registration_space() if the reg status changes FROM approved to any other reg status |
|
123 | - * |
|
124 | - * @param string $new_STS_ID |
|
125 | - * @param boolean $use_default |
|
126 | - * @return bool |
|
127 | - * @throws \RuntimeException |
|
128 | - * @throws \EE_Error |
|
129 | - */ |
|
118 | + /** |
|
119 | + * Set Status ID |
|
120 | + * updates the registration status and ALSO... |
|
121 | + * calls reserve_registration_space() if the reg status changes TO approved from any other reg status |
|
122 | + * calls release_registration_space() if the reg status changes FROM approved to any other reg status |
|
123 | + * |
|
124 | + * @param string $new_STS_ID |
|
125 | + * @param boolean $use_default |
|
126 | + * @return bool |
|
127 | + * @throws \RuntimeException |
|
128 | + * @throws \EE_Error |
|
129 | + */ |
|
130 | 130 | public function set_status( $new_STS_ID = NULL, $use_default = FALSE ) { |
131 | 131 | // get current REG_Status |
132 | 132 | $old_STS_ID = $this->status_ID(); |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | && ! empty( $new_STS_ID ) // as well as the new status |
138 | 138 | && $this->ID() // ensure registration is in the db |
139 | 139 | ) { |
140 | - // TO approved |
|
140 | + // TO approved |
|
141 | 141 | if ( $new_STS_ID === EEM_Registration::status_id_approved ) { |
142 | 142 | // reserve a space by incrementing ticket and datetime sold values |
143 | 143 | $this->_reserve_registration_space(); |
@@ -148,12 +148,12 @@ discard block |
||
148 | 148 | $this->_release_registration_space(); |
149 | 149 | do_action( 'AHEE__EE_Registration__set_status__from_approved', $this, $old_STS_ID, $new_STS_ID ); |
150 | 150 | } |
151 | - // update status |
|
152 | - parent::set('STS_ID', $new_STS_ID, $use_default); |
|
153 | - $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID); |
|
154 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
155 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
156 | - $transaction_payments->recalculate_transaction_total( $this->transaction(), false ); |
|
151 | + // update status |
|
152 | + parent::set('STS_ID', $new_STS_ID, $use_default); |
|
153 | + $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID); |
|
154 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
155 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
156 | + $transaction_payments->recalculate_transaction_total( $this->transaction(), false ); |
|
157 | 157 | $this->transaction()->update_status_based_on_total_paid( true ); |
158 | 158 | do_action( 'AHEE__EE_Registration__set_status__after_update', $this ); |
159 | 159 | return TRUE; |
@@ -167,60 +167,60 @@ discard block |
||
167 | 167 | |
168 | 168 | |
169 | 169 | |
170 | - /** |
|
171 | - * update REGs and TXN when cancelled or declined registrations involved |
|
172 | - * |
|
173 | - * @param string $new_STS_ID |
|
174 | - * @param string $old_STS_ID |
|
175 | - * @throws \EE_Error |
|
176 | - */ |
|
177 | - private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID) |
|
178 | - { |
|
179 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
180 | - $closed_reg_statuses = EEM_Registration::closed_reg_statuses(); |
|
181 | - // true if registration has been cancelled or declined |
|
182 | - if ( |
|
183 | - in_array($new_STS_ID, $closed_reg_statuses, true) |
|
184 | - && ! in_array($old_STS_ID, $closed_reg_statuses, true) |
|
185 | - ) { |
|
186 | - /** @type EE_Registration_Processor $registration_processor */ |
|
187 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
188 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
189 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
190 | - // cancelled or declined registration |
|
191 | - $registration_processor->update_registration_after_being_canceled_or_declined( |
|
192 | - $this, |
|
193 | - $closed_reg_statuses |
|
194 | - ); |
|
195 | - $transaction_processor->update_transaction_after_canceled_or_declined_registration( |
|
196 | - $this, |
|
197 | - $closed_reg_statuses, |
|
198 | - false |
|
199 | - ); |
|
200 | - do_action('AHEE__EE_Registration__set_status__canceled_or_declined', $this, $old_STS_ID, $new_STS_ID); |
|
201 | - return; |
|
202 | - } |
|
203 | - // true if reinstating cancelled or declined registration |
|
204 | - if ( |
|
205 | - in_array($old_STS_ID, $closed_reg_statuses, true) |
|
206 | - && ! in_array($new_STS_ID, $closed_reg_statuses, true) |
|
207 | - ) { |
|
208 | - /** @type EE_Registration_Processor $registration_processor */ |
|
209 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
210 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
211 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
212 | - // reinstating cancelled or declined registration |
|
213 | - $registration_processor->update_canceled_or_declined_registration_after_being_reinstated( |
|
214 | - $this, |
|
215 | - $closed_reg_statuses |
|
216 | - ); |
|
217 | - $transaction_processor->update_transaction_after_reinstating_canceled_registration( |
|
218 | - $this, |
|
219 | - $closed_reg_statuses, |
|
220 | - false |
|
221 | - ); |
|
222 | - do_action('AHEE__EE_Registration__set_status__after_reinstated', $this, $old_STS_ID, $new_STS_ID); |
|
223 | - } |
|
170 | + /** |
|
171 | + * update REGs and TXN when cancelled or declined registrations involved |
|
172 | + * |
|
173 | + * @param string $new_STS_ID |
|
174 | + * @param string $old_STS_ID |
|
175 | + * @throws \EE_Error |
|
176 | + */ |
|
177 | + private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID) |
|
178 | + { |
|
179 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
180 | + $closed_reg_statuses = EEM_Registration::closed_reg_statuses(); |
|
181 | + // true if registration has been cancelled or declined |
|
182 | + if ( |
|
183 | + in_array($new_STS_ID, $closed_reg_statuses, true) |
|
184 | + && ! in_array($old_STS_ID, $closed_reg_statuses, true) |
|
185 | + ) { |
|
186 | + /** @type EE_Registration_Processor $registration_processor */ |
|
187 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
188 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
189 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
190 | + // cancelled or declined registration |
|
191 | + $registration_processor->update_registration_after_being_canceled_or_declined( |
|
192 | + $this, |
|
193 | + $closed_reg_statuses |
|
194 | + ); |
|
195 | + $transaction_processor->update_transaction_after_canceled_or_declined_registration( |
|
196 | + $this, |
|
197 | + $closed_reg_statuses, |
|
198 | + false |
|
199 | + ); |
|
200 | + do_action('AHEE__EE_Registration__set_status__canceled_or_declined', $this, $old_STS_ID, $new_STS_ID); |
|
201 | + return; |
|
202 | + } |
|
203 | + // true if reinstating cancelled or declined registration |
|
204 | + if ( |
|
205 | + in_array($old_STS_ID, $closed_reg_statuses, true) |
|
206 | + && ! in_array($new_STS_ID, $closed_reg_statuses, true) |
|
207 | + ) { |
|
208 | + /** @type EE_Registration_Processor $registration_processor */ |
|
209 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
210 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
211 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
212 | + // reinstating cancelled or declined registration |
|
213 | + $registration_processor->update_canceled_or_declined_registration_after_being_reinstated( |
|
214 | + $this, |
|
215 | + $closed_reg_statuses |
|
216 | + ); |
|
217 | + $transaction_processor->update_transaction_after_reinstating_canceled_registration( |
|
218 | + $this, |
|
219 | + $closed_reg_statuses, |
|
220 | + false |
|
221 | + ); |
|
222 | + do_action('AHEE__EE_Registration__set_status__after_reinstated', $this, $old_STS_ID, $new_STS_ID); |
|
223 | + } |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | |
@@ -233,16 +233,16 @@ discard block |
||
233 | 233 | |
234 | 234 | |
235 | 235 | |
236 | - /** |
|
237 | - * increments this registration's related ticket sold and corresponding datetime sold values |
|
238 | - * |
|
239 | - * @return void |
|
240 | - * @throws \EE_Error |
|
241 | - */ |
|
236 | + /** |
|
237 | + * increments this registration's related ticket sold and corresponding datetime sold values |
|
238 | + * |
|
239 | + * @return void |
|
240 | + * @throws \EE_Error |
|
241 | + */ |
|
242 | 242 | private function _reserve_registration_space() { |
243 | - // reserved ticket and datetime counts will be decremented as sold counts are incremented |
|
244 | - // so stop tracking that this reg has a ticket reserved |
|
245 | - $this->release_reserved_ticket(); |
|
243 | + // reserved ticket and datetime counts will be decremented as sold counts are incremented |
|
244 | + // so stop tracking that this reg has a ticket reserved |
|
245 | + $this->release_reserved_ticket(); |
|
246 | 246 | $ticket = $this->ticket(); |
247 | 247 | $ticket->increase_sold(); |
248 | 248 | $ticket->save(); |
@@ -252,13 +252,13 @@ discard block |
||
252 | 252 | |
253 | 253 | |
254 | 254 | |
255 | - /** |
|
256 | - * Gets the ticket this registration is for |
|
257 | - * |
|
258 | - * @param boolean $include_archived whether to include archived tickets or not. |
|
259 | - * @return EE_Ticket|EE_Base_Class |
|
260 | - * @throws \EE_Error |
|
261 | - */ |
|
255 | + /** |
|
256 | + * Gets the ticket this registration is for |
|
257 | + * |
|
258 | + * @param boolean $include_archived whether to include archived tickets or not. |
|
259 | + * @return EE_Ticket|EE_Base_Class |
|
260 | + * @throws \EE_Error |
|
261 | + */ |
|
262 | 262 | public function ticket( $include_archived = TRUE ) { |
263 | 263 | $query_params = array(); |
264 | 264 | if ( $include_archived ) { |
@@ -300,12 +300,12 @@ discard block |
||
300 | 300 | |
301 | 301 | |
302 | 302 | |
303 | - /** |
|
304 | - * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values |
|
305 | - * |
|
306 | - * @return void |
|
307 | - * @throws \EE_Error |
|
308 | - */ |
|
303 | + /** |
|
304 | + * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values |
|
305 | + * |
|
306 | + * @return void |
|
307 | + * @throws \EE_Error |
|
308 | + */ |
|
309 | 309 | private function _release_registration_space() { |
310 | 310 | $ticket = $this->ticket(); |
311 | 311 | $ticket->decrease_sold(); |
@@ -314,46 +314,46 @@ discard block |
||
314 | 314 | |
315 | 315 | |
316 | 316 | |
317 | - /** |
|
318 | - * tracks this registration's ticket reservation in extra meta |
|
319 | - * and can increment related ticket reserved and corresponding datetime reserved values |
|
320 | - * |
|
321 | - * @param bool $update_ticket if true, will increment ticket and datetime reserved count |
|
322 | - * @return void |
|
323 | - * @throws \EE_Error |
|
324 | - */ |
|
317 | + /** |
|
318 | + * tracks this registration's ticket reservation in extra meta |
|
319 | + * and can increment related ticket reserved and corresponding datetime reserved values |
|
320 | + * |
|
321 | + * @param bool $update_ticket if true, will increment ticket and datetime reserved count |
|
322 | + * @return void |
|
323 | + * @throws \EE_Error |
|
324 | + */ |
|
325 | 325 | public function reserve_ticket($update_ticket = false) { |
326 | - if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) === false) { |
|
327 | - // PLZ NOTE: although checking $update_ticket first would be more efficient, |
|
328 | - // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
329 | - if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) && $update_ticket) { |
|
330 | - $ticket = $this->ticket(); |
|
331 | - $ticket->increase_reserved(); |
|
332 | - $ticket->save(); |
|
333 | - } |
|
334 | - } |
|
326 | + if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) === false) { |
|
327 | + // PLZ NOTE: although checking $update_ticket first would be more efficient, |
|
328 | + // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
329 | + if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) && $update_ticket) { |
|
330 | + $ticket = $this->ticket(); |
|
331 | + $ticket->increase_reserved(); |
|
332 | + $ticket->save(); |
|
333 | + } |
|
334 | + } |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | |
338 | 338 | |
339 | - /** |
|
340 | - * stops tracking this registration's ticket reservation in extra meta |
|
341 | - * decrements (subtracts) related ticket reserved and corresponding datetime reserved values |
|
342 | - * |
|
343 | - * @param bool $update_ticket if true, will decrement ticket and datetime reserved count |
|
344 | - * @return void |
|
345 | - * @throws \EE_Error |
|
346 | - */ |
|
347 | - public function release_reserved_ticket($update_ticket = false) { |
|
348 | - if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) !== false) { |
|
349 | - // PLZ NOTE: although checking $update_ticket first would be more efficient, |
|
350 | - // we NEED to ALWAYS call delete_extra_meta(), which is why that is done first |
|
351 | - if ($this->delete_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY) && $update_ticket) { |
|
352 | - $ticket = $this->ticket(); |
|
353 | - $ticket->decrease_reserved(); |
|
354 | - $ticket->save(); |
|
355 | - } |
|
356 | - } |
|
339 | + /** |
|
340 | + * stops tracking this registration's ticket reservation in extra meta |
|
341 | + * decrements (subtracts) related ticket reserved and corresponding datetime reserved values |
|
342 | + * |
|
343 | + * @param bool $update_ticket if true, will decrement ticket and datetime reserved count |
|
344 | + * @return void |
|
345 | + * @throws \EE_Error |
|
346 | + */ |
|
347 | + public function release_reserved_ticket($update_ticket = false) { |
|
348 | + if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) !== false) { |
|
349 | + // PLZ NOTE: although checking $update_ticket first would be more efficient, |
|
350 | + // we NEED to ALWAYS call delete_extra_meta(), which is why that is done first |
|
351 | + if ($this->delete_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY) && $update_ticket) { |
|
352 | + $ticket = $this->ticket(); |
|
353 | + $ticket->decrease_reserved(); |
|
354 | + $ticket->save(); |
|
355 | + } |
|
356 | + } |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | |
@@ -742,9 +742,9 @@ discard block |
||
742 | 742 | |
743 | 743 | |
744 | 744 | /** |
745 | - * get Attendee Number |
|
746 | - * @access public |
|
747 | - */ |
|
745 | + * get Attendee Number |
|
746 | + * @access public |
|
747 | + */ |
|
748 | 748 | public function count() { |
749 | 749 | return $this->get( 'REG_count' ); |
750 | 750 | } |
@@ -1021,11 +1021,11 @@ discard block |
||
1021 | 1021 | * @return boolean |
1022 | 1022 | */ |
1023 | 1023 | public function set_deleted($deleted) { |
1024 | - if ( $deleted ) { |
|
1025 | - $this->delete(); |
|
1026 | - } else { |
|
1027 | - $this->restore(); |
|
1028 | - } |
|
1024 | + if ( $deleted ) { |
|
1025 | + $this->delete(); |
|
1026 | + } else { |
|
1027 | + $this->restore(); |
|
1028 | + } |
|
1029 | 1029 | } |
1030 | 1030 | |
1031 | 1031 | |
@@ -1130,20 +1130,20 @@ discard block |
||
1130 | 1130 | |
1131 | 1131 | |
1132 | 1132 | |
1133 | - /** |
|
1134 | - * toggle Check-in status for this registration |
|
1135 | - * Check-ins are toggled in the following order: |
|
1136 | - * never checked in -> checked in |
|
1137 | - * checked in -> checked out |
|
1138 | - * checked out -> checked in |
|
1139 | - * |
|
1140 | - * @param int $DTT_ID include specific datetime to toggle Check-in for. |
|
1141 | - * If not included or null, then it is assumed latest datetime is being toggled. |
|
1142 | - * @param bool $verify If true then can_checkin() is used to verify whether the person |
|
1143 | - * can be checked in or not. Otherwise this forces change in checkin status. |
|
1144 | - * @return bool|int the chk_in status toggled to OR false if nothing got changed. |
|
1145 | - * @throws EE_Error |
|
1146 | - */ |
|
1133 | + /** |
|
1134 | + * toggle Check-in status for this registration |
|
1135 | + * Check-ins are toggled in the following order: |
|
1136 | + * never checked in -> checked in |
|
1137 | + * checked in -> checked out |
|
1138 | + * checked out -> checked in |
|
1139 | + * |
|
1140 | + * @param int $DTT_ID include specific datetime to toggle Check-in for. |
|
1141 | + * If not included or null, then it is assumed latest datetime is being toggled. |
|
1142 | + * @param bool $verify If true then can_checkin() is used to verify whether the person |
|
1143 | + * can be checked in or not. Otherwise this forces change in checkin status. |
|
1144 | + * @return bool|int the chk_in status toggled to OR false if nothing got changed. |
|
1145 | + * @throws EE_Error |
|
1146 | + */ |
|
1147 | 1147 | public function toggle_checkin_status( $DTT_ID = null, $verify = false ) { |
1148 | 1148 | if ( empty( $DTT_ID ) ) { |
1149 | 1149 | $datetime = $this->get_latest_related_datetime(); |
@@ -1200,13 +1200,13 @@ discard block |
||
1200 | 1200 | |
1201 | 1201 | |
1202 | 1202 | |
1203 | - /** |
|
1204 | - * Returns the latest datetime related to this registration (via the ticket attached to the registration). |
|
1205 | - * "Latest" is defined by the `DTT_EVT_start` column. |
|
1206 | - * |
|
1207 | - * @return EE_Datetime|null |
|
1208 | - * @throws \EE_Error |
|
1209 | - */ |
|
1203 | + /** |
|
1204 | + * Returns the latest datetime related to this registration (via the ticket attached to the registration). |
|
1205 | + * "Latest" is defined by the `DTT_EVT_start` column. |
|
1206 | + * |
|
1207 | + * @return EE_Datetime|null |
|
1208 | + * @throws \EE_Error |
|
1209 | + */ |
|
1210 | 1210 | public function get_latest_related_datetime() { |
1211 | 1211 | return EEM_Datetime::instance()->get_one( |
1212 | 1212 | array( |
@@ -1220,12 +1220,12 @@ discard block |
||
1220 | 1220 | |
1221 | 1221 | |
1222 | 1222 | |
1223 | - /** |
|
1224 | - * Returns the earliest datetime related to this registration (via the ticket attached to the registration). |
|
1225 | - * "Earliest" is defined by the `DTT_EVT_start` column. |
|
1226 | - * |
|
1227 | - * @throws \EE_Error |
|
1228 | - */ |
|
1223 | + /** |
|
1224 | + * Returns the earliest datetime related to this registration (via the ticket attached to the registration). |
|
1225 | + * "Earliest" is defined by the `DTT_EVT_start` column. |
|
1226 | + * |
|
1227 | + * @throws \EE_Error |
|
1228 | + */ |
|
1229 | 1229 | public function get_earliest_related_datetime() { |
1230 | 1230 | return EEM_Datetime::instance()->get_one( |
1231 | 1231 | array( |
@@ -1239,18 +1239,18 @@ discard block |
||
1239 | 1239 | |
1240 | 1240 | |
1241 | 1241 | |
1242 | - /** |
|
1243 | - * This method simply returns the check-in status for this registration and the given datetime. |
|
1244 | - * If neither the datetime nor the checkin values are provided as arguments, |
|
1245 | - * then this will return the LATEST check-in status for the registration across all datetimes it belongs to. |
|
1246 | - * |
|
1247 | - * @param int $DTT_ID The ID of the datetime we're checking against |
|
1248 | - * (if empty we'll get the primary datetime for |
|
1249 | - * this registration (via event) and use it's ID); |
|
1250 | - * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id. |
|
1251 | - * @return int Integer representing Check-in status. |
|
1252 | - * @throws \EE_Error |
|
1253 | - */ |
|
1242 | + /** |
|
1243 | + * This method simply returns the check-in status for this registration and the given datetime. |
|
1244 | + * If neither the datetime nor the checkin values are provided as arguments, |
|
1245 | + * then this will return the LATEST check-in status for the registration across all datetimes it belongs to. |
|
1246 | + * |
|
1247 | + * @param int $DTT_ID The ID of the datetime we're checking against |
|
1248 | + * (if empty we'll get the primary datetime for |
|
1249 | + * this registration (via event) and use it's ID); |
|
1250 | + * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id. |
|
1251 | + * @return int Integer representing Check-in status. |
|
1252 | + * @throws \EE_Error |
|
1253 | + */ |
|
1254 | 1254 | public function check_in_status_for_datetime( $DTT_ID = 0, $checkin = null ) { |
1255 | 1255 | $checkin_query_params = array( |
1256 | 1256 | 'order_by' => array( 'CHK_timestamp' => 'DESC' ) |
@@ -1262,8 +1262,8 @@ discard block |
||
1262 | 1262 | |
1263 | 1263 | //get checkin object (if exists) |
1264 | 1264 | $checkin = $checkin instanceof EE_Checkin |
1265 | - ? $checkin |
|
1266 | - : $this->get_first_related( 'Checkin', $checkin_query_params ); |
|
1265 | + ? $checkin |
|
1266 | + : $this->get_first_related( 'Checkin', $checkin_query_params ); |
|
1267 | 1267 | if ( $checkin instanceof EE_Checkin ) { |
1268 | 1268 | if ( $checkin->get( 'CHK_in' ) ) { |
1269 | 1269 | return EE_Registration::checkin_status_in; //checked in |
@@ -1516,46 +1516,46 @@ discard block |
||
1516 | 1516 | |
1517 | 1517 | |
1518 | 1518 | |
1519 | - /** |
|
1520 | - * Soft Deletes this model object. |
|
1521 | - * |
|
1522 | - * @return boolean | int |
|
1523 | - * @throws \RuntimeException |
|
1524 | - * @throws \EE_Error |
|
1525 | - */ |
|
1526 | - public function delete() |
|
1527 | - { |
|
1528 | - if($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) { |
|
1529 | - $this->set_status(EEM_Registration::status_id_cancelled); |
|
1530 | - } |
|
1531 | - return parent::delete(); |
|
1532 | - } |
|
1519 | + /** |
|
1520 | + * Soft Deletes this model object. |
|
1521 | + * |
|
1522 | + * @return boolean | int |
|
1523 | + * @throws \RuntimeException |
|
1524 | + * @throws \EE_Error |
|
1525 | + */ |
|
1526 | + public function delete() |
|
1527 | + { |
|
1528 | + if($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) { |
|
1529 | + $this->set_status(EEM_Registration::status_id_cancelled); |
|
1530 | + } |
|
1531 | + return parent::delete(); |
|
1532 | + } |
|
1533 | 1533 | |
1534 | 1534 | |
1535 | 1535 | |
1536 | - /** |
|
1537 | - * Restores whatever the previous status was on a registration before it was trashed (if possible) |
|
1538 | - * |
|
1539 | - * @throws \EE_Error |
|
1540 | - * @throws \RuntimeException |
|
1541 | - */ |
|
1542 | - public function restore() |
|
1543 | - { |
|
1544 | - $previous_status = $this->get_extra_meta( |
|
1545 | - EE_Registration::PRE_TRASH_REG_STATUS_KEY, |
|
1546 | - true, |
|
1547 | - EEM_Registration::status_id_cancelled |
|
1548 | - ); |
|
1549 | - if ($previous_status) { |
|
1550 | - $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY); |
|
1551 | - $this->set_status($previous_status); |
|
1552 | - } |
|
1553 | - return parent::restore(); |
|
1554 | - } |
|
1536 | + /** |
|
1537 | + * Restores whatever the previous status was on a registration before it was trashed (if possible) |
|
1538 | + * |
|
1539 | + * @throws \EE_Error |
|
1540 | + * @throws \RuntimeException |
|
1541 | + */ |
|
1542 | + public function restore() |
|
1543 | + { |
|
1544 | + $previous_status = $this->get_extra_meta( |
|
1545 | + EE_Registration::PRE_TRASH_REG_STATUS_KEY, |
|
1546 | + true, |
|
1547 | + EEM_Registration::status_id_cancelled |
|
1548 | + ); |
|
1549 | + if ($previous_status) { |
|
1550 | + $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY); |
|
1551 | + $this->set_status($previous_status); |
|
1552 | + } |
|
1553 | + return parent::restore(); |
|
1554 | + } |
|
1555 | 1555 | |
1556 | 1556 | |
1557 | 1557 | |
1558 | - /*************************** DEPRECATED ***************************/ |
|
1558 | + /*************************** DEPRECATED ***************************/ |
|
1559 | 1559 | |
1560 | 1560 | |
1561 | 1561 | |
@@ -1605,24 +1605,24 @@ discard block |
||
1605 | 1605 | |
1606 | 1606 | |
1607 | 1607 | |
1608 | - /** |
|
1609 | - * Gets the primary datetime related to this registration via the related Event to this registration |
|
1610 | - * |
|
1611 | - * @deprecated 4.9.17 |
|
1612 | - * @return EE_Datetime |
|
1613 | - */ |
|
1614 | - public function get_related_primary_datetime() { |
|
1615 | - EE_Error::doing_it_wrong( |
|
1616 | - __METHOD__, |
|
1617 | - esc_html__( |
|
1618 | - 'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()', |
|
1619 | - 'event_espresso' |
|
1620 | - ), |
|
1621 | - '4.9.17', |
|
1622 | - '5.0.0' |
|
1623 | - ); |
|
1624 | - return $this->event()->primary_datetime(); |
|
1625 | - } |
|
1608 | + /** |
|
1609 | + * Gets the primary datetime related to this registration via the related Event to this registration |
|
1610 | + * |
|
1611 | + * @deprecated 4.9.17 |
|
1612 | + * @return EE_Datetime |
|
1613 | + */ |
|
1614 | + public function get_related_primary_datetime() { |
|
1615 | + EE_Error::doing_it_wrong( |
|
1616 | + __METHOD__, |
|
1617 | + esc_html__( |
|
1618 | + 'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()', |
|
1619 | + 'event_espresso' |
|
1620 | + ), |
|
1621 | + '4.9.17', |
|
1622 | + '5.0.0' |
|
1623 | + ); |
|
1624 | + return $this->event()->primary_datetime(); |
|
1625 | + } |
|
1626 | 1626 | |
1627 | 1627 | |
1628 | 1628 |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\exceptions\EntityNotFoundException; |
2 | 2 | |
3 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
4 | - exit( 'No direct script access allowed' ); |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | /** |
7 | 7 | * EE_Registration class |
@@ -59,9 +59,9 @@ discard block |
||
59 | 59 | * date_format and the second value is the time format |
60 | 60 | * @return EE_Registration |
61 | 61 | */ |
62 | - public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
|
63 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats ); |
|
64 | - return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
|
62 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) { |
|
63 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
64 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | |
@@ -72,8 +72,8 @@ discard block |
||
72 | 72 | * the website will be used. |
73 | 73 | * @return EE_Registration |
74 | 74 | */ |
75 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
|
76 | - return new self( $props_n_values, TRUE, $timezone ); |
|
75 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) { |
|
76 | + return new self($props_n_values, TRUE, $timezone); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | |
@@ -83,8 +83,8 @@ discard block |
||
83 | 83 | * |
84 | 84 | * @param int $EVT_ID Event ID |
85 | 85 | */ |
86 | - public function set_event( $EVT_ID = 0 ) { |
|
87 | - $this->set( 'EVT_ID', $EVT_ID ); |
|
86 | + public function set_event($EVT_ID = 0) { |
|
87 | + $this->set('EVT_ID', $EVT_ID); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | |
@@ -98,18 +98,18 @@ discard block |
||
98 | 98 | * @throws \EE_Error |
99 | 99 | * @throws \RuntimeException |
100 | 100 | */ |
101 | - public function set( $field_name, $field_value, $use_default = FALSE ) { |
|
102 | - switch( $field_name ) { |
|
101 | + public function set($field_name, $field_value, $use_default = FALSE) { |
|
102 | + switch ($field_name) { |
|
103 | 103 | case 'REG_code' : |
104 | - if ( ! empty( $field_value ) && $this->reg_code() === null ) { |
|
105 | - $this->set_reg_code( $field_value, $use_default ); |
|
104 | + if ( ! empty($field_value) && $this->reg_code() === null) { |
|
105 | + $this->set_reg_code($field_value, $use_default); |
|
106 | 106 | } |
107 | 107 | break; |
108 | 108 | case 'STS_ID' : |
109 | - $this->set_status( $field_value, $use_default ); |
|
109 | + $this->set_status($field_value, $use_default); |
|
110 | 110 | break; |
111 | 111 | default : |
112 | - parent::set( $field_name, $field_value, $use_default ); |
|
112 | + parent::set($field_name, $field_value, $use_default); |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
@@ -127,40 +127,40 @@ discard block |
||
127 | 127 | * @throws \RuntimeException |
128 | 128 | * @throws \EE_Error |
129 | 129 | */ |
130 | - public function set_status( $new_STS_ID = NULL, $use_default = FALSE ) { |
|
130 | + public function set_status($new_STS_ID = NULL, $use_default = FALSE) { |
|
131 | 131 | // get current REG_Status |
132 | 132 | $old_STS_ID = $this->status_ID(); |
133 | 133 | // if status has changed |
134 | 134 | if ( |
135 | 135 | $old_STS_ID !== $new_STS_ID // and that status has actually changed |
136 | - && ! empty( $old_STS_ID ) // and that old status is actually set |
|
137 | - && ! empty( $new_STS_ID ) // as well as the new status |
|
136 | + && ! empty($old_STS_ID) // and that old status is actually set |
|
137 | + && ! empty($new_STS_ID) // as well as the new status |
|
138 | 138 | && $this->ID() // ensure registration is in the db |
139 | 139 | ) { |
140 | 140 | // TO approved |
141 | - if ( $new_STS_ID === EEM_Registration::status_id_approved ) { |
|
141 | + if ($new_STS_ID === EEM_Registration::status_id_approved) { |
|
142 | 142 | // reserve a space by incrementing ticket and datetime sold values |
143 | 143 | $this->_reserve_registration_space(); |
144 | - do_action( 'AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID ); |
|
144 | + do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID); |
|
145 | 145 | // OR FROM approved |
146 | - } else if ( $old_STS_ID === EEM_Registration::status_id_approved ) { |
|
146 | + } else if ($old_STS_ID === EEM_Registration::status_id_approved) { |
|
147 | 147 | // release a space by decrementing ticket and datetime sold values |
148 | 148 | $this->_release_registration_space(); |
149 | - do_action( 'AHEE__EE_Registration__set_status__from_approved', $this, $old_STS_ID, $new_STS_ID ); |
|
149 | + do_action('AHEE__EE_Registration__set_status__from_approved', $this, $old_STS_ID, $new_STS_ID); |
|
150 | 150 | } |
151 | 151 | // update status |
152 | 152 | parent::set('STS_ID', $new_STS_ID, $use_default); |
153 | 153 | $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID); |
154 | 154 | /** @type EE_Transaction_Payments $transaction_payments */ |
155 | 155 | $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
156 | - $transaction_payments->recalculate_transaction_total( $this->transaction(), false ); |
|
157 | - $this->transaction()->update_status_based_on_total_paid( true ); |
|
158 | - do_action( 'AHEE__EE_Registration__set_status__after_update', $this ); |
|
156 | + $transaction_payments->recalculate_transaction_total($this->transaction(), false); |
|
157 | + $this->transaction()->update_status_based_on_total_paid(true); |
|
158 | + do_action('AHEE__EE_Registration__set_status__after_update', $this); |
|
159 | 159 | return TRUE; |
160 | 160 | } else { |
161 | 161 | //even though the old value matches the new value, it's still good to |
162 | 162 | //allow the parent set method to have a say |
163 | - parent::set( 'STS_ID', $new_STS_ID, $use_default ); |
|
163 | + parent::set('STS_ID', $new_STS_ID, $use_default); |
|
164 | 164 | return TRUE; |
165 | 165 | } |
166 | 166 | } |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | * get Status ID |
229 | 229 | */ |
230 | 230 | public function status_ID() { |
231 | - return $this->get( 'STS_ID' ); |
|
231 | + return $this->get('STS_ID'); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | |
@@ -259,12 +259,12 @@ discard block |
||
259 | 259 | * @return EE_Ticket|EE_Base_Class |
260 | 260 | * @throws \EE_Error |
261 | 261 | */ |
262 | - public function ticket( $include_archived = TRUE ) { |
|
262 | + public function ticket($include_archived = TRUE) { |
|
263 | 263 | $query_params = array(); |
264 | - if ( $include_archived ) { |
|
265 | - $query_params[ 'default_where_conditions' ] = 'none'; |
|
264 | + if ($include_archived) { |
|
265 | + $query_params['default_where_conditions'] = 'none'; |
|
266 | 266 | } |
267 | - return $this->get_first_related( 'Ticket', $query_params ); |
|
267 | + return $this->get_first_related('Ticket', $query_params); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | */ |
293 | 293 | public function wp_user() { |
294 | 294 | $event = $this->event(); |
295 | - if ( $event instanceof EE_Event ) { |
|
295 | + if ($event instanceof EE_Event) { |
|
296 | 296 | return $event->wp_user(); |
297 | 297 | } |
298 | 298 | return 0; |
@@ -363,8 +363,8 @@ discard block |
||
363 | 363 | * |
364 | 364 | * @param int $ATT_ID Attendee ID |
365 | 365 | */ |
366 | - public function set_attendee_id( $ATT_ID = 0 ) { |
|
367 | - $this->set( 'ATT_ID', $ATT_ID ); |
|
366 | + public function set_attendee_id($ATT_ID = 0) { |
|
367 | + $this->set('ATT_ID', $ATT_ID); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | |
@@ -374,8 +374,8 @@ discard block |
||
374 | 374 | * |
375 | 375 | * @param int $TXN_ID Transaction ID |
376 | 376 | */ |
377 | - public function set_transaction_id( $TXN_ID = 0 ) { |
|
378 | - $this->set( 'TXN_ID', $TXN_ID ); |
|
377 | + public function set_transaction_id($TXN_ID = 0) { |
|
378 | + $this->set('TXN_ID', $TXN_ID); |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | |
@@ -385,8 +385,8 @@ discard block |
||
385 | 385 | * |
386 | 386 | * @param string $REG_session PHP Session ID |
387 | 387 | */ |
388 | - public function set_session( $REG_session = '' ) { |
|
389 | - $this->set( 'REG_session', $REG_session ); |
|
388 | + public function set_session($REG_session = '') { |
|
389 | + $this->set('REG_session', $REG_session); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | |
@@ -396,8 +396,8 @@ discard block |
||
396 | 396 | * |
397 | 397 | * @param string $REG_url_link Registration URL Link |
398 | 398 | */ |
399 | - public function set_reg_url_link( $REG_url_link = '' ) { |
|
400 | - $this->set( 'REG_url_link', $REG_url_link ); |
|
399 | + public function set_reg_url_link($REG_url_link = '') { |
|
400 | + $this->set('REG_url_link', $REG_url_link); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | |
@@ -407,8 +407,8 @@ discard block |
||
407 | 407 | * |
408 | 408 | * @param int $REG_count Primary Attendee |
409 | 409 | */ |
410 | - public function set_count( $REG_count = 1 ) { |
|
411 | - $this->set( 'REG_count', $REG_count ); |
|
410 | + public function set_count($REG_count = 1) { |
|
411 | + $this->set('REG_count', $REG_count); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | |
@@ -418,8 +418,8 @@ discard block |
||
418 | 418 | * |
419 | 419 | * @param boolean $REG_group_size Group Registration |
420 | 420 | */ |
421 | - public function set_group_size( $REG_group_size = FALSE ) { |
|
422 | - $this->set( 'REG_group_size', $REG_group_size ); |
|
421 | + public function set_group_size($REG_group_size = FALSE) { |
|
422 | + $this->set('REG_group_size', $REG_group_size); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | |
@@ -495,8 +495,8 @@ discard block |
||
495 | 495 | * |
496 | 496 | * @param mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of Date |
497 | 497 | */ |
498 | - public function set_reg_date( $REG_date = FALSE ) { |
|
499 | - $this->set( 'REG_date', $REG_date ); |
|
498 | + public function set_reg_date($REG_date = FALSE) { |
|
499 | + $this->set('REG_date', $REG_date); |
|
500 | 500 | } |
501 | 501 | |
502 | 502 | |
@@ -507,8 +507,8 @@ discard block |
||
507 | 507 | * @access public |
508 | 508 | * @param float $REG_final_price |
509 | 509 | */ |
510 | - public function set_final_price( $REG_final_price = 0.00 ) { |
|
511 | - $this->set( 'REG_final_price', $REG_final_price ); |
|
510 | + public function set_final_price($REG_final_price = 0.00) { |
|
511 | + $this->set('REG_final_price', $REG_final_price); |
|
512 | 512 | } |
513 | 513 | |
514 | 514 | |
@@ -519,8 +519,8 @@ discard block |
||
519 | 519 | * @access public |
520 | 520 | * @param float $REG_paid |
521 | 521 | */ |
522 | - public function set_paid( $REG_paid = 0.00 ) { |
|
523 | - $this->set( 'REG_paid', $REG_paid ); |
|
522 | + public function set_paid($REG_paid = 0.00) { |
|
523 | + $this->set('REG_paid', $REG_paid); |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | |
@@ -530,8 +530,8 @@ discard block |
||
530 | 530 | * |
531 | 531 | * @param boolean $REG_att_is_going Attendee Is Going |
532 | 532 | */ |
533 | - public function set_att_is_going( $REG_att_is_going = FALSE ) { |
|
534 | - $this->set( 'REG_att_is_going', $REG_att_is_going ); |
|
533 | + public function set_att_is_going($REG_att_is_going = FALSE) { |
|
534 | + $this->set('REG_att_is_going', $REG_att_is_going); |
|
535 | 535 | } |
536 | 536 | |
537 | 537 | |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | * @return EE_Attendee |
542 | 542 | */ |
543 | 543 | public function attendee() { |
544 | - return $this->get_first_related( 'Attendee' ); |
|
544 | + return $this->get_first_related('Attendee'); |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | |
@@ -550,7 +550,7 @@ discard block |
||
550 | 550 | * get Event ID |
551 | 551 | */ |
552 | 552 | public function event_ID() { |
553 | - return $this->get( 'EVT_ID' ); |
|
553 | + return $this->get('EVT_ID'); |
|
554 | 554 | } |
555 | 555 | |
556 | 556 | |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | */ |
561 | 561 | public function event_name() { |
562 | 562 | $event = $this->event_obj(); |
563 | - if ( $event ) { |
|
563 | + if ($event) { |
|
564 | 564 | return $event->name(); |
565 | 565 | } else { |
566 | 566 | return NULL; |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | * @return EE_Event |
575 | 575 | */ |
576 | 576 | public function event_obj() { |
577 | - return $this->get_first_related( 'Event' ); |
|
577 | + return $this->get_first_related('Event'); |
|
578 | 578 | } |
579 | 579 | |
580 | 580 | |
@@ -583,7 +583,7 @@ discard block |
||
583 | 583 | * get Attendee ID |
584 | 584 | */ |
585 | 585 | public function attendee_ID() { |
586 | - return $this->get( 'ATT_ID' ); |
|
586 | + return $this->get('ATT_ID'); |
|
587 | 587 | } |
588 | 588 | |
589 | 589 | |
@@ -592,7 +592,7 @@ discard block |
||
592 | 592 | * get PHP Session ID |
593 | 593 | */ |
594 | 594 | public function session_ID() { |
595 | - return $this->get( 'REG_session' ); |
|
595 | + return $this->get('REG_session'); |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | * @param string $messenger 'pdf' or 'html'. Default 'html'. |
603 | 603 | * @return string |
604 | 604 | */ |
605 | - public function receipt_url( $messenger = 'html' ) { |
|
605 | + public function receipt_url($messenger = 'html') { |
|
606 | 606 | |
607 | 607 | /** |
608 | 608 | * The below will be deprecated one version after this. We check first if there is a custom receipt template already in use on old system. If there is then we just return the standard url for it. |
@@ -610,12 +610,12 @@ discard block |
||
610 | 610 | * @since 4.5.0 |
611 | 611 | */ |
612 | 612 | $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php'; |
613 | - $has_custom = EEH_Template::locate_template( $template_relative_path , array(), TRUE, TRUE, TRUE ); |
|
613 | + $has_custom = EEH_Template::locate_template($template_relative_path, array(), TRUE, TRUE, TRUE); |
|
614 | 614 | |
615 | - if ( $has_custom ) { |
|
616 | - return add_query_arg( array( 'receipt' => 'true' ), $this->invoice_url( 'launch' ) ); |
|
615 | + if ($has_custom) { |
|
616 | + return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch')); |
|
617 | 617 | } |
618 | - return apply_filters( 'FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt' ); |
|
618 | + return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt'); |
|
619 | 619 | } |
620 | 620 | |
621 | 621 | |
@@ -626,28 +626,28 @@ discard block |
||
626 | 626 | * @param string $messenger 'pdf' or 'html'. Default 'html'. |
627 | 627 | * @return string |
628 | 628 | */ |
629 | - public function invoice_url( $messenger = 'html' ) { |
|
629 | + public function invoice_url($messenger = 'html') { |
|
630 | 630 | /** |
631 | 631 | * The below will be deprecated one version after this. We check first if there is a custom invoice template already in use on old system. If there is then we just return the standard url for it. |
632 | 632 | * |
633 | 633 | * @since 4.5.0 |
634 | 634 | */ |
635 | 635 | $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php'; |
636 | - $has_custom = EEH_Template::locate_template( $template_relative_path , array(), TRUE, TRUE, TRUE ); |
|
636 | + $has_custom = EEH_Template::locate_template($template_relative_path, array(), TRUE, TRUE, TRUE); |
|
637 | 637 | |
638 | - if ( $has_custom ) { |
|
639 | - if ( $messenger == 'html' ) { |
|
640 | - return $this->invoice_url( 'launch' ); |
|
638 | + if ($has_custom) { |
|
639 | + if ($messenger == 'html') { |
|
640 | + return $this->invoice_url('launch'); |
|
641 | 641 | } |
642 | 642 | $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice'; |
643 | 643 | |
644 | - $query_args = array( 'ee' => $route, 'id' => $this->reg_url_link() ); |
|
645 | - if ( $messenger == 'html' ) { |
|
644 | + $query_args = array('ee' => $route, 'id' => $this->reg_url_link()); |
|
645 | + if ($messenger == 'html') { |
|
646 | 646 | $query_args['html'] = TRUE; |
647 | 647 | } |
648 | - return add_query_arg( $query_args, get_permalink( EE_Registry::instance()->CFG->core->thank_you_page_id ) ); |
|
648 | + return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id)); |
|
649 | 649 | } |
650 | - return apply_filters( 'FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice' ); |
|
650 | + return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice'); |
|
651 | 651 | } |
652 | 652 | |
653 | 653 | |
@@ -660,7 +660,7 @@ discard block |
||
660 | 660 | * @throws \EE_Error |
661 | 661 | */ |
662 | 662 | public function reg_url_link() { |
663 | - return (string)$this->get( 'REG_url_link' ); |
|
663 | + return (string) $this->get('REG_url_link'); |
|
664 | 664 | } |
665 | 665 | |
666 | 666 | |
@@ -670,8 +670,8 @@ discard block |
||
670 | 670 | * @param string $type 'download','launch', or 'html' (default is 'launch') |
671 | 671 | * @return void |
672 | 672 | */ |
673 | - public function e_invoice_url( $type = 'launch' ) { |
|
674 | - echo $this->invoice_url( $type ); |
|
673 | + public function e_invoice_url($type = 'launch') { |
|
674 | + echo $this->invoice_url($type); |
|
675 | 675 | } |
676 | 676 | |
677 | 677 | |
@@ -691,7 +691,7 @@ discard block |
||
691 | 691 | * @return string |
692 | 692 | */ |
693 | 693 | public function payment_overview_url() { |
694 | - return add_query_arg( array( 'e_reg_url_link' => $this->reg_url_link(), 'step' => 'payment_options', 'revisit' => TRUE ), EE_Registry::instance()->CFG->core->reg_page_url() ); |
|
694 | + return add_query_arg(array('e_reg_url_link' => $this->reg_url_link(), 'step' => 'payment_options', 'revisit' => TRUE), EE_Registry::instance()->CFG->core->reg_page_url()); |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | |
@@ -702,7 +702,7 @@ discard block |
||
702 | 702 | * @return string |
703 | 703 | */ |
704 | 704 | public function edit_attendee_information_url() { |
705 | - return add_query_arg( array( 'e_reg_url_link' => $this->reg_url_link(), 'step' => 'attendee_information', 'revisit' => TRUE ), EE_Registry::instance()->CFG->core->reg_page_url() ); |
|
705 | + return add_query_arg(array('e_reg_url_link' => $this->reg_url_link(), 'step' => 'attendee_information', 'revisit' => TRUE), EE_Registry::instance()->CFG->core->reg_page_url()); |
|
706 | 706 | } |
707 | 707 | |
708 | 708 | |
@@ -712,7 +712,7 @@ discard block |
||
712 | 712 | * @return string |
713 | 713 | */ |
714 | 714 | public function get_admin_edit_url() { |
715 | - return EEH_URL::add_query_args_and_nonce( array( 'page' => 'espresso_registrations', 'action' => 'view_registration', '_REG_ID' => $this->ID() ), admin_url( 'admin.php' ) ); |
|
715 | + return EEH_URL::add_query_args_and_nonce(array('page' => 'espresso_registrations', 'action' => 'view_registration', '_REG_ID' => $this->ID()), admin_url('admin.php')); |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | |
@@ -721,7 +721,7 @@ discard block |
||
721 | 721 | * is_primary_registrant? |
722 | 722 | */ |
723 | 723 | public function is_primary_registrant() { |
724 | - return $this->get( 'REG_count' ) == 1 ? TRUE : FALSE; |
|
724 | + return $this->get('REG_count') == 1 ? TRUE : FALSE; |
|
725 | 725 | } |
726 | 726 | |
727 | 727 | |
@@ -730,12 +730,12 @@ discard block |
||
730 | 730 | * This returns the primary registration object for this registration group (which may be this object). |
731 | 731 | * @return EE_Registration |
732 | 732 | */ |
733 | - public function get_primary_registration() { |
|
734 | - if ( $this->is_primary_registrant() ) |
|
733 | + public function get_primary_registration() { |
|
734 | + if ($this->is_primary_registrant()) |
|
735 | 735 | return $this; |
736 | 736 | |
737 | 737 | //k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1 |
738 | - $primary_registrant = EEM_Registration::instance()->get_one( array( array('TXN_ID' => $this->transaction_ID(), 'REG_count' => 1 ) ) ); |
|
738 | + $primary_registrant = EEM_Registration::instance()->get_one(array(array('TXN_ID' => $this->transaction_ID(), 'REG_count' => 1))); |
|
739 | 739 | return $primary_registrant; |
740 | 740 | } |
741 | 741 | |
@@ -746,7 +746,7 @@ discard block |
||
746 | 746 | * @access public |
747 | 747 | */ |
748 | 748 | public function count() { |
749 | - return $this->get( 'REG_count' ); |
|
749 | + return $this->get('REG_count'); |
|
750 | 750 | } |
751 | 751 | |
752 | 752 | |
@@ -755,7 +755,7 @@ discard block |
||
755 | 755 | * get Group Size |
756 | 756 | */ |
757 | 757 | public function group_size() { |
758 | - return $this->get( 'REG_group_size' ); |
|
758 | + return $this->get('REG_group_size'); |
|
759 | 759 | } |
760 | 760 | |
761 | 761 | |
@@ -764,7 +764,7 @@ discard block |
||
764 | 764 | * get Registration Date |
765 | 765 | */ |
766 | 766 | public function date() { |
767 | - return $this->get( 'REG_date' ); |
|
767 | + return $this->get('REG_date'); |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | |
@@ -775,8 +775,8 @@ discard block |
||
775 | 775 | * @param string $time_format |
776 | 776 | * @return string |
777 | 777 | */ |
778 | - public function pretty_date( $date_format = NULL, $time_format = NULL ) { |
|
779 | - return $this->get_datetime( 'REG_date', $date_format, $time_format ); |
|
778 | + public function pretty_date($date_format = NULL, $time_format = NULL) { |
|
779 | + return $this->get_datetime('REG_date', $date_format, $time_format); |
|
780 | 780 | } |
781 | 781 | |
782 | 782 | |
@@ -788,7 +788,7 @@ discard block |
||
788 | 788 | * @return float |
789 | 789 | */ |
790 | 790 | public function final_price() { |
791 | - return $this->get( 'REG_final_price' ); |
|
791 | + return $this->get('REG_final_price'); |
|
792 | 792 | } |
793 | 793 | |
794 | 794 | |
@@ -799,7 +799,7 @@ discard block |
||
799 | 799 | * @return string |
800 | 800 | */ |
801 | 801 | public function pretty_final_price() { |
802 | - return $this->get_pretty( 'REG_final_price' ); |
|
802 | + return $this->get_pretty('REG_final_price'); |
|
803 | 803 | } |
804 | 804 | |
805 | 805 | |
@@ -809,7 +809,7 @@ discard block |
||
809 | 809 | * @return float |
810 | 810 | */ |
811 | 811 | public function paid() { |
812 | - return $this->get( 'REG_paid' ); |
|
812 | + return $this->get('REG_paid'); |
|
813 | 813 | } |
814 | 814 | |
815 | 815 | |
@@ -819,7 +819,7 @@ discard block |
||
819 | 819 | * @return float |
820 | 820 | */ |
821 | 821 | public function pretty_paid() { |
822 | - return $this->get_pretty( 'REG_paid' ); |
|
822 | + return $this->get_pretty('REG_paid'); |
|
823 | 823 | } |
824 | 824 | |
825 | 825 | |
@@ -830,11 +830,11 @@ discard block |
||
830 | 830 | * @param array $requires_payment |
831 | 831 | * @return bool |
832 | 832 | */ |
833 | - public function owes_monies_and_can_pay( $requires_payment = array()) { |
|
833 | + public function owes_monies_and_can_pay($requires_payment = array()) { |
|
834 | 834 | // these reg statuses require payment (if event is not free) |
835 | - $requires_payment = ! empty( $requires_payment ) ? $requires_payment : EEM_Registration::reg_statuses_that_allow_payment(); |
|
835 | + $requires_payment = ! empty($requires_payment) ? $requires_payment : EEM_Registration::reg_statuses_that_allow_payment(); |
|
836 | 836 | if ( |
837 | - in_array( $this->status_ID(), $requires_payment ) && |
|
837 | + in_array($this->status_ID(), $requires_payment) && |
|
838 | 838 | $this->final_price() != 0 && |
839 | 839 | $this->final_price() != $this->paid() |
840 | 840 | ) { |
@@ -851,8 +851,8 @@ discard block |
||
851 | 851 | * @param bool $show_icons |
852 | 852 | * @return void |
853 | 853 | */ |
854 | - public function e_pretty_status( $show_icons = FALSE ) { |
|
855 | - echo $this->pretty_status( $show_icons ); |
|
854 | + public function e_pretty_status($show_icons = FALSE) { |
|
855 | + echo $this->pretty_status($show_icons); |
|
856 | 856 | } |
857 | 857 | |
858 | 858 | |
@@ -863,10 +863,10 @@ discard block |
||
863 | 863 | * @param bool $show_icons |
864 | 864 | * @return string |
865 | 865 | */ |
866 | - public function pretty_status( $show_icons = FALSE ) { |
|
867 | - $status = EEM_Status::instance()->localized_status( array( $this->status_ID() => __( 'unknown', 'event_espresso' ) ), FALSE, 'sentence' ); |
|
866 | + public function pretty_status($show_icons = FALSE) { |
|
867 | + $status = EEM_Status::instance()->localized_status(array($this->status_ID() => __('unknown', 'event_espresso')), FALSE, 'sentence'); |
|
868 | 868 | $icon = ''; |
869 | - switch ( $this->status_ID() ) { |
|
869 | + switch ($this->status_ID()) { |
|
870 | 870 | case EEM_Registration::status_id_approved: |
871 | 871 | $icon = $show_icons ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' : ''; |
872 | 872 | break; |
@@ -889,7 +889,7 @@ discard block |
||
889 | 889 | $icon = $show_icons ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' : ''; |
890 | 890 | break; |
891 | 891 | } |
892 | - return $icon . $status[ $this->status_ID() ]; |
|
892 | + return $icon.$status[$this->status_ID()]; |
|
893 | 893 | } |
894 | 894 | |
895 | 895 | |
@@ -898,7 +898,7 @@ discard block |
||
898 | 898 | * get Attendee Is Going |
899 | 899 | */ |
900 | 900 | public function att_is_going() { |
901 | - return $this->get( 'REG_att_is_going' ); |
|
901 | + return $this->get('REG_att_is_going'); |
|
902 | 902 | } |
903 | 903 | |
904 | 904 | |
@@ -908,8 +908,8 @@ discard block |
||
908 | 908 | * @param array $query_params like EEM_Base::get_all |
909 | 909 | * @return EE_Answer[] |
910 | 910 | */ |
911 | - public function answers( $query_params = NULL ) { |
|
912 | - return $this->get_many_related( 'Answer', $query_params ); |
|
911 | + public function answers($query_params = NULL) { |
|
912 | + return $this->get_many_related('Answer', $query_params); |
|
913 | 913 | } |
914 | 914 | |
915 | 915 | |
@@ -923,9 +923,9 @@ discard block |
||
923 | 923 | * (because the answer might be an array of answer values, so passing pretty_value=true |
924 | 924 | * will convert it into some kind of string) |
925 | 925 | */ |
926 | - public function answer_value_to_question( $question, $pretty_value=true ) { |
|
926 | + public function answer_value_to_question($question, $pretty_value = true) { |
|
927 | 927 | $question_id = EEM_Question::instance()->ensure_is_ID($question); |
928 | - return EEM_Answer::instance()->get_answer_value_to_question($this,$question_id,$pretty_value); |
|
928 | + return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value); |
|
929 | 929 | } |
930 | 930 | |
931 | 931 | |
@@ -938,13 +938,13 @@ discard block |
||
938 | 938 | */ |
939 | 939 | public function question_groups() { |
940 | 940 | $question_groups = array(); |
941 | - if ( $this->event() instanceof EE_Event ) { |
|
941 | + if ($this->event() instanceof EE_Event) { |
|
942 | 942 | $question_groups = $this->event()->question_groups( |
943 | 943 | array( |
944 | 944 | array( |
945 | 945 | 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false |
946 | 946 | ), |
947 | - 'order_by' => array( 'QSG_order' => 'ASC' ) |
|
947 | + 'order_by' => array('QSG_order' => 'ASC') |
|
948 | 948 | ) |
949 | 949 | ); |
950 | 950 | } |
@@ -961,7 +961,7 @@ discard block |
||
961 | 961 | */ |
962 | 962 | public function count_question_groups() { |
963 | 963 | $qg_count = 0; |
964 | - if ( $this->event() instanceof EE_Event ) { |
|
964 | + if ($this->event() instanceof EE_Event) { |
|
965 | 965 | $qg_count = $this->event()->count_related( |
966 | 966 | 'Question_Group', |
967 | 967 | array( |
@@ -982,7 +982,7 @@ discard block |
||
982 | 982 | * @return string |
983 | 983 | */ |
984 | 984 | public function reg_date() { |
985 | - return $this->get_datetime( 'REG_date' ); |
|
985 | + return $this->get_datetime('REG_date'); |
|
986 | 986 | } |
987 | 987 | |
988 | 988 | |
@@ -994,7 +994,7 @@ discard block |
||
994 | 994 | * @return EE_Datetime_Ticket |
995 | 995 | */ |
996 | 996 | public function datetime_ticket() { |
997 | - return $this->get_first_related( 'Datetime_Ticket' ); |
|
997 | + return $this->get_first_related('Datetime_Ticket'); |
|
998 | 998 | } |
999 | 999 | |
1000 | 1000 | |
@@ -1004,15 +1004,15 @@ discard block |
||
1004 | 1004 | * @param EE_Datetime_Ticket $datetime_ticket |
1005 | 1005 | * @return EE_Datetime_Ticket |
1006 | 1006 | */ |
1007 | - public function set_datetime_ticket( $datetime_ticket ) { |
|
1008 | - return $this->_add_relation_to( $datetime_ticket, 'Datetime_Ticket' ); |
|
1007 | + public function set_datetime_ticket($datetime_ticket) { |
|
1008 | + return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket'); |
|
1009 | 1009 | } |
1010 | 1010 | /** |
1011 | 1011 | * Gets deleted |
1012 | 1012 | * @return boolean |
1013 | 1013 | */ |
1014 | 1014 | public function deleted() { |
1015 | - return $this->get( 'REG_deleted' ); |
|
1015 | + return $this->get('REG_deleted'); |
|
1016 | 1016 | } |
1017 | 1017 | |
1018 | 1018 | /** |
@@ -1021,7 +1021,7 @@ discard block |
||
1021 | 1021 | * @return boolean |
1022 | 1022 | */ |
1023 | 1023 | public function set_deleted($deleted) { |
1024 | - if ( $deleted ) { |
|
1024 | + if ($deleted) { |
|
1025 | 1025 | $this->delete(); |
1026 | 1026 | } else { |
1027 | 1027 | $this->restore(); |
@@ -1035,7 +1035,7 @@ discard block |
||
1035 | 1035 | * @return EE_Status |
1036 | 1036 | */ |
1037 | 1037 | public function status_obj() { |
1038 | - return $this->get_first_related( 'Status' ); |
|
1038 | + return $this->get_first_related('Status'); |
|
1039 | 1039 | } |
1040 | 1040 | |
1041 | 1041 | |
@@ -1046,7 +1046,7 @@ discard block |
||
1046 | 1046 | * @return int |
1047 | 1047 | */ |
1048 | 1048 | public function count_checkins() { |
1049 | - return $this->get_model()->count_related( $this, 'Checkin' ); |
|
1049 | + return $this->get_model()->count_related($this, 'Checkin'); |
|
1050 | 1050 | } |
1051 | 1051 | |
1052 | 1052 | |
@@ -1056,7 +1056,7 @@ discard block |
||
1056 | 1056 | * @return int |
1057 | 1057 | */ |
1058 | 1058 | public function count_checkins_not_checkedout() { |
1059 | - return $this->get_model()->count_related( $this, 'Checkin', array( array( 'CHK_in' => 1 ) ) ); |
|
1059 | + return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1))); |
|
1060 | 1060 | } |
1061 | 1061 | |
1062 | 1062 | |
@@ -1069,20 +1069,20 @@ discard block |
||
1069 | 1069 | * |
1070 | 1070 | * @return bool |
1071 | 1071 | */ |
1072 | - public function can_checkin( $DTT_OR_ID, $check_approved = TRUE ) { |
|
1073 | - $DTT_ID = EEM_Datetime::instance()->ensure_is_ID( $DTT_OR_ID ); |
|
1072 | + public function can_checkin($DTT_OR_ID, $check_approved = TRUE) { |
|
1073 | + $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
1074 | 1074 | |
1075 | 1075 | //first check registration status |
1076 | - if ( ( $check_approved && ! $this->is_approved() ) || ! $DTT_ID ) { |
|
1076 | + if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) { |
|
1077 | 1077 | return false; |
1078 | 1078 | } |
1079 | 1079 | //is there a datetime ticket that matches this dtt_ID? |
1080 | - if ( ! ( EEM_Datetime_Ticket::instance()->exists( array( array( 'TKT_ID' => $this->get('TKT_ID' ), 'DTT_ID' => $DTT_ID ) ) ) ) ) { |
|
1080 | + if ( ! (EEM_Datetime_Ticket::instance()->exists(array(array('TKT_ID' => $this->get('TKT_ID'), 'DTT_ID' => $DTT_ID))))) { |
|
1081 | 1081 | return false; |
1082 | 1082 | } |
1083 | 1083 | |
1084 | 1084 | //final check is against TKT_uses |
1085 | - return $this->verify_can_checkin_against_TKT_uses( $DTT_ID ); |
|
1085 | + return $this->verify_can_checkin_against_TKT_uses($DTT_ID); |
|
1086 | 1086 | } |
1087 | 1087 | |
1088 | 1088 | |
@@ -1095,10 +1095,10 @@ discard block |
||
1095 | 1095 | * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
1096 | 1096 | * @return bool true means can checkin. false means cannot checkin. |
1097 | 1097 | */ |
1098 | - public function verify_can_checkin_against_TKT_uses( $DTT_OR_ID ) { |
|
1099 | - $DTT_ID = EEM_Datetime::instance()->ensure_is_ID( $DTT_OR_ID ); |
|
1098 | + public function verify_can_checkin_against_TKT_uses($DTT_OR_ID) { |
|
1099 | + $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
1100 | 1100 | |
1101 | - if ( ! $DTT_ID ) { |
|
1101 | + if ( ! $DTT_ID) { |
|
1102 | 1102 | return false; |
1103 | 1103 | } |
1104 | 1104 | |
@@ -1106,23 +1106,23 @@ discard block |
||
1106 | 1106 | |
1107 | 1107 | // if max uses is not set or equals infinity then return true cause its not a factor for whether user can check-in |
1108 | 1108 | // or not. |
1109 | - if ( ! $max_uses || $max_uses === EE_INF ) { |
|
1109 | + if ( ! $max_uses || $max_uses === EE_INF) { |
|
1110 | 1110 | return true; |
1111 | 1111 | } |
1112 | 1112 | |
1113 | 1113 | //does this datetime have a checkin record? If so, then the dtt count has already been verified so we can just |
1114 | 1114 | //go ahead and toggle. |
1115 | - if ( EEM_Checkin::instance()->exists( array( array( 'REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID ) ) ) ) { |
|
1115 | + if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) { |
|
1116 | 1116 | return true; |
1117 | 1117 | } |
1118 | 1118 | |
1119 | 1119 | //made it here so the last check is whether the number of checkins per unique datetime on this registration |
1120 | 1120 | //disallows further check-ins. |
1121 | - $count_unique_dtt_checkins = EEM_Checkin::instance()->count( array( array( 'REG_ID' => $this->ID(), 'CHK_in' => true ) ), 'DTT_ID', true ); |
|
1121 | + $count_unique_dtt_checkins = EEM_Checkin::instance()->count(array(array('REG_ID' => $this->ID(), 'CHK_in' => true)), 'DTT_ID', true); |
|
1122 | 1122 | // checkins have already reached their max number of uses |
1123 | 1123 | // so registrant can NOT checkin |
1124 | - if ( $count_unique_dtt_checkins >= $max_uses ) { |
|
1125 | - EE_Error::add_error( __( 'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
1124 | + if ($count_unique_dtt_checkins >= $max_uses) { |
|
1125 | + EE_Error::add_error(__('Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
1126 | 1126 | return false; |
1127 | 1127 | } |
1128 | 1128 | return true; |
@@ -1144,15 +1144,15 @@ discard block |
||
1144 | 1144 | * @return bool|int the chk_in status toggled to OR false if nothing got changed. |
1145 | 1145 | * @throws EE_Error |
1146 | 1146 | */ |
1147 | - public function toggle_checkin_status( $DTT_ID = null, $verify = false ) { |
|
1148 | - if ( empty( $DTT_ID ) ) { |
|
1147 | + public function toggle_checkin_status($DTT_ID = null, $verify = false) { |
|
1148 | + if (empty($DTT_ID)) { |
|
1149 | 1149 | $datetime = $this->get_latest_related_datetime(); |
1150 | 1150 | $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; |
1151 | 1151 | // verify the registration can checkin for the given DTT_ID |
1152 | - } elseif ( ! $this->can_checkin( $DTT_ID, $verify ) ) { |
|
1152 | + } elseif ( ! $this->can_checkin($DTT_ID, $verify)) { |
|
1153 | 1153 | EE_Error::add_error( |
1154 | 1154 | sprintf( |
1155 | - __( 'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', 'event_espresso'), |
|
1155 | + __('The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', 'event_espresso'), |
|
1156 | 1156 | $this->ID(), |
1157 | 1157 | $DTT_ID |
1158 | 1158 | ), |
@@ -1166,8 +1166,8 @@ discard block |
||
1166 | 1166 | EE_Registration::checkin_status_out => EE_Registration::checkin_status_in |
1167 | 1167 | ); |
1168 | 1168 | //start by getting the current status so we know what status we'll be changing to. |
1169 | - $cur_status = $this->check_in_status_for_datetime( $DTT_ID, NULL ); |
|
1170 | - $status_to = $status_paths[ $cur_status ]; |
|
1169 | + $cur_status = $this->check_in_status_for_datetime($DTT_ID, NULL); |
|
1170 | + $status_to = $status_paths[$cur_status]; |
|
1171 | 1171 | // database only records true for checked IN or false for checked OUT |
1172 | 1172 | // no record ( null ) means checked in NEVER, but we obviously don't save that |
1173 | 1173 | $new_status = $status_to === EE_Registration::checkin_status_in ? true : false; |
@@ -1175,24 +1175,24 @@ discard block |
||
1175 | 1175 | // because we are keeping track of Check-ins over time. |
1176 | 1176 | // Eventually we'll probably want to show a list table |
1177 | 1177 | // for the individual Check-ins so that they can be managed. |
1178 | - $checkin = EE_Checkin::new_instance( array( |
|
1178 | + $checkin = EE_Checkin::new_instance(array( |
|
1179 | 1179 | 'REG_ID' => $this->ID(), |
1180 | 1180 | 'DTT_ID' => $DTT_ID, |
1181 | 1181 | 'CHK_in' => $new_status |
1182 | - ) ); |
|
1182 | + )); |
|
1183 | 1183 | // if the record could not be saved then return false |
1184 | - if ( $checkin->save() === 0 ) { |
|
1185 | - if ( WP_DEBUG ) { |
|
1184 | + if ($checkin->save() === 0) { |
|
1185 | + if (WP_DEBUG) { |
|
1186 | 1186 | global $wpdb; |
1187 | 1187 | $error = sprintf( |
1188 | - __( 'Registration check in update failed because of the following database error: %1$s%2$s', 'event_espresso' ), |
|
1188 | + __('Registration check in update failed because of the following database error: %1$s%2$s', 'event_espresso'), |
|
1189 | 1189 | '<br />', |
1190 | 1190 | $wpdb->last_error |
1191 | 1191 | ); |
1192 | 1192 | } else { |
1193 | - $error = __( 'Registration check in update failed because of an unknown database error', 'event_espresso' ); |
|
1193 | + $error = __('Registration check in update failed because of an unknown database error', 'event_espresso'); |
|
1194 | 1194 | } |
1195 | - EE_Error::add_error( $error, __FILE__, __FUNCTION__, __LINE__ ); |
|
1195 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
1196 | 1196 | return false; |
1197 | 1197 | } |
1198 | 1198 | return $status_to; |
@@ -1213,7 +1213,7 @@ discard block |
||
1213 | 1213 | array( |
1214 | 1214 | 'Ticket.Registration.REG_ID' => $this->ID() |
1215 | 1215 | ), |
1216 | - 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) |
|
1216 | + 'order_by' => array('DTT_EVT_start' => 'DESC') |
|
1217 | 1217 | ) |
1218 | 1218 | ); |
1219 | 1219 | } |
@@ -1232,7 +1232,7 @@ discard block |
||
1232 | 1232 | array( |
1233 | 1233 | 'Ticket.Registration.REG_ID' => $this->ID() |
1234 | 1234 | ), |
1235 | - 'order_by' => array( 'DTT_EVT_start' => 'ASC' ) |
|
1235 | + 'order_by' => array('DTT_EVT_start' => 'ASC') |
|
1236 | 1236 | ) |
1237 | 1237 | ); |
1238 | 1238 | } |
@@ -1251,21 +1251,21 @@ discard block |
||
1251 | 1251 | * @return int Integer representing Check-in status. |
1252 | 1252 | * @throws \EE_Error |
1253 | 1253 | */ |
1254 | - public function check_in_status_for_datetime( $DTT_ID = 0, $checkin = null ) { |
|
1254 | + public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null) { |
|
1255 | 1255 | $checkin_query_params = array( |
1256 | - 'order_by' => array( 'CHK_timestamp' => 'DESC' ) |
|
1256 | + 'order_by' => array('CHK_timestamp' => 'DESC') |
|
1257 | 1257 | ); |
1258 | 1258 | |
1259 | - if ( $DTT_ID > 0 ) { |
|
1260 | - $checkin_query_params[0] = array( 'DTT_ID' => $DTT_ID ); |
|
1259 | + if ($DTT_ID > 0) { |
|
1260 | + $checkin_query_params[0] = array('DTT_ID' => $DTT_ID); |
|
1261 | 1261 | } |
1262 | 1262 | |
1263 | 1263 | //get checkin object (if exists) |
1264 | 1264 | $checkin = $checkin instanceof EE_Checkin |
1265 | 1265 | ? $checkin |
1266 | - : $this->get_first_related( 'Checkin', $checkin_query_params ); |
|
1267 | - if ( $checkin instanceof EE_Checkin ) { |
|
1268 | - if ( $checkin->get( 'CHK_in' ) ) { |
|
1266 | + : $this->get_first_related('Checkin', $checkin_query_params); |
|
1267 | + if ($checkin instanceof EE_Checkin) { |
|
1268 | + if ($checkin->get('CHK_in')) { |
|
1269 | 1269 | return EE_Registration::checkin_status_in; //checked in |
1270 | 1270 | } |
1271 | 1271 | return EE_Registration::checkin_status_out; //had checked in but is now checked out. |
@@ -1281,28 +1281,28 @@ discard block |
||
1281 | 1281 | * @param bool $error This just flags that you want an error message returned. This is put in so that the error message can be customized with the attendee name. |
1282 | 1282 | * @return string internationalized message |
1283 | 1283 | */ |
1284 | - public function get_checkin_msg( $DTT_ID, $error = FALSE ) { |
|
1284 | + public function get_checkin_msg($DTT_ID, $error = FALSE) { |
|
1285 | 1285 | //let's get the attendee first so we can include the name of the attendee |
1286 | - $attendee = $this->get_first_related( 'Attendee' ); |
|
1287 | - if ( $attendee instanceof EE_Attendee ) { |
|
1288 | - if ( $error ) { |
|
1289 | - return sprintf( __( "%s's check-in status was not changed.", "event_espresso" ), $attendee->full_name() ); |
|
1286 | + $attendee = $this->get_first_related('Attendee'); |
|
1287 | + if ($attendee instanceof EE_Attendee) { |
|
1288 | + if ($error) { |
|
1289 | + return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name()); |
|
1290 | 1290 | } |
1291 | - $cur_status = $this->check_in_status_for_datetime( $DTT_ID ); |
|
1291 | + $cur_status = $this->check_in_status_for_datetime($DTT_ID); |
|
1292 | 1292 | //what is the status message going to be? |
1293 | - switch ( $cur_status ) { |
|
1293 | + switch ($cur_status) { |
|
1294 | 1294 | case EE_Registration::checkin_status_never : |
1295 | - return sprintf( __( "%s has been removed from Check-in records", "event_espresso" ), $attendee->full_name() ); |
|
1295 | + return sprintf(__("%s has been removed from Check-in records", "event_espresso"), $attendee->full_name()); |
|
1296 | 1296 | break; |
1297 | 1297 | case EE_Registration::checkin_status_in : |
1298 | - return sprintf( __( '%s has been checked in', 'event_espresso' ), $attendee->full_name() ); |
|
1298 | + return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name()); |
|
1299 | 1299 | break; |
1300 | 1300 | case EE_Registration::checkin_status_out : |
1301 | - return sprintf( __( '%s has been checked out', 'event_espresso' ), $attendee->full_name() ); |
|
1301 | + return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name()); |
|
1302 | 1302 | break; |
1303 | 1303 | } |
1304 | 1304 | } |
1305 | - return __( "The check-in status could not be determined.", "event_espresso" ); |
|
1305 | + return __("The check-in status could not be determined.", "event_espresso"); |
|
1306 | 1306 | } |
1307 | 1307 | |
1308 | 1308 | |
@@ -1326,7 +1326,7 @@ discard block |
||
1326 | 1326 | * get Registration Code |
1327 | 1327 | */ |
1328 | 1328 | public function reg_code() { |
1329 | - return $this->get( 'REG_code' ); |
|
1329 | + return $this->get('REG_code'); |
|
1330 | 1330 | } |
1331 | 1331 | |
1332 | 1332 | |
@@ -1335,7 +1335,7 @@ discard block |
||
1335 | 1335 | * get Transaction ID |
1336 | 1336 | */ |
1337 | 1337 | public function transaction_ID() { |
1338 | - return $this->get( 'TXN_ID' ); |
|
1338 | + return $this->get('TXN_ID'); |
|
1339 | 1339 | } |
1340 | 1340 | |
1341 | 1341 | |
@@ -1344,7 +1344,7 @@ discard block |
||
1344 | 1344 | * @return int |
1345 | 1345 | */ |
1346 | 1346 | public function ticket_ID() { |
1347 | - return $this->get( 'TKT_ID' ); |
|
1347 | + return $this->get('TKT_ID'); |
|
1348 | 1348 | } |
1349 | 1349 | |
1350 | 1350 | |
@@ -1356,17 +1356,17 @@ discard block |
||
1356 | 1356 | * @param string $REG_code Registration Code |
1357 | 1357 | * @param boolean $use_default |
1358 | 1358 | */ |
1359 | - public function set_reg_code( $REG_code, $use_default = FALSE ) { |
|
1360 | - if ( empty( $REG_code )) { |
|
1361 | - EE_Error::add_error( __( 'REG_code can not be empty.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
1359 | + public function set_reg_code($REG_code, $use_default = FALSE) { |
|
1360 | + if (empty($REG_code)) { |
|
1361 | + EE_Error::add_error(__('REG_code can not be empty.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
1362 | 1362 | return; |
1363 | 1363 | } |
1364 | - if ( ! $this->reg_code() ) { |
|
1365 | - parent::set( 'REG_code', $REG_code, $use_default ); |
|
1364 | + if ( ! $this->reg_code()) { |
|
1365 | + parent::set('REG_code', $REG_code, $use_default); |
|
1366 | 1366 | } else { |
1367 | 1367 | EE_Error::doing_it_wrong( |
1368 | - __CLASS__ . '::' . __FUNCTION__, |
|
1369 | - __( 'Can not change a registration REG_code once it has been set.', 'event_espresso' ), |
|
1368 | + __CLASS__.'::'.__FUNCTION__, |
|
1369 | + __('Can not change a registration REG_code once it has been set.', 'event_espresso'), |
|
1370 | 1370 | '4.6.0' |
1371 | 1371 | ); |
1372 | 1372 | } |
@@ -1386,17 +1386,17 @@ discard block |
||
1386 | 1386 | * @return EE_Registration[] or empty array if this isn't a group registration. |
1387 | 1387 | */ |
1388 | 1388 | public function get_all_other_registrations_in_group() { |
1389 | - if ( $this->group_size() < 2 ) { |
|
1389 | + if ($this->group_size() < 2) { |
|
1390 | 1390 | return array(); |
1391 | 1391 | } |
1392 | 1392 | |
1393 | 1393 | $query[0] = array( |
1394 | 1394 | 'TXN_ID' => $this->transaction_ID(), |
1395 | - 'REG_ID' => array( '!=', $this->ID() ), |
|
1395 | + 'REG_ID' => array('!=', $this->ID()), |
|
1396 | 1396 | 'TKT_ID' => $this->ticket_ID() |
1397 | 1397 | ); |
1398 | 1398 | |
1399 | - $registrations = $this->get_model()->get_all( $query ); |
|
1399 | + $registrations = $this->get_model()->get_all($query); |
|
1400 | 1400 | return $registrations; |
1401 | 1401 | } |
1402 | 1402 | |
@@ -1405,14 +1405,14 @@ discard block |
||
1405 | 1405 | * @return string |
1406 | 1406 | */ |
1407 | 1407 | public function get_admin_details_link() { |
1408 | - EE_Registry::instance()->load_helper( 'URL' ); |
|
1408 | + EE_Registry::instance()->load_helper('URL'); |
|
1409 | 1409 | return EEH_URL::add_query_args_and_nonce( |
1410 | 1410 | array( |
1411 | 1411 | 'page' => 'espresso_registrations', |
1412 | 1412 | 'action' => 'view_registration', |
1413 | 1413 | '_REG_ID' => $this->ID() |
1414 | 1414 | ), |
1415 | - admin_url( 'admin.php' ) |
|
1415 | + admin_url('admin.php') |
|
1416 | 1416 | ); |
1417 | 1417 | } |
1418 | 1418 | |
@@ -1437,12 +1437,12 @@ discard block |
||
1437 | 1437 | * @return string |
1438 | 1438 | */ |
1439 | 1439 | public function get_admin_overview_link() { |
1440 | - EE_Registry::instance()->load_helper( 'URL' ); |
|
1440 | + EE_Registry::instance()->load_helper('URL'); |
|
1441 | 1441 | return EEH_URL::add_query_args_and_nonce( |
1442 | 1442 | array( |
1443 | 1443 | 'page' => 'espresso_registrations' |
1444 | 1444 | ), |
1445 | - admin_url( 'admin.php' ) |
|
1445 | + admin_url('admin.php') |
|
1446 | 1446 | ); |
1447 | 1447 | } |
1448 | 1448 | |
@@ -1453,8 +1453,8 @@ discard block |
||
1453 | 1453 | * @return \EE_Registration[] |
1454 | 1454 | * @throws \EE_Error |
1455 | 1455 | */ |
1456 | - public function payments( $query_params = array() ) { |
|
1457 | - return $this->get_many_related( 'Payment', $query_params ); |
|
1456 | + public function payments($query_params = array()) { |
|
1457 | + return $this->get_many_related('Payment', $query_params); |
|
1458 | 1458 | } |
1459 | 1459 | |
1460 | 1460 | |
@@ -1464,8 +1464,8 @@ discard block |
||
1464 | 1464 | * @return \EE_Registration_Payment[] |
1465 | 1465 | * @throws \EE_Error |
1466 | 1466 | */ |
1467 | - public function registration_payments( $query_params = array() ) { |
|
1468 | - return $this->get_many_related( 'Registration_Payment', $query_params ); |
|
1467 | + public function registration_payments($query_params = array()) { |
|
1468 | + return $this->get_many_related('Registration_Payment', $query_params); |
|
1469 | 1469 | } |
1470 | 1470 | |
1471 | 1471 | |
@@ -1478,7 +1478,7 @@ discard block |
||
1478 | 1478 | * @return EE_Payment_Method|null |
1479 | 1479 | */ |
1480 | 1480 | public function payment_method() { |
1481 | - return EEM_Payment_Method::instance()->get_last_used_for_registration( $this ); |
|
1481 | + return EEM_Payment_Method::instance()->get_last_used_for_registration($this); |
|
1482 | 1482 | } |
1483 | 1483 | |
1484 | 1484 | |
@@ -1525,7 +1525,7 @@ discard block |
||
1525 | 1525 | */ |
1526 | 1526 | public function delete() |
1527 | 1527 | { |
1528 | - if($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) { |
|
1528 | + if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) { |
|
1529 | 1529 | $this->set_status(EEM_Registration::status_id_cancelled); |
1530 | 1530 | } |
1531 | 1531 | return parent::delete(); |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | * |
471 | 471 | * @access protected |
472 | 472 | * @param \EE_Payment_Method $payment_method |
473 | - * @return \EE_Form_Section_Proper |
|
473 | + * @return EE_Form_Section_HTML |
|
474 | 474 | */ |
475 | 475 | protected function _pci_dss_compliance(EE_Payment_Method $payment_method) |
476 | 476 | { |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | * |
507 | 507 | * @access protected |
508 | 508 | * @param \EE_Payment_Method $payment_method |
509 | - * @return \EE_Form_Section_Proper |
|
509 | + * @return EE_Form_Section_HTML |
|
510 | 510 | */ |
511 | 511 | protected function _currency_support(EE_Payment_Method $payment_method) |
512 | 512 | { |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | * |
542 | 542 | * @access protected |
543 | 543 | * @param \EE_Payment_Method $payment_method |
544 | - * @return \EE_Form_Section_HTML |
|
544 | + * @return EE_Payment_Method_Form |
|
545 | 545 | */ |
546 | 546 | protected function _payment_method_settings(EE_Payment_Method $payment_method) |
547 | 547 | { |
@@ -615,7 +615,7 @@ discard block |
||
615 | 615 | * |
616 | 616 | * @access protected |
617 | 617 | * @param \EE_Payment_Method $payment_method |
618 | - * @return \EE_Form_Section_Proper |
|
618 | + * @return EE_Form_Section_HTML |
|
619 | 619 | */ |
620 | 620 | protected function _deactivate_payment_method_button(EE_Payment_Method $payment_method) |
621 | 621 | { |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('NO direct script access allowed'); |
|
3 | + exit('NO direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -27,838 +27,838 @@ discard block |
||
27 | 27 | class Payments_Admin_Page extends EE_Admin_Page |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * Variables used for when we're re-sorting the logs results, in case |
|
32 | - * we needed to do two queries and we need to resort |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - private $_sort_logs_again_direction; |
|
37 | - |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * @Constructor |
|
42 | - * @access public |
|
43 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
44 | - * @return \Payments_Admin_Page |
|
45 | - */ |
|
46 | - public function __construct($routing = true) |
|
47 | - { |
|
48 | - parent::__construct($routing); |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - |
|
53 | - protected function _init_page_props() |
|
54 | - { |
|
55 | - $this->page_slug = EE_PAYMENTS_PG_SLUG; |
|
56 | - $this->page_label = __('Payment Methods', 'event_espresso'); |
|
57 | - $this->_admin_base_url = EE_PAYMENTS_ADMIN_URL; |
|
58 | - $this->_admin_base_path = EE_PAYMENTS_ADMIN; |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - |
|
63 | - protected function _ajax_hooks() |
|
64 | - { |
|
65 | - //todo: all hooks for ajax goes here. |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - |
|
70 | - protected function _define_page_props() |
|
71 | - { |
|
72 | - $this->_admin_page_title = $this->page_label; |
|
73 | - $this->_labels = array( |
|
74 | - 'publishbox' => __('Update Settings', 'event_espresso'), |
|
75 | - ); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - |
|
80 | - protected function _set_page_routes() |
|
81 | - { |
|
82 | - /** |
|
83 | - * note that with payment method capabilities, although we've implemented |
|
84 | - * capability mapping which will be used for accessing payment methods owned by |
|
85 | - * other users. This is not fully implemented yet in the payment method ui. |
|
86 | - * Currently only the "plural" caps are in active use. |
|
87 | - * When cap mapping is implemented, some routes will need to use the singular form of |
|
88 | - * capability method and also include the $id of the payment method for the route. |
|
89 | - **/ |
|
90 | - $this->_page_routes = array( |
|
91 | - 'default' => array( |
|
92 | - 'func' => '_payment_methods_list', |
|
93 | - 'capability' => 'ee_edit_payment_methods', |
|
94 | - ), |
|
95 | - 'payment_settings' => array( |
|
96 | - 'func' => '_payment_settings', |
|
97 | - 'capability' => 'ee_manage_gateways', |
|
98 | - ), |
|
99 | - 'activate_payment_method' => array( |
|
100 | - 'func' => '_activate_payment_method', |
|
101 | - 'noheader' => true, |
|
102 | - 'capability' => 'ee_edit_payment_methods', |
|
103 | - ), |
|
104 | - 'deactivate_payment_method' => array( |
|
105 | - 'func' => '_deactivate_payment_method', |
|
106 | - 'noheader' => true, |
|
107 | - 'capability' => 'ee_delete_payment_methods', |
|
108 | - ), |
|
109 | - 'update_payment_method' => array( |
|
110 | - 'func' => '_update_payment_method', |
|
111 | - 'noheader' => true, |
|
112 | - 'headers_sent_route' => 'default', |
|
113 | - 'capability' => 'ee_edit_payment_methods', |
|
114 | - ), |
|
115 | - 'update_payment_settings' => array( |
|
116 | - 'func' => '_update_payment_settings', |
|
117 | - 'noheader' => true, |
|
118 | - 'capability' => 'ee_manage_gateways', |
|
119 | - ), |
|
120 | - 'payment_log' => array( |
|
121 | - 'func' => '_payment_log_overview_list_table', |
|
122 | - 'capability' => 'ee_read_payment_methods', |
|
123 | - ), |
|
124 | - 'payment_log_details' => array( |
|
125 | - 'func' => '_payment_log_details', |
|
126 | - 'capability' => 'ee_read_payment_methods', |
|
127 | - ), |
|
128 | - ); |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - |
|
133 | - protected function _set_page_config() |
|
134 | - { |
|
135 | - $payment_method_list_config = array( |
|
136 | - 'nav' => array( |
|
137 | - 'label' => __('Payment Methods', 'event_espresso'), |
|
138 | - 'order' => 10, |
|
139 | - ), |
|
140 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
141 | - 'help_tabs' => array_merge( |
|
142 | - array( |
|
143 | - 'payment_methods_overview_help_tab' => array( |
|
144 | - 'title' => __('Payment Methods Overview', 'event_espresso'), |
|
145 | - 'filename' => 'payment_methods_overview', |
|
146 | - ), |
|
147 | - ), |
|
148 | - $this->_add_payment_method_help_tabs()), |
|
149 | - 'help_tour' => array('Payment_Methods_Selection_Help_Tour'), |
|
150 | - 'require_nonce' => false, |
|
151 | - ); |
|
152 | - $this->_page_config = array( |
|
153 | - 'default' => $payment_method_list_config, |
|
154 | - 'payment_settings' => array( |
|
155 | - 'nav' => array( |
|
156 | - 'label' => __('Settings', 'event_espresso'), |
|
157 | - 'order' => 20, |
|
158 | - ), |
|
159 | - 'help_tabs' => array( |
|
160 | - 'payment_methods_settings_help_tab' => array( |
|
161 | - 'title' => __('Payment Method Settings', 'event_espresso'), |
|
162 | - 'filename' => 'payment_methods_settings', |
|
163 | - ), |
|
164 | - ), |
|
165 | - //'help_tour' => array( 'Payment_Methods_Settings_Help_Tour' ), |
|
166 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
167 | - 'require_nonce' => false, |
|
168 | - ), |
|
169 | - 'payment_log' => array( |
|
170 | - 'nav' => array( |
|
171 | - 'label' => __("Logs", 'event_espresso'), |
|
172 | - 'order' => 30, |
|
173 | - ), |
|
174 | - 'list_table' => 'Payment_Log_Admin_List_Table', |
|
175 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
176 | - 'require_nonce' => false, |
|
177 | - ), |
|
178 | - ); |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * @return array |
|
185 | - */ |
|
186 | - protected function _add_payment_method_help_tabs() |
|
187 | - { |
|
188 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
189 | - $payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types(); |
|
190 | - $all_pmt_help_tabs_config = array(); |
|
191 | - foreach ($payment_method_types as $payment_method_type) { |
|
192 | - if (! EE_Registry::instance()->CAP->current_user_can($payment_method_type->cap_name(), |
|
193 | - 'specific_payment_method_type_access') |
|
194 | - ) { |
|
195 | - continue; |
|
196 | - } |
|
197 | - foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) { |
|
198 | - $template_args = isset($config['template_args']) ? $config['template_args'] : array(); |
|
199 | - $template_args['admin_page_obj'] = $this; |
|
200 | - $all_pmt_help_tabs_config[$help_tab_name] = array( |
|
201 | - 'title' => $config['title'], |
|
202 | - 'content' => EEH_Template::display_template( |
|
203 | - $payment_method_type->file_folder() . 'help_tabs' . DS . $config['filename'] . '.help_tab.php', |
|
204 | - $template_args, |
|
205 | - true), |
|
206 | - ); |
|
207 | - } |
|
208 | - } |
|
209 | - return $all_pmt_help_tabs_config; |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - |
|
214 | - //none of the below group are currently used for Gateway Settings |
|
215 | - protected function _add_screen_options() |
|
216 | - { |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - |
|
221 | - protected function _add_feature_pointers() |
|
222 | - { |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - |
|
227 | - public function admin_init() |
|
228 | - { |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - |
|
233 | - public function admin_notices() |
|
234 | - { |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - |
|
239 | - public function admin_footer_scripts() |
|
240 | - { |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - |
|
245 | - public function load_scripts_styles() |
|
246 | - { |
|
247 | - wp_enqueue_script('ee_admin_js'); |
|
248 | - wp_enqueue_script('ee-text-links'); |
|
249 | - wp_enqueue_script('espresso_payments', EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js', |
|
250 | - array('espresso-ui-theme', 'ee-datepicker'), EVENT_ESPRESSO_VERSION, true); |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - |
|
255 | - public function load_scripts_styles_default() |
|
256 | - { |
|
257 | - //styles |
|
258 | - wp_register_style('espresso_payments', EE_PAYMENTS_ASSETS_URL . 'ee-payments.css', array(), |
|
259 | - EVENT_ESPRESSO_VERSION); |
|
260 | - wp_enqueue_style('espresso_payments'); |
|
261 | - wp_enqueue_style('ee-text-links'); |
|
262 | - //scripts |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - |
|
267 | - protected function _payment_methods_list() |
|
268 | - { |
|
269 | - /** |
|
270 | - * first let's ensure payment methods have been setup. We do this here because when people activate a |
|
271 | - * payment method for the first time (as an addon), it may not setup its capabilities or get registered correctly due |
|
272 | - * to the loading process. However, people MUST setup the details for the payment method so its safe to do a |
|
273 | - * recheck here. |
|
274 | - */ |
|
275 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
276 | - EEM_Payment_Method::instance()->verify_button_urls(); |
|
277 | - //setup tabs, one for each payment method type |
|
278 | - $tabs = array(); |
|
279 | - $payment_methods = array(); |
|
280 | - foreach (EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj) { |
|
281 | - // we don't want to show admin-only PMTs for now |
|
282 | - if ($pmt_obj instanceof EE_PMT_Admin_Only) { |
|
283 | - continue; |
|
284 | - } |
|
285 | - //check access |
|
286 | - if (! EE_Registry::instance()->CAP->current_user_can($pmt_obj->cap_name(), |
|
287 | - 'specific_payment_method_type_access') |
|
288 | - ) { |
|
289 | - continue; |
|
290 | - } |
|
291 | - //check for any active pms of that type |
|
292 | - $payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name()); |
|
293 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
294 | - $payment_method = EE_Payment_Method::new_instance( |
|
295 | - array( |
|
296 | - 'PMD_slug' => sanitize_key($pmt_obj->system_name()), |
|
297 | - 'PMD_type' => $pmt_obj->system_name(), |
|
298 | - 'PMD_name' => $pmt_obj->pretty_name(), |
|
299 | - 'PMD_admin_name' => $pmt_obj->pretty_name(), |
|
300 | - ) |
|
301 | - ); |
|
302 | - } |
|
303 | - $payment_methods[$payment_method->slug()] = $payment_method; |
|
304 | - } |
|
305 | - $payment_methods = apply_filters('FHEE__Payments_Admin_Page___payment_methods_list__payment_methods', |
|
306 | - $payment_methods); |
|
307 | - foreach ($payment_methods as $payment_method) { |
|
308 | - if ($payment_method instanceof EE_Payment_Method) { |
|
309 | - add_meta_box( |
|
310 | - //html id |
|
311 | - 'espresso_' . $payment_method->slug() . '_payment_settings', |
|
312 | - //title |
|
313 | - sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()), |
|
314 | - //callback |
|
315 | - array($this, 'payment_method_settings_meta_box'), |
|
316 | - //post type |
|
317 | - null, |
|
318 | - //context |
|
319 | - 'normal', |
|
320 | - //priority |
|
321 | - 'default', |
|
322 | - //callback args |
|
323 | - array('payment_method' => $payment_method) |
|
324 | - ); |
|
325 | - //setup for tabbed content |
|
326 | - $tabs[$payment_method->slug()] = array( |
|
327 | - 'label' => $payment_method->admin_name(), |
|
328 | - 'class' => $payment_method->active() ? 'gateway-active' : '', |
|
329 | - 'href' => 'espresso_' . $payment_method->slug() . '_payment_settings', |
|
330 | - 'title' => __('Modify this Payment Method', 'event_espresso'), |
|
331 | - 'slug' => $payment_method->slug(), |
|
332 | - ); |
|
333 | - } |
|
334 | - } |
|
335 | - $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links($tabs, 'payment_method_links', |
|
336 | - '|', $this->_get_active_payment_method_slug()); |
|
337 | - $this->display_admin_page_with_sidebar(); |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * _get_active_payment_method_slug |
|
344 | - * |
|
345 | - * @return string |
|
346 | - */ |
|
347 | - protected function _get_active_payment_method_slug() |
|
348 | - { |
|
349 | - $payment_method_slug = false; |
|
350 | - //decide which payment method tab to open first, as dictated by the request's 'payment_method' |
|
351 | - if (isset($this->_req_data['payment_method'])) { |
|
352 | - // if they provided the current payment method, use it |
|
353 | - $payment_method_slug = sanitize_key($this->_req_data['payment_method']); |
|
354 | - } |
|
355 | - $payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug))); |
|
356 | - // if that didn't work or wasn't provided, find another way to select the current pm |
|
357 | - if (! $this->_verify_payment_method($payment_method)) { |
|
358 | - // like, looking for an active one |
|
359 | - $payment_method = EEM_Payment_Method::instance()->get_one_active('CART'); |
|
360 | - // test that one as well |
|
361 | - if ($this->_verify_payment_method($payment_method)) { |
|
362 | - $payment_method_slug = $payment_method->slug(); |
|
363 | - } else { |
|
364 | - $payment_method_slug = 'paypal_standard'; |
|
365 | - } |
|
366 | - } |
|
367 | - return $payment_method_slug; |
|
368 | - } |
|
369 | - |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * payment_method_settings_meta_box |
|
374 | - * returns TRUE if the passed payment method is properly constructed and the logged in user has the correct |
|
375 | - * capabilities to access it |
|
376 | - * |
|
377 | - * @param \EE_Payment_Method $payment_method |
|
378 | - * @return boolean |
|
379 | - */ |
|
380 | - protected function _verify_payment_method($payment_method) |
|
381 | - { |
|
382 | - if ( |
|
383 | - $payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base |
|
384 | - && EE_Registry::instance()->CAP->current_user_can($payment_method->type_obj()->cap_name(), |
|
385 | - 'specific_payment_method_type_access') |
|
386 | - ) { |
|
387 | - return true; |
|
388 | - } |
|
389 | - return false; |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * payment_method_settings_meta_box |
|
396 | - * |
|
397 | - * @param NULL $post_obj_which_is_null is an object containing the current post (as a $post object) |
|
398 | - * @param array $metabox is an array with metabox id, title, callback, and args elements. the value |
|
399 | - * at 'args' has key 'payment_method', as set within _payment_methods_list |
|
400 | - * @return string |
|
401 | - * @throws EE_Error |
|
402 | - */ |
|
403 | - public function payment_method_settings_meta_box($post_obj_which_is_null, $metabox) |
|
404 | - { |
|
405 | - $payment_method = isset($metabox['args'], $metabox['args']['payment_method']) |
|
406 | - ? $metabox['args']['payment_method'] : null; |
|
407 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
408 | - throw new EE_Error(sprintf(__('Payment method metabox setup incorrectly. No Payment method object was supplied', |
|
409 | - 'event_espresso'))); |
|
410 | - } |
|
411 | - $payment_method_scopes = $payment_method->active(); |
|
412 | - // if the payment method really exists show its form, otherwise the activation template |
|
413 | - if ($payment_method->ID() && ! empty($payment_method_scopes)) { |
|
414 | - $form = $this->_generate_payment_method_settings_form($payment_method); |
|
415 | - if ($form->form_data_present_in($this->_req_data)) { |
|
416 | - $form->receive_form_submission($this->_req_data); |
|
417 | - } |
|
418 | - echo $form->form_open() . $form->get_html_and_js() . $form->form_close(); |
|
419 | - } else { |
|
420 | - echo $this->_activate_payment_method_button($payment_method)->get_html_and_js(); |
|
421 | - } |
|
422 | - } |
|
423 | - |
|
424 | - |
|
425 | - |
|
426 | - /** |
|
427 | - * Gets the form for all the settings related to this payment method type |
|
428 | - * |
|
429 | - * @access protected |
|
430 | - * @param \EE_Payment_Method $payment_method |
|
431 | - * @return \EE_Form_Section_Proper |
|
432 | - */ |
|
433 | - protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method) |
|
434 | - { |
|
435 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
436 | - return new EE_Form_Section_Proper(); |
|
437 | - } |
|
438 | - return new EE_Form_Section_Proper( |
|
439 | - array( |
|
440 | - 'name' => $payment_method->slug() . '_settings_form', |
|
441 | - 'html_id' => $payment_method->slug() . '_settings_form', |
|
442 | - 'action' => EE_Admin_Page::add_query_args_and_nonce( |
|
443 | - array( |
|
444 | - 'action' => 'update_payment_method', |
|
445 | - 'payment_method' => $payment_method->slug(), |
|
446 | - ), |
|
447 | - EE_PAYMENTS_ADMIN_URL |
|
448 | - ), |
|
449 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
450 | - 'subsections' => apply_filters( |
|
451 | - 'FHEE__Payments_Admin_Page___generate_payment_method_settings_form__form_subsections', |
|
452 | - array( |
|
453 | - 'pci_dss_compliance' => $this->_pci_dss_compliance($payment_method), |
|
454 | - 'currency_support' => $this->_currency_support($payment_method), |
|
455 | - 'payment_method_settings' => $this->_payment_method_settings($payment_method), |
|
456 | - 'update' => $this->_update_payment_method_button($payment_method), |
|
457 | - 'deactivate' => $this->_deactivate_payment_method_button($payment_method), |
|
458 | - 'fine_print' => $this->_fine_print(), |
|
459 | - ), |
|
460 | - $payment_method |
|
461 | - ), |
|
462 | - ) |
|
463 | - ); |
|
464 | - } |
|
465 | - |
|
466 | - |
|
467 | - |
|
468 | - /** |
|
469 | - * _pci_dss_compliance |
|
470 | - * |
|
471 | - * @access protected |
|
472 | - * @param \EE_Payment_Method $payment_method |
|
473 | - * @return \EE_Form_Section_Proper |
|
474 | - */ |
|
475 | - protected function _pci_dss_compliance(EE_Payment_Method $payment_method) |
|
476 | - { |
|
477 | - if ($payment_method->type_obj()->requires_https()) { |
|
478 | - return new EE_Form_Section_HTML( |
|
479 | - EEH_HTML::tr( |
|
480 | - EEH_HTML::th( |
|
481 | - EEH_HTML::label( |
|
482 | - EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice') |
|
483 | - ) |
|
484 | - ) . |
|
485 | - EEH_HTML::td( |
|
486 | - EEH_HTML::strong(__('You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.', |
|
487 | - 'event_espresso')) |
|
488 | - . |
|
489 | - EEH_HTML::br() |
|
490 | - . |
|
491 | - __('Learn more about ', 'event_espresso') |
|
492 | - . EEH_HTML::link('https://www.pcisecuritystandards.org/merchants/index.php', |
|
493 | - __('PCI DSS compliance', 'event_espresso')) |
|
494 | - ) |
|
495 | - ) |
|
496 | - ); |
|
497 | - } else { |
|
498 | - return new EE_Form_Section_HTML(''); |
|
499 | - } |
|
500 | - } |
|
501 | - |
|
502 | - |
|
503 | - |
|
504 | - /** |
|
505 | - * _currency_support |
|
506 | - * |
|
507 | - * @access protected |
|
508 | - * @param \EE_Payment_Method $payment_method |
|
509 | - * @return \EE_Form_Section_Proper |
|
510 | - */ |
|
511 | - protected function _currency_support(EE_Payment_Method $payment_method) |
|
512 | - { |
|
513 | - if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) { |
|
514 | - return new EE_Form_Section_HTML( |
|
515 | - EEH_HTML::tr( |
|
516 | - EEH_HTML::th( |
|
517 | - EEH_HTML::label( |
|
518 | - EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice') |
|
519 | - ) |
|
520 | - ) . |
|
521 | - EEH_HTML::td( |
|
522 | - EEH_HTML::strong( |
|
523 | - sprintf( |
|
524 | - __('This payment method does not support the currency set on your site (%1$s). Please activate a different payment method or change your site\'s country and associated currency.', |
|
525 | - 'event_espresso'), |
|
526 | - EE_Config::instance()->currency->code |
|
527 | - ) |
|
528 | - ) |
|
529 | - ) |
|
530 | - ) |
|
531 | - ); |
|
532 | - } else { |
|
533 | - return new EE_Form_Section_HTML(''); |
|
534 | - } |
|
535 | - } |
|
536 | - |
|
537 | - |
|
538 | - |
|
539 | - /** |
|
540 | - * _update_payment_method_button |
|
541 | - * |
|
542 | - * @access protected |
|
543 | - * @param \EE_Payment_Method $payment_method |
|
544 | - * @return \EE_Form_Section_HTML |
|
545 | - */ |
|
546 | - protected function _payment_method_settings(EE_Payment_Method $payment_method) |
|
547 | - { |
|
548 | - //modify the form so we only have/show fields that will be implemented for this version |
|
549 | - return $this->_simplify_form($payment_method->type_obj()->settings_form(), $payment_method->name()); |
|
550 | - } |
|
551 | - |
|
552 | - |
|
553 | - |
|
554 | - /** |
|
555 | - * Simplifies the form to merely reproduce 4.1's gateway settings functionality |
|
556 | - * |
|
557 | - * @param EE_Form_Section_Proper $form_section |
|
558 | - * @param string $payment_method_name |
|
559 | - * @return \EE_Payment_Method_Form |
|
560 | - * @throws \EE_Error |
|
561 | - */ |
|
562 | - protected function _simplify_form($form_section, $payment_method_name = '') |
|
563 | - { |
|
564 | - if ($form_section instanceof EE_Payment_Method_Form) { |
|
565 | - $form_section->exclude( |
|
566 | - array( |
|
567 | - 'PMD_type', //dont want them changing the type |
|
568 | - 'PMD_slug', //or the slug (probably never) |
|
569 | - 'PMD_wp_user', //or the user's ID |
|
570 | - 'Currency' //or the currency, until the rest of EE supports simultaneous currencies |
|
571 | - ) |
|
572 | - ); |
|
573 | - return $form_section; |
|
574 | - } else { |
|
575 | - throw new EE_Error(sprintf(__('The EE_Payment_Method_Form for the "%1$s" payment method is missing or invalid.', |
|
576 | - 'event_espresso'), $payment_method_name)); |
|
577 | - } |
|
578 | - } |
|
579 | - |
|
580 | - |
|
581 | - |
|
582 | - /** |
|
583 | - * _update_payment_method_button |
|
584 | - * |
|
585 | - * @access protected |
|
586 | - * @param \EE_Payment_Method $payment_method |
|
587 | - * @return \EE_Form_Section_HTML |
|
588 | - */ |
|
589 | - protected function _update_payment_method_button(EE_Payment_Method $payment_method) |
|
590 | - { |
|
591 | - $update_button = new EE_Submit_Input( |
|
592 | - array( |
|
593 | - 'name' => 'submit', |
|
594 | - 'html_id' => 'save_' . $payment_method->slug() . '_settings', |
|
595 | - 'default' => sprintf(__('Update %s Payment Settings', 'event_espresso'), |
|
596 | - $payment_method->admin_name()), |
|
597 | - 'html_label' => EEH_HTML::nbsp(), |
|
598 | - ) |
|
599 | - ); |
|
600 | - return new EE_Form_Section_HTML( |
|
601 | - EEH_HTML::no_row(EEH_HTML::br(2)) . |
|
602 | - EEH_HTML::tr( |
|
603 | - EEH_HTML::th(__('Update Settings', 'event_espresso')) . |
|
604 | - EEH_HTML::td( |
|
605 | - $update_button->get_html_for_input() |
|
606 | - ) |
|
607 | - ) |
|
608 | - ); |
|
609 | - } |
|
610 | - |
|
611 | - |
|
612 | - |
|
613 | - /** |
|
614 | - * _deactivate_payment_method_button |
|
615 | - * |
|
616 | - * @access protected |
|
617 | - * @param \EE_Payment_Method $payment_method |
|
618 | - * @return \EE_Form_Section_Proper |
|
619 | - */ |
|
620 | - protected function _deactivate_payment_method_button(EE_Payment_Method $payment_method) |
|
621 | - { |
|
622 | - $link_text_and_title = sprintf(__('Deactivate %1$s Payments?', 'event_espresso'), |
|
623 | - $payment_method->admin_name()); |
|
624 | - return new EE_Form_Section_HTML( |
|
625 | - EEH_HTML::tr( |
|
626 | - EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')) . |
|
627 | - EEH_HTML::td( |
|
628 | - EEH_HTML::link( |
|
629 | - EE_Admin_Page::add_query_args_and_nonce( |
|
630 | - array( |
|
631 | - 'action' => 'deactivate_payment_method', |
|
632 | - 'payment_method' => $payment_method->slug(), |
|
633 | - ), |
|
634 | - EE_PAYMENTS_ADMIN_URL |
|
635 | - ), |
|
636 | - $link_text_and_title, |
|
637 | - $link_text_and_title, |
|
638 | - 'deactivate_' . $payment_method->slug(), |
|
639 | - 'espresso-button button-secondary' |
|
640 | - ) |
|
641 | - ) |
|
642 | - ) |
|
643 | - ); |
|
644 | - } |
|
645 | - |
|
646 | - |
|
647 | - |
|
648 | - /** |
|
649 | - * _activate_payment_method_button |
|
650 | - * |
|
651 | - * @access protected |
|
652 | - * @param \EE_Payment_Method $payment_method |
|
653 | - * @return \EE_Form_Section_Proper |
|
654 | - */ |
|
655 | - protected function _activate_payment_method_button(EE_Payment_Method $payment_method) |
|
656 | - { |
|
657 | - $link_text_and_title = sprintf(__('Activate %1$s Payment Method?', 'event_espresso'), |
|
658 | - $payment_method->admin_name()); |
|
659 | - return new EE_Form_Section_Proper( |
|
660 | - array( |
|
661 | - 'name' => 'activate_' . $payment_method->slug() . '_settings_form', |
|
662 | - 'html_id' => 'activate_' . $payment_method->slug() . '_settings_form', |
|
663 | - 'action' => '#', |
|
664 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
665 | - 'subsections' => apply_filters( |
|
666 | - 'FHEE__Payments_Admin_Page___activate_payment_method_button__form_subsections', |
|
667 | - array( |
|
668 | - new EE_Form_Section_HTML( |
|
669 | - EEH_HTML::tr( |
|
670 | - EEH_HTML::td($payment_method->type_obj()->introductory_html(), |
|
671 | - '', |
|
672 | - '', |
|
673 | - '', |
|
674 | - 'colspan="2"' |
|
675 | - ) |
|
676 | - ) . |
|
677 | - EEH_HTML::tr( |
|
678 | - EEH_HTML::th( |
|
679 | - EEH_HTML::label(__('Click to Activate ', 'event_espresso')) |
|
680 | - ) . |
|
681 | - EEH_HTML::td( |
|
682 | - EEH_HTML::link( |
|
683 | - EE_Admin_Page::add_query_args_and_nonce( |
|
684 | - array( |
|
685 | - 'action' => 'activate_payment_method', |
|
686 | - 'payment_method_type' => $payment_method->type(), |
|
687 | - ), |
|
688 | - EE_PAYMENTS_ADMIN_URL |
|
689 | - ), |
|
690 | - $link_text_and_title, |
|
691 | - $link_text_and_title, |
|
692 | - 'activate_' . $payment_method->slug(), |
|
693 | - 'espresso-button-green button-primary' |
|
694 | - ) |
|
695 | - ) |
|
696 | - ) |
|
697 | - ), |
|
698 | - ), |
|
699 | - $payment_method |
|
700 | - ), |
|
701 | - ) |
|
702 | - ); |
|
703 | - } |
|
704 | - |
|
705 | - |
|
706 | - |
|
707 | - /** |
|
708 | - * _fine_print |
|
709 | - * |
|
710 | - * @access protected |
|
711 | - * @return \EE_Form_Section_HTML |
|
712 | - */ |
|
713 | - protected function _fine_print() |
|
714 | - { |
|
715 | - return new EE_Form_Section_HTML( |
|
716 | - EEH_HTML::tr( |
|
717 | - EEH_HTML::th() . |
|
718 | - EEH_HTML::td( |
|
719 | - EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text') |
|
720 | - ) |
|
721 | - ) |
|
722 | - ); |
|
723 | - } |
|
724 | - |
|
725 | - |
|
726 | - |
|
727 | - /** |
|
728 | - * Activates a payment method of that type. Mostly assuming there is only 1 of that type (or none so far) |
|
729 | - * |
|
730 | - * @global WP_User $current_user |
|
731 | - */ |
|
732 | - protected function _activate_payment_method() |
|
733 | - { |
|
734 | - if (isset($this->_req_data['payment_method_type'])) { |
|
735 | - $payment_method_type = sanitize_text_field($this->_req_data['payment_method_type']); |
|
736 | - //see if one exists |
|
737 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
738 | - $payment_method = EE_Payment_Method_Manager::instance() |
|
739 | - ->activate_a_payment_method_of_type($payment_method_type); |
|
740 | - $this->_redirect_after_action(1, 'Payment Method', 'activated', |
|
741 | - array('action' => 'default', 'payment_method' => $payment_method->slug())); |
|
742 | - } else { |
|
743 | - $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default')); |
|
744 | - } |
|
745 | - } |
|
746 | - |
|
747 | - |
|
748 | - |
|
749 | - /** |
|
750 | - * Deactivates the payment method with the specified slug, and redirects. |
|
751 | - */ |
|
752 | - protected function _deactivate_payment_method() |
|
753 | - { |
|
754 | - if (isset($this->_req_data['payment_method'])) { |
|
755 | - $payment_method_slug = sanitize_key($this->_req_data['payment_method']); |
|
756 | - //deactivate it |
|
757 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
758 | - $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method($payment_method_slug); |
|
759 | - $this->_redirect_after_action($count_updated, 'Payment Method', 'deactivated', |
|
760 | - array('action' => 'default', 'payment_method' => $payment_method_slug)); |
|
761 | - } else { |
|
762 | - $this->_redirect_after_action(false, 'Payment Method', 'deactivated', array('action' => 'default')); |
|
763 | - } |
|
764 | - } |
|
765 | - |
|
766 | - |
|
767 | - |
|
768 | - /** |
|
769 | - * Processes the payment method form that was submitted. This is slightly trickier than usual form |
|
770 | - * processing because we first need to identify WHICH form was processed and which payment method |
|
771 | - * it corresponds to. Once we have done that, we see if the form is valid. If it is, the |
|
772 | - * form's data is saved and we redirect to the default payment methods page, setting the updated payment method |
|
773 | - * as the currently-selected one. If it DOESN'T validate, we render the page with the form's errors (in the |
|
774 | - * subsequently called 'headers_sent_func' which is _payment_methods_list) |
|
775 | - * |
|
776 | - * @return void |
|
777 | - */ |
|
778 | - protected function _update_payment_method() |
|
779 | - { |
|
780 | - if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
781 | - //ok let's find which gateway form to use based on the form input |
|
782 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
783 | - /** @var $correct_pmt_form_to_use EE_Payment_Method_Form */ |
|
784 | - $correct_pmt_form_to_use = null; |
|
785 | - $payment_method = null; |
|
786 | - foreach (EEM_Payment_Method::instance()->get_all() as $payment_method) { |
|
787 | - //get the form and simplify it, like what we do when we display it |
|
788 | - $pmt_form = $this->_generate_payment_method_settings_form($payment_method); |
|
789 | - if ($pmt_form->form_data_present_in($this->_req_data)) { |
|
790 | - $correct_pmt_form_to_use = $pmt_form; |
|
791 | - break; |
|
792 | - } |
|
793 | - } |
|
794 | - //if we couldn't find the correct payment method type... |
|
795 | - if (! $correct_pmt_form_to_use) { |
|
796 | - EE_Error::add_error(__("We could not find which payment method type your form submission related to. Please contact support", |
|
797 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
798 | - $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default')); |
|
799 | - } |
|
800 | - $correct_pmt_form_to_use->receive_form_submission($this->_req_data); |
|
801 | - if ($correct_pmt_form_to_use->is_valid()) { |
|
802 | - $payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings'); |
|
803 | - if (! $payment_settings_subform instanceof EE_Payment_Method_Form) { |
|
804 | - throw new EE_Error( |
|
805 | - sprintf( |
|
806 | - __('The payment method could not be saved because the form sections were misnamed. We expected to find %1$s, but did not.', |
|
807 | - 'event_espresso'), |
|
808 | - 'payment_method_settings' |
|
809 | - ) |
|
810 | - ); |
|
811 | - } |
|
812 | - $payment_settings_subform->save(); |
|
813 | - /** @var $pm EE_Payment_Method */ |
|
814 | - $this->_redirect_after_action(true, 'Payment Method', 'updated', |
|
815 | - array('action' => 'default', 'payment_method' => $payment_method->slug())); |
|
816 | - } else { |
|
817 | - EE_Error::add_error( |
|
818 | - sprintf( |
|
819 | - __('Payment method of type %s was not saved because there were validation errors. They have been marked in the form', |
|
820 | - 'event_espresso'), |
|
821 | - $payment_method instanceof EE_PMT_Base ? $payment_method->pretty_name() |
|
822 | - : __('"(unknown)"', 'event_espresso') |
|
823 | - ), |
|
824 | - __FILE__, |
|
825 | - __FUNCTION__, |
|
826 | - __LINE__ |
|
827 | - ); |
|
828 | - } |
|
829 | - } |
|
830 | - return; |
|
831 | - } |
|
832 | - |
|
833 | - |
|
834 | - |
|
835 | - protected function _payment_settings() |
|
836 | - { |
|
837 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
838 | - $this->_template_args['show_pending_payment_options'] = isset(EE_Registry::instance()->CFG->registration->show_pending_payment_options) |
|
839 | - ? absint(EE_Registry::instance()->CFG->registration->show_pending_payment_options) : false; |
|
840 | - $this->_set_add_edit_form_tags('update_payment_settings'); |
|
841 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
842 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template(EE_PAYMENTS_TEMPLATE_PATH |
|
843 | - . 'payment_settings.template.php', |
|
844 | - $this->_template_args, true); |
|
845 | - $this->display_admin_page_with_sidebar(); |
|
846 | - } |
|
847 | - |
|
848 | - |
|
849 | - |
|
850 | - /** |
|
851 | - * _update_payment_settings |
|
852 | - * |
|
853 | - * @access protected |
|
854 | - * @return array |
|
855 | - */ |
|
856 | - protected function _update_payment_settings() |
|
857 | - { |
|
858 | - EE_Registry::instance()->CFG->registration->show_pending_payment_options = isset($this->_req_data['show_pending_payment_options']) |
|
859 | - ? $this->_req_data['show_pending_payment_options'] : false; |
|
860 | - EE_Registry::instance()->CFG = apply_filters('FHEE__Payments_Admin_Page___update_payment_settings__CFG', |
|
861 | - EE_Registry::instance()->CFG); |
|
30 | + /** |
|
31 | + * Variables used for when we're re-sorting the logs results, in case |
|
32 | + * we needed to do two queries and we need to resort |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + private $_sort_logs_again_direction; |
|
37 | + |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * @Constructor |
|
42 | + * @access public |
|
43 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
44 | + * @return \Payments_Admin_Page |
|
45 | + */ |
|
46 | + public function __construct($routing = true) |
|
47 | + { |
|
48 | + parent::__construct($routing); |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + |
|
53 | + protected function _init_page_props() |
|
54 | + { |
|
55 | + $this->page_slug = EE_PAYMENTS_PG_SLUG; |
|
56 | + $this->page_label = __('Payment Methods', 'event_espresso'); |
|
57 | + $this->_admin_base_url = EE_PAYMENTS_ADMIN_URL; |
|
58 | + $this->_admin_base_path = EE_PAYMENTS_ADMIN; |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + |
|
63 | + protected function _ajax_hooks() |
|
64 | + { |
|
65 | + //todo: all hooks for ajax goes here. |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + |
|
70 | + protected function _define_page_props() |
|
71 | + { |
|
72 | + $this->_admin_page_title = $this->page_label; |
|
73 | + $this->_labels = array( |
|
74 | + 'publishbox' => __('Update Settings', 'event_espresso'), |
|
75 | + ); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + |
|
80 | + protected function _set_page_routes() |
|
81 | + { |
|
82 | + /** |
|
83 | + * note that with payment method capabilities, although we've implemented |
|
84 | + * capability mapping which will be used for accessing payment methods owned by |
|
85 | + * other users. This is not fully implemented yet in the payment method ui. |
|
86 | + * Currently only the "plural" caps are in active use. |
|
87 | + * When cap mapping is implemented, some routes will need to use the singular form of |
|
88 | + * capability method and also include the $id of the payment method for the route. |
|
89 | + **/ |
|
90 | + $this->_page_routes = array( |
|
91 | + 'default' => array( |
|
92 | + 'func' => '_payment_methods_list', |
|
93 | + 'capability' => 'ee_edit_payment_methods', |
|
94 | + ), |
|
95 | + 'payment_settings' => array( |
|
96 | + 'func' => '_payment_settings', |
|
97 | + 'capability' => 'ee_manage_gateways', |
|
98 | + ), |
|
99 | + 'activate_payment_method' => array( |
|
100 | + 'func' => '_activate_payment_method', |
|
101 | + 'noheader' => true, |
|
102 | + 'capability' => 'ee_edit_payment_methods', |
|
103 | + ), |
|
104 | + 'deactivate_payment_method' => array( |
|
105 | + 'func' => '_deactivate_payment_method', |
|
106 | + 'noheader' => true, |
|
107 | + 'capability' => 'ee_delete_payment_methods', |
|
108 | + ), |
|
109 | + 'update_payment_method' => array( |
|
110 | + 'func' => '_update_payment_method', |
|
111 | + 'noheader' => true, |
|
112 | + 'headers_sent_route' => 'default', |
|
113 | + 'capability' => 'ee_edit_payment_methods', |
|
114 | + ), |
|
115 | + 'update_payment_settings' => array( |
|
116 | + 'func' => '_update_payment_settings', |
|
117 | + 'noheader' => true, |
|
118 | + 'capability' => 'ee_manage_gateways', |
|
119 | + ), |
|
120 | + 'payment_log' => array( |
|
121 | + 'func' => '_payment_log_overview_list_table', |
|
122 | + 'capability' => 'ee_read_payment_methods', |
|
123 | + ), |
|
124 | + 'payment_log_details' => array( |
|
125 | + 'func' => '_payment_log_details', |
|
126 | + 'capability' => 'ee_read_payment_methods', |
|
127 | + ), |
|
128 | + ); |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + |
|
133 | + protected function _set_page_config() |
|
134 | + { |
|
135 | + $payment_method_list_config = array( |
|
136 | + 'nav' => array( |
|
137 | + 'label' => __('Payment Methods', 'event_espresso'), |
|
138 | + 'order' => 10, |
|
139 | + ), |
|
140 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
141 | + 'help_tabs' => array_merge( |
|
142 | + array( |
|
143 | + 'payment_methods_overview_help_tab' => array( |
|
144 | + 'title' => __('Payment Methods Overview', 'event_espresso'), |
|
145 | + 'filename' => 'payment_methods_overview', |
|
146 | + ), |
|
147 | + ), |
|
148 | + $this->_add_payment_method_help_tabs()), |
|
149 | + 'help_tour' => array('Payment_Methods_Selection_Help_Tour'), |
|
150 | + 'require_nonce' => false, |
|
151 | + ); |
|
152 | + $this->_page_config = array( |
|
153 | + 'default' => $payment_method_list_config, |
|
154 | + 'payment_settings' => array( |
|
155 | + 'nav' => array( |
|
156 | + 'label' => __('Settings', 'event_espresso'), |
|
157 | + 'order' => 20, |
|
158 | + ), |
|
159 | + 'help_tabs' => array( |
|
160 | + 'payment_methods_settings_help_tab' => array( |
|
161 | + 'title' => __('Payment Method Settings', 'event_espresso'), |
|
162 | + 'filename' => 'payment_methods_settings', |
|
163 | + ), |
|
164 | + ), |
|
165 | + //'help_tour' => array( 'Payment_Methods_Settings_Help_Tour' ), |
|
166 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
167 | + 'require_nonce' => false, |
|
168 | + ), |
|
169 | + 'payment_log' => array( |
|
170 | + 'nav' => array( |
|
171 | + 'label' => __("Logs", 'event_espresso'), |
|
172 | + 'order' => 30, |
|
173 | + ), |
|
174 | + 'list_table' => 'Payment_Log_Admin_List_Table', |
|
175 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
176 | + 'require_nonce' => false, |
|
177 | + ), |
|
178 | + ); |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * @return array |
|
185 | + */ |
|
186 | + protected function _add_payment_method_help_tabs() |
|
187 | + { |
|
188 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
189 | + $payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types(); |
|
190 | + $all_pmt_help_tabs_config = array(); |
|
191 | + foreach ($payment_method_types as $payment_method_type) { |
|
192 | + if (! EE_Registry::instance()->CAP->current_user_can($payment_method_type->cap_name(), |
|
193 | + 'specific_payment_method_type_access') |
|
194 | + ) { |
|
195 | + continue; |
|
196 | + } |
|
197 | + foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) { |
|
198 | + $template_args = isset($config['template_args']) ? $config['template_args'] : array(); |
|
199 | + $template_args['admin_page_obj'] = $this; |
|
200 | + $all_pmt_help_tabs_config[$help_tab_name] = array( |
|
201 | + 'title' => $config['title'], |
|
202 | + 'content' => EEH_Template::display_template( |
|
203 | + $payment_method_type->file_folder() . 'help_tabs' . DS . $config['filename'] . '.help_tab.php', |
|
204 | + $template_args, |
|
205 | + true), |
|
206 | + ); |
|
207 | + } |
|
208 | + } |
|
209 | + return $all_pmt_help_tabs_config; |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + |
|
214 | + //none of the below group are currently used for Gateway Settings |
|
215 | + protected function _add_screen_options() |
|
216 | + { |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + |
|
221 | + protected function _add_feature_pointers() |
|
222 | + { |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + |
|
227 | + public function admin_init() |
|
228 | + { |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + |
|
233 | + public function admin_notices() |
|
234 | + { |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + |
|
239 | + public function admin_footer_scripts() |
|
240 | + { |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + |
|
245 | + public function load_scripts_styles() |
|
246 | + { |
|
247 | + wp_enqueue_script('ee_admin_js'); |
|
248 | + wp_enqueue_script('ee-text-links'); |
|
249 | + wp_enqueue_script('espresso_payments', EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js', |
|
250 | + array('espresso-ui-theme', 'ee-datepicker'), EVENT_ESPRESSO_VERSION, true); |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + |
|
255 | + public function load_scripts_styles_default() |
|
256 | + { |
|
257 | + //styles |
|
258 | + wp_register_style('espresso_payments', EE_PAYMENTS_ASSETS_URL . 'ee-payments.css', array(), |
|
259 | + EVENT_ESPRESSO_VERSION); |
|
260 | + wp_enqueue_style('espresso_payments'); |
|
261 | + wp_enqueue_style('ee-text-links'); |
|
262 | + //scripts |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + |
|
267 | + protected function _payment_methods_list() |
|
268 | + { |
|
269 | + /** |
|
270 | + * first let's ensure payment methods have been setup. We do this here because when people activate a |
|
271 | + * payment method for the first time (as an addon), it may not setup its capabilities or get registered correctly due |
|
272 | + * to the loading process. However, people MUST setup the details for the payment method so its safe to do a |
|
273 | + * recheck here. |
|
274 | + */ |
|
275 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
276 | + EEM_Payment_Method::instance()->verify_button_urls(); |
|
277 | + //setup tabs, one for each payment method type |
|
278 | + $tabs = array(); |
|
279 | + $payment_methods = array(); |
|
280 | + foreach (EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj) { |
|
281 | + // we don't want to show admin-only PMTs for now |
|
282 | + if ($pmt_obj instanceof EE_PMT_Admin_Only) { |
|
283 | + continue; |
|
284 | + } |
|
285 | + //check access |
|
286 | + if (! EE_Registry::instance()->CAP->current_user_can($pmt_obj->cap_name(), |
|
287 | + 'specific_payment_method_type_access') |
|
288 | + ) { |
|
289 | + continue; |
|
290 | + } |
|
291 | + //check for any active pms of that type |
|
292 | + $payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name()); |
|
293 | + if (! $payment_method instanceof EE_Payment_Method) { |
|
294 | + $payment_method = EE_Payment_Method::new_instance( |
|
295 | + array( |
|
296 | + 'PMD_slug' => sanitize_key($pmt_obj->system_name()), |
|
297 | + 'PMD_type' => $pmt_obj->system_name(), |
|
298 | + 'PMD_name' => $pmt_obj->pretty_name(), |
|
299 | + 'PMD_admin_name' => $pmt_obj->pretty_name(), |
|
300 | + ) |
|
301 | + ); |
|
302 | + } |
|
303 | + $payment_methods[$payment_method->slug()] = $payment_method; |
|
304 | + } |
|
305 | + $payment_methods = apply_filters('FHEE__Payments_Admin_Page___payment_methods_list__payment_methods', |
|
306 | + $payment_methods); |
|
307 | + foreach ($payment_methods as $payment_method) { |
|
308 | + if ($payment_method instanceof EE_Payment_Method) { |
|
309 | + add_meta_box( |
|
310 | + //html id |
|
311 | + 'espresso_' . $payment_method->slug() . '_payment_settings', |
|
312 | + //title |
|
313 | + sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()), |
|
314 | + //callback |
|
315 | + array($this, 'payment_method_settings_meta_box'), |
|
316 | + //post type |
|
317 | + null, |
|
318 | + //context |
|
319 | + 'normal', |
|
320 | + //priority |
|
321 | + 'default', |
|
322 | + //callback args |
|
323 | + array('payment_method' => $payment_method) |
|
324 | + ); |
|
325 | + //setup for tabbed content |
|
326 | + $tabs[$payment_method->slug()] = array( |
|
327 | + 'label' => $payment_method->admin_name(), |
|
328 | + 'class' => $payment_method->active() ? 'gateway-active' : '', |
|
329 | + 'href' => 'espresso_' . $payment_method->slug() . '_payment_settings', |
|
330 | + 'title' => __('Modify this Payment Method', 'event_espresso'), |
|
331 | + 'slug' => $payment_method->slug(), |
|
332 | + ); |
|
333 | + } |
|
334 | + } |
|
335 | + $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links($tabs, 'payment_method_links', |
|
336 | + '|', $this->_get_active_payment_method_slug()); |
|
337 | + $this->display_admin_page_with_sidebar(); |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * _get_active_payment_method_slug |
|
344 | + * |
|
345 | + * @return string |
|
346 | + */ |
|
347 | + protected function _get_active_payment_method_slug() |
|
348 | + { |
|
349 | + $payment_method_slug = false; |
|
350 | + //decide which payment method tab to open first, as dictated by the request's 'payment_method' |
|
351 | + if (isset($this->_req_data['payment_method'])) { |
|
352 | + // if they provided the current payment method, use it |
|
353 | + $payment_method_slug = sanitize_key($this->_req_data['payment_method']); |
|
354 | + } |
|
355 | + $payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug))); |
|
356 | + // if that didn't work or wasn't provided, find another way to select the current pm |
|
357 | + if (! $this->_verify_payment_method($payment_method)) { |
|
358 | + // like, looking for an active one |
|
359 | + $payment_method = EEM_Payment_Method::instance()->get_one_active('CART'); |
|
360 | + // test that one as well |
|
361 | + if ($this->_verify_payment_method($payment_method)) { |
|
362 | + $payment_method_slug = $payment_method->slug(); |
|
363 | + } else { |
|
364 | + $payment_method_slug = 'paypal_standard'; |
|
365 | + } |
|
366 | + } |
|
367 | + return $payment_method_slug; |
|
368 | + } |
|
369 | + |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * payment_method_settings_meta_box |
|
374 | + * returns TRUE if the passed payment method is properly constructed and the logged in user has the correct |
|
375 | + * capabilities to access it |
|
376 | + * |
|
377 | + * @param \EE_Payment_Method $payment_method |
|
378 | + * @return boolean |
|
379 | + */ |
|
380 | + protected function _verify_payment_method($payment_method) |
|
381 | + { |
|
382 | + if ( |
|
383 | + $payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base |
|
384 | + && EE_Registry::instance()->CAP->current_user_can($payment_method->type_obj()->cap_name(), |
|
385 | + 'specific_payment_method_type_access') |
|
386 | + ) { |
|
387 | + return true; |
|
388 | + } |
|
389 | + return false; |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * payment_method_settings_meta_box |
|
396 | + * |
|
397 | + * @param NULL $post_obj_which_is_null is an object containing the current post (as a $post object) |
|
398 | + * @param array $metabox is an array with metabox id, title, callback, and args elements. the value |
|
399 | + * at 'args' has key 'payment_method', as set within _payment_methods_list |
|
400 | + * @return string |
|
401 | + * @throws EE_Error |
|
402 | + */ |
|
403 | + public function payment_method_settings_meta_box($post_obj_which_is_null, $metabox) |
|
404 | + { |
|
405 | + $payment_method = isset($metabox['args'], $metabox['args']['payment_method']) |
|
406 | + ? $metabox['args']['payment_method'] : null; |
|
407 | + if (! $payment_method instanceof EE_Payment_Method) { |
|
408 | + throw new EE_Error(sprintf(__('Payment method metabox setup incorrectly. No Payment method object was supplied', |
|
409 | + 'event_espresso'))); |
|
410 | + } |
|
411 | + $payment_method_scopes = $payment_method->active(); |
|
412 | + // if the payment method really exists show its form, otherwise the activation template |
|
413 | + if ($payment_method->ID() && ! empty($payment_method_scopes)) { |
|
414 | + $form = $this->_generate_payment_method_settings_form($payment_method); |
|
415 | + if ($form->form_data_present_in($this->_req_data)) { |
|
416 | + $form->receive_form_submission($this->_req_data); |
|
417 | + } |
|
418 | + echo $form->form_open() . $form->get_html_and_js() . $form->form_close(); |
|
419 | + } else { |
|
420 | + echo $this->_activate_payment_method_button($payment_method)->get_html_and_js(); |
|
421 | + } |
|
422 | + } |
|
423 | + |
|
424 | + |
|
425 | + |
|
426 | + /** |
|
427 | + * Gets the form for all the settings related to this payment method type |
|
428 | + * |
|
429 | + * @access protected |
|
430 | + * @param \EE_Payment_Method $payment_method |
|
431 | + * @return \EE_Form_Section_Proper |
|
432 | + */ |
|
433 | + protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method) |
|
434 | + { |
|
435 | + if (! $payment_method instanceof EE_Payment_Method) { |
|
436 | + return new EE_Form_Section_Proper(); |
|
437 | + } |
|
438 | + return new EE_Form_Section_Proper( |
|
439 | + array( |
|
440 | + 'name' => $payment_method->slug() . '_settings_form', |
|
441 | + 'html_id' => $payment_method->slug() . '_settings_form', |
|
442 | + 'action' => EE_Admin_Page::add_query_args_and_nonce( |
|
443 | + array( |
|
444 | + 'action' => 'update_payment_method', |
|
445 | + 'payment_method' => $payment_method->slug(), |
|
446 | + ), |
|
447 | + EE_PAYMENTS_ADMIN_URL |
|
448 | + ), |
|
449 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
450 | + 'subsections' => apply_filters( |
|
451 | + 'FHEE__Payments_Admin_Page___generate_payment_method_settings_form__form_subsections', |
|
452 | + array( |
|
453 | + 'pci_dss_compliance' => $this->_pci_dss_compliance($payment_method), |
|
454 | + 'currency_support' => $this->_currency_support($payment_method), |
|
455 | + 'payment_method_settings' => $this->_payment_method_settings($payment_method), |
|
456 | + 'update' => $this->_update_payment_method_button($payment_method), |
|
457 | + 'deactivate' => $this->_deactivate_payment_method_button($payment_method), |
|
458 | + 'fine_print' => $this->_fine_print(), |
|
459 | + ), |
|
460 | + $payment_method |
|
461 | + ), |
|
462 | + ) |
|
463 | + ); |
|
464 | + } |
|
465 | + |
|
466 | + |
|
467 | + |
|
468 | + /** |
|
469 | + * _pci_dss_compliance |
|
470 | + * |
|
471 | + * @access protected |
|
472 | + * @param \EE_Payment_Method $payment_method |
|
473 | + * @return \EE_Form_Section_Proper |
|
474 | + */ |
|
475 | + protected function _pci_dss_compliance(EE_Payment_Method $payment_method) |
|
476 | + { |
|
477 | + if ($payment_method->type_obj()->requires_https()) { |
|
478 | + return new EE_Form_Section_HTML( |
|
479 | + EEH_HTML::tr( |
|
480 | + EEH_HTML::th( |
|
481 | + EEH_HTML::label( |
|
482 | + EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice') |
|
483 | + ) |
|
484 | + ) . |
|
485 | + EEH_HTML::td( |
|
486 | + EEH_HTML::strong(__('You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.', |
|
487 | + 'event_espresso')) |
|
488 | + . |
|
489 | + EEH_HTML::br() |
|
490 | + . |
|
491 | + __('Learn more about ', 'event_espresso') |
|
492 | + . EEH_HTML::link('https://www.pcisecuritystandards.org/merchants/index.php', |
|
493 | + __('PCI DSS compliance', 'event_espresso')) |
|
494 | + ) |
|
495 | + ) |
|
496 | + ); |
|
497 | + } else { |
|
498 | + return new EE_Form_Section_HTML(''); |
|
499 | + } |
|
500 | + } |
|
501 | + |
|
502 | + |
|
503 | + |
|
504 | + /** |
|
505 | + * _currency_support |
|
506 | + * |
|
507 | + * @access protected |
|
508 | + * @param \EE_Payment_Method $payment_method |
|
509 | + * @return \EE_Form_Section_Proper |
|
510 | + */ |
|
511 | + protected function _currency_support(EE_Payment_Method $payment_method) |
|
512 | + { |
|
513 | + if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) { |
|
514 | + return new EE_Form_Section_HTML( |
|
515 | + EEH_HTML::tr( |
|
516 | + EEH_HTML::th( |
|
517 | + EEH_HTML::label( |
|
518 | + EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice') |
|
519 | + ) |
|
520 | + ) . |
|
521 | + EEH_HTML::td( |
|
522 | + EEH_HTML::strong( |
|
523 | + sprintf( |
|
524 | + __('This payment method does not support the currency set on your site (%1$s). Please activate a different payment method or change your site\'s country and associated currency.', |
|
525 | + 'event_espresso'), |
|
526 | + EE_Config::instance()->currency->code |
|
527 | + ) |
|
528 | + ) |
|
529 | + ) |
|
530 | + ) |
|
531 | + ); |
|
532 | + } else { |
|
533 | + return new EE_Form_Section_HTML(''); |
|
534 | + } |
|
535 | + } |
|
536 | + |
|
537 | + |
|
538 | + |
|
539 | + /** |
|
540 | + * _update_payment_method_button |
|
541 | + * |
|
542 | + * @access protected |
|
543 | + * @param \EE_Payment_Method $payment_method |
|
544 | + * @return \EE_Form_Section_HTML |
|
545 | + */ |
|
546 | + protected function _payment_method_settings(EE_Payment_Method $payment_method) |
|
547 | + { |
|
548 | + //modify the form so we only have/show fields that will be implemented for this version |
|
549 | + return $this->_simplify_form($payment_method->type_obj()->settings_form(), $payment_method->name()); |
|
550 | + } |
|
551 | + |
|
552 | + |
|
553 | + |
|
554 | + /** |
|
555 | + * Simplifies the form to merely reproduce 4.1's gateway settings functionality |
|
556 | + * |
|
557 | + * @param EE_Form_Section_Proper $form_section |
|
558 | + * @param string $payment_method_name |
|
559 | + * @return \EE_Payment_Method_Form |
|
560 | + * @throws \EE_Error |
|
561 | + */ |
|
562 | + protected function _simplify_form($form_section, $payment_method_name = '') |
|
563 | + { |
|
564 | + if ($form_section instanceof EE_Payment_Method_Form) { |
|
565 | + $form_section->exclude( |
|
566 | + array( |
|
567 | + 'PMD_type', //dont want them changing the type |
|
568 | + 'PMD_slug', //or the slug (probably never) |
|
569 | + 'PMD_wp_user', //or the user's ID |
|
570 | + 'Currency' //or the currency, until the rest of EE supports simultaneous currencies |
|
571 | + ) |
|
572 | + ); |
|
573 | + return $form_section; |
|
574 | + } else { |
|
575 | + throw new EE_Error(sprintf(__('The EE_Payment_Method_Form for the "%1$s" payment method is missing or invalid.', |
|
576 | + 'event_espresso'), $payment_method_name)); |
|
577 | + } |
|
578 | + } |
|
579 | + |
|
580 | + |
|
581 | + |
|
582 | + /** |
|
583 | + * _update_payment_method_button |
|
584 | + * |
|
585 | + * @access protected |
|
586 | + * @param \EE_Payment_Method $payment_method |
|
587 | + * @return \EE_Form_Section_HTML |
|
588 | + */ |
|
589 | + protected function _update_payment_method_button(EE_Payment_Method $payment_method) |
|
590 | + { |
|
591 | + $update_button = new EE_Submit_Input( |
|
592 | + array( |
|
593 | + 'name' => 'submit', |
|
594 | + 'html_id' => 'save_' . $payment_method->slug() . '_settings', |
|
595 | + 'default' => sprintf(__('Update %s Payment Settings', 'event_espresso'), |
|
596 | + $payment_method->admin_name()), |
|
597 | + 'html_label' => EEH_HTML::nbsp(), |
|
598 | + ) |
|
599 | + ); |
|
600 | + return new EE_Form_Section_HTML( |
|
601 | + EEH_HTML::no_row(EEH_HTML::br(2)) . |
|
602 | + EEH_HTML::tr( |
|
603 | + EEH_HTML::th(__('Update Settings', 'event_espresso')) . |
|
604 | + EEH_HTML::td( |
|
605 | + $update_button->get_html_for_input() |
|
606 | + ) |
|
607 | + ) |
|
608 | + ); |
|
609 | + } |
|
610 | + |
|
611 | + |
|
612 | + |
|
613 | + /** |
|
614 | + * _deactivate_payment_method_button |
|
615 | + * |
|
616 | + * @access protected |
|
617 | + * @param \EE_Payment_Method $payment_method |
|
618 | + * @return \EE_Form_Section_Proper |
|
619 | + */ |
|
620 | + protected function _deactivate_payment_method_button(EE_Payment_Method $payment_method) |
|
621 | + { |
|
622 | + $link_text_and_title = sprintf(__('Deactivate %1$s Payments?', 'event_espresso'), |
|
623 | + $payment_method->admin_name()); |
|
624 | + return new EE_Form_Section_HTML( |
|
625 | + EEH_HTML::tr( |
|
626 | + EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')) . |
|
627 | + EEH_HTML::td( |
|
628 | + EEH_HTML::link( |
|
629 | + EE_Admin_Page::add_query_args_and_nonce( |
|
630 | + array( |
|
631 | + 'action' => 'deactivate_payment_method', |
|
632 | + 'payment_method' => $payment_method->slug(), |
|
633 | + ), |
|
634 | + EE_PAYMENTS_ADMIN_URL |
|
635 | + ), |
|
636 | + $link_text_and_title, |
|
637 | + $link_text_and_title, |
|
638 | + 'deactivate_' . $payment_method->slug(), |
|
639 | + 'espresso-button button-secondary' |
|
640 | + ) |
|
641 | + ) |
|
642 | + ) |
|
643 | + ); |
|
644 | + } |
|
645 | + |
|
646 | + |
|
647 | + |
|
648 | + /** |
|
649 | + * _activate_payment_method_button |
|
650 | + * |
|
651 | + * @access protected |
|
652 | + * @param \EE_Payment_Method $payment_method |
|
653 | + * @return \EE_Form_Section_Proper |
|
654 | + */ |
|
655 | + protected function _activate_payment_method_button(EE_Payment_Method $payment_method) |
|
656 | + { |
|
657 | + $link_text_and_title = sprintf(__('Activate %1$s Payment Method?', 'event_espresso'), |
|
658 | + $payment_method->admin_name()); |
|
659 | + return new EE_Form_Section_Proper( |
|
660 | + array( |
|
661 | + 'name' => 'activate_' . $payment_method->slug() . '_settings_form', |
|
662 | + 'html_id' => 'activate_' . $payment_method->slug() . '_settings_form', |
|
663 | + 'action' => '#', |
|
664 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
665 | + 'subsections' => apply_filters( |
|
666 | + 'FHEE__Payments_Admin_Page___activate_payment_method_button__form_subsections', |
|
667 | + array( |
|
668 | + new EE_Form_Section_HTML( |
|
669 | + EEH_HTML::tr( |
|
670 | + EEH_HTML::td($payment_method->type_obj()->introductory_html(), |
|
671 | + '', |
|
672 | + '', |
|
673 | + '', |
|
674 | + 'colspan="2"' |
|
675 | + ) |
|
676 | + ) . |
|
677 | + EEH_HTML::tr( |
|
678 | + EEH_HTML::th( |
|
679 | + EEH_HTML::label(__('Click to Activate ', 'event_espresso')) |
|
680 | + ) . |
|
681 | + EEH_HTML::td( |
|
682 | + EEH_HTML::link( |
|
683 | + EE_Admin_Page::add_query_args_and_nonce( |
|
684 | + array( |
|
685 | + 'action' => 'activate_payment_method', |
|
686 | + 'payment_method_type' => $payment_method->type(), |
|
687 | + ), |
|
688 | + EE_PAYMENTS_ADMIN_URL |
|
689 | + ), |
|
690 | + $link_text_and_title, |
|
691 | + $link_text_and_title, |
|
692 | + 'activate_' . $payment_method->slug(), |
|
693 | + 'espresso-button-green button-primary' |
|
694 | + ) |
|
695 | + ) |
|
696 | + ) |
|
697 | + ), |
|
698 | + ), |
|
699 | + $payment_method |
|
700 | + ), |
|
701 | + ) |
|
702 | + ); |
|
703 | + } |
|
704 | + |
|
705 | + |
|
706 | + |
|
707 | + /** |
|
708 | + * _fine_print |
|
709 | + * |
|
710 | + * @access protected |
|
711 | + * @return \EE_Form_Section_HTML |
|
712 | + */ |
|
713 | + protected function _fine_print() |
|
714 | + { |
|
715 | + return new EE_Form_Section_HTML( |
|
716 | + EEH_HTML::tr( |
|
717 | + EEH_HTML::th() . |
|
718 | + EEH_HTML::td( |
|
719 | + EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text') |
|
720 | + ) |
|
721 | + ) |
|
722 | + ); |
|
723 | + } |
|
724 | + |
|
725 | + |
|
726 | + |
|
727 | + /** |
|
728 | + * Activates a payment method of that type. Mostly assuming there is only 1 of that type (or none so far) |
|
729 | + * |
|
730 | + * @global WP_User $current_user |
|
731 | + */ |
|
732 | + protected function _activate_payment_method() |
|
733 | + { |
|
734 | + if (isset($this->_req_data['payment_method_type'])) { |
|
735 | + $payment_method_type = sanitize_text_field($this->_req_data['payment_method_type']); |
|
736 | + //see if one exists |
|
737 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
738 | + $payment_method = EE_Payment_Method_Manager::instance() |
|
739 | + ->activate_a_payment_method_of_type($payment_method_type); |
|
740 | + $this->_redirect_after_action(1, 'Payment Method', 'activated', |
|
741 | + array('action' => 'default', 'payment_method' => $payment_method->slug())); |
|
742 | + } else { |
|
743 | + $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default')); |
|
744 | + } |
|
745 | + } |
|
746 | + |
|
747 | + |
|
748 | + |
|
749 | + /** |
|
750 | + * Deactivates the payment method with the specified slug, and redirects. |
|
751 | + */ |
|
752 | + protected function _deactivate_payment_method() |
|
753 | + { |
|
754 | + if (isset($this->_req_data['payment_method'])) { |
|
755 | + $payment_method_slug = sanitize_key($this->_req_data['payment_method']); |
|
756 | + //deactivate it |
|
757 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
758 | + $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method($payment_method_slug); |
|
759 | + $this->_redirect_after_action($count_updated, 'Payment Method', 'deactivated', |
|
760 | + array('action' => 'default', 'payment_method' => $payment_method_slug)); |
|
761 | + } else { |
|
762 | + $this->_redirect_after_action(false, 'Payment Method', 'deactivated', array('action' => 'default')); |
|
763 | + } |
|
764 | + } |
|
765 | + |
|
766 | + |
|
767 | + |
|
768 | + /** |
|
769 | + * Processes the payment method form that was submitted. This is slightly trickier than usual form |
|
770 | + * processing because we first need to identify WHICH form was processed and which payment method |
|
771 | + * it corresponds to. Once we have done that, we see if the form is valid. If it is, the |
|
772 | + * form's data is saved and we redirect to the default payment methods page, setting the updated payment method |
|
773 | + * as the currently-selected one. If it DOESN'T validate, we render the page with the form's errors (in the |
|
774 | + * subsequently called 'headers_sent_func' which is _payment_methods_list) |
|
775 | + * |
|
776 | + * @return void |
|
777 | + */ |
|
778 | + protected function _update_payment_method() |
|
779 | + { |
|
780 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
781 | + //ok let's find which gateway form to use based on the form input |
|
782 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
783 | + /** @var $correct_pmt_form_to_use EE_Payment_Method_Form */ |
|
784 | + $correct_pmt_form_to_use = null; |
|
785 | + $payment_method = null; |
|
786 | + foreach (EEM_Payment_Method::instance()->get_all() as $payment_method) { |
|
787 | + //get the form and simplify it, like what we do when we display it |
|
788 | + $pmt_form = $this->_generate_payment_method_settings_form($payment_method); |
|
789 | + if ($pmt_form->form_data_present_in($this->_req_data)) { |
|
790 | + $correct_pmt_form_to_use = $pmt_form; |
|
791 | + break; |
|
792 | + } |
|
793 | + } |
|
794 | + //if we couldn't find the correct payment method type... |
|
795 | + if (! $correct_pmt_form_to_use) { |
|
796 | + EE_Error::add_error(__("We could not find which payment method type your form submission related to. Please contact support", |
|
797 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
798 | + $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default')); |
|
799 | + } |
|
800 | + $correct_pmt_form_to_use->receive_form_submission($this->_req_data); |
|
801 | + if ($correct_pmt_form_to_use->is_valid()) { |
|
802 | + $payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings'); |
|
803 | + if (! $payment_settings_subform instanceof EE_Payment_Method_Form) { |
|
804 | + throw new EE_Error( |
|
805 | + sprintf( |
|
806 | + __('The payment method could not be saved because the form sections were misnamed. We expected to find %1$s, but did not.', |
|
807 | + 'event_espresso'), |
|
808 | + 'payment_method_settings' |
|
809 | + ) |
|
810 | + ); |
|
811 | + } |
|
812 | + $payment_settings_subform->save(); |
|
813 | + /** @var $pm EE_Payment_Method */ |
|
814 | + $this->_redirect_after_action(true, 'Payment Method', 'updated', |
|
815 | + array('action' => 'default', 'payment_method' => $payment_method->slug())); |
|
816 | + } else { |
|
817 | + EE_Error::add_error( |
|
818 | + sprintf( |
|
819 | + __('Payment method of type %s was not saved because there were validation errors. They have been marked in the form', |
|
820 | + 'event_espresso'), |
|
821 | + $payment_method instanceof EE_PMT_Base ? $payment_method->pretty_name() |
|
822 | + : __('"(unknown)"', 'event_espresso') |
|
823 | + ), |
|
824 | + __FILE__, |
|
825 | + __FUNCTION__, |
|
826 | + __LINE__ |
|
827 | + ); |
|
828 | + } |
|
829 | + } |
|
830 | + return; |
|
831 | + } |
|
832 | + |
|
833 | + |
|
834 | + |
|
835 | + protected function _payment_settings() |
|
836 | + { |
|
837 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
838 | + $this->_template_args['show_pending_payment_options'] = isset(EE_Registry::instance()->CFG->registration->show_pending_payment_options) |
|
839 | + ? absint(EE_Registry::instance()->CFG->registration->show_pending_payment_options) : false; |
|
840 | + $this->_set_add_edit_form_tags('update_payment_settings'); |
|
841 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
842 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template(EE_PAYMENTS_TEMPLATE_PATH |
|
843 | + . 'payment_settings.template.php', |
|
844 | + $this->_template_args, true); |
|
845 | + $this->display_admin_page_with_sidebar(); |
|
846 | + } |
|
847 | + |
|
848 | + |
|
849 | + |
|
850 | + /** |
|
851 | + * _update_payment_settings |
|
852 | + * |
|
853 | + * @access protected |
|
854 | + * @return array |
|
855 | + */ |
|
856 | + protected function _update_payment_settings() |
|
857 | + { |
|
858 | + EE_Registry::instance()->CFG->registration->show_pending_payment_options = isset($this->_req_data['show_pending_payment_options']) |
|
859 | + ? $this->_req_data['show_pending_payment_options'] : false; |
|
860 | + EE_Registry::instance()->CFG = apply_filters('FHEE__Payments_Admin_Page___update_payment_settings__CFG', |
|
861 | + EE_Registry::instance()->CFG); |
|
862 | 862 | // $superform = new EE_Form_Section_Proper( |
863 | 863 | // array( |
864 | 864 | // 'subsections' => array( |
@@ -876,176 +876,176 @@ discard block |
||
876 | 876 | // ); |
877 | 877 | // $this->_redirect_after_action( 0, 'settings', 'updated', array( 'action' => 'payment_settings' ) ); |
878 | 878 | // } |
879 | - $what = __('Payment Settings', 'event_espresso'); |
|
880 | - $success = $this->_update_espresso_configuration($what, EE_Registry::instance()->CFG, __FILE__, __FUNCTION__, |
|
881 | - __LINE__); |
|
882 | - $this->_redirect_after_action($success, $what, __('updated', 'event_espresso'), |
|
883 | - array('action' => 'payment_settings')); |
|
884 | - } |
|
879 | + $what = __('Payment Settings', 'event_espresso'); |
|
880 | + $success = $this->_update_espresso_configuration($what, EE_Registry::instance()->CFG, __FILE__, __FUNCTION__, |
|
881 | + __LINE__); |
|
882 | + $this->_redirect_after_action($success, $what, __('updated', 'event_espresso'), |
|
883 | + array('action' => 'payment_settings')); |
|
884 | + } |
|
885 | 885 | |
886 | 886 | |
887 | 887 | |
888 | - protected function _payment_log_overview_list_table() |
|
889 | - { |
|
888 | + protected function _payment_log_overview_list_table() |
|
889 | + { |
|
890 | 890 | // $this->_search_btn_label = __('Payment Log', 'event_espresso'); |
891 | - $this->display_admin_list_table_page_with_sidebar(); |
|
892 | - } |
|
893 | - |
|
894 | - |
|
895 | - |
|
896 | - protected function _set_list_table_views_payment_log() |
|
897 | - { |
|
898 | - $this->_views = array( |
|
899 | - 'all' => array( |
|
900 | - 'slug' => 'all', |
|
901 | - 'label' => __('View All Logs', 'event_espresso'), |
|
902 | - 'count' => 0, |
|
903 | - ), |
|
904 | - ); |
|
905 | - } |
|
906 | - |
|
907 | - |
|
908 | - |
|
909 | - /** |
|
910 | - * @param int $per_page |
|
911 | - * @param int $current_page |
|
912 | - * @param bool $count |
|
913 | - * @return array |
|
914 | - */ |
|
915 | - public function get_payment_logs($per_page = 50, $current_page = 0, $count = false) |
|
916 | - { |
|
917 | - EE_Registry::instance()->load_model('Change_Log'); |
|
918 | - //we may need to do multiple queries (joining differently), so we actually wan tan array of query params |
|
919 | - $query_params = array(array('LOG_type' => EEM_Change_Log::type_gateway)); |
|
920 | - //check if they've selected a specific payment method |
|
921 | - if (isset($this->_req_data['_payment_method']) && $this->_req_data['_payment_method'] !== 'all') { |
|
922 | - $query_params[0]['OR*pm_or_pay_pm'] = array( |
|
923 | - 'Payment.Payment_Method.PMD_ID' => $this->_req_data['_payment_method'], |
|
924 | - 'Payment_Method.PMD_ID' => $this->_req_data['_payment_method'], |
|
925 | - ); |
|
926 | - } |
|
927 | - //take into account search |
|
928 | - if (isset($this->_req_data['s']) && $this->_req_data['s']) { |
|
929 | - $similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%'); |
|
930 | - $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string; |
|
931 | - $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string; |
|
932 | - $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string; |
|
933 | - $query_params[0]['OR*s']['Payment.Payment_Method.PMD_name'] = $similarity_string; |
|
934 | - $query_params[0]['OR*s']['Payment.Payment_Method.PMD_admin_name'] = $similarity_string; |
|
935 | - $query_params[0]['OR*s']['Payment.Payment_Method.PMD_type'] = $similarity_string; |
|
936 | - $query_params[0]['OR*s']['LOG_message'] = $similarity_string; |
|
937 | - $query_params[0]['OR*s']['Payment_Method.PMD_name'] = $similarity_string; |
|
938 | - $query_params[0]['OR*s']['Payment_Method.PMD_admin_name'] = $similarity_string; |
|
939 | - $query_params[0]['OR*s']['Payment_Method.PMD_type'] = $similarity_string; |
|
940 | - $query_params[0]['OR*s']['LOG_message'] = $similarity_string; |
|
941 | - } |
|
942 | - if (isset($this->_req_data['payment-filter-start-date']) |
|
943 | - && isset($this->_req_data['payment-filter-end-date']) |
|
944 | - ) { |
|
945 | - //add date |
|
946 | - $start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']); |
|
947 | - $end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']); |
|
948 | - //make sure our timestamps start and end right at the boundaries for each day |
|
949 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
950 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
951 | - //convert to timestamps |
|
952 | - $start_date = strtotime($start_date); |
|
953 | - $end_date = strtotime($end_date); |
|
954 | - //makes sure start date is the lowest value and vice versa |
|
955 | - $start_date = min($start_date, $end_date); |
|
956 | - $end_date = max($start_date, $end_date); |
|
957 | - //convert for query |
|
958 | - $start_date = EEM_Change_Log::instance() |
|
959 | - ->convert_datetime_for_query('LOG_time', date('Y-m-d H:i:s', $start_date), |
|
960 | - 'Y-m-d H:i:s'); |
|
961 | - $end_date = EEM_Change_Log::instance() |
|
962 | - ->convert_datetime_for_query('LOG_time', date('Y-m-d H:i:s', $end_date), |
|
963 | - 'Y-m-d H:i:s'); |
|
964 | - $query_params[0]['LOG_time'] = array('BETWEEN', array($start_date, $end_date)); |
|
965 | - } |
|
966 | - if ($count) { |
|
967 | - return EEM_Change_Log::instance()->count($query_params); |
|
968 | - } |
|
969 | - if (isset($this->_req_data['order'])) { |
|
970 | - $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
971 | - : 'DESC'; |
|
972 | - $query_params['order_by'] = array('LOG_time' => $sort); |
|
973 | - } else { |
|
974 | - $query_params['order_by'] = array('LOG_time' => 'DESC'); |
|
975 | - } |
|
976 | - $offset = ($current_page - 1) * $per_page; |
|
977 | - if (! isset($this->_req_data['download_results'])) { |
|
978 | - $query_params['limit'] = array($offset, $per_page); |
|
979 | - } |
|
980 | - //now they've requested to instead just download the file instead of viewing it. |
|
981 | - if (isset($this->_req_data['download_results'])) { |
|
982 | - $wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params); |
|
983 | - header('Content-Disposition: attachment'); |
|
984 | - header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url())); |
|
985 | - echo "<h1>Payment Logs for " . site_url() . "</h1>"; |
|
986 | - echo "<h3>Query:</h3>"; |
|
987 | - var_dump($query_params); |
|
988 | - echo "<h3>Results:</h3>"; |
|
989 | - var_dump($wpdb_results); |
|
990 | - die; |
|
991 | - } |
|
992 | - $results = EEM_Change_Log::instance()->get_all($query_params); |
|
993 | - return $results; |
|
994 | - } |
|
995 | - |
|
996 | - |
|
997 | - |
|
998 | - /** |
|
999 | - * Used by usort to RE-sort log query results, because we lose the ordering |
|
1000 | - * because we're possibly combining the results from two queries |
|
1001 | - * |
|
1002 | - * @param EE_Change_Log $logA |
|
1003 | - * @param EE_Change_Log $logB |
|
1004 | - * @return int |
|
1005 | - */ |
|
1006 | - protected function _sort_logs_again($logA, $logB) |
|
1007 | - { |
|
1008 | - $timeA = $logA->get_raw('LOG_time'); |
|
1009 | - $timeB = $logB->get_raw('LOG_time'); |
|
1010 | - if ($timeA == $timeB) { |
|
1011 | - return 0; |
|
1012 | - } |
|
1013 | - $comparison = $timeA < $timeB ? -1 : 1; |
|
1014 | - if (strtoupper($this->_sort_logs_again_direction) == 'DESC') { |
|
1015 | - return $comparison * -1; |
|
1016 | - } else { |
|
1017 | - return $comparison; |
|
1018 | - } |
|
1019 | - } |
|
1020 | - |
|
1021 | - |
|
1022 | - |
|
1023 | - protected function _payment_log_details() |
|
1024 | - { |
|
1025 | - EE_Registry::instance()->load_model('Change_Log'); |
|
1026 | - /** @var $payment_log EE_Change_Log */ |
|
1027 | - $payment_log = EEM_Change_Log::instance()->get_one_by_ID($this->_req_data['ID']); |
|
1028 | - $payment_method = null; |
|
1029 | - $transaction = null; |
|
1030 | - if ($payment_log instanceof EE_Change_Log) { |
|
1031 | - if ($payment_log->object() instanceof EE_Payment) { |
|
1032 | - $payment_method = $payment_log->object()->payment_method(); |
|
1033 | - $transaction = $payment_log->object()->transaction(); |
|
1034 | - } elseif ($payment_log->object() instanceof EE_Payment_Method) { |
|
1035 | - $payment_method = $payment_log->object(); |
|
1036 | - } |
|
1037 | - } |
|
1038 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
1039 | - EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php', |
|
1040 | - array( |
|
1041 | - 'payment_log' => $payment_log, |
|
1042 | - 'payment_method' => $payment_method, |
|
1043 | - 'transaction' => $transaction, |
|
1044 | - ), |
|
1045 | - true |
|
1046 | - ); |
|
1047 | - $this->display_admin_page_with_sidebar(); |
|
1048 | - } |
|
891 | + $this->display_admin_list_table_page_with_sidebar(); |
|
892 | + } |
|
893 | + |
|
894 | + |
|
895 | + |
|
896 | + protected function _set_list_table_views_payment_log() |
|
897 | + { |
|
898 | + $this->_views = array( |
|
899 | + 'all' => array( |
|
900 | + 'slug' => 'all', |
|
901 | + 'label' => __('View All Logs', 'event_espresso'), |
|
902 | + 'count' => 0, |
|
903 | + ), |
|
904 | + ); |
|
905 | + } |
|
906 | + |
|
907 | + |
|
908 | + |
|
909 | + /** |
|
910 | + * @param int $per_page |
|
911 | + * @param int $current_page |
|
912 | + * @param bool $count |
|
913 | + * @return array |
|
914 | + */ |
|
915 | + public function get_payment_logs($per_page = 50, $current_page = 0, $count = false) |
|
916 | + { |
|
917 | + EE_Registry::instance()->load_model('Change_Log'); |
|
918 | + //we may need to do multiple queries (joining differently), so we actually wan tan array of query params |
|
919 | + $query_params = array(array('LOG_type' => EEM_Change_Log::type_gateway)); |
|
920 | + //check if they've selected a specific payment method |
|
921 | + if (isset($this->_req_data['_payment_method']) && $this->_req_data['_payment_method'] !== 'all') { |
|
922 | + $query_params[0]['OR*pm_or_pay_pm'] = array( |
|
923 | + 'Payment.Payment_Method.PMD_ID' => $this->_req_data['_payment_method'], |
|
924 | + 'Payment_Method.PMD_ID' => $this->_req_data['_payment_method'], |
|
925 | + ); |
|
926 | + } |
|
927 | + //take into account search |
|
928 | + if (isset($this->_req_data['s']) && $this->_req_data['s']) { |
|
929 | + $similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%'); |
|
930 | + $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string; |
|
931 | + $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string; |
|
932 | + $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string; |
|
933 | + $query_params[0]['OR*s']['Payment.Payment_Method.PMD_name'] = $similarity_string; |
|
934 | + $query_params[0]['OR*s']['Payment.Payment_Method.PMD_admin_name'] = $similarity_string; |
|
935 | + $query_params[0]['OR*s']['Payment.Payment_Method.PMD_type'] = $similarity_string; |
|
936 | + $query_params[0]['OR*s']['LOG_message'] = $similarity_string; |
|
937 | + $query_params[0]['OR*s']['Payment_Method.PMD_name'] = $similarity_string; |
|
938 | + $query_params[0]['OR*s']['Payment_Method.PMD_admin_name'] = $similarity_string; |
|
939 | + $query_params[0]['OR*s']['Payment_Method.PMD_type'] = $similarity_string; |
|
940 | + $query_params[0]['OR*s']['LOG_message'] = $similarity_string; |
|
941 | + } |
|
942 | + if (isset($this->_req_data['payment-filter-start-date']) |
|
943 | + && isset($this->_req_data['payment-filter-end-date']) |
|
944 | + ) { |
|
945 | + //add date |
|
946 | + $start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']); |
|
947 | + $end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']); |
|
948 | + //make sure our timestamps start and end right at the boundaries for each day |
|
949 | + $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
950 | + $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
951 | + //convert to timestamps |
|
952 | + $start_date = strtotime($start_date); |
|
953 | + $end_date = strtotime($end_date); |
|
954 | + //makes sure start date is the lowest value and vice versa |
|
955 | + $start_date = min($start_date, $end_date); |
|
956 | + $end_date = max($start_date, $end_date); |
|
957 | + //convert for query |
|
958 | + $start_date = EEM_Change_Log::instance() |
|
959 | + ->convert_datetime_for_query('LOG_time', date('Y-m-d H:i:s', $start_date), |
|
960 | + 'Y-m-d H:i:s'); |
|
961 | + $end_date = EEM_Change_Log::instance() |
|
962 | + ->convert_datetime_for_query('LOG_time', date('Y-m-d H:i:s', $end_date), |
|
963 | + 'Y-m-d H:i:s'); |
|
964 | + $query_params[0]['LOG_time'] = array('BETWEEN', array($start_date, $end_date)); |
|
965 | + } |
|
966 | + if ($count) { |
|
967 | + return EEM_Change_Log::instance()->count($query_params); |
|
968 | + } |
|
969 | + if (isset($this->_req_data['order'])) { |
|
970 | + $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
971 | + : 'DESC'; |
|
972 | + $query_params['order_by'] = array('LOG_time' => $sort); |
|
973 | + } else { |
|
974 | + $query_params['order_by'] = array('LOG_time' => 'DESC'); |
|
975 | + } |
|
976 | + $offset = ($current_page - 1) * $per_page; |
|
977 | + if (! isset($this->_req_data['download_results'])) { |
|
978 | + $query_params['limit'] = array($offset, $per_page); |
|
979 | + } |
|
980 | + //now they've requested to instead just download the file instead of viewing it. |
|
981 | + if (isset($this->_req_data['download_results'])) { |
|
982 | + $wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params); |
|
983 | + header('Content-Disposition: attachment'); |
|
984 | + header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url())); |
|
985 | + echo "<h1>Payment Logs for " . site_url() . "</h1>"; |
|
986 | + echo "<h3>Query:</h3>"; |
|
987 | + var_dump($query_params); |
|
988 | + echo "<h3>Results:</h3>"; |
|
989 | + var_dump($wpdb_results); |
|
990 | + die; |
|
991 | + } |
|
992 | + $results = EEM_Change_Log::instance()->get_all($query_params); |
|
993 | + return $results; |
|
994 | + } |
|
995 | + |
|
996 | + |
|
997 | + |
|
998 | + /** |
|
999 | + * Used by usort to RE-sort log query results, because we lose the ordering |
|
1000 | + * because we're possibly combining the results from two queries |
|
1001 | + * |
|
1002 | + * @param EE_Change_Log $logA |
|
1003 | + * @param EE_Change_Log $logB |
|
1004 | + * @return int |
|
1005 | + */ |
|
1006 | + protected function _sort_logs_again($logA, $logB) |
|
1007 | + { |
|
1008 | + $timeA = $logA->get_raw('LOG_time'); |
|
1009 | + $timeB = $logB->get_raw('LOG_time'); |
|
1010 | + if ($timeA == $timeB) { |
|
1011 | + return 0; |
|
1012 | + } |
|
1013 | + $comparison = $timeA < $timeB ? -1 : 1; |
|
1014 | + if (strtoupper($this->_sort_logs_again_direction) == 'DESC') { |
|
1015 | + return $comparison * -1; |
|
1016 | + } else { |
|
1017 | + return $comparison; |
|
1018 | + } |
|
1019 | + } |
|
1020 | + |
|
1021 | + |
|
1022 | + |
|
1023 | + protected function _payment_log_details() |
|
1024 | + { |
|
1025 | + EE_Registry::instance()->load_model('Change_Log'); |
|
1026 | + /** @var $payment_log EE_Change_Log */ |
|
1027 | + $payment_log = EEM_Change_Log::instance()->get_one_by_ID($this->_req_data['ID']); |
|
1028 | + $payment_method = null; |
|
1029 | + $transaction = null; |
|
1030 | + if ($payment_log instanceof EE_Change_Log) { |
|
1031 | + if ($payment_log->object() instanceof EE_Payment) { |
|
1032 | + $payment_method = $payment_log->object()->payment_method(); |
|
1033 | + $transaction = $payment_log->object()->transaction(); |
|
1034 | + } elseif ($payment_log->object() instanceof EE_Payment_Method) { |
|
1035 | + $payment_method = $payment_log->object(); |
|
1036 | + } |
|
1037 | + } |
|
1038 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
1039 | + EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php', |
|
1040 | + array( |
|
1041 | + 'payment_log' => $payment_log, |
|
1042 | + 'payment_method' => $payment_method, |
|
1043 | + 'transaction' => $transaction, |
|
1044 | + ), |
|
1045 | + true |
|
1046 | + ); |
|
1047 | + $this->display_admin_page_with_sidebar(); |
|
1048 | + } |
|
1049 | 1049 | |
1050 | 1050 | |
1051 | 1051 | } //end Payments_Admin_Page class |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | 4 | } |
5 | 5 | |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | $payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types(); |
190 | 190 | $all_pmt_help_tabs_config = array(); |
191 | 191 | foreach ($payment_method_types as $payment_method_type) { |
192 | - if (! EE_Registry::instance()->CAP->current_user_can($payment_method_type->cap_name(), |
|
192 | + if ( ! EE_Registry::instance()->CAP->current_user_can($payment_method_type->cap_name(), |
|
193 | 193 | 'specific_payment_method_type_access') |
194 | 194 | ) { |
195 | 195 | continue; |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | $all_pmt_help_tabs_config[$help_tab_name] = array( |
201 | 201 | 'title' => $config['title'], |
202 | 202 | 'content' => EEH_Template::display_template( |
203 | - $payment_method_type->file_folder() . 'help_tabs' . DS . $config['filename'] . '.help_tab.php', |
|
203 | + $payment_method_type->file_folder().'help_tabs'.DS.$config['filename'].'.help_tab.php', |
|
204 | 204 | $template_args, |
205 | 205 | true), |
206 | 206 | ); |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | { |
247 | 247 | wp_enqueue_script('ee_admin_js'); |
248 | 248 | wp_enqueue_script('ee-text-links'); |
249 | - wp_enqueue_script('espresso_payments', EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js', |
|
249 | + wp_enqueue_script('espresso_payments', EE_PAYMENTS_ASSETS_URL.'espresso_payments_admin.js', |
|
250 | 250 | array('espresso-ui-theme', 'ee-datepicker'), EVENT_ESPRESSO_VERSION, true); |
251 | 251 | } |
252 | 252 | |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | public function load_scripts_styles_default() |
256 | 256 | { |
257 | 257 | //styles |
258 | - wp_register_style('espresso_payments', EE_PAYMENTS_ASSETS_URL . 'ee-payments.css', array(), |
|
258 | + wp_register_style('espresso_payments', EE_PAYMENTS_ASSETS_URL.'ee-payments.css', array(), |
|
259 | 259 | EVENT_ESPRESSO_VERSION); |
260 | 260 | wp_enqueue_style('espresso_payments'); |
261 | 261 | wp_enqueue_style('ee-text-links'); |
@@ -283,14 +283,14 @@ discard block |
||
283 | 283 | continue; |
284 | 284 | } |
285 | 285 | //check access |
286 | - if (! EE_Registry::instance()->CAP->current_user_can($pmt_obj->cap_name(), |
|
286 | + if ( ! EE_Registry::instance()->CAP->current_user_can($pmt_obj->cap_name(), |
|
287 | 287 | 'specific_payment_method_type_access') |
288 | 288 | ) { |
289 | 289 | continue; |
290 | 290 | } |
291 | 291 | //check for any active pms of that type |
292 | 292 | $payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name()); |
293 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
293 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
294 | 294 | $payment_method = EE_Payment_Method::new_instance( |
295 | 295 | array( |
296 | 296 | 'PMD_slug' => sanitize_key($pmt_obj->system_name()), |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | if ($payment_method instanceof EE_Payment_Method) { |
309 | 309 | add_meta_box( |
310 | 310 | //html id |
311 | - 'espresso_' . $payment_method->slug() . '_payment_settings', |
|
311 | + 'espresso_'.$payment_method->slug().'_payment_settings', |
|
312 | 312 | //title |
313 | 313 | sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()), |
314 | 314 | //callback |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | $tabs[$payment_method->slug()] = array( |
327 | 327 | 'label' => $payment_method->admin_name(), |
328 | 328 | 'class' => $payment_method->active() ? 'gateway-active' : '', |
329 | - 'href' => 'espresso_' . $payment_method->slug() . '_payment_settings', |
|
329 | + 'href' => 'espresso_'.$payment_method->slug().'_payment_settings', |
|
330 | 330 | 'title' => __('Modify this Payment Method', 'event_espresso'), |
331 | 331 | 'slug' => $payment_method->slug(), |
332 | 332 | ); |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | } |
355 | 355 | $payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug))); |
356 | 356 | // if that didn't work or wasn't provided, find another way to select the current pm |
357 | - if (! $this->_verify_payment_method($payment_method)) { |
|
357 | + if ( ! $this->_verify_payment_method($payment_method)) { |
|
358 | 358 | // like, looking for an active one |
359 | 359 | $payment_method = EEM_Payment_Method::instance()->get_one_active('CART'); |
360 | 360 | // test that one as well |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | { |
405 | 405 | $payment_method = isset($metabox['args'], $metabox['args']['payment_method']) |
406 | 406 | ? $metabox['args']['payment_method'] : null; |
407 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
407 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
408 | 408 | throw new EE_Error(sprintf(__('Payment method metabox setup incorrectly. No Payment method object was supplied', |
409 | 409 | 'event_espresso'))); |
410 | 410 | } |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | if ($form->form_data_present_in($this->_req_data)) { |
416 | 416 | $form->receive_form_submission($this->_req_data); |
417 | 417 | } |
418 | - echo $form->form_open() . $form->get_html_and_js() . $form->form_close(); |
|
418 | + echo $form->form_open().$form->get_html_and_js().$form->form_close(); |
|
419 | 419 | } else { |
420 | 420 | echo $this->_activate_payment_method_button($payment_method)->get_html_and_js(); |
421 | 421 | } |
@@ -432,13 +432,13 @@ discard block |
||
432 | 432 | */ |
433 | 433 | protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method) |
434 | 434 | { |
435 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
435 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
436 | 436 | return new EE_Form_Section_Proper(); |
437 | 437 | } |
438 | 438 | return new EE_Form_Section_Proper( |
439 | 439 | array( |
440 | - 'name' => $payment_method->slug() . '_settings_form', |
|
441 | - 'html_id' => $payment_method->slug() . '_settings_form', |
|
440 | + 'name' => $payment_method->slug().'_settings_form', |
|
441 | + 'html_id' => $payment_method->slug().'_settings_form', |
|
442 | 442 | 'action' => EE_Admin_Page::add_query_args_and_nonce( |
443 | 443 | array( |
444 | 444 | 'action' => 'update_payment_method', |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | EEH_HTML::label( |
482 | 482 | EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice') |
483 | 483 | ) |
484 | - ) . |
|
484 | + ). |
|
485 | 485 | EEH_HTML::td( |
486 | 486 | EEH_HTML::strong(__('You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.', |
487 | 487 | 'event_espresso')) |
@@ -510,14 +510,14 @@ discard block |
||
510 | 510 | */ |
511 | 511 | protected function _currency_support(EE_Payment_Method $payment_method) |
512 | 512 | { |
513 | - if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) { |
|
513 | + if ( ! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) { |
|
514 | 514 | return new EE_Form_Section_HTML( |
515 | 515 | EEH_HTML::tr( |
516 | 516 | EEH_HTML::th( |
517 | 517 | EEH_HTML::label( |
518 | 518 | EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice') |
519 | 519 | ) |
520 | - ) . |
|
520 | + ). |
|
521 | 521 | EEH_HTML::td( |
522 | 522 | EEH_HTML::strong( |
523 | 523 | sprintf( |
@@ -591,16 +591,16 @@ discard block |
||
591 | 591 | $update_button = new EE_Submit_Input( |
592 | 592 | array( |
593 | 593 | 'name' => 'submit', |
594 | - 'html_id' => 'save_' . $payment_method->slug() . '_settings', |
|
594 | + 'html_id' => 'save_'.$payment_method->slug().'_settings', |
|
595 | 595 | 'default' => sprintf(__('Update %s Payment Settings', 'event_espresso'), |
596 | 596 | $payment_method->admin_name()), |
597 | 597 | 'html_label' => EEH_HTML::nbsp(), |
598 | 598 | ) |
599 | 599 | ); |
600 | 600 | return new EE_Form_Section_HTML( |
601 | - EEH_HTML::no_row(EEH_HTML::br(2)) . |
|
601 | + EEH_HTML::no_row(EEH_HTML::br(2)). |
|
602 | 602 | EEH_HTML::tr( |
603 | - EEH_HTML::th(__('Update Settings', 'event_espresso')) . |
|
603 | + EEH_HTML::th(__('Update Settings', 'event_espresso')). |
|
604 | 604 | EEH_HTML::td( |
605 | 605 | $update_button->get_html_for_input() |
606 | 606 | ) |
@@ -623,7 +623,7 @@ discard block |
||
623 | 623 | $payment_method->admin_name()); |
624 | 624 | return new EE_Form_Section_HTML( |
625 | 625 | EEH_HTML::tr( |
626 | - EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')) . |
|
626 | + EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')). |
|
627 | 627 | EEH_HTML::td( |
628 | 628 | EEH_HTML::link( |
629 | 629 | EE_Admin_Page::add_query_args_and_nonce( |
@@ -635,7 +635,7 @@ discard block |
||
635 | 635 | ), |
636 | 636 | $link_text_and_title, |
637 | 637 | $link_text_and_title, |
638 | - 'deactivate_' . $payment_method->slug(), |
|
638 | + 'deactivate_'.$payment_method->slug(), |
|
639 | 639 | 'espresso-button button-secondary' |
640 | 640 | ) |
641 | 641 | ) |
@@ -658,8 +658,8 @@ discard block |
||
658 | 658 | $payment_method->admin_name()); |
659 | 659 | return new EE_Form_Section_Proper( |
660 | 660 | array( |
661 | - 'name' => 'activate_' . $payment_method->slug() . '_settings_form', |
|
662 | - 'html_id' => 'activate_' . $payment_method->slug() . '_settings_form', |
|
661 | + 'name' => 'activate_'.$payment_method->slug().'_settings_form', |
|
662 | + 'html_id' => 'activate_'.$payment_method->slug().'_settings_form', |
|
663 | 663 | 'action' => '#', |
664 | 664 | 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
665 | 665 | 'subsections' => apply_filters( |
@@ -673,11 +673,11 @@ discard block |
||
673 | 673 | '', |
674 | 674 | 'colspan="2"' |
675 | 675 | ) |
676 | - ) . |
|
676 | + ). |
|
677 | 677 | EEH_HTML::tr( |
678 | 678 | EEH_HTML::th( |
679 | 679 | EEH_HTML::label(__('Click to Activate ', 'event_espresso')) |
680 | - ) . |
|
680 | + ). |
|
681 | 681 | EEH_HTML::td( |
682 | 682 | EEH_HTML::link( |
683 | 683 | EE_Admin_Page::add_query_args_and_nonce( |
@@ -689,7 +689,7 @@ discard block |
||
689 | 689 | ), |
690 | 690 | $link_text_and_title, |
691 | 691 | $link_text_and_title, |
692 | - 'activate_' . $payment_method->slug(), |
|
692 | + 'activate_'.$payment_method->slug(), |
|
693 | 693 | 'espresso-button-green button-primary' |
694 | 694 | ) |
695 | 695 | ) |
@@ -714,7 +714,7 @@ discard block |
||
714 | 714 | { |
715 | 715 | return new EE_Form_Section_HTML( |
716 | 716 | EEH_HTML::tr( |
717 | - EEH_HTML::th() . |
|
717 | + EEH_HTML::th(). |
|
718 | 718 | EEH_HTML::td( |
719 | 719 | EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text') |
720 | 720 | ) |
@@ -792,7 +792,7 @@ discard block |
||
792 | 792 | } |
793 | 793 | } |
794 | 794 | //if we couldn't find the correct payment method type... |
795 | - if (! $correct_pmt_form_to_use) { |
|
795 | + if ( ! $correct_pmt_form_to_use) { |
|
796 | 796 | EE_Error::add_error(__("We could not find which payment method type your form submission related to. Please contact support", |
797 | 797 | 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
798 | 798 | $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default')); |
@@ -800,7 +800,7 @@ discard block |
||
800 | 800 | $correct_pmt_form_to_use->receive_form_submission($this->_req_data); |
801 | 801 | if ($correct_pmt_form_to_use->is_valid()) { |
802 | 802 | $payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings'); |
803 | - if (! $payment_settings_subform instanceof EE_Payment_Method_Form) { |
|
803 | + if ( ! $payment_settings_subform instanceof EE_Payment_Method_Form) { |
|
804 | 804 | throw new EE_Error( |
805 | 805 | sprintf( |
806 | 806 | __('The payment method could not be saved because the form sections were misnamed. We expected to find %1$s, but did not.', |
@@ -926,7 +926,7 @@ discard block |
||
926 | 926 | } |
927 | 927 | //take into account search |
928 | 928 | if (isset($this->_req_data['s']) && $this->_req_data['s']) { |
929 | - $similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%'); |
|
929 | + $similarity_string = array('LIKE', '%'.str_replace("", "%", $this->_req_data['s']).'%'); |
|
930 | 930 | $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string; |
931 | 931 | $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string; |
932 | 932 | $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string; |
@@ -946,8 +946,8 @@ discard block |
||
946 | 946 | $start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']); |
947 | 947 | $end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']); |
948 | 948 | //make sure our timestamps start and end right at the boundaries for each day |
949 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
950 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
949 | + $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00'; |
|
950 | + $end_date = date('Y-m-d', strtotime($end_date)).' 23:59:59'; |
|
951 | 951 | //convert to timestamps |
952 | 952 | $start_date = strtotime($start_date); |
953 | 953 | $end_date = strtotime($end_date); |
@@ -974,15 +974,15 @@ discard block |
||
974 | 974 | $query_params['order_by'] = array('LOG_time' => 'DESC'); |
975 | 975 | } |
976 | 976 | $offset = ($current_page - 1) * $per_page; |
977 | - if (! isset($this->_req_data['download_results'])) { |
|
977 | + if ( ! isset($this->_req_data['download_results'])) { |
|
978 | 978 | $query_params['limit'] = array($offset, $per_page); |
979 | 979 | } |
980 | 980 | //now they've requested to instead just download the file instead of viewing it. |
981 | 981 | if (isset($this->_req_data['download_results'])) { |
982 | 982 | $wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params); |
983 | 983 | header('Content-Disposition: attachment'); |
984 | - header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url())); |
|
985 | - echo "<h1>Payment Logs for " . site_url() . "</h1>"; |
|
984 | + header("Content-Disposition: attachment; filename=ee_payment_logs_for_".sanitize_key(site_url())); |
|
985 | + echo "<h1>Payment Logs for ".site_url()."</h1>"; |
|
986 | 986 | echo "<h3>Query:</h3>"; |
987 | 987 | var_dump($query_params); |
988 | 988 | echo "<h3>Results:</h3>"; |
@@ -1036,7 +1036,7 @@ discard block |
||
1036 | 1036 | } |
1037 | 1037 | } |
1038 | 1038 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
1039 | - EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php', |
|
1039 | + EE_PAYMENTS_TEMPLATE_PATH.'payment_log_details.template.php', |
|
1040 | 1040 | array( |
1041 | 1041 | 'payment_log' => $payment_log, |
1042 | 1042 | 'payment_method' => $payment_method, |
@@ -372,6 +372,7 @@ |
||
372 | 372 | * save the relations indicated |
373 | 373 | * |
374 | 374 | * @type string $relation_name |
375 | + * @param integer $relation_name |
|
375 | 376 | * @return bool |
376 | 377 | * @throws EE_Error |
377 | 378 | */ |
@@ -14,439 +14,439 @@ |
||
14 | 14 | class EE_Model_Form_Section extends EE_Form_Section_Proper |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @var EEM_Base |
|
19 | - */ |
|
20 | - protected $_model = null; |
|
21 | - |
|
22 | - /** |
|
23 | - * @var EE_Base_Class |
|
24 | - */ |
|
25 | - protected $_model_object = null; |
|
26 | - |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * @param array $options_array keys: { |
|
31 | - * @type EEM_Base $model |
|
32 | - * @type EE_Base_Class $model_object |
|
33 | - * @type array $subsection_args array keys should be subsection names (that either do or will exist), and |
|
34 | - * values are the arrays as you would pass them to that subsection |
|
35 | - * } |
|
36 | - * @throws EE_Error |
|
37 | - */ |
|
38 | - public function __construct($options_array = array()) |
|
39 | - { |
|
40 | - if (isset($options_array['model']) && $options_array['model'] instanceof EEM_Base) { |
|
41 | - $this->_model = $options_array['model']; |
|
42 | - } |
|
43 | - if (! $this->_model || ! $this->_model instanceof EEM_Base) { |
|
44 | - throw new EE_Error(sprintf(__("Model Form Sections must first specify the _model property to be a subclass of EEM_Base", |
|
45 | - "event_espresso"))); |
|
46 | - } |
|
47 | - if (isset($options_array['subsection_args'])) { |
|
48 | - $subsection_args = $options_array['subsection_args']; |
|
49 | - } else { |
|
50 | - $subsection_args = array(); |
|
51 | - } |
|
52 | - //gather fields and relations to convert to inputs |
|
53 | - //but if they're just going to exclude a field anyways, don't bother converting it to an input |
|
54 | - $exclude = $this->_subsections; |
|
55 | - if (isset($options_array['exclude'])) { |
|
56 | - $exclude = array_merge($exclude, array_flip($options_array['exclude'])); |
|
57 | - } |
|
58 | - $model_fields = array_diff_key($this->_model->field_settings(), $exclude); |
|
59 | - $model_relations = array_diff_key($this->_model->relation_settings(), $exclude); |
|
60 | - //convert fields and relations to inputs |
|
61 | - $this->_subsections = array_merge( |
|
62 | - $this->_convert_model_fields_to_inputs($model_fields), |
|
63 | - $this->_convert_model_relations_to_inputs($model_relations, $subsection_args), |
|
64 | - $this->_subsections |
|
65 | - ); |
|
66 | - parent::__construct($options_array); |
|
67 | - if (isset($options_array['model_object']) && $options_array['model_object'] instanceof EE_Base_Class) { |
|
68 | - $this->populate_model_obj($options_array['model_object']); |
|
69 | - } |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * For now, just makes inputs for only HABTM relations |
|
76 | - * |
|
77 | - * @param EE_Model_Relation_Base[] $relations |
|
78 | - * @param array $subsection_args keys should be existing or soon-to-be-existing input names, and |
|
79 | - * their values are { |
|
80 | - * @type array { |
|
81 | - * @type EE_Base_Class[] $model_objects if the subsection is an EE_Select_Multi_Model_Input |
|
82 | - * } |
|
83 | - * } |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - protected function _convert_model_relations_to_inputs($relations, $subsection_args = array()) |
|
87 | - { |
|
88 | - $inputs = array(); |
|
89 | - foreach ($relations as $relation_name => $relation_obj) { |
|
90 | - $input_constructor_args = array( |
|
91 | - array_merge( |
|
92 | - array( |
|
93 | - 'required' => $relation_obj instanceof EE_Belongs_To_Relation, |
|
94 | - 'html_label_text' => $relation_obj instanceof EE_Belongs_To_Relation |
|
95 | - ? $relation_obj->get_other_model()->item_name(1) |
|
96 | - : $relation_obj->get_other_model() |
|
97 | - ->item_name(2), |
|
98 | - ), |
|
99 | - $subsection_args |
|
100 | - ), |
|
101 | - ); |
|
102 | - $input = null; |
|
103 | - switch (get_class($relation_obj)) { |
|
104 | - case 'EE_HABTM_Relation': |
|
105 | - if (isset($subsection_args[$relation_name]) |
|
106 | - && isset($subsection_args[$relation_name]['model_objects']) |
|
107 | - ) { |
|
108 | - $model_objects = $subsection_args[$relation_name]['model_objects']; |
|
109 | - } else { |
|
110 | - $model_objects = $relation_obj->get_other_model()->get_all(); |
|
111 | - } |
|
112 | - $input = new EE_Select_Multi_Model_Input($model_objects, $input_constructor_args); |
|
113 | - break; |
|
114 | - default: |
|
115 | - } |
|
116 | - if ($input) { |
|
117 | - $inputs[$relation_name] = $input; |
|
118 | - } |
|
119 | - } |
|
120 | - return $inputs; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * Changes model fields into form section inputs |
|
127 | - * |
|
128 | - * @param EE_Model_Field_Base[] $model_fields keys are the model's name |
|
129 | - * @throws EE_Error |
|
130 | - * @return EE_Form_Input_Base[] |
|
131 | - */ |
|
132 | - protected function _convert_model_fields_to_inputs($model_fields = array()) |
|
133 | - { |
|
134 | - $inputs = array(); |
|
135 | - foreach ($model_fields as $field_name => $model_field) { |
|
136 | - if ($model_field instanceof EE_Model_Field_Base) { |
|
137 | - $input_constructor_args = array( |
|
138 | - array( |
|
139 | - 'required' => ! $model_field->is_nullable() |
|
140 | - && $model_field->get_default_value() |
|
141 | - === null, |
|
142 | - 'html_label_text' => $model_field->get_nicename(), |
|
143 | - 'default' => $model_field->get_default_value(), |
|
144 | - ), |
|
145 | - ); |
|
146 | - switch (get_class($model_field)) { |
|
147 | - case 'EE_All_Caps_Text_Field': |
|
148 | - case 'EE_Any_Foreign_Model_Name_Field': |
|
149 | - $input_class = 'EE_Text_Input'; |
|
150 | - break; |
|
151 | - case 'EE_Boolean_Field': |
|
152 | - $input_class = 'EE_Yes_No_Input'; |
|
153 | - break; |
|
154 | - case 'EE_Datetime_Field': |
|
155 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
156 | - "event_espresso"), get_class($model_field))); |
|
157 | - break; |
|
158 | - case 'EE_Email_Field': |
|
159 | - $input_class = 'EE_Email_Input'; |
|
160 | - break; |
|
161 | - case 'EE_Enum_Integer_Field': |
|
162 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
163 | - "event_espresso"), get_class($model_field))); |
|
164 | - break; |
|
165 | - case 'EE_Enum_Text_Field': |
|
166 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
167 | - "event_espresso"), get_class($model_field))); |
|
168 | - break; |
|
169 | - case 'EE_Float_Field': |
|
170 | - $input_class = 'EE_Float_Input'; |
|
171 | - break; |
|
172 | - case 'EE_Foreign_Key_Int_Field': |
|
173 | - case 'EE_Foreign_Key_String_Field': |
|
174 | - case 'EE_WP_User_Field': |
|
175 | - $models_pointed_to = $model_field instanceof EE_Field_With_Model_Name |
|
176 | - ? $model_field->get_model_class_names_pointed_to() : array(); |
|
177 | - if (true || is_array($models_pointed_to) && count($models_pointed_to) > 1) { |
|
178 | - $input_class = 'EE_Text_Input'; |
|
179 | - } else { |
|
180 | - //so its just one model |
|
181 | - $model_name = is_array($models_pointed_to) ? reset($models_pointed_to) : $models_pointed_to; |
|
182 | - $model = EE_Registry::instance()->load_model($model_name); |
|
183 | - $model_names = $model->get_all_names(array('limit' => 10)); |
|
184 | - if ($model_field->is_nullable()) { |
|
185 | - array_unshift($model_names, __("Please Select", 'event_espresso')); |
|
186 | - } |
|
187 | - $input_constructor_args[1] = $input_constructor_args[0]; |
|
188 | - $input_constructor_args[0] = $model_names; |
|
189 | - $input_class = 'EE_Select_Input'; |
|
190 | - } |
|
191 | - break; |
|
192 | - case 'EE_Full_HTML_Field': |
|
193 | - $input_class = 'EE_Text_Area_Input'; |
|
194 | - $input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy()); |
|
195 | - break; |
|
196 | - case 'EE_Infinite_Integer': |
|
197 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
198 | - "event_espresso"), get_class($model_field))); |
|
199 | - break; |
|
200 | - case 'EE_Integer_Field': |
|
201 | - $input_class = 'EE_Text_Input'; |
|
202 | - break; |
|
203 | - case 'EE_Maybe_Serialized_Text_Field': |
|
204 | - $input_class = 'EE_Text_Area_Input'; |
|
205 | - break; |
|
206 | - case 'EE_Money_Field': |
|
207 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
208 | - "event_espresso"), get_class($model_field))); |
|
209 | - break; |
|
210 | - case 'EE_Post_Content_Field': |
|
211 | - $input_class = 'EE_Text_Area_Input'; |
|
212 | - $input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy()); |
|
213 | - break; |
|
214 | - case 'EE_Plain_Text_Field': |
|
215 | - $input_class = 'EE_Text_Input'; |
|
216 | - break; |
|
217 | - case 'EE_Primary_Key_Int_Field': |
|
218 | - $input_class = 'EE_Hidden_Input'; |
|
219 | - $input_constructor_args['normalization_strategy'] = new EE_Int_Normalization(); |
|
220 | - break; |
|
221 | - case 'EE_Primary_Key_String_Field': |
|
222 | - $input_class = 'EE_Hidden_Input'; |
|
223 | - break; |
|
224 | - case 'EE_Serialized_Text_Field': |
|
225 | - $input_class = 'EE_Text_Area_Input'; |
|
226 | - break; |
|
227 | - case 'EE_Simple_HTML_Field': |
|
228 | - $input_class = 'EE_Text_Area_Input'; |
|
229 | - $input_constructor_args[0]['validation_strategies'] = array(new EE_Simple_HTML_Validation_Strategy()); |
|
230 | - break; |
|
231 | - case 'EE_Slug_Field': |
|
232 | - $input_class = 'EE_Text_Input'; |
|
233 | - break; |
|
234 | - case 'EE_Trashed_Flag_Field': |
|
235 | - $input_class = 'EE_Yes_No_Input'; |
|
236 | - break; |
|
237 | - case 'EE_WP_Post_Status_Field': |
|
238 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
239 | - "event_espresso"), get_class($model_field))); |
|
240 | - break; |
|
241 | - case 'EE_WP_Post_Type_Field': |
|
242 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
243 | - "event_espresso"), get_class($model_field))); |
|
244 | - break; |
|
245 | - default: |
|
246 | - throw new EE_Error(sprintf(__("Model field of type '%s' does not convert to any known Form Input. Please add a case to EE_Model_Form_section's _convert_model_fields_to_inputs switch statement", |
|
247 | - "event_espresso"), get_class($model_field))); |
|
248 | - } |
|
249 | - $reflection = new ReflectionClass($input_class); |
|
250 | - $input = $reflection->newInstanceArgs($input_constructor_args); |
|
251 | - $inputs[$field_name] = $input; |
|
252 | - } |
|
253 | - } |
|
254 | - return $inputs; |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * Mostly the same as populate_defaults , except takes a model object as input, not an array, |
|
261 | - * and also sets the form's _model_object |
|
262 | - * |
|
263 | - * @param EE_Base_Class $model_obj |
|
264 | - * @return void |
|
265 | - */ |
|
266 | - public function populate_model_obj($model_obj) |
|
267 | - { |
|
268 | - $model_obj = $this->_model->ensure_is_obj($model_obj); |
|
269 | - $this->_model_object = $model_obj; |
|
270 | - $defaults = $model_obj->model_field_array(); |
|
271 | - foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) { |
|
272 | - $subsection = $this->get_subsection($relation_name, false); |
|
273 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
274 | - if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
275 | - //then we only expect there to be one |
|
276 | - $related_item = $this->_model_object->get_first_related($relation_name); |
|
277 | - $defaults[$relation_name] = $related_item->ID(); |
|
278 | - } else { |
|
279 | - $related_items = $this->_model_object->get_many_related($relation_name); |
|
280 | - $ids = array(); |
|
281 | - foreach ($related_items as $related_item) { |
|
282 | - $ids[] = $related_item->ID(); |
|
283 | - } |
|
284 | - $defaults[$relation_name] = $ids; |
|
285 | - } |
|
286 | - } |
|
287 | - } |
|
288 | - $defaults = apply_filters( |
|
289 | - 'FHEE__EE_Model_Form_Section__populate_model_obj', |
|
290 | - $defaults, |
|
291 | - $this |
|
292 | - ); |
|
293 | - $this->populate_defaults($defaults); |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * Gets all the input values that correspond to model fields. Keys are the input/field names, |
|
300 | - * values are their normalized values |
|
301 | - * |
|
302 | - * @return array |
|
303 | - */ |
|
304 | - public function inputs_values_corresponding_to_model_fields() |
|
305 | - { |
|
306 | - return array_intersect_key($this->input_values(), $this->_model->field_settings()); |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * After we've normalized the data as normal, set the corresponding model object |
|
313 | - * on the form. |
|
314 | - * |
|
315 | - * @param array $req_data should usually be $_REQUEST (the default). |
|
316 | - * @return void |
|
317 | - */ |
|
318 | - public function _normalize($req_data) |
|
319 | - { |
|
320 | - parent::_normalize($req_data); |
|
321 | - //create or set the model object, if it isn't already |
|
322 | - if (! $this->_model_object) { |
|
323 | - //check to see if the form indicates a PK, in which case we want to only retrieve it and update it |
|
324 | - $pk_name = $this->_model->primary_key_name(); |
|
325 | - $model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name)); |
|
326 | - if ($model_obj) { |
|
327 | - $this->_model_object = $model_obj; |
|
328 | - } else { |
|
329 | - $this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name()); |
|
330 | - } |
|
331 | - } |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * After this form has been initialized and is verified to be valid, |
|
338 | - * either creates a model object from its data and saves it, or updates |
|
339 | - * the model object its data represents |
|
340 | - * |
|
341 | - * @throws EE_Error |
|
342 | - * @return int, 1 on a successful update, the ID of |
|
343 | - * the new entry on insert; 0 on failure |
|
344 | - */ |
|
345 | - public function save() |
|
346 | - { |
|
347 | - if (! $this->_model_object) { |
|
348 | - throw new EE_Error(sprintf(__("Cannot save the model form's model object (model is '%s') because there is no model object set. You must either set it, or call receive_form_submission where it is set automatically", |
|
349 | - "event_espresso"), get_class($this->_model))); |
|
350 | - } |
|
351 | - //ok so the model object is set. Just set it with the submitted form data |
|
352 | - foreach ($this->inputs_values_corresponding_to_model_fields() as $field_name => $field_value) { |
|
353 | - //only set the non-primary key |
|
354 | - if ($field_name != $this->_model->primary_key_name()) { |
|
355 | - $this->_model_object->set($field_name, $field_value); |
|
356 | - } |
|
357 | - } |
|
358 | - $success = $this->_model_object->save(); |
|
359 | - foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) { |
|
360 | - if (isset($this->_subsections[$relation_name])) { |
|
361 | - $success = $this->_save_related_info($relation_name); |
|
362 | - } |
|
363 | - } |
|
364 | - do_action('AHEE__EE_Model_Form_Section__save__done', $this, $success); |
|
365 | - return $success; |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * Automatically finds the related model info from the form, if present, and |
|
372 | - * save the relations indicated |
|
373 | - * |
|
374 | - * @type string $relation_name |
|
375 | - * @return bool |
|
376 | - * @throws EE_Error |
|
377 | - */ |
|
378 | - protected function _save_related_info($relation_name) |
|
379 | - { |
|
380 | - $relation_obj = $this->_model->related_settings_for($relation_name); |
|
381 | - if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
382 | - //there is just a foreign key on this model pointing to that one |
|
383 | - $this->_model_object->_add_relation_to($this->get_input_value($relation_name), $relation_name); |
|
384 | - } elseif ($relation_obj instanceof EE_Has_Many_Relation) { |
|
385 | - //then we want to consider all of its currently-related things. |
|
386 | - //if they're in this list, keep them |
|
387 | - //if they're not in this list, remove them |
|
388 | - //and lastly add all the new items |
|
389 | - throw new EE_Error(sprintf(__('Automatic saving of related info across a "has many" relation is not yet supported', |
|
390 | - "event_espresso"))); |
|
391 | - } elseif ($relation_obj instanceof EE_HABTM_Relation) { |
|
392 | - //delete everything NOT in this list |
|
393 | - $normalized_input_value = $this->get_input_value($relation_name); |
|
394 | - if ($normalized_input_value && is_array($normalized_input_value)) { |
|
395 | - $where_query_params = array( |
|
396 | - $relation_obj->get_other_model()->primary_key_name() => array('NOT_IN', $normalized_input_value), |
|
397 | - ); |
|
398 | - } else { |
|
399 | - $where_query_params = array(); |
|
400 | - } |
|
401 | - $this->_model_object->_remove_relations($relation_name, $where_query_params); |
|
402 | - foreach ($normalized_input_value as $id) { |
|
403 | - $this->_model_object->_add_relation_to($id, $relation_name); |
|
404 | - } |
|
405 | - } |
|
406 | - return true; |
|
407 | - } |
|
408 | - |
|
409 | - |
|
410 | - |
|
411 | - /** |
|
412 | - * Gets the model of this model form |
|
413 | - * |
|
414 | - * @return EEM_Base |
|
415 | - */ |
|
416 | - public function get_model() |
|
417 | - { |
|
418 | - return $this->_model; |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - |
|
423 | - /** |
|
424 | - * Gets the model object for this model form, which was either set |
|
425 | - * upon construction (using the $options_array arg 'model_object'), by using |
|
426 | - * set_model_object($model_obj), or implicitly |
|
427 | - * when receive_form_submission($req_data) was called. |
|
428 | - * |
|
429 | - * @return EE_Base_Class |
|
430 | - */ |
|
431 | - public function get_model_object() |
|
432 | - { |
|
433 | - return $this->_model_object; |
|
434 | - } |
|
435 | - |
|
436 | - |
|
437 | - |
|
438 | - /** |
|
439 | - * gets teh default name of this form section if none is specified |
|
440 | - * |
|
441 | - * @return string |
|
442 | - */ |
|
443 | - protected function _set_default_name_if_empty() |
|
444 | - { |
|
445 | - if (! $this->_name) { |
|
446 | - $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form"; |
|
447 | - $this->_name = $default_name; |
|
448 | - } |
|
449 | - } |
|
17 | + /** |
|
18 | + * @var EEM_Base |
|
19 | + */ |
|
20 | + protected $_model = null; |
|
21 | + |
|
22 | + /** |
|
23 | + * @var EE_Base_Class |
|
24 | + */ |
|
25 | + protected $_model_object = null; |
|
26 | + |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * @param array $options_array keys: { |
|
31 | + * @type EEM_Base $model |
|
32 | + * @type EE_Base_Class $model_object |
|
33 | + * @type array $subsection_args array keys should be subsection names (that either do or will exist), and |
|
34 | + * values are the arrays as you would pass them to that subsection |
|
35 | + * } |
|
36 | + * @throws EE_Error |
|
37 | + */ |
|
38 | + public function __construct($options_array = array()) |
|
39 | + { |
|
40 | + if (isset($options_array['model']) && $options_array['model'] instanceof EEM_Base) { |
|
41 | + $this->_model = $options_array['model']; |
|
42 | + } |
|
43 | + if (! $this->_model || ! $this->_model instanceof EEM_Base) { |
|
44 | + throw new EE_Error(sprintf(__("Model Form Sections must first specify the _model property to be a subclass of EEM_Base", |
|
45 | + "event_espresso"))); |
|
46 | + } |
|
47 | + if (isset($options_array['subsection_args'])) { |
|
48 | + $subsection_args = $options_array['subsection_args']; |
|
49 | + } else { |
|
50 | + $subsection_args = array(); |
|
51 | + } |
|
52 | + //gather fields and relations to convert to inputs |
|
53 | + //but if they're just going to exclude a field anyways, don't bother converting it to an input |
|
54 | + $exclude = $this->_subsections; |
|
55 | + if (isset($options_array['exclude'])) { |
|
56 | + $exclude = array_merge($exclude, array_flip($options_array['exclude'])); |
|
57 | + } |
|
58 | + $model_fields = array_diff_key($this->_model->field_settings(), $exclude); |
|
59 | + $model_relations = array_diff_key($this->_model->relation_settings(), $exclude); |
|
60 | + //convert fields and relations to inputs |
|
61 | + $this->_subsections = array_merge( |
|
62 | + $this->_convert_model_fields_to_inputs($model_fields), |
|
63 | + $this->_convert_model_relations_to_inputs($model_relations, $subsection_args), |
|
64 | + $this->_subsections |
|
65 | + ); |
|
66 | + parent::__construct($options_array); |
|
67 | + if (isset($options_array['model_object']) && $options_array['model_object'] instanceof EE_Base_Class) { |
|
68 | + $this->populate_model_obj($options_array['model_object']); |
|
69 | + } |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * For now, just makes inputs for only HABTM relations |
|
76 | + * |
|
77 | + * @param EE_Model_Relation_Base[] $relations |
|
78 | + * @param array $subsection_args keys should be existing or soon-to-be-existing input names, and |
|
79 | + * their values are { |
|
80 | + * @type array { |
|
81 | + * @type EE_Base_Class[] $model_objects if the subsection is an EE_Select_Multi_Model_Input |
|
82 | + * } |
|
83 | + * } |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + protected function _convert_model_relations_to_inputs($relations, $subsection_args = array()) |
|
87 | + { |
|
88 | + $inputs = array(); |
|
89 | + foreach ($relations as $relation_name => $relation_obj) { |
|
90 | + $input_constructor_args = array( |
|
91 | + array_merge( |
|
92 | + array( |
|
93 | + 'required' => $relation_obj instanceof EE_Belongs_To_Relation, |
|
94 | + 'html_label_text' => $relation_obj instanceof EE_Belongs_To_Relation |
|
95 | + ? $relation_obj->get_other_model()->item_name(1) |
|
96 | + : $relation_obj->get_other_model() |
|
97 | + ->item_name(2), |
|
98 | + ), |
|
99 | + $subsection_args |
|
100 | + ), |
|
101 | + ); |
|
102 | + $input = null; |
|
103 | + switch (get_class($relation_obj)) { |
|
104 | + case 'EE_HABTM_Relation': |
|
105 | + if (isset($subsection_args[$relation_name]) |
|
106 | + && isset($subsection_args[$relation_name]['model_objects']) |
|
107 | + ) { |
|
108 | + $model_objects = $subsection_args[$relation_name]['model_objects']; |
|
109 | + } else { |
|
110 | + $model_objects = $relation_obj->get_other_model()->get_all(); |
|
111 | + } |
|
112 | + $input = new EE_Select_Multi_Model_Input($model_objects, $input_constructor_args); |
|
113 | + break; |
|
114 | + default: |
|
115 | + } |
|
116 | + if ($input) { |
|
117 | + $inputs[$relation_name] = $input; |
|
118 | + } |
|
119 | + } |
|
120 | + return $inputs; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * Changes model fields into form section inputs |
|
127 | + * |
|
128 | + * @param EE_Model_Field_Base[] $model_fields keys are the model's name |
|
129 | + * @throws EE_Error |
|
130 | + * @return EE_Form_Input_Base[] |
|
131 | + */ |
|
132 | + protected function _convert_model_fields_to_inputs($model_fields = array()) |
|
133 | + { |
|
134 | + $inputs = array(); |
|
135 | + foreach ($model_fields as $field_name => $model_field) { |
|
136 | + if ($model_field instanceof EE_Model_Field_Base) { |
|
137 | + $input_constructor_args = array( |
|
138 | + array( |
|
139 | + 'required' => ! $model_field->is_nullable() |
|
140 | + && $model_field->get_default_value() |
|
141 | + === null, |
|
142 | + 'html_label_text' => $model_field->get_nicename(), |
|
143 | + 'default' => $model_field->get_default_value(), |
|
144 | + ), |
|
145 | + ); |
|
146 | + switch (get_class($model_field)) { |
|
147 | + case 'EE_All_Caps_Text_Field': |
|
148 | + case 'EE_Any_Foreign_Model_Name_Field': |
|
149 | + $input_class = 'EE_Text_Input'; |
|
150 | + break; |
|
151 | + case 'EE_Boolean_Field': |
|
152 | + $input_class = 'EE_Yes_No_Input'; |
|
153 | + break; |
|
154 | + case 'EE_Datetime_Field': |
|
155 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
156 | + "event_espresso"), get_class($model_field))); |
|
157 | + break; |
|
158 | + case 'EE_Email_Field': |
|
159 | + $input_class = 'EE_Email_Input'; |
|
160 | + break; |
|
161 | + case 'EE_Enum_Integer_Field': |
|
162 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
163 | + "event_espresso"), get_class($model_field))); |
|
164 | + break; |
|
165 | + case 'EE_Enum_Text_Field': |
|
166 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
167 | + "event_espresso"), get_class($model_field))); |
|
168 | + break; |
|
169 | + case 'EE_Float_Field': |
|
170 | + $input_class = 'EE_Float_Input'; |
|
171 | + break; |
|
172 | + case 'EE_Foreign_Key_Int_Field': |
|
173 | + case 'EE_Foreign_Key_String_Field': |
|
174 | + case 'EE_WP_User_Field': |
|
175 | + $models_pointed_to = $model_field instanceof EE_Field_With_Model_Name |
|
176 | + ? $model_field->get_model_class_names_pointed_to() : array(); |
|
177 | + if (true || is_array($models_pointed_to) && count($models_pointed_to) > 1) { |
|
178 | + $input_class = 'EE_Text_Input'; |
|
179 | + } else { |
|
180 | + //so its just one model |
|
181 | + $model_name = is_array($models_pointed_to) ? reset($models_pointed_to) : $models_pointed_to; |
|
182 | + $model = EE_Registry::instance()->load_model($model_name); |
|
183 | + $model_names = $model->get_all_names(array('limit' => 10)); |
|
184 | + if ($model_field->is_nullable()) { |
|
185 | + array_unshift($model_names, __("Please Select", 'event_espresso')); |
|
186 | + } |
|
187 | + $input_constructor_args[1] = $input_constructor_args[0]; |
|
188 | + $input_constructor_args[0] = $model_names; |
|
189 | + $input_class = 'EE_Select_Input'; |
|
190 | + } |
|
191 | + break; |
|
192 | + case 'EE_Full_HTML_Field': |
|
193 | + $input_class = 'EE_Text_Area_Input'; |
|
194 | + $input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy()); |
|
195 | + break; |
|
196 | + case 'EE_Infinite_Integer': |
|
197 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
198 | + "event_espresso"), get_class($model_field))); |
|
199 | + break; |
|
200 | + case 'EE_Integer_Field': |
|
201 | + $input_class = 'EE_Text_Input'; |
|
202 | + break; |
|
203 | + case 'EE_Maybe_Serialized_Text_Field': |
|
204 | + $input_class = 'EE_Text_Area_Input'; |
|
205 | + break; |
|
206 | + case 'EE_Money_Field': |
|
207 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
208 | + "event_espresso"), get_class($model_field))); |
|
209 | + break; |
|
210 | + case 'EE_Post_Content_Field': |
|
211 | + $input_class = 'EE_Text_Area_Input'; |
|
212 | + $input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy()); |
|
213 | + break; |
|
214 | + case 'EE_Plain_Text_Field': |
|
215 | + $input_class = 'EE_Text_Input'; |
|
216 | + break; |
|
217 | + case 'EE_Primary_Key_Int_Field': |
|
218 | + $input_class = 'EE_Hidden_Input'; |
|
219 | + $input_constructor_args['normalization_strategy'] = new EE_Int_Normalization(); |
|
220 | + break; |
|
221 | + case 'EE_Primary_Key_String_Field': |
|
222 | + $input_class = 'EE_Hidden_Input'; |
|
223 | + break; |
|
224 | + case 'EE_Serialized_Text_Field': |
|
225 | + $input_class = 'EE_Text_Area_Input'; |
|
226 | + break; |
|
227 | + case 'EE_Simple_HTML_Field': |
|
228 | + $input_class = 'EE_Text_Area_Input'; |
|
229 | + $input_constructor_args[0]['validation_strategies'] = array(new EE_Simple_HTML_Validation_Strategy()); |
|
230 | + break; |
|
231 | + case 'EE_Slug_Field': |
|
232 | + $input_class = 'EE_Text_Input'; |
|
233 | + break; |
|
234 | + case 'EE_Trashed_Flag_Field': |
|
235 | + $input_class = 'EE_Yes_No_Input'; |
|
236 | + break; |
|
237 | + case 'EE_WP_Post_Status_Field': |
|
238 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
239 | + "event_espresso"), get_class($model_field))); |
|
240 | + break; |
|
241 | + case 'EE_WP_Post_Type_Field': |
|
242 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", |
|
243 | + "event_espresso"), get_class($model_field))); |
|
244 | + break; |
|
245 | + default: |
|
246 | + throw new EE_Error(sprintf(__("Model field of type '%s' does not convert to any known Form Input. Please add a case to EE_Model_Form_section's _convert_model_fields_to_inputs switch statement", |
|
247 | + "event_espresso"), get_class($model_field))); |
|
248 | + } |
|
249 | + $reflection = new ReflectionClass($input_class); |
|
250 | + $input = $reflection->newInstanceArgs($input_constructor_args); |
|
251 | + $inputs[$field_name] = $input; |
|
252 | + } |
|
253 | + } |
|
254 | + return $inputs; |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * Mostly the same as populate_defaults , except takes a model object as input, not an array, |
|
261 | + * and also sets the form's _model_object |
|
262 | + * |
|
263 | + * @param EE_Base_Class $model_obj |
|
264 | + * @return void |
|
265 | + */ |
|
266 | + public function populate_model_obj($model_obj) |
|
267 | + { |
|
268 | + $model_obj = $this->_model->ensure_is_obj($model_obj); |
|
269 | + $this->_model_object = $model_obj; |
|
270 | + $defaults = $model_obj->model_field_array(); |
|
271 | + foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) { |
|
272 | + $subsection = $this->get_subsection($relation_name, false); |
|
273 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
274 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
275 | + //then we only expect there to be one |
|
276 | + $related_item = $this->_model_object->get_first_related($relation_name); |
|
277 | + $defaults[$relation_name] = $related_item->ID(); |
|
278 | + } else { |
|
279 | + $related_items = $this->_model_object->get_many_related($relation_name); |
|
280 | + $ids = array(); |
|
281 | + foreach ($related_items as $related_item) { |
|
282 | + $ids[] = $related_item->ID(); |
|
283 | + } |
|
284 | + $defaults[$relation_name] = $ids; |
|
285 | + } |
|
286 | + } |
|
287 | + } |
|
288 | + $defaults = apply_filters( |
|
289 | + 'FHEE__EE_Model_Form_Section__populate_model_obj', |
|
290 | + $defaults, |
|
291 | + $this |
|
292 | + ); |
|
293 | + $this->populate_defaults($defaults); |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * Gets all the input values that correspond to model fields. Keys are the input/field names, |
|
300 | + * values are their normalized values |
|
301 | + * |
|
302 | + * @return array |
|
303 | + */ |
|
304 | + public function inputs_values_corresponding_to_model_fields() |
|
305 | + { |
|
306 | + return array_intersect_key($this->input_values(), $this->_model->field_settings()); |
|
307 | + } |
|
308 | + |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * After we've normalized the data as normal, set the corresponding model object |
|
313 | + * on the form. |
|
314 | + * |
|
315 | + * @param array $req_data should usually be $_REQUEST (the default). |
|
316 | + * @return void |
|
317 | + */ |
|
318 | + public function _normalize($req_data) |
|
319 | + { |
|
320 | + parent::_normalize($req_data); |
|
321 | + //create or set the model object, if it isn't already |
|
322 | + if (! $this->_model_object) { |
|
323 | + //check to see if the form indicates a PK, in which case we want to only retrieve it and update it |
|
324 | + $pk_name = $this->_model->primary_key_name(); |
|
325 | + $model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name)); |
|
326 | + if ($model_obj) { |
|
327 | + $this->_model_object = $model_obj; |
|
328 | + } else { |
|
329 | + $this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name()); |
|
330 | + } |
|
331 | + } |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * After this form has been initialized and is verified to be valid, |
|
338 | + * either creates a model object from its data and saves it, or updates |
|
339 | + * the model object its data represents |
|
340 | + * |
|
341 | + * @throws EE_Error |
|
342 | + * @return int, 1 on a successful update, the ID of |
|
343 | + * the new entry on insert; 0 on failure |
|
344 | + */ |
|
345 | + public function save() |
|
346 | + { |
|
347 | + if (! $this->_model_object) { |
|
348 | + throw new EE_Error(sprintf(__("Cannot save the model form's model object (model is '%s') because there is no model object set. You must either set it, or call receive_form_submission where it is set automatically", |
|
349 | + "event_espresso"), get_class($this->_model))); |
|
350 | + } |
|
351 | + //ok so the model object is set. Just set it with the submitted form data |
|
352 | + foreach ($this->inputs_values_corresponding_to_model_fields() as $field_name => $field_value) { |
|
353 | + //only set the non-primary key |
|
354 | + if ($field_name != $this->_model->primary_key_name()) { |
|
355 | + $this->_model_object->set($field_name, $field_value); |
|
356 | + } |
|
357 | + } |
|
358 | + $success = $this->_model_object->save(); |
|
359 | + foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) { |
|
360 | + if (isset($this->_subsections[$relation_name])) { |
|
361 | + $success = $this->_save_related_info($relation_name); |
|
362 | + } |
|
363 | + } |
|
364 | + do_action('AHEE__EE_Model_Form_Section__save__done', $this, $success); |
|
365 | + return $success; |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * Automatically finds the related model info from the form, if present, and |
|
372 | + * save the relations indicated |
|
373 | + * |
|
374 | + * @type string $relation_name |
|
375 | + * @return bool |
|
376 | + * @throws EE_Error |
|
377 | + */ |
|
378 | + protected function _save_related_info($relation_name) |
|
379 | + { |
|
380 | + $relation_obj = $this->_model->related_settings_for($relation_name); |
|
381 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
382 | + //there is just a foreign key on this model pointing to that one |
|
383 | + $this->_model_object->_add_relation_to($this->get_input_value($relation_name), $relation_name); |
|
384 | + } elseif ($relation_obj instanceof EE_Has_Many_Relation) { |
|
385 | + //then we want to consider all of its currently-related things. |
|
386 | + //if they're in this list, keep them |
|
387 | + //if they're not in this list, remove them |
|
388 | + //and lastly add all the new items |
|
389 | + throw new EE_Error(sprintf(__('Automatic saving of related info across a "has many" relation is not yet supported', |
|
390 | + "event_espresso"))); |
|
391 | + } elseif ($relation_obj instanceof EE_HABTM_Relation) { |
|
392 | + //delete everything NOT in this list |
|
393 | + $normalized_input_value = $this->get_input_value($relation_name); |
|
394 | + if ($normalized_input_value && is_array($normalized_input_value)) { |
|
395 | + $where_query_params = array( |
|
396 | + $relation_obj->get_other_model()->primary_key_name() => array('NOT_IN', $normalized_input_value), |
|
397 | + ); |
|
398 | + } else { |
|
399 | + $where_query_params = array(); |
|
400 | + } |
|
401 | + $this->_model_object->_remove_relations($relation_name, $where_query_params); |
|
402 | + foreach ($normalized_input_value as $id) { |
|
403 | + $this->_model_object->_add_relation_to($id, $relation_name); |
|
404 | + } |
|
405 | + } |
|
406 | + return true; |
|
407 | + } |
|
408 | + |
|
409 | + |
|
410 | + |
|
411 | + /** |
|
412 | + * Gets the model of this model form |
|
413 | + * |
|
414 | + * @return EEM_Base |
|
415 | + */ |
|
416 | + public function get_model() |
|
417 | + { |
|
418 | + return $this->_model; |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + |
|
423 | + /** |
|
424 | + * Gets the model object for this model form, which was either set |
|
425 | + * upon construction (using the $options_array arg 'model_object'), by using |
|
426 | + * set_model_object($model_obj), or implicitly |
|
427 | + * when receive_form_submission($req_data) was called. |
|
428 | + * |
|
429 | + * @return EE_Base_Class |
|
430 | + */ |
|
431 | + public function get_model_object() |
|
432 | + { |
|
433 | + return $this->_model_object; |
|
434 | + } |
|
435 | + |
|
436 | + |
|
437 | + |
|
438 | + /** |
|
439 | + * gets teh default name of this form section if none is specified |
|
440 | + * |
|
441 | + * @return string |
|
442 | + */ |
|
443 | + protected function _set_default_name_if_empty() |
|
444 | + { |
|
445 | + if (! $this->_name) { |
|
446 | + $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form"; |
|
447 | + $this->_name = $default_name; |
|
448 | + } |
|
449 | + } |
|
450 | 450 | |
451 | 451 | |
452 | 452 |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | if (isset($options_array['model']) && $options_array['model'] instanceof EEM_Base) { |
41 | 41 | $this->_model = $options_array['model']; |
42 | 42 | } |
43 | - if (! $this->_model || ! $this->_model instanceof EEM_Base) { |
|
43 | + if ( ! $this->_model || ! $this->_model instanceof EEM_Base) { |
|
44 | 44 | throw new EE_Error(sprintf(__("Model Form Sections must first specify the _model property to be a subclass of EEM_Base", |
45 | 45 | "event_espresso"))); |
46 | 46 | } |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | { |
320 | 320 | parent::_normalize($req_data); |
321 | 321 | //create or set the model object, if it isn't already |
322 | - if (! $this->_model_object) { |
|
322 | + if ( ! $this->_model_object) { |
|
323 | 323 | //check to see if the form indicates a PK, in which case we want to only retrieve it and update it |
324 | 324 | $pk_name = $this->_model->primary_key_name(); |
325 | 325 | $model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name)); |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | */ |
345 | 345 | public function save() |
346 | 346 | { |
347 | - if (! $this->_model_object) { |
|
347 | + if ( ! $this->_model_object) { |
|
348 | 348 | throw new EE_Error(sprintf(__("Cannot save the model form's model object (model is '%s') because there is no model object set. You must either set it, or call receive_form_submission where it is set automatically", |
349 | 349 | "event_espresso"), get_class($this->_model))); |
350 | 350 | } |
@@ -442,8 +442,8 @@ discard block |
||
442 | 442 | */ |
443 | 443 | protected function _set_default_name_if_empty() |
444 | 444 | { |
445 | - if (! $this->_name) { |
|
446 | - $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form"; |
|
445 | + if ( ! $this->_name) { |
|
446 | + $default_name = str_replace("EEM_", "", get_class($this->_model))."_Model_Form"; |
|
447 | 447 | $this->_name = $default_name; |
448 | 448 | } |
449 | 449 | } |