@@ -34,15 +34,15 @@ discard block |
||
34 | 34 | /** |
35 | 35 | * @since 1.0.0 |
36 | 36 | */ |
37 | - protected function get_related_entity_ids( WordPoints_Entity $entity ) { |
|
38 | - return $entity->get_the_attr_value( $this->related_ids_field ); |
|
37 | + protected function get_related_entity_ids(WordPoints_Entity $entity) { |
|
38 | + return $entity->get_the_attr_value($this->related_ids_field); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * @since 1.0.0 |
43 | 43 | */ |
44 | 44 | public function get_title() { |
45 | - return __( 'Roles', 'wordpoints' ); |
|
45 | + return __('Roles', 'wordpoints'); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | 'conditions' => array( |
63 | 63 | array( |
64 | 64 | 'field' => 'meta_key', |
65 | - 'value' => $GLOBALS['wpdb']->get_blog_prefix() . 'capabilities', |
|
65 | + 'value' => $GLOBALS['wpdb']->get_blog_prefix().'capabilities', |
|
66 | 66 | ), |
67 | 67 | ), |
68 | 68 | ), |
@@ -35,18 +35,18 @@ discard block |
||
35 | 35 | /** |
36 | 36 | * @since 1.0.0 |
37 | 37 | */ |
38 | - public function __construct( $id, WordPoints_Hook_Reaction_StoreI $store ) { |
|
38 | + public function __construct($id, WordPoints_Hook_Reaction_StoreI $store) { |
|
39 | 39 | |
40 | - $this->ID = wordpoints_int( $id ); |
|
40 | + $this->ID = wordpoints_int($id); |
|
41 | 41 | $this->store = $store; |
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
45 | 45 | * @since 1.0.0 |
46 | 46 | */ |
47 | - public function __get( $var ) { |
|
47 | + public function __get($var) { |
|
48 | 48 | |
49 | - if ( 'ID' === $var ) { |
|
49 | + if ('ID' === $var) { |
|
50 | 50 | return $this->ID; |
51 | 51 | } |
52 | 52 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @since 1.0.0 |
70 | 70 | */ |
71 | 71 | public function get_reactor_slug() { |
72 | - return $this->get_meta( 'reactor' ); // TODO remove this method? |
|
72 | + return $this->get_meta('reactor'); // TODO remove this method? |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -103,12 +103,12 @@ discard block |
||
103 | 103 | * @param bool $fail_fast Whether to fail as soon as |
104 | 104 | * the first error is found. |
105 | 105 | */ |
106 | - public function __construct( $settings, $fail_fast = false ) { |
|
106 | + public function __construct($settings, $fail_fast = false) { |
|
107 | 107 | |
108 | 108 | $this->fail_fast = $fail_fast; |
109 | 109 | $this->hooks = wordpoints_hooks(); |
110 | 110 | |
111 | - if ( $settings instanceof WordPoints_Hook_ReactionI ) { |
|
111 | + if ($settings instanceof WordPoints_Hook_ReactionI) { |
|
112 | 112 | |
113 | 113 | $this->reaction = $settings; |
114 | 114 | $this->settings = $this->reaction->get_all_meta(); |
@@ -119,11 +119,11 @@ discard block |
||
119 | 119 | |
120 | 120 | $this->settings = $settings; |
121 | 121 | |
122 | - if ( isset( $this->settings['event'] ) ) { |
|
122 | + if (isset($this->settings['event'])) { |
|
123 | 123 | $this->event_slug = $this->settings['event']; |
124 | 124 | } |
125 | 125 | |
126 | - if ( isset( $this->settings['reactor'] ) ) { |
|
126 | + if (isset($this->settings['reactor'])) { |
|
127 | 127 | $this->reactor_slug = $this->settings['reactor']; |
128 | 128 | } |
129 | 129 | } |
@@ -146,16 +146,16 @@ discard block |
||
146 | 146 | $fail_fast = $this->fail_fast; |
147 | 147 | $this->fail_fast = true; |
148 | 148 | |
149 | - if ( ! isset( $this->event_slug ) ) { |
|
150 | - $this->add_error( __( 'Event is missing.', 'wordpoints' ), 'event' ); |
|
151 | - } elseif ( ! $this->hooks->events->is_registered( $this->event_slug ) ) { |
|
152 | - $this->add_error( __( 'Event is invalid.', 'wordpoints' ), 'event' ); |
|
149 | + if ( ! isset($this->event_slug)) { |
|
150 | + $this->add_error(__('Event is missing.', 'wordpoints'), 'event'); |
|
151 | + } elseif ( ! $this->hooks->events->is_registered($this->event_slug)) { |
|
152 | + $this->add_error(__('Event is invalid.', 'wordpoints'), 'event'); |
|
153 | 153 | } |
154 | 154 | |
155 | - if ( ! isset( $this->reactor_slug ) ) { |
|
156 | - $this->add_error( __( 'Reactor is missing.', 'wordpoints' ), 'reactor' ); |
|
157 | - } elseif ( ! $this->hooks->reactors->is_registered( $this->reactor_slug ) ) { |
|
158 | - $this->add_error( __( 'Reactor is invalid.', 'wordpoints' ), 'reactor' ); |
|
155 | + if ( ! isset($this->reactor_slug)) { |
|
156 | + $this->add_error(__('Reactor is missing.', 'wordpoints'), 'reactor'); |
|
157 | + } elseif ( ! $this->hooks->reactors->is_registered($this->reactor_slug)) { |
|
158 | + $this->add_error(__('Reactor is invalid.', 'wordpoints'), 'reactor'); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | // From here on out we can collect errors as they come (unless we are |
@@ -166,16 +166,16 @@ discard block |
||
166 | 166 | $this->event_slug |
167 | 167 | ); |
168 | 168 | |
169 | - $this->event_args = new WordPoints_Hook_Event_Args( $event_args ); |
|
170 | - $this->event_args->set_validator( $this ); |
|
169 | + $this->event_args = new WordPoints_Hook_Event_Args($event_args); |
|
170 | + $this->event_args->set_validator($this); |
|
171 | 171 | |
172 | - $reactor = $this->hooks->reactors->get( $this->reactor_slug ); |
|
172 | + $reactor = $this->hooks->reactors->get($this->reactor_slug); |
|
173 | 173 | |
174 | - $this->settings = $reactor->validate_settings( $this->settings, $this, $this->event_args ); |
|
174 | + $this->settings = $reactor->validate_settings($this->settings, $this, $this->event_args); |
|
175 | 175 | |
176 | 176 | /** @var WordPoints_Hook_Extension $extension */ |
177 | - foreach ( $this->hooks->extensions->get_all() as $extension ) { |
|
178 | - $this->settings = $extension->validate_settings( $this->settings, $this, $this->event_args ); |
|
177 | + foreach ($this->hooks->extensions->get_all() as $extension) { |
|
178 | + $this->settings = $extension->validate_settings($this->settings, $this, $this->event_args); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -185,12 +185,12 @@ discard block |
||
185 | 185 | * @param WordPoints_Hook_Reaction_Validator $validator The validator object. |
186 | 186 | * @param WordPoints_Hook_Event_Args $args The event args object. |
187 | 187 | */ |
188 | - $this->settings = apply_filters( 'wordpoints_hook_reaction_validate', $this->settings, $this, $this->event_args ); |
|
188 | + $this->settings = apply_filters('wordpoints_hook_reaction_validate', $this->settings, $this, $this->event_args); |
|
189 | 189 | |
190 | - } catch ( WordPoints_Hook_Validator_Exception $e ) { |
|
190 | + } catch (WordPoints_Hook_Validator_Exception $e) { |
|
191 | 191 | |
192 | 192 | // Do nothing. |
193 | - unset( $e ); |
|
193 | + unset($e); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | return $this->settings; |
@@ -218,17 +218,17 @@ discard block |
||
218 | 218 | * @throws WordPoints_Hook_Validator_Exception If the validator is configured to |
219 | 219 | * fail as soon as an error is found. |
220 | 220 | */ |
221 | - public function add_error( $message, $field = null ) { |
|
221 | + public function add_error($message, $field = null) { |
|
222 | 222 | |
223 | 223 | $field_stack = $this->field_stack; |
224 | 224 | |
225 | - if ( null !== $field ) { |
|
225 | + if (null !== $field) { |
|
226 | 226 | $field_stack[] = $field; |
227 | 227 | } |
228 | 228 | |
229 | - $this->errors[] = array( 'message' => $message, 'field' => $field_stack ); |
|
229 | + $this->errors[] = array('message' => $message, 'field' => $field_stack); |
|
230 | 230 | |
231 | - if ( $this->fail_fast ) { |
|
231 | + if ($this->fail_fast) { |
|
232 | 232 | throw new WordPoints_Hook_Validator_Exception; |
233 | 233 | } |
234 | 234 | } |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * @return bool Whether the validator found any errors. |
242 | 242 | */ |
243 | 243 | public function had_errors() { |
244 | - return ! empty( $this->errors ); |
|
244 | + return ! empty($this->errors); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * |
263 | 263 | * @param string $field The field. |
264 | 264 | */ |
265 | - public function push_field( $field ) { |
|
265 | + public function push_field($field) { |
|
266 | 266 | $this->field_stack[] = $field; |
267 | 267 | } |
268 | 268 | |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | * @since 1.0.0 |
273 | 273 | */ |
274 | 274 | public function pop_field() { |
275 | - array_pop( $this->field_stack ); |
|
275 | + array_pop($this->field_stack); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | */ |
318 | 318 | public function get_id() { |
319 | 319 | |
320 | - if ( ! $this->reaction ) { |
|
320 | + if ( ! $this->reaction) { |
|
321 | 321 | return false; |
322 | 322 | } |
323 | 323 | |
@@ -355,13 +355,13 @@ discard block |
||
355 | 355 | * |
356 | 356 | * @return mixed The meta value. |
357 | 357 | */ |
358 | - public function get_meta( $key ) { |
|
358 | + public function get_meta($key) { |
|
359 | 359 | |
360 | - if ( ! isset( $this->settings[ $key ] ) ) { |
|
360 | + if ( ! isset($this->settings[$key])) { |
|
361 | 361 | return null; |
362 | 362 | } |
363 | 363 | |
364 | - return $this->settings[ $key ]; |
|
364 | + return $this->settings[$key]; |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | /** |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @param string $slug The slug of this store. |
26 | 26 | */ |
27 | - public function __construct( $slug ); |
|
27 | + public function __construct($slug); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Get the slug of this reaction store. |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @return bool Whether the reaction exists. |
61 | 61 | */ |
62 | - public function reaction_exists( $id ); |
|
62 | + public function reaction_exists($id); |
|
63 | 63 | |
64 | 64 | /** |
65 | 65 | * Get an reaction object. |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @return WordPoints_Hook_ReactionI|false The reaction, or false if nonexistent. |
72 | 72 | */ |
73 | - public function get_reaction( $id ); |
|
73 | + public function get_reaction($id); |
|
74 | 74 | |
75 | 75 | /** |
76 | 76 | * Create an reaction. |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | * The reaction object if created successfully. False or a validator |
84 | 84 | * instance if not. |
85 | 85 | */ |
86 | - public function create_reaction( array $settings ); |
|
86 | + public function create_reaction(array $settings); |
|
87 | 87 | |
88 | 88 | /** |
89 | 89 | * Update an reaction. |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * The reaction object if updated successfully. False or a validator |
98 | 98 | * instance if not. |
99 | 99 | */ |
100 | - public function update_reaction( $id, array $settings ); |
|
100 | + public function update_reaction($id, array $settings); |
|
101 | 101 | |
102 | 102 | /** |
103 | 103 | * Delete an reaction. |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @return bool Whether the reaction was deleted successfully. |
110 | 110 | */ |
111 | - public function delete_reaction( $id ); |
|
111 | + public function delete_reaction($id); |
|
112 | 112 | |
113 | 113 | /** |
114 | 114 | * Get all hook reactions for the reactor. |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @return WordPoints_Hook_ReactionI[] |
133 | 133 | */ |
134 | - public function get_reactions_to_event( $event_slug ); |
|
134 | + public function get_reactions_to_event($event_slug); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | // EOF |
@@ -37,8 +37,8 @@ |
||
37 | 37 | /** |
38 | 38 | * @since 1.0.0 |
39 | 39 | */ |
40 | - protected function get_related_entity_ids( WordPoints_Entity $entity ) { |
|
41 | - return $entity->get_the_attr_value( $this->related_ids_field ); |
|
40 | + protected function get_related_entity_ids(WordPoints_Entity $entity) { |
|
41 | + return $entity->get_the_attr_value($this->related_ids_field); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -37,13 +37,13 @@ discard block |
||
37 | 37 | /** |
38 | 38 | * @since 1.0.0 |
39 | 39 | */ |
40 | - public function __construct( $slug ) { |
|
40 | + public function __construct($slug) { |
|
41 | 41 | |
42 | 42 | $hooks = wordpoints_hooks(); |
43 | 43 | |
44 | 44 | $this->router = $hooks->router; |
45 | 45 | |
46 | - parent::__construct( $slug ); |
|
46 | + parent::__construct($slug); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function init() { |
53 | 53 | |
54 | - $this->sub_apps->register( 'args', 'WordPoints_Class_Registry_Children' ); |
|
54 | + $this->sub_apps->register('args', 'WordPoints_Class_Registry_Children'); |
|
55 | 55 | |
56 | 56 | parent::init(); |
57 | 57 | } |
@@ -75,25 +75,25 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @return bool Whether the event was registered. |
77 | 77 | */ |
78 | - public function register( $slug, $class, array $args = array() ) { |
|
78 | + public function register($slug, $class, array $args = array()) { |
|
79 | 79 | |
80 | - parent::register( $slug, $class, $args ); |
|
80 | + parent::register($slug, $class, $args); |
|
81 | 81 | |
82 | - if ( isset( $args['actions'] ) ) { |
|
83 | - foreach ( $args['actions'] as $type => $actions ) { |
|
84 | - foreach ( (array) $actions as $action_slug ) { |
|
85 | - $this->router->add_event_to_action( $slug, $action_slug, $type ); |
|
82 | + if (isset($args['actions'])) { |
|
83 | + foreach ($args['actions'] as $type => $actions) { |
|
84 | + foreach ((array) $actions as $action_slug) { |
|
85 | + $this->router->add_event_to_action($slug, $action_slug, $type); |
|
86 | 86 | } |
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
90 | - if ( isset( $args['args'] ) ) { |
|
91 | - foreach ( $args['args'] as $arg_slug => $class ) { |
|
92 | - $this->args->register( $slug, $arg_slug, $class ); |
|
90 | + if (isset($args['args'])) { |
|
91 | + foreach ($args['args'] as $arg_slug => $class) { |
|
92 | + $this->args->register($slug, $arg_slug, $class); |
|
93 | 93 | } |
94 | 94 | } |
95 | 95 | |
96 | - $this->event_data[ $slug ] = $args; |
|
96 | + $this->event_data[$slug] = $args; |
|
97 | 97 | |
98 | 98 | return true; |
99 | 99 | } |
@@ -101,23 +101,23 @@ discard block |
||
101 | 101 | /** |
102 | 102 | * @since 1.0.0 |
103 | 103 | */ |
104 | - public function deregister( $slug ) { |
|
104 | + public function deregister($slug) { |
|
105 | 105 | |
106 | - if ( ! $this->is_registered( $slug ) ) { |
|
106 | + if ( ! $this->is_registered($slug)) { |
|
107 | 107 | return; |
108 | 108 | } |
109 | 109 | |
110 | - parent::deregister( $slug ); |
|
110 | + parent::deregister($slug); |
|
111 | 111 | |
112 | - foreach ( (array) $this->event_data[ $slug ]['actions'] as $type => $actions ) { |
|
113 | - foreach ( (array) $actions as $action_slug ) { |
|
114 | - $this->router->remove_event_from_action( $slug, $action_slug, $type ); |
|
112 | + foreach ((array) $this->event_data[$slug]['actions'] as $type => $actions) { |
|
113 | + foreach ((array) $actions as $action_slug) { |
|
114 | + $this->router->remove_event_from_action($slug, $action_slug, $type); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
118 | - $this->args->deregister_children( $slug ); |
|
118 | + $this->args->deregister_children($slug); |
|
119 | 119 | |
120 | - unset( $this->event_data[ $slug ] ); |
|
120 | + unset($this->event_data[$slug]); |
|
121 | 121 | } |
122 | 122 | } |
123 | 123 |
@@ -36,11 +36,11 @@ discard block |
||
36 | 36 | public function get_ui_script_data() { |
37 | 37 | |
38 | 38 | $periods = array( |
39 | - MINUTE_IN_SECONDS => __( 'Minute', 'wordpoints' ), |
|
40 | - HOUR_IN_SECONDS => __( 'Hour', 'wordpoints' ), |
|
41 | - DAY_IN_SECONDS => __( 'Day', 'wordpoints' ), |
|
42 | - WEEK_IN_SECONDS => __( 'Week', 'wordpoints' ), |
|
43 | - 30 * DAY_IN_SECONDS => __( 'Month', 'wordpoints' ), |
|
39 | + MINUTE_IN_SECONDS => __('Minute', 'wordpoints'), |
|
40 | + HOUR_IN_SECONDS => __('Hour', 'wordpoints'), |
|
41 | + DAY_IN_SECONDS => __('Day', 'wordpoints'), |
|
42 | + WEEK_IN_SECONDS => __('Week', 'wordpoints'), |
|
43 | + 30 * DAY_IN_SECONDS => __('Month', 'wordpoints'), |
|
44 | 44 | ); |
45 | 45 | |
46 | 46 | /** |
@@ -50,12 +50,12 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @param string[] $periods The period titles, indexed by length in seconds. |
52 | 52 | */ |
53 | - $periods = apply_filters( 'wordpoints_hooks_ui_data_periods', $periods ); |
|
53 | + $periods = apply_filters('wordpoints_hooks_ui_data_periods', $periods); |
|
54 | 54 | |
55 | 55 | return array( |
56 | 56 | 'periods' => $periods, |
57 | 57 | 'l10n' => array( |
58 | - 'label' => __( 'Trigger reaction no more than once per:', 'wordpoints' ), |
|
58 | + 'label' => __('Trigger reaction no more than once per:', 'wordpoints'), |
|
59 | 59 | ), |
60 | 60 | ); |
61 | 61 | } |
@@ -69,25 +69,25 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return array The validated periods. |
71 | 71 | */ |
72 | - protected function validate_action_type_settings( $periods ) { |
|
72 | + protected function validate_action_type_settings($periods) { |
|
73 | 73 | |
74 | - if ( ! is_array( $periods ) ) { |
|
74 | + if ( ! is_array($periods)) { |
|
75 | 75 | |
76 | 76 | $this->validator->add_error( |
77 | - __( 'Periods do not match expected format.', 'wordpoints' ) |
|
77 | + __('Periods do not match expected format.', 'wordpoints') |
|
78 | 78 | ); |
79 | 79 | |
80 | 80 | return array(); |
81 | 81 | } |
82 | 82 | |
83 | - foreach ( $periods as $index => $period ) { |
|
83 | + foreach ($periods as $index => $period) { |
|
84 | 84 | |
85 | - $this->validator->push_field( $index ); |
|
85 | + $this->validator->push_field($index); |
|
86 | 86 | |
87 | - $period = $this->validate_period( $period ); |
|
87 | + $period = $this->validate_period($period); |
|
88 | 88 | |
89 | - if ( $period ) { |
|
90 | - $periods[ $index ] = $period; |
|
89 | + if ($period) { |
|
90 | + $periods[$index] = $period; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | $this->validator->pop_field(); |
@@ -105,30 +105,30 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @return array|false The validated period, or false if invalid. |
107 | 107 | */ |
108 | - protected function validate_period( $period ) { |
|
108 | + protected function validate_period($period) { |
|
109 | 109 | |
110 | - if ( ! is_array( $period ) ) { |
|
110 | + if ( ! is_array($period)) { |
|
111 | 111 | $this->validator->add_error( |
112 | - __( 'Period does not match expected format.', 'wordpoints' ) |
|
112 | + __('Period does not match expected format.', 'wordpoints') |
|
113 | 113 | ); |
114 | 114 | |
115 | 115 | return false; |
116 | 116 | } |
117 | 117 | |
118 | - if ( isset( $period['args'] ) ) { |
|
119 | - $this->validate_period_args( $period['args'] ); |
|
118 | + if (isset($period['args'])) { |
|
119 | + $this->validate_period_args($period['args']); |
|
120 | 120 | } |
121 | 121 | |
122 | - if ( ! isset( $period['length'] ) ) { |
|
122 | + if ( ! isset($period['length'])) { |
|
123 | 123 | |
124 | 124 | $this->validator->add_error( |
125 | - __( 'Period length setting is missing.', 'wordpoints' ) |
|
125 | + __('Period length setting is missing.', 'wordpoints') |
|
126 | 126 | ); |
127 | 127 | |
128 | - } elseif ( false === wordpoints_posint( $period['length'] ) ) { |
|
128 | + } elseif (false === wordpoints_posint($period['length'])) { |
|
129 | 129 | |
130 | 130 | $this->validator->add_error( |
131 | - __( 'Period length must be a positive integer.', 'wordpoints' ) |
|
131 | + __('Period length must be a positive integer.', 'wordpoints') |
|
132 | 132 | , 'length' |
133 | 133 | ); |
134 | 134 | |
@@ -145,34 +145,34 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @param mixed $args The args the period is related to. |
147 | 147 | */ |
148 | - protected function validate_period_args( $args ) { |
|
148 | + protected function validate_period_args($args) { |
|
149 | 149 | |
150 | - if ( ! is_array( $args ) ) { |
|
150 | + if ( ! is_array($args)) { |
|
151 | 151 | |
152 | 152 | $this->validator->add_error( |
153 | - __( 'Period does not match expected format.', 'wordpoints' ) |
|
153 | + __('Period does not match expected format.', 'wordpoints') |
|
154 | 154 | , 'args' |
155 | 155 | ); |
156 | 156 | |
157 | 157 | return; |
158 | 158 | } |
159 | 159 | |
160 | - $this->validator->push_field( 'args' ); |
|
160 | + $this->validator->push_field('args'); |
|
161 | 161 | |
162 | - foreach ( $args as $index => $hierarchy ) { |
|
162 | + foreach ($args as $index => $hierarchy) { |
|
163 | 163 | |
164 | - $this->validator->push_field( $index ); |
|
164 | + $this->validator->push_field($index); |
|
165 | 165 | |
166 | - if ( ! is_array( $hierarchy ) ) { |
|
166 | + if ( ! is_array($hierarchy)) { |
|
167 | 167 | |
168 | 168 | $this->validator->add_error( |
169 | - __( 'Period does not match expected format.', 'wordpoints' ) |
|
169 | + __('Period does not match expected format.', 'wordpoints') |
|
170 | 170 | ); |
171 | 171 | |
172 | - } elseif ( ! $this->event_args->get_from_hierarchy( $hierarchy ) ) { |
|
172 | + } elseif ( ! $this->event_args->get_from_hierarchy($hierarchy)) { |
|
173 | 173 | |
174 | 174 | $this->validator->add_error( |
175 | - __( 'Invalid period.', 'wordpoints' ) // TODO better error message |
|
175 | + __('Invalid period.', 'wordpoints') // TODO better error message |
|
176 | 176 | ); |
177 | 177 | } |
178 | 178 | |
@@ -185,19 +185,19 @@ discard block |
||
185 | 185 | /** |
186 | 186 | * @since 1.0.0 |
187 | 187 | */ |
188 | - public function should_hit( WordPoints_Hook_Fire $fire ) { |
|
188 | + public function should_hit(WordPoints_Hook_Fire $fire) { |
|
189 | 189 | |
190 | - $periods = $this->get_settings_from_fire( $fire ); |
|
190 | + $periods = $this->get_settings_from_fire($fire); |
|
191 | 191 | |
192 | - if ( empty( $periods ) ) { |
|
192 | + if (empty($periods)) { |
|
193 | 193 | return true; |
194 | 194 | } |
195 | 195 | |
196 | 196 | $this->event_args = $fire->event_args; |
197 | 197 | $this->action_type = $fire->action_type; |
198 | 198 | |
199 | - foreach ( $periods as $period ) { |
|
200 | - if ( ! $this->has_period_ended( $period, $fire->reaction ) ) { |
|
199 | + foreach ($periods as $period) { |
|
200 | + if ( ! $this->has_period_ended($period, $fire->reaction)) { |
|
201 | 201 | return false; |
202 | 202 | } |
203 | 203 | } |
@@ -221,24 +221,24 @@ discard block |
||
221 | 221 | ) { |
222 | 222 | |
223 | 223 | $period = $this->get_period_by_reaction( |
224 | - $this->get_period_signature( $settings, $reaction ) |
|
224 | + $this->get_period_signature($settings, $reaction) |
|
225 | 225 | , $reaction |
226 | 226 | ); |
227 | 227 | |
228 | 228 | // If the period isn't found, we know that we can still fire. |
229 | - if ( ! $period ) { |
|
229 | + if ( ! $period) { |
|
230 | 230 | return true; |
231 | 231 | } |
232 | 232 | |
233 | - $now = current_time( 'timestamp' ); |
|
234 | - $hit_time = strtotime( $period->date, $now ); |
|
233 | + $now = current_time('timestamp'); |
|
234 | + $hit_time = strtotime($period->date, $now); |
|
235 | 235 | |
236 | - if ( ! empty( $settings['relative'] ) ) { |
|
237 | - return ( $hit_time < $now - $settings['length'] ); |
|
236 | + if ( ! empty($settings['relative'])) { |
|
237 | + return ($hit_time < $now - $settings['length']); |
|
238 | 238 | } else { |
239 | 239 | return ( |
240 | - (int) ( $hit_time / $settings['length'] ) |
|
241 | - < (int) ( $now / $settings['length'] ) |
|
240 | + (int) ($hit_time / $settings['length']) |
|
241 | + < (int) ($now / $settings['length']) |
|
242 | 242 | ); |
243 | 243 | } |
244 | 244 | } |
@@ -252,24 +252,24 @@ discard block |
||
252 | 252 | * |
253 | 253 | * @return array The arg values. |
254 | 254 | */ |
255 | - protected function get_arg_values( array $period_args ) { |
|
255 | + protected function get_arg_values(array $period_args) { |
|
256 | 256 | |
257 | 257 | $values = array(); |
258 | 258 | |
259 | - foreach ( $period_args as $arg_hierarchy ) { |
|
259 | + foreach ($period_args as $arg_hierarchy) { |
|
260 | 260 | |
261 | 261 | $arg = $this->event_args->get_from_hierarchy( |
262 | 262 | $arg_hierarchy |
263 | 263 | ); |
264 | 264 | |
265 | - if ( ! $arg instanceof WordPoints_EntityishI ) { |
|
265 | + if ( ! $arg instanceof WordPoints_EntityishI) { |
|
266 | 266 | continue; |
267 | 267 | } |
268 | 268 | |
269 | - $values[ implode( '.', $arg_hierarchy ) ] = $arg->get_the_value(); |
|
269 | + $values[implode('.', $arg_hierarchy)] = $arg->get_the_value(); |
|
270 | 270 | } |
271 | 271 | |
272 | - ksort( $values ); |
|
272 | + ksort($values); |
|
273 | 273 | |
274 | 274 | return $values; |
275 | 275 | } |
@@ -283,11 +283,11 @@ discard block |
||
283 | 283 | * |
284 | 284 | * @return object|false The period data, or false if not found. |
285 | 285 | */ |
286 | - protected function get_period( $period_id ) { |
|
286 | + protected function get_period($period_id) { |
|
287 | 287 | |
288 | - $period = wp_cache_get( $period_id, 'wordpoints_hook_periods' ); |
|
288 | + $period = wp_cache_get($period_id, 'wordpoints_hook_periods'); |
|
289 | 289 | |
290 | - if ( ! $period ) { |
|
290 | + if ( ! $period) { |
|
291 | 291 | |
292 | 292 | global $wpdb; |
293 | 293 | |
@@ -304,11 +304,11 @@ discard block |
||
304 | 304 | ) |
305 | 305 | ); |
306 | 306 | |
307 | - if ( ! $period ) { |
|
307 | + if ( ! $period) { |
|
308 | 308 | return false; |
309 | 309 | } |
310 | 310 | |
311 | - wp_cache_set( $period->id, $period, 'wordpoints_hook_periods' ); |
|
311 | + wp_cache_set($period->id, $period, 'wordpoints_hook_periods'); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | return $period; |
@@ -332,14 +332,14 @@ discard block |
||
332 | 332 | |
333 | 333 | $reaction_guid = $reaction->get_guid(); |
334 | 334 | |
335 | - $cache_key = wp_json_encode( $reaction_guid ) . "-{$signature}-{$this->action_type}"; |
|
335 | + $cache_key = wp_json_encode($reaction_guid)."-{$signature}-{$this->action_type}"; |
|
336 | 336 | |
337 | 337 | // Before we run the query, we try to lookup the ID in the cache. |
338 | - $period_id = wp_cache_get( $cache_key, 'wordpoints_hook_period_ids_by_reaction' ); |
|
338 | + $period_id = wp_cache_get($cache_key, 'wordpoints_hook_period_ids_by_reaction'); |
|
339 | 339 | |
340 | 340 | // If we found it, we can retrieve the period by ID instead. |
341 | - if ( $period_id ) { |
|
342 | - return $this->get_period( $period_id ); |
|
341 | + if ($period_id) { |
|
342 | + return $this->get_period($period_id); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | global $wpdb; |
@@ -362,18 +362,18 @@ discard block |
||
362 | 362 | " |
363 | 363 | , $signature |
364 | 364 | , $reaction_guid['store'] |
365 | - , wp_json_encode( $reaction_guid['context_id'] ) |
|
365 | + , wp_json_encode($reaction_guid['context_id']) |
|
366 | 366 | , $reaction_guid['id'] |
367 | 367 | , $this->action_type |
368 | 368 | ) |
369 | 369 | ); |
370 | 370 | |
371 | - if ( ! $period ) { |
|
371 | + if ( ! $period) { |
|
372 | 372 | return false; |
373 | 373 | } |
374 | 374 | |
375 | - wp_cache_set( $cache_key, $period->id, 'wordpoints_hook_period_ids_by_reaction' ); |
|
376 | - wp_cache_set( $period->id, $period, 'wordpoints_hook_periods' ); |
|
375 | + wp_cache_set($cache_key, $period->id, 'wordpoints_hook_period_ids_by_reaction'); |
|
376 | + wp_cache_set($period->id, $period, 'wordpoints_hook_periods'); |
|
377 | 377 | |
378 | 378 | return $period; |
379 | 379 | } |
@@ -381,21 +381,21 @@ discard block |
||
381 | 381 | /** |
382 | 382 | * @since 1.0.0 |
383 | 383 | */ |
384 | - public function after_hit( WordPoints_Hook_Fire $fire ) { |
|
384 | + public function after_hit(WordPoints_Hook_Fire $fire) { |
|
385 | 385 | |
386 | - $periods = $this->get_settings_from_fire( $fire ); |
|
386 | + $periods = $this->get_settings_from_fire($fire); |
|
387 | 387 | |
388 | - if ( empty( $periods ) ) { |
|
388 | + if (empty($periods)) { |
|
389 | 389 | return; |
390 | 390 | } |
391 | 391 | |
392 | 392 | $this->event_args = $fire->event_args; |
393 | 393 | $this->action_type = $fire->action_type; |
394 | 394 | |
395 | - foreach ( $periods as $settings ) { |
|
395 | + foreach ($periods as $settings) { |
|
396 | 396 | |
397 | 397 | $this->add_period( |
398 | - $this->get_period_signature( $settings, $fire->reaction ) |
|
398 | + $this->get_period_signature($settings, $fire->reaction) |
|
399 | 399 | , $fire |
400 | 400 | ); |
401 | 401 | } |
@@ -420,14 +420,14 @@ discard block |
||
420 | 420 | WordPoints_Hook_ReactionI $reaction |
421 | 421 | ) { |
422 | 422 | |
423 | - if ( isset( $settings['args'] ) ) { |
|
423 | + if (isset($settings['args'])) { |
|
424 | 424 | $period_args = $settings['args']; |
425 | 425 | } else { |
426 | - $period_args = array( $reaction->get_meta( 'target' ) ); |
|
426 | + $period_args = array($reaction->get_meta('target')); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | return wordpoints_hash( |
430 | - wp_json_encode( $this->get_arg_values( $period_args ) ) |
|
430 | + wp_json_encode($this->get_arg_values($period_args)) |
|
431 | 431 | ); |
432 | 432 | } |
433 | 433 | |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | * |
442 | 442 | * @return false|object The period data, or false if not found. |
443 | 443 | */ |
444 | - protected function add_period( $signature, WordPoints_Hook_Fire $fire ) { |
|
444 | + protected function add_period($signature, WordPoints_Hook_Fire $fire) { |
|
445 | 445 | |
446 | 446 | global $wpdb; |
447 | 447 | |
@@ -451,17 +451,17 @@ discard block |
||
451 | 451 | 'hit_id' => $fire->hit_id, |
452 | 452 | 'signature' => $signature, |
453 | 453 | ) |
454 | - , array( '%d', '%s' ) |
|
454 | + , array('%d', '%s') |
|
455 | 455 | ); |
456 | 456 | |
457 | - if ( ! $inserted ) { |
|
457 | + if ( ! $inserted) { |
|
458 | 458 | return false; |
459 | 459 | } |
460 | 460 | |
461 | 461 | $period_id = $wpdb->insert_id; |
462 | 462 | |
463 | 463 | wp_cache_set( |
464 | - wp_json_encode( $fire->reaction->get_guid() ) . "-{$signature}-{$this->action_type}" |
|
464 | + wp_json_encode($fire->reaction->get_guid())."-{$signature}-{$this->action_type}" |
|
465 | 465 | , $period_id |
466 | 466 | , 'wordpoints_hook_period_ids_by_reaction' |
467 | 467 | ); |
@@ -143,21 +143,21 @@ discard block |
||
143 | 143 | ) { |
144 | 144 | |
145 | 145 | if ( |
146 | - empty( $settings['target'] ) |
|
147 | - || ! is_array( $settings['target'] ) |
|
146 | + empty($settings['target']) |
|
147 | + || ! is_array($settings['target']) |
|
148 | 148 | ) { |
149 | 149 | |
150 | - $validator->add_error( __( 'Invalid target.', 'wordpoints' ), 'target' ); |
|
150 | + $validator->add_error(__('Invalid target.', 'wordpoints'), 'target'); |
|
151 | 151 | |
152 | 152 | } else { |
153 | 153 | |
154 | - $target = $event_args->get_from_hierarchy( $settings['target'] ); |
|
154 | + $target = $event_args->get_from_hierarchy($settings['target']); |
|
155 | 155 | |
156 | 156 | if ( |
157 | 157 | ! $target instanceof WordPoints_Entity |
158 | - || ! in_array( $target->get_slug(), (array) $this->arg_types ) |
|
158 | + || ! in_array($target->get_slug(), (array) $this->arg_types) |
|
159 | 159 | ) { |
160 | - $validator->add_error( __( 'Invalid target.', 'wordpoints' ), 'target' ); |
|
160 | + $validator->add_error(__('Invalid target.', 'wordpoints'), 'target'); |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | |
@@ -167,8 +167,8 @@ discard block |
||
167 | 167 | /** |
168 | 168 | * @since 1.0.0 |
169 | 169 | */ |
170 | - public function update_settings( WordPoints_Hook_ReactionI $reaction, array $settings ) { |
|
171 | - $reaction->update_meta( 'target', $settings['target'] ); |
|
170 | + public function update_settings(WordPoints_Hook_ReactionI $reaction, array $settings) { |
|
171 | + $reaction->update_meta('target', $settings['target']); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * |
179 | 179 | * @param WordPoints_Hook_Fire $fire The hook fire object. |
180 | 180 | */ |
181 | - abstract public function hit( WordPoints_Hook_Fire $fire ); |
|
181 | + abstract public function hit(WordPoints_Hook_Fire $fire); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | // EOF |
@@ -58,8 +58,20 @@ discard block |
||
58 | 58 | |
59 | 59 | // this is basically a reactor |
60 | 60 | interface WordPoints_Entity_Change_ListenerI { |
61 | + |
|
62 | + /** |
|
63 | + * @return void |
|
64 | + */ |
|
61 | 65 | public function created( WordPoints_Entity $entity ); |
66 | + |
|
67 | + /** |
|
68 | + * @return void |
|
69 | + */ |
|
62 | 70 | public function updated( WordPoints_Entity $before, WordPoints_Entity $after ); |
71 | + |
|
72 | + /** |
|
73 | + * @return void |
|
74 | + */ |
|
63 | 75 | public function deleted( WordPoints_Entity $entity ); |
64 | 76 | } |
65 | 77 | |
@@ -129,6 +141,9 @@ discard block |
||
129 | 141 | return true; |
130 | 142 | } |
131 | 143 | |
144 | + /** |
|
145 | + * @param string $type |
|
146 | + */ |
|
132 | 147 | protected function fire_event( $type, WordPoints_Entity $entity ) { |
133 | 148 | |
134 | 149 | $args = new WordPoints_Hook_Event_Args( array() ); |
@@ -10,19 +10,19 @@ discard block |
||
10 | 10 | // this is basicaly a router. |
11 | 11 | class WordPoints_Entity_chang_trigger implements WordPoints_Entity_Change_ListenerI { |
12 | 12 | |
13 | - public function created( WordPoints_Entity $entity ) { |
|
13 | + public function created(WordPoints_Entity $entity) { |
|
14 | 14 | // can multiple entities be created at once? not using insert() but via query() |
15 | 15 | // maybe? and how shoudl we handle that, all at once or one by one? |
16 | 16 | |
17 | 17 | /** @var WordPoints_Entity_Change_ListenerI[] $listeners */ |
18 | - $listeners = wordpoints_apps()->sub_apps->get( 'entity_change_listeners' ); |
|
19 | - foreach ( $listeners as $listener ) { |
|
20 | - $listener->created( $entity ); |
|
18 | + $listeners = wordpoints_apps()->sub_apps->get('entity_change_listeners'); |
|
19 | + foreach ($listeners as $listener) { |
|
20 | + $listener->created($entity); |
|
21 | 21 | } |
22 | 22 | } |
23 | 23 | |
24 | 24 | |
25 | - public function updated( WordPoints_Entity $before, WordPoints_Entity $after ) { |
|
25 | + public function updated(WordPoints_Entity $before, WordPoints_Entity $after) { |
|
26 | 26 | |
27 | 27 | // what if multiple entities are updated at once? do we run each one separatately? |
28 | 28 | // mayb ethat should be left up to the listenter. |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | } |
31 | 31 | |
32 | 32 | |
33 | - public function deleted( WordPoints_Entity $entity ) { |
|
33 | + public function deleted(WordPoints_Entity $entity) { |
|
34 | 34 | |
35 | 35 | // what if we need information about this entitie's relationships, etc., that |
36 | 36 | // isn't included inthe entity object? |
@@ -58,41 +58,41 @@ discard block |
||
58 | 58 | |
59 | 59 | // this is basically a reactor |
60 | 60 | interface WordPoints_Entity_Change_ListenerI { |
61 | - public function created( WordPoints_Entity $entity ); |
|
62 | - public function updated( WordPoints_Entity $before, WordPoints_Entity $after ); |
|
63 | - public function deleted( WordPoints_Entity $entity ); |
|
61 | + public function created(WordPoints_Entity $entity); |
|
62 | + public function updated(WordPoints_Entity $before, WordPoints_Entity $after); |
|
63 | + public function deleted(WordPoints_Entity $entity); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | class WordPoints_Entity_Change_Listener_Hooks implements WordPoints_Entity_Change_ListenerI { |
67 | 67 | |
68 | - public function created( WordPoints_Entity $entity ) { |
|
68 | + public function created(WordPoints_Entity $entity) { |
|
69 | 69 | |
70 | 70 | // maybe we would have multuiple events with requirements for a single entity? |
71 | 71 | // like comment author and post commentn author targets for the same hook. |
72 | 72 | // but I guess taht is just one event. |
73 | 73 | // what about user register vs user create on MS? |
74 | - if ( $this->matches_requirements( $entity ) ) { |
|
75 | - $this->fire_event( 'add', $entity ); |
|
74 | + if ($this->matches_requirements($entity)) { |
|
75 | + $this->fire_event('add', $entity); |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 | |
79 | - public function updated( WordPoints_Entity $before, WordPoints_Entity $after ) { |
|
79 | + public function updated(WordPoints_Entity $before, WordPoints_Entity $after) { |
|
80 | 80 | |
81 | - if ( $this->matches_requirements( $after ) ) { |
|
82 | - if ( ! $this->matches_requirements( $before ) ) { |
|
83 | - $this->fire_event( 'add', $after ); |
|
81 | + if ($this->matches_requirements($after)) { |
|
82 | + if ( ! $this->matches_requirements($before)) { |
|
83 | + $this->fire_event('add', $after); |
|
84 | 84 | } |
85 | 85 | } else { |
86 | - if ( $this->matches_requirements( $before ) ) { |
|
87 | - $this->fire_event( 'remove', $after ); |
|
86 | + if ($this->matches_requirements($before)) { |
|
87 | + $this->fire_event('remove', $after); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
92 | - public function deleted( WordPoints_Entity $entity ) { |
|
92 | + public function deleted(WordPoints_Entity $entity) { |
|
93 | 93 | |
94 | - if ( $this->matches_requirements( $entity ) ) { |
|
95 | - $this->fire_event( 'remove', $entity ); |
|
94 | + if ($this->matches_requirements($entity)) { |
|
95 | + $this->fire_event('remove', $entity); |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
@@ -108,20 +108,20 @@ discard block |
||
108 | 108 | // called into play when the entity itself is deleted is moot, because the |
109 | 109 | // reltionships, etc., aren't even taken into account when toggle-off is called, |
110 | 110 | // in the points reactor. other reators might, i guess. |
111 | - protected function matches_requirements( WordPoints_Entity $entity ) { |
|
111 | + protected function matches_requirements(WordPoints_Entity $entity) { |
|
112 | 112 | |
113 | 113 | /** @var WordPoints_Class_Registry $defaults */ |
114 | - $defaults = wordpoints_apps()->sub_apps->get( 'entity_possession_defaults' ); |
|
114 | + $defaults = wordpoints_apps()->sub_apps->get('entity_possession_defaults'); |
|
115 | 115 | |
116 | - $defaults = $defaults->get( $entity->get_slug() ); |
|
116 | + $defaults = $defaults->get($entity->get_slug()); |
|
117 | 117 | |
118 | - if ( ! $defaults ) { |
|
118 | + if ( ! $defaults) { |
|
119 | 119 | return false; |
120 | 120 | } |
121 | 121 | |
122 | 122 | // use conditions here? |
123 | - foreach ( $defaults as $child => $value ) { |
|
124 | - if ( $entity->get_child( $child ) !== $value ) { |
|
123 | + foreach ($defaults as $child => $value) { |
|
124 | + if ($entity->get_child($child) !== $value) { |
|
125 | 125 | return false; |
126 | 126 | } |
127 | 127 | } |
@@ -129,13 +129,13 @@ discard block |
||
129 | 129 | return true; |
130 | 130 | } |
131 | 131 | |
132 | - protected function fire_event( $type, WordPoints_Entity $entity ) { |
|
132 | + protected function fire_event($type, WordPoints_Entity $entity) { |
|
133 | 133 | |
134 | - $args = new WordPoints_Hook_Event_Args( array() ); |
|
135 | - $args->add_entity( $entity ); |
|
134 | + $args = new WordPoints_Hook_Event_Args(array()); |
|
135 | + $args->add_entity($entity); |
|
136 | 136 | |
137 | 137 | wordpoints_hooks()->fire( |
138 | - $type . '_entity_' . $entity->get_slug(), |
|
138 | + $type.'_entity_'.$entity->get_slug(), |
|
139 | 139 | $args, |
140 | 140 | 'toggle_on' |
141 | 141 | ); |
@@ -144,31 +144,31 @@ discard block |
||
144 | 144 | |
145 | 145 | class WordPoints_Entity_Change_Listener_Points implements WordPoints_Entity_Change_ListenerI { |
146 | 146 | |
147 | - public function created( WordPoints_Entity $entity ) { |
|
147 | + public function created(WordPoints_Entity $entity) { |
|
148 | 148 | |
149 | 149 | $this->process_entityish( |
150 | 150 | $entity |
151 | - , $this->get_settings_for_entity( $entity ) |
|
151 | + , $this->get_settings_for_entity($entity) |
|
152 | 152 | ); |
153 | 153 | } |
154 | 154 | |
155 | - protected function process_entityish( WordPoints_EntityishI $entity, $settings ) { |
|
155 | + protected function process_entityish(WordPoints_EntityishI $entity, $settings) { |
|
156 | 156 | |
157 | 157 | // possibly make this more like extension handling |
158 | - if ( ! $this->meets_conditions( $entity, $settings['conditions'] ) ) { |
|
158 | + if ( ! $this->meets_conditions($entity, $settings['conditions'])) { |
|
159 | 159 | return; |
160 | 160 | } |
161 | 161 | |
162 | 162 | // possibly make this more like reactor handling. |
163 | - $this->award_points( $settings ); |
|
163 | + $this->award_points($settings); |
|
164 | 164 | |
165 | 165 | // only proces the attributes taht have changed. |
166 | 166 | // acutally, in this case, the entity was just created. |
167 | - if ( $entity instanceof WordPoints_Entity_ParentI ) { |
|
167 | + if ($entity instanceof WordPoints_Entity_ParentI) { |
|
168 | 168 | |
169 | 169 | // this check runs on attributes only. |
170 | - foreach ( $settings['children'] as $child_slug => $child_settings ) { |
|
171 | - $this->process_entityish( $entity->get_child( $child_slug ), $child_settings ); |
|
170 | + foreach ($settings['children'] as $child_slug => $child_settings) { |
|
171 | + $this->process_entityish($entity->get_child($child_slug), $child_settings); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | // we also need to check for any children, like relationships, that have |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | // for this we need a list of relationships. |
177 | 177 | // if we do two-way relationships, we may need to have infinite-loop |
178 | 178 | // halding here, depending. |
179 | - foreach ( $this->get_related_entities( $entity ) as $child_entity ) { |
|
179 | + foreach ($this->get_related_entities($entity) as $child_entity) { |
|
180 | 180 | // If a comment was just created, for example, and we have conditions |
181 | 181 | // on the post entity, that affect the comment author, this allows |
182 | 182 | // us to handle those by pulling up the settings for the post entity |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | // as we've proposed... |
196 | 196 | $this->process_entityish( |
197 | 197 | $child_entity |
198 | - , $this->get_entity_settings( $child_entity ) |
|
198 | + , $this->get_entity_settings($child_entity) |
|
199 | 199 | ); |
200 | 200 | } |
201 | 201 | } |
@@ -209,15 +209,15 @@ discard block |
||
209 | 209 | // doesn't really make sense. |
210 | 210 | // I think relationships can be created and deleted, but not really updated. |
211 | 211 | // so maybe what we need is a separate api? |
212 | - public function updated( WordPoints_Entity $before, WordPoints_Entity $after ) { |
|
212 | + public function updated(WordPoints_Entity $before, WordPoints_Entity $after) { |
|
213 | 213 | |
214 | - $settings = $this->get_settings_for_entity( $before ); |
|
214 | + $settings = $this->get_settings_for_entity($before); |
|
215 | 215 | |
216 | 216 | /** @var WordPoints_Class_Registry_ChildrenI $children */ |
217 | 217 | $children = wordpoints_entities()->children; |
218 | - foreach ( $children->get_children_slugs( $before->get_slug() ) as $child_slug ) { |
|
218 | + foreach ($children->get_children_slugs($before->get_slug()) as $child_slug) { |
|
219 | 219 | |
220 | - if ( ! isset( $settings['children'][ $child_slug ] ) ) { |
|
220 | + if ( ! isset($settings['children'][$child_slug])) { |
|
221 | 221 | continue; |
222 | 222 | } |
223 | 223 | |
@@ -232,23 +232,23 @@ discard block |
||
232 | 232 | // but then we'll not be checking even the relationships taht are defined |
233 | 233 | // on the atts. so we have to decide whether those should be handled by |
234 | 234 | // a separate api or not. |
235 | - if ( $before->get_the_attr_value( $child_slug ) === $after->get_the_attr_value( $child_slug ) ) { |
|
235 | + if ($before->get_the_attr_value($child_slug) === $after->get_the_attr_value($child_slug)) { |
|
236 | 236 | continue; |
237 | 237 | } |
238 | 238 | |
239 | 239 | $this->process_modified_entityish( |
240 | - $before->get_child( $child_slug ) |
|
241 | - , $after->get_child( $child_slug ) |
|
242 | - , $settings['children'][ $child_slug ] |
|
240 | + $before->get_child($child_slug) |
|
241 | + , $after->get_child($child_slug) |
|
242 | + , $settings['children'][$child_slug] |
|
243 | 243 | ); |
244 | 244 | } |
245 | 245 | } |
246 | 246 | |
247 | - protected function process_modified_entityish( WordPoints_EntityishI $before, WordPoints_EntityishI $after, $settings ) { |
|
247 | + protected function process_modified_entityish(WordPoints_EntityishI $before, WordPoints_EntityishI $after, $settings) { |
|
248 | 248 | |
249 | - if ( ! $this->meets_conditions( $before, $settings['conditions'] ) ) { |
|
250 | - if ( $this->meets_conditions( $after, $settings['conditions'] ) ) { |
|
251 | - $this->award_points( $settings ); |
|
249 | + if ( ! $this->meets_conditions($before, $settings['conditions'])) { |
|
250 | + if ($this->meets_conditions($after, $settings['conditions'])) { |
|
251 | + $this->award_points($settings); |
|
252 | 252 | |
253 | 253 | // also need to process other eneities that are affected by this |
254 | 254 | // change, which may have conditions on this, i.e., that could be |
@@ -265,38 +265,38 @@ discard block |
||
265 | 265 | // then we do indeed need to run through the children/parents. |
266 | 266 | } |
267 | 267 | } else { |
268 | - if ( ! $this->meets_conditions( $after, $settings['conditions'] ) ) { |
|
269 | - $this->remove_points( $settings ); |
|
268 | + if ( ! $this->meets_conditions($after, $settings['conditions'])) { |
|
269 | + $this->remove_points($settings); |
|
270 | 270 | } |
271 | 271 | } |
272 | 272 | } |
273 | 273 | |
274 | - public function deleted( WordPoints_Entity $entity ) { |
|
274 | + public function deleted(WordPoints_Entity $entity) { |
|
275 | 275 | // basically the opposite of created(). |
276 | - $this->process_entityish_reverse( $entity ); |
|
276 | + $this->process_entityish_reverse($entity); |
|
277 | 277 | } |
278 | 278 | |
279 | - protected function meets_conditions( WordPoints_EntityishI $entityish, $conditions ) { |
|
279 | + protected function meets_conditions(WordPoints_EntityishI $entityish, $conditions) { |
|
280 | 280 | // use conditions api |
281 | 281 | |
282 | 282 | return false; |
283 | 283 | } |
284 | 284 | |
285 | - private function award_points( $settings ) { |
|
285 | + private function award_points($settings) { |
|
286 | 286 | |
287 | - $hierarchy = new WordPoints_Entity_Hierarchy( $this->eitnty ); |
|
287 | + $hierarchy = new WordPoints_Entity_Hierarchy($this->eitnty); |
|
288 | 288 | // todo we'll need to introudce entity array targets, possibly. |
289 | 289 | // how will we know how to reverse the target reltinoship chains in the UI |
290 | 290 | // before saving? i guess we'll need to either have a dedicated index fo taht |
291 | 291 | // or else juust look it up by looping through the relationships (though we'd |
292 | 292 | // have to remove the entity array {} part from any one-to-many relationships |
293 | 293 | // and maybe we'd have to add it to others?) |
294 | - $targets = $hierarchy->get_from_hierarchy( $settings['target'] ); |
|
294 | + $targets = $hierarchy->get_from_hierarchy($settings['target']); |
|
295 | 295 | |
296 | 296 | // maybe just one target, maybe several, depending. |
297 | 297 | } |
298 | 298 | |
299 | - private function get_related_entities( WordPoints_Entity $entity ) { |
|
299 | + private function get_related_entities(WordPoints_Entity $entity) { |
|
300 | 300 | |
301 | 301 | // what we need is parental conditions. Conditions that go up the chain, |
302 | 302 | // and look back at parent entities. This way we can handle the info about |