BFCM2025.php
96 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Promotions\BFCM; |
| 4 | |
| 5 | use DateTimeImmutable; |
| 6 | use Give\Framework\Views\View; |
| 7 | use Give\Vendors\StellarWP\AdminNotices\AdminNotice; |
| 8 | use Give\Vendors\StellarWP\AdminNotices\AdminNotices; |
| 9 | use Give\Vendors\StellarWP\AdminNotices\DataTransferObjects\NoticeElementProperties; |
| 10 | |
| 11 | /** |
| 12 | * @since 4.11.0 |
| 13 | */ |
| 14 | class BFCM2025 |
| 15 | { |
| 16 | /** |
| 17 | * @var string |
| 18 | */ |
| 19 | public $id = 'givewp-bfcm-2025'; |
| 20 | |
| 21 | /** |
| 22 | * @var string |
| 23 | */ |
| 24 | private const START_DATE = '2025-11-24 00:00:00'; |
| 25 | |
| 26 | /** |
| 27 | * @var string |
| 28 | */ |
| 29 | private const END_DATE = '2025-12-02 23:59:59'; |
| 30 | |
| 31 | /** |
| 32 | * @since 4.11.0 |
| 33 | */ |
| 34 | public function __invoke() |
| 35 | { |
| 36 | $this->render(); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * @since 4.11.0 |
| 41 | */ |
| 42 | public function render() |
| 43 | { |
| 44 | [$start, $end] = $this->getDateRange(); |
| 45 | |
| 46 | AdminNotices::show($this->id, [$this, 'renderCallback']) |
| 47 | ->custom() |
| 48 | ->location('inline') |
| 49 | ->enqueueStylesheet(GIVE_PLUGIN_URL . 'build/bfcm2025.css', [], '1.0.0') |
| 50 | ->enqueueScript(GIVE_PLUGIN_URL . 'build/bfcm2025.js', [], '1.0.0') |
| 51 | ->between($start, $end) |
| 52 | ->on('give-campaigns') |
| 53 | ->on('give-donors') |
| 54 | ->on('give-payment-history') |
| 55 | ->on('give-settings') |
| 56 | ->on('give-add-ons') |
| 57 | ->on('give-reports'); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @since 4.11.0 |
| 62 | */ |
| 63 | private function getDateRange(): array |
| 64 | { |
| 65 | $timezone = wp_timezone(); |
| 66 | |
| 67 | return [ |
| 68 | new DateTimeImmutable(self::START_DATE, $timezone), |
| 69 | new DateTimeImmutable(self::END_DATE, $timezone), |
| 70 | ]; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * @since 4.11.0 |
| 75 | */ |
| 76 | public function renderCallback(AdminNotice $notice, NoticeElementProperties $elements): string |
| 77 | { |
| 78 | $backgroundLarge = GIVE_PLUGIN_URL . 'build/assets/dist/images/admin/promotions/bfcm-banner/2025/bfcm-background-lg.svg'; |
| 79 | $backgroundMedium = GIVE_PLUGIN_URL . 'build/assets/dist/images/admin/promotions/bfcm-banner/2025/bfcm-background-md.svg'; |
| 80 | $backgroundSmall = GIVE_PLUGIN_URL . 'build/assets/dist/images/admin/promotions/bfcm-banner/2025/bfcm-background-sm.svg'; |
| 81 | $cartIcon = GIVE_PLUGIN_URL . 'build/assets/dist/images/admin/promotions/bfcm-banner/2025/bfcm-cart-icon.svg'; |
| 82 | |
| 83 | return View::load( |
| 84 | 'Promotions.BFCM2025', |
| 85 | [ |
| 86 | 'elements' => $elements, |
| 87 | 'backgroundLarge' => $backgroundLarge, |
| 88 | 'backgroundMedium' => $backgroundMedium, |
| 89 | 'backgroundSmall' => $backgroundSmall, |
| 90 | 'cartIcon' => $cartIcon, |
| 91 | ], |
| 92 | false |
| 93 | ); |
| 94 | } |
| 95 | } |
| 96 |