3 * Table Definition for core_notify_recur
5 require_once 'DB/DataObject.php';
7 class Pman_Core_DataObjects_Core_notify_recur extends DB_DataObject
10 /* the code below is auto generated do not remove the above tag */
12 public $__table = 'core_notify_recur'; // table name
13 public $id; // int(11) not_null primary_key auto_increment
14 public $person_id; // int(11) not_null
16 public $dtstart; // datetime(19) not_null binary
17 public $dtend; // datetime(19) not_null binary
18 public $tz; // real(6) not_null
20 public $updated_dt; // datetime(19) not_null binary
22 public $last_applied_dt; // datetime(19) not_null binary
23 // public $max_applied_dtl
24 public $freq; // varchar(8) NOT NULL;
25 public $freq_day; // text NOT NULL;
26 public $freq_hour; // text
28 public $onid; // int(11) not_null
29 public $ontable; // string(128) not_null
30 public $last_event_id; // int(11)
31 public $method; // string(128) not_null
40 freq = DAILY | YEARLY | MONTHLY
42 * THESE ARE EXCLUSIVE..
43 * freq_day = 1,2,3,4,5" - day number.. or dayofmonth USES TIME FROM DTSTART (unless hours are speced.)
45 * freq_hourly = 'what hours' << OR IF EMPTY USES TIME FROM DTSTART
47 /* the code above is auto generated do not remove the tag below */
50 function notifytimesRange($advance) {
52 $this->start = date('Y-m-d H:i:s', max(strtotime("NOW - 24 HOURS"), strtotime($this->dtstart)));
53 $this->end = date('Y-m-d H:i:s', min(strtotime("NOW + $advance DAYS"), strtotime($this->dtend)));
54 error_log($this->start);
55 error_log($this->end);
59 function notifytimes($advance)
61 error_log($this->start);
62 error_log($this->end);
63 // make a list of datetimes when notifies need to be generated for.
64 // it starts 24 hours ago.. or when dtstart
65 list($this->start, $this->end) = $this->notifytimesRange($advance);
67 if (strtotime($this->start) > strtotime($this->end)) {
68 return array(); // no data..
78 // happens every day based on freq_hour.
79 $hours = explode(',', $this->freq_hour);
80 for ($day = date('Y-m-d', strtotime($start));
81 strtotime($day) < strtotime($end);
82 $day = date('Y-m-d', strtotime("$day + 1 DAY")))
84 foreach($hours as $h) {
85 $hh = strpos($h,":") > 0 ? $h : "$H:00";
86 $ret[] = $day . ' ' . $hh;
89 return $this->applyTimezoneToList($ret);
92 $hours = explode(',', $this->freq_hour);
94 $hours = array(date('H:i', strtotime($this->dtstart)));
97 $days = explode(','. $this->freq_day);
99 for ($day = date('Y-m-d', strtotime($start));
100 strtotime($day) < strtotime($end);
101 $day = date('Y-m-d', strtotime("$day + 1 DAY")))
103 // skip days not accounted for..
104 if (!in_array(date('N', strtotime($day)), $days)) {
108 foreach($hours as $h) {
109 $hh = strpos($h,":") > 0 ? $h : "$H:00";
110 $ret[] = $day . ' ' . $hh;
114 return $this->applyTimezoneToList($ret);
117 case 'MONTHLY': // ignored..
118 case 'YEARLY': // ignored..
124 function applyTimezoneToList($ar)
128 $tz = explode($this->tz, ":");
132 $append = ($tz[0] < 0) ? " - " : " + ";
134 $append .= abs($tz[0]) . " HOURS";
135 if (!empty($tz[1])) {
136 $append .= $tz[1] . " MINUTES";
141 $ret[] = date('Y-m-d H:i', strtotime($a . $append));
149 function generateNotifications(){
150 //$this->notifytimes(2);
151 $test = $this->notifytimes(2);