Beispiel #1
0
 private function addOrUpdatePersonTimeSlots($personId, $slotdate, $slotvalue){
     $slot = $this->getSlotfromCT($slotdate);
     if($slot === null){
         return;
     }
     $slotdatestr = $slotdate->format('Y-m-d');
     $conditions = array('person_id=? AND DATE(slotdate)=?', $personId, $slotdatestr);
     $result = \Persontimeslot::find('all', array('conditions' => $conditions));
     $rec===null;
     if(count($result) > 0){
         $rec = $result[0];
         //$rec = \Persontimeslot::find($result[0]->id);
     }
     if($rec===null){
         $attributes = array('person_id' => $personId
                             ,'slotdate' => $slotdate);
         $rec = \Persontimeslot::create($attributes);
     }
     $oldvalue = (is_null($rec->$slot))?0:$rec->$slot;
     $newvalue = $oldvalue + $slotvalue;
     if($newvalue <= 0) $newvalue = null;
     $attributes = array($slot => $newvalue);
     $rec->update_attributes($attributes);
 }