public function updatestatushistory($ofwhich, $ofwhichid, $status, $statusdt) {//1 -order 2- ordertask etc., // $statusmodel = Statusmaster::model()->getStatusByNameOrId($status, $ofwhich, true); // if(empty($statusmodel)) // { // return; // } // $status = $statusmodel->name; $rtn = false; try { $higherflds = array(); $stsfldtoupdate = $this->getStatusHistoryFieldFromId($ofwhich, $status, $higherflds); if(empty($stsfldtoupdate)) { return; } $cndn = 'ofwhich_id=:ofwhich'; $params = array(':ofwhich' => $ofwhichid); $criteria=new CDbCriteria(array( 'condition' => $cndn, 'params'=> $params, )); $result = Statushistory::model()->findAll($criteria); $attributes = array( "$stsfldtoupdate" => $statusdt ); foreach($higherflds as $higerfld) { $attributes["$higerfld"] = null; } if(!empty($result) && !empty($result[0])) { $record = Statushistory::model()->findByPk($result[0]->id); } else { $record = new Statushistory; $attributes["ofwhich_id"] = $ofwhichid; } if(!empty($record)) { $record->attributes = $attributes; $rtn = $record->save(); } } catch(Exception $e) { $rtn = false; } 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=Statushistory::model()->findByPk($id); if($model===null) throw new CHttpException(404,'The requested page does not exist.'); return $model; }