/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model=new Geolocation; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if(isset($_POST['Geolocation'])) { $model->attributes=$_POST['Geolocation']; if($model->save()) $this->redirect(array('view','id'=>$model->id)); } $this->render('create',array( 'model'=>$model, )); }
public function saveGeo($post) { foreach ($post as $id => $arr) { if (is_numeric($id)) { $model = Geolocation::model()->findByPk($id); $model->attributes = $arr; @$model->save(); } if ($id == "new") { $model = new Geolocation(); if (!empty($arr['user_input'])) { $model->attributes = $arr; if ($model->save()) { return new Geolocation(); } } return $model; } } }
public function actionGeolocations() { $rtn = false; $trans = Yii::app()->db->beginTransaction(); try { $postedData = $this->getPostedData(); if(empty($postedData[0])) {//single object one job-onestatus $postedData =array($postedData); } else { //multiple as array of jobid=status } foreach($postedData as $single) { $longitude = (isset($single['lng'])?$single['lng']:null); $latitude = (isset($single['lat'])?$single['lat']:null); $capturedat = (isset($single['captured_at'])?$single['captured_at']:null); $capturedat = Yii::app()->controller->getMysqlFormattedDatetime($capturedat); if(empty($capturedat)) { $capturedat = date('Y-m-d H:i:s'); } $person_id = $this->mobileUser->person->id; $model = new Geolocation; $model->lng = $longitude; $model->lat = $latitude; $model->captured_at = $capturedat; $model->person_id = $person_id; $rtn = $model->save(); if(!$rtn) break; } } catch (Exception $e) { $rtn = false; } if($rtn) { $trans->commit(); $rtnCode = Helper::CONST_Error_None; $message = Helper::CONST_PERSON_GPS_SAVED; } else { $trans->rollback(); $rtnCode = Helper::CONST_SaveError; $message = Helper::CONST_PERSON_GPS_SAVE_FAIL; } $this->returnJsonResponse($rtnCode, array(), $message); }