| 1 |
<?php |
| 2 |
|
| 3 |
namespace Hurrytimer\Placeholders; |
| 4 |
|
| 5 |
use Hurrytimer\C; |
| 6 |
use Hurrytimer\Dependencies\Carbon\Carbon; |
| 7 |
|
| 8 |
|
| 9 |
class Time_Placeholder extends Placeholder |
| 10 |
{ |
| 11 |
|
| 12 |
/** |
| 13 |
* @var \Hurrytimer\Campaign |
| 14 |
*/ |
| 15 |
protected $campaign; |
| 16 |
|
| 17 |
public function __construct( $campaign ) |
| 18 |
{ |
| 19 |
$this->campaign = $campaign; |
| 20 |
} |
| 21 |
|
| 22 |
public function get_format() |
| 23 |
{ |
| 24 |
return apply_filters( 'hurryt_time_format', get_option( 'time_format' ) ); |
| 25 |
} |
| 26 |
|
| 27 |
public function get_value( $options = []) |
| 28 |
{ |
| 29 |
switch ( $this->campaign->mode ) { |
| 30 |
case C::MODE_REGULAR: |
| 31 |
return Carbon::parse( $this->campaign->getEndDatetime() )->format( $this->get_format() ); |
| 32 |
case C::MODE_RECURRING: |
| 33 |
return $this->campaign->getRecurrenceEndDate()->format( $this->get_format() ); |
| 34 |
default: |
| 35 |
return '{{time}}'; |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
} |