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..
69 $hours = array_unique(json_decode($this->freq_hour));
71 $days = json_decode($this->freq_day);
74 foreach($hours as $h){
75 $ret[] = date('Y-m-d', strtotime($d)) . ' ' . $h;
78 return $this->applyTimezoneToList($ret);
80 // for ($day = date('Y-m-d', strtotime($start)); strtotime($day) < strtotime($end); $day = date('Y-m-d', strtotime("$day + 1 DAY"))){
82 // // skip days not accounted for..
83 // if (!in_array(date('N', strtotime($day)), $days)) {
86 // foreach($hours as $h) {
87 // $hh = strpos($h,":") > 0 ? $h : "$H:00";
88 // $ret[] = $day . ' ' . $hh;
91 // return $this->applyTimezoneToList($ret);
93 // if($this->freq_hour){
94 // // happens every day based on freq_hour.
95 // $hours = json_decode($this->freq_hour);
96 // for ($day = date('Y-m-d', strtotime($start));
97 // strtotime($day) < strtotime($end);
98 // $day = date('Y-m-d', strtotime("$day + 1 DAY")))
100 // foreach($hours as $h) {
101 // $hh = strpos($h,":") > 0 ? $h : "$H:00";
102 // $ret[] = $day . ' ' . $hh;
105 // return $this->applyTimezoneToList($ret);
107 // switch($this->freq) {
109 // // happens every day based on freq_hour.
110 // $hours = explode(',', $this->freq_hour);
111 // for ($day = date('Y-m-d', strtotime($start));
112 // strtotime($day) < strtotime($end);
113 // $day = date('Y-m-d', strtotime("$day + 1 DAY")))
115 // foreach($hours as $h) {
116 // $hh = strpos($h,":") > 0 ? $h : "$H:00";
117 // $ret[] = $day . ' ' . $hh;
120 // return $this->applyTimezoneToList($ret);
123 // $hours = explode(',', $this->freq_hour);
125 // $hours = array(date('H:i', strtotime($this->dtstart)));
128 // $days = explode(','. $this->freq_day);
130 // for ($day = date('Y-m-d', strtotime($start));
131 // strtotime($day) < strtotime($end);
132 // $day = date('Y-m-d', strtotime("$day + 1 DAY")))
134 // // skip days not accounted for..
135 // if (!in_array(date('N', strtotime($day)), $days)) {
139 // foreach($hours as $h) {
140 // $hh = strpos($h,":") > 0 ? $h : "$H:00";
141 // $ret[] = $day . ' ' . $hh;
145 // return $this->applyTimezoneToList($ret);
148 // case 'MONTHLY': // ignored..
149 // case 'YEARLY': // ignored..
155 function applyTimezoneToList($ar)
159 // $tz = explode($this->tz, ":");
163 // $append = ($tz[0] < 0) ? " - " : " + ";
165 // $append .= abs($tz[0]) . " HOURS";
166 // if (!empty($tz[1])) {
167 // $append .= $tz[1] . " MINUTES";
172 $ret[] = date_timezone_set(strtotime($a), timezone_open($this->tz));
173 //$ret[] = date('Y-m-d H:i', strtotime($a . $append));
181 function generateNotifications(){
182 //$this->notifytimes(2);
183 //DB_DataObject::debugLevel(1);
185 $w = DB_DataObject::factory($this->tableName());
186 //$this->notifytimes(2);
188 //$test = $w->fetchAll();
190 //$test = $this->notifytimes(2);
195 $notifytime = $w->notifyTimes(2);
196 var_dump($notifytime);
197 // $this->id = $w->id;
198 // $this->person_id = $w->person_id;
199 // $this->dtstart = $w->dtstart;
200 // $this->dtend = $w->dtend;
201 // $this->tz = $w->tz;
202 // $this->updated_dt = $w->updated_dt;
203 // $this->last_applied_dt = $w->last_applied_dt;
204 // $this->freq = $w->freq;
205 // $this->freq_day = $w->freq_day;
206 // $this->freq_hour = $w->freq_hour;
207 // $this->onid = $w->onid;
208 // $this->ontable = $w->ontable;
209 // $this->last_event_id = $w->last_event_id;
210 // $this->method = $w->method;
211 //$this->dtstart = $w->dtstart;
212 //$this->dtend = $w->dtend;
214 //$w->notifytimes(2);
215 //var_dump($w->notifytimes(2));
217 // foreach($test as $item){