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
38 freq = DAILY | YEARLY | MONTHLY
40 * THESE ARE EXCLUSIVE..
41 * freq_day = 1,2,3,4,5" - day number.. or dayofmonth USES TIME FROM DTSTART (unless hours are speced.)
43 * freq_hourly = 'what hours' << OR IF EMPTY USES TIME FROM DTSTART
45 /* the code above is auto generated do not remove the tag below */
48 function notifytimesRange($advance) {
50 $start = date('Y-m-d H:i:s', max(strtotime("NOW - 24 HOURS"), strtotime($this->dtstart)));
51 $end = date('Y-m-d H:i:s', min(strtotime("NOW + $advance DAYS"), strtotime($this->dtend)));
55 function notifytimes($advance)
58 // make a list of datetimes when notifies need to be generated for.
59 // it starts 24 hours ago.. or when dtstart
61 list($start, $end) = $this->notifytimesRange($advance);
63 if (strtotime($start) > strtotime($end)) {
64 return array(); // no data..
67 print_r(json_decode($this->freq_day));
72 $hours = json_decode($this->freq_hour);
73 //$dayAry = json_decode($this->freq_day);
75 $hours = array(date('H:i', strtotime($this->dtstart)));
78 $days = explode(','. $this->freq_day);
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 // skip days not accounted for..
85 if (!in_array(date('N', strtotime($day)), $days)) {
89 foreach($hours as $h) {
90 $hh = strpos($h,":") > 0 ? $h : "$H:00";
91 $ret[] = $day . ' ' . $hh;
95 return $this->applyTimezoneToList($ret);
98 for($day = date('Y-m-d', strtotime($start));
99 strtotime($day) < strtotime($end);
100 $day = date('Y-m-d', strtotime("$day + 1 DAY")))
102 foreach($hours as $h) {
103 $hh = strpos($h,":") > 0 ? $h : "$H:00";
104 $ret[] = $day . ' ' . $hh;
106 return $this->applyTimezoneToList($ret);
109 switch($this->freq) {
111 // happens every day based on freq_hour.
112 $hours = explode(',', $this->freq_hour);
113 for ($day = date('Y-m-d', strtotime($start));
114 strtotime($day) < strtotime($end);
115 $day = date('Y-m-d', strtotime("$day + 1 DAY")))
117 foreach($hours as $h) {
118 $hh = strpos($h,":") > 0 ? $h : "$H:00";
119 $ret[] = $day . ' ' . $hh;
122 return $this->applyTimezoneToList($ret);
125 $hours = explode(',', $this->freq_hour);
127 $hours = array(date('H:i', strtotime($this->dtstart)));
130 $days = explode(','. $this->freq_day);
132 for ($day = date('Y-m-d', strtotime($start));
133 strtotime($day) < strtotime($end);
134 $day = date('Y-m-d', strtotime("$day + 1 DAY")))
136 // skip days not accounted for..
137 if (!in_array(date('N', strtotime($day)), $days)) {
141 foreach($hours as $h) {
142 $hh = strpos($h,":") > 0 ? $h : "$H:00";
143 $ret[] = $day . ' ' . $hh;
147 return $this->applyTimezoneToList($ret);
150 case 'MONTHLY': // ignored..
151 case 'YEARLY': // ignored..
157 function applyTimezoneToList($ar)
161 $tz = explode($this->tz, ":");
165 $append = ($tz[0] < 0) ? " - " : " + ";
167 $append .= abs($tz[0]) . " HOURS";
168 if (!empty($tz[1])) {
169 $append .= $tz[1] . " MINUTES";
174 $ret[] = date('Y-m-d H:i', strtotime($a . $append));
182 function generateNotifications(){
183 //$this->notifytimes(2);
184 //DB_DataObject::debugLevel(1);
186 $w = DB_DataObject::factory($this->tableName());
187 //$this->notifytimes(2);
189 //$test = $w->fetchAll();
191 //$test = $this->notifytimes(2);
196 $notifytime = $w->notifyTimes(2);
197 var_dump($notifytime);
198 // $this->id = $w->id;
199 // $this->person_id = $w->person_id;
200 // $this->dtstart = $w->dtstart;
201 // $this->dtend = $w->dtend;
202 // $this->tz = $w->tz;
203 // $this->updated_dt = $w->updated_dt;
204 // $this->last_applied_dt = $w->last_applied_dt;
205 // $this->freq = $w->freq;
206 // $this->freq_day = $w->freq_day;
207 // $this->freq_hour = $w->freq_hour;
208 // $this->onid = $w->onid;
209 // $this->ontable = $w->ontable;
210 // $this->last_event_id = $w->last_event_id;
211 // $this->method = $w->method;
212 //$this->dtstart = $w->dtstart;
213 //$this->dtend = $w->dtend;
215 //$w->notifytimes(2);
216 //var_dump($w->notifytimes(2));
218 // foreach($test as $item){