PluginProbe
WANotifier for Forms and Actions / 2.7.5
WANotifier for Forms and Actions v2.7.5
3.1.1 3.1.0 3.0.4 2.7.10 2.7.11 2.7.12 2.7.13 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 3.0.0 3.0.1 3.0.2 3.0.3 trunk 0.1.0 0.1.1 1.0.0 1.0.1 1.0.2 All 67 releases
notifier / libraries / action-scheduler / classes / abstracts / ActionScheduler_Abstract_Schedule.php

ActionScheduler_Abstract_Schedule.php in WANotifier for Forms and Actions 2.7.5, at libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schedule.php

84 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class ActionScheduler_Abstract_Schedule
5 */
6 abstract class ActionScheduler_Abstract_Schedule extends ActionScheduler_Schedule_Deprecated {
7
8 /**
9 * The date & time the schedule is set to run.
10 *
11 * @var DateTime
12 */
13 private $scheduled_date = NULL;
14
15 /**
16 * Timestamp equivalent of @see $this->scheduled_date
17 *
18 * @var int
19 */
20 protected $scheduled_timestamp = NULL;
21
22 /**
23 * @param DateTime $date The date & time to run the action.
24 */
25 public function __construct( DateTime $date ) {
26 $this->scheduled_date = $date;
27 }
28
29 /**
30 * Check if a schedule should recur.
31 *
32 * @return bool
33 */
34 abstract public function is_recurring();
35
36 /**
37 * Calculate when the next instance of this schedule would run based on a given date & time.
38 *
39 * @param DateTime $after
40 * @return DateTime
41 */
42 abstract protected function calculate_next( DateTime $after );
43
44 /**
45 * Get the next date & time when this schedule should run after a given date & time.
46 *
47 * @param DateTime $after
48 * @return DateTime|null
49 */
50 public function get_next( DateTime $after ) {
51 $after = clone $after;
52 if ( $after > $this->scheduled_date ) {
53 $after = $this->calculate_next( $after );
54 return $after;
55 }
56 return clone $this->scheduled_date;
57 }
58
59 /**
60 * Get the date & time the schedule is set to run.
61 *
62 * @return DateTime|null
63 */
64 public function get_date() {
65 return $this->scheduled_date;
66 }
67
68 /**
69 * For PHP 5.2 compat, since DateTime objects can't be serialized
70 * @return array
71 */
72 public function __sleep() {
73 $this->scheduled_timestamp = $this->scheduled_date->getTimestamp();
74 return array(
75 'scheduled_timestamp',
76 );
77 }
78
79 public function __wakeup() {
80 $this->scheduled_date = as_get_datetime_object( $this->scheduled_timestamp );
81 unset( $this->scheduled_timestamp );
82 }
83 }
84