PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.9
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.9
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / promotions / application / promotion-manager.php

promotion-manager.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.9, at src/promotions/application/promotion-manager.php

75 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Promotions\Application;
4
5 use Yoast\WP\SEO\Promotions\Domain\Promotion_Interface;
6
7 /**
8 * Class to manage promotional promotions.
9 *
10 * @makePublic
11 */
12 class Promotion_Manager implements Promotion_Manager_Interface {
13
14 /**
15 * The centralized list of promotions: all promotions should be passed to the constructor.
16 *
17 * @var array<Abstract_Promotion>
18 */
19 private $promotions_list = [];
20
21 /**
22 * Class constructor.
23 *
24 * @param Promotion_Interface ...$promotions List of promotions.
25 */
26 public function __construct( Promotion_Interface ...$promotions ) {
27 $this->promotions_list = $promotions;
28 }
29
30 /**
31 * Whether the promotion is effective.
32 *
33 * @param string $promotion_name The name of the promotion.
34 *
35 * @return bool Whether the promotion is effective.
36 */
37 public function is( string $promotion_name ): bool {
38 $time = \time();
39
40 foreach ( $this->promotions_list as $promotion ) {
41 if ( $promotion->get_promotion_name() === $promotion_name ) {
42 return $promotion->get_time_interval()->contains( $time );
43 }
44 }
45
46 return false;
47 }
48
49 /**
50 * Get the list of promotions.
51 *
52 * @return array<Abstract_Promotion> The list of promotions.
53 */
54 public function get_promotions_list(): array {
55 return $this->promotions_list;
56 }
57
58 /**
59 * Get the names of currently active promotions.
60 *
61 * @return array<string> The list of promotions.
62 */
63 public function get_current_promotions(): array {
64 $current_promotions = [];
65 $time = \time();
66 foreach ( $this->promotions_list as $promotion ) {
67 if ( $promotion->get_time_interval()->contains( $time ) ) {
68 $current_promotions[] = $promotion->get_promotion_name();
69 }
70 }
71
72 return $current_promotions;
73 }
74 }
75