/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model=new Persontimeslot;

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

if(isset($_POST['Persontimeslot']))
{
$model->attributes=$_POST['Persontimeslot'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}

$this->render('create',array(
'model'=>$model,
));
}
예제 #2
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;
 }