- foreach($notifytimes as $newTimes){
- $newSearch = DB_DataObject::factory('core_notify');
-
- $newSearch->whereAdd("act_start == $newTimes");
- $newSearch->delete(DB_DATAOBJECT_WHEREADD_ONLY);
-// if($newSearch->find(true)){
-//
-// continue;
-// }else{
-// $newSearch->id = $w->id;
-// $newSearch->recur_id = $w->id;
-// $newSearch->act_when = $w->dtstart;
-// $newSearch->onid = $w->onid;
-// $newSearch->ontable = $w->ontable;
-// $newSearch->person_id = $w->person_id;
-// $newSearch->act_start = $w->dtstart;
-// }
+ }
+
+
+ function generateNotificationsSingle()
+ {
+
+
+ $notifytimes = $this->notifyTimes(2);
+ $newSearch = DB_DataObject::factory('core_notify');
+ $newSearch->whereAdd( 'act_start > NOW()');
+ $newSearch->recur_id = $this->id;
+ $old = $newSearch->fetchAll('act_start', 'id');
+ // returns array('2012-12-xx'=>12, 'date' => id....)
+
+
+ foreach($notifytimes as $time){
+ if (strtotime($time) < time()) {
+ // will not get deleted..
+ unset($old[$time]);
+ continue;
+ }
+ if (isset($old[$time])) {
+ // we already have it...
+ unset($old[$time]);
+ continue;
+ }
+
+ // do not have a notify event... creat it..
+ $add = DB_DataObject::factory('core_notify');
+ $add->setFrom(array(
+ "recur_id" => $this->id,
+ "act_start" => $time,
+ "act_when" => $time,
+ "person_id" => $this->person_id,
+ "onid" => $this->onid,
+ "ontable" => $this->ontable,
+ 'evtype' => $this->method,
+ ));
+ $add->insert();
+ }
+ foreach($old as $date => $id ) {
+ $del = DB_DataObject::factory('core_notify');
+ $del->get($id);
+ $del->delete();