@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | { |
49 | 49 | // if there are no standard caps for this model, then for now |
50 | 50 | // all we know is if they need the default cap to access this |
51 | - if (! $this->model()->cap_slug()) { |
|
51 | + if ( ! $this->model()->cap_slug()) { |
|
52 | 52 | return [ |
53 | 53 | EE_Restriction_Generator_Base::get_default_restrictions_cap( |
54 | 54 | ) => new EE_Return_None_Where_Conditions(), |
@@ -61,14 +61,14 @@ discard block |
||
61 | 61 | ) => new EE_Return_None_Where_Conditions(), |
62 | 62 | EE_Restriction_Generator_Base::get_cap_name( |
63 | 63 | $this->model(), |
64 | - $this->action() . '_others' |
|
64 | + $this->action().'_others' |
|
65 | 65 | ) => new EE_Default_Where_Conditions( |
66 | 66 | [ |
67 | 67 | // I need to be the owner, or it must be a global item |
68 | - 'OR*no_' . |
|
68 | + 'OR*no_'. |
|
69 | 69 | EE_Restriction_Generator_Base::get_cap_name( |
70 | 70 | $this->model(), |
71 | - $this->action() . '_others' |
|
71 | + $this->action().'_others' |
|
72 | 72 | ) => [ |
73 | 73 | EE_QUERY_PLACEHOLDER_USER_FIELD_NAME => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
74 | 74 | $this->_global_field_name => true, |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | ), |
78 | 78 | EE_Restriction_Generator_Base::get_cap_name( |
79 | 79 | $this->model(), |
80 | - $this->action() . '_global' |
|
80 | + $this->action().'_global' |
|
81 | 81 | ) => new EE_Default_Where_Conditions( |
82 | 82 | [ |
83 | 83 | // it mustn't be global |
@@ -19,70 +19,70 @@ |
||
19 | 19 | */ |
20 | 20 | class EE_Restriction_Generator_Global extends EE_Restriction_Generator_Base |
21 | 21 | { |
22 | - /** |
|
23 | - * name of the model field that indicates whether or not a model object is |
|
24 | - * "global" |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - protected $_global_field_name; |
|
22 | + /** |
|
23 | + * name of the model field that indicates whether or not a model object is |
|
24 | + * "global" |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + protected $_global_field_name; |
|
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * @param string $global_field_name name of the model field that indicates |
|
33 | - * whether or not a model object is |
|
34 | - * "global" |
|
35 | - */ |
|
36 | - public function __construct(string $global_field_name) |
|
37 | - { |
|
38 | - $this->_global_field_name = $global_field_name; |
|
39 | - } |
|
31 | + /** |
|
32 | + * @param string $global_field_name name of the model field that indicates |
|
33 | + * whether or not a model object is |
|
34 | + * "global" |
|
35 | + */ |
|
36 | + public function __construct(string $global_field_name) |
|
37 | + { |
|
38 | + $this->_global_field_name = $global_field_name; |
|
39 | + } |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * @return EE_Default_Where_Conditions[]|EE_Return_None_Where_Conditions[] |
|
44 | - * @throws EE_Error |
|
45 | - */ |
|
46 | - protected function _generate_restrictions(): array |
|
47 | - { |
|
48 | - // if there are no standard caps for this model, then for now |
|
49 | - // all we know is if they need the default cap to access this |
|
50 | - if (! $this->model()->cap_slug()) { |
|
51 | - return [ |
|
52 | - EE_Restriction_Generator_Base::get_default_restrictions_cap( |
|
53 | - ) => new EE_Return_None_Where_Conditions(), |
|
54 | - ]; |
|
55 | - } |
|
56 | - return [ |
|
57 | - EE_Restriction_Generator_Base::get_cap_name( |
|
58 | - $this->model(), |
|
59 | - $this->action() |
|
60 | - ) => new EE_Return_None_Where_Conditions(), |
|
61 | - EE_Restriction_Generator_Base::get_cap_name( |
|
62 | - $this->model(), |
|
63 | - $this->action() . '_others' |
|
64 | - ) => new EE_Default_Where_Conditions( |
|
65 | - [ |
|
66 | - // I need to be the owner, or it must be a global item |
|
67 | - 'OR*no_' . |
|
68 | - EE_Restriction_Generator_Base::get_cap_name( |
|
69 | - $this->model(), |
|
70 | - $this->action() . '_others' |
|
71 | - ) => [ |
|
72 | - EE_QUERY_PLACEHOLDER_USER_FIELD_NAME => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
73 | - $this->_global_field_name => true, |
|
74 | - ], |
|
75 | - ] |
|
76 | - ), |
|
77 | - EE_Restriction_Generator_Base::get_cap_name( |
|
78 | - $this->model(), |
|
79 | - $this->action() . '_global' |
|
80 | - ) => new EE_Default_Where_Conditions( |
|
81 | - [ |
|
82 | - // it mustn't be global |
|
83 | - $this->_global_field_name => false, |
|
84 | - ] |
|
85 | - ), |
|
86 | - ]; |
|
87 | - } |
|
42 | + /** |
|
43 | + * @return EE_Default_Where_Conditions[]|EE_Return_None_Where_Conditions[] |
|
44 | + * @throws EE_Error |
|
45 | + */ |
|
46 | + protected function _generate_restrictions(): array |
|
47 | + { |
|
48 | + // if there are no standard caps for this model, then for now |
|
49 | + // all we know is if they need the default cap to access this |
|
50 | + if (! $this->model()->cap_slug()) { |
|
51 | + return [ |
|
52 | + EE_Restriction_Generator_Base::get_default_restrictions_cap( |
|
53 | + ) => new EE_Return_None_Where_Conditions(), |
|
54 | + ]; |
|
55 | + } |
|
56 | + return [ |
|
57 | + EE_Restriction_Generator_Base::get_cap_name( |
|
58 | + $this->model(), |
|
59 | + $this->action() |
|
60 | + ) => new EE_Return_None_Where_Conditions(), |
|
61 | + EE_Restriction_Generator_Base::get_cap_name( |
|
62 | + $this->model(), |
|
63 | + $this->action() . '_others' |
|
64 | + ) => new EE_Default_Where_Conditions( |
|
65 | + [ |
|
66 | + // I need to be the owner, or it must be a global item |
|
67 | + 'OR*no_' . |
|
68 | + EE_Restriction_Generator_Base::get_cap_name( |
|
69 | + $this->model(), |
|
70 | + $this->action() . '_others' |
|
71 | + ) => [ |
|
72 | + EE_QUERY_PLACEHOLDER_USER_FIELD_NAME => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
73 | + $this->_global_field_name => true, |
|
74 | + ], |
|
75 | + ] |
|
76 | + ), |
|
77 | + EE_Restriction_Generator_Base::get_cap_name( |
|
78 | + $this->model(), |
|
79 | + $this->action() . '_global' |
|
80 | + ) => new EE_Default_Where_Conditions( |
|
81 | + [ |
|
82 | + // it mustn't be global |
|
83 | + $this->_global_field_name => false, |
|
84 | + ] |
|
85 | + ), |
|
86 | + ]; |
|
87 | + } |
|
88 | 88 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | { |
45 | 45 | // if there are no standard caps for this model, then for now |
46 | 46 | // all we know if they need the default cap to access this |
47 | - if (! $this->model()->cap_slug()) { |
|
47 | + if ( ! $this->model()->cap_slug()) { |
|
48 | 48 | return [ |
49 | 49 | self::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions(), |
50 | 50 | ]; |
@@ -67,15 +67,15 @@ discard block |
||
67 | 67 | // they can't access others' non-default items |
68 | 68 | self::get_cap_name( |
69 | 69 | $event_model, |
70 | - $this->action() . '_others' |
|
70 | + $this->action().'_others' |
|
71 | 71 | ) => new EE_Default_Where_Conditions( |
72 | 72 | [ |
73 | - 'OR*' . self::get_cap_name( |
|
73 | + 'OR*'.self::get_cap_name( |
|
74 | 74 | $event_model, |
75 | - $this->action() . '_others' |
|
75 | + $this->action().'_others' |
|
76 | 76 | ) => $this->addPublishedPostConditions( |
77 | 77 | [ |
78 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
78 | + $this->_path_to_event_model.'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
79 | 79 | ], |
80 | 80 | true, |
81 | 81 | $this->_path_to_event_model |
@@ -84,14 +84,14 @@ discard block |
||
84 | 84 | ), |
85 | 85 | // if they have basic and others, but not private, |
86 | 86 | // they can't access others' private non-default items |
87 | - self::get_cap_name($event_model, $this->action() . '_private') => new EE_Default_Where_Conditions( |
|
87 | + self::get_cap_name($event_model, $this->action().'_private') => new EE_Default_Where_Conditions( |
|
88 | 88 | [ |
89 | - 'OR*no_' . self::get_cap_name( |
|
89 | + 'OR*no_'.self::get_cap_name( |
|
90 | 90 | $event_model, |
91 | - $this->action() . '_private' |
|
91 | + $this->action().'_private' |
|
92 | 92 | ) => $this->addPublishedPostConditions( |
93 | 93 | [ |
94 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
94 | + $this->_path_to_event_model.'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
95 | 95 | ], |
96 | 96 | false, |
97 | 97 | $this->_path_to_event_model |
@@ -13,90 +13,90 @@ |
||
13 | 13 | */ |
14 | 14 | class EE_Restriction_Generator_Event_Related_Public extends EE_Restriction_Generator_Base |
15 | 15 | { |
16 | - /** |
|
17 | - * Path to the event model from the model this restriction generator will |
|
18 | - * be applied to; including the event model itself. Eg |
|
19 | - * "Ticket.Datetime.Event" |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $_path_to_event_model; |
|
16 | + /** |
|
17 | + * Path to the event model from the model this restriction generator will |
|
18 | + * be applied to; including the event model itself. Eg |
|
19 | + * "Ticket.Datetime.Event" |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $_path_to_event_model; |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * @param string $path_to_event_model |
|
28 | - */ |
|
29 | - public function __construct(string $path_to_event_model) |
|
30 | - { |
|
31 | - if (substr($path_to_event_model, -1, 1) != '.') { |
|
32 | - $path_to_event_model .= '.'; |
|
33 | - } |
|
34 | - $this->_path_to_event_model = $path_to_event_model; |
|
35 | - } |
|
26 | + /** |
|
27 | + * @param string $path_to_event_model |
|
28 | + */ |
|
29 | + public function __construct(string $path_to_event_model) |
|
30 | + { |
|
31 | + if (substr($path_to_event_model, -1, 1) != '.') { |
|
32 | + $path_to_event_model .= '.'; |
|
33 | + } |
|
34 | + $this->_path_to_event_model = $path_to_event_model; |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * @return EE_Default_Where_Conditions[]|EE_Return_None_Where_Conditions[] |
|
40 | - * @throws EE_Error |
|
41 | - */ |
|
42 | - protected function _generate_restrictions(): array |
|
43 | - { |
|
44 | - // if there are no standard caps for this model, then for now |
|
45 | - // all we know if they need the default cap to access this |
|
46 | - if (! $this->model()->cap_slug()) { |
|
47 | - return [ |
|
48 | - self::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions(), |
|
49 | - ]; |
|
50 | - } |
|
38 | + /** |
|
39 | + * @return EE_Default_Where_Conditions[]|EE_Return_None_Where_Conditions[] |
|
40 | + * @throws EE_Error |
|
41 | + */ |
|
42 | + protected function _generate_restrictions(): array |
|
43 | + { |
|
44 | + // if there are no standard caps for this model, then for now |
|
45 | + // all we know if they need the default cap to access this |
|
46 | + if (! $this->model()->cap_slug()) { |
|
47 | + return [ |
|
48 | + self::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions(), |
|
49 | + ]; |
|
50 | + } |
|
51 | 51 | |
52 | - $event_model = EEM_Event::instance(); |
|
53 | - return [ |
|
54 | - // first: basically access to non-defaults is essentially |
|
55 | - // controlled by which events are accessible |
|
56 | - // if they don't have the basic event cap, |
|
57 | - // they can only read things for published events |
|
58 | - self::get_cap_name($event_model, $this->action()) => new EE_Default_Where_Conditions( |
|
59 | - $this->addPublishedPostConditions( |
|
60 | - [], |
|
61 | - true, |
|
62 | - $this->_path_to_event_model |
|
63 | - ) |
|
64 | - ), |
|
65 | - // if they don't have the others event cap, |
|
66 | - // they can't access others' non-default items |
|
67 | - self::get_cap_name( |
|
68 | - $event_model, |
|
69 | - $this->action() . '_others' |
|
70 | - ) => new EE_Default_Where_Conditions( |
|
71 | - [ |
|
72 | - 'OR*' . self::get_cap_name( |
|
73 | - $event_model, |
|
74 | - $this->action() . '_others' |
|
75 | - ) => $this->addPublishedPostConditions( |
|
76 | - [ |
|
77 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
78 | - ], |
|
79 | - true, |
|
80 | - $this->_path_to_event_model |
|
81 | - ), |
|
82 | - ] |
|
83 | - ), |
|
84 | - // if they have basic and others, but not private, |
|
85 | - // they can't access others' private non-default items |
|
86 | - self::get_cap_name($event_model, $this->action() . '_private') => new EE_Default_Where_Conditions( |
|
87 | - [ |
|
88 | - 'OR*no_' . self::get_cap_name( |
|
89 | - $event_model, |
|
90 | - $this->action() . '_private' |
|
91 | - ) => $this->addPublishedPostConditions( |
|
92 | - [ |
|
93 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
94 | - ], |
|
95 | - false, |
|
96 | - $this->_path_to_event_model |
|
97 | - ), |
|
98 | - ] |
|
99 | - ), |
|
100 | - ]; |
|
101 | - } |
|
52 | + $event_model = EEM_Event::instance(); |
|
53 | + return [ |
|
54 | + // first: basically access to non-defaults is essentially |
|
55 | + // controlled by which events are accessible |
|
56 | + // if they don't have the basic event cap, |
|
57 | + // they can only read things for published events |
|
58 | + self::get_cap_name($event_model, $this->action()) => new EE_Default_Where_Conditions( |
|
59 | + $this->addPublishedPostConditions( |
|
60 | + [], |
|
61 | + true, |
|
62 | + $this->_path_to_event_model |
|
63 | + ) |
|
64 | + ), |
|
65 | + // if they don't have the others event cap, |
|
66 | + // they can't access others' non-default items |
|
67 | + self::get_cap_name( |
|
68 | + $event_model, |
|
69 | + $this->action() . '_others' |
|
70 | + ) => new EE_Default_Where_Conditions( |
|
71 | + [ |
|
72 | + 'OR*' . self::get_cap_name( |
|
73 | + $event_model, |
|
74 | + $this->action() . '_others' |
|
75 | + ) => $this->addPublishedPostConditions( |
|
76 | + [ |
|
77 | + $this->_path_to_event_model . 'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
78 | + ], |
|
79 | + true, |
|
80 | + $this->_path_to_event_model |
|
81 | + ), |
|
82 | + ] |
|
83 | + ), |
|
84 | + // if they have basic and others, but not private, |
|
85 | + // they can't access others' private non-default items |
|
86 | + self::get_cap_name($event_model, $this->action() . '_private') => new EE_Default_Where_Conditions( |
|
87 | + [ |
|
88 | + 'OR*no_' . self::get_cap_name( |
|
89 | + $event_model, |
|
90 | + $this->action() . '_private' |
|
91 | + ) => $this->addPublishedPostConditions( |
|
92 | + [ |
|
93 | + $this->_path_to_event_model . 'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
94 | + ], |
|
95 | + false, |
|
96 | + $this->_path_to_event_model |
|
97 | + ), |
|
98 | + ] |
|
99 | + ), |
|
100 | + ]; |
|
101 | + } |
|
102 | 102 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | { |
64 | 64 | // if there are no standard caps for this model, then for now all we know |
65 | 65 | // if they need the default cap to access this |
66 | - if (! $this->model()->cap_slug()) { |
|
66 | + if ( ! $this->model()->cap_slug()) { |
|
67 | 67 | return [ |
68 | 68 | self::get_default_restrictions_cap( |
69 | 69 | ) => new EE_Return_None_Where_Conditions(), |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $this->action() |
83 | 83 | ) => new EE_Default_Where_Conditions( |
84 | 84 | [ |
85 | - 'OR*no_' . |
|
85 | + 'OR*no_'. |
|
86 | 86 | EE_Restriction_Generator_Base::get_cap_name( |
87 | 87 | $event_model, |
88 | 88 | $this->action() |
@@ -100,16 +100,16 @@ discard block |
||
100 | 100 | // others' that are for published events, or defaults |
101 | 101 | EE_Restriction_Generator_Base::get_cap_name( |
102 | 102 | $event_model, |
103 | - $this->action() . '_others' |
|
103 | + $this->action().'_others' |
|
104 | 104 | ) => new EE_Default_Where_Conditions( |
105 | 105 | [ |
106 | - 'OR*no_' . |
|
106 | + 'OR*no_'. |
|
107 | 107 | EE_Restriction_Generator_Base::get_cap_name( |
108 | 108 | $event_model, |
109 | - $this->action() . '_others' |
|
109 | + $this->action().'_others' |
|
110 | 110 | ) => $this->addPublishedPostConditions( |
111 | 111 | [ |
112 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
112 | + $this->_path_to_event_model.'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
113 | 113 | $this->_default_field_name => true, |
114 | 114 | ], |
115 | 115 | true, |
@@ -122,16 +122,16 @@ discard block |
||
122 | 122 | // and others' that aren't private |
123 | 123 | EE_Restriction_Generator_Base::get_cap_name( |
124 | 124 | $event_model, |
125 | - $this->action() . '_private' |
|
125 | + $this->action().'_private' |
|
126 | 126 | ) => new EE_Default_Where_Conditions( |
127 | 127 | [ |
128 | - 'OR*no_' . |
|
128 | + 'OR*no_'. |
|
129 | 129 | EE_Restriction_Generator_Base::get_cap_name( |
130 | 130 | $event_model, |
131 | - $this->action() . '_private' |
|
131 | + $this->action().'_private' |
|
132 | 132 | ) => $this->addPublishedPostConditions( |
133 | 133 | [ |
134 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
134 | + $this->_path_to_event_model.'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
135 | 135 | $this->_default_field_name => true, |
136 | 136 | ], |
137 | 137 | false, |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | // restrict access to only non-default items |
146 | 146 | EE_Restriction_Generator_Base::get_cap_name( |
147 | 147 | $this->model(), |
148 | - $this->action() . '_default' |
|
148 | + $this->action().'_default' |
|
149 | 149 | ) => new EE_Default_Where_Conditions( |
150 | 150 | [$this->_default_field_name => false] |
151 | 151 | ), |
@@ -153,24 +153,24 @@ discard block |
||
153 | 153 | if ( |
154 | 154 | EE_Restriction_Generator_Base::is_cap( |
155 | 155 | $this->model(), |
156 | - $this->action() . '_others_default' |
|
156 | + $this->action().'_others_default' |
|
157 | 157 | ) |
158 | 158 | ) { |
159 | 159 | // if they don't have the "others" default capability, |
160 | 160 | // restrict access to only their default ones, and non-default ones |
161 | - $restrictions[ EE_Restriction_Generator_Base::get_cap_name( |
|
161 | + $restrictions[EE_Restriction_Generator_Base::get_cap_name( |
|
162 | 162 | $this->model(), |
163 | - $this->action() . '_others_default' |
|
164 | - ) ] = new EE_Default_Where_Conditions( |
|
163 | + $this->action().'_others_default' |
|
164 | + )] = new EE_Default_Where_Conditions( |
|
165 | 165 | [ |
166 | 166 | // if they don't have the others default cap, |
167 | 167 | // they can't access others default items |
168 | 168 | // (but they can access their own default items, |
169 | 169 | // and non-default items) |
170 | - 'OR*no_' . |
|
170 | + 'OR*no_'. |
|
171 | 171 | EE_Restriction_Generator_Base::get_cap_name( |
172 | 172 | $this->model(), |
173 | - $this->action() . '_others_default' |
|
173 | + $this->action().'_others_default' |
|
174 | 174 | ) => [ |
175 | 175 | 'AND' => [ |
176 | 176 | EE_QUERY_PLACEHOLDER_USER_FIELD_NAME => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
@@ -14,172 +14,172 @@ |
||
14 | 14 | */ |
15 | 15 | class EE_Restriction_Generator_Default_Public extends EE_Restriction_Generator_Base |
16 | 16 | { |
17 | - /** |
|
18 | - * Name of the field on this model (or a related model, including the model |
|
19 | - * chain to it) that is a boolean indicating whether or not a model object |
|
20 | - * is considered "Default" or not |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $_default_field_name; |
|
17 | + /** |
|
18 | + * Name of the field on this model (or a related model, including the model |
|
19 | + * chain to it) that is a boolean indicating whether or not a model object |
|
20 | + * is considered "Default" or not |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $_default_field_name; |
|
25 | 25 | |
26 | - /** |
|
27 | - * The model chain to follow to get to the event model, including the event |
|
28 | - * model itself. Eg 'Ticket.Datetime.Event' |
|
29 | - * |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - protected $_path_to_event_model; |
|
26 | + /** |
|
27 | + * The model chain to follow to get to the event model, including the event |
|
28 | + * model itself. Eg 'Ticket.Datetime.Event' |
|
29 | + * |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + protected $_path_to_event_model; |
|
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * @param string $default_field_name the name of the field Name of the |
|
37 | - * field on this model (or a related |
|
38 | - * model, including the model chain to |
|
39 | - * it) that is a boolean indicating |
|
40 | - * whether or not a model object is |
|
41 | - * considered "Default" or not |
|
42 | - * @param string $path_to_event_model The model chain to follow to get to |
|
43 | - * the event model, including the event |
|
44 | - * model itself. Eg |
|
45 | - * 'Ticket.Datetime.Event' |
|
46 | - */ |
|
47 | - public function __construct(string $default_field_name, string $path_to_event_model) |
|
48 | - { |
|
49 | - $this->_default_field_name = $default_field_name; |
|
50 | - if (substr($path_to_event_model, -1, 1) != '.') { |
|
51 | - $path_to_event_model .= '.'; |
|
52 | - } |
|
53 | - $this->_path_to_event_model = $path_to_event_model; |
|
54 | - } |
|
35 | + /** |
|
36 | + * @param string $default_field_name the name of the field Name of the |
|
37 | + * field on this model (or a related |
|
38 | + * model, including the model chain to |
|
39 | + * it) that is a boolean indicating |
|
40 | + * whether or not a model object is |
|
41 | + * considered "Default" or not |
|
42 | + * @param string $path_to_event_model The model chain to follow to get to |
|
43 | + * the event model, including the event |
|
44 | + * model itself. Eg |
|
45 | + * 'Ticket.Datetime.Event' |
|
46 | + */ |
|
47 | + public function __construct(string $default_field_name, string $path_to_event_model) |
|
48 | + { |
|
49 | + $this->_default_field_name = $default_field_name; |
|
50 | + if (substr($path_to_event_model, -1, 1) != '.') { |
|
51 | + $path_to_event_model .= '.'; |
|
52 | + } |
|
53 | + $this->_path_to_event_model = $path_to_event_model; |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * @return EE_Default_Where_Conditions[]|EE_Return_None_Where_Conditions[] |
|
59 | - * @throws EE_Error |
|
60 | - */ |
|
61 | - protected function _generate_restrictions(): array |
|
62 | - { |
|
63 | - // if there are no standard caps for this model, then for now all we know |
|
64 | - // if they need the default cap to access this |
|
65 | - if (! $this->model()->cap_slug()) { |
|
66 | - return [ |
|
67 | - self::get_default_restrictions_cap( |
|
68 | - ) => new EE_Return_None_Where_Conditions(), |
|
69 | - ]; |
|
70 | - } |
|
57 | + /** |
|
58 | + * @return EE_Default_Where_Conditions[]|EE_Return_None_Where_Conditions[] |
|
59 | + * @throws EE_Error |
|
60 | + */ |
|
61 | + protected function _generate_restrictions(): array |
|
62 | + { |
|
63 | + // if there are no standard caps for this model, then for now all we know |
|
64 | + // if they need the default cap to access this |
|
65 | + if (! $this->model()->cap_slug()) { |
|
66 | + return [ |
|
67 | + self::get_default_restrictions_cap( |
|
68 | + ) => new EE_Return_None_Where_Conditions(), |
|
69 | + ]; |
|
70 | + } |
|
71 | 71 | |
72 | - $event_model = EEM_Event::instance(); |
|
72 | + $event_model = EEM_Event::instance(); |
|
73 | 73 | |
74 | - $restrictions = [ |
|
75 | - // first: basically access to non-defaults is essentially |
|
76 | - // controlled by which events are accessible |
|
77 | - // if they don't have the basic event cap, |
|
78 | - // they can't access ANY non-default items |
|
79 | - EE_Restriction_Generator_Base::get_cap_name( |
|
80 | - $event_model, |
|
81 | - $this->action() |
|
82 | - ) => new EE_Default_Where_Conditions( |
|
83 | - [ |
|
84 | - 'OR*no_' . |
|
85 | - EE_Restriction_Generator_Base::get_cap_name( |
|
86 | - $event_model, |
|
87 | - $this->action() |
|
88 | - ) => $this->addPublishedPostConditions( |
|
89 | - [ |
|
90 | - $this->_default_field_name => true, |
|
91 | - ], |
|
92 | - true, |
|
93 | - $this->_path_to_event_model |
|
94 | - ), |
|
95 | - ] |
|
96 | - ), |
|
97 | - // if they don't have the others event cap, |
|
98 | - // they can only access their own, |
|
99 | - // others' that are for published events, or defaults |
|
100 | - EE_Restriction_Generator_Base::get_cap_name( |
|
101 | - $event_model, |
|
102 | - $this->action() . '_others' |
|
103 | - ) => new EE_Default_Where_Conditions( |
|
104 | - [ |
|
105 | - 'OR*no_' . |
|
106 | - EE_Restriction_Generator_Base::get_cap_name( |
|
107 | - $event_model, |
|
108 | - $this->action() . '_others' |
|
109 | - ) => $this->addPublishedPostConditions( |
|
110 | - [ |
|
111 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
112 | - $this->_default_field_name => true, |
|
113 | - ], |
|
114 | - true, |
|
115 | - $this->_path_to_event_model |
|
116 | - ), |
|
117 | - ] |
|
118 | - ), |
|
119 | - // if they have basic and others, but not private, |
|
120 | - // they can access default, their own, |
|
121 | - // and others' that aren't private |
|
122 | - EE_Restriction_Generator_Base::get_cap_name( |
|
123 | - $event_model, |
|
124 | - $this->action() . '_private' |
|
125 | - ) => new EE_Default_Where_Conditions( |
|
126 | - [ |
|
127 | - 'OR*no_' . |
|
128 | - EE_Restriction_Generator_Base::get_cap_name( |
|
129 | - $event_model, |
|
130 | - $this->action() . '_private' |
|
131 | - ) => $this->addPublishedPostConditions( |
|
132 | - [ |
|
133 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
134 | - $this->_default_field_name => true, |
|
135 | - ], |
|
136 | - false, |
|
137 | - $this->_path_to_event_model |
|
138 | - ), |
|
139 | - ] |
|
140 | - ), |
|
141 | - // second: access to defaults is controlled |
|
142 | - // by the default capabilities |
|
143 | - // if they don't have the basic default capability, |
|
144 | - // restrict access to only non-default items |
|
145 | - EE_Restriction_Generator_Base::get_cap_name( |
|
146 | - $this->model(), |
|
147 | - $this->action() . '_default' |
|
148 | - ) => new EE_Default_Where_Conditions( |
|
149 | - [$this->_default_field_name => false] |
|
150 | - ), |
|
151 | - ]; |
|
152 | - if ( |
|
153 | - EE_Restriction_Generator_Base::is_cap( |
|
154 | - $this->model(), |
|
155 | - $this->action() . '_others_default' |
|
156 | - ) |
|
157 | - ) { |
|
158 | - // if they don't have the "others" default capability, |
|
159 | - // restrict access to only their default ones, and non-default ones |
|
160 | - $restrictions[ EE_Restriction_Generator_Base::get_cap_name( |
|
161 | - $this->model(), |
|
162 | - $this->action() . '_others_default' |
|
163 | - ) ] = new EE_Default_Where_Conditions( |
|
164 | - [ |
|
165 | - // if they don't have the others default cap, |
|
166 | - // they can't access others default items |
|
167 | - // (but they can access their own default items, |
|
168 | - // and non-default items) |
|
169 | - 'OR*no_' . |
|
170 | - EE_Restriction_Generator_Base::get_cap_name( |
|
171 | - $this->model(), |
|
172 | - $this->action() . '_others_default' |
|
173 | - ) => [ |
|
174 | - 'AND' => [ |
|
175 | - EE_QUERY_PLACEHOLDER_USER_FIELD_NAME => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
176 | - $this->_default_field_name => true |
|
177 | - ], |
|
178 | - $this->_default_field_name => false |
|
179 | - ] |
|
180 | - ] |
|
181 | - ); |
|
182 | - } |
|
183 | - return $restrictions; |
|
184 | - } |
|
74 | + $restrictions = [ |
|
75 | + // first: basically access to non-defaults is essentially |
|
76 | + // controlled by which events are accessible |
|
77 | + // if they don't have the basic event cap, |
|
78 | + // they can't access ANY non-default items |
|
79 | + EE_Restriction_Generator_Base::get_cap_name( |
|
80 | + $event_model, |
|
81 | + $this->action() |
|
82 | + ) => new EE_Default_Where_Conditions( |
|
83 | + [ |
|
84 | + 'OR*no_' . |
|
85 | + EE_Restriction_Generator_Base::get_cap_name( |
|
86 | + $event_model, |
|
87 | + $this->action() |
|
88 | + ) => $this->addPublishedPostConditions( |
|
89 | + [ |
|
90 | + $this->_default_field_name => true, |
|
91 | + ], |
|
92 | + true, |
|
93 | + $this->_path_to_event_model |
|
94 | + ), |
|
95 | + ] |
|
96 | + ), |
|
97 | + // if they don't have the others event cap, |
|
98 | + // they can only access their own, |
|
99 | + // others' that are for published events, or defaults |
|
100 | + EE_Restriction_Generator_Base::get_cap_name( |
|
101 | + $event_model, |
|
102 | + $this->action() . '_others' |
|
103 | + ) => new EE_Default_Where_Conditions( |
|
104 | + [ |
|
105 | + 'OR*no_' . |
|
106 | + EE_Restriction_Generator_Base::get_cap_name( |
|
107 | + $event_model, |
|
108 | + $this->action() . '_others' |
|
109 | + ) => $this->addPublishedPostConditions( |
|
110 | + [ |
|
111 | + $this->_path_to_event_model . 'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
112 | + $this->_default_field_name => true, |
|
113 | + ], |
|
114 | + true, |
|
115 | + $this->_path_to_event_model |
|
116 | + ), |
|
117 | + ] |
|
118 | + ), |
|
119 | + // if they have basic and others, but not private, |
|
120 | + // they can access default, their own, |
|
121 | + // and others' that aren't private |
|
122 | + EE_Restriction_Generator_Base::get_cap_name( |
|
123 | + $event_model, |
|
124 | + $this->action() . '_private' |
|
125 | + ) => new EE_Default_Where_Conditions( |
|
126 | + [ |
|
127 | + 'OR*no_' . |
|
128 | + EE_Restriction_Generator_Base::get_cap_name( |
|
129 | + $event_model, |
|
130 | + $this->action() . '_private' |
|
131 | + ) => $this->addPublishedPostConditions( |
|
132 | + [ |
|
133 | + $this->_path_to_event_model . 'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
134 | + $this->_default_field_name => true, |
|
135 | + ], |
|
136 | + false, |
|
137 | + $this->_path_to_event_model |
|
138 | + ), |
|
139 | + ] |
|
140 | + ), |
|
141 | + // second: access to defaults is controlled |
|
142 | + // by the default capabilities |
|
143 | + // if they don't have the basic default capability, |
|
144 | + // restrict access to only non-default items |
|
145 | + EE_Restriction_Generator_Base::get_cap_name( |
|
146 | + $this->model(), |
|
147 | + $this->action() . '_default' |
|
148 | + ) => new EE_Default_Where_Conditions( |
|
149 | + [$this->_default_field_name => false] |
|
150 | + ), |
|
151 | + ]; |
|
152 | + if ( |
|
153 | + EE_Restriction_Generator_Base::is_cap( |
|
154 | + $this->model(), |
|
155 | + $this->action() . '_others_default' |
|
156 | + ) |
|
157 | + ) { |
|
158 | + // if they don't have the "others" default capability, |
|
159 | + // restrict access to only their default ones, and non-default ones |
|
160 | + $restrictions[ EE_Restriction_Generator_Base::get_cap_name( |
|
161 | + $this->model(), |
|
162 | + $this->action() . '_others_default' |
|
163 | + ) ] = new EE_Default_Where_Conditions( |
|
164 | + [ |
|
165 | + // if they don't have the others default cap, |
|
166 | + // they can't access others default items |
|
167 | + // (but they can access their own default items, |
|
168 | + // and non-default items) |
|
169 | + 'OR*no_' . |
|
170 | + EE_Restriction_Generator_Base::get_cap_name( |
|
171 | + $this->model(), |
|
172 | + $this->action() . '_others_default' |
|
173 | + ) => [ |
|
174 | + 'AND' => [ |
|
175 | + EE_QUERY_PLACEHOLDER_USER_FIELD_NAME => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
176 | + $this->_default_field_name => true |
|
177 | + ], |
|
178 | + $this->_default_field_name => false |
|
179 | + ] |
|
180 | + ] |
|
181 | + ); |
|
182 | + } |
|
183 | + return $restrictions; |
|
184 | + } |
|
185 | 185 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | { |
90 | 90 | // if there are no standard caps for this model, then for now |
91 | 91 | // all we know if they need the default cap to access this |
92 | - if (! $this->model()->cap_slug()) { |
|
92 | + if ( ! $this->model()->cap_slug()) { |
|
93 | 93 | return [ |
94 | 94 | self::get_default_restrictions_cap( |
95 | 95 | ) => new EE_Return_None_Where_Conditions(), |
@@ -110,26 +110,26 @@ discard block |
||
110 | 110 | // they can't access others' non-default items |
111 | 111 | EE_Restriction_Generator_Base::get_cap_name( |
112 | 112 | $event_model, |
113 | - $this->action_for_event() . '_others' |
|
113 | + $this->action_for_event().'_others' |
|
114 | 114 | ) => new EE_Default_Where_Conditions( |
115 | 115 | [ |
116 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
116 | + $this->_path_to_event_model.'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
117 | 117 | ] |
118 | 118 | ), |
119 | 119 | // if they have basic and others, but not private, |
120 | 120 | // they can't access others' private non-default items |
121 | 121 | EE_Restriction_Generator_Base::get_cap_name( |
122 | 122 | $event_model, |
123 | - $this->action_for_event() . '_private' |
|
123 | + $this->action_for_event().'_private' |
|
124 | 124 | ) => new EE_Default_Where_Conditions( |
125 | 125 | [ |
126 | - 'OR*no_' . |
|
126 | + 'OR*no_'. |
|
127 | 127 | EE_Restriction_Generator_Base::get_cap_name( |
128 | 128 | $event_model, |
129 | - $this->action_for_event() . '_private' |
|
129 | + $this->action_for_event().'_private' |
|
130 | 130 | ) => $this->addPublishedPostConditions( |
131 | 131 | [ |
132 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
132 | + $this->_path_to_event_model.'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
133 | 133 | ], |
134 | 134 | false, |
135 | 135 | $this->_path_to_event_model |
@@ -13,128 +13,128 @@ |
||
13 | 13 | */ |
14 | 14 | class EE_Restriction_Generator_Event_Related_Protected extends EE_Restriction_Generator_Base |
15 | 15 | { |
16 | - /** |
|
17 | - * Path to the event model from the model this restriction generator will |
|
18 | - * be applied to; including the event model itself. Eg |
|
19 | - * "Ticket.Datetime.Event" |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $_path_to_event_model = null; |
|
16 | + /** |
|
17 | + * Path to the event model from the model this restriction generator will |
|
18 | + * be applied to; including the event model itself. Eg |
|
19 | + * "Ticket.Datetime.Event" |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $_path_to_event_model = null; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Capability context on event model when creating restrictions. |
|
27 | - * Eg, although we may want capability restrictions relating to deleting |
|
28 | - * datetimes, they don't need to be able to DELETE EVENTS, they just need |
|
29 | - * to be able to EDIT EVENTS in order to DELETE DATETIMES. |
|
30 | - * |
|
31 | - * @var string one of EEM_Base::valid_cap_contexts() |
|
32 | - */ |
|
33 | - protected $_cap_context_on_event_model = null; |
|
25 | + /** |
|
26 | + * Capability context on event model when creating restrictions. |
|
27 | + * Eg, although we may want capability restrictions relating to deleting |
|
28 | + * datetimes, they don't need to be able to DELETE EVENTS, they just need |
|
29 | + * to be able to EDIT EVENTS in order to DELETE DATETIMES. |
|
30 | + * |
|
31 | + * @var string one of EEM_Base::valid_cap_contexts() |
|
32 | + */ |
|
33 | + protected $_cap_context_on_event_model = null; |
|
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * @param string $path_to_event_model |
|
38 | - * @param string $cap_context_on_event_model capability context on event |
|
39 | - * model when creating |
|
40 | - * restrictions. Eg, although we |
|
41 | - * may want capability |
|
42 | - * restrictions relating to |
|
43 | - * deleting datetimes, they don't |
|
44 | - * need to be able to DELETE |
|
45 | - * EVENTS, they just need to be |
|
46 | - * able to EDIT EVENTS in order |
|
47 | - * to DELETE DATETIMES. If none |
|
48 | - * if provided, assumed to be the |
|
49 | - * same as on the primary model. |
|
50 | - */ |
|
51 | - public function __construct( |
|
52 | - string $path_to_event_model, |
|
53 | - string $cap_context_on_event_model = '' |
|
54 | - ) { |
|
55 | - if (substr($path_to_event_model, -1, 1) != '.') { |
|
56 | - $path_to_event_model .= '.'; |
|
57 | - } |
|
58 | - $this->_path_to_event_model = $path_to_event_model; |
|
59 | - $this->_cap_context_on_event_model = $cap_context_on_event_model; |
|
60 | - } |
|
36 | + /** |
|
37 | + * @param string $path_to_event_model |
|
38 | + * @param string $cap_context_on_event_model capability context on event |
|
39 | + * model when creating |
|
40 | + * restrictions. Eg, although we |
|
41 | + * may want capability |
|
42 | + * restrictions relating to |
|
43 | + * deleting datetimes, they don't |
|
44 | + * need to be able to DELETE |
|
45 | + * EVENTS, they just need to be |
|
46 | + * able to EDIT EVENTS in order |
|
47 | + * to DELETE DATETIMES. If none |
|
48 | + * if provided, assumed to be the |
|
49 | + * same as on the primary model. |
|
50 | + */ |
|
51 | + public function __construct( |
|
52 | + string $path_to_event_model, |
|
53 | + string $cap_context_on_event_model = '' |
|
54 | + ) { |
|
55 | + if (substr($path_to_event_model, -1, 1) != '.') { |
|
56 | + $path_to_event_model .= '.'; |
|
57 | + } |
|
58 | + $this->_path_to_event_model = $path_to_event_model; |
|
59 | + $this->_cap_context_on_event_model = $cap_context_on_event_model; |
|
60 | + } |
|
61 | 61 | |
62 | 62 | |
63 | - /** |
|
64 | - * Returns `$this->_cap_context_on_event_model`, the relevant action |
|
65 | - * ("read", |
|
66 | - * "read_admin", "edit" or "delete") for the EVENT related to this model. |
|
67 | - * |
|
68 | - * @return string one of EEM_Base::valid_cap_contexts() |
|
69 | - * @throws EE_Error |
|
70 | - * @see EE_Restriction_Generator_Event_Related_Protected::__construct() |
|
71 | - */ |
|
72 | - protected function action_for_event(): ?string |
|
73 | - { |
|
74 | - if ($this->_cap_context_on_event_model) { |
|
75 | - return $this->_cap_context_on_event_model; |
|
76 | - } else { |
|
77 | - return $this->action(); |
|
78 | - } |
|
79 | - } |
|
63 | + /** |
|
64 | + * Returns `$this->_cap_context_on_event_model`, the relevant action |
|
65 | + * ("read", |
|
66 | + * "read_admin", "edit" or "delete") for the EVENT related to this model. |
|
67 | + * |
|
68 | + * @return string one of EEM_Base::valid_cap_contexts() |
|
69 | + * @throws EE_Error |
|
70 | + * @see EE_Restriction_Generator_Event_Related_Protected::__construct() |
|
71 | + */ |
|
72 | + protected function action_for_event(): ?string |
|
73 | + { |
|
74 | + if ($this->_cap_context_on_event_model) { |
|
75 | + return $this->_cap_context_on_event_model; |
|
76 | + } else { |
|
77 | + return $this->action(); |
|
78 | + } |
|
79 | + } |
|
80 | 80 | |
81 | 81 | |
82 | - /** |
|
83 | - * @return EE_Default_Where_Conditions[]|EE_Return_None_Where_Conditions[] |
|
84 | - * @throws EE_Error |
|
85 | - * @throws EE_Error |
|
86 | - */ |
|
87 | - protected function _generate_restrictions(): array |
|
88 | - { |
|
89 | - // if there are no standard caps for this model, then for now |
|
90 | - // all we know if they need the default cap to access this |
|
91 | - if (! $this->model()->cap_slug()) { |
|
92 | - return [ |
|
93 | - self::get_default_restrictions_cap( |
|
94 | - ) => new EE_Return_None_Where_Conditions(), |
|
95 | - ]; |
|
96 | - } |
|
82 | + /** |
|
83 | + * @return EE_Default_Where_Conditions[]|EE_Return_None_Where_Conditions[] |
|
84 | + * @throws EE_Error |
|
85 | + * @throws EE_Error |
|
86 | + */ |
|
87 | + protected function _generate_restrictions(): array |
|
88 | + { |
|
89 | + // if there are no standard caps for this model, then for now |
|
90 | + // all we know if they need the default cap to access this |
|
91 | + if (! $this->model()->cap_slug()) { |
|
92 | + return [ |
|
93 | + self::get_default_restrictions_cap( |
|
94 | + ) => new EE_Return_None_Where_Conditions(), |
|
95 | + ]; |
|
96 | + } |
|
97 | 97 | |
98 | - $event_model = EEM_Event::instance(); |
|
99 | - return [ |
|
100 | - // first: basically access to non-defaults is essentially |
|
101 | - // controlled by which events are accessible |
|
102 | - // if they don't have the basic event cap, |
|
103 | - // they can't access ANY non-default items |
|
104 | - EE_Restriction_Generator_Base::get_cap_name( |
|
105 | - $event_model, |
|
106 | - $this->action_for_event() |
|
107 | - ) => new EE_Return_None_Where_Conditions(), |
|
108 | - // if they don't have the others event cap, |
|
109 | - // they can't access others' non-default items |
|
110 | - EE_Restriction_Generator_Base::get_cap_name( |
|
111 | - $event_model, |
|
112 | - $this->action_for_event() . '_others' |
|
113 | - ) => new EE_Default_Where_Conditions( |
|
114 | - [ |
|
115 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
116 | - ] |
|
117 | - ), |
|
118 | - // if they have basic and others, but not private, |
|
119 | - // they can't access others' private non-default items |
|
120 | - EE_Restriction_Generator_Base::get_cap_name( |
|
121 | - $event_model, |
|
122 | - $this->action_for_event() . '_private' |
|
123 | - ) => new EE_Default_Where_Conditions( |
|
124 | - [ |
|
125 | - 'OR*no_' . |
|
126 | - EE_Restriction_Generator_Base::get_cap_name( |
|
127 | - $event_model, |
|
128 | - $this->action_for_event() . '_private' |
|
129 | - ) => $this->addPublishedPostConditions( |
|
130 | - [ |
|
131 | - $this->_path_to_event_model . 'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
132 | - ], |
|
133 | - false, |
|
134 | - $this->_path_to_event_model |
|
135 | - ) |
|
136 | - ] |
|
137 | - ), |
|
138 | - ]; |
|
139 | - } |
|
98 | + $event_model = EEM_Event::instance(); |
|
99 | + return [ |
|
100 | + // first: basically access to non-defaults is essentially |
|
101 | + // controlled by which events are accessible |
|
102 | + // if they don't have the basic event cap, |
|
103 | + // they can't access ANY non-default items |
|
104 | + EE_Restriction_Generator_Base::get_cap_name( |
|
105 | + $event_model, |
|
106 | + $this->action_for_event() |
|
107 | + ) => new EE_Return_None_Where_Conditions(), |
|
108 | + // if they don't have the others event cap, |
|
109 | + // they can't access others' non-default items |
|
110 | + EE_Restriction_Generator_Base::get_cap_name( |
|
111 | + $event_model, |
|
112 | + $this->action_for_event() . '_others' |
|
113 | + ) => new EE_Default_Where_Conditions( |
|
114 | + [ |
|
115 | + $this->_path_to_event_model . 'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
116 | + ] |
|
117 | + ), |
|
118 | + // if they have basic and others, but not private, |
|
119 | + // they can't access others' private non-default items |
|
120 | + EE_Restriction_Generator_Base::get_cap_name( |
|
121 | + $event_model, |
|
122 | + $this->action_for_event() . '_private' |
|
123 | + ) => new EE_Default_Where_Conditions( |
|
124 | + [ |
|
125 | + 'OR*no_' . |
|
126 | + EE_Restriction_Generator_Base::get_cap_name( |
|
127 | + $event_model, |
|
128 | + $this->action_for_event() . '_private' |
|
129 | + ) => $this->addPublishedPostConditions( |
|
130 | + [ |
|
131 | + $this->_path_to_event_model . 'EVT_wp_user' => EE_QUERY_PLACEHOLDER_CURRENT_USER, |
|
132 | + ], |
|
133 | + false, |
|
134 | + $this->_path_to_event_model |
|
135 | + ) |
|
136 | + ] |
|
137 | + ), |
|
138 | + ]; |
|
139 | + } |
|
140 | 140 | } |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | */ |
297 | 297 | public function timestamp($dt_frmt = '', $tm_frmt = '') |
298 | 298 | { |
299 | - return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt . ' ' . $tm_frmt)); |
|
299 | + return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt.' '.$tm_frmt)); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | : ''; |
482 | 482 | break; |
483 | 483 | } |
484 | - return $icon . $status[ $this->STS_ID() ]; |
|
484 | + return $icon.$status[$this->STS_ID()]; |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | |
@@ -627,7 +627,7 @@ discard block |
||
627 | 627 | public function redirect_form($inside_form_html = null) |
628 | 628 | { |
629 | 629 | $redirect_url = $this->redirect_url(); |
630 | - if (! empty($redirect_url)) { |
|
630 | + if ( ! empty($redirect_url)) { |
|
631 | 631 | // what ? no inner form content? |
632 | 632 | if ($inside_form_html === null) { |
633 | 633 | $inside_form_html = EEH_HTML::p( |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | $get_params = null; |
658 | 658 | parse_str($querystring, $get_params); |
659 | 659 | $inside_form_html .= $this->_args_as_inputs($get_params); |
660 | - $redirect_url = str_replace('?' . $querystring, '', $redirect_url); |
|
660 | + $redirect_url = str_replace('?'.$querystring, '', $redirect_url); |
|
661 | 661 | } |
662 | 662 | $form = EEH_HTML::nl(1) |
663 | 663 | . '<form method="' |
@@ -665,9 +665,9 @@ discard block |
||
665 | 665 | . '" name="gateway_form" action="' |
666 | 666 | . $redirect_url |
667 | 667 | . '">'; |
668 | - $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs(); |
|
668 | + $form .= EEH_HTML::nl(1).$this->redirect_args_as_inputs(); |
|
669 | 669 | $form .= $inside_form_html; |
670 | - $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1); |
|
670 | + $form .= EEH_HTML::nl(-1).'</form>'.EEH_HTML::nl(-1); |
|
671 | 671 | return $form; |
672 | 672 | } else { |
673 | 673 | return null; |
@@ -725,8 +725,8 @@ discard block |
||
725 | 725 | return $html; |
726 | 726 | } |
727 | 727 | return EEH_HTML::nl() |
728 | - . '<input type="hidden" name="' . $name . '"' |
|
729 | - . ' value="' . esc_attr($value) . '"/>'; |
|
728 | + . '<input type="hidden" name="'.$name.'"' |
|
729 | + . ' value="'.esc_attr($value).'"/>'; |
|
730 | 730 | } |
731 | 731 | |
732 | 732 |
@@ -11,874 +11,874 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Payment extends EE_Base_Class implements EEI_Payment |
13 | 13 | { |
14 | - /** |
|
15 | - * @param array $props_n_values incoming values |
|
16 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
17 | - * used.) |
|
18 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
19 | - * date_format and the second value is the time format |
|
20 | - * @return EE_Payment |
|
21 | - * @throws EE_Error|ReflectionException |
|
22 | - */ |
|
23 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
24 | - { |
|
25 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
26 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
27 | - } |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * @param array $props_n_values incoming values from the database |
|
32 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
33 | - * the website will be used. |
|
34 | - * @return EE_Payment |
|
35 | - * @throws EE_Error |
|
36 | - */ |
|
37 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
38 | - { |
|
39 | - return new self($props_n_values, true, $timezone); |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * Set Transaction ID |
|
45 | - * |
|
46 | - * @access public |
|
47 | - * @param int $TXN_ID |
|
48 | - * @throws EE_Error |
|
49 | - */ |
|
50 | - public function set_transaction_id($TXN_ID = 0) |
|
51 | - { |
|
52 | - $this->set('TXN_ID', $TXN_ID); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * Gets the transaction related to this payment |
|
58 | - * |
|
59 | - * @return EE_Transaction |
|
60 | - * @throws EE_Error |
|
61 | - */ |
|
62 | - public function transaction() |
|
63 | - { |
|
64 | - return $this->get_first_related('Transaction'); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * Set Status |
|
70 | - * |
|
71 | - * @access public |
|
72 | - * @param string $STS_ID |
|
73 | - * @throws EE_Error |
|
74 | - */ |
|
75 | - public function set_status($STS_ID = '') |
|
76 | - { |
|
77 | - $this->set('STS_ID', $STS_ID); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * Set Payment Timestamp |
|
83 | - * |
|
84 | - * @access public |
|
85 | - * @param int $timestamp |
|
86 | - * @throws EE_Error |
|
87 | - */ |
|
88 | - public function set_timestamp($timestamp = 0) |
|
89 | - { |
|
90 | - $this->set('PAY_timestamp', $timestamp); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * Set Payment Method |
|
96 | - * |
|
97 | - * @access public |
|
98 | - * @param string $PAY_source |
|
99 | - * @throws EE_Error |
|
100 | - */ |
|
101 | - public function set_source($PAY_source = '') |
|
102 | - { |
|
103 | - $this->set('PAY_source', $PAY_source); |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * Set Payment Amount |
|
109 | - * |
|
110 | - * @access public |
|
111 | - * @param float $amount |
|
112 | - * @throws EE_Error |
|
113 | - */ |
|
114 | - public function set_amount($amount = 0.00) |
|
115 | - { |
|
116 | - $this->set('PAY_amount', (float) $amount); |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * Set Payment Gateway Response |
|
122 | - * |
|
123 | - * @access public |
|
124 | - * @param string $gateway_response |
|
125 | - * @throws EE_Error |
|
126 | - */ |
|
127 | - public function set_gateway_response($gateway_response = '') |
|
128 | - { |
|
129 | - $this->set('PAY_gateway_response', $gateway_response); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * Returns the name of the payment method used on this payment (previously known merely as 'gateway') |
|
135 | - * but since 4.6.0, payment methods are models and the payment keeps a foreign key to the payment method |
|
136 | - * used on it |
|
137 | - * |
|
138 | - * @return string |
|
139 | - * @throws EE_Error |
|
140 | - * @deprecated |
|
141 | - */ |
|
142 | - public function gateway() |
|
143 | - { |
|
144 | - EE_Error::doing_it_wrong( |
|
145 | - 'EE_Payment::gateway', |
|
146 | - esc_html__( |
|
147 | - 'The method EE_Payment::gateway() has been deprecated. Consider instead using EE_Payment::payment_method()->name()', |
|
148 | - 'event_espresso' |
|
149 | - ), |
|
150 | - '4.6.0' |
|
151 | - ); |
|
152 | - return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso'); |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * Set Gateway Transaction ID |
|
158 | - * |
|
159 | - * @access public |
|
160 | - * @param string $txn_id_chq_nmbr |
|
161 | - * @throws EE_Error |
|
162 | - */ |
|
163 | - public function set_txn_id_chq_nmbr($txn_id_chq_nmbr = '') |
|
164 | - { |
|
165 | - $this->set('PAY_txn_id_chq_nmbr', $txn_id_chq_nmbr); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * Set Purchase Order Number |
|
171 | - * |
|
172 | - * @access public |
|
173 | - * @param string $po_number |
|
174 | - * @throws EE_Error |
|
175 | - */ |
|
176 | - public function set_po_number($po_number = '') |
|
177 | - { |
|
178 | - $this->set('PAY_po_number', $po_number); |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * Set Extra Accounting Field |
|
184 | - * |
|
185 | - * @access public |
|
186 | - * @param string $extra_accntng |
|
187 | - * @throws EE_Error |
|
188 | - */ |
|
189 | - public function set_extra_accntng($extra_accntng = '') |
|
190 | - { |
|
191 | - $this->set('PAY_extra_accntng', $extra_accntng); |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * Set Payment made via admin flag |
|
197 | - * |
|
198 | - * @access public |
|
199 | - * @param bool $via_admin |
|
200 | - * @throws EE_Error |
|
201 | - */ |
|
202 | - public function set_payment_made_via_admin($via_admin = false) |
|
203 | - { |
|
204 | - if ($via_admin) { |
|
205 | - $this->set('PAY_source', EEM_Payment_Method::scope_admin); |
|
206 | - } else { |
|
207 | - $this->set('PAY_source', EEM_Payment_Method::scope_cart); |
|
208 | - } |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * Set Payment Details |
|
214 | - * |
|
215 | - * @access public |
|
216 | - * @param string|array $details |
|
217 | - * @throws EE_Error |
|
218 | - */ |
|
219 | - public function set_details($details = '') |
|
220 | - { |
|
221 | - if (is_array($details)) { |
|
222 | - array_walk_recursive($details, array($this, '_strip_all_tags_within_array')); |
|
223 | - } else { |
|
224 | - $details = wp_strip_all_tags($details); |
|
225 | - } |
|
226 | - $this->set('PAY_details', $details); |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * Sets redirect_url |
|
232 | - * |
|
233 | - * @param string $redirect_url |
|
234 | - * @throws EE_Error |
|
235 | - */ |
|
236 | - public function set_redirect_url($redirect_url) |
|
237 | - { |
|
238 | - $this->set('PAY_redirect_url', $redirect_url); |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * Sets redirect_args |
|
244 | - * |
|
245 | - * @param array $redirect_args |
|
246 | - * @throws EE_Error |
|
247 | - */ |
|
248 | - public function set_redirect_args($redirect_args) |
|
249 | - { |
|
250 | - $this->set('PAY_redirect_args', $redirect_args); |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * get Payment Transaction ID |
|
256 | - * |
|
257 | - * @access public |
|
258 | - * @throws EE_Error |
|
259 | - */ |
|
260 | - public function TXN_ID() |
|
261 | - { |
|
262 | - return $this->get('TXN_ID'); |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - /** |
|
267 | - * get Payment Status |
|
268 | - * |
|
269 | - * @access public |
|
270 | - * @throws EE_Error |
|
271 | - */ |
|
272 | - public function status() |
|
273 | - { |
|
274 | - return $this->get('STS_ID'); |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * get Payment Status |
|
280 | - * |
|
281 | - * @access public |
|
282 | - * @throws EE_Error |
|
283 | - */ |
|
284 | - public function STS_ID() |
|
285 | - { |
|
286 | - return $this->get('STS_ID'); |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * get Payment Timestamp |
|
292 | - * |
|
293 | - * @access public |
|
294 | - * @param string $dt_frmt |
|
295 | - * @param string $tm_frmt |
|
296 | - * @return string |
|
297 | - * @throws EE_Error |
|
298 | - */ |
|
299 | - public function timestamp($dt_frmt = '', $tm_frmt = '') |
|
300 | - { |
|
301 | - return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt . ' ' . $tm_frmt)); |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * get Payment Source |
|
307 | - * |
|
308 | - * @access public |
|
309 | - * @throws EE_Error |
|
310 | - */ |
|
311 | - public function source() |
|
312 | - { |
|
313 | - return $this->get('PAY_source'); |
|
314 | - } |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * get Payment Amount |
|
319 | - * |
|
320 | - * @access public |
|
321 | - * @return float |
|
322 | - * @throws EE_Error |
|
323 | - */ |
|
324 | - public function amount() |
|
325 | - { |
|
326 | - return (float) $this->get('PAY_amount'); |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * @return mixed |
|
332 | - * @throws EE_Error |
|
333 | - */ |
|
334 | - public function amount_no_code() |
|
335 | - { |
|
336 | - return $this->get_pretty('PAY_amount', 'no_currency_code'); |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * get Payment Gateway Response |
|
342 | - * |
|
343 | - * @access public |
|
344 | - * @throws EE_Error |
|
345 | - */ |
|
346 | - public function gateway_response() |
|
347 | - { |
|
348 | - return $this->get('PAY_gateway_response'); |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * get Payment Gateway Transaction ID |
|
354 | - * |
|
355 | - * @access public |
|
356 | - * @throws EE_Error |
|
357 | - */ |
|
358 | - public function txn_id_chq_nmbr() |
|
359 | - { |
|
360 | - return $this->get('PAY_txn_id_chq_nmbr'); |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * get Purchase Order Number |
|
366 | - * |
|
367 | - * @access public |
|
368 | - * @throws EE_Error |
|
369 | - */ |
|
370 | - public function po_number() |
|
371 | - { |
|
372 | - return $this->get('PAY_po_number'); |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * get Extra Accounting Field |
|
378 | - * |
|
379 | - * @access public |
|
380 | - * @throws EE_Error |
|
381 | - */ |
|
382 | - public function extra_accntng() |
|
383 | - { |
|
384 | - return $this->get('PAY_extra_accntng'); |
|
385 | - } |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * get Payment made via admin source |
|
390 | - * |
|
391 | - * @access public |
|
392 | - * @throws EE_Error |
|
393 | - */ |
|
394 | - public function payment_made_via_admin() |
|
395 | - { |
|
396 | - return ($this->get('PAY_source') === EEM_Payment_Method::scope_admin); |
|
397 | - } |
|
398 | - |
|
399 | - |
|
400 | - /** |
|
401 | - * get Payment Details |
|
402 | - * |
|
403 | - * @access public |
|
404 | - * @throws EE_Error |
|
405 | - */ |
|
406 | - public function details() |
|
407 | - { |
|
408 | - return $this->get('PAY_details'); |
|
409 | - } |
|
410 | - |
|
411 | - |
|
412 | - /** |
|
413 | - * Gets redirect_url |
|
414 | - * |
|
415 | - * @return string |
|
416 | - * @throws EE_Error |
|
417 | - */ |
|
418 | - public function redirect_url() |
|
419 | - { |
|
420 | - return $this->get('PAY_redirect_url'); |
|
421 | - } |
|
422 | - |
|
423 | - |
|
424 | - /** |
|
425 | - * Gets redirect_args |
|
426 | - * |
|
427 | - * @return array |
|
428 | - * @throws EE_Error |
|
429 | - */ |
|
430 | - public function redirect_args() |
|
431 | - { |
|
432 | - return $this->get('PAY_redirect_args'); |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * echoes $this->pretty_status() |
|
438 | - * |
|
439 | - * @param bool $show_icons |
|
440 | - * @return void |
|
441 | - * @throws EE_Error |
|
442 | - */ |
|
443 | - public function e_pretty_status($show_icons = false) |
|
444 | - { |
|
445 | - echo wp_kses($this->pretty_status($show_icons), AllowedTags::getAllowedTags()); |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - /** |
|
450 | - * returns a pretty version of the status, good for displaying to users |
|
451 | - * |
|
452 | - * @param bool $show_icons |
|
453 | - * @return string |
|
454 | - * @throws EE_Error |
|
455 | - */ |
|
456 | - public function pretty_status($show_icons = false) |
|
457 | - { |
|
458 | - $status = EEM_Status::instance()->localized_status( |
|
459 | - array($this->STS_ID() => esc_html__('unknown', 'event_espresso')), |
|
460 | - false, |
|
461 | - 'sentence' |
|
462 | - ); |
|
463 | - $icon = ''; |
|
464 | - switch ($this->STS_ID()) { |
|
465 | - case EEM_Payment::status_id_approved: |
|
466 | - $icon = $show_icons |
|
467 | - ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' |
|
468 | - : ''; |
|
469 | - break; |
|
470 | - case EEM_Payment::status_id_pending: |
|
471 | - $icon = $show_icons |
|
472 | - ? '<span class="dashicons dashicons-clock ee-icon-size-16 orange-text"></span>' |
|
473 | - : ''; |
|
474 | - break; |
|
475 | - case EEM_Payment::status_id_cancelled: |
|
476 | - $icon = $show_icons |
|
477 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
478 | - : ''; |
|
479 | - break; |
|
480 | - case EEM_Payment::status_id_declined: |
|
481 | - $icon = $show_icons |
|
482 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
483 | - : ''; |
|
484 | - break; |
|
485 | - } |
|
486 | - return $icon . $status[ $this->STS_ID() ]; |
|
487 | - } |
|
488 | - |
|
489 | - |
|
490 | - /** |
|
491 | - * For determining the status of the payment |
|
492 | - * |
|
493 | - * @return boolean whether the payment is approved or not |
|
494 | - * @throws EE_Error |
|
495 | - */ |
|
496 | - public function is_approved() |
|
497 | - { |
|
498 | - return $this->status_is(EEM_Payment::status_id_approved); |
|
499 | - } |
|
500 | - |
|
501 | - |
|
502 | - /** |
|
503 | - * Generally determines if the status of this payment equals |
|
504 | - * the $STS_ID string |
|
505 | - * |
|
506 | - * @param string $STS_ID an ID from the esp_status table/ |
|
507 | - * one of the status_id_* on the EEM_Payment model |
|
508 | - * @return boolean whether the status of this payment equals the status id |
|
509 | - * @throws EE_Error |
|
510 | - */ |
|
511 | - protected function status_is($STS_ID) |
|
512 | - { |
|
513 | - return $STS_ID === $this->STS_ID() ? true : false; |
|
514 | - } |
|
515 | - |
|
516 | - |
|
517 | - /** |
|
518 | - * For determining the status of the payment |
|
519 | - * |
|
520 | - * @return boolean whether the payment is pending or not |
|
521 | - * @throws EE_Error |
|
522 | - */ |
|
523 | - public function is_pending() |
|
524 | - { |
|
525 | - return $this->status_is(EEM_Payment::status_id_pending); |
|
526 | - } |
|
527 | - |
|
528 | - |
|
529 | - /** |
|
530 | - * For determining the status of the payment |
|
531 | - * |
|
532 | - * @return boolean |
|
533 | - * @throws EE_Error |
|
534 | - */ |
|
535 | - public function is_cancelled() |
|
536 | - { |
|
537 | - return $this->status_is(EEM_Payment::status_id_cancelled); |
|
538 | - } |
|
539 | - |
|
540 | - |
|
541 | - /** |
|
542 | - * For determining the status of the payment |
|
543 | - * |
|
544 | - * @return boolean |
|
545 | - * @throws EE_Error |
|
546 | - */ |
|
547 | - public function is_declined() |
|
548 | - { |
|
549 | - return $this->status_is(EEM_Payment::status_id_declined); |
|
550 | - } |
|
551 | - |
|
552 | - |
|
553 | - /** |
|
554 | - * For determining the status of the payment |
|
555 | - * |
|
556 | - * @return boolean |
|
557 | - * @throws EE_Error |
|
558 | - */ |
|
559 | - public function is_failed() |
|
560 | - { |
|
561 | - return $this->status_is(EEM_Payment::status_id_failed); |
|
562 | - } |
|
563 | - |
|
564 | - |
|
565 | - /** |
|
566 | - * For determining if the payment is actually a refund ( ie: has a negative value ) |
|
567 | - * |
|
568 | - * @return boolean |
|
569 | - * @throws EE_Error |
|
570 | - */ |
|
571 | - public function is_a_refund() |
|
572 | - { |
|
573 | - return $this->amount() < 0 ? true : false; |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * Get the status object of this object |
|
579 | - * |
|
580 | - * @return EE_Status |
|
581 | - * @throws EE_Error |
|
582 | - */ |
|
583 | - public function status_obj() |
|
584 | - { |
|
585 | - return $this->get_first_related('Status'); |
|
586 | - } |
|
587 | - |
|
588 | - |
|
589 | - /** |
|
590 | - * Gets all the extra meta info on this payment |
|
591 | - * |
|
592 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
593 | - * @return EE_Extra_Meta |
|
594 | - * @throws EE_Error |
|
595 | - */ |
|
596 | - public function extra_meta($query_params = array()) |
|
597 | - { |
|
598 | - return $this->get_many_related('Extra_Meta', $query_params); |
|
599 | - } |
|
600 | - |
|
601 | - |
|
602 | - /** |
|
603 | - * Gets the last-used payment method on this transaction |
|
604 | - * (we COULD just use the last-made payment, but some payment methods, namely |
|
605 | - * offline ones, dont' create payments) |
|
606 | - * |
|
607 | - * @return EE_Payment_Method |
|
608 | - * @throws EE_Error |
|
609 | - */ |
|
610 | - public function payment_method() |
|
611 | - { |
|
612 | - return $this->get_first_related('Payment_Method'); |
|
613 | - } |
|
614 | - |
|
615 | - |
|
616 | - /** |
|
617 | - * Gets the HTML for redirecting the user to an offsite gateway |
|
618 | - * You can pass it special content to put inside the form, or use |
|
619 | - * the default inner content (or possibly generate this all yourself using |
|
620 | - * redirect_url() and redirect_args() or redirect_args_as_inputs()). |
|
621 | - * Creates a POST request by default, but if no redirect args are specified, creates a GET request instead |
|
622 | - * (and any querystring variables in the redirect_url are converted into html inputs |
|
623 | - * so browsers submit them properly) |
|
624 | - * |
|
625 | - * @param string $inside_form_html |
|
626 | - * @return string html |
|
627 | - * @throws EE_Error |
|
628 | - */ |
|
629 | - public function redirect_form($inside_form_html = null) |
|
630 | - { |
|
631 | - $redirect_url = $this->redirect_url(); |
|
632 | - if (! empty($redirect_url)) { |
|
633 | - // what ? no inner form content? |
|
634 | - if ($inside_form_html === null) { |
|
635 | - $inside_form_html = EEH_HTML::p( |
|
636 | - sprintf( |
|
637 | - esc_html__( |
|
638 | - 'If you are not automatically redirected to the payment website within 10 seconds... %1$s %2$s Click Here %3$s', |
|
639 | - 'event_espresso' |
|
640 | - ), |
|
641 | - EEH_HTML::br(2), |
|
642 | - '<input type="submit" value="', |
|
643 | - '">' |
|
644 | - ), |
|
645 | - '', |
|
646 | - '', |
|
647 | - 'text-align:center;' |
|
648 | - ); |
|
649 | - } |
|
650 | - $method = apply_filters( |
|
651 | - 'FHEE__EE_Payment__redirect_form__method', |
|
652 | - $this->redirect_args() ? 'POST' : 'GET', |
|
653 | - $this |
|
654 | - ); |
|
655 | - // if it's a GET request, we need to remove all the GET params in the querystring |
|
656 | - // and put them into the form instead |
|
657 | - if ($method === 'GET') { |
|
658 | - $querystring = parse_url($redirect_url, PHP_URL_QUERY); |
|
659 | - $get_params = null; |
|
660 | - parse_str($querystring, $get_params); |
|
661 | - $inside_form_html .= $this->_args_as_inputs($get_params); |
|
662 | - $redirect_url = str_replace('?' . $querystring, '', $redirect_url); |
|
663 | - } |
|
664 | - $form = EEH_HTML::nl(1) |
|
665 | - . '<form method="' |
|
666 | - . $method |
|
667 | - . '" name="gateway_form" action="' |
|
668 | - . $redirect_url |
|
669 | - . '">'; |
|
670 | - $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs(); |
|
671 | - $form .= $inside_form_html; |
|
672 | - $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1); |
|
673 | - return $form; |
|
674 | - } else { |
|
675 | - return null; |
|
676 | - } |
|
677 | - } |
|
678 | - |
|
679 | - |
|
680 | - /** |
|
681 | - * Changes all the name-value pairs of the redirect args into html inputs |
|
682 | - * and returns the html as a string |
|
683 | - * |
|
684 | - * @return string |
|
685 | - * @throws EE_Error |
|
686 | - */ |
|
687 | - public function redirect_args_as_inputs() |
|
688 | - { |
|
689 | - return $this->_args_as_inputs($this->redirect_args()); |
|
690 | - } |
|
691 | - |
|
692 | - |
|
693 | - /** |
|
694 | - * Converts a 2d array of key-value pairs into html hidden inputs |
|
695 | - * and returns the string of html |
|
696 | - * |
|
697 | - * @param array $args key-value pairs |
|
698 | - * @return string |
|
699 | - */ |
|
700 | - protected function _args_as_inputs($args) |
|
701 | - { |
|
702 | - $html = ''; |
|
703 | - if ($args !== null && is_array($args)) { |
|
704 | - foreach ($args as $name => $value) { |
|
705 | - $html .= $this->generateInput($name, $value); |
|
706 | - } |
|
707 | - } |
|
708 | - return $html; |
|
709 | - } |
|
710 | - |
|
711 | - /** |
|
712 | - * Converts either a single name and value or array of values into html hidden inputs |
|
713 | - * and returns the string of html |
|
714 | - * |
|
715 | - * @param string $name |
|
716 | - * @param string|array $value |
|
717 | - * @return string |
|
718 | - */ |
|
719 | - private function generateInput($name, $value) |
|
720 | - { |
|
721 | - if (is_array($value)) { |
|
722 | - $html = ''; |
|
723 | - $name = "{$name}[]"; |
|
724 | - foreach ($value as $array_value) { |
|
725 | - $html .= $this->generateInput($name, $array_value); |
|
726 | - } |
|
727 | - return $html; |
|
728 | - } |
|
729 | - return EEH_HTML::nl() |
|
730 | - . '<input type="hidden" name="' . $name . '"' |
|
731 | - . ' value="' . esc_attr($value) . '"/>'; |
|
732 | - } |
|
733 | - |
|
734 | - |
|
735 | - /** |
|
736 | - * Returns the currency of the payment. |
|
737 | - * (At the time of writing, this will always be the currency in the configuration; |
|
738 | - * however in the future it is anticipated that this will be stored on the payment |
|
739 | - * object itself) |
|
740 | - * |
|
741 | - * @return string for the currency code |
|
742 | - */ |
|
743 | - public function currency_code() |
|
744 | - { |
|
745 | - return EE_Config::instance()->currency->code; |
|
746 | - } |
|
747 | - |
|
748 | - |
|
749 | - /** |
|
750 | - * apply wp_strip_all_tags to all elements within an array |
|
751 | - * |
|
752 | - * @access private |
|
753 | - * @param mixed $item |
|
754 | - */ |
|
755 | - private function _strip_all_tags_within_array(&$item) |
|
756 | - { |
|
757 | - if (is_object($item)) { |
|
758 | - $item = (array) $item; |
|
759 | - } |
|
760 | - if (is_array($item)) { |
|
761 | - array_walk_recursive($item, array($this, '_strip_all_tags_within_array')); |
|
762 | - } else { |
|
763 | - $item = wp_strip_all_tags((string) $item); |
|
764 | - } |
|
765 | - } |
|
766 | - |
|
767 | - |
|
768 | - /** |
|
769 | - * Returns TRUE is this payment was set to approved during this request (or |
|
770 | - * is approved and was created during this request). False otherwise. |
|
771 | - * |
|
772 | - * @return boolean |
|
773 | - * @throws EE_Error |
|
774 | - */ |
|
775 | - public function just_approved() |
|
776 | - { |
|
777 | - $original_status = EEH_Array::is_set( |
|
778 | - $this->_props_n_values_provided_in_constructor, |
|
779 | - 'STS_ID', |
|
780 | - $this->get_model()->field_settings_for('STS_ID')->get_default_value() |
|
781 | - ); |
|
782 | - $current_status = $this->status(); |
|
783 | - if ( |
|
784 | - $original_status !== EEM_Payment::status_id_approved |
|
785 | - && $current_status === EEM_Payment::status_id_approved |
|
786 | - ) { |
|
787 | - return true; |
|
788 | - } else { |
|
789 | - return false; |
|
790 | - } |
|
791 | - } |
|
792 | - |
|
793 | - |
|
794 | - /** |
|
795 | - * Overrides parents' get_pretty() function just for legacy reasons |
|
796 | - * (to allow ticket https://events.codebasehq.com/projects/event-espresso/tickets/7420) |
|
797 | - * |
|
798 | - * @param string $field_name |
|
799 | - * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
800 | - * (in cases where the same property may be used for different outputs |
|
801 | - * - i.e. datetime, money etc.) |
|
802 | - * @return mixed |
|
803 | - * @throws EE_Error |
|
804 | - */ |
|
805 | - public function get_pretty($field_name, $extra_cache_ref = null) |
|
806 | - { |
|
807 | - if ($field_name === 'PAY_gateway') { |
|
808 | - return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso'); |
|
809 | - } |
|
810 | - return $this->_get_cached_property($field_name, true, $extra_cache_ref); |
|
811 | - } |
|
812 | - |
|
813 | - |
|
814 | - /** |
|
815 | - * Gets details regarding which registrations this payment was applied to |
|
816 | - * |
|
817 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
818 | - * @return EE_Registration_Payment[] |
|
819 | - * @throws EE_Error |
|
820 | - */ |
|
821 | - public function registration_payments($query_params = array()) |
|
822 | - { |
|
823 | - return $this->get_many_related('Registration_Payment', $query_params); |
|
824 | - } |
|
825 | - |
|
826 | - |
|
827 | - /** |
|
828 | - * Gets the first event for this payment (it's possible that it could be for multiple) |
|
829 | - * |
|
830 | - * @return EE_Event|null |
|
831 | - */ |
|
832 | - public function get_first_event() |
|
833 | - { |
|
834 | - $transaction = $this->transaction(); |
|
835 | - if ($transaction instanceof EE_Transaction) { |
|
836 | - $primary_registrant = $transaction->primary_registration(); |
|
837 | - if ($primary_registrant instanceof EE_Registration) { |
|
838 | - return $primary_registrant->event_obj(); |
|
839 | - } |
|
840 | - } |
|
841 | - return null; |
|
842 | - } |
|
843 | - |
|
844 | - |
|
845 | - /** |
|
846 | - * Gets the name of the first event for which is being paid |
|
847 | - * |
|
848 | - * @return string |
|
849 | - */ |
|
850 | - public function get_first_event_name() |
|
851 | - { |
|
852 | - $event = $this->get_first_event(); |
|
853 | - return $event instanceof EE_Event ? $event->name() : esc_html__('Event', 'event_espresso'); |
|
854 | - } |
|
855 | - |
|
856 | - |
|
857 | - /** |
|
858 | - * Returns the payment's transaction's primary registration |
|
859 | - * |
|
860 | - * @return EE_Registration|null |
|
861 | - */ |
|
862 | - public function get_primary_registration() |
|
863 | - { |
|
864 | - if ($this->transaction() instanceof EE_Transaction) { |
|
865 | - return $this->transaction()->primary_registration(); |
|
866 | - } |
|
867 | - return null; |
|
868 | - } |
|
869 | - |
|
870 | - |
|
871 | - /** |
|
872 | - * Gets the payment's transaction's primary registration's attendee, or null |
|
873 | - * |
|
874 | - * @return EE_Attendee|null |
|
875 | - */ |
|
876 | - public function get_primary_attendee() |
|
877 | - { |
|
878 | - $primary_reg = $this->get_primary_registration(); |
|
879 | - if ($primary_reg instanceof EE_Registration) { |
|
880 | - return $primary_reg->attendee(); |
|
881 | - } |
|
882 | - return null; |
|
883 | - } |
|
14 | + /** |
|
15 | + * @param array $props_n_values incoming values |
|
16 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
17 | + * used.) |
|
18 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
19 | + * date_format and the second value is the time format |
|
20 | + * @return EE_Payment |
|
21 | + * @throws EE_Error|ReflectionException |
|
22 | + */ |
|
23 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
24 | + { |
|
25 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
26 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
27 | + } |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * @param array $props_n_values incoming values from the database |
|
32 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
33 | + * the website will be used. |
|
34 | + * @return EE_Payment |
|
35 | + * @throws EE_Error |
|
36 | + */ |
|
37 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
38 | + { |
|
39 | + return new self($props_n_values, true, $timezone); |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * Set Transaction ID |
|
45 | + * |
|
46 | + * @access public |
|
47 | + * @param int $TXN_ID |
|
48 | + * @throws EE_Error |
|
49 | + */ |
|
50 | + public function set_transaction_id($TXN_ID = 0) |
|
51 | + { |
|
52 | + $this->set('TXN_ID', $TXN_ID); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * Gets the transaction related to this payment |
|
58 | + * |
|
59 | + * @return EE_Transaction |
|
60 | + * @throws EE_Error |
|
61 | + */ |
|
62 | + public function transaction() |
|
63 | + { |
|
64 | + return $this->get_first_related('Transaction'); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * Set Status |
|
70 | + * |
|
71 | + * @access public |
|
72 | + * @param string $STS_ID |
|
73 | + * @throws EE_Error |
|
74 | + */ |
|
75 | + public function set_status($STS_ID = '') |
|
76 | + { |
|
77 | + $this->set('STS_ID', $STS_ID); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * Set Payment Timestamp |
|
83 | + * |
|
84 | + * @access public |
|
85 | + * @param int $timestamp |
|
86 | + * @throws EE_Error |
|
87 | + */ |
|
88 | + public function set_timestamp($timestamp = 0) |
|
89 | + { |
|
90 | + $this->set('PAY_timestamp', $timestamp); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * Set Payment Method |
|
96 | + * |
|
97 | + * @access public |
|
98 | + * @param string $PAY_source |
|
99 | + * @throws EE_Error |
|
100 | + */ |
|
101 | + public function set_source($PAY_source = '') |
|
102 | + { |
|
103 | + $this->set('PAY_source', $PAY_source); |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * Set Payment Amount |
|
109 | + * |
|
110 | + * @access public |
|
111 | + * @param float $amount |
|
112 | + * @throws EE_Error |
|
113 | + */ |
|
114 | + public function set_amount($amount = 0.00) |
|
115 | + { |
|
116 | + $this->set('PAY_amount', (float) $amount); |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * Set Payment Gateway Response |
|
122 | + * |
|
123 | + * @access public |
|
124 | + * @param string $gateway_response |
|
125 | + * @throws EE_Error |
|
126 | + */ |
|
127 | + public function set_gateway_response($gateway_response = '') |
|
128 | + { |
|
129 | + $this->set('PAY_gateway_response', $gateway_response); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * Returns the name of the payment method used on this payment (previously known merely as 'gateway') |
|
135 | + * but since 4.6.0, payment methods are models and the payment keeps a foreign key to the payment method |
|
136 | + * used on it |
|
137 | + * |
|
138 | + * @return string |
|
139 | + * @throws EE_Error |
|
140 | + * @deprecated |
|
141 | + */ |
|
142 | + public function gateway() |
|
143 | + { |
|
144 | + EE_Error::doing_it_wrong( |
|
145 | + 'EE_Payment::gateway', |
|
146 | + esc_html__( |
|
147 | + 'The method EE_Payment::gateway() has been deprecated. Consider instead using EE_Payment::payment_method()->name()', |
|
148 | + 'event_espresso' |
|
149 | + ), |
|
150 | + '4.6.0' |
|
151 | + ); |
|
152 | + return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso'); |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * Set Gateway Transaction ID |
|
158 | + * |
|
159 | + * @access public |
|
160 | + * @param string $txn_id_chq_nmbr |
|
161 | + * @throws EE_Error |
|
162 | + */ |
|
163 | + public function set_txn_id_chq_nmbr($txn_id_chq_nmbr = '') |
|
164 | + { |
|
165 | + $this->set('PAY_txn_id_chq_nmbr', $txn_id_chq_nmbr); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * Set Purchase Order Number |
|
171 | + * |
|
172 | + * @access public |
|
173 | + * @param string $po_number |
|
174 | + * @throws EE_Error |
|
175 | + */ |
|
176 | + public function set_po_number($po_number = '') |
|
177 | + { |
|
178 | + $this->set('PAY_po_number', $po_number); |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * Set Extra Accounting Field |
|
184 | + * |
|
185 | + * @access public |
|
186 | + * @param string $extra_accntng |
|
187 | + * @throws EE_Error |
|
188 | + */ |
|
189 | + public function set_extra_accntng($extra_accntng = '') |
|
190 | + { |
|
191 | + $this->set('PAY_extra_accntng', $extra_accntng); |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * Set Payment made via admin flag |
|
197 | + * |
|
198 | + * @access public |
|
199 | + * @param bool $via_admin |
|
200 | + * @throws EE_Error |
|
201 | + */ |
|
202 | + public function set_payment_made_via_admin($via_admin = false) |
|
203 | + { |
|
204 | + if ($via_admin) { |
|
205 | + $this->set('PAY_source', EEM_Payment_Method::scope_admin); |
|
206 | + } else { |
|
207 | + $this->set('PAY_source', EEM_Payment_Method::scope_cart); |
|
208 | + } |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * Set Payment Details |
|
214 | + * |
|
215 | + * @access public |
|
216 | + * @param string|array $details |
|
217 | + * @throws EE_Error |
|
218 | + */ |
|
219 | + public function set_details($details = '') |
|
220 | + { |
|
221 | + if (is_array($details)) { |
|
222 | + array_walk_recursive($details, array($this, '_strip_all_tags_within_array')); |
|
223 | + } else { |
|
224 | + $details = wp_strip_all_tags($details); |
|
225 | + } |
|
226 | + $this->set('PAY_details', $details); |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * Sets redirect_url |
|
232 | + * |
|
233 | + * @param string $redirect_url |
|
234 | + * @throws EE_Error |
|
235 | + */ |
|
236 | + public function set_redirect_url($redirect_url) |
|
237 | + { |
|
238 | + $this->set('PAY_redirect_url', $redirect_url); |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * Sets redirect_args |
|
244 | + * |
|
245 | + * @param array $redirect_args |
|
246 | + * @throws EE_Error |
|
247 | + */ |
|
248 | + public function set_redirect_args($redirect_args) |
|
249 | + { |
|
250 | + $this->set('PAY_redirect_args', $redirect_args); |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * get Payment Transaction ID |
|
256 | + * |
|
257 | + * @access public |
|
258 | + * @throws EE_Error |
|
259 | + */ |
|
260 | + public function TXN_ID() |
|
261 | + { |
|
262 | + return $this->get('TXN_ID'); |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + /** |
|
267 | + * get Payment Status |
|
268 | + * |
|
269 | + * @access public |
|
270 | + * @throws EE_Error |
|
271 | + */ |
|
272 | + public function status() |
|
273 | + { |
|
274 | + return $this->get('STS_ID'); |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * get Payment Status |
|
280 | + * |
|
281 | + * @access public |
|
282 | + * @throws EE_Error |
|
283 | + */ |
|
284 | + public function STS_ID() |
|
285 | + { |
|
286 | + return $this->get('STS_ID'); |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * get Payment Timestamp |
|
292 | + * |
|
293 | + * @access public |
|
294 | + * @param string $dt_frmt |
|
295 | + * @param string $tm_frmt |
|
296 | + * @return string |
|
297 | + * @throws EE_Error |
|
298 | + */ |
|
299 | + public function timestamp($dt_frmt = '', $tm_frmt = '') |
|
300 | + { |
|
301 | + return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt . ' ' . $tm_frmt)); |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * get Payment Source |
|
307 | + * |
|
308 | + * @access public |
|
309 | + * @throws EE_Error |
|
310 | + */ |
|
311 | + public function source() |
|
312 | + { |
|
313 | + return $this->get('PAY_source'); |
|
314 | + } |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * get Payment Amount |
|
319 | + * |
|
320 | + * @access public |
|
321 | + * @return float |
|
322 | + * @throws EE_Error |
|
323 | + */ |
|
324 | + public function amount() |
|
325 | + { |
|
326 | + return (float) $this->get('PAY_amount'); |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * @return mixed |
|
332 | + * @throws EE_Error |
|
333 | + */ |
|
334 | + public function amount_no_code() |
|
335 | + { |
|
336 | + return $this->get_pretty('PAY_amount', 'no_currency_code'); |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * get Payment Gateway Response |
|
342 | + * |
|
343 | + * @access public |
|
344 | + * @throws EE_Error |
|
345 | + */ |
|
346 | + public function gateway_response() |
|
347 | + { |
|
348 | + return $this->get('PAY_gateway_response'); |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * get Payment Gateway Transaction ID |
|
354 | + * |
|
355 | + * @access public |
|
356 | + * @throws EE_Error |
|
357 | + */ |
|
358 | + public function txn_id_chq_nmbr() |
|
359 | + { |
|
360 | + return $this->get('PAY_txn_id_chq_nmbr'); |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * get Purchase Order Number |
|
366 | + * |
|
367 | + * @access public |
|
368 | + * @throws EE_Error |
|
369 | + */ |
|
370 | + public function po_number() |
|
371 | + { |
|
372 | + return $this->get('PAY_po_number'); |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * get Extra Accounting Field |
|
378 | + * |
|
379 | + * @access public |
|
380 | + * @throws EE_Error |
|
381 | + */ |
|
382 | + public function extra_accntng() |
|
383 | + { |
|
384 | + return $this->get('PAY_extra_accntng'); |
|
385 | + } |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * get Payment made via admin source |
|
390 | + * |
|
391 | + * @access public |
|
392 | + * @throws EE_Error |
|
393 | + */ |
|
394 | + public function payment_made_via_admin() |
|
395 | + { |
|
396 | + return ($this->get('PAY_source') === EEM_Payment_Method::scope_admin); |
|
397 | + } |
|
398 | + |
|
399 | + |
|
400 | + /** |
|
401 | + * get Payment Details |
|
402 | + * |
|
403 | + * @access public |
|
404 | + * @throws EE_Error |
|
405 | + */ |
|
406 | + public function details() |
|
407 | + { |
|
408 | + return $this->get('PAY_details'); |
|
409 | + } |
|
410 | + |
|
411 | + |
|
412 | + /** |
|
413 | + * Gets redirect_url |
|
414 | + * |
|
415 | + * @return string |
|
416 | + * @throws EE_Error |
|
417 | + */ |
|
418 | + public function redirect_url() |
|
419 | + { |
|
420 | + return $this->get('PAY_redirect_url'); |
|
421 | + } |
|
422 | + |
|
423 | + |
|
424 | + /** |
|
425 | + * Gets redirect_args |
|
426 | + * |
|
427 | + * @return array |
|
428 | + * @throws EE_Error |
|
429 | + */ |
|
430 | + public function redirect_args() |
|
431 | + { |
|
432 | + return $this->get('PAY_redirect_args'); |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * echoes $this->pretty_status() |
|
438 | + * |
|
439 | + * @param bool $show_icons |
|
440 | + * @return void |
|
441 | + * @throws EE_Error |
|
442 | + */ |
|
443 | + public function e_pretty_status($show_icons = false) |
|
444 | + { |
|
445 | + echo wp_kses($this->pretty_status($show_icons), AllowedTags::getAllowedTags()); |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + /** |
|
450 | + * returns a pretty version of the status, good for displaying to users |
|
451 | + * |
|
452 | + * @param bool $show_icons |
|
453 | + * @return string |
|
454 | + * @throws EE_Error |
|
455 | + */ |
|
456 | + public function pretty_status($show_icons = false) |
|
457 | + { |
|
458 | + $status = EEM_Status::instance()->localized_status( |
|
459 | + array($this->STS_ID() => esc_html__('unknown', 'event_espresso')), |
|
460 | + false, |
|
461 | + 'sentence' |
|
462 | + ); |
|
463 | + $icon = ''; |
|
464 | + switch ($this->STS_ID()) { |
|
465 | + case EEM_Payment::status_id_approved: |
|
466 | + $icon = $show_icons |
|
467 | + ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' |
|
468 | + : ''; |
|
469 | + break; |
|
470 | + case EEM_Payment::status_id_pending: |
|
471 | + $icon = $show_icons |
|
472 | + ? '<span class="dashicons dashicons-clock ee-icon-size-16 orange-text"></span>' |
|
473 | + : ''; |
|
474 | + break; |
|
475 | + case EEM_Payment::status_id_cancelled: |
|
476 | + $icon = $show_icons |
|
477 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
478 | + : ''; |
|
479 | + break; |
|
480 | + case EEM_Payment::status_id_declined: |
|
481 | + $icon = $show_icons |
|
482 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
483 | + : ''; |
|
484 | + break; |
|
485 | + } |
|
486 | + return $icon . $status[ $this->STS_ID() ]; |
|
487 | + } |
|
488 | + |
|
489 | + |
|
490 | + /** |
|
491 | + * For determining the status of the payment |
|
492 | + * |
|
493 | + * @return boolean whether the payment is approved or not |
|
494 | + * @throws EE_Error |
|
495 | + */ |
|
496 | + public function is_approved() |
|
497 | + { |
|
498 | + return $this->status_is(EEM_Payment::status_id_approved); |
|
499 | + } |
|
500 | + |
|
501 | + |
|
502 | + /** |
|
503 | + * Generally determines if the status of this payment equals |
|
504 | + * the $STS_ID string |
|
505 | + * |
|
506 | + * @param string $STS_ID an ID from the esp_status table/ |
|
507 | + * one of the status_id_* on the EEM_Payment model |
|
508 | + * @return boolean whether the status of this payment equals the status id |
|
509 | + * @throws EE_Error |
|
510 | + */ |
|
511 | + protected function status_is($STS_ID) |
|
512 | + { |
|
513 | + return $STS_ID === $this->STS_ID() ? true : false; |
|
514 | + } |
|
515 | + |
|
516 | + |
|
517 | + /** |
|
518 | + * For determining the status of the payment |
|
519 | + * |
|
520 | + * @return boolean whether the payment is pending or not |
|
521 | + * @throws EE_Error |
|
522 | + */ |
|
523 | + public function is_pending() |
|
524 | + { |
|
525 | + return $this->status_is(EEM_Payment::status_id_pending); |
|
526 | + } |
|
527 | + |
|
528 | + |
|
529 | + /** |
|
530 | + * For determining the status of the payment |
|
531 | + * |
|
532 | + * @return boolean |
|
533 | + * @throws EE_Error |
|
534 | + */ |
|
535 | + public function is_cancelled() |
|
536 | + { |
|
537 | + return $this->status_is(EEM_Payment::status_id_cancelled); |
|
538 | + } |
|
539 | + |
|
540 | + |
|
541 | + /** |
|
542 | + * For determining the status of the payment |
|
543 | + * |
|
544 | + * @return boolean |
|
545 | + * @throws EE_Error |
|
546 | + */ |
|
547 | + public function is_declined() |
|
548 | + { |
|
549 | + return $this->status_is(EEM_Payment::status_id_declined); |
|
550 | + } |
|
551 | + |
|
552 | + |
|
553 | + /** |
|
554 | + * For determining the status of the payment |
|
555 | + * |
|
556 | + * @return boolean |
|
557 | + * @throws EE_Error |
|
558 | + */ |
|
559 | + public function is_failed() |
|
560 | + { |
|
561 | + return $this->status_is(EEM_Payment::status_id_failed); |
|
562 | + } |
|
563 | + |
|
564 | + |
|
565 | + /** |
|
566 | + * For determining if the payment is actually a refund ( ie: has a negative value ) |
|
567 | + * |
|
568 | + * @return boolean |
|
569 | + * @throws EE_Error |
|
570 | + */ |
|
571 | + public function is_a_refund() |
|
572 | + { |
|
573 | + return $this->amount() < 0 ? true : false; |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * Get the status object of this object |
|
579 | + * |
|
580 | + * @return EE_Status |
|
581 | + * @throws EE_Error |
|
582 | + */ |
|
583 | + public function status_obj() |
|
584 | + { |
|
585 | + return $this->get_first_related('Status'); |
|
586 | + } |
|
587 | + |
|
588 | + |
|
589 | + /** |
|
590 | + * Gets all the extra meta info on this payment |
|
591 | + * |
|
592 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
593 | + * @return EE_Extra_Meta |
|
594 | + * @throws EE_Error |
|
595 | + */ |
|
596 | + public function extra_meta($query_params = array()) |
|
597 | + { |
|
598 | + return $this->get_many_related('Extra_Meta', $query_params); |
|
599 | + } |
|
600 | + |
|
601 | + |
|
602 | + /** |
|
603 | + * Gets the last-used payment method on this transaction |
|
604 | + * (we COULD just use the last-made payment, but some payment methods, namely |
|
605 | + * offline ones, dont' create payments) |
|
606 | + * |
|
607 | + * @return EE_Payment_Method |
|
608 | + * @throws EE_Error |
|
609 | + */ |
|
610 | + public function payment_method() |
|
611 | + { |
|
612 | + return $this->get_first_related('Payment_Method'); |
|
613 | + } |
|
614 | + |
|
615 | + |
|
616 | + /** |
|
617 | + * Gets the HTML for redirecting the user to an offsite gateway |
|
618 | + * You can pass it special content to put inside the form, or use |
|
619 | + * the default inner content (or possibly generate this all yourself using |
|
620 | + * redirect_url() and redirect_args() or redirect_args_as_inputs()). |
|
621 | + * Creates a POST request by default, but if no redirect args are specified, creates a GET request instead |
|
622 | + * (and any querystring variables in the redirect_url are converted into html inputs |
|
623 | + * so browsers submit them properly) |
|
624 | + * |
|
625 | + * @param string $inside_form_html |
|
626 | + * @return string html |
|
627 | + * @throws EE_Error |
|
628 | + */ |
|
629 | + public function redirect_form($inside_form_html = null) |
|
630 | + { |
|
631 | + $redirect_url = $this->redirect_url(); |
|
632 | + if (! empty($redirect_url)) { |
|
633 | + // what ? no inner form content? |
|
634 | + if ($inside_form_html === null) { |
|
635 | + $inside_form_html = EEH_HTML::p( |
|
636 | + sprintf( |
|
637 | + esc_html__( |
|
638 | + 'If you are not automatically redirected to the payment website within 10 seconds... %1$s %2$s Click Here %3$s', |
|
639 | + 'event_espresso' |
|
640 | + ), |
|
641 | + EEH_HTML::br(2), |
|
642 | + '<input type="submit" value="', |
|
643 | + '">' |
|
644 | + ), |
|
645 | + '', |
|
646 | + '', |
|
647 | + 'text-align:center;' |
|
648 | + ); |
|
649 | + } |
|
650 | + $method = apply_filters( |
|
651 | + 'FHEE__EE_Payment__redirect_form__method', |
|
652 | + $this->redirect_args() ? 'POST' : 'GET', |
|
653 | + $this |
|
654 | + ); |
|
655 | + // if it's a GET request, we need to remove all the GET params in the querystring |
|
656 | + // and put them into the form instead |
|
657 | + if ($method === 'GET') { |
|
658 | + $querystring = parse_url($redirect_url, PHP_URL_QUERY); |
|
659 | + $get_params = null; |
|
660 | + parse_str($querystring, $get_params); |
|
661 | + $inside_form_html .= $this->_args_as_inputs($get_params); |
|
662 | + $redirect_url = str_replace('?' . $querystring, '', $redirect_url); |
|
663 | + } |
|
664 | + $form = EEH_HTML::nl(1) |
|
665 | + . '<form method="' |
|
666 | + . $method |
|
667 | + . '" name="gateway_form" action="' |
|
668 | + . $redirect_url |
|
669 | + . '">'; |
|
670 | + $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs(); |
|
671 | + $form .= $inside_form_html; |
|
672 | + $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1); |
|
673 | + return $form; |
|
674 | + } else { |
|
675 | + return null; |
|
676 | + } |
|
677 | + } |
|
678 | + |
|
679 | + |
|
680 | + /** |
|
681 | + * Changes all the name-value pairs of the redirect args into html inputs |
|
682 | + * and returns the html as a string |
|
683 | + * |
|
684 | + * @return string |
|
685 | + * @throws EE_Error |
|
686 | + */ |
|
687 | + public function redirect_args_as_inputs() |
|
688 | + { |
|
689 | + return $this->_args_as_inputs($this->redirect_args()); |
|
690 | + } |
|
691 | + |
|
692 | + |
|
693 | + /** |
|
694 | + * Converts a 2d array of key-value pairs into html hidden inputs |
|
695 | + * and returns the string of html |
|
696 | + * |
|
697 | + * @param array $args key-value pairs |
|
698 | + * @return string |
|
699 | + */ |
|
700 | + protected function _args_as_inputs($args) |
|
701 | + { |
|
702 | + $html = ''; |
|
703 | + if ($args !== null && is_array($args)) { |
|
704 | + foreach ($args as $name => $value) { |
|
705 | + $html .= $this->generateInput($name, $value); |
|
706 | + } |
|
707 | + } |
|
708 | + return $html; |
|
709 | + } |
|
710 | + |
|
711 | + /** |
|
712 | + * Converts either a single name and value or array of values into html hidden inputs |
|
713 | + * and returns the string of html |
|
714 | + * |
|
715 | + * @param string $name |
|
716 | + * @param string|array $value |
|
717 | + * @return string |
|
718 | + */ |
|
719 | + private function generateInput($name, $value) |
|
720 | + { |
|
721 | + if (is_array($value)) { |
|
722 | + $html = ''; |
|
723 | + $name = "{$name}[]"; |
|
724 | + foreach ($value as $array_value) { |
|
725 | + $html .= $this->generateInput($name, $array_value); |
|
726 | + } |
|
727 | + return $html; |
|
728 | + } |
|
729 | + return EEH_HTML::nl() |
|
730 | + . '<input type="hidden" name="' . $name . '"' |
|
731 | + . ' value="' . esc_attr($value) . '"/>'; |
|
732 | + } |
|
733 | + |
|
734 | + |
|
735 | + /** |
|
736 | + * Returns the currency of the payment. |
|
737 | + * (At the time of writing, this will always be the currency in the configuration; |
|
738 | + * however in the future it is anticipated that this will be stored on the payment |
|
739 | + * object itself) |
|
740 | + * |
|
741 | + * @return string for the currency code |
|
742 | + */ |
|
743 | + public function currency_code() |
|
744 | + { |
|
745 | + return EE_Config::instance()->currency->code; |
|
746 | + } |
|
747 | + |
|
748 | + |
|
749 | + /** |
|
750 | + * apply wp_strip_all_tags to all elements within an array |
|
751 | + * |
|
752 | + * @access private |
|
753 | + * @param mixed $item |
|
754 | + */ |
|
755 | + private function _strip_all_tags_within_array(&$item) |
|
756 | + { |
|
757 | + if (is_object($item)) { |
|
758 | + $item = (array) $item; |
|
759 | + } |
|
760 | + if (is_array($item)) { |
|
761 | + array_walk_recursive($item, array($this, '_strip_all_tags_within_array')); |
|
762 | + } else { |
|
763 | + $item = wp_strip_all_tags((string) $item); |
|
764 | + } |
|
765 | + } |
|
766 | + |
|
767 | + |
|
768 | + /** |
|
769 | + * Returns TRUE is this payment was set to approved during this request (or |
|
770 | + * is approved and was created during this request). False otherwise. |
|
771 | + * |
|
772 | + * @return boolean |
|
773 | + * @throws EE_Error |
|
774 | + */ |
|
775 | + public function just_approved() |
|
776 | + { |
|
777 | + $original_status = EEH_Array::is_set( |
|
778 | + $this->_props_n_values_provided_in_constructor, |
|
779 | + 'STS_ID', |
|
780 | + $this->get_model()->field_settings_for('STS_ID')->get_default_value() |
|
781 | + ); |
|
782 | + $current_status = $this->status(); |
|
783 | + if ( |
|
784 | + $original_status !== EEM_Payment::status_id_approved |
|
785 | + && $current_status === EEM_Payment::status_id_approved |
|
786 | + ) { |
|
787 | + return true; |
|
788 | + } else { |
|
789 | + return false; |
|
790 | + } |
|
791 | + } |
|
792 | + |
|
793 | + |
|
794 | + /** |
|
795 | + * Overrides parents' get_pretty() function just for legacy reasons |
|
796 | + * (to allow ticket https://events.codebasehq.com/projects/event-espresso/tickets/7420) |
|
797 | + * |
|
798 | + * @param string $field_name |
|
799 | + * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
800 | + * (in cases where the same property may be used for different outputs |
|
801 | + * - i.e. datetime, money etc.) |
|
802 | + * @return mixed |
|
803 | + * @throws EE_Error |
|
804 | + */ |
|
805 | + public function get_pretty($field_name, $extra_cache_ref = null) |
|
806 | + { |
|
807 | + if ($field_name === 'PAY_gateway') { |
|
808 | + return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso'); |
|
809 | + } |
|
810 | + return $this->_get_cached_property($field_name, true, $extra_cache_ref); |
|
811 | + } |
|
812 | + |
|
813 | + |
|
814 | + /** |
|
815 | + * Gets details regarding which registrations this payment was applied to |
|
816 | + * |
|
817 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
818 | + * @return EE_Registration_Payment[] |
|
819 | + * @throws EE_Error |
|
820 | + */ |
|
821 | + public function registration_payments($query_params = array()) |
|
822 | + { |
|
823 | + return $this->get_many_related('Registration_Payment', $query_params); |
|
824 | + } |
|
825 | + |
|
826 | + |
|
827 | + /** |
|
828 | + * Gets the first event for this payment (it's possible that it could be for multiple) |
|
829 | + * |
|
830 | + * @return EE_Event|null |
|
831 | + */ |
|
832 | + public function get_first_event() |
|
833 | + { |
|
834 | + $transaction = $this->transaction(); |
|
835 | + if ($transaction instanceof EE_Transaction) { |
|
836 | + $primary_registrant = $transaction->primary_registration(); |
|
837 | + if ($primary_registrant instanceof EE_Registration) { |
|
838 | + return $primary_registrant->event_obj(); |
|
839 | + } |
|
840 | + } |
|
841 | + return null; |
|
842 | + } |
|
843 | + |
|
844 | + |
|
845 | + /** |
|
846 | + * Gets the name of the first event for which is being paid |
|
847 | + * |
|
848 | + * @return string |
|
849 | + */ |
|
850 | + public function get_first_event_name() |
|
851 | + { |
|
852 | + $event = $this->get_first_event(); |
|
853 | + return $event instanceof EE_Event ? $event->name() : esc_html__('Event', 'event_espresso'); |
|
854 | + } |
|
855 | + |
|
856 | + |
|
857 | + /** |
|
858 | + * Returns the payment's transaction's primary registration |
|
859 | + * |
|
860 | + * @return EE_Registration|null |
|
861 | + */ |
|
862 | + public function get_primary_registration() |
|
863 | + { |
|
864 | + if ($this->transaction() instanceof EE_Transaction) { |
|
865 | + return $this->transaction()->primary_registration(); |
|
866 | + } |
|
867 | + return null; |
|
868 | + } |
|
869 | + |
|
870 | + |
|
871 | + /** |
|
872 | + * Gets the payment's transaction's primary registration's attendee, or null |
|
873 | + * |
|
874 | + * @return EE_Attendee|null |
|
875 | + */ |
|
876 | + public function get_primary_attendee() |
|
877 | + { |
|
878 | + $primary_reg = $this->get_primary_registration(); |
|
879 | + if ($primary_reg instanceof EE_Registration) { |
|
880 | + return $primary_reg->attendee(); |
|
881 | + } |
|
882 | + return null; |
|
883 | + } |
|
884 | 884 | } |
@@ -445,11 +445,11 @@ discard block |
||
445 | 445 | */ |
446 | 446 | public function type_obj() |
447 | 447 | { |
448 | - if (! $this->_type_obj) { |
|
448 | + if ( ! $this->_type_obj) { |
|
449 | 449 | EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
450 | 450 | if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
451 | 451 | $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
452 | - if (! class_exists($class_name)) { |
|
452 | + if ( ! class_exists($class_name)) { |
|
453 | 453 | throw new EE_Error( |
454 | 454 | sprintf( |
455 | 455 | esc_html__( |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | ), |
459 | 459 | $class_name, |
460 | 460 | '<br />', |
461 | - '<a href="' . admin_url('plugins.php') . '">', |
|
461 | + '<a href="'.admin_url('plugins.php').'">', |
|
462 | 462 | '</a>' |
463 | 463 | ) |
464 | 464 | ); |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | foreach ($fields as $key => $value) { |
500 | 500 | if (strpos($key, 'PMD_') === 0) { |
501 | 501 | $key_sans_model_prefix = str_replace('PMD_', '', $key); |
502 | - $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
502 | + $combined_settings_array [$key_sans_model_prefix] = $value; |
|
503 | 503 | } |
504 | 504 | } |
505 | 505 | $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
@@ -522,14 +522,14 @@ discard block |
||
522 | 522 | <div id="' |
523 | 523 | . $this->slug() |
524 | 524 | . '-payment-option-dv" class="' |
525 | - . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
525 | + . $payment_occurs.'-payment-gateway reg-page-payment-option-dv'.$css_class.'"> |
|
526 | 526 | <a id="payment-gateway-button-' . $this->slug() |
527 | 527 | . '" class="reg-page-payment-option-lnk" rel="' |
528 | - . $this->slug() . '" href="' . $url . '" > |
|
529 | - <img src="' . $this->button_url() . '" alt="' . sprintf( |
|
528 | + . $this->slug().'" href="'.$url.'" > |
|
529 | + <img src="' . $this->button_url().'" alt="'.sprintf( |
|
530 | 530 | esc_attr__('Pay using %s', 'event_espresso'), |
531 | 531 | $this->get_pretty('PMD_name', 'form_input') |
532 | - ) . '" /> |
|
532 | + ).'" /> |
|
533 | 533 | </a> |
534 | 534 | </div> |
535 | 535 | '; |
@@ -13,582 +13,582 @@ |
||
13 | 13 | */ |
14 | 14 | class EE_Payment_Method extends EE_Base_Class |
15 | 15 | { |
16 | - /** |
|
17 | - * Payment Method type object, which has all the info about this type of payment method, |
|
18 | - * including functions for processing payments, to get settings forms, etc. |
|
19 | - * |
|
20 | - * @var EE_PMT_Base |
|
21 | - */ |
|
22 | - protected $_type_obj; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * @param array $props_n_values |
|
27 | - * @return EE_Payment_Method |
|
28 | - * @throws \EE_Error |
|
29 | - */ |
|
30 | - public static function new_instance($props_n_values = array()) |
|
31 | - { |
|
32 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
33 | - return $has_object ? $has_object : new self($props_n_values, false); |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @param array $props_n_values |
|
39 | - * @return EE_Payment_Method |
|
40 | - * @throws \EE_Error |
|
41 | - */ |
|
42 | - public static function new_instance_from_db($props_n_values = array()) |
|
43 | - { |
|
44 | - return new self($props_n_values, true); |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * Checks if there is a payment method class of the given 'PMD_type', and if so returns the classname. |
|
51 | - * Otherwise returns a normal EE_Payment_Method |
|
52 | - * |
|
53 | - * @param array $props_n_values where 'PMD_type' is a gateway name like 'Paypal_Standard','Invoice',etc (basically |
|
54 | - * the classname minus 'EEPM_') |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - // private static function _payment_method_type($props_n_values) |
|
58 | - // { |
|
59 | - // EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
60 | - // $type_string = isset($props_n_values['PMD_type']) ? $props_n_values['PMD_type'] : null; |
|
61 | - // if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($type_string)) { |
|
62 | - // return 'EEPM_' . $type_string; |
|
63 | - // } else { |
|
64 | - // return __CLASS__; |
|
65 | - // } |
|
66 | - // } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * Gets whether this payment method can be used anywhere at all (ie frontend cart, admin, etc) |
|
71 | - * |
|
72 | - * @return boolean |
|
73 | - */ |
|
74 | - public function active() |
|
75 | - { |
|
76 | - return array_intersect(array_keys(EEM_Payment_Method::instance()->scopes()), $this->scope()); |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * Sets this PM as active by making it usable within the CART scope. Offline gateways |
|
82 | - * are also usable from the admin-scope as well. DOES NOT SAVE it |
|
83 | - * |
|
84 | - * @throws \EE_Error |
|
85 | - */ |
|
86 | - public function set_active() |
|
87 | - { |
|
88 | - $default_scopes = array(EEM_Payment_Method::scope_cart); |
|
89 | - if ( |
|
90 | - $this->type_obj() && |
|
91 | - $this->type_obj()->payment_occurs() === EE_PMT_Base::offline |
|
92 | - ) { |
|
93 | - $default_scopes[] = EEM_Payment_Method::scope_admin; |
|
94 | - } |
|
95 | - $this->set_scope($default_scopes); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * Makes this payment method apply to NO scopes at all. DOES NOT SAVE it. |
|
101 | - */ |
|
102 | - public function deactivate() |
|
103 | - { |
|
104 | - $this->set_scope(array()); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * Gets button_url |
|
110 | - * |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function button_url() |
|
114 | - { |
|
115 | - return $this->get('PMD_button_url'); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * Sets button_url |
|
121 | - * |
|
122 | - * @param string $button_url |
|
123 | - */ |
|
124 | - public function set_button_url($button_url) |
|
125 | - { |
|
126 | - $this->set('PMD_button_url', $button_url); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * Gets debug_mode |
|
132 | - * |
|
133 | - * @return boolean |
|
134 | - */ |
|
135 | - public function debug_mode() |
|
136 | - { |
|
137 | - return (bool) $this->get('PMD_debug_mode'); |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * Sets debug_mode |
|
143 | - * |
|
144 | - * @param boolean $debug_mode |
|
145 | - */ |
|
146 | - public function set_debug_mode($debug_mode) |
|
147 | - { |
|
148 | - $this->set('PMD_debug_mode', $debug_mode); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * Gets description |
|
154 | - * |
|
155 | - * @return string |
|
156 | - */ |
|
157 | - public function description() |
|
158 | - { |
|
159 | - return $this->get('PMD_desc'); |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * Sets description |
|
165 | - * |
|
166 | - * @param string $description |
|
167 | - */ |
|
168 | - public function set_description($description) |
|
169 | - { |
|
170 | - $this->set('PMD_desc', $description); |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * Gets name |
|
176 | - * |
|
177 | - * @return string |
|
178 | - */ |
|
179 | - public function name() |
|
180 | - { |
|
181 | - return $this->get('PMD_name'); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * Sets name |
|
187 | - * |
|
188 | - * @param string $name |
|
189 | - */ |
|
190 | - public function set_name($name) |
|
191 | - { |
|
192 | - $this->set('PMD_name', $name); |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * Gets open_by_default |
|
198 | - * |
|
199 | - * @return boolean |
|
200 | - */ |
|
201 | - public function open_by_default() |
|
202 | - { |
|
203 | - return $this->get('PMD_open_by_default'); |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - /** |
|
208 | - * Sets open_by_default |
|
209 | - * |
|
210 | - * @param boolean $open_by_default |
|
211 | - */ |
|
212 | - public function set_open_by_default($open_by_default) |
|
213 | - { |
|
214 | - $this->set('PMD_open_by_default', $open_by_default); |
|
215 | - } |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * Gets order |
|
220 | - * |
|
221 | - * @return int |
|
222 | - */ |
|
223 | - public function order() |
|
224 | - { |
|
225 | - return $this->get('PMD_order'); |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * Sets order |
|
231 | - * |
|
232 | - * @param int $order |
|
233 | - */ |
|
234 | - public function set_order($order) |
|
235 | - { |
|
236 | - $this->set('PMD_order', $order); |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * Gets slug |
|
242 | - * |
|
243 | - * @return string |
|
244 | - */ |
|
245 | - public function slug() |
|
246 | - { |
|
247 | - return $this->get('PMD_slug'); |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * Sets slug |
|
253 | - * |
|
254 | - * @param string $slug |
|
255 | - */ |
|
256 | - public function set_slug($slug) |
|
257 | - { |
|
258 | - $this->set('PMD_slug', $slug); |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * Gets type |
|
264 | - * |
|
265 | - * @return string |
|
266 | - */ |
|
267 | - public function type() |
|
268 | - { |
|
269 | - return $this->get('PMD_type'); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * Sets type |
|
275 | - * |
|
276 | - * @param string $type |
|
277 | - */ |
|
278 | - public function set_type($type) |
|
279 | - { |
|
280 | - $this->set('PMD_type', $type); |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * Gets wp_user |
|
286 | - * |
|
287 | - * @return int |
|
288 | - */ |
|
289 | - public function wp_user() |
|
290 | - { |
|
291 | - return $this->get('PMD_wp_user'); |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * Sets wp_user |
|
297 | - * |
|
298 | - * @param int $wp_user_id |
|
299 | - */ |
|
300 | - public function set_wp_user($wp_user_id) |
|
301 | - { |
|
302 | - $this->set('PMD_wp_user', $wp_user_id); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Overrides parent so when PMD_type is changed we refresh the _type_obj |
|
307 | - * |
|
308 | - * @param string $field_name |
|
309 | - * @param mixed $field_value |
|
310 | - * @param boolean $use_default |
|
311 | - */ |
|
312 | - public function set($field_name, $field_value, $use_default = false) |
|
313 | - { |
|
314 | - if ($field_name === 'PMD_type') { |
|
315 | - // the type has probably changed, so forget about its old type object |
|
316 | - $this->_type_obj = null; |
|
317 | - } |
|
318 | - parent::set($field_name, $field_value, $use_default); |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * Gets admin_name |
|
324 | - * |
|
325 | - * @return string |
|
326 | - */ |
|
327 | - public function admin_name() |
|
328 | - { |
|
329 | - return $this->get('PMD_admin_name'); |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - /** |
|
334 | - * Sets admin_name |
|
335 | - * |
|
336 | - * @param string $admin_name |
|
337 | - */ |
|
338 | - public function set_admin_name($admin_name) |
|
339 | - { |
|
340 | - $this->set('PMD_admin_name', $admin_name); |
|
341 | - } |
|
342 | - |
|
343 | - |
|
344 | - /** |
|
345 | - * Gets admin_desc |
|
346 | - * |
|
347 | - * @return string |
|
348 | - */ |
|
349 | - public function admin_desc() |
|
350 | - { |
|
351 | - return $this->get('PMD_admin_desc'); |
|
352 | - } |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * Sets admin_desc |
|
357 | - * |
|
358 | - * @param string $admin_desc |
|
359 | - */ |
|
360 | - public function set_admin_desc($admin_desc) |
|
361 | - { |
|
362 | - $this->set('PMD_admin_desc', $admin_desc); |
|
363 | - } |
|
364 | - |
|
365 | - |
|
366 | - /** |
|
367 | - * Gets scope |
|
368 | - * |
|
369 | - * @return array |
|
370 | - */ |
|
371 | - public function scope() |
|
372 | - { |
|
373 | - return $this->get('PMD_scope'); |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * Sets scope |
|
379 | - * |
|
380 | - * @param array $scope |
|
381 | - */ |
|
382 | - public function set_scope($scope) |
|
383 | - { |
|
384 | - $this->set('PMD_scope', $scope); |
|
385 | - } |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * Gets the payment method type for this payment method instance |
|
390 | - * |
|
391 | - * @return EE_PMT_Base |
|
392 | - * @throws EE_Error |
|
393 | - */ |
|
394 | - public function type_obj() |
|
395 | - { |
|
396 | - if (! $this->_type_obj) { |
|
397 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
398 | - if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
|
399 | - $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
|
400 | - if (! class_exists($class_name)) { |
|
401 | - throw new EE_Error( |
|
402 | - sprintf( |
|
403 | - esc_html__( |
|
404 | - 'An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s', |
|
405 | - 'event_espresso' |
|
406 | - ), |
|
407 | - $class_name, |
|
408 | - '<br />', |
|
409 | - '<a href="' . admin_url('plugins.php') . '">', |
|
410 | - '</a>' |
|
411 | - ) |
|
412 | - ); |
|
413 | - } |
|
414 | - $r = new ReflectionClass($class_name); |
|
415 | - $this->_type_obj = $r->newInstanceArgs(array($this)); |
|
416 | - } else { |
|
417 | - throw new EE_Error( |
|
418 | - sprintf( |
|
419 | - esc_html__( |
|
420 | - 'A payment method of type "%1$s" does not exist. Only ones existing are: %2$s', |
|
421 | - 'event_espresso' |
|
422 | - ), |
|
423 | - $this->type(), |
|
424 | - implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names()) |
|
425 | - ) |
|
426 | - ); |
|
427 | - } |
|
428 | - } |
|
429 | - return $this->_type_obj; |
|
430 | - } |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * Returns a simple array of key-value pairs combining the payment method's fields (without the 'PMD_' prefix) |
|
435 | - * and the extra meta. Mostly used for passing off ot gateways. * |
|
436 | - * |
|
437 | - * @return array |
|
438 | - */ |
|
439 | - public function settings_array() |
|
440 | - { |
|
441 | - $fields = $this->model_field_array(); |
|
442 | - $extra_meta = $this->all_extra_meta_array(); |
|
443 | - // remove the model's prefix from the fields |
|
444 | - $combined_settings_array = array(); |
|
445 | - foreach ($fields as $key => $value) { |
|
446 | - if (strpos($key, 'PMD_') === 0) { |
|
447 | - $key_sans_model_prefix = str_replace('PMD_', '', $key); |
|
448 | - $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
449 | - } |
|
450 | - } |
|
451 | - $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
|
452 | - return $combined_settings_array; |
|
453 | - } |
|
454 | - |
|
455 | - |
|
456 | - /** |
|
457 | - * Gets the HTML for displaying the payment method on a page. |
|
458 | - * |
|
459 | - * @param string $url |
|
460 | - * @param string $css_class |
|
461 | - * @return string of HTML for displaying the button |
|
462 | - * @throws \EE_Error |
|
463 | - */ |
|
464 | - public function button_html($url = '', $css_class = '') |
|
465 | - { |
|
466 | - $payment_occurs = $this->type_obj()->payment_occurs(); |
|
467 | - return ' |
|
16 | + /** |
|
17 | + * Payment Method type object, which has all the info about this type of payment method, |
|
18 | + * including functions for processing payments, to get settings forms, etc. |
|
19 | + * |
|
20 | + * @var EE_PMT_Base |
|
21 | + */ |
|
22 | + protected $_type_obj; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * @param array $props_n_values |
|
27 | + * @return EE_Payment_Method |
|
28 | + * @throws \EE_Error |
|
29 | + */ |
|
30 | + public static function new_instance($props_n_values = array()) |
|
31 | + { |
|
32 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
33 | + return $has_object ? $has_object : new self($props_n_values, false); |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @param array $props_n_values |
|
39 | + * @return EE_Payment_Method |
|
40 | + * @throws \EE_Error |
|
41 | + */ |
|
42 | + public static function new_instance_from_db($props_n_values = array()) |
|
43 | + { |
|
44 | + return new self($props_n_values, true); |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * Checks if there is a payment method class of the given 'PMD_type', and if so returns the classname. |
|
51 | + * Otherwise returns a normal EE_Payment_Method |
|
52 | + * |
|
53 | + * @param array $props_n_values where 'PMD_type' is a gateway name like 'Paypal_Standard','Invoice',etc (basically |
|
54 | + * the classname minus 'EEPM_') |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + // private static function _payment_method_type($props_n_values) |
|
58 | + // { |
|
59 | + // EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
60 | + // $type_string = isset($props_n_values['PMD_type']) ? $props_n_values['PMD_type'] : null; |
|
61 | + // if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($type_string)) { |
|
62 | + // return 'EEPM_' . $type_string; |
|
63 | + // } else { |
|
64 | + // return __CLASS__; |
|
65 | + // } |
|
66 | + // } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * Gets whether this payment method can be used anywhere at all (ie frontend cart, admin, etc) |
|
71 | + * |
|
72 | + * @return boolean |
|
73 | + */ |
|
74 | + public function active() |
|
75 | + { |
|
76 | + return array_intersect(array_keys(EEM_Payment_Method::instance()->scopes()), $this->scope()); |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * Sets this PM as active by making it usable within the CART scope. Offline gateways |
|
82 | + * are also usable from the admin-scope as well. DOES NOT SAVE it |
|
83 | + * |
|
84 | + * @throws \EE_Error |
|
85 | + */ |
|
86 | + public function set_active() |
|
87 | + { |
|
88 | + $default_scopes = array(EEM_Payment_Method::scope_cart); |
|
89 | + if ( |
|
90 | + $this->type_obj() && |
|
91 | + $this->type_obj()->payment_occurs() === EE_PMT_Base::offline |
|
92 | + ) { |
|
93 | + $default_scopes[] = EEM_Payment_Method::scope_admin; |
|
94 | + } |
|
95 | + $this->set_scope($default_scopes); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * Makes this payment method apply to NO scopes at all. DOES NOT SAVE it. |
|
101 | + */ |
|
102 | + public function deactivate() |
|
103 | + { |
|
104 | + $this->set_scope(array()); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * Gets button_url |
|
110 | + * |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function button_url() |
|
114 | + { |
|
115 | + return $this->get('PMD_button_url'); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * Sets button_url |
|
121 | + * |
|
122 | + * @param string $button_url |
|
123 | + */ |
|
124 | + public function set_button_url($button_url) |
|
125 | + { |
|
126 | + $this->set('PMD_button_url', $button_url); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * Gets debug_mode |
|
132 | + * |
|
133 | + * @return boolean |
|
134 | + */ |
|
135 | + public function debug_mode() |
|
136 | + { |
|
137 | + return (bool) $this->get('PMD_debug_mode'); |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * Sets debug_mode |
|
143 | + * |
|
144 | + * @param boolean $debug_mode |
|
145 | + */ |
|
146 | + public function set_debug_mode($debug_mode) |
|
147 | + { |
|
148 | + $this->set('PMD_debug_mode', $debug_mode); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * Gets description |
|
154 | + * |
|
155 | + * @return string |
|
156 | + */ |
|
157 | + public function description() |
|
158 | + { |
|
159 | + return $this->get('PMD_desc'); |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * Sets description |
|
165 | + * |
|
166 | + * @param string $description |
|
167 | + */ |
|
168 | + public function set_description($description) |
|
169 | + { |
|
170 | + $this->set('PMD_desc', $description); |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * Gets name |
|
176 | + * |
|
177 | + * @return string |
|
178 | + */ |
|
179 | + public function name() |
|
180 | + { |
|
181 | + return $this->get('PMD_name'); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * Sets name |
|
187 | + * |
|
188 | + * @param string $name |
|
189 | + */ |
|
190 | + public function set_name($name) |
|
191 | + { |
|
192 | + $this->set('PMD_name', $name); |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * Gets open_by_default |
|
198 | + * |
|
199 | + * @return boolean |
|
200 | + */ |
|
201 | + public function open_by_default() |
|
202 | + { |
|
203 | + return $this->get('PMD_open_by_default'); |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + /** |
|
208 | + * Sets open_by_default |
|
209 | + * |
|
210 | + * @param boolean $open_by_default |
|
211 | + */ |
|
212 | + public function set_open_by_default($open_by_default) |
|
213 | + { |
|
214 | + $this->set('PMD_open_by_default', $open_by_default); |
|
215 | + } |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * Gets order |
|
220 | + * |
|
221 | + * @return int |
|
222 | + */ |
|
223 | + public function order() |
|
224 | + { |
|
225 | + return $this->get('PMD_order'); |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * Sets order |
|
231 | + * |
|
232 | + * @param int $order |
|
233 | + */ |
|
234 | + public function set_order($order) |
|
235 | + { |
|
236 | + $this->set('PMD_order', $order); |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * Gets slug |
|
242 | + * |
|
243 | + * @return string |
|
244 | + */ |
|
245 | + public function slug() |
|
246 | + { |
|
247 | + return $this->get('PMD_slug'); |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * Sets slug |
|
253 | + * |
|
254 | + * @param string $slug |
|
255 | + */ |
|
256 | + public function set_slug($slug) |
|
257 | + { |
|
258 | + $this->set('PMD_slug', $slug); |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * Gets type |
|
264 | + * |
|
265 | + * @return string |
|
266 | + */ |
|
267 | + public function type() |
|
268 | + { |
|
269 | + return $this->get('PMD_type'); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * Sets type |
|
275 | + * |
|
276 | + * @param string $type |
|
277 | + */ |
|
278 | + public function set_type($type) |
|
279 | + { |
|
280 | + $this->set('PMD_type', $type); |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * Gets wp_user |
|
286 | + * |
|
287 | + * @return int |
|
288 | + */ |
|
289 | + public function wp_user() |
|
290 | + { |
|
291 | + return $this->get('PMD_wp_user'); |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * Sets wp_user |
|
297 | + * |
|
298 | + * @param int $wp_user_id |
|
299 | + */ |
|
300 | + public function set_wp_user($wp_user_id) |
|
301 | + { |
|
302 | + $this->set('PMD_wp_user', $wp_user_id); |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Overrides parent so when PMD_type is changed we refresh the _type_obj |
|
307 | + * |
|
308 | + * @param string $field_name |
|
309 | + * @param mixed $field_value |
|
310 | + * @param boolean $use_default |
|
311 | + */ |
|
312 | + public function set($field_name, $field_value, $use_default = false) |
|
313 | + { |
|
314 | + if ($field_name === 'PMD_type') { |
|
315 | + // the type has probably changed, so forget about its old type object |
|
316 | + $this->_type_obj = null; |
|
317 | + } |
|
318 | + parent::set($field_name, $field_value, $use_default); |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * Gets admin_name |
|
324 | + * |
|
325 | + * @return string |
|
326 | + */ |
|
327 | + public function admin_name() |
|
328 | + { |
|
329 | + return $this->get('PMD_admin_name'); |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + /** |
|
334 | + * Sets admin_name |
|
335 | + * |
|
336 | + * @param string $admin_name |
|
337 | + */ |
|
338 | + public function set_admin_name($admin_name) |
|
339 | + { |
|
340 | + $this->set('PMD_admin_name', $admin_name); |
|
341 | + } |
|
342 | + |
|
343 | + |
|
344 | + /** |
|
345 | + * Gets admin_desc |
|
346 | + * |
|
347 | + * @return string |
|
348 | + */ |
|
349 | + public function admin_desc() |
|
350 | + { |
|
351 | + return $this->get('PMD_admin_desc'); |
|
352 | + } |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * Sets admin_desc |
|
357 | + * |
|
358 | + * @param string $admin_desc |
|
359 | + */ |
|
360 | + public function set_admin_desc($admin_desc) |
|
361 | + { |
|
362 | + $this->set('PMD_admin_desc', $admin_desc); |
|
363 | + } |
|
364 | + |
|
365 | + |
|
366 | + /** |
|
367 | + * Gets scope |
|
368 | + * |
|
369 | + * @return array |
|
370 | + */ |
|
371 | + public function scope() |
|
372 | + { |
|
373 | + return $this->get('PMD_scope'); |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * Sets scope |
|
379 | + * |
|
380 | + * @param array $scope |
|
381 | + */ |
|
382 | + public function set_scope($scope) |
|
383 | + { |
|
384 | + $this->set('PMD_scope', $scope); |
|
385 | + } |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * Gets the payment method type for this payment method instance |
|
390 | + * |
|
391 | + * @return EE_PMT_Base |
|
392 | + * @throws EE_Error |
|
393 | + */ |
|
394 | + public function type_obj() |
|
395 | + { |
|
396 | + if (! $this->_type_obj) { |
|
397 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
398 | + if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
|
399 | + $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
|
400 | + if (! class_exists($class_name)) { |
|
401 | + throw new EE_Error( |
|
402 | + sprintf( |
|
403 | + esc_html__( |
|
404 | + 'An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s', |
|
405 | + 'event_espresso' |
|
406 | + ), |
|
407 | + $class_name, |
|
408 | + '<br />', |
|
409 | + '<a href="' . admin_url('plugins.php') . '">', |
|
410 | + '</a>' |
|
411 | + ) |
|
412 | + ); |
|
413 | + } |
|
414 | + $r = new ReflectionClass($class_name); |
|
415 | + $this->_type_obj = $r->newInstanceArgs(array($this)); |
|
416 | + } else { |
|
417 | + throw new EE_Error( |
|
418 | + sprintf( |
|
419 | + esc_html__( |
|
420 | + 'A payment method of type "%1$s" does not exist. Only ones existing are: %2$s', |
|
421 | + 'event_espresso' |
|
422 | + ), |
|
423 | + $this->type(), |
|
424 | + implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names()) |
|
425 | + ) |
|
426 | + ); |
|
427 | + } |
|
428 | + } |
|
429 | + return $this->_type_obj; |
|
430 | + } |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * Returns a simple array of key-value pairs combining the payment method's fields (without the 'PMD_' prefix) |
|
435 | + * and the extra meta. Mostly used for passing off ot gateways. * |
|
436 | + * |
|
437 | + * @return array |
|
438 | + */ |
|
439 | + public function settings_array() |
|
440 | + { |
|
441 | + $fields = $this->model_field_array(); |
|
442 | + $extra_meta = $this->all_extra_meta_array(); |
|
443 | + // remove the model's prefix from the fields |
|
444 | + $combined_settings_array = array(); |
|
445 | + foreach ($fields as $key => $value) { |
|
446 | + if (strpos($key, 'PMD_') === 0) { |
|
447 | + $key_sans_model_prefix = str_replace('PMD_', '', $key); |
|
448 | + $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
449 | + } |
|
450 | + } |
|
451 | + $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
|
452 | + return $combined_settings_array; |
|
453 | + } |
|
454 | + |
|
455 | + |
|
456 | + /** |
|
457 | + * Gets the HTML for displaying the payment method on a page. |
|
458 | + * |
|
459 | + * @param string $url |
|
460 | + * @param string $css_class |
|
461 | + * @return string of HTML for displaying the button |
|
462 | + * @throws \EE_Error |
|
463 | + */ |
|
464 | + public function button_html($url = '', $css_class = '') |
|
465 | + { |
|
466 | + $payment_occurs = $this->type_obj()->payment_occurs(); |
|
467 | + return ' |
|
468 | 468 | <div id="' |
469 | - . $this->slug() |
|
470 | - . '-payment-option-dv" class="' |
|
471 | - . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
469 | + . $this->slug() |
|
470 | + . '-payment-option-dv" class="' |
|
471 | + . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
472 | 472 | <a id="payment-gateway-button-' . $this->slug() |
473 | - . '" class="reg-page-payment-option-lnk" rel="' |
|
474 | - . $this->slug() . '" href="' . $url . '" > |
|
473 | + . '" class="reg-page-payment-option-lnk" rel="' |
|
474 | + . $this->slug() . '" href="' . $url . '" > |
|
475 | 475 | <img src="' . $this->button_url() . '" alt="' . sprintf( |
476 | - esc_attr__('Pay using %s', 'event_espresso'), |
|
477 | - $this->get_pretty('PMD_name', 'form_input') |
|
478 | - ) . '" /> |
|
476 | + esc_attr__('Pay using %s', 'event_espresso'), |
|
477 | + $this->get_pretty('PMD_name', 'form_input') |
|
478 | + ) . '" /> |
|
479 | 479 | </a> |
480 | 480 | </div> |
481 | 481 | '; |
482 | - } |
|
483 | - |
|
484 | - |
|
485 | - /** |
|
486 | - * Gets all the currencies which are an option for this payment method |
|
487 | - * (as defined by the gateway and the currently active currencies) |
|
488 | - * |
|
489 | - * @return EE_Currency[] |
|
490 | - * @throws \EE_Error |
|
491 | - */ |
|
492 | - public function get_all_usable_currencies() |
|
493 | - { |
|
494 | - return EEM_Currency::instance()->get_all_currencies_usable_by($this->type_obj()); |
|
495 | - } |
|
496 | - |
|
497 | - |
|
498 | - /** |
|
499 | - * Reports whether or not this payment method can be used for this payment method |
|
500 | - * |
|
501 | - * @param string $currency_code currency ID (code) |
|
502 | - * @return boolean |
|
503 | - * @throws \EE_Error |
|
504 | - */ |
|
505 | - public function usable_for_currency($currency_code) |
|
506 | - { |
|
507 | - foreach ($this->get_all_usable_currencies() as $currency_obj) { |
|
508 | - if ($currency_obj->ID() === $currency_code) { |
|
509 | - return true; |
|
510 | - } |
|
511 | - } |
|
512 | - return false; |
|
513 | - } |
|
514 | - |
|
515 | - |
|
516 | - /** |
|
517 | - * Returns TRUE if this payment method's gateway is an instance of EE_Onsite_Gateway |
|
518 | - * |
|
519 | - * @return bool |
|
520 | - * @throws \EE_Error |
|
521 | - */ |
|
522 | - public function is_on_site() |
|
523 | - { |
|
524 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::onsite; |
|
525 | - } |
|
526 | - |
|
527 | - |
|
528 | - /** |
|
529 | - * Returns TRUE if this payment method's gateway is an instance of EE_Offsite_Gateway |
|
530 | - * |
|
531 | - * @return bool |
|
532 | - * @throws \EE_Error |
|
533 | - */ |
|
534 | - public function is_off_site() |
|
535 | - { |
|
536 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::offsite; |
|
537 | - } |
|
538 | - |
|
539 | - |
|
540 | - /** |
|
541 | - * Returns TRUE if this payment method does not utilize a gateway |
|
542 | - * |
|
543 | - * @return bool |
|
544 | - * @throws \EE_Error |
|
545 | - */ |
|
546 | - public function is_off_line() |
|
547 | - { |
|
548 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::offline; |
|
549 | - } |
|
550 | - |
|
551 | - /** |
|
552 | - * Overrides default __sleep so the object type is NOT cached. |
|
553 | - * This way we can rely on the normal EE_Payment_Method::type_obj() logic |
|
554 | - * to load the required classes, and don't need them at the time of unserialization |
|
555 | - * |
|
556 | - * @return array |
|
557 | - */ |
|
558 | - public function __sleep() |
|
559 | - { |
|
560 | - $properties = get_object_vars($this); |
|
561 | - unset($properties['_type_obj']); |
|
562 | - return array_keys($properties); |
|
563 | - } |
|
564 | - |
|
565 | - |
|
566 | - /** |
|
567 | - * Overrides parent to add some logging for when payment methods get deactivated |
|
568 | - * |
|
569 | - * @param array $set_cols_n_values |
|
570 | - * @return int @see EE_Base_Class::save() |
|
571 | - * @throws \EE_Error |
|
572 | - */ |
|
573 | - public function save($set_cols_n_values = array()) |
|
574 | - { |
|
575 | - $results = parent::save($set_cols_n_values); |
|
576 | - if ($this->get_original('PMD_scope') !== $this->get('PMD_scope')) { |
|
577 | - /** @var CurrentPage $current_page */ |
|
578 | - $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
|
579 | - EE_Log::instance()->log( |
|
580 | - __FILE__, |
|
581 | - __FUNCTION__, |
|
582 | - sprintf( |
|
583 | - esc_html__('Set new scope on payment method %1$s to %2$s from %3$s on URL %4$s', 'event_espresso'), |
|
584 | - $this->name(), |
|
585 | - serialize($this->get_original('PMD_scope')), |
|
586 | - serialize($this->get('PMD_scope')), |
|
587 | - $current_page->getPermalink() |
|
588 | - ), |
|
589 | - 'payment_method_change' |
|
590 | - ); |
|
591 | - } |
|
592 | - return $results; |
|
593 | - } |
|
482 | + } |
|
483 | + |
|
484 | + |
|
485 | + /** |
|
486 | + * Gets all the currencies which are an option for this payment method |
|
487 | + * (as defined by the gateway and the currently active currencies) |
|
488 | + * |
|
489 | + * @return EE_Currency[] |
|
490 | + * @throws \EE_Error |
|
491 | + */ |
|
492 | + public function get_all_usable_currencies() |
|
493 | + { |
|
494 | + return EEM_Currency::instance()->get_all_currencies_usable_by($this->type_obj()); |
|
495 | + } |
|
496 | + |
|
497 | + |
|
498 | + /** |
|
499 | + * Reports whether or not this payment method can be used for this payment method |
|
500 | + * |
|
501 | + * @param string $currency_code currency ID (code) |
|
502 | + * @return boolean |
|
503 | + * @throws \EE_Error |
|
504 | + */ |
|
505 | + public function usable_for_currency($currency_code) |
|
506 | + { |
|
507 | + foreach ($this->get_all_usable_currencies() as $currency_obj) { |
|
508 | + if ($currency_obj->ID() === $currency_code) { |
|
509 | + return true; |
|
510 | + } |
|
511 | + } |
|
512 | + return false; |
|
513 | + } |
|
514 | + |
|
515 | + |
|
516 | + /** |
|
517 | + * Returns TRUE if this payment method's gateway is an instance of EE_Onsite_Gateway |
|
518 | + * |
|
519 | + * @return bool |
|
520 | + * @throws \EE_Error |
|
521 | + */ |
|
522 | + public function is_on_site() |
|
523 | + { |
|
524 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::onsite; |
|
525 | + } |
|
526 | + |
|
527 | + |
|
528 | + /** |
|
529 | + * Returns TRUE if this payment method's gateway is an instance of EE_Offsite_Gateway |
|
530 | + * |
|
531 | + * @return bool |
|
532 | + * @throws \EE_Error |
|
533 | + */ |
|
534 | + public function is_off_site() |
|
535 | + { |
|
536 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::offsite; |
|
537 | + } |
|
538 | + |
|
539 | + |
|
540 | + /** |
|
541 | + * Returns TRUE if this payment method does not utilize a gateway |
|
542 | + * |
|
543 | + * @return bool |
|
544 | + * @throws \EE_Error |
|
545 | + */ |
|
546 | + public function is_off_line() |
|
547 | + { |
|
548 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::offline; |
|
549 | + } |
|
550 | + |
|
551 | + /** |
|
552 | + * Overrides default __sleep so the object type is NOT cached. |
|
553 | + * This way we can rely on the normal EE_Payment_Method::type_obj() logic |
|
554 | + * to load the required classes, and don't need them at the time of unserialization |
|
555 | + * |
|
556 | + * @return array |
|
557 | + */ |
|
558 | + public function __sleep() |
|
559 | + { |
|
560 | + $properties = get_object_vars($this); |
|
561 | + unset($properties['_type_obj']); |
|
562 | + return array_keys($properties); |
|
563 | + } |
|
564 | + |
|
565 | + |
|
566 | + /** |
|
567 | + * Overrides parent to add some logging for when payment methods get deactivated |
|
568 | + * |
|
569 | + * @param array $set_cols_n_values |
|
570 | + * @return int @see EE_Base_Class::save() |
|
571 | + * @throws \EE_Error |
|
572 | + */ |
|
573 | + public function save($set_cols_n_values = array()) |
|
574 | + { |
|
575 | + $results = parent::save($set_cols_n_values); |
|
576 | + if ($this->get_original('PMD_scope') !== $this->get('PMD_scope')) { |
|
577 | + /** @var CurrentPage $current_page */ |
|
578 | + $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
|
579 | + EE_Log::instance()->log( |
|
580 | + __FILE__, |
|
581 | + __FUNCTION__, |
|
582 | + sprintf( |
|
583 | + esc_html__('Set new scope on payment method %1$s to %2$s from %3$s on URL %4$s', 'event_espresso'), |
|
584 | + $this->name(), |
|
585 | + serialize($this->get_original('PMD_scope')), |
|
586 | + serialize($this->get('PMD_scope')), |
|
587 | + $current_page->getPermalink() |
|
588 | + ), |
|
589 | + 'payment_method_change' |
|
590 | + ); |
|
591 | + } |
|
592 | + return $results; |
|
593 | + } |
|
594 | 594 | } |
@@ -22,7 +22,7 @@ |
||
22 | 22 | */ |
23 | 23 | public function __construct() |
24 | 24 | { |
25 | - $this->setName($this->namespace . 'TicketVisibilityEnum'); |
|
25 | + $this->setName($this->namespace.'TicketVisibilityEnum'); |
|
26 | 26 | $this->setDescription(esc_html__('Where the ticket can be viewed throughout the UI', 'event_espresso')); |
27 | 27 | parent::__construct(); |
28 | 28 | } |
@@ -17,24 +17,24 @@ |
||
17 | 17 | */ |
18 | 18 | class TicketVisibilityEnum extends EnumBase |
19 | 19 | { |
20 | - /** |
|
21 | - * TicketVisibilityEnum constructor. |
|
22 | - */ |
|
23 | - public function __construct() |
|
24 | - { |
|
25 | - $this->setName($this->namespace . 'TicketVisibilityEnum'); |
|
26 | - $this->setDescription(esc_html__('Where the ticket can be viewed throughout the UI', 'event_espresso')); |
|
27 | - parent::__construct(); |
|
28 | - } |
|
20 | + /** |
|
21 | + * TicketVisibilityEnum constructor. |
|
22 | + */ |
|
23 | + public function __construct() |
|
24 | + { |
|
25 | + $this->setName($this->namespace . 'TicketVisibilityEnum'); |
|
26 | + $this->setDescription(esc_html__('Where the ticket can be viewed throughout the UI', 'event_espresso')); |
|
27 | + parent::__construct(); |
|
28 | + } |
|
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * @return array |
|
33 | - * @throws EE_Error |
|
34 | - * @throws ReflectionException |
|
35 | - */ |
|
36 | - protected function getValues(): array |
|
37 | - { |
|
38 | - return EEM_Ticket::instance()->getTicketVisibilityValues(); |
|
39 | - } |
|
31 | + /** |
|
32 | + * @return array |
|
33 | + * @throws EE_Error |
|
34 | + * @throws ReflectionException |
|
35 | + */ |
|
36 | + protected function getValues(): array |
|
37 | + { |
|
38 | + return EEM_Ticket::instance()->getTicketVisibilityValues(); |
|
39 | + } |
|
40 | 40 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | { |
36 | 36 | $args = []; |
37 | 37 | |
38 | - if (! empty($input['datetimes'])) { |
|
38 | + if ( ! empty($input['datetimes'])) { |
|
39 | 39 | $args['datetimes'] = array_map('sanitize_text_field', (array) $input['datetimes']); |
40 | 40 | } |
41 | 41 | |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $args['TKT_description'] = wp_kses_post($input['description']); |
44 | 44 | } |
45 | 45 | |
46 | - if (! empty($input['endDate'])) { |
|
46 | + if ( ! empty($input['endDate'])) { |
|
47 | 47 | $args['TKT_end_date'] = new DateTime(sanitize_text_field($input['endDate'])); |
48 | 48 | } |
49 | 49 | |
@@ -79,9 +79,9 @@ discard block |
||
79 | 79 | $args['TKT_order'] = (int) $input['order']; |
80 | 80 | } |
81 | 81 | |
82 | - if (! empty($input['parent'])) { |
|
82 | + if ( ! empty($input['parent'])) { |
|
83 | 83 | $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
84 | - $args['TKT_parent'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
84 | + $args['TKT_parent'] = ( ! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | // price can be 0 |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | $args['TKT_sold'] = (int) $input['sold']; |
115 | 115 | } |
116 | 116 | |
117 | - if (! empty($input['startDate'])) { |
|
117 | + if ( ! empty($input['startDate'])) { |
|
118 | 118 | $args['TKT_start_date'] = new DateTime(sanitize_text_field($input['startDate'])); |
119 | 119 | } |
120 | 120 | |
@@ -122,9 +122,9 @@ discard block |
||
122 | 122 | $args['TKT_uses'] = (int) $input['uses']; |
123 | 123 | } |
124 | 124 | |
125 | - if (! empty($input['wpUser'])) { |
|
125 | + if ( ! empty($input['wpUser'])) { |
|
126 | 126 | $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser'])); |
127 | - $args['TKT_wp_user'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
127 | + $args['TKT_wp_user'] = ( ! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | if (array_key_exists('visibility', $input)) { |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | // @todo replace loop with single query |
160 | 160 | foreach ($datetimes as $ID) { |
161 | 161 | $parts = Relay::fromGlobalId($ID); |
162 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
162 | + if ( ! empty($parts['id']) && absint($parts['id'])) { |
|
163 | 163 | $entity->_add_relation_to( |
164 | 164 | $parts['id'], |
165 | 165 | $relationName |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | // @todo replace loop with single query |
190 | 190 | foreach ($prices as $ID) { |
191 | 191 | $parts = Relay::fromGlobalId($ID); |
192 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
192 | + if ( ! empty($parts['id']) && absint($parts['id'])) { |
|
193 | 193 | $entity->_add_relation_to( |
194 | 194 | $parts['id'], |
195 | 195 | $relationName |
@@ -22,195 +22,195 @@ |
||
22 | 22 | */ |
23 | 23 | class TicketMutation |
24 | 24 | { |
25 | - /** |
|
26 | - * Maps the GraphQL input to a format that the model functions can use |
|
27 | - * |
|
28 | - * @param array $input Data coming from the GraphQL mutation query input |
|
29 | - * @return array |
|
30 | - * @throws Exception |
|
31 | - */ |
|
32 | - public static function prepareFields(array $input): array |
|
33 | - { |
|
34 | - $args = []; |
|
35 | - |
|
36 | - if (! empty($input['datetimes'])) { |
|
37 | - $args['datetimes'] = array_map('sanitize_text_field', (array) $input['datetimes']); |
|
38 | - } |
|
39 | - |
|
40 | - if (isset($input['description'])) { |
|
41 | - $args['TKT_description'] = wp_kses_post($input['description']); |
|
42 | - } |
|
43 | - |
|
44 | - if (! empty($input['endDate'])) { |
|
45 | - $args['TKT_end_date'] = new DateTime(sanitize_text_field($input['endDate'])); |
|
46 | - } |
|
47 | - |
|
48 | - if (array_key_exists('isDefault', $input)) { |
|
49 | - $args['TKT_is_default'] = (bool) $input['isDefault']; |
|
50 | - } |
|
51 | - |
|
52 | - if (array_key_exists('isRequired', $input)) { |
|
53 | - $args['TKT_required'] = (bool) $input['isRequired']; |
|
54 | - } |
|
55 | - |
|
56 | - if (array_key_exists('isTaxable', $input)) { |
|
57 | - $args['TKT_taxable'] = (bool) $input['isTaxable']; |
|
58 | - } |
|
59 | - |
|
60 | - if (array_key_exists('isTrashed', $input)) { |
|
61 | - $args['TKT_deleted'] = (bool) $input['isTrashed']; |
|
62 | - } |
|
63 | - |
|
64 | - if (array_key_exists('max', $input)) { |
|
65 | - $args['TKT_max'] = (int) $input['max']; |
|
66 | - } |
|
67 | - |
|
68 | - if (array_key_exists('min', $input)) { |
|
69 | - $args['TKT_min'] = (int) $input['min']; |
|
70 | - } |
|
71 | - |
|
72 | - if (isset($input['name'])) { |
|
73 | - $args['TKT_name'] = sanitize_text_field($input['name']); |
|
74 | - } |
|
75 | - |
|
76 | - if (array_key_exists('order', $input)) { |
|
77 | - $args['TKT_order'] = (int) $input['order']; |
|
78 | - } |
|
79 | - |
|
80 | - if (! empty($input['parent'])) { |
|
81 | - $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
|
82 | - $args['TKT_parent'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
83 | - } |
|
84 | - |
|
85 | - // price can be 0 |
|
86 | - if (array_key_exists('price', $input)) { |
|
87 | - $args['TKT_price'] = (float) $input['price']; |
|
88 | - } |
|
89 | - |
|
90 | - // prices can be an empty array when all prices are deleted |
|
91 | - if (array_key_exists('prices', $input) && is_array($input['prices'])) { |
|
92 | - $args['prices'] = array_map('sanitize_text_field', $input['prices']); |
|
93 | - } |
|
94 | - |
|
95 | - if (array_key_exists('quantity', $input)) { |
|
96 | - $args['TKT_qty'] = (int) $input['quantity']; |
|
97 | - } |
|
98 | - |
|
99 | - if (array_key_exists('reserved', $input)) { |
|
100 | - $args['TKT_reserved'] = (int) $input['reserved']; |
|
101 | - } |
|
102 | - |
|
103 | - if (array_key_exists('reverseCalculate', $input)) { |
|
104 | - $args['TKT_reverse_calculate'] = (bool) $input['reverseCalculate']; |
|
105 | - } |
|
106 | - |
|
107 | - if (array_key_exists('row', $input)) { |
|
108 | - $args['TKT_row'] = (int) $input['row']; |
|
109 | - } |
|
110 | - |
|
111 | - if (array_key_exists('sold', $input)) { |
|
112 | - $args['TKT_sold'] = (int) $input['sold']; |
|
113 | - } |
|
114 | - |
|
115 | - if (! empty($input['startDate'])) { |
|
116 | - $args['TKT_start_date'] = new DateTime(sanitize_text_field($input['startDate'])); |
|
117 | - } |
|
118 | - |
|
119 | - if (array_key_exists('uses', $input)) { |
|
120 | - $args['TKT_uses'] = (int) $input['uses']; |
|
121 | - } |
|
122 | - |
|
123 | - if (! empty($input['wpUser'])) { |
|
124 | - $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser'])); |
|
125 | - $args['TKT_wp_user'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
126 | - } |
|
127 | - |
|
128 | - if (array_key_exists('visibility', $input)) { |
|
129 | - $args['TKT_visibility'] = (int) $input['visibility']; |
|
130 | - } |
|
131 | - |
|
132 | - return apply_filters( |
|
133 | - 'FHEE__EventEspresso_core_domain_services_graphql_data_mutations__ticket_args', |
|
134 | - $args, |
|
135 | - $input |
|
136 | - ); |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * Sets the related datetimes for the given ticket. |
|
142 | - * |
|
143 | - * @param EE_Ticket $entity The Ticket instance. |
|
144 | - * @param array $datetimes Array of datetime IDs to relate. |
|
145 | - * @throws EE_Error |
|
146 | - * @throws InvalidArgumentException |
|
147 | - * @throws InvalidDataTypeException |
|
148 | - * @throws InvalidInterfaceException |
|
149 | - * @throws ReflectionException |
|
150 | - */ |
|
151 | - public static function setRelatedDatetimes(EE_Ticket $entity, array $datetimes) |
|
152 | - { |
|
153 | - $relationName = 'Datetime'; |
|
154 | - // Remove all the existing related datetimes |
|
155 | - |
|
156 | - $entity->_remove_relations($relationName); |
|
157 | - // @todo replace loop with single query |
|
158 | - foreach ($datetimes as $ID) { |
|
159 | - $parts = Relay::fromGlobalId($ID); |
|
160 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
161 | - $entity->_add_relation_to( |
|
162 | - $parts['id'], |
|
163 | - $relationName |
|
164 | - ); |
|
165 | - } |
|
166 | - } |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * Sets the related prices for the given ticket. |
|
172 | - * |
|
173 | - * @param EE_Ticket $entity The Ticket instance. |
|
174 | - * @param array $prices Array of entity IDs to relate. |
|
175 | - * @throws EE_Error |
|
176 | - * @throws InvalidArgumentException |
|
177 | - * @throws InvalidDataTypeException |
|
178 | - * @throws InvalidInterfaceException |
|
179 | - * @throws ReflectionException |
|
180 | - */ |
|
181 | - public static function setRelatedPrices(EE_Ticket $entity, array $prices) |
|
182 | - { |
|
183 | - $relationName = 'Price'; |
|
184 | - // Remove all the existing related entities |
|
185 | - $entity->_remove_relations($relationName); |
|
186 | - |
|
187 | - // @todo replace loop with single query |
|
188 | - foreach ($prices as $ID) { |
|
189 | - $parts = Relay::fromGlobalId($ID); |
|
190 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
191 | - $entity->_add_relation_to( |
|
192 | - $parts['id'], |
|
193 | - $relationName |
|
194 | - ); |
|
195 | - } |
|
196 | - } |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @param EE_Ticket $ticket_entity |
|
202 | - * @throws EE_Error |
|
203 | - * @throws InvalidArgumentException |
|
204 | - * @throws InvalidDataTypeException |
|
205 | - * @throws InvalidInterfaceException |
|
206 | - * @throws ReflectionException |
|
207 | - */ |
|
208 | - public static function addDefaultPrices(EE_Ticket $ticket_entity) |
|
209 | - { |
|
210 | - /** @var DefaultPrices $default_prices */ |
|
211 | - $default_prices = LoaderFactory::getLoader()->getShared( |
|
212 | - 'EventEspresso\core\domain\services\admin\entities\DefaultPrices' |
|
213 | - ); |
|
214 | - $default_prices->create($ticket_entity); |
|
215 | - } |
|
25 | + /** |
|
26 | + * Maps the GraphQL input to a format that the model functions can use |
|
27 | + * |
|
28 | + * @param array $input Data coming from the GraphQL mutation query input |
|
29 | + * @return array |
|
30 | + * @throws Exception |
|
31 | + */ |
|
32 | + public static function prepareFields(array $input): array |
|
33 | + { |
|
34 | + $args = []; |
|
35 | + |
|
36 | + if (! empty($input['datetimes'])) { |
|
37 | + $args['datetimes'] = array_map('sanitize_text_field', (array) $input['datetimes']); |
|
38 | + } |
|
39 | + |
|
40 | + if (isset($input['description'])) { |
|
41 | + $args['TKT_description'] = wp_kses_post($input['description']); |
|
42 | + } |
|
43 | + |
|
44 | + if (! empty($input['endDate'])) { |
|
45 | + $args['TKT_end_date'] = new DateTime(sanitize_text_field($input['endDate'])); |
|
46 | + } |
|
47 | + |
|
48 | + if (array_key_exists('isDefault', $input)) { |
|
49 | + $args['TKT_is_default'] = (bool) $input['isDefault']; |
|
50 | + } |
|
51 | + |
|
52 | + if (array_key_exists('isRequired', $input)) { |
|
53 | + $args['TKT_required'] = (bool) $input['isRequired']; |
|
54 | + } |
|
55 | + |
|
56 | + if (array_key_exists('isTaxable', $input)) { |
|
57 | + $args['TKT_taxable'] = (bool) $input['isTaxable']; |
|
58 | + } |
|
59 | + |
|
60 | + if (array_key_exists('isTrashed', $input)) { |
|
61 | + $args['TKT_deleted'] = (bool) $input['isTrashed']; |
|
62 | + } |
|
63 | + |
|
64 | + if (array_key_exists('max', $input)) { |
|
65 | + $args['TKT_max'] = (int) $input['max']; |
|
66 | + } |
|
67 | + |
|
68 | + if (array_key_exists('min', $input)) { |
|
69 | + $args['TKT_min'] = (int) $input['min']; |
|
70 | + } |
|
71 | + |
|
72 | + if (isset($input['name'])) { |
|
73 | + $args['TKT_name'] = sanitize_text_field($input['name']); |
|
74 | + } |
|
75 | + |
|
76 | + if (array_key_exists('order', $input)) { |
|
77 | + $args['TKT_order'] = (int) $input['order']; |
|
78 | + } |
|
79 | + |
|
80 | + if (! empty($input['parent'])) { |
|
81 | + $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
|
82 | + $args['TKT_parent'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
83 | + } |
|
84 | + |
|
85 | + // price can be 0 |
|
86 | + if (array_key_exists('price', $input)) { |
|
87 | + $args['TKT_price'] = (float) $input['price']; |
|
88 | + } |
|
89 | + |
|
90 | + // prices can be an empty array when all prices are deleted |
|
91 | + if (array_key_exists('prices', $input) && is_array($input['prices'])) { |
|
92 | + $args['prices'] = array_map('sanitize_text_field', $input['prices']); |
|
93 | + } |
|
94 | + |
|
95 | + if (array_key_exists('quantity', $input)) { |
|
96 | + $args['TKT_qty'] = (int) $input['quantity']; |
|
97 | + } |
|
98 | + |
|
99 | + if (array_key_exists('reserved', $input)) { |
|
100 | + $args['TKT_reserved'] = (int) $input['reserved']; |
|
101 | + } |
|
102 | + |
|
103 | + if (array_key_exists('reverseCalculate', $input)) { |
|
104 | + $args['TKT_reverse_calculate'] = (bool) $input['reverseCalculate']; |
|
105 | + } |
|
106 | + |
|
107 | + if (array_key_exists('row', $input)) { |
|
108 | + $args['TKT_row'] = (int) $input['row']; |
|
109 | + } |
|
110 | + |
|
111 | + if (array_key_exists('sold', $input)) { |
|
112 | + $args['TKT_sold'] = (int) $input['sold']; |
|
113 | + } |
|
114 | + |
|
115 | + if (! empty($input['startDate'])) { |
|
116 | + $args['TKT_start_date'] = new DateTime(sanitize_text_field($input['startDate'])); |
|
117 | + } |
|
118 | + |
|
119 | + if (array_key_exists('uses', $input)) { |
|
120 | + $args['TKT_uses'] = (int) $input['uses']; |
|
121 | + } |
|
122 | + |
|
123 | + if (! empty($input['wpUser'])) { |
|
124 | + $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser'])); |
|
125 | + $args['TKT_wp_user'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
126 | + } |
|
127 | + |
|
128 | + if (array_key_exists('visibility', $input)) { |
|
129 | + $args['TKT_visibility'] = (int) $input['visibility']; |
|
130 | + } |
|
131 | + |
|
132 | + return apply_filters( |
|
133 | + 'FHEE__EventEspresso_core_domain_services_graphql_data_mutations__ticket_args', |
|
134 | + $args, |
|
135 | + $input |
|
136 | + ); |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * Sets the related datetimes for the given ticket. |
|
142 | + * |
|
143 | + * @param EE_Ticket $entity The Ticket instance. |
|
144 | + * @param array $datetimes Array of datetime IDs to relate. |
|
145 | + * @throws EE_Error |
|
146 | + * @throws InvalidArgumentException |
|
147 | + * @throws InvalidDataTypeException |
|
148 | + * @throws InvalidInterfaceException |
|
149 | + * @throws ReflectionException |
|
150 | + */ |
|
151 | + public static function setRelatedDatetimes(EE_Ticket $entity, array $datetimes) |
|
152 | + { |
|
153 | + $relationName = 'Datetime'; |
|
154 | + // Remove all the existing related datetimes |
|
155 | + |
|
156 | + $entity->_remove_relations($relationName); |
|
157 | + // @todo replace loop with single query |
|
158 | + foreach ($datetimes as $ID) { |
|
159 | + $parts = Relay::fromGlobalId($ID); |
|
160 | + if (! empty($parts['id']) && absint($parts['id'])) { |
|
161 | + $entity->_add_relation_to( |
|
162 | + $parts['id'], |
|
163 | + $relationName |
|
164 | + ); |
|
165 | + } |
|
166 | + } |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * Sets the related prices for the given ticket. |
|
172 | + * |
|
173 | + * @param EE_Ticket $entity The Ticket instance. |
|
174 | + * @param array $prices Array of entity IDs to relate. |
|
175 | + * @throws EE_Error |
|
176 | + * @throws InvalidArgumentException |
|
177 | + * @throws InvalidDataTypeException |
|
178 | + * @throws InvalidInterfaceException |
|
179 | + * @throws ReflectionException |
|
180 | + */ |
|
181 | + public static function setRelatedPrices(EE_Ticket $entity, array $prices) |
|
182 | + { |
|
183 | + $relationName = 'Price'; |
|
184 | + // Remove all the existing related entities |
|
185 | + $entity->_remove_relations($relationName); |
|
186 | + |
|
187 | + // @todo replace loop with single query |
|
188 | + foreach ($prices as $ID) { |
|
189 | + $parts = Relay::fromGlobalId($ID); |
|
190 | + if (! empty($parts['id']) && absint($parts['id'])) { |
|
191 | + $entity->_add_relation_to( |
|
192 | + $parts['id'], |
|
193 | + $relationName |
|
194 | + ); |
|
195 | + } |
|
196 | + } |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @param EE_Ticket $ticket_entity |
|
202 | + * @throws EE_Error |
|
203 | + * @throws InvalidArgumentException |
|
204 | + * @throws InvalidDataTypeException |
|
205 | + * @throws InvalidInterfaceException |
|
206 | + * @throws ReflectionException |
|
207 | + */ |
|
208 | + public static function addDefaultPrices(EE_Ticket $ticket_entity) |
|
209 | + { |
|
210 | + /** @var DefaultPrices $default_prices */ |
|
211 | + $default_prices = LoaderFactory::getLoader()->getShared( |
|
212 | + 'EventEspresso\core\domain\services\admin\entities\DefaultPrices' |
|
213 | + ); |
|
214 | + $default_prices->create($ticket_entity); |
|
215 | + } |
|
216 | 216 | } |
@@ -50,7 +50,7 @@ |
||
50 | 50 | |
51 | 51 | public function setCurrentUser(): void |
52 | 52 | { |
53 | - if (! $this->current_user instanceof WP_User) { |
|
53 | + if ( ! $this->current_user instanceof WP_User) { |
|
54 | 54 | $this->current_user = wp_get_current_user(); |
55 | 55 | $event_manager_roles = array_keys($this->event_managers->roles()); |
56 | 56 | $current_user_roles = $this->current_user->roles; |
@@ -13,78 +13,78 @@ |
||
13 | 13 | */ |
14 | 14 | class CurrentUser |
15 | 15 | { |
16 | - /** |
|
17 | - * @var WP_User |
|
18 | - */ |
|
19 | - private $current_user; |
|
20 | - |
|
21 | - /** |
|
22 | - * @var boolean |
|
23 | - */ |
|
24 | - private $is_event_manager = false; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var boolean |
|
28 | - */ |
|
29 | - private $is_logged_in = false; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @var EventManagers |
|
34 | - */ |
|
35 | - private $event_managers; |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * CurrentUser constructor. |
|
40 | - * |
|
41 | - * @param EventManagers $event_managers |
|
42 | - */ |
|
43 | - public function __construct(EventManagers $event_managers) |
|
44 | - { |
|
45 | - $this->event_managers = $event_managers; |
|
46 | - $this->setCurrentUser(); |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - public function setCurrentUser(): void |
|
51 | - { |
|
52 | - if (! $this->current_user instanceof WP_User) { |
|
53 | - $this->current_user = wp_get_current_user(); |
|
54 | - $event_manager_roles = array_keys($this->event_managers->roles()); |
|
55 | - $current_user_roles = $this->current_user->roles; |
|
56 | - $this->is_event_manager = ! empty(array_intersect($event_manager_roles, $current_user_roles)); |
|
57 | - $this->is_logged_in = $this->current_user->exists(); |
|
58 | - } |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @return WP_User |
|
64 | - */ |
|
65 | - public function currentUser(): ?WP_User |
|
66 | - { |
|
67 | - $this->setCurrentUser(); |
|
68 | - return $this->current_user; |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @return bool |
|
74 | - */ |
|
75 | - public function isEventManager(): bool |
|
76 | - { |
|
77 | - $this->setCurrentUser(); |
|
78 | - return $this->is_event_manager; |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @return bool |
|
84 | - */ |
|
85 | - public function isLoggedIn(): bool |
|
86 | - { |
|
87 | - $this->setCurrentUser(); |
|
88 | - return $this->is_logged_in; |
|
89 | - } |
|
16 | + /** |
|
17 | + * @var WP_User |
|
18 | + */ |
|
19 | + private $current_user; |
|
20 | + |
|
21 | + /** |
|
22 | + * @var boolean |
|
23 | + */ |
|
24 | + private $is_event_manager = false; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var boolean |
|
28 | + */ |
|
29 | + private $is_logged_in = false; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @var EventManagers |
|
34 | + */ |
|
35 | + private $event_managers; |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * CurrentUser constructor. |
|
40 | + * |
|
41 | + * @param EventManagers $event_managers |
|
42 | + */ |
|
43 | + public function __construct(EventManagers $event_managers) |
|
44 | + { |
|
45 | + $this->event_managers = $event_managers; |
|
46 | + $this->setCurrentUser(); |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + public function setCurrentUser(): void |
|
51 | + { |
|
52 | + if (! $this->current_user instanceof WP_User) { |
|
53 | + $this->current_user = wp_get_current_user(); |
|
54 | + $event_manager_roles = array_keys($this->event_managers->roles()); |
|
55 | + $current_user_roles = $this->current_user->roles; |
|
56 | + $this->is_event_manager = ! empty(array_intersect($event_manager_roles, $current_user_roles)); |
|
57 | + $this->is_logged_in = $this->current_user->exists(); |
|
58 | + } |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @return WP_User |
|
64 | + */ |
|
65 | + public function currentUser(): ?WP_User |
|
66 | + { |
|
67 | + $this->setCurrentUser(); |
|
68 | + return $this->current_user; |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @return bool |
|
74 | + */ |
|
75 | + public function isEventManager(): bool |
|
76 | + { |
|
77 | + $this->setCurrentUser(); |
|
78 | + return $this->is_event_manager; |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @return bool |
|
84 | + */ |
|
85 | + public function isLoggedIn(): bool |
|
86 | + { |
|
87 | + $this->setCurrentUser(); |
|
88 | + return $this->is_logged_in; |
|
89 | + } |
|
90 | 90 | } |