woocommerce
/
packages
/
woocommerce-admin
/
src
/
RemoteInboxNotifications
/
PublishBeforeTimeRuleProcessor.php
BaseLocationCountryRuleProcessor.php
5 years ago
BaseLocationStateRuleProcessor.php
5 years ago
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
NoteStatusRuleProcessor.php
5 years ago
OnboardingProfileRuleProcessor.php
5 years ago
OptionRuleProcessor.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
PublishBeforeTimeRuleProcessor.php
54 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Rule processor for sending before a specified date/time. |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Admin\RemoteInboxNotifications; |
| 7 | |
| 8 | defined( 'ABSPATH' ) || exit; |
| 9 | |
| 10 | use \Automattic\WooCommerce\Admin\DateTimeProvider\CurrentDateTimeProvider; |
| 11 | |
| 12 | /** |
| 13 | * Rule processor for sending before a specified date/time. |
| 14 | */ |
| 15 | class PublishBeforeTimeRuleProcessor implements RuleProcessorInterface { |
| 16 | /** |
| 17 | * Constructor. |
| 18 | * |
| 19 | * @param DateTimeProviderInterface $date_time_provider The DateTime provider. |
| 20 | */ |
| 21 | public function __construct( $date_time_provider = null ) { |
| 22 | $this->date_time_provider = null === $date_time_provider |
| 23 | ? new CurrentDateTimeProvider() |
| 24 | : $date_time_provider; |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Process the rule. |
| 29 | * |
| 30 | * @param object $rule The specific rule being processed by this rule processor. |
| 31 | * @param object $stored_state Stored state. |
| 32 | * |
| 33 | * @return bool Whether the rule passes or not. |
| 34 | */ |
| 35 | public function process( $rule, $stored_state ) { |
| 36 | return $this->date_time_provider->get_now() <= new \DateTime( $rule->publish_before ); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Validates the rule. |
| 41 | * |
| 42 | * @param object $rule The rule to validate. |
| 43 | * |
| 44 | * @return bool Pass/fail. |
| 45 | */ |
| 46 | public function validate( $rule ) { |
| 47 | if ( ! isset( $rule->publish_before ) ) { |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | return true; |
| 52 | } |
| 53 | } |
| 54 |