Help
8 years ago
Page
8 years ago
Promo
8 years ago
Help.php
8 years ago
Page.php
8 years ago
Pages.php
8 years ago
Promo.php
8 years ago
Promo.php
143 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | abstract class AC_Admin_Promo { |
| 8 | |
| 9 | /** |
| 10 | * @var array |
| 11 | */ |
| 12 | private $date_ranges; |
| 13 | |
| 14 | /** |
| 15 | * @var string |
| 16 | */ |
| 17 | private $title; |
| 18 | |
| 19 | /** |
| 20 | * @var int |
| 21 | */ |
| 22 | private $discount; |
| 23 | |
| 24 | /** |
| 25 | * @var string |
| 26 | */ |
| 27 | private $url; |
| 28 | |
| 29 | /** |
| 30 | * @return string |
| 31 | */ |
| 32 | public function get_title() { |
| 33 | return $this->title; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @param string $title |
| 38 | */ |
| 39 | public function set_title( $title ) { |
| 40 | $this->title = $title; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @return int |
| 45 | */ |
| 46 | public function get_discount() { |
| 47 | return $this->discount; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * @param int $discount |
| 52 | */ |
| 53 | public function set_discount( $discount ) { |
| 54 | $this->discount = $discount; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * @return int |
| 59 | */ |
| 60 | public function get_url() { |
| 61 | if ( null === $this->url ) { |
| 62 | |
| 63 | $campaign = str_replace( get_parent_class( $this ) . '_', '', get_class( $this ) ); |
| 64 | |
| 65 | $this->set_url( ac_get_site_utm_url( 'pricing-purchase', 'promo', null, $campaign ) ); |
| 66 | } |
| 67 | |
| 68 | return $this->url; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * @param int $url |
| 73 | */ |
| 74 | public function set_url( $url ) { |
| 75 | $this->url = $url; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * @param string $start_date |
| 80 | * @param string $end_date |
| 81 | */ |
| 82 | public function add_date_range( $start_date, $end_date ) { |
| 83 | if ( ! $start_date || ! $end_date ) { |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | $this->date_ranges[] = array( |
| 88 | 'start' => $start_date, |
| 89 | 'end' => $end_date, |
| 90 | ); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @return bool True when promo is active |
| 95 | */ |
| 96 | public function is_active() { |
| 97 | return $this->get_active_date_range() ? true : false; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Active date range |
| 102 | * |
| 103 | * @return array|false |
| 104 | */ |
| 105 | private function get_active_date_range() { |
| 106 | $today = date( 'Y-m-d' ); |
| 107 | |
| 108 | foreach ( $this->date_ranges as $date_range ) { |
| 109 | if ( $today >= $date_range['start'] && $today <= $date_range['end'] ) { |
| 110 | return $date_range; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | return false; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * @return bool|string |
| 119 | */ |
| 120 | public function end_date() { |
| 121 | $date_range = $this->get_active_date_range(); |
| 122 | |
| 123 | return $date_range ? date_i18n( get_option( 'date_format' ), strtotime( $date_range['end'] ) ) : false; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Render HTML |
| 128 | */ |
| 129 | public function display() { ?> |
| 130 | <h3> |
| 131 | <?php echo esc_html( $this->get_title() ); ?> |
| 132 | </h3> |
| 133 | <a target="_blank" href="<?php echo esc_url( $this->get_url() ); ?>" class="acp-button"> |
| 134 | <?php echo esc_html( sprintf( __( 'Get %s Off', 'codepress-admin-columns' ), $this->get_discount() . '%' ) ); ?> |
| 135 | </a> |
| 136 | <p class="nomargin"> |
| 137 | <?php echo esc_html( sprintf( __( "Discount is valid until %s", 'codepress-admin-columns' ), $this->end_date() ) ); ?> |
| 138 | </p> |
| 139 | <?php |
| 140 | } |
| 141 | |
| 142 | } |
| 143 |