Пример #1
0
 private function updatestatushistory($ofwhich, $ofwhichid, $statusname, $statusdt){//1 -order 2- ordertask etc.,
     $higherflds = array();
     $stsfldtoupdate = $this->getStatusFieldFromName($ofwhich, $statusname, $higherflds);
     if(is_null($stsfldtoupdate))
     {
         return;
     }
     $condition = array('ofwhich_id=?', $ofwhichid);
     $result = \Statushistory::find('all', array('conditions' => $condition));
     $attributes = array(
             "$stsfldtoupdate" => $statusdt                    
             );
     foreach($higherflds as $higerfld){
         $attributes["$higerfld"] = null;
     }
     if(isset($result) && count($result) > 0){
         $recid = isset($result[0]->id)?$result[0]->id:-1;
         try{
             $data = \Statushistory::find($recid);
         }catch (\ActiveRecord\RecordNotFound $ex) {
             $data = null;
         }
         if(!is_null($data)){
             $data->update_attributes($attributes);
         }
     }else{
         $attributes["ofwhich_id"] = $ofwhichid;
         $data = \Statushistory::create($attributes);
     }
 }
Пример #2
0
    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;
}