woocommerce
/
packages
/
woocommerce-admin
/
src
/
RemoteInboxNotifications
/
OnboardingProfileRuleProcessor.php
ComparisonOperation.php
5 years ago
DataSourcePoller.php
5 years ago
EvaluateAndGetStatus.php
5 years ago
FailRuleProcessor.php
5 years ago
GetRuleProcessor.php
5 years ago
IsEcommerceRuleProcessor.php
5 years ago
NotRuleProcessor.php
5 years ago
OnboardingProfileRuleProcessor.php
5 years ago
OrRuleProcessor.php
5 years ago
OrderCountRuleProcessor.php
5 years ago
OrdersProvider.php
5 years ago
PassRuleProcessor.php
5 years ago
PluginVersionRuleProcessor.php
5 years ago
PluginsActivatedRuleProcessor.php
5 years ago
ProductCountRuleProcessor.php
5 years ago
PublishAfterTimeRuleProcessor.php
5 years ago
PublishBeforeTimeRuleProcessor.php
5 years ago
RemoteInboxNotificationsEngine.php
5 years ago
RuleEvaluator.php
5 years ago
RuleProcessorInterface.php
5 years ago
SpecRunner.php
5 years ago
StoredStateRuleProcessor.php
5 years ago
StoredStateSetupForProducts.php
5 years ago
WCAdminActiveForProvider.php
5 years ago
WCAdminActiveForRuleProcessor.php
5 years ago
OnboardingProfileRuleProcessor.php
66 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Rule processor that performs a comparison operation against a value in the |
| 4 | * onboarding profile. |
| 5 | */ |
| 6 | |
| 7 | namespace Automattic\WooCommerce\Admin\RemoteInboxNotifications; |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | /** |
| 12 | * Rule processor that performs a comparison operation against a value in the |
| 13 | * onboarding profile. |
| 14 | */ |
| 15 | class OnboardingProfileRuleProcessor implements RuleProcessorInterface { |
| 16 | /** |
| 17 | * Performs a comparison operation against a value in the onboarding |
| 18 | * profile. |
| 19 | * |
| 20 | * @param object $rule The rule being processed by this rule processor. |
| 21 | * @param object $stored_state Stored state. |
| 22 | * |
| 23 | * @return bool The result of the operation. |
| 24 | */ |
| 25 | public function process( $rule, $stored_state ) { |
| 26 | $onboarding_profile = get_option( 'woocommerce_onboarding_profile' ); |
| 27 | |
| 28 | if ( empty( $onboarding_profile ) ) { |
| 29 | return false; |
| 30 | } |
| 31 | |
| 32 | if ( ! isset( $onboarding_profile[ $rule->index ] ) ) { |
| 33 | return false; |
| 34 | } |
| 35 | |
| 36 | return ComparisonOperation::compare( |
| 37 | $onboarding_profile[ $rule->index ], |
| 38 | $rule->value, |
| 39 | $rule->operation |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Validates the rule. |
| 45 | * |
| 46 | * @param object $rule The rule to validate. |
| 47 | * |
| 48 | * @return bool Pass/fail. |
| 49 | */ |
| 50 | public function validate( $rule ) { |
| 51 | if ( ! isset( $rule->index ) ) { |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | if ( ! isset( $rule->value ) ) { |
| 56 | return false; |
| 57 | } |
| 58 | |
| 59 | if ( ! isset( $rule->operation ) ) { |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | return true; |
| 64 | } |
| 65 | } |
| 66 |