Beispiel #1
0
 public function addOrUpdatePersonTimeSlots($personId, $slotdate, $slotvalue)
 {
     if(empty($slotdate)) return false;
     $t1 = '';
     $t2 = '';
     $this->splitCT($slotdate, $t1, $t2);
     $slot = $this->getSlotfromCT($t1);
     $rtn = $slot !== null;
     if(!$rtn) return $rtn;
     
     $criteria=new CDbCriteria();
     $criteria->addCondition('person_id =' . $personId);
     $criteria->addCondition('DATE(slotdate) >= DATE("'. $t1 .'")');
     $result = Persontimeslot::model()->findAll($criteria);
     //$slotdatestr = $slotdate->format('Y-m-d');
     //Yii::app()->controller->getMysqlFormattedDatetime($slotdate)
     if(count($result) > 0)
     {
         $rec= $result[0];
     }
     else if($slotvalue > 0)
     {
         $rec = new Persontimeslot;
     }
     else
     {
         return true;//no work. meaningless.
     }
     $oldvalue = (is_null($rec->$slot))?0:$rec->$slot;
     $newvalue = $oldvalue + $slotvalue;
     if($newvalue <= 0) $newvalue = null;
     $attributes = array('person_id' => $personId
                         ,'slotdate' => $t1
                         ,"$slot" => $newvalue
                         );
     $rec->attributes = $attributes;
     $rtn = $rec->save();
     return $rtn;
 }
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer the ID of the model to be loaded
*/
public function loadModel($id)
{
$model=Persontimeslot::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}